Skip to content

Commit 23d0d21

Browse files
authored
Merge branch 'main' into fix/sharded-mixed-indexing-3691
2 parents 7d78645 + a02d996 commit 23d0d21

3 files changed

Lines changed: 41 additions & 9 deletions

File tree

src/zarr/core/array.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,24 +1235,28 @@ def basename(self) -> str:
12351235
@property
12361236
def cdata_shape(self) -> tuple[int, ...]:
12371237
"""
1238-
The shape of the chunk grid for this array.
1238+
The number of chunks along each dimension.
1239+
1240+
When sharding is used, this counts inner chunks (not shards) per dimension.
12391241
12401242
Returns
12411243
-------
12421244
tuple[int, ...]
1243-
The shape of the chunk grid for this array.
1245+
The number of chunks along each dimension.
12441246
"""
12451247
return self._chunk_grid_shape
12461248

12471249
@property
12481250
def _chunk_grid_shape(self) -> tuple[int, ...]:
12491251
"""
1250-
The shape of the chunk grid for this array.
1252+
The number of chunks along each dimension.
1253+
1254+
When sharding is used, this counts inner chunks (not shards) per dimension.
12511255
12521256
Returns
12531257
-------
12541258
tuple[int, ...]
1255-
The shape of the chunk grid for this array.
1259+
The number of chunks along each dimension.
12561260
"""
12571261
return tuple(starmap(ceildiv, zip(self.shape, self.chunks, strict=True)))
12581262

@@ -2399,14 +2403,23 @@ def compressors(self) -> tuple[Numcodec, ...] | tuple[BytesBytesCodec, ...]:
23992403
@property
24002404
def cdata_shape(self) -> tuple[int, ...]:
24012405
"""
2402-
The shape of the chunk grid for this array.
2406+
The number of chunks along each dimension.
2407+
2408+
When sharding is used, this counts inner chunks (not shards) per dimension.
24032409
"""
24042410
return self.async_array._chunk_grid_shape
24052411

24062412
@property
24072413
def _chunk_grid_shape(self) -> tuple[int, ...]:
24082414
"""
2409-
The shape of the chunk grid for this array.
2415+
The number of chunks along each dimension.
2416+
2417+
When sharding is used, this counts inner chunks (not shards) per dimension.
2418+
2419+
Returns
2420+
-------
2421+
tuple[int, ...]
2422+
The number of chunks along each dimension.
24102423
"""
24112424
return self.async_array._chunk_grid_shape
24122425

src/zarr/core/dtype/npy/float.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,16 @@ def _check_scalar(self, data: object) -> TypeGuard[FloatLike]:
201201
TypeGuard[FloatLike]
202202
True if the input is a valid scalar value, False otherwise.
203203
"""
204+
if isinstance(data, str):
205+
# Only accept strings that are valid float representations (e.g. "NaN", "inf").
206+
# Plain strings that cannot be converted should return False so that cast_scalar
207+
# raises TypeError rather than a confusing ValueError.
208+
try:
209+
self.to_native_dtype().type(data)
210+
except (ValueError, OverflowError):
211+
return False
212+
else:
213+
return True
204214
return isinstance(data, FloatLike)
205215

206216
def _cast_scalar_unchecked(self, data: FloatLike) -> TFloatScalar_co:

tests/test_dtype/test_npy/test_float.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,10 @@ class TestFloat16(_BaseTestFloat):
6565
(Float16(), -1.0, np.float16(-1.0)),
6666
(Float16(), "NaN", np.float16("NaN")),
6767
)
68-
invalid_scalar_params = ((Float16(), {"set!"}),)
68+
invalid_scalar_params = (
69+
(Float16(), {"set!"}),
70+
(Float16(), "not_a_float"),
71+
)
6972
hex_string_params = (("0x7fc0", np.nan), ("0x7fc1", np.nan), ("0x3c00", 1.0))
7073
item_size_params = (Float16(),)
7174

@@ -113,7 +116,10 @@ class TestFloat32(_BaseTestFloat):
113116
(Float32(), -1.0, np.float32(-1.0)),
114117
(Float32(), "NaN", np.float32("NaN")),
115118
)
116-
invalid_scalar_params = ((Float32(), {"set!"}),)
119+
invalid_scalar_params = (
120+
(Float32(), {"set!"}),
121+
(Float32(), "not_a_float"),
122+
)
117123
hex_string_params = (("0x7fc00000", np.nan), ("0x7fc00001", np.nan), ("0x3f800000", 1.0))
118124
item_size_params = (Float32(),)
119125

@@ -160,7 +166,10 @@ class TestFloat64(_BaseTestFloat):
160166
(Float64(), -1.0, np.float64(-1.0)),
161167
(Float64(), "NaN", np.float64("NaN")),
162168
)
163-
invalid_scalar_params = ((Float64(), {"set!"}),)
169+
invalid_scalar_params = (
170+
(Float64(), {"set!"}),
171+
(Float64(), "not_a_float"),
172+
)
164173
hex_string_params = (
165174
("0x7ff8000000000000", np.nan),
166175
("0x7ff8000000000001", np.nan),

0 commit comments

Comments
 (0)