Skip to content

Commit

Permalink
Apply assorted ruff/refurb rules (FURB) (#1873)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
DimitriPapadopoulos and jhamman authored May 17, 2024
1 parent 333f37f commit 88946d2
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
3 changes: 2 additions & 1 deletion src/zarr/codecs/sharding.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from dataclasses import dataclass, field, replace
from enum import Enum
from functools import lru_cache
from operator import itemgetter
from typing import TYPE_CHECKING, NamedTuple

import numpy as np
Expand Down Expand Up @@ -124,7 +125,7 @@ def is_dense(self, chunk_byte_length: int) -> bool:
for offset, length in self.offsets_and_lengths
if offset != MAX_UINT_64
],
key=lambda entry: entry[0],
key=itemgetter(0),
)

# Are all non-empty offsets unique?
Expand Down
3 changes: 2 additions & 1 deletion src/zarr/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import asyncio
import contextvars
import functools
import operator
from collections.abc import Iterable
from dataclasses import dataclass
from enum import Enum
Expand All @@ -28,7 +29,7 @@


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


T = TypeVar("T", bound=tuple[Any, ...])
Expand Down
10 changes: 5 additions & 5 deletions src/zarr/v2/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,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 @@ -269,23 +269,23 @@ def encode_fill_value(cls, v: Any, dtype: np.dtype, object_codec: Any = None) ->
return "-Infinity"
else:
return float(v)
elif dtype.kind in "ui":
elif dtype.kind in ("u", "i"):
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),
cls.encode_fill_value(v.imag, c.imag.dtype, object_codec),
)
return v
elif dtype.kind in "SV":
elif dtype.kind in ("S", "V"):
v = str(base64.standard_b64encode(v), "ascii")
return v
elif dtype.kind == "U":
return v
elif dtype.kind in "mM":
elif dtype.kind in ("m", "M"):
return int(v.view("i8"))
else:
return v
Expand Down
4 changes: 1 addition & 3 deletions tests/v2/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1947,9 +1947,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 88946d2

Please sign in to comment.