-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
DataArray creation prone to errors when data shares dimension shapes #727
Comments
I agree, this can be ambiguous. It makes sense for ordered mappings, but not for normal dicts. And unfortunately there is no Pythonic way to tell whether a mapping is ordered or not. I originally included it because I wanted to make sure operations like So I would support deprecating supplying dict-like coordinates without explicitly provided I don't want to simply error when coordinates have ambiguous lengths compared to the size of the data, because adding errors in special cases makes things harder to predict. |
I've also run into this and I'm 👍 on this solution. |
That sounds like a fair plan to me - throwing errors etc definitely On Tue, Jan 26, 2016 at 8:58 PM, Joe Hamman notifications@github.com
|
Any interest in putting together a PR? :) On Tue, Jan 26, 2016 at 9:46 PM, Chris Holdgraf notifications@github.com
|
Lemme take a look at the code tomorrow. I'm pretty new to xarray but I've
|
So it looks like the relevant code is somewhere around here, no? Is "auto-coords" done in many other places in the codebase? And as far as future behavior, do you imagine just changing the |
@choldgraf Yes, that looks right to me -- this code path in particular should trigger a DeprecationWarning:
|
Cool - I'll make a PR in the next week or two...I know this isn't a big change but have a few deadlines in the coming days. |
whoops - that's what I get for not putting this on my to-do list...totally forgot about this issue. My bad, but thanks for fixing! |
@choldgraf no worries! |
It seems like there would be unexpected behavior whenever someone creates a DataArray using data with some subset of dimensions that have the same shape, and when supplying coords as a dictionary of
coord_name: coords
pairs. Since the dictionary isn't ordered, won't it be unclear which dimension it is referring to?Maybe that's not such a good description, here's an example:
For the first dimension it's no problem, since it's the only one with length 20. For the 2nd and 3rd dimensions since they are the same shape, the coordinates will be assigned depending on which order python takes the keys, which means they could sometimes be flipped depending on something arbitrary like what you named a dimension.
It seems like this could be addressed by doing a quick check (when supplying coordinates in this fashion) to see if any of the dimensions of the coordinates are the same, and throwing a warning that behavior might be unstable. Or maybe it throws an error and says "if data coordinates are same length, please supply coordinate values in a tuple or list instead"?
The text was updated successfully, but these errors were encountered: