From de181daf28d0c1617058c62846fd330b6f772e97 Mon Sep 17 00:00:00 2001 From: andrii-riazanov Date: Tue, 20 Sep 2022 21:56:16 -0400 Subject: [PATCH] Bench move_quantile(q=0.5) with slow.move_median --- bottleneck/benchmark/bench_detailed.py | 3 ++- bottleneck/slow/move.py | 1 + bottleneck/src/move_quantile.py | 4 ++-- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/bottleneck/benchmark/bench_detailed.py b/bottleneck/benchmark/bench_detailed.py index 4907446414..e3e56a7ce8 100644 --- a/bottleneck/benchmark/bench_detailed.py +++ b/bottleneck/benchmark/bench_detailed.py @@ -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 @@ -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) diff --git a/bottleneck/slow/move.py b/bottleneck/slow/move.py index 30bdcdd815..22a1b03e75 100644 --- a/bottleneck/slow/move.py +++ b/bottleneck/slow/move.py @@ -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" diff --git a/bottleneck/src/move_quantile.py b/bottleneck/src/move_quantile.py index 5a303ad830..53d2a1b86f 100644 --- a/bottleneck/src/move_quantile.py +++ b/bottleneck/src/move_quantile.py @@ -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)