Skip to content

Commit

Permalink
move numbagg nanquantiles logic to nputils-module
Browse files Browse the repository at this point in the history
  • Loading branch information
maawoo committed Feb 3, 2024
1 parent 04d9e7f commit cbd4ed7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 17 deletions.
6 changes: 6 additions & 0 deletions xarray/core/nputils.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,11 @@ def f(values, axis=None, **kwargs):
# to ddof=1 above.
if pycompat.mod_version("numbagg") < Version("0.7.0"):
kwargs.pop("ddof", None)
if name == "nanquantile":
if kwargs.get("method", None) != "linear":
return
kwargs["quantiles"] = kwargs.pop("q")
kwargs.pop("method", None)
return nba_func(values, axis=axis, **kwargs)
if (
_BOTTLENECK_AVAILABLE
Expand Down Expand Up @@ -285,3 +290,4 @@ def least_squares(lhs, rhs, rcond=None, skipna=False):
nancumprod = _create_method("nancumprod")
nanargmin = _create_method("nanargmin")
nanargmax = _create_method("nanargmax")
nanquantile = _create_method("nanquantile")
19 changes: 2 additions & 17 deletions xarray/core/variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -1995,20 +1995,8 @@ def quantile(

method = interpolation

using_numbagg = False
if skipna or (skipna is None and self.dtype.kind in "cfO"):
if (
module_available("numbagg", minversion="0.5.1")
and OPTIONS["use_numbagg"] is True
and method == "linear"
and not isinstance(self.data, array_type("pint"))
):
import numbagg

_quantile_func = numbagg.nanquantile
using_numbagg = True
else:
_quantile_func = np.nanquantile
_quantile_func = nputils.nanquantile
else:
_quantile_func = np.quantile

Expand All @@ -2030,10 +2018,7 @@ def _wrapper(npa, **kwargs):

axis = np.arange(-1, -1 * len(dim) - 1, -1)

if using_numbagg:
kwargs = {"quantiles": q, "axis": axis}
else:
kwargs = {"q": q, "axis": axis, "method": method}
kwargs = {"q": q, "axis": axis, "method": method}

result = apply_ufunc(
_wrapper,
Expand Down

0 comments on commit cbd4ed7

Please sign in to comment.