|
8 | 8 |
|
9 | 9 | import numcodecs |
10 | 10 | import numpy as np |
| 11 | +import numpy.typing as npt |
11 | 12 | import pytest |
12 | 13 |
|
13 | 14 | import zarr.api.asynchronous |
@@ -1299,8 +1300,8 @@ async def test_creation_from_other_zarr_format( |
1299 | 1300 |
|
1300 | 1301 | @pytest.mark.parametrize("store", ["local", "memory", "zip"], indirect=True) |
1301 | 1302 | @pytest.mark.parametrize("store2", ["local", "memory", "zip"], indirect=["store2"]) |
1302 | | -@pytest.mark.parametrize("src_chunks", [(10, 2), (50, 10)]) |
1303 | | -@pytest.mark.parametrize("new_chunks", [(10, 2), (50, 10)]) |
| 1303 | +@pytest.mark.parametrize("src_chunks", [(40, 10), (11, 50)]) |
| 1304 | +@pytest.mark.parametrize("new_chunks", [(40, 10), (11, 50)]) |
1304 | 1305 | async def test_from_array( |
1305 | 1306 | store: Store, |
1306 | 1307 | store2: Store, |
@@ -1340,11 +1341,30 @@ async def test_from_array( |
1340 | 1341 | assert result.chunks == new_chunks |
1341 | 1342 |
|
1342 | 1343 |
|
1343 | | -@pytest.mark.parametrize("store", ["local", "memory", "zip"], indirect=True) |
1344 | | -@pytest.mark.parametrize("chunks", [(10, 2, 3), "keep", "auto"]) |
1345 | | -async def test_from_numpy_array( |
1346 | | - store: Store, chunks: Literal["auto", "keep"] | tuple[int, int] |
| 1344 | +@pytest.mark.parametrize("store", ["local"], indirect=True) |
| 1345 | +@pytest.mark.parametrize("chunks", ["keep", "auto"]) |
| 1346 | +@pytest.mark.parametrize("write_data", [True, False]) |
| 1347 | +@pytest.mark.parametrize( |
| 1348 | + "src", |
| 1349 | + [ |
| 1350 | + np.arange(1000).reshape(10, 10, 10), |
| 1351 | + zarr.ones((10, 10, 10)), |
| 1352 | + 5, |
| 1353 | + [1, 2, 3], |
| 1354 | + [[1, 2, 3], [4, 5, 6]], |
| 1355 | + ], |
| 1356 | +) # add other npt.ArrayLike? |
| 1357 | +async def test_from_array_arraylike( |
| 1358 | + store: Store, |
| 1359 | + chunks: Literal["auto", "keep"] | tuple[int, int], |
| 1360 | + write_data: bool, |
| 1361 | + src: Array | npt.ArrayLike, |
1347 | 1362 | ) -> None: |
1348 | | - src = np.arange(1000).reshape(10, 10, 10) |
1349 | | - result = zarr.from_array(src, store=store, chunks=chunks) |
1350 | | - np.testing.assert_array_equal(result[:], src) |
| 1363 | + fill_value = 42 |
| 1364 | + result = zarr.from_array( |
| 1365 | + src, store=store, chunks=chunks, write_data=write_data, fill_value=fill_value |
| 1366 | + ) |
| 1367 | + if write_data: |
| 1368 | + np.testing.assert_array_equal(result[...], src) |
| 1369 | + else: |
| 1370 | + np.testing.assert_array_equal(result[...], np.full_like(src, fill_value)) |
0 commit comments