chore: deprecated addNewAtom#157
Conversation
cadenmyers13
left a comment
There was a problem hiding this comment.
@stevenhua0320 thanks, please see inline.
I responded to your slack message about the tests. Please check that out and do your best to get the DeprecationWarning to show up when you run pytest
src/diffpy/structure/structure.py
Outdated
| """ | ||
| kwargs["lattice"] = self.lattice | ||
| a = Atom(*args, **kwargs) | ||
| self.append(a, copy=False) |
There was a problem hiding this comment.
remove all the content of this function and have it take the new function name so we dont have duplicate code, ie,
def addNewAtom(self, *args, **kwargs):
"""This function has been deprecated and will be removed in
version 4.0.0.
Please use diffpy.structure.Structure.add_new_atom instead.
"""
self.add_new_atom(*args, **kwargs):
return
There was a problem hiding this comment.
I have done a global search, we only have test for this which is all commented in the test.
# def test_addNewAtom(self):
# """check Structure.addNewAtom()"""
# return
# def test_getLastAtom(self):
# """check Structure.getLastAtom()"""
# return
|
Also looks like there is typo in your PR title 😉 |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## v3.4.0 #157 +/- ##
==========================================
+ Coverage 98.93% 98.95% +0.01%
==========================================
Files 13 13
Lines 1878 1905 +27
==========================================
+ Hits 1858 1885 +27
Misses 20 20
🚀 New features to boost your workflow:
|
sbillinge
left a comment
There was a problem hiding this comment.
this looks good. If there is no test, please can we add one? But as @cadenmyers13 says, please check if it is tested any other way.
Let me try to add one, I have done a global search and we don't have it. Also for |
|
Thanks guys... The code continuously improves! |
|
@cadenmyers13 ready to review. I have added a test to test the behavior of |
|
@stevenhua0320 Looks great! Thanks! Can you please add a minimal docstring to the test for the deprecated function? Something like |
sbillinge
left a comment
There was a problem hiding this comment.
Please see inline comments. Also. Please, as usual, add comments that capture the cases being tested and what we expect to happen
tests/test_structure.py
Outdated
| expected = Structure(lattice=s_lat) | ||
|
|
||
| length = len(expected) | ||
| expected.add_new_atom(atype="C", xyz=[0.1, 0.2, 0.3]) |
There was a problem hiding this comment.
This test is done but the code is a bit lazily written. Please can we think more carefully to make it more readable? For example, isn't assert len(expected) == len(actual)? And "object", what object?
There was a problem hiding this comment.
Since add_new_atom would return nothing in the original function, we must have a variable to check the length of the Structure object before and after the method. I also changed the object variable to a more precise name to atom_object. See the latest commit.
|
@cadenmyers13 also just as a side note, do we really need a test for this function? I did a global search and we only use this function but we don't have anywhere used in test. However, I don't think we actually need the test for this function. |
sbillinge
left a comment
There was a problem hiding this comment.
nearly there, just please see comment.
tests/test_structure.py
Outdated
| def test_add_new_atom(self): | ||
| """Check Structure.add_new_item()""" | ||
| # Case: We initialize a Structure object, after calling | ||
| # add_new_item method, we check whether length of Structure |
There was a problem hiding this comment.
This is describing the test, but remember the test tests behavior so we want to describe the behavior we want. This would be better as something like
Case 1: valid atom added to an empty structure. Expect the atom list length to go from 0 to 1. Expect the atom attributes are successfully loaded.
Then we will likely need
Case 2: valid atom added to exissting atom list. Expect ....
and
Case 3: duplicate atom added to existing atom list. Expect ....
and some behaviors for invalid atoms maybe, if we can think of tests that don't take too long to write.
There was a problem hiding this comment.
I'm not quite sure about the physical perspective here. Do we allow duplicated atom into the atom list (for Case 3)? If not then we might expect an error and give the user some message about it.
There was a problem hiding this comment.
@sbillinge ready for review. Note that from my bad physical perspective what I can think of is we should not allow a same atom at the same position in the space. So, I add the case 3 in the test, refining the original function here.
tests/test_structure.py
Outdated
| expected.add_new_atom(atype="C", xyz=[0.1, 0.2, 0.3]) | ||
| length = len(structure) | ||
| structure.add_new_atom(atype="C", xyz=[0.1, 0.2, 0.3]) | ||
| expected = len(structure) # length of structure should add by 1 |
There was a problem hiding this comment.
remove comment. this is handled in the comment at the top. Is this LLM code? OK, to get help from an LLM if it is, but I want you in charge, so you are responsible for what is happening and not the chatbot.
|
This is the |
| *args, **kwargs : | ||
| See `Atom` class constructor. | ||
|
|
||
| Raises |
There was a problem hiding this comment.
I think this is undesirable behavior. Let's allow the atom to be added. We could raise a warning. But I think it is on the user to get this how they want it. So I would be inclined to simply allow it.
tests/test_structure.py
Outdated
| assert atom_object.element == "C" | ||
| assert numpy.allclose(atom_object.xyz, [0.1, 0.2, 0.3]) | ||
|
|
||
| # Case 2: valid atom added to existing atom list. |
There was a problem hiding this comment.
There is lots of copy-pasted code here. I think using parametrize is better
|
@sbillinge ready for another review, I changed to |
@cadenmyers13 ready to review first. Note that this is the scenario that I described in the slack chat in the first case. We don't have any test for this function, so there will be no deprecation warning when we run
pytest. But we are not sure whether in some other packages that we use the CamelCase one, so I still add this deprecation here.