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

Function _get_range_edges

xarray/core/resample_cftime.py:296–352  ·  view source on GitHub ↗

Get the correct starting and ending datetimes for the resampled CFTimeIndex range. Parameters ---------- first : cftime.datetime Uncorrected starting datetime object for resampled CFTimeIndex range. Usually the min of the original CFTimeIndex. last : cftime.datet

(
    first: CFTimeDatetime,
    last: CFTimeDatetime,
    freq: BaseCFTimeOffset,
    closed: SideOptions = "left",
    origin: str | CFTimeDatetime = "start_day",
    offset: datetime.timedelta | None = None,
)

Source from the content-addressed store, hash-verified

294
295
296def _get_range_edges(
297 first: CFTimeDatetime,
298 last: CFTimeDatetime,
299 freq: BaseCFTimeOffset,
300 closed: SideOptions = "left",
301 origin: str | CFTimeDatetime = "start_day",
302 offset: datetime.timedelta | None = None,
303):
304 """Get the correct starting and ending datetimes for the resampled
305 CFTimeIndex range.
306
307 Parameters
308 ----------
309 first : cftime.datetime
310 Uncorrected starting datetime object for resampled CFTimeIndex range.
311 Usually the min of the original CFTimeIndex.
312 last : cftime.datetime
313 Uncorrected ending datetime object for resampled CFTimeIndex range.
314 Usually the max of the original CFTimeIndex.
315 freq : xarray.coding.cftime_offsets.BaseCFTimeOffset
316 The offset object representing target conversion a.k.a. resampling
317 frequency. Contains information on offset type (e.g. Day or 'D') and
318 offset magnitude (e.g., n = 3).
319 closed : 'left' or 'right'
320 Which side of bin interval is closed. Defaults to 'left'.
321 origin : {'epoch', 'start', 'start_day', 'end', 'end_day'} or cftime.datetime, default 'start_day'
322 The datetime on which to adjust the grouping. The timezone of origin
323 must match the timezone of the index.
324
325 If a datetime is not used, these values are also supported:
326 - 'epoch': `origin` is 1970-01-01
327 - 'start': `origin` is the first value of the timeseries
328 - 'start_day': `origin` is the first day at midnight of the timeseries
329 - 'end': `origin` is the last value of the timeseries
330 - 'end_day': `origin` is the ceiling midnight of the last day
331 offset : datetime.timedelta, default is None
332 An offset timedelta added to the origin.
333
334 Returns
335 -------
336 first : cftime.datetime
337 Corrected starting datetime object for resampled CFTimeIndex range.
338 last : cftime.datetime
339 Corrected ending datetime object for resampled CFTimeIndex range.
340 """
341 if isinstance(freq, Tick):
342 first, last = _adjust_dates_anchored(
343 first, last, freq, closed=closed, origin=origin, offset=offset
344 )
345 return first, last
346 else:
347 first = normalize_date(first)
348 last = normalize_date(last)
349
350 first = freq.rollback(first) if closed == "left" else first - freq
351 last = last + freq
352 return first, last
353

Callers 1

_get_time_binsFunction · 0.85

Calls 3

normalize_dateFunction · 0.90
_adjust_dates_anchoredFunction · 0.85
rollbackMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…