MCPcopy
hub / github.com/pandas-dev/pandas / _apply_rule

Method _apply_rule

pandas/tseries/holiday.py:396–426  ·  view source on GitHub ↗

Apply the given offset/observance to a DatetimeIndex of dates. Parameters ---------- dates : DatetimeIndex Dates to apply the given offset/observance rule Returns ------- Dates with rules applied

(self, dates: DatetimeIndex)

Source from the content-addressed store, hash-verified

394 return dates
395
396 def _apply_rule(self, dates: DatetimeIndex) -> DatetimeIndex:
397 """
398 Apply the given offset/observance to a DatetimeIndex of dates.
399
400 Parameters
401 ----------
402 dates : DatetimeIndex
403 Dates to apply the given offset/observance rule
404
405 Returns
406 -------
407 Dates with rules applied
408 """
409 if dates.empty:
410 return dates.copy()
411
412 if self.observance is not None:
413 return dates.map(lambda d: self.observance(d))
414
415 if self.offset is not None:
416 if not isinstance(self.offset, list):
417 offsets = [self.offset]
418 else:
419 offsets = self.offset
420 for offset in offsets:
421 # if we are adding a non-vectorized value
422 # ignore the PerformanceWarnings:
423 with warnings.catch_warnings():
424 warnings.simplefilter("ignore", PerformanceWarning)
425 dates += offset
426 return dates
427
428
429holiday_calendars: dict[str, type[AbstractHolidayCalendar]] = {}

Callers 1

datesMethod · 0.95

Calls 2

copyMethod · 0.45
mapMethod · 0.45

Tested by

no test coverage detected