Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 450
[v3] Array.append#2413
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
[v3] Array.append #2413
Changes from all commits
dc89c13d84f08511c1345ef6b9199095e041ef58f8fd376a3File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -419,6 +419,194 @@ def test_update_attrs(zarr_format: int) -> None: | ||
| assert arr2.attrs["foo"] == "bar" | ||
| @pytest.mark.parametrize("store", ["memory"], indirect=True) | ||
| @pytest.mark.parametrize("zarr_format", [2, 3]) | ||
| def test_resize_1d(store: MemoryStore, zarr_format: int) -> None: | ||
Comment on lines
+422
to
+424
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. to fight test bloat we should find a way to parameterize over dimensionality instead of making separate 1d, 2d, etc tests. but that's not a blocker here. MemberAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. agree! These tests were copied over from v2 so I'm going to leave them for now. | ||
| z = zarr.create( | ||
| shape=105, chunks=10, dtype="i4", fill_value=0, store=store, zarr_format=zarr_format | ||
| ) | ||
| a = np.arange(105, dtype="i4") | ||
| z[:] = a | ||
| assert (105,) == z.shape | ||
| assert (105,) == z[:].shape | ||
| assert np.dtype("i4") == z.dtype | ||
| assert np.dtype("i4") == z[:].dtype | ||
| assert (10,) == z.chunks | ||
| np.testing.assert_array_equal(a, z[:]) | ||
| z.resize(205) | ||
| assert (205,) == z.shape | ||
| assert (205,) == z[:].shape | ||
| assert np.dtype("i4") == z.dtype | ||
| assert np.dtype("i4") == z[:].dtype | ||
| assert (10,) == z.chunks | ||
| np.testing.assert_array_equal(a, z[:105]) | ||
| np.testing.assert_array_equal(np.zeros(100, dtype="i4"), z[105:]) | ||
| z.resize(55) | ||
| assert (55,) == z.shape | ||
| assert (55,) == z[:].shape | ||
| assert np.dtype("i4") == z.dtype | ||
| assert np.dtype("i4") == z[:].dtype | ||
| assert (10,) == z.chunks | ||
| np.testing.assert_array_equal(a[:55], z[:]) | ||
| # via shape setter | ||
| new_shape = (105,) | ||
| z.shape = new_shape | ||
| assert new_shape == z.shape | ||
| assert new_shape == z[:].shape | ||
| @pytest.mark.parametrize("store", ["memory"], indirect=True) | ||
| @pytest.mark.parametrize("zarr_format", [2, 3]) | ||
| def test_resize_2d(store: MemoryStore, zarr_format: int) -> None: | ||
| z = zarr.create( | ||
| shape=(105, 105), | ||
| chunks=(10, 10), | ||
| dtype="i4", | ||
| fill_value=0, | ||
| store=store, | ||
| zarr_format=zarr_format, | ||
| ) | ||
| a = np.arange(105 * 105, dtype="i4").reshape((105, 105)) | ||
| z[:] = a | ||
| assert (105, 105) == z.shape | ||
| assert (105, 105) == z[:].shape | ||
| assert np.dtype("i4") == z.dtype | ||
| assert np.dtype("i4") == z[:].dtype | ||
| assert (10, 10) == z.chunks | ||
| np.testing.assert_array_equal(a, z[:]) | ||
| z.resize((205, 205)) | ||
| assert (205, 205) == z.shape | ||
| assert (205, 205) == z[:].shape | ||
| assert np.dtype("i4") == z.dtype | ||
| assert np.dtype("i4") == z[:].dtype | ||
| assert (10, 10) == z.chunks | ||
| np.testing.assert_array_equal(a, z[:105, :105]) | ||
| np.testing.assert_array_equal(np.zeros((100, 205), dtype="i4"), z[105:, :]) | ||
| np.testing.assert_array_equal(np.zeros((205, 100), dtype="i4"), z[:, 105:]) | ||
| z.resize((55, 55)) | ||
| assert (55, 55) == z.shape | ||
| assert (55, 55) == z[:].shape | ||
| assert np.dtype("i4") == z.dtype | ||
| assert np.dtype("i4") == z[:].dtype | ||
| assert (10, 10) == z.chunks | ||
| np.testing.assert_array_equal(a[:55, :55], z[:]) | ||
| z.resize((55, 1)) | ||
| assert (55, 1) == z.shape | ||
| assert (55, 1) == z[:].shape | ||
| assert np.dtype("i4") == z.dtype | ||
| assert np.dtype("i4") == z[:].dtype | ||
| assert (10, 10) == z.chunks | ||
| np.testing.assert_array_equal(a[:55, :1], z[:]) | ||
| z.resize((1, 55)) | ||
| assert (1, 55) == z.shape | ||
| assert (1, 55) == z[:].shape | ||
| assert np.dtype("i4") == z.dtype | ||
| assert np.dtype("i4") == z[:].dtype | ||
| assert (10, 10) == z.chunks | ||
| np.testing.assert_array_equal(a[:1, :10], z[:, :10]) | ||
| np.testing.assert_array_equal(np.zeros((1, 55 - 10), dtype="i4"), z[:, 10:55]) | ||
| # via shape setter | ||
| new_shape = (105, 105) | ||
| z.shape = new_shape | ||
| assert new_shape == z.shape | ||
| assert new_shape == z[:].shape | ||
| @pytest.mark.parametrize("store", ["memory"], indirect=True) | ||
| @pytest.mark.parametrize("zarr_format", [2, 3]) | ||
| def test_append_1d(store: MemoryStore, zarr_format: int) -> None: | ||
| a = np.arange(105) | ||
| z = zarr.create(shape=a.shape, chunks=10, dtype=a.dtype, store=store, zarr_format=zarr_format) | ||
| z[:] = a | ||
| assert a.shape == z.shape | ||
| assert a.dtype == z.dtype | ||
| assert (10,) == z.chunks | ||
| np.testing.assert_array_equal(a, z[:]) | ||
| b = np.arange(105, 205) | ||
| e = np.append(a, b) | ||
| assert z.shape == (105,) | ||
| z.append(b) | ||
| assert e.shape == z.shape | ||
| assert e.dtype == z.dtype | ||
| assert (10,) == z.chunks | ||
| np.testing.assert_array_equal(e, z[:]) | ||
| # check append handles array-like | ||
| c = [1, 2, 3] | ||
| f = np.append(e, c) | ||
| z.append(c) | ||
| assert f.shape == z.shape | ||
| assert f.dtype == z.dtype | ||
| assert (10,) == z.chunks | ||
| np.testing.assert_array_equal(f, z[:]) | ||
| @pytest.mark.parametrize("store", ["memory"], indirect=True) | ||
| @pytest.mark.parametrize("zarr_format", [2, 3]) | ||
| def test_append_2d(store: MemoryStore, zarr_format: int) -> None: | ||
| a = np.arange(105 * 105, dtype="i4").reshape((105, 105)) | ||
| z = zarr.create( | ||
| shape=a.shape, chunks=(10, 10), dtype=a.dtype, store=store, zarr_format=zarr_format | ||
| ) | ||
| z[:] = a | ||
| assert a.shape == z.shape | ||
| assert a.dtype == z.dtype | ||
| assert (10, 10) == z.chunks | ||
| actual = z[:] | ||
| np.testing.assert_array_equal(a, actual) | ||
| b = np.arange(105 * 105, 2 * 105 * 105, dtype="i4").reshape((105, 105)) | ||
| e = np.append(a, b, axis=0) | ||
| z.append(b) | ||
| assert e.shape == z.shape | ||
| assert e.dtype == z.dtype | ||
| assert (10, 10) == z.chunks | ||
| actual = z[:] | ||
| np.testing.assert_array_equal(e, actual) | ||
| @pytest.mark.parametrize("store", ["memory"], indirect=True) | ||
| @pytest.mark.parametrize("zarr_format", [2, 3]) | ||
| def test_append_2d_axis(store: MemoryStore, zarr_format: int) -> None: | ||
| a = np.arange(105 * 105, dtype="i4").reshape((105, 105)) | ||
| z = zarr.create( | ||
| shape=a.shape, chunks=(10, 10), dtype=a.dtype, store=store, zarr_format=zarr_format | ||
| ) | ||
| z[:] = a | ||
| assert a.shape == z.shape | ||
| assert a.dtype == z.dtype | ||
| assert (10, 10) == z.chunks | ||
| np.testing.assert_array_equal(a, z[:]) | ||
| b = np.arange(105 * 105, 2 * 105 * 105, dtype="i4").reshape((105, 105)) | ||
| e = np.append(a, b, axis=1) | ||
| z.append(b, axis=1) | ||
| assert e.shape == z.shape | ||
| assert e.dtype == z.dtype | ||
| assert (10, 10) == z.chunks | ||
| np.testing.assert_array_equal(e, z[:]) | ||
| @pytest.mark.parametrize("store", ["memory"], indirect=True) | ||
| @pytest.mark.parametrize("zarr_format", [2, 3]) | ||
| def test_append_bad_shape(store: MemoryStore, zarr_format: int) -> None: | ||
| a = np.arange(100) | ||
| z = zarr.create(shape=a.shape, chunks=10, dtype=a.dtype, store=store, zarr_format=zarr_format) | ||
| z[:] = a | ||
| b = a.reshape(10, 10) | ||
| with pytest.raises(ValueError): | ||
| z.append(b) | ||
| @pytest.mark.parametrize("order", ["C", "F", None]) | ||
| @pytest.mark.parametrize("zarr_format", [2, 3]) | ||
| @pytest.mark.parametrize("store", ["memory"], indirect=True) | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@TomAugspurger - calling this out because it will impact the xarray use of resize... now in-place again :)