Skip to content

Commit f1ed57b

Browse files
committed
Return ndarrays from decode where possible
Where possible, ensure that `decode` returns an `ndarray`. Many codecs already do this except for some unusual ones that work with Python objects or text data. In the cases where the data is known to be binary, try to return `ndarray`s. This makes it pretty easy for end users of this data to do whatever they would like with it.
1 parent 97fc7c9 commit f1ed57b

File tree

3 files changed

+4
-3
lines changed

3 files changed

+4
-3
lines changed

numcodecs/blosc.pyx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,8 @@ class Blosc(Codec):
493493

494494
def decode(self, buf, out=None):
495495
buf = ensure_contiguous_ndarray(buf, self.max_buffer_size)
496-
return decompress(buf, out)
496+
out = decompress(buf, out)
497+
return ensure_ndarray(out)
497498

498499
def __repr__(self):
499500
r = '%s(cname=%r, clevel=%r, shuffle=%s, blocksize=%s)' % \

numcodecs/lz4.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ class LZ4(Codec):
223223

224224
def decode(self, buf, out=None):
225225
buf = ensure_contiguous_ndarray(buf, self.max_buffer_size)
226-
return decompress(buf, out)
226+
return ensure_ndarray(decompress(buf, out))
227227

228228
def __repr__(self):
229229
r = '%s(acceleration=%r)' % \

numcodecs/zstd.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ class Zstd(Codec):
218218

219219
def decode(self, buf, out=None):
220220
buf = ensure_contiguous_ndarray(buf)
221-
return decompress(buf, out)
221+
return ensure_ndarray(decompress(buf, out))
222222

223223
def __repr__(self):
224224
r = '%s(level=%r)' % \

0 commit comments

Comments
 (0)