Skip to content

Commit 3e3920a

Browse files
committed
Consolidate type checks in _decode_chunk
As refactoring of the `reshape` step has effectively dropped the expected `object` type case, the checks for different types is a little more complicated than needed. To fix this, basically invert and swap the case ordering. This way we can handle all generally expected types first and simply cast them. Then we can raise if an `object` type shows up and is unexpected.
1 parent f3144ae commit 3e3920a

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

zarr/core.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1746,18 +1746,17 @@ def _decode_chunk(self, cdata):
17461746

17471747
# view as numpy array with correct dtype
17481748
chunk = ensure_ndarray(chunk)
1749-
if self._dtype == object:
1750-
# special case object dtype, because incorrect handling can lead to
1751-
# segfaults and other bad things happening
1752-
if chunk.dtype != object:
1753-
# If we end up here, someone must have hacked around with the filters.
1754-
# We cannot deal with object arrays unless there is an object
1755-
# codec in the filter chain, i.e., a filter that converts from object
1756-
# array to something else during encoding, and converts back to object
1757-
# array during decoding.
1758-
raise RuntimeError('cannot read object array without object codec')
1759-
else:
1749+
# special case object dtype, because incorrect handling can lead to
1750+
# segfaults and other bad things happening
1751+
if self._dtype != object:
17601752
chunk = chunk.view(self._dtype)
1753+
elif chunk.dtype != object:
1754+
# If we end up here, someone must have hacked around with the filters.
1755+
# We cannot deal with object arrays unless there is an object
1756+
# codec in the filter chain, i.e., a filter that converts from object
1757+
# array to something else during encoding, and converts back to object
1758+
# array during decoding.
1759+
raise RuntimeError('cannot read object array without object codec')
17611760

17621761
# ensure correct chunk shape
17631762
chunk = chunk.reshape(-1, order='A')

0 commit comments

Comments
 (0)