|
5 | 5 | from asyncio import gather |
6 | 6 | from collections.abc import Iterable |
7 | 7 | from dataclasses import dataclass, field, replace |
8 | | -from functools import cached_property |
9 | 8 | from itertools import starmap |
10 | 9 | from logging import getLogger |
11 | 10 | from typing import ( |
|
32 | 31 | from zarr.codecs._v2 import V2Codec |
33 | 32 | from zarr.codecs.bytes import BytesCodec |
34 | 33 | from zarr.core._info import ArrayInfo |
35 | | -from zarr.core.array_spec import ArrayConfig, ArrayConfigLike, ArraySpec, parse_array_config |
| 34 | +from zarr.core.array_spec import ArrayConfig, ArrayConfigLike, parse_array_config |
36 | 35 | from zarr.core.attributes import Attributes |
37 | 36 | from zarr.core.buffer import ( |
38 | 37 | BufferPrototype, |
|
42 | 41 | default_buffer_prototype, |
43 | 42 | ) |
44 | 43 | from zarr.core.buffer.cpu import buffer_prototype as cpu_buffer_prototype |
45 | | -from zarr.core.chunk_grids import ChunkGrid, RegularChunkGrid, _auto_partition, normalize_chunks |
| 44 | +from zarr.core.chunk_grids import RegularChunkGrid, _auto_partition, normalize_chunks |
46 | 45 | from zarr.core.chunk_key_encodings import ( |
47 | 46 | ChunkKeyEncoding, |
48 | 47 | ChunkKeyEncodingLike, |
@@ -951,13 +950,6 @@ def chunks(self) -> ChunkCoords: |
951 | 950 | """ |
952 | 951 | return self.metadata.chunks |
953 | 952 |
|
954 | | - @cached_property |
955 | | - def chunk_grid(self) -> ChunkGrid: |
956 | | - if self.metadata.zarr_format == 2: |
957 | | - return RegularChunkGrid(chunk_shape=self.chunks) |
958 | | - else: |
959 | | - return self.metadata.chunk_grid |
960 | | - |
961 | 953 | @property |
962 | 954 | def shards(self) -> ChunkCoords | None: |
963 | 955 | """Returns the shard shape of the Array. |
@@ -1281,20 +1273,6 @@ def nbytes(self) -> int: |
1281 | 1273 | """ |
1282 | 1274 | return self.size * self.dtype.itemsize |
1283 | 1275 |
|
1284 | | - def get_chunk_spec( |
1285 | | - self, _chunk_coords: ChunkCoords, array_config: ArrayConfig, prototype: BufferPrototype |
1286 | | - ) -> ArraySpec: |
1287 | | - assert isinstance(self.chunk_grid, RegularChunkGrid), ( |
1288 | | - "Currently, only regular chunk grid is supported" |
1289 | | - ) |
1290 | | - return ArraySpec( |
1291 | | - shape=self.chunk_grid.chunk_shape, |
1292 | | - dtype=self._zdtype, |
1293 | | - fill_value=self.metadata.fill_value, |
1294 | | - config=array_config, |
1295 | | - prototype=prototype, |
1296 | | - ) |
1297 | | - |
1298 | 1276 | async def _get_selection( |
1299 | 1277 | self, |
1300 | 1278 | indexer: Indexer, |
@@ -1334,7 +1312,7 @@ async def _get_selection( |
1334 | 1312 | [ |
1335 | 1313 | ( |
1336 | 1314 | self.store_path / self.metadata.encode_chunk_key(chunk_coords), |
1337 | | - self.get_chunk_spec(chunk_coords, _config, prototype=prototype), |
| 1315 | + self.metadata.get_chunk_spec(chunk_coords, _config, prototype=prototype), |
1338 | 1316 | chunk_selection, |
1339 | 1317 | out_selection, |
1340 | 1318 | is_complete_chunk, |
@@ -1389,7 +1367,7 @@ async def getitem( |
1389 | 1367 | indexer = BasicIndexer( |
1390 | 1368 | selection, |
1391 | 1369 | shape=self.metadata.shape, |
1392 | | - chunk_grid=self.chunk_grid, |
| 1370 | + chunk_grid=self.metadata.chunk_grid, |
1393 | 1371 | ) |
1394 | 1372 | return await self._get_selection(indexer, prototype=prototype) |
1395 | 1373 |
|
@@ -1464,7 +1442,7 @@ async def _set_selection( |
1464 | 1442 | [ |
1465 | 1443 | ( |
1466 | 1444 | self.store_path / self.metadata.encode_chunk_key(chunk_coords), |
1467 | | - self.get_chunk_spec(chunk_coords, _config, prototype), |
| 1445 | + self.metadata.get_chunk_spec(chunk_coords, _config, prototype), |
1468 | 1446 | chunk_selection, |
1469 | 1447 | out_selection, |
1470 | 1448 | is_complete_chunk, |
@@ -1519,7 +1497,7 @@ async def setitem( |
1519 | 1497 | indexer = BasicIndexer( |
1520 | 1498 | selection, |
1521 | 1499 | shape=self.metadata.shape, |
1522 | | - chunk_grid=self.chunk_grid, |
| 1500 | + chunk_grid=self.metadata.chunk_grid, |
1523 | 1501 | ) |
1524 | 1502 | return await self._set_selection(indexer, value, prototype=prototype) |
1525 | 1503 |
|
@@ -1556,8 +1534,8 @@ async def resize(self, new_shape: ShapeLike, delete_outside_chunks: bool = True) |
1556 | 1534 |
|
1557 | 1535 | if delete_outside_chunks: |
1558 | 1536 | # Remove all chunks outside of the new shape |
1559 | | - old_chunk_coords = set(self.chunk_grid.all_chunk_coords(self.metadata.shape)) |
1560 | | - new_chunk_coords = set(self.chunk_grid.all_chunk_coords(new_shape)) |
| 1537 | + old_chunk_coords = set(self.metadata.chunk_grid.all_chunk_coords(self.metadata.shape)) |
| 1538 | + new_chunk_coords = set(self.metadata.chunk_grid.all_chunk_coords(new_shape)) |
1561 | 1539 |
|
1562 | 1540 | async def _delete_key(key: str) -> None: |
1563 | 1541 | await (self.store_path / key).delete() |
@@ -2687,7 +2665,7 @@ def get_basic_selection( |
2687 | 2665 | prototype = default_buffer_prototype() |
2688 | 2666 | return sync( |
2689 | 2667 | self._async_array._get_selection( |
2690 | | - BasicIndexer(selection, self.shape, self._async_array.chunk_grid), |
| 2668 | + BasicIndexer(selection, self.shape, self.metadata.chunk_grid), |
2691 | 2669 | out=out, |
2692 | 2670 | fields=fields, |
2693 | 2671 | prototype=prototype, |
@@ -2787,7 +2765,7 @@ def set_basic_selection( |
2787 | 2765 | """ |
2788 | 2766 | if prototype is None: |
2789 | 2767 | prototype = default_buffer_prototype() |
2790 | | - indexer = BasicIndexer(selection, self.shape, self._async_array.chunk_grid) |
| 2768 | + indexer = BasicIndexer(selection, self.shape, self.metadata.chunk_grid) |
2791 | 2769 | sync(self._async_array._set_selection(indexer, value, fields=fields, prototype=prototype)) |
2792 | 2770 |
|
2793 | 2771 | @_deprecate_positional_args |
@@ -2908,7 +2886,7 @@ def get_orthogonal_selection( |
2908 | 2886 | """ |
2909 | 2887 | if prototype is None: |
2910 | 2888 | prototype = default_buffer_prototype() |
2911 | | - indexer = OrthogonalIndexer(selection, self.shape, self._async_array.chunk_grid) |
| 2889 | + indexer = OrthogonalIndexer(selection, self.shape, self.metadata.chunk_grid) |
2912 | 2890 | return sync( |
2913 | 2891 | self._async_array._get_selection( |
2914 | 2892 | indexer=indexer, out=out, fields=fields, prototype=prototype |
@@ -3021,7 +2999,7 @@ def set_orthogonal_selection( |
3021 | 2999 | """ |
3022 | 3000 | if prototype is None: |
3023 | 3001 | prototype = default_buffer_prototype() |
3024 | | - indexer = OrthogonalIndexer(selection, self.shape, self._async_array.chunk_grid) |
| 3002 | + indexer = OrthogonalIndexer(selection, self.shape, self.metadata.chunk_grid) |
3025 | 3003 | return sync( |
3026 | 3004 | self._async_array._set_selection(indexer, value, fields=fields, prototype=prototype) |
3027 | 3005 | ) |
@@ -3102,7 +3080,7 @@ def get_mask_selection( |
3102 | 3080 |
|
3103 | 3081 | if prototype is None: |
3104 | 3082 | prototype = default_buffer_prototype() |
3105 | | - indexer = MaskIndexer(mask, self.shape, self._async_array.chunk_grid) |
| 3083 | + indexer = MaskIndexer(mask, self.shape, self.metadata.chunk_grid) |
3106 | 3084 | return sync( |
3107 | 3085 | self._async_array._get_selection( |
3108 | 3086 | indexer=indexer, out=out, fields=fields, prototype=prototype |
@@ -3185,7 +3163,7 @@ def set_mask_selection( |
3185 | 3163 | """ |
3186 | 3164 | if prototype is None: |
3187 | 3165 | prototype = default_buffer_prototype() |
3188 | | - indexer = MaskIndexer(mask, self.shape, self._async_array.chunk_grid) |
| 3166 | + indexer = MaskIndexer(mask, self.shape, self.metadata.chunk_grid) |
3189 | 3167 | sync(self._async_array._set_selection(indexer, value, fields=fields, prototype=prototype)) |
3190 | 3168 |
|
3191 | 3169 | @_deprecate_positional_args |
@@ -3266,7 +3244,7 @@ def get_coordinate_selection( |
3266 | 3244 | """ |
3267 | 3245 | if prototype is None: |
3268 | 3246 | prototype = default_buffer_prototype() |
3269 | | - indexer = CoordinateIndexer(selection, self.shape, self._async_array.chunk_grid) |
| 3247 | + indexer = CoordinateIndexer(selection, self.shape, self.metadata.chunk_grid) |
3270 | 3248 | out_array = sync( |
3271 | 3249 | self._async_array._get_selection( |
3272 | 3250 | indexer=indexer, out=out, fields=fields, prototype=prototype |
@@ -3352,7 +3330,7 @@ def set_coordinate_selection( |
3352 | 3330 | if prototype is None: |
3353 | 3331 | prototype = default_buffer_prototype() |
3354 | 3332 | # setup indexer |
3355 | | - indexer = CoordinateIndexer(selection, self.shape, self._async_array.chunk_grid) |
| 3333 | + indexer = CoordinateIndexer(selection, self.shape, self.metadata.chunk_grid) |
3356 | 3334 |
|
3357 | 3335 | # handle value - need ndarray-like flatten value |
3358 | 3336 | if not is_scalar(value, self.dtype): |
@@ -3468,7 +3446,7 @@ def get_block_selection( |
3468 | 3446 | """ |
3469 | 3447 | if prototype is None: |
3470 | 3448 | prototype = default_buffer_prototype() |
3471 | | - indexer = BlockIndexer(selection, self.shape, self._async_array.chunk_grid) |
| 3449 | + indexer = BlockIndexer(selection, self.shape, self.metadata.chunk_grid) |
3472 | 3450 | return sync( |
3473 | 3451 | self._async_array._get_selection( |
3474 | 3452 | indexer=indexer, out=out, fields=fields, prototype=prototype |
@@ -3562,7 +3540,7 @@ def set_block_selection( |
3562 | 3540 | """ |
3563 | 3541 | if prototype is None: |
3564 | 3542 | prototype = default_buffer_prototype() |
3565 | | - indexer = BlockIndexer(selection, self.shape, self._async_array.chunk_grid) |
| 3543 | + indexer = BlockIndexer(selection, self.shape, self.metadata.chunk_grid) |
3566 | 3544 | sync(self._async_array._set_selection(indexer, value, fields=fields, prototype=prototype)) |
3567 | 3545 |
|
3568 | 3546 | @property |
|
0 commit comments