Skip to content

Commit

Permalink
Fix reductions for np.complex_ dtypes with numbagg (#9210)
Browse files Browse the repository at this point in the history
max-sixty authored Jul 7, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 52a7371 commit 971d71d
Showing 3 changed files with 12 additions and 1 deletion.
3 changes: 3 additions & 0 deletions doc/whats-new.rst
Original file line number Diff line number Diff line change
@@ -49,6 +49,9 @@ Bug fixes
By `Michael Niklas <https://github.com/headtr1ck>`_.
- Dark themes are now properly detected for ``html[data-theme=dark]``-tags (:pull:`9200`).
By `Dieter Werthmüller <https://github.com/prisae>`_.
- Reductions no longer fail for ``np.complex_`` dtype arrays when numbagg is
installed.
By `Maximilian Roos <https://github.com/max-sixty>`_

Documentation
~~~~~~~~~~~~~
2 changes: 1 addition & 1 deletion xarray/core/nputils.py
Original file line number Diff line number Diff line change
@@ -191,7 +191,7 @@ def f(values, axis=None, **kwargs):
or kwargs.get("ddof", 0) == 1
)
# TODO: bool?
and values.dtype.kind in "uifc"
and values.dtype.kind in "uif"
# and values.dtype.isnative
and (dtype is None or np.dtype(dtype) == values.dtype)
# numbagg.nanquantile only available after 0.8.0 and with linear method
8 changes: 8 additions & 0 deletions xarray/tests/test_computation.py
Original file line number Diff line number Diff line change
@@ -2598,3 +2598,11 @@ def test_cross(a, b, ae, be, dim: str, axis: int, use_dask: bool) -> None:

actual = xr.cross(a, b, dim=dim)
xr.testing.assert_duckarray_allclose(expected, actual)


@pytest.mark.parametrize("compute_backend", ["numbagg"], indirect=True)
def test_complex_number_reduce(compute_backend):
da = xr.DataArray(np.ones((2,), dtype=np.complex_), dims=["x"])
# Check that xarray doesn't call into numbagg, which doesn't compile for complex
# numbers at the moment (but will when numba supports dynamic compilation)
da.min()

0 comments on commit 971d71d

Please sign in to comment.