issue_comments: 1256553736
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/2835#issuecomment-1256553736 | https://api.github.com/repos/pydata/xarray/issues/2835 | 1256553736 | IC_kwDOAMm_X85K5X0I | 4447466 | 2022-09-23T18:47:58Z | 2022-09-27T15:00:51Z | CONTRIBUTOR | Just for the record, I just ran into this for the specific case of nested dictionary attrs in Dataarray.attrs. It's definitely an issue in 2022.3.0 and 2022.6.0. Here's a minimal test example in case anyone else runs into this too... ```python MINIMAL EXAMPLEimport xarray as xr import numpy as np data = xr.DataArray(np.random.randn(2, 3), dims=("x", "y"), coords={"x": [10, 20]}) data.attrs['flat']='0' data.attrs['nested']={'level1':'1'} data2 = data.copy(deep=True) data2.attrs['flat']='2' # OK data2.attrs['nested']={'level1':'2'} # OKdata2.attrs['nested']['level1'] = '2' # Fails - overwrites datadata2.attrs['nested'].update({'level1':'2'}) # Fails - overwrites data print(data.attrs) print(data2.attrs) ``` Outputs In XR 2022.3.0 and 2022.6.0 this gives (incorrect): ``` {'flat': '0', 'nested': {'level1': '2'}} {'flat': '2', 'nested': {'level1': '2'}} ``` As a work-around, safe attrs copy with deepcopy works: ```python data2 = data.copy(deep=True) data2.attrs = copy.deepcopy(data.attrs) ``` With correct results after modification: ``` {'flat': '0', 'nested': {'level1': '1'}} {'flat': '2', 'nested': {'level1': '2'}} ``` EDIT 26th Sept: retested in 2022.6.0 and found it was, in fact, failing there too. Updated comment to reflect this. |
{ "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 } |
423742774 |