From db0fc0b8ee86e6c8e7445f3ee959ac4342d61973 Mon Sep 17 00:00:00 2001 From: Zach Anderson Date: Fri, 21 Jun 2024 11:17:59 -0500 Subject: [PATCH 1/2] Replaced `np.string_` with `np.bytes_` NumPy v2.0 removed `np.string_` from the API and recommended using `np.bytes_` instead. I checked the other API removals in the NumPy v2.0 change log and didn't see any instances of removed objects in the nexusformat codebase. See https://numpy.org/doc/stable/release/2.0.0-notes.html for more info. --- src/nexusformat/nexus/tree.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/nexusformat/nexus/tree.py b/src/nexusformat/nexus/tree.py index 07dc993..138cb10 100644 --- a/src/nexusformat/nexus/tree.py +++ b/src/nexusformat/nexus/tree.py @@ -1864,7 +1864,7 @@ def __unicode__(self): def __repr__(self): if (self.dtype is not None and (self.shape == () or self.shape == (1,)) and - (self.dtype.type == np.string_ or self.dtype.type == np.str_ or + (self.dtype.type == np.bytes_ or self.dtype.type == np.str_ or self.dtype == string_dtype)): return f"NXattr('{self}')" else: @@ -1898,7 +1898,7 @@ def nxvalue(self): if self._value is None: return '' elif (self.dtype is not None and - (self.dtype.type == np.string_ or self.dtype.type == np.str_ or + (self.dtype.type == np.bytes_ or self.dtype.type == np.str_ or self.dtype == string_dtype)): if self.shape == (): return text(self._value) @@ -3721,7 +3721,7 @@ def nxvalue(self): if _value is None: return None elif (self.dtype is not None and - (self.dtype.type == np.string_ or self.dtype.type == np.str_ or + (self.dtype.type == np.bytes_ or self.dtype.type == np.str_ or self.dtype == string_dtype)): if self.shape == (): return text(_value) From d75e614cbd2297cb2c824ed893ff030650e18a99 Mon Sep 17 00:00:00 2001 From: Zach Anderson Date: Fri, 21 Jun 2024 15:35:27 -0500 Subject: [PATCH 2/2] Update NXfield.__array_wrap__() arguments For NumPy 2.0 compatibility. --- src/nexusformat/nexus/tree.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nexusformat/nexus/tree.py b/src/nexusformat/nexus/tree.py index 138cb10..00c7e3e 100644 --- a/src/nexusformat/nexus/tree.py +++ b/src/nexusformat/nexus/tree.py @@ -3280,7 +3280,7 @@ def __array__(self, *args, **kwargs): """Cast the NXfield as a NumPy array.""" return np.asarray(self.nxdata, *args, **kwargs) - def __array_wrap__(self, value, context=None): + def __array_wrap__(self, value, context=None, return_scalar=False): """Transform the array resulting from a ufunc to an NXfield.""" return NXfield(value, name=self.nxname)