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

Numpy JSON serialization #160

Merged
merged 3 commits into from Jul 7, 2017
Merged

Numpy JSON serialization #160

merged 3 commits into from Jul 7, 2017

Conversation

bmcfee
Copy link
Contributor

@bmcfee bmcfee commented Jul 5, 2017

This PR fixes #159 by doing explicit type coercion on numpy scalars when converting to JSON.

It's a bit of a stop-gap solution for now. I think we should at some point re-structure how serialize_obj is implemented and used, so that it applies transparently throughout all __json__ calls. That's probably out of scope for this fix though, so this PR should be ready to go.

@bmcfee bmcfee added the bug label Jul 5, 2017
@bmcfee bmcfee added this to the 0.3.0 milestone Jul 5, 2017
@bmcfee bmcfee self-assigned this Jul 5, 2017
@bmcfee bmcfee requested a review from ejhumphrey July 5, 2017 20:45
self.data.add(Observation(time=time,
duration=duration,
self.data.add(Observation(time=float(time),
duration=float(duration),
value=value,
confidence=confidence))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know confidence can be None, but might we want a similar coercion here too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confidence is not typed in the schema. Technically it can be anything, just like value, so we can't coerce here.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reeeheheally... 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup. The reasoning here is confidence is namespace-dependent; sometimes it's required (tempo), sometimes it's optional (msd_tagtraum).

@@ -1117,3 +1117,9 @@ def _foo():

# And that it says the right thing (roughly)
assert 'deprecated' in str(out[0].message).lower()


def test_numpy_serialize():
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good for JObject, which I guess is testing serialize_object under the hood ... I'm wondering if it's worth checking the float casting for the observation data in Annotation?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly. I just pushed up a second test for Annotation, working on observation fields. I think that should cover it for now.

@ejhumphrey
Copy link
Collaborator

LGTM 👍

@bmcfee bmcfee merged commit 72b4760 into master Jul 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NumPy float format serialization issues
2 participants