issues: 347895055
This data as json
id | node_id | number | title | user | state | locked | assignee | milestone | comments | created_at | updated_at | closed_at | author_association | active_lock_reason | draft | pull_request | body | reactions | performed_via_github_app | state_reason | repo | type |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
347895055 | MDU6SXNzdWUzNDc4OTUwNTU= | 2346 | Dataset/DataArray to_dataframe() dimensions order mismatch. | 1492047 | closed | 0 | 4 | 2018-08-06T12:03:00Z | 2020-08-10T17:45:43Z | 2020-08-08T07:10:28Z | CONTRIBUTOR | Code Sample```python import xarray as xr import numpy as np data = xr.DataArray(np.random.randn(2, 3), coords={'x': ['a', 'b']}, dims=('y', 'x')) ds = xr.Dataset({'foo': data}) Applied on the Datasetds.to_dataframe() foox ya 0 0.3485191 -0.3226342 -0.683181b 0 0.1975011 0.5048102 -1.871626Applied to the DataArrayds['foo'].to_dataframe() fooy x0 a 0.348519b 0.1975011 a -0.322634b 0.5048102 a -0.683181b -1.871626``` Problem descriptionThe to_dataframe method applied to a DataArray will respect the dimensions order whereas the same method applied to a Dataset will use an alphabetically sorted order. In both situation to_dataframe calls _to_dataframe() with an argument. The DataArray uses an OrderedDict but the Dataset uses self.dims (which is a SortedKeyDict) as argument. Output of
|
{ "url": "https://api.github.com/repos/pydata/xarray/issues/2346/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 } |
completed | 13221727 | issue |