diff --git a/doc/whats-new.rst b/doc/whats-new.rst index db8c43d3726..6bfdf0b6f0a 100644 --- a/doc/whats-new.rst +++ b/doc/whats-new.rst @@ -35,6 +35,8 @@ Deprecations Bug fixes ~~~~~~~~~ +- Fix :py:meth:`xr.polyval` with non-system standard integer coeffs (:pull:`7619`). + By `Shreyal Gupta `_ and `Michael Niklas `_. Documentation ~~~~~~~~~~~~~ diff --git a/xarray/core/computation.py b/xarray/core/computation.py index 2305e753cee..9b282d32a45 100644 --- a/xarray/core/computation.py +++ b/xarray/core/computation.py @@ -1968,7 +1968,7 @@ def polyval( raise ValueError( f"Dimension `{degree_dim}` should be a coordinate variable with labels." ) - if not np.issubdtype(coeffs[degree_dim].dtype, int): + if not np.issubdtype(coeffs[degree_dim].dtype, np.integer): raise ValueError( f"Dimension `{degree_dim}` should be of integer dtype. Received {coeffs[degree_dim].dtype} instead." ) diff --git a/xarray/tests/test_computation.py b/xarray/tests/test_computation.py index 8e45a07d6a2..3c10e3f27ab 100644 --- a/xarray/tests/test_computation.py +++ b/xarray/tests/test_computation.py @@ -2092,6 +2092,36 @@ def test_where_attrs() -> None: xr.DataArray([1000.0, 2000.0, 3000.0], dims="x"), id="timedelta", ), + pytest.param( + xr.DataArray([1, 2, 3], dims="x"), + xr.DataArray( + [2, 3, 4], + dims="degree", + coords={"degree": np.array([0, 1, 2], dtype=np.int64)}, + ), + xr.DataArray([9, 2 + 6 + 16, 2 + 9 + 36], dims="x"), + id="int64-degree", + ), + pytest.param( + xr.DataArray([1, 2, 3], dims="x"), + xr.DataArray( + [2, 3, 4], + dims="degree", + coords={"degree": np.array([0, 1, 2], dtype=np.int32)}, + ), + xr.DataArray([9, 2 + 6 + 16, 2 + 9 + 36], dims="x"), + id="int32-degree", + ), + pytest.param( + xr.DataArray([1, 2, 3], dims="x"), + xr.DataArray( + [2, 3, 4], + dims="degree", + coords={"degree": np.array([0, 1, 2], dtype=np.uint8)}, + ), + xr.DataArray([9, 2 + 6 + 16, 2 + 9 + 36], dims="x"), + id="uint8-degree", + ), ], ) def test_polyval(