Skip to content

Commit

Permalink
Use ddof in numbagg>=0.7.0
Browse files Browse the repository at this point in the history
  • Loading branch information
max-sixty committed Jan 19, 2024
1 parent 75d0f88 commit 29c9e27
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
14 changes: 10 additions & 4 deletions xarray/core/nputils.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,12 @@ def f(values, axis=None, **kwargs):
and pycompat.mod_version("numbagg") >= Version("0.5.0")
and OPTIONS["use_numbagg"]
and isinstance(values, np.ndarray)
# numbagg uses ddof=1 only, but numpy uses ddof=0 by default
and (("var" in name or "std" in name) and kwargs.get("ddof", 0) == 1)
# numbagg<0.7.0 uses ddof=1 only, but numpy uses ddof=0 by default
and (
pycompat.mod_version("numbagg") >= Version("0.7.0")
or ("var" not in name and "std" not in name)
or kwargs.get("ddof", 0) == 1
)
# TODO: bool?
and values.dtype.kind in "uifc"
# and values.dtype.isnative
Expand All @@ -196,9 +200,11 @@ def f(values, axis=None, **kwargs):

nba_func = getattr(numbagg, name, None)
if nba_func is not None:
# numbagg does not take care dtype, ddof
# numbagg does not use dtype
kwargs.pop("dtype", None)
kwargs.pop("ddof", None)
# prior to 0.7.0, numbagg did not support ddof
if pycompat.mod_version("numbagg") < Version("0.7.0"):
kwargs.pop("ddof", None)
return nba_func(values, axis=axis, **kwargs)
if (
_BOTTLENECK_AVAILABLE
Expand Down
7 changes: 3 additions & 4 deletions xarray/core/rolling.py
Original file line number Diff line number Diff line change
Expand Up @@ -649,11 +649,10 @@ def _array_reduce(
):
import numbagg

# Numbagg has a default ddof of 1. I (@max-sixty) think we should make
# this the default in xarray too, but until we do, don't use numbagg for
# std and var unless ddof is set to 1.
# Numbagg < 0.7.0 always uses ddof=1.
if (
numbagg_move_func not in [numbagg.move_std, numbagg.move_var]
pycompat.mod_version("numbagg") >= Version("0.7.0")
or numbagg_move_func not in [numbagg.move_std, numbagg.move_var]
or kwargs.get("ddof") == 1
):
return self._numbagg_reduce(
Expand Down

0 comments on commit 29c9e27

Please sign in to comment.