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

don't use issubdtype to check for integer dtypes in polyval #7619

Merged
merged 9 commits into from
Mar 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ Deprecations
Bug fixes
~~~~~~~~~

- Fix :py:meth:`xr.polyval` with non-system standard integer coeffs (:pull:`7619`).
By `Shreyal Gupta <https://github.com/Ravenin7>`_ and `Michael Niklas <https://github.com/headtr1ck>`_.

Documentation
~~~~~~~~~~~~~
Expand Down
2 changes: 1 addition & 1 deletion xarray/core/computation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."
)
Expand Down
30 changes: 30 additions & 0 deletions xarray/tests/test_computation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down