-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Change np.core.defchararray to np.char (#9165) #9166
Conversation
Replace a reference to np.core.defchararray with np.char.chararray in xarray.testing.assertions, since the former no longer works on NumPy 2.0.0 and the latter is the "preferred alias" according to NumPy docs. See Issue pydata#9165.
Thank you for opening this pull request! It may take us a few days to respond here, so thank you for being patient. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the fix, @pont-us.
Could you add a test to make sure we don't regress, please? This could be as simple as adding another parameter set to
xarray/xarray/tests/test_assertions.py
Lines 39 to 61 in 872c1c5
@pytest.mark.parametrize( | |
"obj1,obj2", | |
( | |
pytest.param( | |
xr.Variable("x", [1e-17, 2]), xr.Variable("x", [0, 3]), id="Variable" | |
), | |
pytest.param( | |
xr.DataArray([1e-17, 2], dims="x"), | |
xr.DataArray([0, 3], dims="x"), | |
id="DataArray", | |
), | |
pytest.param( | |
xr.Dataset({"a": ("x", [1e-17, 2]), "b": ("y", [-2e-18, 2])}), | |
xr.Dataset({"a": ("x", [0, 2]), "b": ("y", [0, 1])}), | |
id="Dataset", | |
), | |
), | |
) | |
def test_assert_allclose(obj1, obj2) -> None: | |
with pytest.raises(AssertionError): | |
xr.testing.assert_allclose(obj1, obj2) | |
with pytest.raises(AssertionError): | |
xr.testing.assert_allclose(obj1, obj2, check_dim_order=False) |
xarray/xarray/tests/test_assertions.py
Lines 33 to 36 in 872c1c5
def test_allclose_regression() -> None: | |
x = xr.DataArray(1.01) | |
y = xr.DataArray(1.02) | |
xr.testing.assert_allclose(x, y, atol=0.01) |
You might also want to add a note to whats-new.rst
... in assertions._decode_string_data. See pydata#9166.
I didn't think this would qualify as a "notable" bug fix, but glad to oblige :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good to me, just one small nit.
Co-authored-by: Justus Magin <[email protected]>
From a quick look, it appears that the failing Doctests are due to other, unrelated NumPy 2 changes (mainly NEP 51). |
yep, this is also fails on |
Thanks @pont-us (any other changes for numpy 2.0 would be greatly appreciated if you're up for it...) |
just FYI, the doctest / rtd will be fixed by #9177, and the normal CI will be fixed by #9136 (we just need to figure out whether using |
That's awesome, thanks @keewis ! |
Thanks for the help @keewis and thanks for the thanks @max-sixty :). I don't think I'll have time for another PR in the short term, unfortunately, but I plan to at least open issues for one or two other NumPy-2-related surprises that I've come across (if nobody else does first). |
* main: promote floating-point numeric datetimes to 64-bit before decoding (pydata#9182) also pin `numpy` in the all-but-dask CI (pydata#9184) temporarily remove `pydap` from CI (pydata#9183) temporarily pin `numpy<2` (pydata#9181) Change np.core.defchararray to np.char (pydata#9165) (pydata#9166) Fix example code formatting for CachingFileManager (pydata#9178) Slightly improve DataTree repr (pydata#9064) switch to unit `"D"` (pydata#9170) Docs: Add page with figure for navigating help resources (pydata#9147) Add test for pydata#9155 (pydata#9161) Remove mypy exclusions for a couple more libraries (pydata#9160) Include numbagg in type checks (pydata#9159) Improve zarr chunks docs (pydata#9140)
Replace a reference to np.core.defchararray with np.char.chararray in xarray.testing.assertions, since the former no longer works on NumPy 2.0.0 and the latter is the "preferred alias" according to NumPy docs. See Issue #9165.
whats-new.rst