| 560 | return full_index, first_items, codes |
| 561 | |
| 562 | def first_items(self) -> tuple[pd.Series, np.ndarray]: |
| 563 | if isinstance(self.index_grouper, CFTimeGrouper): |
| 564 | return self.index_grouper.first_items( |
| 565 | cast(CFTimeIndex, self.group_as_index) |
| 566 | ) |
| 567 | else: |
| 568 | s = pd.Series(np.arange(self.group_as_index.size), self.group_as_index) |
| 569 | grouped = s.groupby(self.index_grouper) |
| 570 | first_items = grouped.first() |
| 571 | counts = grouped.count() |
| 572 | # This way we generate codes for the final output index: full_index. |
| 573 | # So for _flox_reduce we avoid one reindex and copy by avoiding |
| 574 | # _maybe_reindex |
| 575 | codes = np.repeat(np.arange(len(first_items)), counts) |
| 576 | return first_items, codes |
| 577 | |
| 578 | def factorize(self, group: T_Group) -> EncodedGroups: |
| 579 | self._init_properties(group) |