How to use the holidays.UnitedStates function in holidays

To help you get started, we’ve selected a few holidays examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github awslabs / gluon-ts / src / gluonts / dataset / artificial / generate_synthetic.py View on Github external
"constant_promotions/",
        ConstantDataset(
            is_promotions=True,
            freq="M",
            start="2015-11-30",
            num_timeseries=100,
            num_steps=50,
        ),
    )
    generate_sf2s_and_csv(
        file_path,
        "constant_holidays/",
        ConstantDataset(
            start="2017-07-01",
            freq="D",
            holidays=list(holidays.UnitedStates(years=[2017, 2018]).keys()),
            num_steps=365,
        ),
github maxbbraun / trump2cash / trading.py View on Github external
def is_trading_day(self, timestamp):
        """Tests whether markets are open on a given day."""

        # Markets are closed on holidays.
        if timestamp in UnitedStates():
            self.logs.debug("Identified holiday: %s" % timestamp)
            return False

        # Markets are closed on weekends.
        if timestamp.weekday() in [5, 6]:
            self.logs.debug("Identified weekend: %s" % timestamp)
            return False

        # Otherwise markets are open.
        return True
github openeemeter / eemeter / eemeter / modeling / models / seasonal.py View on Github external
def _holidays_indexed(dt_index):
        holidays_raw = holidays.UnitedStates()

        def clean_holiday_name(dt):
            raw_name = holidays_raw.get(dt, "none")
            if raw_name.endswith(" (Observed)"):
                return raw_name[:-11]
            else:
                return raw_name

        holiday_names = pd.Series(dt_index.map(clean_holiday_name),
                                  index=dt_index)
        return holiday_names
github rconcep / snl-quest / es_gui / readutdata2.py View on Github external
:param wkday_er: a 12x24 NumPy array, wkday_er[i][j] is the energy price in $/kWh during hour j+1 in a weekday of month i+1
    :param wkend_er: a 12x24 NumPy array, wkend_er[i][j] is the energy price in $/kWh during hour j+1 in a weekend day or a holiday of month i+1
    :param wkday_dr: a 12x24 NumPy array, wkday_dr[i][j] is the demand price in $/kW during hour j+1 in a weekday of month i+1
    :param wkend_dr: a 12x24 NumPy array, wkend_dr[i][j] is the demand price in $/kW during hour j+1 in a weekend day or a holiday of month i+1
    :param flat_dr: a float represents the flat demand price in $/kW for all hours of a month.
    :param nem: a float represents the netmetering sell price in $/kWh
    :return opt_df: a Pandas dataframe with the following template:|year|month|day|hour|toue|toud|flatd|neme|
    """
    column_list=['year','month','day','hour','toue','toud','flatd','neme']
    data_list=[]
    nday={1:31,2:28,3:31,4:30,5:31,6:30,7:31,8:31,9:30,10:31,11:30,12:31}
    
    if int(year)%4==0:
        nday[2]=29
        
    us_holidays=holidays.UnitedStates()
    for month in range(1,13):
        for day in range(1,nday[month]+1):
            date=datetime(year, month, day)
            dayofweek = date.weekday()
            for hour in range(1,25):
                if (date in us_holidays) or (dayofweek>4):
                    if wkend_dr.size>1:  
                        row=[year,month,day,hour,wkend_er[month-1][hour-1],wkend_dr[month-1][hour-1],flat_dr,nem]
                    else:
                        row=[year,month,day,hour,wkend_er[month-1][hour-1],0,flat_dr,nem]
                else:
                    if wkday_dr.size>1:  
                        row=[year,month,day,hour,wkday_er[month-1][hour-1],wkday_dr[month-1][hour-1],flat_dr,nem]
                    else:
                        row=[year,month,day,hour,wkday_er[month-1][hour-1],0,flat_dr,nem]
github greenelab / scrumlord / upkeep.py View on Github external
import argparse
import datetime
import functools
import re
import sys
import traceback
import typing

import holidays
import github


class PennHolidays(holidays.UnitedStates):

    def _populate(self, year):
        super()._populate(year)

        # See https://github.com/greenelab/scrum/issues/114
        for day in range(26, 32):
            self[datetime.date(year, 12, day)] = 'Special Winter Vacation'


holiday_names = {
    'Independence Day',
    'Labor Day',
    'Thanksgiving',
    'Christmas Day',
    "New Year's Day",
    'Martin Luther King, Jr. Day',
github dr-prodigy / python-holidays / holidays.py View on Github external
self[date(year, 12, 26) + rd(days=+1)] = name
        elif self.state == 'TX' and year >= 1981:
            self[date(year, 12, 26)] = "Day After Christmas"
        elif self.state == 'VI':
            self[date(year, 12, 26)] = "Christmas Second Day"

        # New Year's Eve
        if (self.state in ('KY', 'MI') and year >= 2013) or \
                (self.state == 'WI' and year >= 2012):
            name = "New Year's Eve"
            self[date(year, 12, 31)] = name
            if self.observed and date(year, 12, 31).weekday() == 5:
                self[date(year, 12, 30)] = name + " (Observed)"


class US(UnitedStates):
    pass


class NewZealand(HolidayBase):
    PROVINCES = ['NTL', 'AUK', 'TKI', 'HKB', 'WGN', 'MBH', 'NSN', 'CAN',
                 'STC', 'WTL', 'OTA', 'STL', 'CIT']

    def __init__(self, **kwargs):
        self.country = 'NZ'
        HolidayBase.__init__(self, **kwargs)

    def _populate(self, year):
        # Bank Holidays Act 1873
        # The Employment of Females Act 1873
        # Factories Act 1894
        # Industrial Conciliation and Arbitration Act 1894