issue_comments
4 rows where issue = 620134014 sorted by updated_at descending
This data as json, CSV (advanced)
Suggested facets: created_at (date), updated_at (date)
issue 1
- Error in DataArray.from_dict(data_array.to_dict()) when using pd.MultiIndex · 4 ✖
id | html_url | issue_url | node_id | user | created_at | updated_at ▲ | author_association | body | reactions | performed_via_github_app | issue |
---|---|---|---|---|---|---|---|---|---|---|---|
1163292454 | https://github.com/pydata/xarray/issues/4073#issuecomment-1163292454 | https://api.github.com/repos/pydata/xarray/issues/4073 | IC_kwDOAMm_X85FVm8m | phockett 4447466 | 2022-06-22T15:51:51Z | 2022-06-22T16:12:34Z | CONTRIBUTOR | I also ran into this when trying to serialize to Some notes below in case it is useful for anyone else trying to do this. Also - this is all quite ugly, and I may have missed some existing core functionality, so I'll be very happy to hear if there is a better way to handle this. Following the above, a minimal example: ```python import pandas as pd import xarray as xr idx = pd.MultiIndex.from_arrays([[1, 2], [3, 4]], names=('one', 'two')) array = xr.DataArray([0, 1], dims='idx', coords={'idx': idx}) Stacked multidim coords > dict > recreate array - Failsxr.DataArray.from_dict(array.to_dict()) Unstack multidim coords > dict > recreate array - OKxr.DataArray.from_dict(array.unstack().to_dict()) Set non-dimensional coordarray2 = array.copy() array2['Labels'] = ('idx', ['A','B']) # Add non-dim coord array2 = array2.swap_dims({'idx':'Labels'}) # Swap dims Non-dim coord case - also need to reset and drop non-dim coordsThis will failarray2_dict = array2.unstack().reset_index('idx').to_dict() xr.DataArray.from_dict(array2_dict) This is OKarray2_dict = array2.unstack().reset_index('idx', drop=True).to_dict() xr.DataArray.from_dict(array2_dict) This is also OKarray2_dict = array2.unstack().drop('idx').to_dict() xr.DataArray.from_dict(array2_dict) ``` In all cases the reconstructed array is flat, and missing non-dim coords. My work-around for this so far is to pull various mappings manually, and dump everything to ```python def mapDims(data): # Get dims from Xarray dims = data.dims # Set dim list - this excludes stacked dims dimsUS = data.unstack().dims # Set unstaked (full) dim list
def deconstructDims(data):
def reconstructDims(data):
``` Dict round-trip is then OK, and the dictionary can also be pushed to standard file types (contains only python native types + numpy array). ```python IO with funcsWith additional tuple coordarray2 = array.copy() array2['Labels'] = ('idx', ['A','B']) # Add non-dim coord array2 = array2.swap_dims({'idx':'Labels'}) # Swap dims Decon to dictsafeDict = deconstructDims(array2).to_dict() RebuildxrFromDict = reconstructDims(xr.DataArray.from_dict(safeDict)) Same as array2 (aside from added attrs)array2.attrs = xrFromDict.attrs array2.identical(xrFromDict) # True ``` Again, there is likely some cleaner/more obvious thing I'm missing here, but I'm not very familiar with Xarray or Pandas internals here - this is just where I ended up when trying to convert to HDF5 compatible datastructures in a semi-general way. (As a side-note, I ran into similar issues with |
{ "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 } |
Error in DataArray.from_dict(data_array.to_dict()) when using pd.MultiIndex 620134014 | |
1102116177 | https://github.com/pydata/xarray/issues/4073#issuecomment-1102116177 | https://api.github.com/repos/pydata/xarray/issues/4073 | IC_kwDOAMm_X85BsPVR | max-sixty 5635139 | 2022-04-19T05:48:31Z | 2022-04-19T05:48:31Z | MEMBER | This is indeed not ideal. I'm not sure we have great round-trip support for I'll mark as a bug. Any PRs working towards this would be greatly appreciated. (and apologies your excellent issue didn't get picked up @genric ) |
{ "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 } |
Error in DataArray.from_dict(data_array.to_dict()) when using pd.MultiIndex 620134014 | |
1102108752 | https://github.com/pydata/xarray/issues/4073#issuecomment-1102108752 | https://api.github.com/repos/pydata/xarray/issues/4073 | IC_kwDOAMm_X85BsNhQ | stale[bot] 26384082 | 2022-04-19T05:43:50Z | 2022-04-19T05:43:50Z | NONE | In order to maintain a list of currently relevant issues, we mark issues as stale after a period of inactivity If this issue remains relevant, please comment here or remove the |
{ "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 } |
Error in DataArray.from_dict(data_array.to_dict()) when using pd.MultiIndex 620134014 | |
641786386 | https://github.com/pydata/xarray/issues/4073#issuecomment-641786386 | https://api.github.com/repos/pydata/xarray/issues/4073 | MDEyOklzc3VlQ29tbWVudDY0MTc4NjM4Ng== | genric 13747844 | 2020-06-10T07:21:56Z | 2020-06-10T07:21:56Z | NONE | Didn't know that it is such a fundamental problem. Managed to get around with set/reset index. |
{ "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 } |
Error in DataArray.from_dict(data_array.to_dict()) when using pd.MultiIndex 620134014 |
Advanced export
JSON shape: default, array, newline-delimited, object
CREATE TABLE [issue_comments] ( [html_url] TEXT, [issue_url] TEXT, [id] INTEGER PRIMARY KEY, [node_id] TEXT, [user] INTEGER REFERENCES [users]([id]), [created_at] TEXT, [updated_at] TEXT, [author_association] TEXT, [body] TEXT, [reactions] TEXT, [performed_via_github_app] TEXT, [issue] INTEGER REFERENCES [issues]([id]) ); CREATE INDEX [idx_issue_comments_issue] ON [issue_comments] ([issue]); CREATE INDEX [idx_issue_comments_user] ON [issue_comments] ([user]);
user 4