-
-
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
sel
fails confusingly or silently when a dimension name matches an optional argument
#3324
Comments
Yes, agree this isn't ideal. One of the great qualities of xarray is the code we write in exploration also works in production, and this behavior violates some of that. FWIW passing a dict to these methods will work, if you want complete dependability |
What if I create a PR with a function in |
+1. Though I prefer raising a more informative over raising a warning. |
Raising an error? |
Yes. fat fingers on mobile :) |
Yes I agree, on reflection |
This sounds great to me! I have also been bitten by this issue, particularly with the same dimension name |
This could be an addition to the Line 248 in df25933
|
Currently, |
Yes add another kwarg |
Given that many Xarray methods accept
dict
or keyword arguments, this may effect other methods. That said, here is a minimal example withsel
.Minimal example
If I want to select based on a dimension named
method
, I cannot because Xarray thinksmethod
is themethod
argument tosel
:And if the
method
dimension has string labels, this fails silently:Expected Output
I think raising a
ValueError
and providing a clarifying error message is the right call, but maybe the maintainers have a different opinion. At the very least, it seems like Xarray could note that theDataArray
instance has a dimension that matches one of the function arguments and ask the user to usedict
-like arguments if required.I imagine a general error handling function could be written to check this for any function and
DataArray
pair.The text was updated successfully, but these errors were encountered: