Skip to content
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

Merge collapsible if statements #1999

Merged
merged 1 commit into from
Jun 27, 2024
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
15 changes: 9 additions & 6 deletions src/zarr/codecs/bytes.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,15 @@ async def _encode_single(
chunk_spec: ArraySpec,
) -> Buffer | None:
assert isinstance(chunk_array, NDBuffer)
if chunk_array.dtype.itemsize > 1:
if self.endian is not None and self.endian != chunk_array.byteorder:
# type-ignore is a numpy bug
# see https://github.com/numpy/numpy/issues/26473
new_dtype = chunk_array.dtype.newbyteorder(self.endian.name) # type: ignore[arg-type]
chunk_array = chunk_array.astype(new_dtype)
if (
chunk_array.dtype.itemsize > 1
and self.endian is not None
and self.endian != chunk_array.byteorder
):
# type-ignore is a numpy bug
# see https://github.com/numpy/numpy/issues/26473
new_dtype = chunk_array.dtype.newbyteorder(self.endian.name) # type: ignore[arg-type]
chunk_array = chunk_array.astype(new_dtype)

nd_array = chunk_array.as_ndarray_like()
# Flatten the nd-array (only copy if needed) and reinterpret as bytes
Expand Down
4 changes: 1 addition & 3 deletions src/zarr/codecs/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,9 +315,7 @@ def _merge_chunk_array(
)
else:
chunk_array = existing_chunk_array.copy() # make a writable copy
if chunk_selection == ():
chunk_value = value
elif is_scalar(value.as_ndarray_like(), chunk_spec.dtype):
if chunk_selection == () or is_scalar(value.as_ndarray_like(), chunk_spec.dtype):
chunk_value = value
else:
chunk_value = value[out_selection]
Expand Down
11 changes: 5 additions & 6 deletions src/zarr/codecs/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,11 @@ def register_codec(key: str, codec_cls: type[Codec]) -> None:

def get_codec_class(key: str) -> type[Codec]:
item = __codec_registry.get(key)
if item is None:
if key in __lazy_load_codecs:
# logger.debug("Auto loading codec '%s' from entrypoint", codec_id)
cls = __lazy_load_codecs[key].load()
register_codec(key, cls)
item = __codec_registry.get(key)
if item is None and key in __lazy_load_codecs:
# logger.debug("Auto loading codec '%s' from entrypoint", codec_id)
cls = __lazy_load_codecs[key].load()
register_codec(key, cls)
item = __codec_registry.get(key)
if item:
return item
raise KeyError(key)
Expand Down
11 changes: 5 additions & 6 deletions src/zarr/v2/convenience.py
Original file line number Diff line number Diff line change
Expand Up @@ -680,12 +680,11 @@ def copy_store(

# decide what to do
do_copy = True
if if_exists != "replace":
if dest_key in dest:
if if_exists == "raise":
raise CopyError("key {!r} exists in destination".format(dest_key))
elif if_exists == "skip":
do_copy = False
if if_exists != "replace" and dest_key in dest:
if if_exists == "raise":
raise CopyError("key {!r} exists in destination".format(dest_key))
elif if_exists == "skip":
do_copy = False

# take action
if do_copy:
Expand Down
7 changes: 3 additions & 4 deletions src/zarr/v2/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,10 +428,9 @@ def __init__(self, obj, depth=0, level=None):
self.level = level

def get_children(self):
if hasattr(self.obj, "values"):
if self.level is None or self.depth < self.level:
depth = self.depth + 1
return [TreeNode(o, depth=depth, level=self.level) for o in self.obj.values()]
if hasattr(self.obj, "values") and (self.level is None or self.depth < self.level):
depth = self.depth + 1
return [TreeNode(o, depth=depth, level=self.level) for o in self.obj.values()]
return []

def get_text(self):
Expand Down