home / github / issue_comments

Menu
  • Search all tables
  • GraphQL API

issue_comments: 904642129

This data as json

html_url issue_url id node_id user created_at updated_at author_association body reactions performed_via_github_app issue
https://github.com/pydata/xarray/issues/5727#issuecomment-904642129 https://api.github.com/repos/pydata/xarray/issues/5727 904642129 IC_kwDOAMm_X841675R 4160723 2021-08-24T13:27:20Z 2021-08-24T13:27:20Z MEMBER

I agree that this kind of "boolean indexing" could be clarified a bit in the docs.

I also had to double check here since I use isel() / sel() much more often than [] and .loc[].

Even now, it's not really clear to me why "boolean"-masking should only work with integer-indexing and not label-indexing. Given that the highlighted maybe_cast_to_coords_dtype is the only reason it does not work for label-based indexing.

Hmm you're right. The primary reason of maybe_cast_to_coords_dtype is because pandas indexes don't support floating point values with lower precision than float64 (e.g., #5700). But here https://github.com/pydata/xarray/blob/a6b44d72010c5311fad4f60194b527194e26094b/xarray/core/indexes.py#L236-L237 we actually bypass the underlying pandas index when the labels are a boolean array-like so that boolean indexing should normally work with both integer and label based indexing (#182).

So we should probably fix maybe_cast_to_coords_dtype with something like

python def maybe_cast_to_coords_dtype(label, coords_dtype): label_dtype = np.dtype(getattr(label, "dtype", None)) if coords_dtype.kind == "f" and not isinstance(label, slice) and label_dtype.kind != "b": label = np.asarray(label, dtype=coords_dtype) return label

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  976207971
Powered by Datasette · Queries took 239.851ms · About: xarray-datasette