pandas.tseries.holiday.Holiday#

class pandas.tseries.holiday.Holiday(name, year=None, month=None, day=None, offset=None, observance=None, start_date=None, end_date=None, days_of_week=None, exclude_dates=None)[source]#

Class that defines a holiday with start/end dates and rules for observance.

A Holiday can either be defined by a fixed year/month/day, or, more commonly, by a recurring month/day combined with an offset or observance rule that adjusts the date in each year it is calculated for. Instances of Holiday are typically collected in the rules of an AbstractHolidayCalendar.

Parameters:
namestr

Name of the holiday, defaults to class name.

yearint, default None

Year of the holiday.

monthint, default None

Month of the holiday.

dayint, default None

Day of the holiday.

offsetDateOffset or list of DateOffset, default None

Computes offset from date. See pandas.tseries.offsets for the available offset classes.

observancefunction, default None

Computes when holiday is given a pandas Timestamp.

start_datedatetime-like, default None

First date the holiday is observed.

end_datedatetime-like, default None

Last date the holiday is observed.

days_of_weektuple of int or dateutil.relativedelta weekday strs, default None

Provide a tuple of days e.g (0,1,2,3,) for Monday through Thursday Monday=0,..,Sunday=6 Only instances of the holiday included in days_of_week will be computed.

exclude_datesDatetimeIndex or default None

Specific dates to exclude e.g. skipping a specific year’s holiday.

See also

tseries.holiday.AbstractHolidayCalendar

Abstract interface to create holidays following certain rules.

tseries.holiday.Holiday.dates

Calculate holidays observed between start date and end date.

Examples

>>> from dateutil.relativedelta import MO
>>> USMemorialDay = pd.tseries.holiday.Holiday(
...     "Memorial Day", month=5, day=31, offset=pd.DateOffset(weekday=MO(-1))
... )
>>> USMemorialDay
Holiday: Memorial Day (month=5, day=31, offset=<DateOffset: weekday=MO(-1)>)
>>> USLaborDay = pd.tseries.holiday.Holiday(
...     "Labor Day", month=9, day=1, offset=pd.DateOffset(weekday=MO(1))
... )
>>> USLaborDay
Holiday: Labor Day (month=9, day=1, offset=<DateOffset: weekday=MO(+1)>)
>>> July3rd = pd.tseries.holiday.Holiday("July 3rd", month=7, day=3)
>>> July3rd
Holiday: July 3rd (month=7, day=3, )
>>> NewYears = pd.tseries.holiday.Holiday(
...     "New Years Day",
...     month=1,
...     day=1,
...     observance=pd.tseries.holiday.nearest_workday,
... )
>>> NewYears
Holiday: New Years Day (
    month=1, day=1, observance=<function nearest_workday at 0x66545e9bc440>
)
>>> July3rd = pd.tseries.holiday.Holiday(
...     "July 3rd", month=7, day=3, days_of_week=(0, 1, 2, 3)
... )
>>> July3rd
Holiday: July 3rd (month=7, day=3, )

Attributes

Methods

dates(start_date, end_date[, return_name])

Calculate holidays observed between start date and end date.