First and last offsets should be calculated from the start day to fix an error cause by resampling across multiple days when a one day period is not a multiple of the frequency. See https://github.com/pandas-dev/pandas/issues/8683 Parameters ---------- first : cftime.datetim
(
first: CFTimeDatetime,
last: CFTimeDatetime,
freq: Tick,
closed: SideOptions = "right",
origin: str | CFTimeDatetime = "start_day",
offset: datetime.timedelta | None = None,
)
| 353 | |
| 354 | |
| 355 | def _adjust_dates_anchored( |
| 356 | first: CFTimeDatetime, |
| 357 | last: CFTimeDatetime, |
| 358 | freq: Tick, |
| 359 | closed: SideOptions = "right", |
| 360 | origin: str | CFTimeDatetime = "start_day", |
| 361 | offset: datetime.timedelta | None = None, |
| 362 | ): |
| 363 | """First and last offsets should be calculated from the start day to fix |
| 364 | an error cause by resampling across multiple days when a one day period is |
| 365 | not a multiple of the frequency. |
| 366 | See https://github.com/pandas-dev/pandas/issues/8683 |
| 367 | |
| 368 | Parameters |
| 369 | ---------- |
| 370 | first : cftime.datetime |
| 371 | A datetime object representing the start of a CFTimeIndex range. |
| 372 | last : cftime.datetime |
| 373 | A datetime object representing the end of a CFTimeIndex range. |
| 374 | freq : xarray.coding.cftime_offsets.BaseCFTimeOffset |
| 375 | The offset object representing target conversion a.k.a. resampling |
| 376 | frequency. Contains information on offset type (e.g. Day or 'D') and |
| 377 | offset magnitude (e.g., n = 3). |
| 378 | closed : 'left' or 'right' |
| 379 | Which side of bin interval is closed. Defaults to 'right'. |
| 380 | origin : {'epoch', 'start', 'start_day', 'end', 'end_day'} or cftime.datetime, default 'start_day' |
| 381 | The datetime on which to adjust the grouping. The timezone of origin |
| 382 | must match the timezone of the index. |
| 383 | |
| 384 | If a datetime is not used, these values are also supported: |
| 385 | - 'epoch': `origin` is 1970-01-01 |
| 386 | - 'start': `origin` is the first value of the timeseries |
| 387 | - 'start_day': `origin` is the first day at midnight of the timeseries |
| 388 | - 'end': `origin` is the last value of the timeseries |
| 389 | - 'end_day': `origin` is the ceiling midnight of the last day |
| 390 | offset : datetime.timedelta, default is None |
| 391 | An offset timedelta added to the origin. |
| 392 | |
| 393 | Returns |
| 394 | ------- |
| 395 | fresult : cftime.datetime |
| 396 | A datetime object representing the start of a date range that has been |
| 397 | adjusted to fix resampling errors. |
| 398 | lresult : cftime.datetime |
| 399 | A datetime object representing the end of a date range that has been |
| 400 | adjusted to fix resampling errors. |
| 401 | """ |
| 402 | import cftime |
| 403 | |
| 404 | if origin == "start_day": |
| 405 | origin_date = normalize_date(first) |
| 406 | elif origin == "start": |
| 407 | origin_date = first |
| 408 | elif origin == "epoch": |
| 409 | origin_date = type(first)(1970, 1, 1) |
| 410 | elif origin in ["end", "end_day"]: |
| 411 | origin_last = last if origin == "end" else _ceil_via_cftimeindex(last, "D") |
| 412 | sub_freq_times = (origin_last - first) // freq.as_timedelta() |
no test coverage detected
searching dependent graphs…