From 7b2a1b236459fd9a2fafa3bbe31a711dcf8a55aa Mon Sep 17 00:00:00 2001 From: Phillip Cloud Date: Mon, 2 Jun 2014 13:45:11 -0400 Subject: [PATCH] BUG: do not check that val != val and not equal inf/-inf since by def val not eq val is nan --- doc/source/v0.14.1.txt | 3 +++ pandas/src/util.pxd | 3 +-- pandas/tests/test_series.py | 10 ++++++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/doc/source/v0.14.1.txt b/doc/source/v0.14.1.txt index 248fa098c7269..45e0e15d311b4 100644 --- a/doc/source/v0.14.1.txt +++ b/doc/source/v0.14.1.txt @@ -82,3 +82,6 @@ Bug Fixes (:issue:`7140`). - Bug in ``StringMethods.extract()`` where a single match group Series would use the matcher's name instead of the group name (:issue:`7313`). +- Bug in ``isnull()`` when ``mode.use_inf_as_null == True`` where isnull + wouldn't test ``True`` when it encountered an ``inf``/``-inf`` + (:issue:`7315`). diff --git a/pandas/src/util.pxd b/pandas/src/util.pxd index 7a30f018e623e..cc1921e6367c5 100644 --- a/pandas/src/util.pxd +++ b/pandas/src/util.pxd @@ -76,8 +76,7 @@ cdef inline bint _checknull_old(object val): cdef double INF = np.inf cdef double NEGINF = -INF try: - return bool(val is None or val != val and val != INF - and val != NEGINF) + return val is None or val != val or val == INF or val == NEGINF except ValueError: return False diff --git a/pandas/tests/test_series.py b/pandas/tests/test_series.py index 2385f9ef514fc..bc12cc5aaaa3b 100644 --- a/pandas/tests/test_series.py +++ b/pandas/tests/test_series.py @@ -2941,6 +2941,16 @@ def test_raise_on_info(self): with tm.assertRaises(AttributeError): s.info() + def test_isnull_for_inf(self): + s = Series(['a', np.inf, np.nan, 1.0]) + with pd.option_context('mode.use_inf_as_null', True): + r = s.isnull() + dr = s.dropna() + e = Series([False, True, True, False]) + de = Series(['a', 1.0], index=[0, 3]) + tm.assert_series_equal(r, e) + tm.assert_series_equal(dr, de) + # TimeSeries-specific