home / github / issue_comments

Menu
  • GraphQL API
  • Search all tables

issue_comments: 708686170

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/4501#issuecomment-708686170 https://api.github.com/repos/pydata/xarray/issues/4501 708686170 MDEyOklzc3VlQ29tbWVudDcwODY4NjE3MA== 1053153 2020-10-14T22:07:38Z 2020-10-14T22:07:38Z CONTRIBUTOR

My mental model of what's happening may not be correct. I did want sel(), isel(), and squeeze() to all operate the same way (and maybe someday even work on non-dim coordinates!). Replacing squeeze() with isel() in my initial example gives the same failure, which I would want it to work:

``` import numpy as np import xarray as xr

arr1 = xr.DataArray(np.zeros((1,5)), dims=['y', 'x'], coords={'e': ('y', [10])}) arr2 = arr1.isel(y=0).expand_dims('y') xr.testing.assert_identical(arr1, arr2) ```

``` AssertionError: Left and right DataArray objects are not identical

Differing coordinates: L e (y) int64 10 R e int64 10 ```

The non-dim coordinate e has forgotten that it was associated with y. I'd prefer that this association remained.

Where it gets really interesting is in the following example where the non-dim coordinate moves from one dim to another. I understand the logic here (since the isel() were done in a way that correlates 'y' and 'z'). In my proposal, this would not happen without explicit user intervention -- which may actually be desired here (it's sorta surprising):

``` import numpy as np import xarray as xr

arr = xr.DataArray(np.zeros((2, 2, 5)), dims=['z', 'y', 'x'], coords={'e': ('y', [10, 20])}) print(arr.coords) print()

arr0 = arr.isel(z=0,y=0) arr1 = arr.isel(z=1,y=1)

arr_concat = xr.concat([arr0, arr1], 'z') print(arr_concat.coords) ```

``` Coordinates: e (y) int64 10 20

Coordinates: e (z) int64 10 20 ```

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