Skip to content

Commit

Permalink
Bench move_quantile(q=0.5) with slow.move_median
Browse files Browse the repository at this point in the history
  • Loading branch information
andrii-riazanov committed Sep 21, 2022
1 parent 9447697 commit de181da
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
3 changes: 2 additions & 1 deletion bottleneck/benchmark/bench_detailed.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ def benchsuite(function, fraction_nan):
# avoid all-nan slice warnings from np.median and np.nanmedian
if "%s" == "median": from bottleneck.slow import median as sl_fn
if "%s" == "nanmedian": from bottleneck.slow import nanmedian as sl_fn
if "%s" == "move_quantile": from bottleneck.slow import move_median as sl_fn
from numpy import array, nan
from numpy.random import RandomState
Expand Down Expand Up @@ -116,7 +117,7 @@ def benchsuite(function, fraction_nan):
run = {}
run["name"] = [f + signature, array]
run["statements"] = ["bn_fn" + signature, "sl_fn" + signature]
run["setup"] = setup % (f, f, f, f, f, array, fraction_nan, fraction_nan)
run["setup"] = setup % (f, f, f, f, f, f, array, fraction_nan, fraction_nan)
run["repeat"] = repeat
suite.append(run)

Expand Down
1 change: 1 addition & 0 deletions bottleneck/slow/move.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ def move_rank(a, window, min_count=None, axis=-1):
return move_func(lastrank, a, window, min_count, axis=axis)

# function for handling infs in np.nanquantile
# keyword argument for interpolation method in np.nanquantile changed in 1.22.0
from packaging import version
if version.parse(np.__version__) > version.parse("1.22.0"):
METHOD_KEYWORD = "method"
Expand Down
4 changes: 2 additions & 2 deletions bottleneck/src/move_quantile.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
all = ["move_quantile"]

def move_quantile(*args, **kwargs):
if ('q' not in kwargs) or ((kwargs['q'] != 1.) and (kwargs['q'] != 0.)):
if ('q' not in kwargs) or ((kwargs['q'] > 0.) and (kwargs['q'] < 1.)):
return move_quantile_c(*args, **kwargs)
elif (kwargs['q'] == 1.):
del kwargs['q']
return move_max(*args, **kwargs)
else:
elif (kwargs['q'] == 0.):
del kwargs['q']
return move_min(*args, **kwargs)

Expand Down

0 comments on commit de181da

Please sign in to comment.