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

Configure Ruff to apply flake8-bugbear/isort/pyupgrade #1864

Closed
wants to merge 7 commits into from
Closed
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: 1 addition & 2 deletions bench/compress_normal.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import sys
import timeit

import numpy as np

import line_profiler
import numpy as np
import zarr
from zarr import blosc

Expand Down
10 changes: 9 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,15 @@ extend-exclude = [
"build",
"dist",
"venv",
"docs"
"docs",
"src/zarr/v2/",
"tests/v2/"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this exclusion didn't seem to work. I'll rerun.

]
[tool.ruff.lint]
extend-select = [
"B", # flake8-bugbear
"I", # isort
"UP", # pyupgrade
]

[tool.ruff.lint]
Expand Down
9 changes: 4 additions & 5 deletions src/zarr/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from __future__ import annotations

from typing import Union

import zarr.codecs # noqa: F401
from zarr._version import version as __version__
from zarr.array import Array, AsyncArray

from zarr.array_v2 import ArrayV2
from zarr.config import config # noqa: F401
from zarr.group import AsyncGroup, Group
Expand All @@ -12,15 +12,14 @@
make_store_path,
)
from zarr.sync import sync as _sync
from zarr._version import version as __version__

# in case setuptools scm screw up and find version to be 0.0.0
assert not __version__.startswith("0.0.0")


async def open_auto_async(
store: StoreLike,
) -> Union[AsyncArray, AsyncGroup]:
) -> AsyncArray | AsyncGroup:
store_path = make_store_path(store)
try:
return await AsyncArray.open(store_path)
Expand All @@ -30,7 +29,7 @@ async def open_auto_async(

def open_auto(
store: StoreLike,
) -> Union[Array, ArrayV2, Group]:
) -> Array | ArrayV2 | Group:
object = _sync(
open_auto_async(store),
)
Expand Down
14 changes: 7 additions & 7 deletions src/zarr/abc/codec.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
from __future__ import annotations

from abc import abstractmethod
from typing import TYPE_CHECKING, Optional
from typing import TYPE_CHECKING

import numpy as np
from zarr.abc.metadata import Metadata

from zarr.abc.metadata import Metadata
from zarr.common import ArraySpec
from zarr.store import StorePath


if TYPE_CHECKING:
from typing_extensions import Self

from zarr.common import BytesLike, SliceSelection
from zarr.metadata import ArrayMetadata

Expand Down Expand Up @@ -47,7 +47,7 @@ async def encode(
self,
chunk_array: np.ndarray,
chunk_spec: ArraySpec,
) -> Optional[np.ndarray]:
) -> np.ndarray | None:
pass


Expand All @@ -65,7 +65,7 @@ async def encode(
self,
chunk_array: np.ndarray,
chunk_spec: ArraySpec,
) -> Optional[BytesLike]:
) -> BytesLike | None:
pass


Expand All @@ -76,7 +76,7 @@ async def decode_partial(
store_path: StorePath,
selection: SliceSelection,
chunk_spec: ArraySpec,
) -> Optional[np.ndarray]:
) -> np.ndarray | None:
pass


Expand Down Expand Up @@ -106,5 +106,5 @@ async def encode(
self,
chunk_array: BytesLike,
chunk_spec: ArraySpec,
) -> Optional[BytesLike]:
) -> BytesLike | None:
pass
9 changes: 5 additions & 4 deletions src/zarr/abc/metadata.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from __future__ import annotations
from typing import TYPE_CHECKING, Sequence

from collections.abc import Sequence
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from typing import Dict
from typing_extensions import Self

from dataclasses import fields, dataclass
from dataclasses import dataclass, fields

from zarr.common import JSON

Expand Down Expand Up @@ -36,7 +37,7 @@ def to_dict(self) -> JSON:
return out_dict

@classmethod
def from_dict(cls, data: Dict[str, JSON]) -> Self:
def from_dict(cls, data: dict[str, JSON]) -> Self:
"""
Create an instance of the model from a dictionary
"""
Expand Down
14 changes: 5 additions & 9 deletions src/zarr/abc/store.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
from abc import abstractmethod, ABC

from abc import ABC, abstractmethod
from collections.abc import AsyncGenerator
from typing import List, Tuple, Optional


class Store(ABC):
@abstractmethod
async def get(
self, key: str, byte_range: Optional[Tuple[int, Optional[int]]] = None
) -> Optional[bytes]:
async def get(self, key: str, byte_range: tuple[int, int | None] | None = None) -> bytes | None:
"""Retrieve the value associated with a given key.

Parameters
Expand All @@ -24,8 +20,8 @@ async def get(

@abstractmethod
async def get_partial_values(
self, key_ranges: List[Tuple[str, Tuple[int, int]]]
) -> List[Optional[bytes]]:
self, key_ranges: list[tuple[str, tuple[int, int]]]
) -> list[bytes | None]:
"""Retrieve possibly partial values from given key_ranges.

Parameters
Expand Down Expand Up @@ -88,7 +84,7 @@ def supports_partial_writes(self) -> bool:
...

