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 JSON serialization for Molecule #745
Conversation
# TODO: More generally check for bytes in dict | ||
if "conformers" in d.keys(): | ||
d = _prep_numpy_data_for_json(d) |
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.
This is only a stopgap solution. It may be better to more generally check for the type of the data, but this field is the only one in the toolkit that currently causes this issue.
Passing locally after the version bump |
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.
Updated json serialization test to use minidrugbank (since it was already pytest.parametrize
d for it) and added the changes to the releasenotes. This should be ready to merge if tests pass!
@@ -416,6 +417,18 @@ def test_serialization_no_conformers(self): | |||
pickle_copy = pickle.loads(pickle.dumps(mol)) | |||
assert mol == pickle_copy | |||
|
|||
def test_json_numpy_roundtrips(self): |
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.
👍 This is a cool test. I've always been vaguely concerned about precision loss and compounding rounding errors, so it's really neat to see this.
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.
I was pleasantly surprised to see it work
Co-authored-by: Jeff Wagner <jwagnerjpl@gmail.com>
LGTM is hanging but the changes here should be small enough in scope to not produce huge warning lights |
Resolves #547
This tries to patch the
dict
inside ofSerializable.to_json()
to convert the conformers from bytes to lists, which surprisingly seem to survive round-trips. This should fixMolecule
serialization but is almost guaranteed to not work for other classes class that need to serialize array data (Topology.box_vectors
?). Improvements to the_prep_numpy_data_for_json
function should enable this, it's currently a half-baked attempt at the general solution.