diff --git a/docs/release.rst b/docs/release.rst index c55df95b..bfb4c387 100644 --- a/docs/release.rst +++ b/docs/release.rst @@ -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 `, :issue:`143`). + + .. _release_0.6.1: 0.6.1 diff --git a/numcodecs/pickles.py b/numcodecs/pickles.py index 2d3ac81d..7e1c26f7 100644 --- a/numcodecs/pickles.py +++ b/numcodecs/pickles.py @@ -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 @@ -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) + dec = pickle.loads(buf) if out is not None: np.copyto(out, dec) diff --git a/numcodecs/tests/common.py b/numcodecs/tests/common.py index a06d4991..cd18491b 100644 --- a/numcodecs/tests/common.py +++ b/numcodecs/tests/common.py @@ -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) + def check_config(codec): config = codec.get_config()