From a5158e8ea27e1ca4e5525e76f4de8306bd3641a8 Mon Sep 17 00:00:00 2001 From: Pontus Lurcock Date: Mon, 24 Jun 2024 16:03:48 +0200 Subject: [PATCH 1/7] Change np.core.defchararray to np.char.chararray (#9165) 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. --- xarray/testing/assertions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xarray/testing/assertions.py b/xarray/testing/assertions.py index 69885868f83..02cbba6092f 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.chararray.decode(data, "utf-8", "replace") return data From 5f63d958712517d7aff8ea70a902b75669059aea Mon Sep 17 00:00:00 2001 From: Pontus Lurcock Date: Tue, 25 Jun 2024 18:21:05 +0200 Subject: [PATCH 2/7] Add test for assert_allclose on dtype S (#9165) --- xarray/tests/test_assertions.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/xarray/tests/test_assertions.py b/xarray/tests/test_assertions.py index aa0ea46f7db..099990334c1 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_dtypeS", + ), ), ) def test_assert_allclose(obj1, obj2) -> None: From 08dcff23c8885519c798648e854de5f3e34917d1 Mon Sep 17 00:00:00 2001 From: Pontus Lurcock Date: Tue, 25 Jun 2024 18:23:46 +0200 Subject: [PATCH 3/7] Use np.char.decode, not np.char.chararray.decode ... in assertions._decode_string_data. See #9166. --- xarray/testing/assertions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xarray/testing/assertions.py b/xarray/testing/assertions.py index 02cbba6092f..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.char.chararray.decode(data, "utf-8", "replace") + return np.char.decode(data, "utf-8", "replace") return data From dbe95c4b98e790b190b1ca90c9c7a4ed090ac2b5 Mon Sep 17 00:00:00 2001 From: Pontus Lurcock Date: Tue, 25 Jun 2024 18:33:47 +0200 Subject: [PATCH 4/7] List #9165 fix in whats-new.rst --- doc/whats-new.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/whats-new.rst b/doc/whats-new.rst index 51a2c98fb9c..ffb56ea8018 100644 --- a/doc/whats-new.rst +++ b/doc/whats-new.rst @@ -35,6 +35,8 @@ Deprecations Bug fixes ~~~~~~~~~ +- Make `testing.assert_allclose` work with numpy 2.0 (:issue:`9165`, :pull:`9166`). + By `Pontus Lurcock `_ Documentation From 4086acf74c987470589ef7831543cae56586fa2a Mon Sep 17 00:00:00 2001 From: Justus Magin Date: Tue, 25 Jun 2024 19:25:55 +0200 Subject: [PATCH 5/7] cross-like the fixed function --- doc/whats-new.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/whats-new.rst b/doc/whats-new.rst index fc7b888e187..dccd1247d00 100644 --- a/doc/whats-new.rst +++ b/doc/whats-new.rst @@ -35,7 +35,7 @@ Deprecations Bug fixes ~~~~~~~~~ -- Make `testing.assert_allclose` work with numpy 2.0 (:issue:`9165`, :pull:`9166`). +- Make :py:func:`testing.assert_allclose` work with numpy 2.0 (:issue:`9165`, :pull:`9166`). By `Pontus Lurcock `_ From cb77fab33637b18ba08cf36cab8642309ef0d969 Mon Sep 17 00:00:00 2001 From: Pontus Lurcock Date: Tue, 25 Jun 2024 22:14:19 +0200 Subject: [PATCH 6/7] Improve a parameter ID in tests.test_assertions Co-authored-by: Justus Magin --- xarray/tests/test_assertions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xarray/tests/test_assertions.py b/xarray/tests/test_assertions.py index 099990334c1..20b5e163662 100644 --- a/xarray/tests/test_assertions.py +++ b/xarray/tests/test_assertions.py @@ -55,7 +55,7 @@ def test_allclose_regression() -> None: pytest.param( xr.DataArray(np.array("a", dtype="|S1")), xr.DataArray(np.array("b", dtype="|S1")), - id="DataArray_dtypeS", + id="DataArray_with_character_dtype", ), ), ) From 11f7c740edc45ce807ec0c92d73452f0cd289c9f Mon Sep 17 00:00:00 2001 From: Justus Magin Date: Wed, 26 Jun 2024 14:42:51 +0200 Subject: [PATCH 7/7] whats-new normalization --- doc/whats-new.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/whats-new.rst b/doc/whats-new.rst index dccd1247d00..97631b4c324 100644 --- a/doc/whats-new.rst +++ b/doc/whats-new.rst @@ -36,7 +36,7 @@ Deprecations Bug fixes ~~~~~~~~~ - Make :py:func:`testing.assert_allclose` work with numpy 2.0 (:issue:`9165`, :pull:`9166`). - By `Pontus Lurcock `_ + By `Pontus Lurcock `_. Documentation