Skip to content

Commit 971d71d

Browse files
authored
Fix reductions for np.complex_ dtypes with numbagg (#9210)
1 parent 52a7371 commit 971d71d

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

doc/whats-new.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ Bug fixes
4949
By `Michael Niklas <https://github.com/headtr1ck>`_.
5050
- Dark themes are now properly detected for ``html[data-theme=dark]``-tags (:pull:`9200`).
5151
By `Dieter Werthmüller <https://github.com/prisae>`_.
52+
- Reductions no longer fail for ``np.complex_`` dtype arrays when numbagg is
53+
installed.
54+
By `Maximilian Roos <https://github.com/max-sixty>`_
5255

5356
Documentation
5457
~~~~~~~~~~~~~

xarray/core/nputils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ def f(values, axis=None, **kwargs):
191191
or kwargs.get("ddof", 0) == 1
192192
)
193193
# TODO: bool?
194-
and values.dtype.kind in "uifc"
194+
and values.dtype.kind in "uif"
195195
# and values.dtype.isnative
196196
and (dtype is None or np.dtype(dtype) == values.dtype)
197197
# numbagg.nanquantile only available after 0.8.0 and with linear method

xarray/tests/test_computation.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2598,3 +2598,11 @@ def test_cross(a, b, ae, be, dim: str, axis: int, use_dask: bool) -> None:
25982598

25992599
actual = xr.cross(a, b, dim=dim)
26002600
xr.testing.assert_duckarray_allclose(expected, actual)
2601+
2602+
2603+
@pytest.mark.parametrize("compute_backend", ["numbagg"], indirect=True)
2604+
def test_complex_number_reduce(compute_backend):
2605+
da = xr.DataArray(np.ones((2,), dtype=np.complex_), dims=["x"])
2606+
# Check that xarray doesn't call into numbagg, which doesn't compile for complex
2607+
# numbers at the moment (but will when numba supports dynamic compilation)
2608+
da.min()

0 commit comments

Comments
 (0)