home / github / issue_comments

Menu
  • Search all tables
  • GraphQL API

issue_comments: 965861064

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/pull/5961#issuecomment-965861064 https://api.github.com/repos/pydata/xarray/issues/5961 965861064 IC_kwDOAMm_X845kd7I 35968931 2021-11-11T00:08:44Z 2021-11-11T00:08:44Z MEMBER

Question: Does this change to ._variables need to propagate down to DatasetCoordinates and DataArrayCoordinates? I'm not sure what the intended behaviour is if the user alters .coords directly.

1) It seems it is possible to alter a ds via ds.coords[new_coord_name] = new_coord:

```python In [34]: ds = xr.Dataset({'a': 0})

In [35]: ds.coords['c'] = 2

In [36]: ds Out[36]: <xarray.Dataset> Dimensions: () Coordinates: c int64 2 Data variables: a int64 0 ```

(That's a bit weird given that the docstring of DatasetCoordinates describes it as an "immutable dictionary" :confused:)

2) It also seems it is possible to similarly alter a da via da.coords[new_coord_name] = new_coord:

```python In [30]: da = xr.DataArray(0)

In [31]: da.coords['c'] = 1

In [32]: da Out[32]: <xarray.DataArray ()> array(0) Coordinates: c int64 1 ```

3) However is it meant to be possible to alter a ds via ds[var].coords[new_coord_name] = new_coord? Because that currently silently fails to update:

```python In [37]: ds = xr.Dataset({'a': 0})

In [38]: ds['a'].coords['c'] = 2

In [39]: ds Out[39]: <xarray.Dataset> Dimensions: () Data variables: a int64 0

In [40]: ds['a'] Out[40]: <xarray.DataArray 'a' ()> array(0)

In [41]: ds['a'].coords Out[41]: Coordinates: empty Bizarrely this does change though:python In [42]: coords = ds['a'].coords

In [43]: coords['c'] = 2

In [44]: coords Out[44]: Coordinates: c int64 2 ```

If altering .coords is intended behaviour though that means that my DataManifest also has to be accessible from DataArrayCoordinates too, so that the wrapping DataTree node can know about any changes to dt.ds[var].coords.

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  1048697792
Powered by Datasette · Queries took 0.649ms · About: xarray-datasette