Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions docs/release.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
Release notes
=============

.. _release_0.6.2:

0.6.2
-----

* Handle (new) buffer protocol conforming types in ``Pickle.decode``.
(by :user:`John Kirkham <jakirkham>`, :issue:`143`).


.. _release_0.6.1:

0.6.1
Expand Down
7 changes: 6 additions & 1 deletion numcodecs/pickles.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


from .abc import Codec
from .compat import PY2
from .compat import PY2, ensure_bytes, ensure_contiguous_ndarray


if PY2: # pragma: py3 no cover
Expand Down Expand Up @@ -48,6 +48,11 @@ def encode(self, buf):
return pickle.dumps(buf, protocol=self.protocol)

def decode(self, buf, out=None):
if PY2: # pragma: py3 no cover
buf = ensure_bytes(buf)
else: # pragma: py2 no cover
buf = ensure_contiguous_ndarray(buf)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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


dec = pickle.loads(buf)
if out is not None:
np.copyto(out, dec)
Expand Down
4 changes: 4 additions & 0 deletions numcodecs/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ def check_encode_decode_array(arr, codec):
codec.decode(enc, out=out)
assert_array_items_equal(arr, out)

enc = codec.encode(arr)
dec = codec.decode(ensure_ndarray(enc))
assert_array_items_equal(arr, dec)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Seems this worked for everything except Pickle on Python 2 as demonstrated by this CI failure. This is likely a consequence of the improved buffer handling under the hood, which MsgPack, JSON, etc. all use already. Pickle was the only one not using these functions, which this PR fixes. So testing this generally seems to be fine. All the other codecs already test decoding with ndarray.



def check_config(codec):
config = codec.get_config()
Expand Down