diff --git a/doc/whats-new.rst b/doc/whats-new.rst index 93f335e625b..effb199f18e 100644 --- a/doc/whats-new.rst +++ b/doc/whats-new.rst @@ -26,6 +26,10 @@ Deprecations Bug Fixes ~~~~~~~~~ +- Fix a major performance regression in :py:meth:`Coordinates.to_index` (and + consequently :py:meth:`Dataset.to_dataframe`) caused by converting the cached + code ndarrays into Python lists (:issue:`11305`). + Documentation ~~~~~~~~~~~~~ diff --git a/xarray/core/coordinates.py b/xarray/core/coordinates.py index 85a9d97abeb..a8d5b724746 100644 --- a/xarray/core/coordinates.py +++ b/xarray/core/coordinates.py @@ -194,7 +194,7 @@ def to_index(self, ordered_dims: Sequence[Hashable] | None = None) -> pd.Index: return pd.MultiIndex( levels=level_list, # type: ignore[arg-type,unused-ignore] - codes=[list(c) for c in code_list], + codes=code_list, # type: ignore[arg-type,unused-ignore] names=names, )