-
-
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
disallow boolean coordinates? #4892
Comments
It's a good issue! I would have thought And I recognize But here, I propose we prioritize the labels above the boolean indexing in In [4]: test = xr.DataArray(
...: np.ones((3,2)),
...: dims=["ternary","binary"],
...: coords={"ternary":[3,7,9],"binary":[False,True]}
...: )
In [5]: test.sel(binary=[True,False])
Out[5]:
<xarray.DataArray (ternary: 3, binary: 1)>
array([[1.],
[1.],
[1.]])
Coordinates:
* ternary (ternary) int64 3 7 9
* binary (binary) bool False
In [6]: test.isel(binary=[True,False])
Out[6]:
<xarray.DataArray (ternary: 3, binary: 1)>
array([[1.],
[1.],
[1.]])
Coordinates:
* ternary (ternary) int64 3 7 9
* binary (binary) bool False I would also be OK removing the |
I don't know the internals of delegation between While that probably be a breaking change for some people, I think it makes a quite complicated topic slightly easier to document, and figure out intentions in written code. |
Today I stumbled over a small pitfall, which I think could be avoided:
I am working with arrays that have axes labeled with categorical values and I ended up using True/False as labels for some binary categories:
now came the big surprise, when I wanted to reduce over selections of the data:
Instead of using the coordinate values like with the ternary category, it uses the list as boolean mask and hence I get a 3x1 array at the binary=False coordinate.
I assume that this behavior is reasonable in most cases - And I for sure will stop using bools as binary category labels.
That said in the above case the conceptually identical call results in completely different outcome.
My (radical) proposal would be: forbid binary coordinates in general to avoid such confusion.
Curious about your thoughts! Hth,
Marti
Originally posted by @martinitus in #4861
The text was updated successfully, but these errors were encountered: