Skip to content

Commit

Permalink
add test for non-numerical warning
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielYang59 committed Nov 26, 2024
1 parent 13e58d6 commit dd1b338
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/pymatgen/core/structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -4769,7 +4769,7 @@ def merge_sites(
props[key] = props[key] * (n + 1) / (n + 2) + self[i].properties[key] / (n + 2)
else:
props[key] = None
warnings.warn( # TODO: test missing
warnings.warn(
f"Sites with different site property {key} are merged. But property is set to None",
stacklevel=2,
)
Expand Down
5 changes: 5 additions & 0 deletions tests/core/test_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -1685,6 +1685,11 @@ def test_merge_sites(self):
assert len(struct_navs2) == 12
assert any(math.isclose(site.properties["prop1"], 51.5) for site in struct_navs2)

# Test non-numerical property warning
struct_navs2.insert(0, "Na", coords[0], properties={"prop1": "hi"})
with pytest.warns(UserWarning, match="But property is set to None"):
struct_navs2.merge_sites(mode="average")

# Test property handling for np.array (selective dynamics)
poscar_str_0 = """Test POSCAR
1.0
Expand Down

0 comments on commit dd1b338

Please sign in to comment.