Skip to content
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
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ repos:
- obstore>=0.5.1
# Tests
- pytest
- hypothesis
- repo: https://github.com/scientific-python/cookie
rev: 2025.01.22
hooks:
Expand Down
1 change: 1 addition & 0 deletions changes/3045.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed the typing of ``dimension_names`` arguments throughout so that it now accepts iterables that contain `None` alongside `str`.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ enable_error_code = ["ignore-without-code", "redundant-expr", "truthy-bool"]
[[tool.mypy.overrides]]
module = [
"tests.package_with_entrypoint.*",
"zarr.testing.stateful",
"tests.test_codecs.test_transpose",
"tests.test_config"
]
Expand All @@ -365,7 +366,6 @@ strict = false
# and fix the errors
[[tool.mypy.overrides]]
module = [
"zarr.testing.stateful", # lots of hypothesis decorator errors
"tests.test_codecs.test_codecs",
"tests.test_metadata.*",
"tests.test_store.*",
Expand Down
3 changes: 2 additions & 1 deletion src/zarr/api/asynchronous.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
JSON,
AccessModeLiteral,
ChunkCoords,
DimensionNames,
MemoryOrder,
ZarrFormat,
_default_zarr_format,
Expand Down Expand Up @@ -865,7 +866,7 @@ async def create(
| None
) = None,
codecs: Iterable[Codec | dict[str, JSON]] | None = None,
dimension_names: Iterable[str] | None = None,
dimension_names: DimensionNames = None,
storage_options: dict[str, Any] | None = None,
config: ArrayConfigLike | None = None,
**kwargs: Any,
Expand Down
7 changes: 4 additions & 3 deletions src/zarr/api/synchronous.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
JSON,
AccessModeLiteral,
ChunkCoords,
DimensionNames,
MemoryOrder,
ShapeLike,
ZarrFormat,
Expand Down Expand Up @@ -626,7 +627,7 @@ def create(
| None
) = None,
codecs: Iterable[Codec | dict[str, JSON]] | None = None,
dimension_names: Iterable[str] | None = None,
dimension_names: DimensionNames = None,
storage_options: dict[str, Any] | None = None,
config: ArrayConfigLike | None = None,
**kwargs: Any,
Expand Down Expand Up @@ -761,7 +762,7 @@ def create_array(
zarr_format: ZarrFormat | None = 3,
attributes: dict[str, JSON] | None = None,
chunk_key_encoding: ChunkKeyEncodingLike | None = None,
dimension_names: Iterable[str] | None = None,
dimension_names: DimensionNames = None,
storage_options: dict[str, Any] | None = None,
overwrite: bool = False,
config: ArrayConfigLike | None = None,
Expand Down Expand Up @@ -926,7 +927,7 @@ def from_array(
zarr_format: ZarrFormat | None = None,
attributes: dict[str, JSON] | None = None,
chunk_key_encoding: ChunkKeyEncodingLike | None = None,
dimension_names: Iterable[str] | None = None,
dimension_names: DimensionNames = None,
storage_options: dict[str, Any] | None = None,
overwrite: bool = False,
config: ArrayConfigLike | None = None,
Expand Down
35 changes: 18 additions & 17 deletions src/zarr/core/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
ZARRAY_JSON,
ZATTRS_JSON,
ChunkCoords,
DimensionNames,
MemoryOrder,
ShapeLike,
ZarrFormat,
Expand Down Expand Up @@ -330,7 +331,7 @@ async def create(
| None
) = None,
codecs: Iterable[Codec | dict[str, JSON]] | None = None,
dimension_names: Iterable[str] | None = None,
dimension_names: DimensionNames = None,
# runtime
overwrite: bool = False,
data: npt.ArrayLike | None = None,
Expand Down Expand Up @@ -358,7 +359,7 @@ async def create(
| None
) = None,
codecs: Iterable[Codec | dict[str, JSON]] | None = None,
dimension_names: Iterable[str] | None = None,
dimension_names: DimensionNames = None,
# runtime
overwrite: bool = False,
data: npt.ArrayLike | None = None,
Expand Down Expand Up @@ -386,7 +387,7 @@ async def create(
| None
) = None,
codecs: Iterable[Codec | dict[str, JSON]] | None = None,
dimension_names: Iterable[str] | None = None,
dimension_names: DimensionNames = None,
# v2 only
chunks: ShapeLike | None = None,
dimension_separator: Literal[".", "/"] | None = None,
Expand Down Expand Up @@ -421,7 +422,7 @@ async def create(
| None
) = None,
codecs: Iterable[Codec | dict[str, JSON]] | None = None,
dimension_names: Iterable[str] | None = None,
dimension_names: DimensionNames = None,
# v2 only
chunks: ShapeLike | None = None,
dimension_separator: Literal[".", "/"] | None = None,
Expand Down Expand Up @@ -473,7 +474,7 @@ async def create(

These defaults can be changed by modifying the value of ``array.v3_default_filters``,
``array.v3_default_serializer`` and ``array.v3_default_compressors`` in :mod:`zarr.core.config`.
dimension_names : Iterable[str], optional
dimension_names : Iterable[str | None], optional
The names of the dimensions (default is None).
Zarr format 3 only. Zarr format 2 arrays should not use this parameter.
chunks : ShapeLike, optional
Expand Down Expand Up @@ -562,7 +563,7 @@ async def _create(
| None
) = None,
codecs: Iterable[Codec | dict[str, JSON]] | None = None,
dimension_names: Iterable[str] | None = None,
dimension_names: DimensionNames = None,
# v2 only
chunks: ShapeLike | None = None,
dimension_separator: Literal[".", "/"] | None = None,
Expand Down Expand Up @@ -672,7 +673,7 @@ def _create_metadata_v3(
fill_value: Any | None = None,
chunk_key_encoding: ChunkKeyEncodingLike | None = None,
codecs: Iterable[Codec | dict[str, JSON]] | None = None,
dimension_names: Iterable[str] | None = None,
dimension_names: DimensionNames = None,
attributes: dict[str, JSON] | None = None,
) -> ArrayV3Metadata:
"""
Expand Down Expand Up @@ -723,7 +724,7 @@ async def _create_v3(
| None
) = None,
codecs: Iterable[Codec | dict[str, JSON]] | None = None,
dimension_names: Iterable[str] | None = None,
dimension_names: DimensionNames = None,
attributes: dict[str, JSON] | None = None,
overwrite: bool = False,
) -> AsyncArray[ArrayV3Metadata]:
Expand Down Expand Up @@ -1743,7 +1744,7 @@ def create(
| None
) = None,
codecs: Iterable[Codec | dict[str, JSON]] | None = None,
dimension_names: Iterable[str] | None = None,
dimension_names: DimensionNames = None,
# v2 only
chunks: ChunkCoords | None = None,
dimension_separator: Literal[".", "/"] | None = None,
Expand Down Expand Up @@ -1788,7 +1789,7 @@ def create(

These defaults can be changed by modifying the value of ``array.v3_default_filters``,
``array.v3_default_serializer`` and ``array.v3_default_compressors`` in :mod:`zarr.core.config`.
dimension_names : Iterable[str], optional
dimension_names : Iterable[str | None], optional
The names of the dimensions (default is None).
Zarr format 3 only. Zarr format 2 arrays should not use this parameter.
chunks : ChunkCoords, optional
Expand Down Expand Up @@ -1872,7 +1873,7 @@ def _create(
| None
) = None,
codecs: Iterable[Codec | dict[str, JSON]] | None = None,
dimension_names: Iterable[str] | None = None,
dimension_names: DimensionNames = None,
# v2 only
chunks: ChunkCoords | None = None,
dimension_separator: Literal[".", "/"] | None = None,
Expand Down Expand Up @@ -3821,7 +3822,7 @@ async def from_array(
zarr_format: ZarrFormat | None = None,
attributes: dict[str, JSON] | None = None,
chunk_key_encoding: ChunkKeyEncodingLike | None = None,
dimension_names: Iterable[str] | None = None,
dimension_names: DimensionNames = None,
storage_options: dict[str, Any] | None = None,
overwrite: bool = False,
config: ArrayConfig | ArrayConfigLike | None = None,
Expand Down Expand Up @@ -3929,7 +3930,7 @@ async def from_array(
For Zarr format 2, the default is ``{"name": "v2", "separator": "."}}``.
If not specified and the data array has the same zarr format as the target array,
the chunk key encoding of the data array is used.
dimension_names : Iterable[str], optional
dimension_names : Iterable[str | None], optional
The names of the dimensions (default is None).
Zarr format 3 only. Zarr format 2 arrays should not use this parameter.
If not specified, defaults to the dimension names of the data array.
Expand Down Expand Up @@ -4083,7 +4084,7 @@ async def init_array(
zarr_format: ZarrFormat | None = 3,
attributes: dict[str, JSON] | None = None,
chunk_key_encoding: ChunkKeyEncodingLike | None = None,
dimension_names: Iterable[str] | None = None,
dimension_names: DimensionNames = None,
overwrite: bool = False,
config: ArrayConfigLike | None,
) -> AsyncArray[ArrayV3Metadata] | AsyncArray[ArrayV2Metadata]:
Expand Down Expand Up @@ -4298,7 +4299,7 @@ async def create_array(
zarr_format: ZarrFormat | None = 3,
attributes: dict[str, JSON] | None = None,
chunk_key_encoding: ChunkKeyEncodingLike | None = None,
dimension_names: Iterable[str] | None = None,
dimension_names: DimensionNames = None,
storage_options: dict[str, Any] | None = None,
overwrite: bool = False,
config: ArrayConfigLike | None = None,
Expand Down Expand Up @@ -4477,7 +4478,7 @@ def _parse_keep_array_attr(
order: MemoryOrder | None,
zarr_format: ZarrFormat | None,
chunk_key_encoding: ChunkKeyEncodingLike | None,
dimension_names: Iterable[str] | None,
dimension_names: DimensionNames,
) -> tuple[
ChunkCoords | Literal["auto"],
ShardsLike | None,
Expand All @@ -4488,7 +4489,7 @@ def _parse_keep_array_attr(
MemoryOrder | None,
ZarrFormat,
ChunkKeyEncodingLike | None,
Iterable[str] | None,
DimensionNames,
]:
if isinstance(data, Array):
if chunks == "keep":
Expand Down
1 change: 1 addition & 0 deletions src/zarr/core/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
JSON = str | int | float | Mapping[str, "JSON"] | Sequence["JSON"] | None
MemoryOrder = Literal["C", "F"]
AccessModeLiteral = Literal["r", "r+", "a", "w", "w-"]
DimensionNames = Iterable[str | None] | None


def product(tup: ChunkCoords) -> int:
Expand Down
7 changes: 4 additions & 3 deletions src/zarr/core/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
ZGROUP_JSON,
ZMETADATA_V2_JSON,
ChunkCoords,
DimensionNames,
NodeType,
ShapeLike,
ZarrFormat,
Expand Down Expand Up @@ -1006,7 +1007,7 @@ async def create_array(
order: MemoryOrder | None = None,
attributes: dict[str, JSON] | None = None,
chunk_key_encoding: ChunkKeyEncodingLike | None = None,
dimension_names: Iterable[str] | None = None,
dimension_names: DimensionNames = None,
storage_options: dict[str, Any] | None = None,
overwrite: bool = False,
config: ArrayConfig | ArrayConfigLike | None = None,
Expand Down Expand Up @@ -2381,7 +2382,7 @@ def create_array(
order: MemoryOrder | None = "C",
attributes: dict[str, JSON] | None = None,
chunk_key_encoding: ChunkKeyEncodingLike | None = None,
dimension_names: Iterable[str] | None = None,
dimension_names: DimensionNames = None,
storage_options: dict[str, Any] | None = None,
overwrite: bool = False,
config: ArrayConfig | ArrayConfigLike | None = None,
Expand Down Expand Up @@ -2775,7 +2776,7 @@ def array(
order: MemoryOrder | None = "C",
attributes: dict[str, JSON] | None = None,
chunk_key_encoding: ChunkKeyEncodingLike | None = None,
dimension_names: Iterable[str] | None = None,
dimension_names: DimensionNames = None,
storage_options: dict[str, Any] | None = None,
overwrite: bool = False,
config: ArrayConfig | ArrayConfigLike | None = None,
Expand Down
5 changes: 3 additions & 2 deletions src/zarr/core/metadata/v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
JSON,
ZARR_JSON,
ChunkCoords,
DimensionNames,
parse_named_configuration,
parse_shapelike,
)
Expand Down Expand Up @@ -242,7 +243,7 @@ class ArrayV3Metadata(Metadata):
fill_value: Any
codecs: tuple[Codec, ...]
attributes: dict[str, Any] = field(default_factory=dict)
dimension_names: tuple[str, ...] | None = None
dimension_names: tuple[str | None, ...] | None = None
zarr_format: Literal[3] = field(default=3, init=False)
node_type: Literal["array"] = field(default="array", init=False)
storage_transformers: tuple[dict[str, JSON], ...]
Expand All @@ -257,7 +258,7 @@ def __init__(
fill_value: Any,
codecs: Iterable[Codec | dict[str, JSON]],
attributes: dict[str, JSON] | None,
dimension_names: Iterable[str] | None,
dimension_names: DimensionNames,
storage_transformers: Iterable[dict[str, JSON]] | None = None,
) -> None:
"""
Expand Down
4 changes: 2 additions & 2 deletions src/zarr/testing/stateful.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,8 @@
self.store.clear()

@rule(key=zarr_keys(), data=st.binary(min_size=0, max_size=MAX_BINARY_SIZE))
def set(self, key: str, data: DataObject) -> None:
note(f"(set) Setting {key!r} with {data}")
def set(self, key: str, data: bytes) -> None:
note(f"(set) Setting {key!r} with {data!r}")

Check warning on line 330 in src/zarr/testing/stateful.py

View check run for this annotation

Codecov / codecov/patch

src/zarr/testing/stateful.py#L330

Added line #L330 was not covered by tests
assert not self.store.read_only
data_buf = cpu.Buffer.from_bytes(data)
self.store.set(key, data_buf)
Expand Down
Loading