Skip to content

Commit

Permalink
Apply assorted ruff/refurb rules (FURB)
Browse files Browse the repository at this point in the history
FURB113 Use `compressors.extend(...)` instead of repeatedly calling `compressors.append()`
FURB118 Use `operator.mul` instead of defining a lambda
FURB171 Membership test against single-item container
  • Loading branch information
DimitriPapadopoulos committed May 13, 2024
1 parent cb4230d commit 24bd82a
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
3 changes: 2 additions & 1 deletion zarr/_storage/v3_storage_transformers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import functools
import itertools
import operator
import os
from typing import NamedTuple, Tuple, Optional, Union, Iterator

Expand Down Expand Up @@ -101,7 +102,7 @@ def __init__(self, _type, chunks_per_shard) -> None:
if chunks_per_shard == ():
chunks_per_shard = (1,)
self.chunks_per_shard = chunks_per_shard
self._num_chunks_per_shard = functools.reduce(lambda x, y: x * y, chunks_per_shard, 1)
self._num_chunks_per_shard = functools.reduce(operator.mul, chunks_per_shard, 1)
self._dimension_separator = None
self._data_key_prefix = None

Expand Down
4 changes: 2 additions & 2 deletions zarr/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def decode_fill_value(cls, v: Any, dtype: np.dtype, object_codec: Any = None) ->
return -np.inf
else:
return np.array(v, dtype=dtype)[()]
elif dtype.kind in "c":
elif dtype.kind == "c":
v = (
cls.decode_fill_value(v[0], dtype.type().real.dtype),
cls.decode_fill_value(v[1], dtype.type().imag.dtype),
Expand Down Expand Up @@ -283,7 +283,7 @@ def encode_fill_value(cls, v: Any, dtype: np.dtype, object_codec: Any = None) ->
return int(v)
elif dtype.kind == "b":
return bool(v)
elif dtype.kind in "c":
elif dtype.kind == "c":
c = cast(np.complex128, np.dtype(complex).type())
v = (
cls.encode_fill_value(v.real, c.real.dtype, object_codec),
Expand Down
4 changes: 1 addition & 3 deletions zarr/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1995,9 +1995,7 @@ def test_attrs_n5_keywords(self):
def test_compressors(self):
compressors = [None, BZ2(), Zlib(), GZip(), MsgPack()]
if LZMA:
compressors.append(LZMA())
compressors.append(LZMA(preset=1))
compressors.append(LZMA(preset=6))
compressors.extend((LZMA(), LZMA(preset=1), LZMA(preset=6)))
for compressor in compressors:
a1 = self.create_array(shape=1000, chunks=100, compressor=compressor)
a1[0:100] = 1
Expand Down

0 comments on commit 24bd82a

Please sign in to comment.