Skip to content

Commit 0762314

Browse files
authored
Merge pull request #159 from stevenhua0320/deprecate-getLastAtom
build: deprecate getLastAtom and add a test
2 parents ca9116a + 793f5b0 commit 0762314

File tree

7 files changed

+59
-4
lines changed

7 files changed

+59
-4
lines changed

news/deprecate-getLastAtom.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
**Added:**
2+
3+
* Added `diffpy.structure.Structure.get_last_atom` in replace of `getLastAtom`
4+
5+
**Changed:**
6+
7+
* <news item>
8+
9+
**Deprecated:**
10+
11+
* Deprecated `diffpy.structure.Structure.getLastAtom` for removal in version 4.0.0
12+
13+
**Removed:**
14+
15+
* <news item>
16+
17+
**Fixed:**
18+
19+
* <news item>
20+
21+
**Security:**
22+
23+
* <news item>

src/diffpy/structure/parsers/p_cif.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ def _parse_atom_site_label(self, block):
498498
continue
499499
self.labelindex[curlabel] = len(self.stru)
500500
self.stru.add_new_atom()
501-
a = self.stru.getLastAtom()
501+
a = self.stru.get_last_atom()
502502
for fset, val in zip(prop_setters, values):
503503
fset(a, val)
504504
if does_adp_type:

src/diffpy/structure/parsers/p_discus.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ def _parse_atom(self, words):
265265
xyz = [float(w) for w in words[1:4]]
266266
Biso = float(words[4])
267267
self.stru.add_new_atom(element, xyz)
268-
a = self.stru.getLastAtom()
268+
a = self.stru.get_last_atom()
269269
a.Bisoequiv = Biso
270270
return
271271

src/diffpy/structure/parsers/p_pdb.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ def parseLines(self, lines):
198198
element = line[12:14].strip()
199199
element = element[0].upper() + element[1:].lower()
200200
stru.add_new_atom(element, occupancy=occupancy, label=name)
201-
last_atom = stru.getLastAtom()
201+
last_atom = stru.get_last_atom()
202202
last_atom.xyz_cartn = rc
203203
last_atom.Uisoequiv = uiso
204204
elif record == "SIGATM":

src/diffpy/structure/parsers/p_pdffit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def parseLines(self, lines):
133133
xyz = [float(w) for w in wl1[1:4]]
134134
occ = float(wl1[4])
135135
stru.add_new_atom(element, xyz=xyz, occupancy=occ)
136-
a = stru.getLastAtom()
136+
a = stru.get_last_atom()
137137
p_nl += 1
138138
wl2 = next(ilines).split()
139139
a.sigxyz = [float(w) for w in wl2[0:3]]

src/diffpy/structure/structure.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@
3434
"add_new_atom",
3535
removal_version,
3636
)
37+
getLastAtom_deprecation_msg = build_deprecation_message(
38+
base,
39+
"getLastAtom",
40+
"get_last_atom",
41+
removal_version,
42+
)
3743

3844

3945
class Structure(list):
@@ -192,7 +198,16 @@ def add_new_atom(self, *args, **kwargs):
192198
self.append(atom, copy=False)
193199
return
194200

201+
@deprecated(getLastAtom_deprecation_msg)
195202
def getLastAtom(self):
203+
"""This function has been deprecated and will be removed in
204+
version 4.0.0.
205+
206+
Please use diffpy.structure.Structure.get_last_atom instead.
207+
"""
208+
return self.get_last_atom()
209+
210+
def get_last_atom(self):
196211
"""Return Reference to the last `Atom` in this structure."""
197212
last_atom = self[-1]
198213
return last_atom

tests/test_structure.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,23 @@ def test___copy__(self):
119119
# def test_getLastAtom(self):
120120
# """check Structure.getLastAtom()"""
121121
# return
122+
def test_getLastAtom(self):
123+
"""Check Structure.getLastAtom()"""
124+
s_lat = Lattice()
125+
expected = Atom("C", [0, 0, 0])
126+
structure = Structure(atoms=[Atom("C", [0, 0, 0])], lattice=s_lat)
127+
actual = structure.getLastAtom()
128+
assert actual.element == expected.element
129+
assert numpy.allclose(expected.xyz, actual.xyz)
130+
131+
def test_get_last_atom(self):
132+
"""Check Structure.get_last_atom()"""
133+
s_lat = Lattice()
134+
expected = Atom("C", [0, 0, 0])
135+
structure = Structure(atoms=[Atom("C", [0, 0, 0])], lattice=s_lat)
136+
actual = structure.get_last_atom()
137+
assert actual.element == expected.element
138+
assert numpy.allclose(expected.xyz, actual.xyz)
122139

123140
def test_addNewAtom(self):
124141
"""Duplicate test for the deprecated addNewAtom method.

0 commit comments

Comments
 (0)