Skip to content

Commit d7c40a1

Browse files
committed
Coordinates.to_index: still use full data dims
This function is used internally for Xarray -> Pandas conversion, where we still want dimensions without coordinate be converted to an index.
1 parent 2b90358 commit d7c40a1

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

xarray/core/coordinates.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,27 +112,28 @@ def to_dataset(self) -> Dataset:
112112
raise NotImplementedError()
113113

114114
def to_index(self, ordered_dims: Sequence[Hashable] | None = None) -> pd.Index:
115-
"""Convert all index coordinates into a :py:class:`pandas.Index`.
115+
"""Convert all index dimension coordinates into a :py:class:`pandas.Index`.
116116
117117
Parameters
118118
----------
119119
ordered_dims : sequence of hashable, optional
120-
Possibly reordered version of this object's dimensions indicating
120+
Possibly reordered version of this object's dimensions (or the full dimensions
121+
of it's corresponding Dataset, DataArray or DataTree object) indicating
121122
the order in which dimensions should appear on the result.
122123
123124
Returns
124125
-------
125126
pandas.Index
126127
Index subclass corresponding to the outer-product of all dimension
127128
coordinates. This will be a MultiIndex if this object is has more
128-
than more dimension.
129+
than one dimension.
129130
"""
130131
if ordered_dims is None:
131-
ordered_dims = list(self.dims)
132-
elif set(ordered_dims) != set(self.dims):
132+
ordered_dims = list(self._data.dims)
133+
elif set(ordered_dims) != set(self._data.dims):
133134
raise ValueError(
134135
"ordered_dims must match dims, but does not: "
135-
f"{ordered_dims} vs {self.dims}"
136+
f"{ordered_dims} vs {tuple(self._data.dims)}"
136137
)
137138

138139
if len(ordered_dims) == 0:

0 commit comments

Comments
 (0)