Skip to content

Commit af2bfb7

Browse files
committed
Merge pull request #8726 from jreback/inf
COMPAT: Compat issue is DataFrame.dtypes when options.mode.use_inf_as_null is True (GH8722)
2 parents 83f3c96 + 489bfff commit af2bfb7

File tree

5 files changed

+15
-23
lines changed

5 files changed

+15
-23
lines changed

doc/source/whatsnew/v0.15.1.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ Bug Fixes
212212
- Bug in duplicated/drop_duplicates with a Categorical (:issue:`8623`)
213213
- Bug in ``Categorical`` reflected comparison operator raising if the first argument was a numpy array scalar (e.g. np.int64) (:issue:`8658`)
214214
- Bug in Panel indexing with a list-like (:issue:`8710`)
215-
215+
- Compat issue is ``DataFrame.dtypes`` when ``options.mode.use_inf_as_null`` is True (:issue:`8722`)
216216

217217

218218

pandas/lib.pyx

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,8 @@ def isnullobj(ndarray[object] arr):
289289
n = len(arr)
290290
result = np.zeros(n, dtype=np.uint8)
291291
for i from 0 <= i < n:
292-
arobj = arr[i]
293-
result[i] = arobj is NaT or _checknull(arobj)
292+
val = arr[i]
293+
result[i] = val is NaT or _checknull(val)
294294
return result.view(np.bool_)
295295

296296
@cython.wraparound(False)
@@ -303,10 +303,10 @@ def isnullobj_old(ndarray[object] arr):
303303
n = len(arr)
304304
result = np.zeros(n, dtype=np.uint8)
305305
for i from 0 <= i < n:
306-
result[i] = util._checknull_old(arr[i])
306+
val = arr[i]
307+
result[i] = val is NaT or util._checknull_old(val)
307308
return result.view(np.bool_)
308309

309-
310310
@cython.wraparound(False)
311311
@cython.boundscheck(False)
312312
def isnullobj2d(ndarray[object, ndim=2] arr):
@@ -323,20 +323,6 @@ def isnullobj2d(ndarray[object, ndim=2] arr):
323323
result[i, j] = 1
324324
return result.view(np.bool_)
325325

326-
@cython.wraparound(False)
327-
@cython.boundscheck(False)
328-
def isnullobj_old(ndarray[object] arr):
329-
cdef Py_ssize_t i, n
330-
cdef object val
331-
cdef ndarray[uint8_t] result
332-
333-
n = len(arr)
334-
result = np.zeros(n, dtype=np.uint8)
335-
for i from 0 <= i < n:
336-
result[i] = util._checknull_old(arr[i])
337-
return result.view(np.bool_)
338-
339-
340326
@cython.wraparound(False)
341327
@cython.boundscheck(False)
342328
def isnullobj2d_old(ndarray[object, ndim=2] arr):

pandas/src/util.pxd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +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 val is None or val != val or val == INF or val == NEGINF
79+
return val is None or (cpython.PyFloat_Check(val) and (val != val or val == INF or val == NEGINF))
8080
except ValueError:
8181
return False
8282

pandas/tests/test_frame.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6783,6 +6783,12 @@ def test_dtypes(self):
67836783
index=result.index)
67846784
assert_series_equal(result, expected)
67856785

6786+
# compat, GH 8722
6787+
with option_context('use_inf_as_null',True):
6788+
df = DataFrame([[1]])
6789+
result = df.dtypes
6790+
assert_series_equal(result,Series({0:np.dtype('int64')}))
6791+
67866792
def test_convert_objects(self):
67876793

67886794
oops = self.mixed_frame.T.T

pandas/tests/test_lib.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import pandas as pd
66
from pandas.lib import isscalar, item_from_zerodim
77
import pandas.util.testing as tm
8-
8+
from pandas.compat import u
99

1010
class TestIsscalar(tm.TestCase):
1111
def test_isscalar_builtin_scalars(self):
@@ -16,7 +16,7 @@ def test_isscalar_builtin_scalars(self):
1616
self.assertTrue(isscalar(np.nan))
1717
self.assertTrue(isscalar('foobar'))
1818
self.assertTrue(isscalar(b'foobar'))
19-
self.assertTrue(isscalar(u'foobar'))
19+
self.assertTrue(isscalar(u('efoobar')))
2020
self.assertTrue(isscalar(datetime(2014, 1, 1)))
2121
self.assertTrue(isscalar(date(2014, 1, 1)))
2222
self.assertTrue(isscalar(time(12, 0)))
@@ -38,7 +38,7 @@ def test_isscalar_numpy_array_scalars(self):
3838
self.assertTrue(isscalar(np.int32(1)))
3939
self.assertTrue(isscalar(np.object_('foobar')))
4040
self.assertTrue(isscalar(np.str_('foobar')))
41-
self.assertTrue(isscalar(np.unicode_(u'foobar')))
41+
self.assertTrue(isscalar(np.unicode_(u('foobar'))))
4242
self.assertTrue(isscalar(np.bytes_(b'foobar')))
4343
self.assertTrue(isscalar(np.datetime64('2014-01-01')))
4444
self.assertTrue(isscalar(np.timedelta64(1, 'h')))

0 commit comments

Comments
 (0)