home / github / issue_comments

Menu
  • Search all tables
  • GraphQL API

issue_comments: 235575744

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/pull/917#issuecomment-235575744 https://api.github.com/repos/pydata/xarray/issues/917 235575744 MDEyOklzc3VlQ29tbWVudDIzNTU3NTc0NA== 4806877 2016-07-27T12:53:53Z 2016-07-27T14:50:13Z CONTRIBUTOR

Ok, I wrote a Dataset.from_dict class method. I imagine the DataArray one will look pretty similar, so I just wanted to see what you think. The main issue that I see is that time doesn't round trip. I wasn't sure if the user should need to set a parse_date flag with the dim name or something or whether the function should try to convert to time any dim with the string 'time' in it?

``` @classmethod def from_dict(cls, d): """ Convert a dictionary into an xarray.Dataset. """ obj = cls()

    dims=OrderedDict([(k, d['coords'][k]) for k in d['dims']])
    for dim, dim_d in dims.items():
        obj[dim] = (dim_d['dims'], dim_d['data'], dim_d['attrs'])

    for var, var_d in d['data_vars'].items():
        obj[var] = (var_d['dims'], var_d['data'], var_d['attrs'])

    # what it coords aren't dims?
    coords = (set(d['coords'].keys()) - set(d['dims']))
    for coord in coords:
        coord_d = d['coords'][coord]
        obj[coord] = (coord_d['dims'], coord_d['data'], coord_d['attrs'])
    obj = obj.set_coords(coords)

    obj.attrs.update(d['attrs'])

    return(obj)

```

Regarding unit tests, I haven't ever written one before but I would be happy to try (I know they are an important part of good development).

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