|
10 | 10 |
|
11 | 11 | from zarr.abc.store import Store |
12 | 12 | from zarr.core.array import Array, AsyncArray, get_array_metadata |
| 13 | +from zarr.core.buffer import NDArrayLike |
13 | 14 | from zarr.core.common import ( |
14 | 15 | JSON, |
15 | 16 | AccessModeLiteral, |
|
31 | 32 | from collections.abc import Iterable |
32 | 33 |
|
33 | 34 | from zarr.abc.codec import Codec |
34 | | - from zarr.core.buffer import NDArrayLike |
35 | 35 | from zarr.core.chunk_key_encodings import ChunkKeyEncoding |
36 | 36 |
|
37 | 37 | # TODO: this type could use some more thought |
@@ -434,6 +434,8 @@ async def save_array( |
434 | 434 | _handle_zarr_version_or_format(zarr_version=zarr_version, zarr_format=zarr_format) |
435 | 435 | or _default_zarr_version() |
436 | 436 | ) |
| 437 | + if not isinstance(arr, NDArrayLike): |
| 438 | + raise TypeError("arr argument must be numpy or other NDArrayLike array") |
437 | 439 |
|
438 | 440 | mode = kwargs.pop("mode", None) |
439 | 441 | store_path = await make_store_path(store, path=path, mode=mode, storage_options=storage_options) |
@@ -488,16 +490,26 @@ async def save_group( |
488 | 490 | or _default_zarr_version() |
489 | 491 | ) |
490 | 492 |
|
| 493 | + for arg in args: |
| 494 | + if not isinstance(arg, NDArrayLike): |
| 495 | + raise TypeError( |
| 496 | + "All arguments must be numpy or other NDArrayLike arrays (except store, path, storage_options, and zarr_format)" |
| 497 | + ) |
| 498 | + for k, v in kwargs.items(): |
| 499 | + if not isinstance(v, NDArrayLike): |
| 500 | + raise TypeError(f"Keyword argument '{k}' must be a numpy or other NDArrayLike array") |
| 501 | + |
491 | 502 | if len(args) == 0 and len(kwargs) == 0: |
492 | 503 | raise ValueError("at least one array must be provided") |
493 | 504 | aws = [] |
494 | 505 | for i, arr in enumerate(args): |
| 506 | + _path = f"{path}/arr_{i}" if path is not None else f"arr_{i}" |
495 | 507 | aws.append( |
496 | 508 | save_array( |
497 | 509 | store, |
498 | 510 | arr, |
499 | 511 | zarr_format=zarr_format, |
500 | | - path=f"{path}/arr_{i}", |
| 512 | + path=_path, |
501 | 513 | storage_options=storage_options, |
502 | 514 | ) |
503 | 515 | ) |
@@ -1137,9 +1149,8 @@ async def create( |
1137 | 1149 | warnings.warn("meta_array is not yet implemented", RuntimeWarning, stacklevel=2) |
1138 | 1150 |
|
1139 | 1151 | mode = kwargs.pop("mode", None) |
1140 | | - if mode is None: |
1141 | | - if not isinstance(store, Store | StorePath): |
1142 | | - mode = "a" |
| 1152 | + if mode is None and not isinstance(store, Store | StorePath): |
| 1153 | + mode = "a" |
1143 | 1154 |
|
1144 | 1155 | store_path = await make_store_path(store, path=path, mode=mode, storage_options=storage_options) |
1145 | 1156 |
|
|
0 commit comments