Skip to content

(fix): remove PandasExtensionArray from repr #10291

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion xarray/core/variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,8 @@ def _new(
@property
def _in_memory(self):
return isinstance(
self._data, np.ndarray | np.number | PandasIndexingAdapter
self._data,
np.ndarray | np.number | PandasIndexingAdapter | PandasExtensionArray,
) or (
isinstance(self._data, indexing.MemoryCachedArray)
and isinstance(self._data.array, indexing.NumpyIndexingAdapter)
Expand Down
5 changes: 3 additions & 2 deletions xarray/tests/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ def lazy_accessible(k, v) -> xr.Variable:

class TestDataset:
def test_repr(self) -> None:
data = create_test_data(seed=123)
data = create_test_data(seed=123, use_extension_array=True)
data.attrs["foo"] = "bar"
# need to insert str dtype at runtime to handle different endianness
expected = dedent(
Expand All @@ -297,6 +297,7 @@ def test_repr(self) -> None:
var1 (dim1, dim2) float64 576B -0.9891 -0.3678 1.288 ... -0.2116 0.364
var2 (dim1, dim2) float64 576B 0.953 1.52 1.704 ... 0.1347 -0.6423
var3 (dim3, dim1) float64 640B 0.4107 0.9941 0.1665 ... 0.716 1.555
var4 (dim1) category 64B 'b' 'c' 'b' 'a' 'c' 'a' 'c' 'a'
Attributes:
foo: bar""".format(
data["dim3"].dtype,
Expand Down Expand Up @@ -1814,7 +1815,7 @@ def test_categorical_index(self) -> None:
actual3 = ds.unstack("index")
assert actual3["var"].shape == (2, 2)

def test_categorical_reindex(self) -> None:
def test_categorical_index_reindex(self) -> None:
cat = pd.CategoricalIndex(
["foo", "bar", "baz"],
categories=["foo", "bar", "baz", "qux", "quux", "corge"],
Expand Down
Loading