-
-
Notifications
You must be signed in to change notification settings - Fork 373
0-dimensional arrays #161
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
0-dimensional arrays #161
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d242979
test and implementation of scalars
alimanfoo 57c6d80
tweak naming
alimanfoo 883af01
fix comments [CI skip]
alimanfoo ae8bf18
ensure set only scalar value
alimanfoo 0a48b6c
property fixes
alimanfoo 56f70ef
fix comments [CI skip]
alimanfoo 3ae26de
set scalar on group
alimanfoo 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 |
|---|---|---|
|
|
@@ -158,6 +158,8 @@ def test_array_1d_fill_value(self): | |
| assert_array_equal(f[310:], z[310:]) | ||
|
|
||
| def test_array_1d_set_scalar(self): | ||
| # test setting the contents of an array with a scalar value | ||
|
|
||
| # setup | ||
| a = np.zeros(100) | ||
| z = self.create_array(shape=a.shape, chunks=10, dtype=a.dtype) | ||
|
|
@@ -587,6 +589,50 @@ def test_0len_dim_2d(self): | |
| with assert_raises(IndexError): | ||
| z[:, 0] = 42 | ||
|
|
||
| def test_array_0d(self): | ||
| # test behaviour for scalars, i.e., array with 0 dimensions | ||
|
|
||
| # setup | ||
| a = np.zeros(()) | ||
| z = self.create_array(shape=(), dtype=a.dtype, fill_value=0) | ||
|
|
||
| # check properties | ||
| eq(a.ndim, z.ndim) | ||
| eq(a.shape, z.shape) | ||
| eq(a.size, z.size) | ||
| eq(a.dtype, z.dtype) | ||
| with assert_raises(TypeError): | ||
| len(z) | ||
| eq((), z.chunks) | ||
| eq(1, z.nchunks) | ||
| # compressor always None - no point in compressing a scalar value | ||
| assert_is_none(z.compressor) | ||
|
Member
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. Would it be worth checking |
||
|
|
||
| # check __getitem__ | ||
| b = z[...] | ||
| assert_is_instance(b, np.ndarray) | ||
| eq(a.shape, b.shape) | ||
| eq(a.dtype, b.dtype) | ||
| assert_array_equal(a, np.array(z)) | ||
| assert_array_equal(a, z[...]) | ||
| eq(a[()], z[()]) | ||
| with assert_raises(IndexError): | ||
| z[0] | ||
| with assert_raises(IndexError): | ||
| z[:] | ||
|
|
||
| # check __setitem__ | ||
| z[...] = 42 | ||
| eq(42, z[()]) | ||
| z[()] = 43 | ||
| eq(43, z[()]) | ||
| with assert_raises(IndexError): | ||
| z[0] = 42 | ||
| with assert_raises(IndexError): | ||
| z[:] = 42 | ||
| with assert_raises(ValueError): | ||
| z[...] = np.array([1, 2, 3]) | ||
|
|
||
|
|
||
| class TestArrayWithPath(TestArray): | ||
|
|
||
|
|
||
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.
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.
Minor point. This seems a bit spaced out. Not sure if that was intentional or not.