Skip to content

Commit

Permalink
BUG: fix isnull handling of objects on which bool fails e.g. DataFrame
Browse files Browse the repository at this point in the history
…close #1749
  • Loading branch information
wesm committed Aug 12, 2012
1 parent ef105e7 commit c030198
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions RELEASE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ pandas 0.8.2
- Support StaticTzInfo in DatetimeIndex infrastructure (#1692)
- Allow MultiIndex setops with length-0 other type indexes (#1727)
- Fix handling of DatetimeIndex in DataFrame.to_records (#1720)
- Fix handling of general objects in isnull on which bool(...) fails (#1749)

pandas 0.8.1
============
Expand Down
5 changes: 4 additions & 1 deletion pandas/src/util.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ cdef inline is_array(object o):


cdef inline bint _checknull(object val):
return not cnp.PyArray_Check(val) and (val is None or val != val)
try:
return bool(val is None or val != val)
except ValueError:
return False

cdef inline bint _checknan(object val):
return not cnp.PyArray_Check(val) and val != val
11 changes: 11 additions & 0 deletions pandas/tests/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -1020,6 +1020,17 @@ def test_repr(self):
rep_str = repr(ser)
self.assert_("Name: 0" in rep_str)

def test_repr_bool_fails(self):
s = Series([DataFrame(np.random.randn(2,2)) for i in range(5)])

import sys

buf = StringIO()
sys.stderr = buf
# it works (with no Cython exception barf)!
repr(s)
sys.stderr = sys.__stderr__
self.assertEquals(buf.getvalue(), '')

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

0 comments on commit c030198

Please sign in to comment.