diff --git a/doc/whats-new.rst b/doc/whats-new.rst index c3383a5648a..97631b4c324 100644 --- a/doc/whats-new.rst +++ b/doc/whats-new.rst @@ -35,6 +35,8 @@ Deprecations Bug fixes ~~~~~~~~~ +- Make :py:func:`testing.assert_allclose` work with numpy 2.0 (:issue:`9165`, :pull:`9166`). + By `Pontus Lurcock `_. Documentation diff --git a/xarray/testing/assertions.py b/xarray/testing/assertions.py index 69885868f83..2a4c17e115a 100644 --- a/xarray/testing/assertions.py +++ b/xarray/testing/assertions.py @@ -36,7 +36,7 @@ def wrapper(*args, **kwargs): def _decode_string_data(data): if data.dtype.kind == "S": - return np.core.defchararray.decode(data, "utf-8", "replace") + return np.char.decode(data, "utf-8", "replace") return data diff --git a/xarray/tests/test_assertions.py b/xarray/tests/test_assertions.py index aa0ea46f7db..20b5e163662 100644 --- a/xarray/tests/test_assertions.py +++ b/xarray/tests/test_assertions.py @@ -52,6 +52,11 @@ def test_allclose_regression() -> None: xr.Dataset({"a": ("x", [0, 2]), "b": ("y", [0, 1])}), id="Dataset", ), + pytest.param( + xr.DataArray(np.array("a", dtype="|S1")), + xr.DataArray(np.array("b", dtype="|S1")), + id="DataArray_with_character_dtype", + ), ), ) def test_assert_allclose(obj1, obj2) -> None: