-
Notifications
You must be signed in to change notification settings - Fork 97
ENH: add Pickle/MsgPack codec with support for object ndarrays #5
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
Conversation
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.
Thanks @jreback, looks good, just a couple of minor comments.
|
||
|
||
class MsgPack(Codec): | ||
"""Codec to encode data as as msgpacked bytes. Useful for encoding python |
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.
"as" repeated; missing "." at end of sentence.
|
||
""" # flake8: noqa | ||
|
||
codec_id = 'x-msgpack' |
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 can be just 'msgpack'. I was using 'x-' as a prefix for codecs not provided by numcodecs itself, but now this codec is inside numcodecs we can drop this prefix..
|
||
class Pickle(Codec): | ||
"""Codec to encode data as as pickled bytes. Useful for encoding python | ||
strings |
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.
Missing '.' at end of sentence.
|
||
""" # flake8: noqa | ||
|
||
codec_id = 'x-pickle' |
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 can be 'pickle'.
if hasattr(buf, 'dtype') and buf.dtype != 'object': | ||
raise ValueError("cannot encode non-object ndarrays, %s " | ||
"dtype was passed" % buf.dtype) | ||
return pickle.dumps(buf, protocol=pickle.HIGHEST_PROTOCOL) |
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.
Could you add protocol
as a configuration parameter of the codec. This would mean adding as a keyword argument to __init__
, and also including in the output from get_config()
.
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.
not sure that's a good idea. These always must be binary seralized. I don't think their is actually a reason to use a not-highest protocol.
63a25ea
to
3671aea
Compare
ok updated & I added the protocol paramater. |
Thanks! |
awesome! assume you are going to rip the codecs out of zarr and replace with this. soonish? |
Yes that's the plan, next Zarr point release. On Monday, 17 October 2016, Jeff Reback [email protected] wrote:
Alistair Miles |
didn't realize you had a doc folder, you need updates? |
No worries, that would be nice if you have time. On Monday, October 17, 2016, Jeff Reback [email protected] wrote:
Alistair Miles |
Fix conflicts with upstream `master`
so choosing to raise for non-object ndarray's rather than pickle them. generally other filters will be much more friendly to other dtypes I think.
added support for msgpack-python as another filter, similar to Pickle. this is an optional import.