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

Class TimeResampler

xarray/groupers.py:474–638  ·  view source on GitHub ↗

Grouper object specialized to resampling the time coordinate. Attributes ---------- freq : str, datetime.timedelta, pandas.Timestamp, or pandas.DateOffset Frequency to resample to. See `Pandas frequency aliases <https://pandas.pydata.org/pandas-docs/stable/user_guid

Source from the content-addressed store, hash-verified

472
473@dataclass(repr=False)
474class TimeResampler(Resampler):
475 """
476 Grouper object specialized to resampling the time coordinate.
477
478 Attributes
479 ----------
480 freq : str, datetime.timedelta, pandas.Timestamp, or pandas.DateOffset
481 Frequency to resample to. See `Pandas frequency
482 aliases <https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html#offset-aliases>`_
483 for a list of possible values.
484 closed : {"left", "right"}, optional
485 Side of each interval to treat as closed.
486 label : {"left", "right"}, optional
487 Side of each interval to use for labeling.
488 origin : {'epoch', 'start', 'start_day', 'end', 'end_day'}, pandas.Timestamp, datetime.datetime, numpy.datetime64, or cftime.datetime, default 'start_day'
489 The datetime on which to adjust the grouping. The timezone of origin
490 must match the timezone of the index.
491
492 If a datetime is not used, these values are also supported:
493 - 'epoch': `origin` is 1970-01-01
494 - 'start': `origin` is the first value of the timeseries
495 - 'start_day': `origin` is the first day at midnight of the timeseries
496 - 'end': `origin` is the last value of the timeseries
497 - 'end_day': `origin` is the ceiling midnight of the last day
498 offset : pd.Timedelta, datetime.timedelta, or str, default is None
499 An offset timedelta added to the origin.
500 """
501
502 freq: ResampleCompatible
503 closed: SideOptions | None = field(default=None)
504 label: SideOptions | None = field(default=None)
505 origin: str | DatetimeLike = field(default="start_day")
506 offset: pd.Timedelta | datetime.timedelta | str | None = field(default=None)
507
508 index_grouper: CFTimeGrouper | pd.Grouper = field(init=False, repr=False)
509 group_as_index: pd.Index = field(init=False, repr=False)
510
511 def reset(self) -> Self:
512 return type(self)(
513 freq=self.freq,
514 closed=self.closed,
515 label=self.label,
516 origin=self.origin,
517 offset=self.offset,
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,

Callers 4

_resampleMethod · 0.90

Calls

no outgoing calls

Tested by 3

Used in the wild real call sites across dependent graphs

searching dependent graphs…