-
Notifications
You must be signed in to change notification settings - Fork 871
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix array comparison in core.Structure.merge_sites
, also allow int
property to be merged instead of float
alone, mode
only allow full name
#4198
base: master
Are you sure you want to change the base?
Changes from 1 commit
644c12d
87da226
bc6645b
5b4b0ae
c2ccd92
13e58d6
dd1b338
2289d54
9618ddc
467b840
658b33a
99988ef
702b80b
091c911
ecc2d05
78e880b
8c1fb79
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -4746,7 +4746,7 @@ def merge_sites(self, tol: float = 0.01, mode: Literal["sum", "delete", "average | |||||||
offset = self[i].frac_coords - coords | ||||||||
coords += ((offset - np.round(offset)) / (n + 2)).astype(coords.dtype) | ||||||||
for key in props: | ||||||||
if props[key] is not None and self[i].properties[key] != props[key]: | ||||||||
if props[key] is not None and np.array_equal(self[i].properties[key], props[key]): | ||||||||
if mode.lower()[0] == "a" and isinstance(props[key], float): | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess only allowing pymatgen/tests/core/test_structure.py Lines 1677 to 1679 in 31f1e1f
Also the docstring would be clarified to explain this behaviour. |
||||||||
# update a running total | ||||||||
props[key] = props[key] * (n + 1) / (n + 2) + self[i].properties[key] / (n + 2) | ||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO tag: Using
array_equal
may not be a good idea either as the property could be (sequence of) floatsTODO2: test failure
pymatgen/tests/core/test_structure.py
Lines 1667 to 1681 in 31f1e1f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Property can actually be anything, including value supplied by user.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for stepping in, I'm here adding a note for myself to work on later.
Yes in this case using
==
for comparison may not be ideal when the value could be float ornp.array
, this is very similar to #4092 where we want to compare the equality of two dict whose value could benp.array
But I assume we would not be able to use
np.allclose
as the value could be non-numerical, so as far as I'm aware, usingarray_equal
would be the best approach (though handling of float would be sub-optimal)