home / github / issue_comments

Menu
  • Search all tables
  • GraphQL API

issue_comments: 603490643

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/3287#issuecomment-603490643 https://api.github.com/repos/pydata/xarray/issues/3287 603490643 MDEyOklzc3VlQ29tbWVudDYwMzQ5MDY0Mw== 6200806 2020-03-24T20:34:58Z 2020-03-24T20:34:58Z CONTRIBUTOR

Here's a quick and dirty workaround that works at least for my use case. arr_orig is the original DataArray from which arr_unstacked_bad was generated via a stack/groupby/apply/unstack chain yielding the _level_0 etc. dims, with the stack call having been arr_orig.stack(**{dim_of_stack: dims_stacked}). Likely excessively convoluted and YMMV.

```python def fix_unstacked_dims(arr_unstacked_bad, arr_orig, dim_of_stack, dims_stacked): """Workaround for xarray bug involving stacking str-based coords.

C.f. https://github.com/pydata/xarray/issues/3287

"""
dims_not_stacked = [dim for dim in arr_orig.dims if dim not in dims_stacked]
stacked_dims_after_unstack = [dim for dim in arr_unstacked_bad.dims 
                              if dim not in dims_not_stacked]
dims_mapping = {d1: d2 for d1, d2 in zip(stacked_dims_after_unstack, dims_stacked)}
arr_unstacked_bad = arr_unstacked_bad.rename(dims_mapping)

arr_out = arr_orig.copy(deep=True)
arr_out.values = arr_unstacked_bad.transpose(*arr_orig.dims).values
return arr_out.assign_coords(arr_orig.coords)

```

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