Skip to content

Commit e01a762

Browse files
committed
ENH: notnull/isnull perf enhancement regression from 0.3.0. address GH #187
1 parent f62e279 commit e01a762

File tree

3 files changed

+23
-19
lines changed

3 files changed

+23
-19
lines changed

bench/zoo_bench.R

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ timings <- numeric()
1212

1313
## indices <- as.POSIXct(1:100000)
1414

15-
indices <- as.POSIXct(Sys.Date()) + 1:100000
15+
indices <- as.POSIXct(Sys.Date()) + 1:1000000
1616

17-
x <- xts(rnorm(100000), indices)
18-
y <- xts(rnorm(90000), indices[sample(1:100000, 90000)])
17+
x <- xts(rnorm(1000000), indices)
18+
y <- xts(rnorm(900000), indices[sample(1:1000000, 900000)])
1919

2020
for (i in 1:10) {
2121
gc()

pandas/core/common.py

+19-15
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
class PandasError(Exception):
2020
pass
2121

22-
def isnull(input):
22+
def isnull(obj):
2323
'''
2424
Replacement for numpy.isnan / -numpy.isfinite which is suitable
2525
for use on object arrays.
@@ -32,29 +32,31 @@ def isnull(input):
3232
-------
3333
boolean ndarray or boolean
3434
'''
35+
if np.isscalar(obj) or obj is None:
36+
return lib.checknull(obj)
37+
3538
from pandas.core.generic import PandasObject
3639
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'):
3942
# Working around NumPy ticket 1542
40-
shape = input.shape
43+
shape = obj.shape
4144
result = np.empty(shape, dtype=bool)
42-
vec = lib.isnullobj(input.ravel())
45+
vec = lib.isnullobj(obj.ravel())
4346
result[:] = vec.reshape(shape)
4447

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)
4750
else:
48-
result = -np.isfinite(input)
49-
elif isinstance(input, PandasObject):
51+
result = -np.isfinite(obj)
52+
return result
53+
elif isinstance(obj, PandasObject):
5054
# TODO: optimize for DataFrame, etc.
51-
return input.apply(isnull)
55+
return obj.apply(isnull)
5256
else:
53-
result = lib.checknull(input)
54-
55-
return result
57+
raise TypeError('cannot handle %s type' % type(obj))
5658

57-
def notnull(input):
59+
def notnull(obj):
5860
'''
5961
Replacement for numpy.isfinite / -numpy.isnan which is suitable
6062
for use on object arrays.
@@ -67,7 +69,9 @@ def notnull(input):
6769
-------
6870
boolean ndarray or boolean
6971
'''
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)
7175

7276
def _pickle_array(arr):
7377
arr = arr.view(np.ndarray)

scripts/groupby_sample.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import string
44

55
g1 = np.array(list(string.letters))[:-1]
6-
g2 = np.arange(5100)
6+
g2 = np.arange(510)
77
df_small = DataFrame({'group1' : ["a","b","a","a","b","c","c","c","c",
88
"c","a","a","a","b","b","b","b"],
99
'group2' : [1,2,3,4,1,3,5,6,5,4,1,2,3,4,3,2,1],

0 commit comments

Comments
 (0)