Obtain the bins and their respective labels for resampling operations. Parameters ---------- index : CFTimeIndex Index object to be resampled (e.g., CFTimeIndex named 'time'). freq : xarray.coding.cftime_offsets.BaseCFTimeOffset The offset object representing target
(
index: CFTimeIndex,
freq: BaseCFTimeOffset,
closed: SideOptions,
label: SideOptions,
origin: str | CFTimeDatetime,
offset: datetime.timedelta | None,
)
| 171 | |
| 172 | |
| 173 | def _get_time_bins( |
| 174 | index: CFTimeIndex, |
| 175 | freq: BaseCFTimeOffset, |
| 176 | closed: SideOptions, |
| 177 | label: SideOptions, |
| 178 | origin: str | CFTimeDatetime, |
| 179 | offset: datetime.timedelta | None, |
| 180 | ): |
| 181 | """Obtain the bins and their respective labels for resampling operations. |
| 182 | |
| 183 | Parameters |
| 184 | ---------- |
| 185 | index : CFTimeIndex |
| 186 | Index object to be resampled (e.g., CFTimeIndex named 'time'). |
| 187 | freq : xarray.coding.cftime_offsets.BaseCFTimeOffset |
| 188 | The offset object representing target conversion a.k.a. resampling |
| 189 | frequency (e.g., 'MS', '2D', 'H', or '3T' with |
| 190 | coding.cftime_offsets.to_offset() applied to it). |
| 191 | closed : 'left' or 'right' |
| 192 | Which side of bin interval is closed. |
| 193 | The default is 'left' for all frequency offsets except for 'M' and 'A', |
| 194 | which have a default of 'right'. |
| 195 | label : 'left' or 'right' |
| 196 | Which bin edge label to label bucket with. |
| 197 | The default is 'left' for all frequency offsets except for 'M' and 'A', |
| 198 | which have a default of 'right'. |
| 199 | origin : {'epoch', 'start', 'start_day', 'end', 'end_day'} or cftime.datetime, default 'start_day' |
| 200 | The datetime on which to adjust the grouping. The timezone of origin |
| 201 | must match the timezone of the index. |
| 202 | |
| 203 | If a datetime is not used, these values are also supported: |
| 204 | - 'epoch': `origin` is 1970-01-01 |
| 205 | - 'start': `origin` is the first value of the timeseries |
| 206 | - 'start_day': `origin` is the first day at midnight of the timeseries |
| 207 | - 'end': `origin` is the last value of the timeseries |
| 208 | - 'end_day': `origin` is the ceiling midnight of the last day |
| 209 | offset : datetime.timedelta, default is None |
| 210 | An offset timedelta added to the origin. |
| 211 | |
| 212 | Returns |
| 213 | ------- |
| 214 | datetime_bins : CFTimeIndex |
| 215 | Defines the edge of resampling bins by which original index values will |
| 216 | be grouped into. |
| 217 | labels : CFTimeIndex |
| 218 | Define what the user actually sees the bins labeled as. |
| 219 | """ |
| 220 | |
| 221 | if not isinstance(index, CFTimeIndex): |
| 222 | raise TypeError( |
| 223 | "index must be a CFTimeIndex, but got " |
| 224 | f"an instance of {type(index).__name__!r}" |
| 225 | ) |
| 226 | if len(index) == 0: |
| 227 | datetime_bins = labels = CFTimeIndex(data=[], name=index.name) |
| 228 | return datetime_bins, labels |
| 229 | |
| 230 | first, last = _get_range_edges( |
no test coverage detected
searching dependent graphs…