home / github / issue_comments

Menu
  • Search all tables
  • GraphQL API

issue_comments: 661087703

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/3245#issuecomment-661087703 https://api.github.com/repos/pydata/xarray/issues/3245 661087703 MDEyOklzc3VlQ29tbWVudDY2MTA4NzcwMw== 1610850 2020-07-20T14:49:55Z 2020-07-20T14:49:55Z CONTRIBUTOR

Thanks @keewis. I did consider that but I assumed that kind of thing wouldn't be encouraged. Happy to go down that path, but I wonder if life would be easier if there were an extension API for this purpose.

I was thinking of something along these lines which would help keep things in check.

```python @xr.register_dataarray_as_method("cupy") class CupyAsMethod: def to_cupy(self): """Convert all data arrays to cupy."""

    for var in self.data_vars: 
        self.data_vars[var].data = cp.asarray(self.data_vars[var].data)

    return self

def to_numpy(self):
    """Convert all data arrays to numpy."""

    for var in self.data_vars: 
        self.data_vars[var].data = self.data_vars[var].data.get()

    return self

```

There would need to be some logic around dispatching as_numpy to CupyAsMethod.as_numpy, but only if the underlying data is cupy.

Perhaps some is_numpy, is_cupy boolean attributes would be useful?

I could go as you suggest and use the current accessor tooling to test this functionality out. Then upstream it into something more maintainable if it works out ok?

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