home / github / issue_comments

Menu
  • Search all tables
  • GraphQL API

issue_comments: 824452843

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/1887#issuecomment-824452843 https://api.github.com/repos/pydata/xarray/issues/1887 824452843 MDEyOklzc3VlQ29tbWVudDgyNDQ1Mjg0Mw== 5635139 2021-04-22T00:33:29Z 2021-04-22T00:35:28Z MEMBER

OK great. To confirm, this is what it would look like:

Context:

```python In [81]: da = xr.DataArray(np.arange(12).reshape(3,4), dims=list('ab'))

In [82]: da Out[82]: <xarray.DataArray (a: 3, b: 4)> array([[ 0, 1, 2, 3], [ 4, 5, 6, 7], [ 8, 9, 10, 11]]) Dimensions without coordinates: a, b

In [84]: key = da % 3 == 0

In [83]: key Out[83]: <xarray.DataArray (a: 3, b: 4)> array([[ True, False, False, True], [False, False, True, False], [False, True, False, False]]) Dimensions without coordinates: a, b ```

Currently ```python

In [85]: da[key]

IndexError Traceback (most recent call last) <ipython-input-85-7fd83c907cb6> in <module> ----> 1 da[key] ... ~/.asdf/installs/python/3.8.8/lib/python3.8/site-packages/xarray/core/variable.py in _validate_indexers(self, key) 697 ) 698 if k.ndim > 1: --> 699 raise IndexError( 700 "{}-dimensional boolean indexing is " 701 "not supported. ".format(k.ndim)

IndexError: 2-dimensional boolean indexing is not supported. ```

Current proposal ("stack"), of da[key] and with a dimension of key's name (and probably no multiindex): python In [86]: da.values[key.values] Out[86]: array([0, 3, 6, 9]) # But the xarray version

Previous suggestion ("where"), for the result of da[key]: python In [87]: da.where(key) Out[87]: <xarray.DataArray (a: 3, b: 4)> array([[ 0., nan, nan, 3.], [nan, nan, 6., nan], [nan, 9., nan, nan]]) Dimensions without coordinates: a, b

(small follow up I'll put in another message, for clarity)

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