home / github / issues

Menu
  • GraphQL API
  • Search all tables

issues: 806218687

This data as json

id node_id number title user state locked assignee milestone comments created_at updated_at closed_at author_association active_lock_reason draft pull_request body reactions performed_via_github_app state_reason repo type
806218687 MDU6SXNzdWU4MDYyMTg2ODc= 4892 disallow boolean coordinates? 10194086 open 0     2 2021-02-11T09:33:17Z 2021-03-31T10:30:49Z   MEMBER      

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:

python test = xarray.DataArray( numpy.ones((3,2)), dims=["binary","ternary"], coords={"ternary":[3,7,9],"binary":[False,True]} ) now came the big surprise, when I wanted to reduce over selections of the data:

test.sel(ternary=[9,3,7]) # does exactly what I expect and gives me the correctly permuted 3x2 array test.sel(binary=[True,False]) # does not do what I expect 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 https://github.com/pydata/xarray/discussions/4861

{
    "url": "https://api.github.com/repos/pydata/xarray/issues/4892/reactions",
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
    13221727 issue

Links from other tables

  • 0 rows from issues_id in issues_labels
  • 2 rows from issue in issue_comments
Powered by Datasette · Queries took 159.519ms · About: xarray-datasette