Skip to content

BUG/TST: Fixes isnull behavior on NaT in array. Closes #5443 #5524

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 6, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pandas/lib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ cdef inline int64_t get_timedelta64_value(val):
cdef double INF = <double> np.inf
cdef double NEGINF = -INF


cpdef checknull(object val):
if util.is_float_object(val) or util.is_complex_object(val):
return val != val # and val != INF and val != NEGINF
Expand All @@ -183,7 +182,7 @@ cpdef checknull(object val):
elif is_array(val):
return False
else:
return util._checknull(val)
return _checknull(val)

cpdef checknull_old(object val):
if util.is_float_object(val) or util.is_complex_object(val):
Expand Down Expand Up @@ -213,7 +212,8 @@ def isnullobj(ndarray[object] arr):
n = len(arr)
result = np.zeros(n, dtype=np.uint8)
for i from 0 <= i < n:
result[i] = util._checknull(arr[i])
arobj = arr[i]
result[i] = arobj is NaT or _checknull(arobj)
return result.view(np.bool_)

@cython.wraparound(False)
Expand Down
2 changes: 1 addition & 1 deletion pandas/src/util.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ cdef inline is_array(object o):

cdef inline bint _checknull(object val):
try:
return val is None or (cpython.PyFloat_Check(val) and val != val)
return val is None or (cpython.PyFloat_Check(val) and val != val)
except ValueError:
return False

Expand Down
10 changes: 9 additions & 1 deletion pandas/tests/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import nose
from nose.tools import assert_equal
import numpy as np
from pandas.tslib import iNaT
from pandas.tslib import iNaT, NaT

from pandas import Series, DataFrame, date_range, DatetimeIndex, Timestamp
from pandas import compat
Expand Down Expand Up @@ -114,6 +114,14 @@ def test_isnull_lists():
result = isnull([u('foo'), u('bar')])
assert(not result.any())

def test_isnull_nat():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test with an exlicit np.array([NaT]),dtype=object as well

result = isnull([NaT])
exp = np.array([True])
assert(np.array_equal(result, exp))

result = isnull(np.array([NaT], dtype=object))
exp = np.array([True])
assert(np.array_equal(result, exp))

def test_isnull_datetime():
assert (not isnull(datetime.now()))
Expand Down