Skip to content

Revert ndarray coercion of encode returned data #155

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

Merged
merged 5 commits into from
Dec 3, 2018
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
3 changes: 3 additions & 0 deletions docs/release.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ Release notes
* Avoid copying into data in ``GZip``'s `decode()` method on Python 2.
By :user:`John Kirkham <jakirkham>`, :issue:`152`.

* Revert ndarray coercion of encode returned data.
By :user:`John Kirkham <jakirkham>`, :issue:`155`.


.. _release_0.6.1:

Expand Down
236 changes: 84 additions & 152 deletions numcodecs/blosc.c

Large diffs are not rendered by default.

8 changes: 3 additions & 5 deletions numcodecs/blosc.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ from cpython.bytes cimport PyBytes_FromStringAndSize, PyBytes_AS_STRING

from .compat_ext cimport Buffer
from .compat_ext import Buffer
from .compat import PY2, text_type, ensure_ndarray, ensure_contiguous_ndarray
from .compat import PY2, text_type, ensure_contiguous_ndarray
from .abc import Codec


Expand Down Expand Up @@ -488,13 +488,11 @@ class Blosc(Codec):

def encode(self, buf):
buf = ensure_contiguous_ndarray(buf, self.max_buffer_size)
out = compress(buf, self._cname_bytes, self.clevel, self.shuffle, self.blocksize)
return ensure_ndarray(out)
return compress(buf, self._cname_bytes, self.clevel, self.shuffle, self.blocksize)

def decode(self, buf, out=None):
buf = ensure_contiguous_ndarray(buf, self.max_buffer_size)
out = decompress(buf, out)
return ensure_ndarray(out)
return decompress(buf, out)

def __repr__(self):
r = '%s(cname=%r, clevel=%r, shuffle=%s, blocksize=%s)' % \
Expand Down
4 changes: 2 additions & 2 deletions numcodecs/bz2.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


from numcodecs.abc import Codec
from numcodecs.compat import ndarray_copy, ensure_ndarray, ensure_contiguous_ndarray
from numcodecs.compat import ndarray_copy, ensure_contiguous_ndarray


class BZ2(Codec):
Expand All @@ -28,7 +28,7 @@ def encode(self, buf):
buf = ensure_contiguous_ndarray(buf)

# do compression
return ensure_ndarray(_bz2.compress(buf, self.level))
return _bz2.compress(buf, self.level)

# noinspection PyMethodMayBeStatic
def decode(self, buf, out=None):
Expand Down
12 changes: 4 additions & 8 deletions numcodecs/gzip.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


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


if PY2: # pragma: py3 no cover
Expand Down Expand Up @@ -42,13 +42,9 @@ def encode(self, buf):
mode='wb',
compresslevel=self.level) as compressor:
compressor.write(buf)
compressed = compressed.getvalue()

try:
compressed = compressed.getbuffer()
except AttributeError: # pragma: py3 no cover
compressed = compressed.getvalue()

return ensure_ndarray(compressed)
return compressed

# noinspection PyMethodMayBeStatic
def decode(self, buf, out=None):
Expand All @@ -70,6 +66,6 @@ def decode(self, buf, out=None):
if decompressor.read(1) != b'':
raise ValueError("Unable to fit data into `out`")
else:
out = ensure_ndarray(decompressor.read())
out = decompressor.read()

return out
Loading