Skip to content

Commit f3144ae

Browse files
committed
Refactor reshape from _decode_chunk
As both the expected `object` case and the non-`object` case perform a `reshape` to flatten the data, go ahead and refactor that out of both cases and handle it generally. Simplifies the code a bit.
1 parent b741fe1 commit f3144ae

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

zarr/core.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1749,21 +1749,18 @@ def _decode_chunk(self, cdata):
17491749
if self._dtype == object:
17501750
# special case object dtype, because incorrect handling can lead to
17511751
# segfaults and other bad things happening
1752-
if chunk.dtype == object:
1753-
# chunk is already of correct dtype, good to carry on
1754-
# flatten just to be sure we can reshape later
1755-
chunk = chunk.reshape(-1, order='A')
1756-
else:
1752+
if chunk.dtype != object:
17571753
# If we end up here, someone must have hacked around with the filters.
17581754
# We cannot deal with object arrays unless there is an object
17591755
# codec in the filter chain, i.e., a filter that converts from object
17601756
# array to something else during encoding, and converts back to object
17611757
# array during decoding.
17621758
raise RuntimeError('cannot read object array without object codec')
17631759
else:
1764-
chunk = chunk.reshape(-1, order='A').view(self._dtype)
1760+
chunk = chunk.view(self._dtype)
17651761

17661762
# ensure correct chunk shape
1763+
chunk = chunk.reshape(-1, order='A')
17671764
chunk = chunk.reshape(self._chunks, order=self._order)
17681765

17691766
return chunk

0 commit comments

Comments
 (0)