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
Conversation
force-serialize numpy dtypes
self.data.add(Observation(time=time, | ||
duration=duration, | ||
self.data.add(Observation(time=float(time), | ||
duration=float(duration), | ||
value=value, | ||
confidence=confidence)) |
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 know confidence
can be None, but might we want a similar coercion here too?
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.
Confidence is not typed in the schema. Technically it can be anything, just like value, so we can't coerce here.
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.
reeeheheally... 🤔
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.
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(): |
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 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
?
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.
Exactly. I just pushed up a second test for Annotation, working on observation fields. I think that should cover it for now.
LGTM 👍 |
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.