Skip to content

Commit 88946d2

Browse files
Apply assorted ruff/refurb rules (FURB) (#1873)
* Apply ruff/refurb rule FURB118 FURB118 Use `operator....` instead of defining a lambda * Apply ruff/refurb rule FURB171 FURB171 Membership test against single-item container * Apply ruff/refurb rule FURB113 FURB113 Use `....extend(...)` instead of repeatedly calling `....append()` --------- Co-authored-by: Joe Hamman <joe@earthmover.io>
1 parent 333f37f commit 88946d2

File tree

4 files changed

+10
-10
lines changed

4 files changed

+10
-10
lines changed

src/zarr/codecs/sharding.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from dataclasses import dataclass, field, replace
55
from enum import Enum
66
from functools import lru_cache
7+
from operator import itemgetter
78
from typing import TYPE_CHECKING, NamedTuple
89

910
import numpy as np
@@ -124,7 +125,7 @@ def is_dense(self, chunk_byte_length: int) -> bool:
124125
for offset, length in self.offsets_and_lengths
125126
if offset != MAX_UINT_64
126127
],
127-
key=lambda entry: entry[0],
128+
key=itemgetter(0),
128129
)
129130

130131
# Are all non-empty offsets unique?

src/zarr/common.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import asyncio
44
import contextvars
55
import functools
6+
import operator
67
from collections.abc import Iterable
78
from dataclasses import dataclass
89
from enum import Enum
@@ -28,7 +29,7 @@
2829

2930

3031
def product(tup: ChunkCoords) -> int:
31-
return functools.reduce(lambda x, y: x * y, tup, 1)
32+
return functools.reduce(operator.mul, tup, 1)
3233

3334

3435
T = TypeVar("T", bound=tuple[Any, ...])

src/zarr/v2/meta.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ def decode_fill_value(cls, v: Any, dtype: np.dtype, object_codec: Any = None) ->
222222
return -np.inf
223223
else:
224224
return np.array(v, dtype=dtype)[()]
225-
elif dtype.kind in "c":
225+
elif dtype.kind == "c":
226226
v = (
227227
cls.decode_fill_value(v[0], dtype.type().real.dtype),
228228
cls.decode_fill_value(v[1], dtype.type().imag.dtype),
@@ -269,23 +269,23 @@ def encode_fill_value(cls, v: Any, dtype: np.dtype, object_codec: Any = None) ->
269269
return "-Infinity"
270270
else:
271271
return float(v)
272-
elif dtype.kind in "ui":
272+
elif dtype.kind in ("u", "i"):
273273
return int(v)
274274
elif dtype.kind == "b":
275275
return bool(v)
276-
elif dtype.kind in "c":
276+
elif dtype.kind == "c":
277277
c = cast(np.complex128, np.dtype(complex).type())
278278
v = (
279279
cls.encode_fill_value(v.real, c.real.dtype, object_codec),
280280
cls.encode_fill_value(v.imag, c.imag.dtype, object_codec),
281281
)
282282
return v
283-
elif dtype.kind in "SV":
283+
elif dtype.kind in ("S", "V"):
284284
v = str(base64.standard_b64encode(v), "ascii")
285285
return v
286286
elif dtype.kind == "U":
287287
return v
288-
elif dtype.kind in "mM":
288+
elif dtype.kind in ("m", "M"):
289289
return int(v.view("i8"))
290290
else:
291291
return v

tests/v2/test_core.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1947,9 +1947,7 @@ def test_attrs_n5_keywords(self):
19471947
def test_compressors(self):
19481948
compressors = [None, BZ2(), Zlib(), GZip(), MsgPack()]
19491949
if LZMA:
1950-
compressors.append(LZMA())
1951-
compressors.append(LZMA(preset=1))
1952-
compressors.append(LZMA(preset=6))
1950+
compressors.extend((LZMA(), LZMA(preset=1), LZMA(preset=6)))
19531951
for compressor in compressors:
19541952
a1 = self.create_array(shape=1000, chunks=100, compressor=compressor)
19551953
a1[0:100] = 1

0 commit comments

Comments
 (0)