Skip to content
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

Add pre/post processors to allow nan and inf values to be stored in JSON #13

Conversation

zhubonan
Copy link

This PR allow nan/inf values to be stored as JSON strings in PostgreSQL.

The `MSONable` class, provided by the `monty` library, is designed to
make arbitrary classes easily JSON-serializable such that they can be
serialized and, for example, stored in a database. The class is used
extensively in `pymatgen` and many of their classes are MSONable. Since
the `pymatgen` classes are used often in the current AiiDA community, it
would be nice if these objects can be easily stored in the provenance
graph.

The new `MsonableData` data plugin, wraps any instance of a `MSONable`
class. When constructed, it calls `as_dict` which by definition returns
a JSON-serialized version of the object, which we can therefore store in
the nodes attributes and allow it to be stored. The `obj` property will
return the original MSONable instance as it deserializes it from the
serialized version stored in the attributes.
@sphuber
Copy link
Owner

sphuber commented Jul 14, 2021

Thanks @zhubonan . I'm out of office this week but will take a look when I'm back

sphuber and others added 2 commits July 21, 2021 12:12
Remove the subclass checking - only check for the as_dict and from_dict
methods. Remove unecessary round trips for json encoding. We still
assume that the output of `as_dict` is JSON serializable as originally
intended by the `MSONable` class.
@zhubonan zhubonan force-pushed the feature/4975/msonable-data-plugin-bonan branch from be846b0 to a15b525 Compare July 30, 2021 23:22
@sphuber sphuber force-pushed the feature/4975/msonable-data-plugin branch from 385b4a4 to d8f88f2 Compare August 1, 2021 08:20
@sphuber
Copy link
Owner

sphuber commented Aug 1, 2021

I have updated the PR to make a more generic plugin, i.e. to decouple it from MSONable and allow any class with the necessary behavior. Therefore it also made more sense to me to rename the class and call it JsonableData.

@sphuber sphuber force-pushed the feature/4975/msonable-data-plugin branch 4 times, most recently from b5a38cb to 6513a79 Compare August 2, 2021 07:32
@sphuber sphuber force-pushed the feature/4975/msonable-data-plugin branch from 6513a79 to 9537ef4 Compare August 12, 2021 14:24
@sphuber sphuber deleted the branch sphuber:feature/4975/msonable-data-plugin August 12, 2021 16:28
@sphuber sphuber closed this Aug 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants