Skip to content

Commit b384a00

Browse files
authored
Merge pull request #102 from bobleesj/numpy
Numpy >=2.0 support with depreciation warning removed
2 parents bfc9b47 + 32a4a2e commit b384a00

File tree

5 files changed

+32
-7
lines changed

5 files changed

+32
-7
lines changed

news/numpy2.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
**Added:**
2+
3+
* support for numpy >=2.0
4+
5+
**Changed:**
6+
7+
* <news item>
8+
9+
**Deprecated:**
10+
11+
* <news item>
12+
13+
**Removed:**
14+
15+
* <news item>
16+
17+
**Fixed:**
18+
19+
* element/label itemsize to 5 in _linkAtomAttribute to support numpy >=2.0
20+
21+
**Security:**
22+
23+
* <news item>

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[build-system]
2-
requires = ["setuptools>=62.0", "setuptools-git-versioning<2"]
2+
requires = ["setuptools>=62.0", "setuptools-git-versioning>=2.0"]
33
build-backend = "setuptools.build_meta"
44

55
[project]

requirements/run.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
numpy < 2.0.0 # Need to fix deprecations before 2.0.0 compat
1+
numpy
22
pycifrw

src/diffpy/structure/atom.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ def __setitem__(self, idx, value):
536536
self._atom.xyz[:] = self._atom.lattice.fractional(self)
537537
return
538538

539-
def __array_wrap__(self, out_arr, context=None):
539+
def __array_wrap__(self, out_arr, context=None, return_scalar=None):
540540
"""Ensure math operations on this type yield standard numpy array."""
541541
return out_arr.view(numpy.ndarray)
542542

src/diffpy/structure/structure.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -711,8 +711,9 @@ def _get_composition(self):
711711
element = _linkAtomAttribute(
712712
"element",
713713
"""Character array of `Atom` types. Assignment updates
714-
the element attribute of the respective `Atoms`.""",
715-
toarray=numpy.char.array,
714+
the element attribute of the respective `Atoms`.
715+
Set the maximum length of the element string to 5 characters.""",
716+
toarray=lambda items: numpy.char.array(items, itemsize=5),
716717
)
717718

718719
xyz = _linkAtomAttribute(
@@ -742,8 +743,9 @@ def _get_composition(self):
742743
label = _linkAtomAttribute(
743744
"label",
744745
"""Character array of `Atom` names. Assignment updates
745-
the label attribute of all `Atoms`.""",
746-
toarray=numpy.char.array,
746+
the label attribute of all `Atoms`.
747+
Set the maximum length of the label string to 5 characters.""",
748+
toarray=lambda items: numpy.char.array(items, itemsize=5),
747749
)
748750

749751
occupancy = _linkAtomAttribute(

0 commit comments

Comments
 (0)