home / github / issue_comments

Menu
  • Search all tables
  • GraphQL API

issue_comments: 427892990

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/2159#issuecomment-427892990 https://api.github.com/repos/pydata/xarray/issues/2159 427892990 MDEyOklzc3VlQ29tbWVudDQyNzg5Mjk5MA== 35968931 2018-10-08T16:12:06Z 2018-10-08T16:12:06Z MEMBER

Thanks @shoyer for the description of how this should be done properly.

In the meantime however, I thought I would describe how I solved the problem in my last comment. My method works but you probably wouldn't want to use it in xarray itself because it's pretty "hacky".

To avoid the issue of numpy reading the __array__ methods of xarray objects and doing weird things, I simply contained each dataset within a single-element dictionary in order to hide the offending methods, i.e.

python data = create_test_data() data_grid = np.array([{'key': data}], dtype='object') With this then creating something which will concatenate the numpy grid-like array of (dicts holding) datasets is quick: ```python from xarray import concat import numpy as np

def _concat_nd(obj_grid, concat_dims=None, data_vars=None, kwargs): # Combine datasets along one dimension at a time, # Have to start with last axis and finish with axis=0 otherwise axes will disappear before the loop reaches them for axis in reversed(range(obj_grid.ndim)): obj_grid = np.apply_along_axis(_concat_dicts, axis, arr=obj_grid, dim=concat_dims[axis], data_vars=data_vars[axis], kwargs)

# Grid should now only contain one dict which contains the concatenated xarray object
return obj_grid.item()['key']

def _concat_dicts(dict_objs, dim, data_vars, kwargs): objs = [dict_obj['key'] for dict_obj in dict_objs] return {'key': concat(objs, dim, data_vars, kwargs)}

``` In case anyone is interested then this is how I've (hopefully temporarily) solved the N-D concatenation problem in the case of my data.

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