home / github / issues

Menu
  • Search all tables
  • GraphQL API

issues: 237807730

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
237807730 MDU6SXNzdWUyMzc4MDc3MzA= 1463 copy / deepcopy not deepcopying coords? 1178948 closed 0     8 2017-06-22T10:59:19Z 2019-07-09T01:05:53Z 2019-07-09T00:54:02Z NONE      

I don't know if this is intentional, I thought that arr.copy(deep=True) or deepcopy(arr) would give me completely independent copies of a DateArray, but this seems not be the case?

```python

import xarray as xr xarr1 = xr.DataArray([1,2], coords=dict(x=[0,1]), dims=('x',)) xarr1.x.data[0] 0 xarr2 = xarr1.copy(deep=True) #xarr2 = deepcopy(xarr1) -> leads to same result xarr2.x.data[0] = -1 xarr1.x.data[0] -1 ```

How can I create completely independent copies of a DateArray? I wrote a function for this, but don't know if this really always does what I expect and if there is a more elegant way? ```python def deepcopy_xarr(xarr): """ Deepcopy for xarray that makes sure coords and attrs are properly deepcopied. With normal copy method from xarray, when i mutated xarr.coords[coord].data it would also mutate in the copy and vice versa. Parameters ---------- xarr: DateArray

Returns
-------
xcopy: DateArray
    Deep copy of xarr
"""
xcopy = xarr.copy(deep=True)

for dim in xcopy.coords:
    xcopy.coords[dim].data = np.copy(xcopy.coords[dim].data)
xcopy.attrs = deepcopy(xcopy.attrs)
for attr in xcopy.attrs:
    xcopy.attrs[attr] = deepcopy(xcopy.attrs[attr])
return xcopy

```

{
    "url": "https://api.github.com/repos/pydata/xarray/issues/1463/reactions",
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  completed 13221727 issue

Links from other tables

  • 2 rows from issues_id in issues_labels
  • 8 rows from issue in issue_comments
Powered by Datasette · Queries took 81.828ms · About: xarray-datasette