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.
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
Initialize empty or full DataArray #3159
Initialize empty or full DataArray #3159
Changes from 27 commits
4f6311e
1aa3ff3
db2cb28
4cecfe9
a538dab
4c45b7b
b0f2d4e
2fa6e48
c481560
28b7336
59a632f
8c165fd
f337550
9a57dc5
70786c1
3f95767
8c97a46
dec7622
8c5aaf3
347ec33
e3127a3
38858c6
4be0607
9bb3530
68ff54a
7407757
4e95cc3
4df28db
8ea1c47
95c88ab
2c0c634
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
I wonder if we should move this logic above
as_compatible_data
, which would let us distinguish between scalar values likefloat
/int
(which don't have an inherentshape
) vs 0-dimensional NumPy arrays (which do have an array shape already).For example:
xarray.DataArray(0.5, coords=[('x', np.arange(3)), ('y', ['a', 'b'])])
-> duplicate the scalar to make an array of shape(3, 2)
xarray.DataArray(np.array(1.0), coords=[('x', np.arange(3)), ('y', ['a', 'b'])])
-> error, shapes do not matchThere 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.
If I understand correctly, the second example you provided shouldn't work since
np.array(1.0)
is a 0-dimensional NumPy array with shape()
andDataArray
expects it to have a(3, 2)
shape, right?. The current behavior is set to duplicate the value as if it werexarray.DataArray(1.0, coords=[('x', np.arange(3)), ('y', ['a', 'b'])])
, which I thought was the desired feature. I am currently pushing a commit that makes this work since I didn't consider the case ofcoords
being a list of tuples (although all test passed).Regarding the
_check_data_shape
position, I placed it afteras_compatible_data
since the latter returns anndarray
containing the value passed to it, scalar orNone
, on which I can check the shape.