Skip to content

.sel does not keep selected coordinate value in case with MultiIndex #1408

Closed
@fujiisoup

Description

@fujiisoup

.sel method usually keeps selected coordinate value as a scalar coordinate

In[4] ds1 = xr.Dataset({'foo': (('x',), [1, 2, 3])}, {'x': [1, 2, 3], 'y': 'a'})

Out[4]: 
<xarray.Dataset>
Dimensions:  ()
Coordinates:
    y        <U1 'a'
    x        int64 1
Data variables:
    foo      int64 1

But in MultiIndex case, does not.

In[5] ds2 = xr.Dataset({'foo': (('x',), [4, 5, 6])}, {'x': [1, 2, 3], 'y': 'b'})
        ds = xr.concat([ds1, ds2], dim='y').stack(yx=['y', 'x'])
        ds.sel(x=2)
Out[5] 
<xarray.Dataset>
Dimensions:  (y: 2)
Coordinates:
  * y        (y) object 'a' 'b'
Data variables:
    foo      (y) int64 2 5

x is gone.
Is it a desired behavior?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions