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/6852#issuecomment-1200925682,https://api.github.com/repos/pydata/xarray/issues/6852,1200925682,IC_kwDOAMm_X85HlKvy,14808389,2022-08-01T09:06:16Z,2022-08-01T09:11:52Z,MEMBER,"bisecting tells me this is a regression introduced by #6389. Looking at the code, this happens because copying the variables with `variables.copy()` makes a shallow copy of the dictionary (and not its values), which means that we're actually mutating the `Dataset` variables. If I change that line to
```python
# make a shallow copy of each variable
new_variables = {name: var.copy() for name, var in variables.items()}
```
we stop mutating the dataset.
cc @benbovy","{""total_count"": 1, ""+1"": 1, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,1323521079
https://github.com/pydata/xarray/issues/6852#issuecomment-1200473092,https://api.github.com/repos/pydata/xarray/issues/6852,1200473092,IC_kwDOAMm_X85HjcQE,17813788,2022-07-31T18:11:12Z,2022-07-31T18:11:12Z,NONE,"keep_attrs=True doesn't help
```python
In [1]: import xarray as xr
In [2]: xr.set_options(keep_attrs=True)
Out[2]:
In [3]: da_withunits = xr.DataArray([1, 1, 1], coords={""frequency"": [1, 2, 3]})
In [4]: da_withunits.frequency.attrs[""units""] = ""GHz""
In [5]: da_withunits.frequency.units
Out[5]: 'GHz'
In [6]: da_withoutunits = xr.DataArray([1, 1, 1], coords={""frequency"": [1, 2, 3]})
In [7]: da_withunits == da_withoutunits
Out[7]:
array([ True, True, True])
Coordinates:
* frequency (frequency) int32 1 2 3
In [8]: da_withunits.frequency.units
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Input In [8], in ()
----> 1 da_withunits.frequency.units
File ~\AppData\Local\Programs\Python\Python39\lib\site-packages\xarray\core\common.py:256, in AttrAccessMixin.__getattr__(self, name)
254 with suppress(KeyError):
255 return source[name]
--> 256 raise AttributeError(
257 f""{type(self).__name__!r} object has no attribute {name!r}""
258 )
AttributeError: 'DataArray' object has no attribute 'units'
```","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,1323521079
https://github.com/pydata/xarray/issues/6852#issuecomment-1200463448,https://api.github.com/repos/pydata/xarray/issues/6852,1200463448,IC_kwDOAMm_X85HjZ5Y,14808389,2022-07-31T17:07:55Z,2022-07-31T17:45:05Z,MEMBER,"~can you try if setting `keep_attrs=True` helps?~
That's wrong, I can reproduce the side-effects. Not sure where that's coming from, though. And interestingly, only the first operand is mutated, `da_withoutunits == da_withunits` does not drop the units on `da_withunits`.","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,1323521079
|