19
19
class PandasError (Exception ):
20
20
pass
21
21
22
- def isnull (input ):
22
+ def isnull (obj ):
23
23
'''
24
24
Replacement for numpy.isnan / -numpy.isfinite which is suitable
25
25
for use on object arrays.
@@ -32,29 +32,31 @@ def isnull(input):
32
32
-------
33
33
boolean ndarray or boolean
34
34
'''
35
+ if np .isscalar (obj ) or obj is None :
36
+ return lib .checknull (obj )
37
+
35
38
from pandas .core .generic import PandasObject
36
39
from pandas import Series
37
- if isinstance (input , np .ndarray ):
38
- if input .dtype .kind in ('O' , 'S' ):
40
+ if isinstance (obj , np .ndarray ):
41
+ if obj .dtype .kind in ('O' , 'S' ):
39
42
# Working around NumPy ticket 1542
40
- shape = input .shape
43
+ shape = obj .shape
41
44
result = np .empty (shape , dtype = bool )
42
- vec = lib .isnullobj (input .ravel ())
45
+ vec = lib .isnullobj (obj .ravel ())
43
46
result [:] = vec .reshape (shape )
44
47
45
- if isinstance (input , Series ):
46
- result = Series (result , index = input .index , copy = False )
48
+ if isinstance (obj , Series ):
49
+ result = Series (result , index = obj .index , copy = False )
47
50
else :
48
- result = - np .isfinite (input )
49
- elif isinstance (input , PandasObject ):
51
+ result = - np .isfinite (obj )
52
+ return result
53
+ elif isinstance (obj , PandasObject ):
50
54
# TODO: optimize for DataFrame, etc.
51
- return input .apply (isnull )
55
+ return obj .apply (isnull )
52
56
else :
53
- result = lib .checknull (input )
54
-
55
- return result
57
+ raise TypeError ('cannot handle %s type' % type (obj ))
56
58
57
- def notnull (input ):
59
+ def notnull (obj ):
58
60
'''
59
61
Replacement for numpy.isfinite / -numpy.isnan which is suitable
60
62
for use on object arrays.
@@ -67,7 +69,9 @@ def notnull(input):
67
69
-------
68
70
boolean ndarray or boolean
69
71
'''
70
- return np .negative (isnull (input ))
72
+ if np .isscalar (obj ) or obj is None :
73
+ return not lib .checknull (obj )
74
+ return - isnull (obj )
71
75
72
76
def _pickle_array (arr ):
73
77
arr = arr .view (np .ndarray )
0 commit comments