materialsvirtuallab/monty

[Bug]: 602 Enum serialization was a breaking change

Closed this issue · 5 comments

janosh commented

Email (Optional)

No response

Version

2024.1.26

Which OS(es) are you using?

  • MacOS
  • Windows
  • Linux

What happened?

TestPhaseDiagram.test_read_json started failing after materialsproject/pymatgen@5137111 bumping monty to 2024.1.26.

Code snippet

def test_read_json(self):
    dumpfn(self.pd, f"{self.tmp_path}/pd.json")
    pd = loadfn(f"{self.tmp_path}/pd.json")
    assert isinstance(pd, PhaseDiagram)
    assert {*pd.as_dict()} == {*self.pd.as_dict()}

Log output

monty/json.py:517: in process_decoded
    return cls_.from_dict(data)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

d = {'value': 'O'}

    @staticmethod
    def from_dict(d) -> Element:
        """Makes Element obey the general json interface used in pymatgen for
        easier serialization.
        """
>       return Element(d["element"])
E       KeyError: 'element'

/Users/janosh/dev/pmg/pymatgen/core/periodic_table.py:755: KeyError

Code of Conduct

  • I agree to follow this project's Code of Conduct
jmmshn commented

Thansk for pining me @Andrew-S-Rosen !
So it looks like serialization should respect custom as_dict and from_dicts but there new code was inserted into the wrong place.
Fixing now.

jmmshn commented

The same pymatgen test now passes on my local.

@janosh This can now be closed.

janosh commented

thanks for the quick fix @jmmshn! 👍