Skip to content

Commit 7b30744

Browse files
committed
error if shape / dtype and data are provided
1 parent b21db55 commit 7b30744

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

src/zarr/core/array.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4373,29 +4373,29 @@ def _parse_data_params(
43734373
"Either provide a value for data, or specify shape."
43744374
)
43754375
raise ValueError(msg)
4376+
shape_out = shape
43764377
if dtype is None:
43774378
msg = (
43784379
"The data parameter was set to None, but dtype was not specified."
43794380
"Either provide an array-like value for data, or specify dtype."
43804381
)
43814382
raise ValueError(msg)
4382-
4383+
dtype_out = dtype
43834384
else:
43844385
if shape is not None:
43854386
msg = (
43864387
"The data parameter was used, but the shape parameter was also "
4387-
"used. The shape parameter will be ignored, and the data.shape "
4388-
"attribute will be used instead."
4388+
"used. This is an error. Either use the data parameter, or the shape parameter, "
4389+
"but not both."
43894390
)
4390-
warnings.warn(msg, UserWarning, stacklevel=2)
4391-
shape = data.shape
4392-
4391+
raise ValueError(msg)
4392+
shape_out = data.shape
43934393
if dtype is not None:
43944394
msg = (
43954395
"The data parameter was used, but the dtype parameter was also "
4396-
"used. The dtype parameter will be ignored, and the data.dtype "
4397-
"attribute will be used instead."
4396+
"used. This is an error. Either use the data parameter, or the dtype parameter, "
4397+
"but not both."
43984398
)
4399-
warnings.warn(msg, UserWarning, stacklevel=2)
4400-
dtype = data.dtype
4401-
return data, shape, dtype # type: ignore[return-value]
4399+
raise ValueError(msg)
4400+
dtype_out = data.dtype
4401+
return data, shape_out, dtype_out

tests/test_array.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1306,14 +1306,20 @@ async def test_create_array_data_ignored_params(store: Store) -> None:
13061306
Test that specify data AND shape AND dtype results in a warning
13071307
"""
13081308
data = np.arange(10)
1309-
with pytest.warns(UserWarning, match="The shape parameter will be ignored"):
1309+
with pytest.raises(
1310+
ValueError, match="The data parameter was used, but the shape parameter was also used."
1311+
):
13101312
await create_array(store, data=data, shape=data.shape, dtype=None, overwrite=True)
13111313

13121314
# we catch shape first, so specifying a dtype should raise the same warning as before
1313-
with pytest.warns(UserWarning, match="The shape parameter will be ignored"):
1315+
with pytest.raises(
1316+
ValueError, match="The data parameter was used, but the shape parameter was also used."
1317+
):
13141318
await create_array(store, data=data, shape=data.shape, dtype=data.dtype, overwrite=True)
13151319

1316-
with pytest.warns(UserWarning, match="The dtype parameter will be ignored"):
1320+
with pytest.raises(
1321+
ValueError, match="The data parameter was used, but the dtype parameter was also used."
1322+
):
13171323
await create_array(store, data=data, shape=None, dtype=data.dtype, overwrite=True)
13181324

13191325

0 commit comments

Comments
 (0)