Skip to content

Commit 1e361cc

Browse files
Ravenin7pre-commit-ci[bot]dcherianTomNicholasheadtr1ck
authored
Allow all integer dtypes in polyval (#7619)
* Fixed unneeded ValueError * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fixed unneeded ValueError * Revert "Merge" This reverts commit 87a82a2, reversing changes made to fb27a96. * add to whats-new * add tests --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: dcherian <[email protected]> Co-authored-by: Tom Nicholas <[email protected]> Co-authored-by: Michael Niklas <[email protected]>
1 parent ed09383 commit 1e361cc

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

doc/whats-new.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ Deprecations
3535
Bug fixes
3636
~~~~~~~~~
3737

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

3941
Documentation
4042
~~~~~~~~~~~~~

xarray/core/computation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1968,7 +1968,7 @@ def polyval(
19681968
raise ValueError(
19691969
f"Dimension `{degree_dim}` should be a coordinate variable with labels."
19701970
)
1971-
if not np.issubdtype(coeffs[degree_dim].dtype, int):
1971+
if not np.issubdtype(coeffs[degree_dim].dtype, np.integer):
19721972
raise ValueError(
19731973
f"Dimension `{degree_dim}` should be of integer dtype. Received {coeffs[degree_dim].dtype} instead."
19741974
)

xarray/tests/test_computation.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2092,6 +2092,36 @@ def test_where_attrs() -> None:
20922092
xr.DataArray([1000.0, 2000.0, 3000.0], dims="x"),
20932093
id="timedelta",
20942094
),
2095+
pytest.param(
2096+
xr.DataArray([1, 2, 3], dims="x"),
2097+
xr.DataArray(
2098+
[2, 3, 4],
2099+
dims="degree",
2100+
coords={"degree": np.array([0, 1, 2], dtype=np.int64)},
2101+
),
2102+
xr.DataArray([9, 2 + 6 + 16, 2 + 9 + 36], dims="x"),
2103+
id="int64-degree",
2104+
),
2105+
pytest.param(
2106+
xr.DataArray([1, 2, 3], dims="x"),
2107+
xr.DataArray(
2108+
[2, 3, 4],
2109+
dims="degree",
2110+
coords={"degree": np.array([0, 1, 2], dtype=np.int32)},
2111+
),
2112+
xr.DataArray([9, 2 + 6 + 16, 2 + 9 + 36], dims="x"),
2113+
id="int32-degree",
2114+
),
2115+
pytest.param(
2116+
xr.DataArray([1, 2, 3], dims="x"),
2117+
xr.DataArray(
2118+
[2, 3, 4],
2119+
dims="degree",
2120+
coords={"degree": np.array([0, 1, 2], dtype=np.uint8)},
2121+
),
2122+
xr.DataArray([9, 2 + 6 + 16, 2 + 9 + 36], dims="x"),
2123+
id="uint8-degree",
2124+
),
20952125
],
20962126
)
20972127
def test_polyval(

0 commit comments

Comments
 (0)