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

Apply assorted ruff/refurb rules (FURB) #1873

Merged
merged 4 commits into from
May 17, 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
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
Loading