(self)
| 305 | ) |
| 306 | |
| 307 | def _factorize_dummy(self) -> EncodedGroups: |
| 308 | size = self.group.size |
| 309 | # no need to factorize |
| 310 | # use slices to do views instead of fancy indexing |
| 311 | # equivalent to: group_indices = group_indices.reshape(-1, 1) |
| 312 | group_indices: GroupIndices = tuple(slice(i, i + 1) for i in range(size)) |
| 313 | size_range = np.arange(size) |
| 314 | full_index: pd.Index |
| 315 | unique_coord: _DummyGroup | Variable |
| 316 | if isinstance(self.group, _DummyGroup): |
| 317 | codes = self.group.to_dataarray().copy(data=size_range) |
| 318 | unique_coord = self.group |
| 319 | full_index = pd.RangeIndex(self.group.size) |
| 320 | coords = Coordinates() |
| 321 | else: |
| 322 | codes = self.group.copy(data=size_range, deep=False) |
| 323 | unique_coord = self.group.variable.to_base_variable() |
| 324 | full_index = self.group_as_index |
| 325 | if isinstance(full_index, pd.MultiIndex): |
| 326 | coords = Coordinates.from_pandas_multiindex( |
| 327 | full_index, dim=self.group.name |
| 328 | ) |
| 329 | else: |
| 330 | if TYPE_CHECKING: |
| 331 | assert isinstance(unique_coord, Variable) |
| 332 | coords = coordinates_from_variable(unique_coord) |
| 333 | |
| 334 | return EncodedGroups( |
| 335 | codes=codes, |
| 336 | group_indices=group_indices, |
| 337 | full_index=full_index, |
| 338 | unique_coord=unique_coord, |
| 339 | coords=coords, |
| 340 | ) |
| 341 | |
| 342 | |
| 343 | @dataclass |
no test coverage detected