diff --git a/docs/release.rst b/docs/release.rst index 1bf12b74..ddf468dd 100644 --- a/docs/release.rst +++ b/docs/release.rst @@ -7,7 +7,7 @@ Release notes ----- * Handle (new) buffer protocol conforming types in ``Pickle.decode``. - By :user:`John Kirkham `, :issue:`143`. + By :user:`John Kirkham `, :issue:`143`, :issue:`150`. * Fix other ``VLen*`` encode() methods to return numpy arrays as well. By :user:`John Kirkham `, :issue:`144`. diff --git a/numcodecs/pickles.py b/numcodecs/pickles.py index 7e1c26f7..9c22b9cb 100644 --- a/numcodecs/pickles.py +++ b/numcodecs/pickles.py @@ -6,11 +6,12 @@ from .abc import Codec -from .compat import PY2, ensure_bytes, ensure_contiguous_ndarray +from .compat import PY2, ensure_contiguous_ndarray if PY2: # pragma: py3 no cover import cPickle as pickle + from cStringIO import StringIO else: # pragma: py2 no cover import pickle @@ -48,12 +49,13 @@ def encode(self, buf): return pickle.dumps(buf, protocol=self.protocol) def decode(self, buf, out=None): + buf = ensure_contiguous_ndarray(buf) + if PY2: # pragma: py3 no cover - buf = ensure_bytes(buf) + dec = pickle.load(StringIO(buf)) else: # pragma: py2 no cover - buf = ensure_contiguous_ndarray(buf) + dec = pickle.loads(buf) - dec = pickle.loads(buf) if out is not None: np.copyto(out, dec) return out