MCPcopy Index your code
hub / github.com/pydata/xarray / first_items

Method first_items

xarray/groupers.py:562–576  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

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)

Callers 1

_get_index_and_itemsMethod · 0.95

Calls 5

arangeMethod · 0.80
firstMethod · 0.80
repeatMethod · 0.80
groupbyMethod · 0.45
countMethod · 0.45

Tested by

no test coverage detected