Skip to content

selection from MultiIndex does not work properly #3512

Closed
@fujiisoup

Description

@fujiisoup

MCVE Code Sample

da = xr.DataArray([0, 1], dims=['x'], coords={'x': [0, 1], 'y': 'a'})
db = xr.DataArray([2, 3], dims=['x'], coords={'x': [0, 1], 'y': 'b'})
data = xr.concat([da, db], dim='x').set_index(xy=['x', 'y'])
data.sel(y='a')

>>> <xarray.DataArray (x: 4)>
>>> array([0, 1, 2, 3])
>>> Coordinates:
>>>   * x        (x) int64 0 1

Expected Output

>>> <xarray.DataArray (x: 2)>
>>> array([0, 1])
>>> Coordinates:
>>>   * x        (x) int64 0 1

Problem Description

Should select the array

Output of xr.show_versions()

INSTALLED VERSIONS ------------------ commit: None python: 3.6.8 |Anaconda, Inc.| (default, Dec 30 2018, 01:22:34) [GCC 7.3.0] python-bits: 64 OS: Linux OS-release: 3.10.0-957.10.1.el7.x86_64 machine: x86_64 processor: x86_64 byteorder: little LC_ALL: None LANG: en_US.UTF-8 LOCALE: en_US.UTF-8 libhdf5: 1.10.4 libnetcdf: 4.6.1

xarray: 0.14.0
pandas: 0.24.2
numpy: 1.15.4
scipy: 1.2.1
netCDF4: 1.4.2
pydap: None
h5netcdf: None
h5py: 2.9.0
Nio: None
zarr: None
cftime: 1.0.3.4
nc_time_axis: None
PseudoNetCDF: None
rasterio: None
cfgrib: None
iris: None
bottleneck: 1.2.1
dask: None
distributed: None
matplotlib: 3.0.2
cartopy: None
seaborn: 0.9.0
numbagg: None
setuptools: 40.8.0
pip: 19.0.3
conda: None
pytest: 5.0.0
IPython: 7.3.0
sphinx: None

Sorry for being quiet for a long time. I hope I could send a fix for this in a few days...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions