From 756be826dc38e5f4b3ca4b7dc992c34aa0cdbde9 Mon Sep 17 00:00:00 2001 From: Sangjoon Bob Lee Date: Sat, 21 Sep 2024 20:23:36 -0400 Subject: [PATCH 1/6] Remove warnings --- pyproject.toml | 2 +- requirements/run.txt | 2 +- src/diffpy/structure/atom.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index e50524b..206884b 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 70f8138..5413a93 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 9693b81..b2af962 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=False): """Ensure math operations on this type yield standard numpy array.""" return out_arr.view(numpy.ndarray) From 65963333017577c8525dd0e662640b524eb7ed63 Mon Sep 17 00:00:00 2001 From: Sangjoon Bob Lee Date: Sat, 21 Sep 2024 20:49:51 -0400 Subject: [PATCH 2/6] Fix lenght to 5 characterse --- src/diffpy/structure/structure.py | 10 ++++++---- src/diffpy/structure/utils.py | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/diffpy/structure/structure.py b/src/diffpy/structure/structure.py index 5bebf4e..fcd1489 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( diff --git a/src/diffpy/structure/utils.py b/src/diffpy/structure/utils.py index e5fa3ce..0feeb5d 100644 --- a/src/diffpy/structure/utils.py +++ b/src/diffpy/structure/utils.py @@ -92,7 +92,7 @@ def _linkAtomAttribute(attrname, doc, toarray=numpy.array): from operator import setitem _all = slice(None) - + def fget(self): va = toarray([getattr(a, attrname) for a in self]) return va From a67e6ac08af2114ba9fbbb6ddee9889945bca82b Mon Sep 17 00:00:00 2001 From: Sangjoon Bob Lee Date: Sat, 21 Sep 2024 20:53:42 -0400 Subject: [PATCH 3/6] Add return_scalar none to array_wrap --- src/diffpy/structure/atom.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/diffpy/structure/atom.py b/src/diffpy/structure/atom.py index b2af962..e531780 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, return_scalar=False): + 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) From dd620e89e08b68ff49c6ca4255824af5abd06ac2 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 22 Sep 2024 00:55:19 +0000 Subject: [PATCH 4/6] [pre-commit.ci] auto fixes from pre-commit hooks --- src/diffpy/structure/structure.py | 4 ++-- src/diffpy/structure/utils.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/diffpy/structure/structure.py b/src/diffpy/structure/structure.py index fcd1489..f0cb515 100644 --- a/src/diffpy/structure/structure.py +++ b/src/diffpy/structure/structure.py @@ -713,7 +713,7 @@ def _get_composition(self): """Character array of `Atom` types. Assignment updates 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) + toarray=lambda items: numpy.char.array(items, itemsize=5), ) xyz = _linkAtomAttribute( @@ -745,7 +745,7 @@ def _get_composition(self): """Character array of `Atom` names. Assignment updates 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) + toarray=lambda items: numpy.char.array(items, itemsize=5), ) occupancy = _linkAtomAttribute( diff --git a/src/diffpy/structure/utils.py b/src/diffpy/structure/utils.py index 0feeb5d..e5fa3ce 100644 --- a/src/diffpy/structure/utils.py +++ b/src/diffpy/structure/utils.py @@ -92,7 +92,7 @@ def _linkAtomAttribute(attrname, doc, toarray=numpy.array): from operator import setitem _all = slice(None) - + def fget(self): va = toarray([getattr(a, attrname) for a in self]) return va From 01d07b239c05f8cc3601187ac1ec8c21efb0537a Mon Sep 17 00:00:00 2001 From: Sangjoon Bob Lee Date: Mon, 23 Sep 2024 08:35:44 -0400 Subject: [PATCH 5/6] Add news for supporting numpy >2.0 --- news/numpy2 | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 news/numpy2 diff --git a/news/numpy2 b/news/numpy2 new file mode 100644 index 0000000..af1631f --- /dev/null +++ b/news/numpy2 @@ -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:** + +* From 32a4a2ef4d3dcc6fd817cc63d5ee64b6ea7e607a Mon Sep 17 00:00:00 2001 From: Sangjoon Bob Lee Date: Mon, 23 Sep 2024 08:46:10 -0400 Subject: [PATCH 6/6] Rename numpy2 to numpy2.rst --- news/{numpy2 => numpy2.rst} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename news/{numpy2 => numpy2.rst} (100%) diff --git a/news/numpy2 b/news/numpy2.rst similarity index 100% rename from news/numpy2 rename to news/numpy2.rst