Skip to content

Commit 12a42dc

Browse files
authored
Merge branch 'main' into docs/sharding
2 parents a8809b7 + 0adcbe7 commit 12a42dc

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

docs/user-guide/v3_migration.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,11 @@ Dependencies
156156
When installing using ``pip``:
157157

158158
- The new ``remote`` dependency group can be used to install a supported version of
159-
``fsspec``, required for remote data access.
159+
``fsspec``, required for remote data access.
160160
- The new ``gpu`` dependency group can be used to install a supported version of
161-
``cuda``, required for GPU functionality.
161+
``cuda``, required for GPU functionality.
162162
- The ``jupyter`` optional dependency group has been removed, since v3 contains no
163-
jupyter specific functionality.
163+
jupyter specific functionality.
164164

165165
Miscellaneous
166166
~~~~~~~~~~~~~

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(

tests/test_group.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,6 +1137,18 @@ async def test_require_groups(store: LocalStore | MemoryStore, zarr_format: Zarr
11371137
assert no_group == ()
11381138

11391139

1140+
def test_create_dataset_with_data(store: Store, zarr_format: ZarrFormat) -> None:
1141+
"""Check that deprecated create_dataset method allows input data.
1142+
1143+
See https://github.com/zarr-developers/zarr-python/issues/2631.
1144+
"""
1145+
root = Group.from_store(store=store, zarr_format=zarr_format)
1146+
arr = np.random.random((5, 5))
1147+
with pytest.warns(DeprecationWarning):
1148+
data = root.create_dataset("random", data=arr, shape=arr.shape)
1149+
np.testing.assert_array_equal(np.asarray(data), arr)
1150+
1151+
11401152
async def test_create_dataset(store: Store, zarr_format: ZarrFormat) -> None:
11411153
root = await AsyncGroup.from_store(store=store, zarr_format=zarr_format)
11421154
with pytest.warns(DeprecationWarning):

0 commit comments

Comments
 (0)