From 1aec6cc75574868690e714072cf2d73da2c6b11b Mon Sep 17 00:00:00 2001 From: ilan-gold Date: Wed, 7 May 2025 11:51:28 +0200 Subject: [PATCH] (fix): remove `PandasExtensionArray` from repr --- xarray/core/variable.py | 3 ++- xarray/tests/test_dataset.py | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/xarray/core/variable.py b/xarray/core/variable.py index b8b33997780..20685a0b3a4 100644 --- a/xarray/core/variable.py +++ b/xarray/core/variable.py @@ -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) diff --git a/xarray/tests/test_dataset.py b/xarray/tests/test_dataset.py index 52c60a77066..a440ec2a244 100644 --- a/xarray/tests/test_dataset.py +++ b/xarray/tests/test_dataset.py @@ -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( @@ -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, @@ -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"],