Skip to content

Commit c0026e9

Browse files
committed
resolve circular import by moving ceildiv to common.py
1 parent d5d5494 commit c0026e9

File tree

5 files changed

+14
-12
lines changed

5 files changed

+14
-12
lines changed

src/zarr/core/array.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
ZarrFormat,
6262
_default_zarr_format,
6363
_warn_order_kwarg,
64+
ceildiv,
6465
concurrent_map,
6566
parse_shapelike,
6667
product,
@@ -94,7 +95,6 @@
9495
Selection,
9596
VIndex,
9697
_iter_grid,
97-
ceildiv,
9898
check_fields,
9999
check_no_multi_fields,
100100
is_pure_fancy_indexing,

src/zarr/core/chunk_grids.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
ChunkCoords,
1919
ChunkCoordsLike,
2020
ShapeLike,
21+
ceildiv,
2122
parse_named_configuration,
2223
parse_shapelike,
2324
)
24-
from zarr.core.indexing import ceildiv
2525

2626
if TYPE_CHECKING:
2727
from collections.abc import Iterator

src/zarr/core/common.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import asyncio
44
import functools
5+
import math
56
import operator
67
import warnings
78
from collections.abc import Iterable, Mapping, Sequence
@@ -69,6 +70,12 @@ def product(tup: ChunkCoords) -> int:
6970
return functools.reduce(operator.mul, tup, 1)
7071

7172

73+
def ceildiv(a: float, b: float) -> int:
74+
if a == 0:
75+
return 0
76+
return math.ceil(a / b)
77+
78+
7279
T = TypeVar("T", bound=tuple[Any, ...])
7380
V = TypeVar("V")
7481

src/zarr/core/indexing.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,15 @@
2626
import numpy as np
2727
import numpy.typing as npt
2828

29-
from zarr.core.common import product
29+
from zarr.core.common import ceildiv, product
30+
from zarr.core.metadata import T_ArrayMetadata
3031

3132
if TYPE_CHECKING:
3233
from zarr.core.array import Array, AsyncArray
3334
from zarr.core.buffer import NDArrayLikeOrScalar
3435
from zarr.core.chunk_grids import ChunkGrid
3536
from zarr.core.common import ChunkCoords
36-
from zarr.core.metadata import T_ArrayMetadata
37+
3738

3839
IntSequence = list[int] | npt.NDArray[np.intp]
3940
ArrayOfIntOrBool = npt.NDArray[np.intp] | npt.NDArray[np.bool_]
@@ -95,12 +96,6 @@ class Indexer(Protocol):
9596
def __iter__(self) -> Iterator[ChunkProjection]: ...
9697

9798

98-
def ceildiv(a: float, b: float) -> int:
99-
if a == 0:
100-
return 0
101-
return math.ceil(a / b)
102-
103-
10499
_ArrayIndexingOrder: TypeAlias = Literal["lexicographic"]
105100

106101

tests/test_array.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
from zarr.core.buffer import NDArrayLike, NDArrayLikeOrScalar, default_buffer_prototype
4242
from zarr.core.chunk_grids import _auto_partition
4343
from zarr.core.chunk_key_encodings import ChunkKeyEncodingParams
44-
from zarr.core.common import JSON, ZarrFormat
44+
from zarr.core.common import JSON, ZarrFormat, ceildiv
4545
from zarr.core.dtype import (
4646
DateTime64,
4747
Float32,
@@ -59,7 +59,7 @@
5959
from zarr.core.dtype.npy.common import NUMPY_ENDIANNESS_STR, endianness_from_numpy_str
6060
from zarr.core.dtype.npy.string import UTF8Base
6161
from zarr.core.group import AsyncGroup
62-
from zarr.core.indexing import BasicIndexer, ceildiv
62+
from zarr.core.indexing import BasicIndexer
6363
from zarr.core.metadata.v2 import ArrayV2Metadata
6464
from zarr.core.metadata.v3 import ArrayV3Metadata
6565
from zarr.core.sync import sync

0 commit comments

Comments
 (0)