Skip to content

Commit

Permalink
BUG: Handle NA values for ExtensionArrays in Series.count (#26836)
Browse files Browse the repository at this point in the history
  • Loading branch information
pilkibun authored and TomAugspurger committed Jun 21, 2019
1 parent 171615a commit 9aef32d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
7 changes: 6 additions & 1 deletion doc/source/whatsnew/v0.25.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -782,11 +782,16 @@ Build Changes

- Fix install error with PyPy on macOS (:issue:`26536`)

ExtensionArray
^^^^^^^^^^^^^^

- Bug in :func:`factorize` when passing an ``ExtensionArray`` with a custom ``na_sentinel`` (:issue:`25696`).
- :meth:`Series.count` miscounts NA values in ExtensionArrays (:issue:`26835`)

Other
^^^^^

- Removed unused C functions from vendored UltraJSON implementation (:issue:`26198`)
- Bug in :func:`factorize` when passing an ``ExtensionArray`` with a custom ``na_sentinel`` (:issue:`25696`).
- Allow :class:`Index` and :class:`RangeIndex` to be passed to numpy ``min`` and ``max`` functions (:issue:`26125`)

.. _whatsnew_0.250.contributors:
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -1659,7 +1659,7 @@ def count(self, level=None):
2
"""
if level is None:
return notna(com.values_from_object(self)).sum()
return notna(self.array).sum()

if isinstance(level, str):
level = self.index._get_level_number(level)
Expand Down
7 changes: 7 additions & 0 deletions pandas/tests/extension/base/methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ def test_count(self, data_missing):
expected = pd.Series([0, 1])
self.assert_series_equal(result, expected)

def test_series_count(self, data_missing):
# GH#26835
ser = pd.Series(data_missing)
result = ser.count()
expected = 1
assert result == expected

def test_apply_simple_series(self, data):
result = pd.Series(data).apply(id)
assert isinstance(result, pd.Series)
Expand Down

0 comments on commit 9aef32d

Please sign in to comment.