|
13 | 13 | from pymatgen.core.lattice import Lattice
|
14 | 14 | from pymatgen.core.periodic_table import DummySpecies, Element, Species, get_el_sp
|
15 | 15 | from pymatgen.util.coord import pbc_diff
|
| 16 | +from pymatgen.util.misc import is_np_dict_equal |
16 | 17 |
|
17 | 18 | if TYPE_CHECKING:
|
18 | 19 | from typing import Any
|
@@ -96,18 +97,10 @@ def __eq__(self, other: object) -> bool:
|
96 | 97 | if not isinstance(other, type(self)):
|
97 | 98 | return NotImplemented
|
98 | 99 |
|
99 |
| - # Some properties could be np.array, and in these cases |
100 |
| - # using "==" for dict equality check would fail |
101 |
| - try: |
102 |
| - np.testing.assert_equal(self.properties, other.properties) |
103 |
| - prop_equal = True |
104 |
| - except AssertionError: |
105 |
| - prop_equal = False |
106 |
| - |
107 | 100 | return (
|
108 | 101 | self.species == other.species
|
109 | 102 | and np.allclose(self.coords, other.coords, atol=type(self).position_atol)
|
110 |
| - and prop_equal |
| 103 | + and is_np_dict_equal(self.properties, other.properties) |
111 | 104 | )
|
112 | 105 |
|
113 | 106 | def __hash__(self) -> int:
|
@@ -368,17 +361,11 @@ def __eq__(self, other: object) -> bool:
|
368 | 361 | if not isinstance(other, type(self)):
|
369 | 362 | return NotImplemented
|
370 | 363 |
|
371 |
| - try: |
372 |
| - np.testing.assert_equal(self.properties, other.properties) |
373 |
| - prop_equal = True |
374 |
| - except AssertionError: |
375 |
| - prop_equal = False |
376 |
| - |
377 | 364 | return (
|
378 | 365 | self.species == other.species
|
379 | 366 | and self.lattice == other.lattice
|
380 | 367 | and np.allclose(self.coords, other.coords, atol=Site.position_atol)
|
381 |
| - and prop_equal |
| 368 | + and is_np_dict_equal(self.properties, other.properties) |
382 | 369 | )
|
383 | 370 |
|
384 | 371 | def __repr__(self) -> str:
|
|
0 commit comments