Skip to content

MultiIndex coordinates loc/sel not working in 0.19.0 #5691

Closed

Description

@genric

What happened:

TypeError: unhashable type: 'numpy.ndarray'

What you expected to happen:
No error

Minimal Complete Verifiable Example:
Take this for example:

import numpy as np
import pandas as pd
import xarray as xr
midx = pd.MultiIndex.from_arrays([["R", "R", "V", "V"], [0.1, 0.2, 0.7, 0.9]], names=("band", "wn"))
mda = xr.DataArray(np.random.rand(4), coords={"spec": midx}, dims="spec")
mda.loc[{'band': 'R', 'wn': 0.1}]

Environment:

Details xarray: 0.19.0, pandas: 1.3.1, numpy: 1.21.1,

Activity

  1. benbovy commented on Aug 11, 2021

    @benbovy
    Member

    Thanks for the report @genric. Probably some regression introduced in #5322. I'm surprised this hasn't been caught in the tests. I'm also surprised that it seems to be fixed in #5692. I'll take a closer look.

  2. added a commit that references this issue on Aug 12, 2021
  3. benbovy commented on Aug 12, 2021

    @benbovy
    Member

    So the issue was that #3153 doesn't work well with multi-indexes that don't like numpy arrays nor even numpy scalars given as labels. Previously it worked because of multi-index virtual coordinates, i.e., the dtype of multi-index levels was ignored when internally re-organizing the indexers passed to .sel in xarray. However, this is not the case anymore as we are currently dropping virtual coordinates by real coordinates in the context of xarray's explicit indexes refactoring.

    This should be fixed in #5692 (a551c7f), although #3153 still doesn't address the case of multi-index level coordinates with float32 values.

  4. added a commit that references this issue on Mar 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions