diff --git a/news/numpy2.rst b/news/numpy2.rst new file mode 100644 index 00000000..af1631fa --- /dev/null +++ b/news/numpy2.rst @@ -0,0 +1,23 @@ +**Added:** + +* support for numpy >=2.0 + +**Changed:** + +* + +**Deprecated:** + +* + +**Removed:** + +* + +**Fixed:** + +* element/label itemsize to 5 in _linkAtomAttribute to support numpy >=2.0 + +**Security:** + +* diff --git a/pyproject.toml b/pyproject.toml index e50524b1..206884bf 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [build-system] -requires = ["setuptools>=62.0", "setuptools-git-versioning<2"] +requires = ["setuptools>=62.0", "setuptools-git-versioning>=2.0"] build-backend = "setuptools.build_meta" [project] diff --git a/requirements/run.txt b/requirements/run.txt index 70f81389..5413a934 100644 --- a/requirements/run.txt +++ b/requirements/run.txt @@ -1,2 +1,2 @@ -numpy < 2.0.0 # Need to fix deprecations before 2.0.0 compat +numpy pycifrw diff --git a/src/diffpy/structure/atom.py b/src/diffpy/structure/atom.py index 9693b812..e531780b 100644 --- a/src/diffpy/structure/atom.py +++ b/src/diffpy/structure/atom.py @@ -536,7 +536,7 @@ def __setitem__(self, idx, value): self._atom.xyz[:] = self._atom.lattice.fractional(self) return - def __array_wrap__(self, out_arr, context=None): + def __array_wrap__(self, out_arr, context=None, return_scalar=None): """Ensure math operations on this type yield standard numpy array.""" return out_arr.view(numpy.ndarray) diff --git a/src/diffpy/structure/structure.py b/src/diffpy/structure/structure.py index 5bebf4eb..f0cb515c 100644 --- a/src/diffpy/structure/structure.py +++ b/src/diffpy/structure/structure.py @@ -711,8 +711,9 @@ def _get_composition(self): element = _linkAtomAttribute( "element", """Character array of `Atom` types. Assignment updates - the element attribute of the respective `Atoms`.""", - toarray=numpy.char.array, + the element attribute of the respective `Atoms`. + Set the maximum length of the element string to 5 characters.""", + toarray=lambda items: numpy.char.array(items, itemsize=5), ) xyz = _linkAtomAttribute( @@ -742,8 +743,9 @@ def _get_composition(self): label = _linkAtomAttribute( "label", """Character array of `Atom` names. Assignment updates - the label attribute of all `Atoms`.""", - toarray=numpy.char.array, + the label attribute of all `Atoms`. + Set the maximum length of the label string to 5 characters.""", + toarray=lambda items: numpy.char.array(items, itemsize=5), ) occupancy = _linkAtomAttribute(