Skip to content
Browse files

REF scipy now has a cython version of rankdata

  • Loading branch information...
1 parent 89e90e9 commit 8d9df1197a13b24f50330c749e5bfbee9f5a92b4 @kwgoodman committed Mar 22, 2013
Showing with 13 additions and 2 deletions.
  1. +1 −1 bottleneck/benchmark/bench.py
  2. +12 −1 bottleneck/slow/func.py
View
2 bottleneck/benchmark/bench.py
@@ -271,7 +271,7 @@ def getsetups(setup, shapes, nans):
run = {}
run['name'] = "rankdata"
run['ref'] = "scipy.stats.rankdata based (axis support added)"
- run['scipy_required'] = False
+ run['scipy_required'] = True
if mode == 'fast':
code = "bn.rankdata(a, axis=AXIS)"
else:
View
13 bottleneck/slow/func.py
@@ -6,6 +6,8 @@
'nanrankdata', 'ss', 'nn', 'partsort', 'argpartsort', 'replace',
'anynan', 'allnan']
+rankdata_func = None
+
def median(arr, axis=None):
"Slow median function used for unaccelerated ndim/dtype combinations."
arr = np.asarray(arr)
@@ -108,6 +110,15 @@ def nanargmax(arr, axis=None):
def rankdata(arr, axis=None):
"Slow rankdata function used for unaccelerated ndim/dtype combinations."
+ global rankdata_func
+ if rankdata_func is None:
+ try:
+ # Use scipy's rankdata; newer scipy has cython version
+ from scipy.stats import rankdata as imported_rankdata
+ rankdata_func = imported_rankdata
+ except ImportError:
+ # Use a local copy of scipy's python (not cython) rankdata
+ rankdata_func = scipy_rankdata
arr = np.asarray(arr)
if axis is None:
arr = arr.ravel()
@@ -119,7 +130,7 @@ def rankdata(arr, axis=None):
itshape.pop(axis)
for ij in np.ndindex(*itshape):
ijslice = list(ij[:axis]) + [slice(None)] + list(ij[axis:])
- y[ijslice] = scipy_rankdata(arr[ijslice].astype('float'))
+ y[ijslice] = rankdata_func(arr[ijslice].astype('float'))
return y
def nanrankdata(arr, axis=None):

0 comments on commit 8d9df11

Please sign in to comment.
Something went wrong with that request. Please try again.