home / github / issues

Menu
  • GraphQL API
  • Search all tables

issues: 588821932

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
588821932 MDU6SXNzdWU1ODg4MjE5MzI= 3899 _indexes of DataArray are not deep copied 2272878 closed 0     4 2020-03-27T01:19:07Z 2020-03-29T02:01:20Z 2020-03-29T02:01:20Z CONTRIBUTOR      

In DataArray.copy, the _indexes attributes is not deep copied. After pull request #3840, this causes deleting a coordinate of a copy will also delete that coordinate from the original, even for deep copies.

MCVE Code Sample

```python a0 = xr.DataArray( np.array([[1, 2, 3], [4, 5, 6]]), dims=["y", "x"], coords={"x": ["a", "b", "c"], "y": [-1, 1]}, )

a1 = a0.copy() del a1.coords["y"]

xr.tests.assert_identical(a0, a0) ```

The result is:

``` xarray/testing.py:272: in _assert_internal_invariants _assert_dataarray_invariants(xarray_obj) xarray/testing.py:222: in _assert_dataarray_invariants _assert_indexes_invariants_checks(da._indexes, da._coords, da.dims)


indexes = {'x': Index(['a', 'b', 'c'], dtype='object', name='x')}, possible_coord_variables = {'x': <xarray.IndexVariable 'x' (x: 3)> array(['a', 'b', 'c'], dtype='<U1'), 'y': <xarray.IndexVariable 'y' (y: 2)> array([-1, 1])} dims = ('y', 'x')

def _assert_indexes_invariants_checks(indexes, possible_coord_variables, dims):
    assert isinstance(indexes, dict), indexes
    assert all(isinstance(v, pd.Index) for v in indexes.values()), {
        k: type(v) for k, v in indexes.items()
    }

    index_vars = {
        k for k, v in possible_coord_variables.items() if isinstance(v, IndexVariable)
    }
    assert indexes.keys() <= index_vars, (set(indexes), index_vars)

    # Note: when we support non-default indexes, these checks should be opt-in
    # only!
    defaults = default_indexes(possible_coord_variables, dims)
  assert indexes.keys() == defaults.keys(), (set(indexes), set(defaults))

E AssertionError: ({'x'}, {'y', 'x'})

xarray/testing.py:185: AssertionError ```

Expected Output

The test should pass.

Problem Description

Doing a deep copy should make a copy of everything. Changing a deep copy should not alter the original in any way.

{
    "url": "https://api.github.com/repos/pydata/xarray/issues/3899/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

  • 0 rows from issues_id in issues_labels
  • 4 rows from issue in issue_comments
Powered by Datasette · Queries took 0.552ms · About: xarray-datasette