issues: 347558405
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 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
347558405 | MDU6SXNzdWUzNDc1NTg0MDU= | 2340 | expand_dims erases named dim in the array's coordinates | 90008 | closed | 0 | 5 | 2018-08-03T23:00:07Z | 2018-08-05T01:15:49Z | 2018-08-04T03:39:49Z | CONTRIBUTOR | Code Sample, a copy-pastable example if possible```python %%import xarray as xa import numpy as np n = np.zeros((3, 2)) data = xa.DataArray(n, dims=['y', 'x'], coords={'y':range(3), 'x':range(2)}) data = data.assign_coords(z=xa.DataArray(np.arange(6).reshape((3, 2)), dims=['y', 'x'])) print('Original Data') print('=============') print(data) %%my_slice = data[0, 1] print("Sliced data") print("===========") print("z coordinate remembers it's own x value") print(f'x = {my_slice.z.x}') %%expanded_slice = data[0, 1].expand_dims('x') print("expanded slice") print("==============") print("forgot that 'z' had 'x' coordinates") print("but remembered it had a 'y' coordinate") print(f"z = {expanded_slice.z}") print(expanded_slice.z.x) ``` Output:
Problem descriptionThe coordinate used to have an explicit dimension. When we expanded the dimension, that information should not be erased. Note that information about other coordinates are maintained. The challengeThe coordinates probably have fewer dimensions than the original data. I'm not sure about xarray's model, but a few challenges come to mind: 1. is the relative order of dimensions maintained between data in the same dataset/dataarray? 2. Can coordinates have MORE dimensions than the array itself? The answer to these two questions might make or break If not, then this becomes a very difficult problem to solve since we don't know where to insert this new dimension in the coordinate array. Output of
|
{ "url": "https://api.github.com/repos/pydata/xarray/issues/2340/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 } |
completed | 13221727 | issue |