-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Check shapes of coordinates and data during DataArray construction #2533
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
base: main
Are you sure you want to change the base?
Conversation
Hello @lilyminium! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found: There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻 Comment last updated at 2021-05-31 21:16:46 UTC |
@lilyminium thanks for looking into this! I think the specific problem here is due to our use of the shortcut xarray/xarray/core/dataarray.py Line 193 in 6d55f99
I think the clean way to fix this would be to add error checking to |
xarray/core/dataarray.py
Outdated
@@ -230,6 +235,9 @@ def __init__(self, data, coords=None, dims=None, name=None, | |||
# uncomment for a useful consistency check: | |||
# assert all(isinstance(v, Variable) for v in coords.values()) | |||
|
|||
# check shape consistency | |||
_check_shape_consistency(variable.shape, coords, variable.dims) |
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.
This could be pretty expensive — it means we have to check shape consistency every time we create a DataArray, even if we know that the shape is already consistent, e.g., because it was created by another xarray operation.
a10d855
to
f488bed
Compare
Does adding fastpath to skip shape checking in array_wrap work? fastpath=True in both DataArray.array_wrap and Variable.array_wrap didn't seem to break any tests. |
I think it would be slightly better to stick with a separate method for xarray's fast-path. |
This would still be valuable if @lilyminium (or someone else, if they're not interested) would want to finish this off. |
Ooh, this is a blast from the past. Anyone passing by, feel free to pick this up if you like, otherwise I'll see what I can do over the weekend :) |
b1cb248
to
b755d1d
Compare
Hmmmm. It's been quite some time since I've last used xarray, but I'm not sure I see an easy way to:
I have for now stuck |
b755d1d
to
b9c6b00
Compare
b9c6b00
to
bd1a76f
Compare
The 3.7 test looks like an installation error. |
I think that's exactly correct. Without being able to tell Maybe this new implementation has a low enough overhead that it's worthwhile? If we do go ahead — what about calling |
8d50ecc
to
e488efd
Compare
I can only find references regarding
|
Nice, that seems to work! Is anyone else more familiar with whether using |
whats-new.rst
for all changes andapi.rst
for new API (remove if this change should not be visible to users, e.g., if it is an internal clean-up, or if this is part of a larger project that will be documented later)This sets DataArrayGroupBy.reduce(shortcut=False), as the shortcut first constructs a DataArray with the previous coordinates and the new mutated data before updating the coordinates; this order of events now raises a ValueError.