Skip to content

Commit b7ccc8b

Browse files
committed
Fix create_dataset with data argument
1 parent 76d6240 commit b7ccc8b

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/zarr/core/group.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1165,7 +1165,16 @@ async def create_dataset(
11651165
.. deprecated:: 3.0.0
11661166
The h5py compatibility methods will be removed in 3.1.0. Use `AsyncGroup.create_array` instead.
11671167
"""
1168-
return await self.create_array(name, shape=shape, **kwargs)
1168+
data = kwargs.pop("data", None)
1169+
# create_dataset in zarr 2.x requires shape but not dtype if data is
1170+
# provided. Allow this configuration by inferring dtype from data if
1171+
# necessary and passing it to create_array
1172+
if "dtype" not in kwargs and data is not None:
1173+
kwargs["dtype"] = data.dtype
1174+
array = await self.create_array(name, shape=shape, **kwargs)
1175+
if data is not None:
1176+
await array.setitem(slice(None), data)
1177+
return array
11691178

11701179
@deprecated("Use AsyncGroup.require_array instead.")
11711180
async def require_dataset(

0 commit comments

Comments
 (0)