@abstractmethod
async def set_partial_values(self, key_start_values: List[Tuple[str, int, bytes]]) -> None:
async def set_partial_values(self, key_start_values: list[tuple[str, int, bytes]]) -> None:
"""Store values at a given key, starting at byte range_start.

Parameters
Expand Down
49 changes: 22 additions & 27 deletions src/zarr/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,17 @@

from __future__ import annotations

from dataclasses import dataclass, replace

import json
from typing import Any, Dict, Iterable, Literal, Optional, Tuple, Union
from collections.abc import Iterable
from dataclasses import dataclass, replace
from typing import Any, Literal

import numpy as np
import numpy.typing as npt
from zarr.abc.codec import Codec

from zarr.abc.codec import Codec
from zarr.chunk_grids import RegularChunkGrid
from zarr.chunk_key_encodings import DefaultChunkKeyEncoding, V2ChunkKeyEncoding

# from zarr.array_v2 import ArrayV2
from zarr.codecs import BytesCodec
Expand All @@ -31,10 +33,7 @@
concurrent_map,
)
from zarr.config import config

from zarr.indexing import BasicIndexer, all_chunk_coords, is_total_slice
from zarr.chunk_grids import RegularChunkGrid
from zarr.chunk_key_encodings import DefaultChunkKeyEncoding, V2ChunkKeyEncoding
from zarr.metadata import ArrayMetadata, parse_indexing_order
from zarr.store import StoreLike, StorePath, make_store_path
from zarr.sync import sync
Expand Down Expand Up @@ -80,14 +79,12 @@ async def create(
shape: ChunkCoords,
dtype: npt.DTypeLike,
chunk_shape: ChunkCoords,
fill_value: Optional[Any] = None,
chunk_key_encoding: Union[
Tuple[Literal["default"], Literal[".", "/"]],
Tuple[Literal["v2"], Literal[".", "/"]],
] = ("default", "/"),
codecs: Optional[Iterable[Union[Codec, Dict[str, Any]]]] = None,
dimension_names: Optional[Iterable[str]] = None,
attributes: Optional[Dict[str, Any]] = None,
fill_value: Any | None = None,
chunk_key_encoding: tuple[Literal["default"], Literal[".", "/"]]
| tuple[Literal["v2"], Literal[".", "/"]] = ("default", "/"),
codecs: Iterable[Codec | dict[str, Any]] | None = None,
dimension_names: Iterable[str] | None = None,
attributes: dict[str, Any] | None = None,
exists_ok: bool = False,
) -> AsyncArray:
store_path = make_store_path(store)
Expand Down Expand Up @@ -129,7 +126,7 @@ async def create(
def from_dict(
cls,
store_path: StorePath,
data: Dict[str, Any],
data: dict[str, Any],
) -> AsyncArray:
metadata = ArrayMetadata.from_dict(data)
async_array = cls(metadata=metadata, store_path=store_path)
Expand Down Expand Up @@ -380,7 +377,7 @@ async def _delete_key(key: str) -> None:
await (self.store_path / ZARR_JSON).set(new_metadata.to_bytes())
return replace(self, metadata=new_metadata)

async def update_attributes(self, new_attributes: Dict[str, Any]) -> AsyncArray:
async def update_attributes(self, new_attributes: dict[str, Any]) -> AsyncArray:
new_metadata = replace(self.metadata, attributes=new_attributes)

# Write new metadata
Expand All @@ -406,14 +403,12 @@ def create(
shape: ChunkCoords,
dtype: npt.DTypeLike,
chunk_shape: ChunkCoords,
fill_value: Optional[Any] = None,
chunk_key_encoding: Union[
Tuple[Literal["default"], Literal[".", "/"]],
Tuple[Literal["v2"], Literal[".", "/"]],
] = ("default", "/"),
codecs: Optional[Iterable[Union[Codec, Dict[str, Any]]]] = None,
dimension_names: Optional[Iterable[str]] = None,
attributes: Optional[Dict[str, Any]] = None,
fill_value: Any | None = None,
chunk_key_encoding: tuple[Literal["default"], Literal[".", "/"]]
| tuple[Literal["v2"], Literal[".", "/"]] = ("default", "/"),
codecs: Iterable[Codec | dict[str, Any]] | None = None,
dimension_names: Iterable[str] | None = None,
attributes: dict[str, Any] | None = None,
exists_ok: bool = False,
) -> Array:
async_array = sync(
Expand All @@ -436,7 +431,7 @@ def create(
def from_dict(
cls,
store_path: StorePath,
data: Dict[str, Any],
data: dict[str, Any],
) -> Array:
async_array = AsyncArray.from_dict(store_path=store_path, data=data)
return cls(async_array)
Expand Down Expand Up @@ -508,7 +503,7 @@ def resize(self, new_shape: ChunkCoords) -> Array:
)
)

def update_attributes(self, new_attributes: Dict[str, Any]) -> Array:
def update_attributes(self, new_attributes: dict[str, Any]) -> Array:
return type(self)(
sync(
self._async_array.update_attributes(new_attributes),
Expand Down
Loading
Loading