-
-
Notifications
You must be signed in to change notification settings - Fork 350
[v3] Implement Group methods for empty, full, ones, and zeros #2210
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
Merged
+128
−34
Merged
Changes from 6 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
7c884f1
fill in stubs for Group.{empty,zeros,ones,full,empty_like, zeros_like…
lindseynield 1a3b432
add shape to function signature
lindseynield c75605e
change type in function signature and add unit tests
lindseynield 8ee9e19
precommit
lindseynield 2ad8b78
small fixes
lindseynield 1d8410d
add shape check to tests
lindseynield bb32056
update function signatures
lindseynield fdb7461
cast path to a str
lindseynield c2379a1
update store path
lindseynield c4ff153
Merge branch 'v3' into v3
jhamman 15c4d28
Merge branch 'v3' into v3
lindseynield File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -390,6 +390,64 @@ def test_group_create_array( | |
assert np.array_equal(array[:], data) | ||
|
||
|
||
def test_group_array_creation( | ||
store: Store, | ||
zarr_format: ZarrFormat, | ||
): | ||
group = Group.create(store, zarr_format=zarr_format) | ||
shape = (10, 10) | ||
|
||
empty_array = group.empty(shape=shape) | ||
assert isinstance(empty_array, Array) | ||
assert empty_array.fill_value == 0 | ||
assert empty_array.shape == shape | ||
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. Fill value expected to be 0: https://github.com/zarr-developers/zarr-python/blob/v3/src/zarr/core/array.py#L253-L257 |
||
|
||
empty_like_array = group.empty_like(empty_array) | ||
assert isinstance(empty_like_array, Array) | ||
assert empty_like_array.fill_value == 0 | ||
assert empty_like_array.shape == shape | ||
jhamman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
empty_array_bool = group.empty(shape=shape, dtype=np.dtype("bool")) | ||
assert isinstance(empty_array_bool, Array) | ||
assert not empty_array_bool.fill_value | ||
assert empty_array.shape == shape | ||
|
||
empty_like_array_bool = group.empty_like(empty_array_bool) | ||
assert isinstance(empty_like_array_bool, Array) | ||
assert not empty_like_array_bool.fill_value | ||
assert empty_like_array.shape == shape | ||
|
||
zeros_array = group.zeros(shape=shape) | ||
assert isinstance(zeros_array, Array) | ||
assert zeros_array.fill_value == 0 | ||
assert zeros_array.shape == shape | ||
|
||
zeros_like_array = group.zeros_like(zeros_array) | ||
assert isinstance(zeros_like_array, Array) | ||
assert zeros_like_array.fill_value == 0 | ||
assert zeros_like_array.shape == shape | ||
|
||
ones_array = group.ones(shape=shape) | ||
assert isinstance(ones_array, Array) | ||
assert ones_array.fill_value == 1 | ||
assert ones_array.shape == shape | ||
|
||
ones_like_array = group.ones_like(ones_array) | ||
assert isinstance(ones_like_array, Array) | ||
assert ones_like_array.fill_value == 1 | ||
assert ones_like_array.shape == shape | ||
|
||
full_array = group.full(shape=shape, fill_value=42) | ||
assert isinstance(full_array, Array) | ||
assert full_array.fill_value == 42 | ||
assert full_array.shape == shape | ||
|
||
full_like_array = group.full_like(full_array, fill_value=43) | ||
assert isinstance(full_like_array, Array) | ||
assert full_like_array.fill_value == 43 | ||
assert full_like_array.shape == shape | ||
|
||
|
||
@pytest.mark.parametrize("store", ("local", "memory", "zip"), indirect=["store"]) | ||
@pytest.mark.parametrize("zarr_format", (2, 3)) | ||
@pytest.mark.parametrize("exists_ok", [True, False]) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.