This is a simple container for the grouping parameters that implements a single method, the only one required for resampling in xarray. It cannot be used in a call to groupby like a pandas.Grouper object can.
| 64 | |
| 65 | |
| 66 | class CFTimeGrouper: |
| 67 | """This is a simple container for the grouping parameters that implements a |
| 68 | single method, the only one required for resampling in xarray. It cannot |
| 69 | be used in a call to groupby like a pandas.Grouper object can.""" |
| 70 | |
| 71 | freq: BaseCFTimeOffset |
| 72 | closed: SideOptions |
| 73 | label: SideOptions |
| 74 | loffset: str | datetime.timedelta | BaseCFTimeOffset | None |
| 75 | origin: str | CFTimeDatetime |
| 76 | offset: datetime.timedelta | None |
| 77 | |
| 78 | def __init__( |
| 79 | self, |
| 80 | freq: ResampleCompatible | BaseCFTimeOffset, |
| 81 | closed: SideOptions | None = None, |
| 82 | label: SideOptions | None = None, |
| 83 | origin: str | CFTimeDatetime = "start_day", |
| 84 | offset: str | datetime.timedelta | BaseCFTimeOffset | None = None, |
| 85 | ): |
| 86 | self.freq = to_offset(freq) |
| 87 | self.origin = origin |
| 88 | |
| 89 | if not isinstance(self.freq, CFTIME_TICKS): |
| 90 | if offset is not None: |
| 91 | message = ( |
| 92 | "The 'offset' keyword does not take effect when " |
| 93 | "resampling with a 'freq' that is not Tick-like (h, m, s, " |
| 94 | "ms, us)" |
| 95 | ) |
| 96 | emit_user_level_warning(message, category=RuntimeWarning) |
| 97 | if origin != "start_day": |
| 98 | message = ( |
| 99 | "The 'origin' keyword does not take effect when " |
| 100 | "resampling with a 'freq' that is not Tick-like (h, m, s, " |
| 101 | "ms, us)" |
| 102 | ) |
| 103 | emit_user_level_warning(message, category=RuntimeWarning) |
| 104 | |
| 105 | if isinstance(self.freq, MonthEnd | QuarterEnd | YearEnd) or self.origin in [ |
| 106 | "end", |
| 107 | "end_day", |
| 108 | ]: |
| 109 | # The backward resample sets ``closed`` to ``'right'`` by default |
| 110 | # since the last value should be considered as the edge point for |
| 111 | # the last bin. When origin in "end" or "end_day", the value for a |
| 112 | # specific ``cftime.datetime`` index stands for the resample result |
| 113 | # from the current ``cftime.datetime`` minus ``freq`` to the current |
| 114 | # ``cftime.datetime`` with a right close. |
| 115 | if closed is None: |
| 116 | self.closed = "right" |
| 117 | else: |
| 118 | self.closed = closed |
| 119 | if label is None: |
| 120 | self.label = "right" |
| 121 | else: |
| 122 | self.label = label |
| 123 | else: |
no outgoing calls
searching dependent graphs…