From 31c2042bfc9b58a165d561b68e96bdbdc5c65b87 Mon Sep 17 00:00:00 2001 From: thy09 Date: Wed, 27 Nov 2019 23:59:22 +0800 Subject: [PATCH 1/3] Add UT for bug in GH29478 --- pandas/tests/series/test_analytics.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pandas/tests/series/test_analytics.py b/pandas/tests/series/test_analytics.py index e25c4456147f7..fe9306a06efc7 100644 --- a/pandas/tests/series/test_analytics.py +++ b/pandas/tests/series/test_analytics.py @@ -554,6 +554,10 @@ def test_count(self, datetime_series): ts.iloc[[0, 3, 5]] = np.nan tm.assert_series_equal(ts.count(level=1), right - 1) + # GH29478 + with pd.option_context("use_inf_as_na", True): + assert pd.Series([pd.Timestamp("1990/1/1")]).count() == 1 + def test_dot(self): a = Series(np.random.randn(4), index=["p", "q", "r", "s"]) b = DataFrame( From 151c1a13ded51c23a03bc926b7debbaebf9808b6 Mon Sep 17 00:00:00 2001 From: thy09 Date: Thu, 28 Nov 2019 00:00:52 +0800 Subject: [PATCH 2/3] Fix bug GH29478: Add ABCExtensionArray checking in isna_old to avoid bug --- pandas/core/dtypes/missing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/dtypes/missing.py b/pandas/core/dtypes/missing.py index cb4199272f574..205ca193636c6 100644 --- a/pandas/core/dtypes/missing.py +++ b/pandas/core/dtypes/missing.py @@ -176,7 +176,7 @@ def _isna_old(obj): raise NotImplementedError("isna is not defined for MultiIndex") elif isinstance(obj, type): return False - elif isinstance(obj, (ABCSeries, np.ndarray, ABCIndexClass)): + elif isinstance(obj, (ABCSeries, np.ndarray, ABCIndexClass, ABCExtensionArray)): return _isna_ndarraylike_old(obj) elif isinstance(obj, ABCGeneric): return obj._constructor(obj._data.isna(func=_isna_old)) From 7db70f8a83afd2865400e449cd87a8ca8c709a65 Mon Sep 17 00:00:00 2001 From: thy09 Date: Thu, 28 Nov 2019 09:23:52 +0800 Subject: [PATCH 3/3] Add whatnew note --- doc/source/whatsnew/v1.0.0.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/source/whatsnew/v1.0.0.rst b/doc/source/whatsnew/v1.0.0.rst index 48808a7ef7a46..e6f02222248c0 100644 --- a/doc/source/whatsnew/v1.0.0.rst +++ b/doc/source/whatsnew/v1.0.0.rst @@ -674,6 +674,7 @@ Other - Bug in :meth:`DataFrame.append` that raised ``IndexError`` when appending with empty list (:issue:`28769`) - Fix :class:`AbstractHolidayCalendar` to return correct results for years after 2030 (now goes up to 2200) (:issue:`27790`) +- Bug in :meth:`Series.count` raises if use_inf_as_na is enabled (:issue:`29478`) .. _whatsnew_1000.contributors: