Skip to content

Commit 4863811

Browse files
committed
test and fix path argument in save_group
1 parent d19f3f0 commit 4863811

2 files changed

Lines changed: 8 additions & 8 deletions

File tree

src/zarr/api/asynchronous.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -505,13 +505,12 @@ async def save_group(
505505
raise ValueError("at least one array must be provided")
506506
aws = []
507507
for i, arr in enumerate(args):
508-
_path = f"{path}/arr_{i}" if path is not None else f"arr_{i}"
509508
aws.append(
510509
save_array(
511510
store_path,
512511
arr,
513512
zarr_format=zarr_format,
514-
path=_path,
513+
path=f"arr_{i}",
515514
storage_options=storage_options,
516515
)
517516
)

tests/test_api.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -229,22 +229,23 @@ async def test_open_group_unspecified_version(
229229
@pytest.mark.parametrize("store", ["local", "memory", "zip"], indirect=["store"])
230230
@pytest.mark.parametrize("n_args", [10, 1, 0])
231231
@pytest.mark.parametrize("n_kwargs", [10, 1, 0])
232-
def test_save(store: Store, n_args: int, n_kwargs: int) -> None:
232+
@pytest.mark.parametrize("path", [None, "some_path"])
233+
def test_save(store: Store, n_args: int, n_kwargs: int, path) -> None:
233234
data = np.arange(10)
234235
args = [np.arange(10) for _ in range(n_args)]
235236
kwargs = {f"arg_{i}": data for i in range(n_kwargs)}
236237

237238
if n_kwargs == 0 and n_args == 0:
238239
with pytest.raises(ValueError):
239-
save(store)
240+
save(store, path=path)
240241
elif n_args == 1 and n_kwargs == 0:
241-
save(store, *args)
242-
array = zarr.api.synchronous.open(store)
242+
save(store, *args, path=path)
243+
array = zarr.api.synchronous.open(store, path=path)
243244
assert isinstance(array, Array)
244245
assert_array_equal(array[:], data)
245246
else:
246-
save(store, *args, **kwargs) # type: ignore [arg-type]
247-
group = zarr.api.synchronous.open(store)
247+
save(store, *args, path=path, **kwargs) # type: ignore [arg-type]
248+
group = zarr.api.synchronous.open(store, path=path)
248249
assert isinstance(group, Group)
249250
for array in group.array_values():
250251
assert_array_equal(array[:], data)

0 commit comments

Comments
 (0)