Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable numbagg in calculation of quantiles #8684

Merged
merged 23 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
c05c28f
Use `numbagg.nanquantile` by default when `method=linear` and `skipna…
maawoo Jan 30, 2024
9ee24ec
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 30, 2024
8351fb2
add `"None"` option to `compute_backend`
maawoo Jan 31, 2024
92bab8e
skip tests when `compute_backend == "numbagg"`
maawoo Jan 31, 2024
3f1aac1
adjust regex pattern to include numbagg error message
maawoo Jan 31, 2024
f424366
skip test if `compute_backend == "numbagg"` and `q == -0.1`
maawoo Jan 31, 2024
b753f0a
Merge remote-tracking branch 'origin/nanquantiles' into nanquantiles
maawoo Jan 31, 2024
91d6be1
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 31, 2024
0e4e06c
test quantile method w/o numbagg backend
maawoo Jan 31, 2024
abc1a90
Merge remote-tracking branch 'origin/nanquantiles' into nanquantiles
maawoo Jan 31, 2024
ebfe30f
change `compute_backend` param `"None"` to `None`
maawoo Feb 1, 2024
9eabd0b
add numbagg `minversion` requirement in `quantile` method
maawoo Feb 1, 2024
dd952e4
align `test_quantile_out_of_bounds` with numbagg>=0.7.2
maawoo Feb 2, 2024
6130c7f
avoid using numbagg on pint arrays; remove exclusion from tests
maawoo Feb 2, 2024
04d9e7f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 2, 2024
cbd4ed7
move numbagg nanquantiles logic to `nputils`-module
maawoo Feb 3, 2024
1a45612
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 3, 2024
857002d
fix logic related to numbagg `nanquantiles`
maawoo Feb 6, 2024
eff2628
Merge branch 'pydata:main' into nanquantiles
maawoo Feb 6, 2024
cea74b2
Merge remote-tracking branch 'origin/nanquantiles' into nanquantiles
maawoo Feb 6, 2024
83bd552
fix logic related to numbagg `nanquantiles`
maawoo Feb 7, 2024
035353e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 7, 2024
18ef827
add `whats-new` entry
maawoo Feb 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")
2 changes: 1 addition & 1 deletion xarray/core/variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -1994,7 +1994,7 @@ def quantile(
method = interpolation

if skipna or (skipna is None and self.dtype.kind in "cfO"):
_quantile_func = np.nanquantile
_quantile_func = nputils.nanquantile
else:
_quantile_func = np.quantile

Expand Down
6 changes: 4 additions & 2 deletions xarray/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ def backend(request):
return request.param


@pytest.fixture(params=["numbagg", "bottleneck"])
@pytest.fixture(params=["numbagg", "bottleneck", None])
def compute_backend(request):
if request.param == "bottleneck":
if request.param is None:
options = dict(use_bottleneck=False, use_numbagg=False)
elif request.param == "bottleneck":
options = dict(use_bottleneck=True, use_numbagg=False)
elif request.param == "numbagg":
options = dict(use_bottleneck=False, use_numbagg=True)
Expand Down
3 changes: 2 additions & 1 deletion xarray/tests/test_dataarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -2889,12 +2889,13 @@
with pytest.raises(TypeError):
orig.mean(out=np.ones(orig.shape))

@pytest.mark.parametrize("compute_backend", ["numbagg", None], indirect=True)
@pytest.mark.parametrize("skipna", [True, False, None])
@pytest.mark.parametrize("q", [0.25, [0.50], [0.25, 0.75]])
@pytest.mark.parametrize(
"axis, dim", zip([None, 0, [0], [0, 1]], [None, "x", ["x"], ["x", "y"]])
)
def test_quantile(self, q, axis, dim, skipna) -> None:
def test_quantile(self, q, axis, dim, skipna, compute_backend) -> None:
va = self.va.copy(deep=True)
va[0, 0] = np.nan

Expand All @@ -2912,7 +2913,7 @@
@pytest.mark.parametrize("method", ["midpoint", "lower"])
def test_quantile_method(self, method) -> None:
q = [0.25, 0.5, 0.75]
actual = DataArray(self.va).quantile(q, method=method)

Check failure on line 2916 in xarray/tests/test_dataarray.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.10 all-but-dask

TestDataArray.test_quantile_method[midpoint] numpy.exceptions.AxisError: source: axis 0 is out of bounds for array of dimension 0

Check failure on line 2916 in xarray/tests/test_dataarray.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.10 all-but-dask

TestDataArray.test_quantile_method[lower] numpy.exceptions.AxisError: source: axis 0 is out of bounds for array of dimension 0

Check failure on line 2916 in xarray/tests/test_dataarray.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.9

TestDataArray.test_quantile_method[midpoint] numpy.exceptions.AxisError: source: axis 0 is out of bounds for array of dimension 0

Check failure on line 2916 in xarray/tests/test_dataarray.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.9

TestDataArray.test_quantile_method[lower] numpy.exceptions.AxisError: source: axis 0 is out of bounds for array of dimension 0

Check failure on line 2916 in xarray/tests/test_dataarray.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.10 flaky

TestDataArray.test_quantile_method[midpoint] numpy.exceptions.AxisError: source: axis 0 is out of bounds for array of dimension 0

Check failure on line 2916 in xarray/tests/test_dataarray.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.10 flaky

TestDataArray.test_quantile_method[lower] numpy.exceptions.AxisError: source: axis 0 is out of bounds for array of dimension 0

Check failure on line 2916 in xarray/tests/test_dataarray.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.11

TestDataArray.test_quantile_method[midpoint] numpy.exceptions.AxisError: source: axis 0 is out of bounds for array of dimension 0

Check failure on line 2916 in xarray/tests/test_dataarray.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.11

TestDataArray.test_quantile_method[lower] numpy.exceptions.AxisError: source: axis 0 is out of bounds for array of dimension 0

Check failure on line 2916 in xarray/tests/test_dataarray.py

View workflow job for this annotation

GitHub Actions / macos-latest py3.9

TestDataArray.test_quantile_method[midpoint] numpy.exceptions.AxisError: source: axis 0 is out of bounds for array of dimension 0

Check failure on line 2916 in xarray/tests/test_dataarray.py

View workflow job for this annotation

GitHub Actions / macos-latest py3.9

TestDataArray.test_quantile_method[lower] numpy.exceptions.AxisError: source: axis 0 is out of bounds for array of dimension 0

Check failure on line 2916 in xarray/tests/test_dataarray.py

View workflow job for this annotation

GitHub Actions / macos-latest py3.11

TestDataArray.test_quantile_method[midpoint] numpy.exceptions.AxisError: source: axis 0 is out of bounds for array of dimension 0

Check failure on line 2916 in xarray/tests/test_dataarray.py

View workflow job for this annotation

GitHub Actions / macos-latest py3.11

TestDataArray.test_quantile_method[lower] numpy.exceptions.AxisError: source: axis 0 is out of bounds for array of dimension 0

expected = np.nanquantile(self.dv.values, np.array(q), method=method)

Expand All @@ -2927,7 +2928,7 @@
FutureWarning,
match="`interpolation` argument to quantile was renamed to `method`",
):
actual = da.quantile(q, interpolation=method)

Check failure on line 2931 in xarray/tests/test_dataarray.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.10 all-but-dask

TestDataArray.test_quantile_interpolation_deprecated[midpoint] numpy.exceptions.AxisError: source: axis 0 is out of bounds for array of dimension 0

Check failure on line 2931 in xarray/tests/test_dataarray.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.10 all-but-dask

TestDataArray.test_quantile_interpolation_deprecated[lower] numpy.exceptions.AxisError: source: axis 0 is out of bounds for array of dimension 0

Check failure on line 2931 in xarray/tests/test_dataarray.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.9

TestDataArray.test_quantile_interpolation_deprecated[midpoint] numpy.exceptions.AxisError: source: axis 0 is out of bounds for array of dimension 0

Check failure on line 2931 in xarray/tests/test_dataarray.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.9

TestDataArray.test_quantile_interpolation_deprecated[lower] numpy.exceptions.AxisError: source: axis 0 is out of bounds for array of dimension 0

Check failure on line 2931 in xarray/tests/test_dataarray.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.10 flaky

TestDataArray.test_quantile_interpolation_deprecated[midpoint] numpy.exceptions.AxisError: source: axis 0 is out of bounds for array of dimension 0

Check failure on line 2931 in xarray/tests/test_dataarray.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.10 flaky

TestDataArray.test_quantile_interpolation_deprecated[lower] numpy.exceptions.AxisError: source: axis 0 is out of bounds for array of dimension 0

Check failure on line 2931 in xarray/tests/test_dataarray.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.11

TestDataArray.test_quantile_interpolation_deprecated[midpoint] numpy.exceptions.AxisError: source: axis 0 is out of bounds for array of dimension 0

Check failure on line 2931 in xarray/tests/test_dataarray.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.11

TestDataArray.test_quantile_interpolation_deprecated[lower] numpy.exceptions.AxisError: source: axis 0 is out of bounds for array of dimension 0

Check failure on line 2931 in xarray/tests/test_dataarray.py

View workflow job for this annotation

GitHub Actions / macos-latest py3.9

TestDataArray.test_quantile_interpolation_deprecated[midpoint] numpy.exceptions.AxisError: source: axis 0 is out of bounds for array of dimension 0

Check failure on line 2931 in xarray/tests/test_dataarray.py

View workflow job for this annotation

GitHub Actions / macos-latest py3.9

TestDataArray.test_quantile_interpolation_deprecated[lower] numpy.exceptions.AxisError: source: axis 0 is out of bounds for array of dimension 0

Check failure on line 2931 in xarray/tests/test_dataarray.py

View workflow job for this annotation

GitHub Actions / macos-latest py3.11

TestDataArray.test_quantile_interpolation_deprecated[midpoint] numpy.exceptions.AxisError: source: axis 0 is out of bounds for array of dimension 0

Check failure on line 2931 in xarray/tests/test_dataarray.py

View workflow job for this annotation

GitHub Actions / macos-latest py3.11

TestDataArray.test_quantile_interpolation_deprecated[lower] numpy.exceptions.AxisError: source: axis 0 is out of bounds for array of dimension 0

expected = da.quantile(q, method=method)

Expand Down
6 changes: 4 additions & 2 deletions xarray/tests/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -5616,9 +5616,10 @@
)
assert_identical(expected, actual)

@pytest.mark.parametrize("compute_backend", ["numbagg", None], indirect=True)
@pytest.mark.parametrize("skipna", [True, False, None])
@pytest.mark.parametrize("q", [0.25, [0.50], [0.25, 0.75]])
def test_quantile(self, q, skipna) -> None:
def test_quantile(self, q, skipna, compute_backend) -> None:
ds = create_test_data(seed=123)
ds.var1.data[0, 0] = np.nan

Expand All @@ -5639,8 +5640,9 @@
assert "dim3" in ds_quantile.dims
assert all(d not in ds_quantile.dims for d in dim)

@pytest.mark.parametrize("compute_backend", ["numbagg", None], indirect=True)
@pytest.mark.parametrize("skipna", [True, False])
def test_quantile_skipna(self, skipna) -> None:
def test_quantile_skipna(self, skipna, compute_backend) -> None:
q = 0.1
dim = "time"
ds = Dataset({"a": ([dim], np.arange(0, 11))})
Expand All @@ -5655,7 +5657,7 @@
@pytest.mark.parametrize("method", ["midpoint", "lower"])
def test_quantile_method(self, method) -> None:
ds = create_test_data(seed=123)
q = [0.25, 0.5, 0.75]

Check failure on line 5660 in xarray/tests/test_dataset.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.10 all-but-dask

TestDataset.test_quantile_method[midpoint] numpy.exceptions.AxisError: source: axis 0 is out of bounds for array of dimension 0

Check failure on line 5660 in xarray/tests/test_dataset.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.10 all-but-dask

TestDataset.test_quantile_method[lower] numpy.exceptions.AxisError: source: axis 0 is out of bounds for array of dimension 0

Check failure on line 5660 in xarray/tests/test_dataset.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.9

TestDataset.test_quantile_method[midpoint] numpy.exceptions.AxisError: source: axis 0 is out of bounds for array of dimension 0

Check failure on line 5660 in xarray/tests/test_dataset.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.9

TestDataset.test_quantile_method[lower] numpy.exceptions.AxisError: source: axis 0 is out of bounds for array of dimension 0

Check failure on line 5660 in xarray/tests/test_dataset.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.10 flaky

TestDataset.test_quantile_method[midpoint] numpy.exceptions.AxisError: source: axis 0 is out of bounds for array of dimension 0

Check failure on line 5660 in xarray/tests/test_dataset.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.10 flaky

TestDataset.test_quantile_method[lower] numpy.exceptions.AxisError: source: axis 0 is out of bounds for array of dimension 0

Check failure on line 5660 in xarray/tests/test_dataset.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.11

TestDataset.test_quantile_method[midpoint] numpy.exceptions.AxisError: source: axis 0 is out of bounds for array of dimension 0

Check failure on line 5660 in xarray/tests/test_dataset.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.11

TestDataset.test_quantile_method[lower] numpy.exceptions.AxisError: source: axis 0 is out of bounds for array of dimension 0

Check failure on line 5660 in xarray/tests/test_dataset.py

View workflow job for this annotation

GitHub Actions / macos-latest py3.9

TestDataset.test_quantile_method[midpoint] numpy.exceptions.AxisError: source: axis 0 is out of bounds for array of dimension 0

Check failure on line 5660 in xarray/tests/test_dataset.py

View workflow job for this annotation

GitHub Actions / macos-latest py3.9

TestDataset.test_quantile_method[lower] numpy.exceptions.AxisError: source: axis 0 is out of bounds for array of dimension 0

Check failure on line 5660 in xarray/tests/test_dataset.py

View workflow job for this annotation

GitHub Actions / macos-latest py3.11

TestDataset.test_quantile_method[midpoint] numpy.exceptions.AxisError: source: axis 0 is out of bounds for array of dimension 0

Check failure on line 5660 in xarray/tests/test_dataset.py

View workflow job for this annotation

GitHub Actions / macos-latest py3.11

TestDataset.test_quantile_method[lower] numpy.exceptions.AxisError: source: axis 0 is out of bounds for array of dimension 0

result = ds.quantile(q, method=method)

Expand All @@ -5667,7 +5669,7 @@
def test_quantile_interpolation_deprecated(self, method) -> None:
ds = create_test_data(seed=123)
q = [0.25, 0.5, 0.75]

Check failure on line 5672 in xarray/tests/test_dataset.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.10 all-but-dask

TestDataset.test_quantile_interpolation_deprecated[midpoint] numpy.exceptions.AxisError: source: axis 0 is out of bounds for array of dimension 0

Check failure on line 5672 in xarray/tests/test_dataset.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.10 all-but-dask

TestDataset.test_quantile_interpolation_deprecated[lower] numpy.exceptions.AxisError: source: axis 0 is out of bounds for array of dimension 0

Check failure on line 5672 in xarray/tests/test_dataset.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.9

TestDataset.test_quantile_interpolation_deprecated[midpoint] numpy.exceptions.AxisError: source: axis 0 is out of bounds for array of dimension 0

Check failure on line 5672 in xarray/tests/test_dataset.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.9

TestDataset.test_quantile_interpolation_deprecated[lower] numpy.exceptions.AxisError: source: axis 0 is out of bounds for array of dimension 0

Check failure on line 5672 in xarray/tests/test_dataset.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.10 flaky

TestDataset.test_quantile_interpolation_deprecated[midpoint] numpy.exceptions.AxisError: source: axis 0 is out of bounds for array of dimension 0

Check failure on line 5672 in xarray/tests/test_dataset.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.10 flaky

TestDataset.test_quantile_interpolation_deprecated[lower] numpy.exceptions.AxisError: source: axis 0 is out of bounds for array of dimension 0

Check failure on line 5672 in xarray/tests/test_dataset.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.11

TestDataset.test_quantile_interpolation_deprecated[midpoint] numpy.exceptions.AxisError: source: axis 0 is out of bounds for array of dimension 0

Check failure on line 5672 in xarray/tests/test_dataset.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.11

TestDataset.test_quantile_interpolation_deprecated[lower] numpy.exceptions.AxisError: source: axis 0 is out of bounds for array of dimension 0

Check failure on line 5672 in xarray/tests/test_dataset.py

View workflow job for this annotation

GitHub Actions / macos-latest py3.9

TestDataset.test_quantile_interpolation_deprecated[midpoint] numpy.exceptions.AxisError: source: axis 0 is out of bounds for array of dimension 0

Check failure on line 5672 in xarray/tests/test_dataset.py

View workflow job for this annotation

GitHub Actions / macos-latest py3.9

TestDataset.test_quantile_interpolation_deprecated[lower] numpy.exceptions.AxisError: source: axis 0 is out of bounds for array of dimension 0

Check failure on line 5672 in xarray/tests/test_dataset.py

View workflow job for this annotation

GitHub Actions / macos-latest py3.11

TestDataset.test_quantile_interpolation_deprecated[midpoint] numpy.exceptions.AxisError: source: axis 0 is out of bounds for array of dimension 0

Check failure on line 5672 in xarray/tests/test_dataset.py

View workflow job for this annotation

GitHub Actions / macos-latest py3.11

TestDataset.test_quantile_interpolation_deprecated[lower] numpy.exceptions.AxisError: source: axis 0 is out of bounds for array of dimension 0
with warnings.catch_warnings(record=True) as w:
ds.quantile(q, interpolation=method)

Expand Down
15 changes: 10 additions & 5 deletions xarray/tests/test_units.py
Original file line number Diff line number Diff line change
Expand Up @@ -2004,6 +2004,7 @@ def test_squeeze(self, dim, dtype):
assert_units_equal(expected, actual)
assert_identical(expected, actual)

@pytest.mark.parametrize("compute_backend", ["numbagg", None], indirect=True)
@pytest.mark.parametrize(
"func",
(
Expand All @@ -2025,7 +2026,7 @@ def test_squeeze(self, dim, dtype):
),
ids=repr,
)
def test_computation(self, func, dtype):
def test_computation(self, func, dtype, compute_backend):
base_unit = unit_registry.m
array = np.linspace(0, 5, 5 * 10).reshape(5, 10).astype(dtype) * base_unit
variable = xr.Variable(("x", "y"), array)
Expand Down Expand Up @@ -3757,6 +3758,7 @@ def test_differentiate_integrate(self, func, variant, dtype):
assert_units_equal(expected, actual)
assert_identical(expected, actual)

@pytest.mark.parametrize("compute_backend", ["numbagg", None], indirect=True)
@pytest.mark.parametrize(
"variant",
(
Expand All @@ -3777,7 +3779,7 @@ def test_differentiate_integrate(self, func, variant, dtype):
),
ids=repr,
)
def test_computation(self, func, variant, dtype):
def test_computation(self, func, variant, dtype, compute_backend):
unit = unit_registry.m

variants = {
Expand Down Expand Up @@ -3883,6 +3885,7 @@ def test_resample(self, dtype):
assert_units_equal(expected, actual)
assert_identical(expected, actual)

@pytest.mark.parametrize("compute_backend", ["numbagg", None], indirect=True)
@pytest.mark.parametrize(
"variant",
(
Expand All @@ -3903,7 +3906,7 @@ def test_resample(self, dtype):
),
ids=repr,
)
def test_grouped_operations(self, func, variant, dtype):
def test_grouped_operations(self, func, variant, dtype, compute_backend):
unit = unit_registry.m

variants = {
Expand Down Expand Up @@ -5240,6 +5243,7 @@ def test_interp_reindex_like_indexing(self, func, unit, error, dtype):
assert_units_equal(expected, actual)
assert_equal(expected, actual)

@pytest.mark.parametrize("compute_backend", ["numbagg", None], indirect=True)
@pytest.mark.parametrize(
"func",
(
Expand All @@ -5262,7 +5266,7 @@ def test_interp_reindex_like_indexing(self, func, unit, error, dtype):
"coords",
),
)
def test_computation(self, func, variant, dtype):
def test_computation(self, func, variant, dtype, compute_backend):
variants = {
"data": ((unit_registry.degK, unit_registry.Pa), 1, 1),
"dims": ((1, 1), unit_registry.m, 1),
Expand Down Expand Up @@ -5394,6 +5398,7 @@ def test_resample(self, variant, dtype):
assert_units_equal(expected, actual)
assert_equal(expected, actual)

@pytest.mark.parametrize("compute_backend", ["numbagg", None], indirect=True)
@pytest.mark.parametrize(
"func",
(
Expand All @@ -5415,7 +5420,7 @@ def test_resample(self, variant, dtype):
"coords",
),
)
def test_grouped_operations(self, func, variant, dtype):
def test_grouped_operations(self, func, variant, dtype, compute_backend):
variants = {
"data": ((unit_registry.degK, unit_registry.Pa), 1, 1),
"dims": ((1, 1), unit_registry.m, 1),
Expand Down
6 changes: 4 additions & 2 deletions xarray/tests/test_variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -1806,14 +1806,14 @@
v = v.chunk({"x": 2})

q = np.array([0.25, 0.5, 0.75])
actual = v.quantile(q, dim="y", method=method)

Check failure on line 1809 in xarray/tests/test_variable.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.10 all-but-dask

TestVariable.test_quantile_method[False-midpoint] numpy.exceptions.AxisError: source: axis 0 is out of bounds for array of dimension 0

Check failure on line 1809 in xarray/tests/test_variable.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.10 all-but-dask

TestVariable.test_quantile_method[False-lower] numpy.exceptions.AxisError: source: axis 0 is out of bounds for array of dimension 0

expected = np.nanquantile(self.d, q, axis=1, method=method)

if use_dask:
assert isinstance(actual.data, dask_array_type)

np.testing.assert_allclose(actual.values, expected)

Check failure on line 1816 in xarray/tests/test_variable.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.9

TestVariable.test_quantile_method[True-midpoint] numpy.exceptions.AxisError: source: axis 0 is out of bounds for array of dimension 0

Check failure on line 1816 in xarray/tests/test_variable.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.9

TestVariable.test_quantile_method[True-lower] numpy.exceptions.AxisError: source: axis 0 is out of bounds for array of dimension 0

Check failure on line 1816 in xarray/tests/test_variable.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.10 flaky

TestVariable.test_quantile_method[True-midpoint] numpy.exceptions.AxisError: source: axis 0 is out of bounds for array of dimension 0

Check failure on line 1816 in xarray/tests/test_variable.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.10 flaky

TestVariable.test_quantile_method[True-lower] numpy.exceptions.AxisError: source: axis 0 is out of bounds for array of dimension 0

Check failure on line 1816 in xarray/tests/test_variable.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.11

TestVariable.test_quantile_method[True-midpoint] numpy.exceptions.AxisError: source: axis 0 is out of bounds for array of dimension 0

Check failure on line 1816 in xarray/tests/test_variable.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.11

TestVariable.test_quantile_method[True-lower] numpy.exceptions.AxisError: source: axis 0 is out of bounds for array of dimension 0

Check failure on line 1816 in xarray/tests/test_variable.py

View workflow job for this annotation

GitHub Actions / macos-latest py3.9

TestVariable.test_quantile_method[True-midpoint] numpy.exceptions.AxisError: source: axis 0 is out of bounds for array of dimension 0

Check failure on line 1816 in xarray/tests/test_variable.py

View workflow job for this annotation

GitHub Actions / macos-latest py3.9

TestVariable.test_quantile_method[True-lower] numpy.exceptions.AxisError: source: axis 0 is out of bounds for array of dimension 0

Check failure on line 1816 in xarray/tests/test_variable.py

View workflow job for this annotation

GitHub Actions / macos-latest py3.11

TestVariable.test_quantile_method[True-midpoint] numpy.exceptions.AxisError: source: axis 0 is out of bounds for array of dimension 0

Check failure on line 1816 in xarray/tests/test_variable.py

View workflow job for this annotation

GitHub Actions / macos-latest py3.11

TestVariable.test_quantile_method[True-lower] numpy.exceptions.AxisError: source: axis 0 is out of bounds for array of dimension 0

@pytest.mark.parametrize("method", ["midpoint", "lower"])
def test_quantile_interpolation_deprecation(self, method) -> None:
Expand Down Expand Up @@ -1842,13 +1842,15 @@
with pytest.raises(ValueError, match=r"consists of multiple chunks"):
v.quantile(0.5, dim="x")

@pytest.mark.parametrize("compute_backend", ["numbagg", None], indirect=True)
@pytest.mark.parametrize("q", [-0.1, 1.1, [2], [0.25, 2]])
def test_quantile_out_of_bounds(self, q):
def test_quantile_out_of_bounds(self, q, compute_backend):
v = Variable(["x", "y"], self.d)

# escape special characters
with pytest.raises(
ValueError, match=r"Quantiles must be in the range \[0, 1\]"
ValueError,
match=r"(Q|q)uantiles must be in the range \[0, 1\]",
):
v.quantile(q, dim="x")

Expand Down
Loading