issues: 1343642737
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 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1343642737 | I_kwDOAMm_X85QFlxx | 6931 | `.swap_dims()` can modify original object | 15079414 | closed | 0 | 0 | 2022-08-18T21:01:27Z | 2022-08-22T10:39:54Z | 2022-08-22T10:39:54Z | CONTRIBUTOR | What happened?This is kind of a convoluted example, but something I ran into. It appears that in certain cases What did you expect to happen?I expected it not to modify the original object. Minimal Complete Verifiable Example```Python import numpy as np import xarray as xr nz = 11 ds = xr.Dataset( data_vars={ "y": ("z", np.random.rand(nz)), "lev": ("z", np.arange(nz) * 10), # ^ We want this to be a dimension coordinate }, ) print(f"ds\n{ds}") print(f"\nds, 'lev' -> dim coord\n{ds.swap_dims(z='lev')}") ds2 = ( ds.swap_dims(z="lev") .rename_dims(lev="z") .reset_index("lev") .reset_coords() ) print(f"\nds2\n{ds2}") ^ This Dataset appears same as the originalprint(f"\nds2, 'lev' -> dim coord\n{ds2.swap_dims(z='lev')}") ^ Produces a Dataset with dimension coordinate 'lev'print(f"\nds2 after .swap_dims() applied\n{ds2}") ^
|
{ "url": "https://api.github.com/repos/pydata/xarray/issues/6931/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 } |
completed | 13221727 | issue |