|
9 | 9 | import datetime
|
10 | 10 | from abc import ABC, abstractmethod
|
11 | 11 | from dataclasses import dataclass, field
|
12 |
| -from typing import Any, Literal, cast |
| 12 | +from typing import TYPE_CHECKING, Any, Literal, cast |
13 | 13 |
|
14 | 14 | import numpy as np
|
15 | 15 | import pandas as pd
|
@@ -205,21 +205,31 @@ def _factorize_dummy(self) -> EncodedGroups:
|
205 | 205 | group_indices: GroupIndices = tuple(slice(i, i + 1) for i in range(size))
|
206 | 206 | size_range = np.arange(size)
|
207 | 207 | full_index: pd.Index
|
| 208 | + unique_coord: _DummyGroup | Variable |
208 | 209 | if isinstance(self.group, _DummyGroup):
|
209 | 210 | codes = self.group.to_dataarray().copy(data=size_range)
|
210 | 211 | unique_coord = self.group
|
211 | 212 | full_index = pd.RangeIndex(self.group.size)
|
| 213 | + coords = Coordinates() |
212 | 214 | else:
|
213 | 215 | codes = self.group.copy(data=size_range)
|
214 | 216 | unique_coord = self.group.variable.to_base_variable()
|
215 | 217 | full_index = self.group_as_index
|
| 218 | + if isinstance(full_index, pd.MultiIndex): |
| 219 | + coords = Coordinates.from_pandas_multiindex( |
| 220 | + full_index, dim=self.group.name |
| 221 | + ) |
| 222 | + else: |
| 223 | + if TYPE_CHECKING: |
| 224 | + assert isinstance(unique_coord, Variable) |
| 225 | + coords = _coordinates_from_variable(unique_coord) |
216 | 226 |
|
217 | 227 | return EncodedGroups(
|
218 | 228 | codes=codes,
|
219 | 229 | group_indices=group_indices,
|
220 | 230 | full_index=full_index,
|
221 | 231 | unique_coord=unique_coord,
|
222 |
| - coords=Coordinates(), |
| 232 | + coords=coords, |
223 | 233 | )
|
224 | 234 |
|
225 | 235 |
|
|
0 commit comments