Skip to content

Commit c030198

Browse files
committed
BUG: fix isnull handling of objects on which bool fails e.g. DataFrame close #1749
1 parent ef105e7 commit c030198

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

RELEASE.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ pandas 0.8.2
8585
- Support StaticTzInfo in DatetimeIndex infrastructure (#1692)
8686
- Allow MultiIndex setops with length-0 other type indexes (#1727)
8787
- Fix handling of DatetimeIndex in DataFrame.to_records (#1720)
88+
- Fix handling of general objects in isnull on which bool(...) fails (#1749)
8889

8990
pandas 0.8.1
9091
============

pandas/src/util.pxd

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,10 @@ cdef inline is_array(object o):
5858

5959

6060
cdef inline bint _checknull(object val):
61-
return not cnp.PyArray_Check(val) and (val is None or val != val)
61+
try:
62+
return bool(val is None or val != val)
63+
except ValueError:
64+
return False
6265

6366
cdef inline bint _checknan(object val):
6467
return not cnp.PyArray_Check(val) and val != val

pandas/tests/test_series.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,6 +1020,17 @@ def test_repr(self):
10201020
rep_str = repr(ser)
10211021
self.assert_("Name: 0" in rep_str)
10221022

1023+
def test_repr_bool_fails(self):
1024+
s = Series([DataFrame(np.random.randn(2,2)) for i in range(5)])
1025+
1026+
import sys
1027+
1028+
buf = StringIO()
1029+
sys.stderr = buf
1030+
# it works (with no Cython exception barf)!
1031+
repr(s)
1032+
sys.stderr = sys.__stderr__
1033+
self.assertEquals(buf.getvalue(), '')
10231034

10241035
def test_timeseries_repr_object_dtype(self):
10251036
index = Index([datetime(2000, 1, 1) + timedelta(i)

0 commit comments

Comments
 (0)