home / github / issue_comments

Menu
  • GraphQL API
  • Search all tables

issue_comments: 456128567

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/2689#issuecomment-456128567 https://api.github.com/repos/pydata/xarray/issues/2689 456128567 MDEyOklzc3VlQ29tbWVudDQ1NjEyODU2Nw== 9658781 2019-01-21T16:21:29Z 2019-01-21T16:21:29Z CONTRIBUTOR

Hey Shoyer,

sure I am happy to propose one. Given the input from the xarray example page (http://xarray.pydata.org/en/stable/examples/weather-data.html), I would imagine something like this:

python xarr = xarr.loc[xarr['tmin'] > 5]

If the DataArray is one dimensional this is straight forward to achieve by altering the _LocIndexer in the following way: ``` class _LocIndexer(object): def init(self, dataset): self.dataset = dataset

def __getitem__(self, key):
    if not utils.is_dict_like(key):
        selector = {dim: key[dim][key] for dim in key.dims}
        keep_vars = []
        for var in self.dataset.data_vars:
            if np.all(dim in self.dataset[var].dims for dim in key.dims):
                keep_vars.append(var)
        return self.dataset[keep_vars].sel(selector)
    return self.dataset.sel(**key)

```

This does not work for higher dimensions though as 2-dimensional boolean indexing is not supported. It would as well get rid of all other DataArrarys which do not have shared dimensions with the indexer. Probably, there is a better place to do this, that in the loc function. However, I think it would be great in case people need to filter their data by something else than the array dimensions.

Cheers,

Jendrik

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