MCPcopy
hub / github.com/pydata/xarray / _init_properties

Method _init_properties

xarray/groupers.py:520–551  ·  view source on GitHub ↗
(self, group: T_Group)

Source from the content-addressed store, hash-verified

518 )
519
520 def _init_properties(self, group: T_Group) -> None:
521 group_as_index = safe_cast_to_index(group)
522 offset = self.offset
523
524 if not group_as_index.is_monotonic_increasing:
525 # TODO: sort instead of raising an error
526 raise ValueError("Index must be monotonic for resampling")
527
528 if isinstance(group_as_index, CFTimeIndex):
529 self.index_grouper = CFTimeGrouper(
530 freq=self.freq,
531 closed=self.closed,
532 label=self.label,
533 origin=self.origin,
534 offset=offset,
535 )
536 else:
537 if isinstance(self.freq, BaseCFTimeOffset):
538 raise ValueError(
539 "'BaseCFTimeOffset' resample frequencies are only supported "
540 "when resampling a 'CFTimeIndex'"
541 )
542
543 self.index_grouper = pd.Grouper(
544 # TODO remove once requiring pandas >= 2.2
545 freq=_new_to_legacy_freq(self.freq),
546 closed=self.closed,
547 label=self.label,
548 origin=self.origin,
549 offset=offset,
550 )
551 self.group_as_index = group_as_index
552
553 def _get_index_and_items(self) -> tuple[pd.Index, pd.Series, np.ndarray]:
554 first_items, codes = self.first_items()

Callers 1

factorizeMethod · 0.95

Calls 3

safe_cast_to_indexFunction · 0.90
CFTimeGrouperClass · 0.90
_new_to_legacy_freqFunction · 0.90

Tested by

no test coverage detected