Closed
Description
It appears that #9520 may have broken some upstream pandas tests, specifically testing round-trips with various index types:
https://github.com/pandas-dev/pandas/blob/e78ebd3f845c086af1d71c0604701ec49df97228/pandas/tests/generic/test_to_xarray.py#L32
Here's a minimal test case:
import pandas as pd
import numpy as np
cat = pd.Categorical(list("abcd"))
df = pd.DataFrame({"f": cat}, index=cat)
restored = df.to_xarray().to_dataframe()
print(restored.index) # Index(['a', 'b', 'c', 'd'], dtype='object', name='index')
print(df.index) # CategoricalIndex(['a', 'b', 'c', 'd'], categories=['a', 'b', 'c', 'd'], ordered=False, dtype='category')
I'm not sure if this is a pandas or xarray issue, but it's one or the other!
(My guess is that most of these tests in pandas should probably live in xarray instead, given that we implement all the conversion logic.)
Originally posted by @shoyer in #9520 (comment)