Skip to content

Commit adb72ea

Browse files
committed
Merge pull request #7315 from cpcloud/fix-dropna-with-inf-7314
BUG: isnull doesn't properly check for inf when requested
2 parents 8549609 + 7b2a1b2 commit adb72ea

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

doc/source/v0.14.1.txt

+3
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,6 @@ Bug Fixes
8282
(:issue:`7140`).
8383
- Bug in ``StringMethods.extract()`` where a single match group Series
8484
would use the matcher's name instead of the group name (:issue:`7313`).
85+
- Bug in ``isnull()`` when ``mode.use_inf_as_null == True`` where isnull
86+
wouldn't test ``True`` when it encountered an ``inf``/``-inf``
87+
(:issue:`7315`).

pandas/src/util.pxd

+1-2
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@ cdef inline bint _checknull_old(object val):
7676
cdef double INF = <double> np.inf
7777
cdef double NEGINF = -INF
7878
try:
79-
return bool(val is None or val != val and val != INF
80-
and val != NEGINF)
79+
return val is None or val != val or val == INF or val == NEGINF
8180
except ValueError:
8281
return False
8382

pandas/tests/test_series.py

+10
Original file line numberDiff line numberDiff line change
@@ -2941,6 +2941,16 @@ def test_raise_on_info(self):
29412941
with tm.assertRaises(AttributeError):
29422942
s.info()
29432943

2944+
def test_isnull_for_inf(self):
2945+
s = Series(['a', np.inf, np.nan, 1.0])
2946+
with pd.option_context('mode.use_inf_as_null', True):
2947+
r = s.isnull()
2948+
dr = s.dropna()
2949+
e = Series([False, True, True, False])
2950+
de = Series(['a', 1.0], index=[0, 3])
2951+
tm.assert_series_equal(r, e)
2952+
tm.assert_series_equal(dr, de)
2953+
29442954

29452955
# TimeSeries-specific
29462956

0 commit comments

Comments
 (0)