def test_get_list(self):
        westland = holidays.NZ(prov="WTL")
        chathams = holidays.NZ(prov="CIT")
        wild = westland + chathams
        self.assertEqual(
            wild[date(1969, 12, 1)],
            ("Westland Anniversary Day, " + "Chatham Islands Anniversary Day"),
        )

        self.assertEqual(
            wild.get_list(date(1969, 12, 1)),
            ["Westland Anniversary Day", "Chatham Islands Anniversary Day"],
        )
        self.assertEqual(wild.get_list(date(1969, 1, 1)), ["New Year's Day"])
        self.assertEqual(westland.get_list(date(1969, 12, 1)),
                         ["Westland Anniversary Day"])
        self.assertEqual(westland.get_list(date(1969, 1, 1)),
                         ["New Year's Day"])
        self.assertEqual(
            chathams.get_list(date(1969, 12, 1)),
            ["Chatham Islands Anniversary Day"],
        )
        self.assertEqual(chathams.get_list(date(1969, 1, 1)),
                         ["New Year's Day"])
        ca = holidays.CA()
        us = holidays.US()
        mx = holidays.MX()
        na = ca + us + mx
        self.assertIn(date(1969, 12, 25), na)
        self.assertEqual(
            na.get_list(date(1969, 12, 25)),
            ["Christmas Day", "Navidad [Christmas]"],
        )
        self.assertEqual(na.get_list(date(1969, 7, 1)), ["Dominion Day"])
        self.assertEqual(na.get_list(date(1969, 1, 3)), [])
 def test_all_holidays_present(self):
     nz_1969 = sum(
         holidays.NZ(years=[1969], prov=p) for p in holidays.NZ.PROVINCES
     )
     holidays_in_1969 = sum((nz_1969.get_list(key) for key in nz_1969), [])
     nz_2015 = sum(
         holidays.NZ(years=[2015], prov=p) for p in holidays.NZ.PROVINCES
     )
     holidays_in_2015 = sum((nz_2015.get_list(key) for key in nz_2015), [])
     nz_1974 = sum(
         holidays.NZ(years=[1974], prov=p) for p in holidays.NZ.PROVINCES
     )
     holidays_in_1974 = sum((nz_1974.get_list(key) for key in nz_1974), [])
     all_holidays = [
         "New Year's Day",
         "Day after New Year's Day",
         "Waitangi Day",
         "Good Friday",
         "Easter Monday",
         "Anzac Day",
         "Queen's Birthday",
         "Labour Day",
         "Christmas Day",
         "Boxing Day",
         "Auckland Anniversary Day",
         "Taranaki Anniversary Day",
         "Hawke's Bay Anniversary Day",
         "Wellington Anniversary Day",
         "Marlborough Anniversary Day",
         "Nelson Anniversary Day",
         "Canterbury Anniversary Day",
         "South Canterbury Anniversary Day",
         "Westland Anniversary Day",
         "Otago Anniversary Day",
         "Southland Anniversary Day",
         "Chatham Islands Anniversary Day",
         "Queen's Birthday",
         "Labour Day",
         "Christmas Day",
         "Boxing Day",
     ]
     for holiday in all_holidays:
         self.assertIn(holiday, holidays_in_1969, holiday)
         self.assertIn(holiday, holidays_in_2015, holiday)
     all_holidays.remove("Waitangi Day")
     all_holidays.insert(2, "New Zealand Day")
     for holiday in all_holidays:
         self.assertIn(holiday, holidays_in_1974, holiday)
     self.assertNotIn("Waitangi Day", holidays_in_1974)
 def test_marlborough_anniversary_day(self):
     mbh_holidays = holidays.NZ(prov="Marlborough")
     for year, day in enumerate(
         [
             29,
             4,
             3,
             1,
             31,  # 2001-05
             30,
             29,
             3,
             2,
             1,  # 2006-10
             31,
             29,
             4,
             3,
             2,  # 2011-15
             31,
             30,
             29,
             4,
             2,
             1,
         ],  # 2016-21
         2001,
     ):
         dt = date(year, 11 if day < 9 else 10, day)
         self.assertIn(dt, mbh_holidays, dt)
         self.assertEqual(
             mbh_holidays[dt], "Marlborough Anniversary Day", dt
         )
 def test_otago_anniversary_day(self):
     ota_holidays = holidays.NZ(prov="Otago")
     for year, day in enumerate(
         [
             26,
             25,
             24,
             22,
             21,  # 2001-05
             20,
             26,
             25,
             23,
             22,  # 2006-10
             21,
             26,
             25,
             24,
             23,  # 2011-15
             21,
             20,
             26,
             25,
             23,
             22,
         ],  # 2016-21
         2001,
     ):
         dt = date(year, 3, day)
         self.assertIn(dt, ota_holidays, dt)
         self.assertEqual(ota_holidays[dt], "Otago Anniversary Day", dt)
 def test_south_canterbury_anniversary_day(self):
     stc_holidays = holidays.NZ(prov="South Canterbury")
     for year, day in enumerate(
         [
             24,
             23,
             22,
             27,
             26,  # 2001-05
             25,
             24,
             22,
             28,
             27,  # 2006-10
             26,
             24,
             23,
             22,
             28,  # 2011-15
             26,
             25,
             24,
             23,
             28,
             27,
         ],  # 2016-21
         2001,
     ):
         dt = date(year, 9, day)
         self.assertIn(dt, stc_holidays, dt)
         self.assertEqual(
             stc_holidays[dt], "South Canterbury Anniversary Day", dt
         )
 def test_southland_anniversary_day(self):
     stl_holidays = holidays.NZ(prov="Southland")
     for year, day in enumerate(
         [15, 14, 20, 19, 17, 16, 15, 14, 19, 18, 17],
         2001,  # 2001-05  # 2006-11
     ):
         dt = date(year, 1, day)
         self.assertIn(dt, stl_holidays, dt)
         self.assertEqual(stl_holidays[dt], "Southland Anniversary Day", dt)
         for year, (month, day) in enumerate(
             [
                 (4, 10),
                 (4, 2),
                 (4, 22),
                 (4, 7),
                 (3, 29),
                 (4, 18),
                 (4, 3),
                 (4, 23),
                 (4, 14),
                 (4, 6),
             ],
             2012,
         ):
             dt = date(year, month, day)
             self.assertIn(dt, stl_holidays, dt)
             self.assertEqual(
                 stl_holidays[dt], "Southland Anniversary Day", dt
             )
 def test_nelson_anniversary_day(self):
     nsn_holidays = holidays.NZ(prov="Nelson")
     for year, day in enumerate(
         [
             29,
             4,
             3,
             2,
             31,  # 2001-05
             30,
             29,
             4,
             2,
             1,  # 2006-10
             31,
             30,
             4,
             3,
             2,  # 2011-15
             1,
             30,
             29,
             4,
             3,
             1,
         ],  # 2016-21
         2001,
     ):
         dt = date(year, 2 if day < 9 else 1, day)
         self.assertIn(dt, nsn_holidays, dt)
         self.assertEqual(nsn_holidays[dt], "Nelson Anniversary Day", dt)
 def test_hawkes_bay_anniversary_day(self):
     hkb_holidays = holidays.NZ(prov="Hawke's Bay")
     for year, day in enumerate(
         [
             19,
             25,
             24,
             22,
             21,  # 2001-05
             20,
             19,
             24,
             23,
             22,  # 2006-10
             21,
             19,
             25,
             24,
             23,  # 2011-15
             21,
             20,
             19,
             25,
             23,
             22,
         ],  # 2016-21
         2001,
     ):
         dt = date(year, 10, day)
         self.assertIn(dt, hkb_holidays, dt)
         self.assertEqual(hkb_holidays[dt], "Hawke's Bay Anniversary Day")
 def test_wellington_anniversary_day(self):
     wgn_holidays = holidays.NZ(prov="Wellington")
     for year, day in enumerate(
         [
             22,
             21,
             20,
             19,
             24,  # 2001-05
             23,
             22,
             21,
             19,
             25,  # 2006-10
             24,
             23,
             21,
             20,
             19,  # 2011-15
             25,
             23,
             22,
             21,
             20,
             25,
         ],  # 2016-21
         2001,
     ):
         dt = date(year, 1, day)
         self.assertIn(dt, wgn_holidays, dt)
         self.assertEqual(
             wgn_holidays[dt], "Wellington Anniversary Day", dt
         )
 def test_taranaki_anniversary_day(self):
     tki_holidays = holidays.NZ(prov="Taranaki")
     for year, day in enumerate(
         [
             12,
             11,
             10,
             8,
             14,  # 2001-05
             13,
             12,
             10,
             9,
             8,  # 2006-10
             14,
             12,
             11,
             10,
             9,  # 2011-15
             14,
             13,
             12,
             11,
             9,
             8,
         ],  # 2016-21
         2001,
     ):
         dt = date(year, 3, day)
         self.assertIn(dt, tki_holidays, dt)
         self.assertEqual(tki_holidays[dt], "Taranaki Anniversary Day")
 def test_auckland_anniversary_day(self):
     auk_holidays = holidays.NZ(prov="Auckland")
     for year, day in enumerate(
         [
             29,
             28,
             27,
             26,
             31,  # 2001-05
             30,
             29,
             28,
             26,
             1,  # 2006-10
             31,
             30,
             28,
             27,
             26,  # 2011-15
             1,
             30,
             29,
             28,
             27,
             1,
         ],  # 2016-21
         2001,
     ):
         dt = date(year, 2 if day < 9 else 1, day)
         self.assertIn(dt, auk_holidays, dt)
         self.assertEqual(auk_holidays[dt], "Auckland Anniversary Day")
 def test_chatham_islands_anniversary_day(self):
     cit_holidays = holidays.NZ(prov="Chatham Islands")
     for year, day in enumerate(
         [
             3,
             2,
             1,
             29,
             28,  # 2001-05
             27,
             3,
             1,
             30,
             29,  # 2006-10
             28,
             3,
             2,
             1,
             30,  # 2011-15
             28,
             27,
             3,
             2,
             30,
             29,
         ],  # 2016-21
         2001,
     ):
         dt = date(year, 12 if day < 9 else 11, day)
         self.assertIn(dt, cit_holidays, dt)
         self.assertEqual(
             cit_holidays[dt], "Chatham Islands Anniversary Day", dt
         )
 def test_westland_anniversary_day(self):
     wtc_holidays = holidays.NZ(prov="Westland")
     for year, day in enumerate(
         [
             3,
             2,
             1,
             29,
             5,  # 2001-05
             4,
             3,
             1,
             30,
             29,  # 2006-10
             28,
             3,
             2,
             1,
             30,  # 2011-15
             28,
             4,
             3,
             2,
             30,
             29,
         ],  # 2016-21
         2001,
     ):
         dt = date(year, 12 if day < 9 else 11, day)
         self.assertIn(dt, wtc_holidays, dt)
         self.assertEqual(wtc_holidays[dt], "Westland Anniversary Day", dt)
 def test_canterbury_anniversary_day(self):
     can_holidays = holidays.NZ(prov="Canterbury")
     for year, day in enumerate(
         [
             16,
             15,
             14,
             12,
             11,  # 2001-05
             17,
             16,
             14,
             13,
             12,  # 2006-10
             11,
             16,
             15,
             14,
             13,  # 2011-15
             11,
             17,
             16,
             15,
             13,
             12,
         ],  # 2016-21
         2001,
     ):
         dt = date(year, 11, day)
         self.assertIn(dt, can_holidays, dt)
         self.assertEqual(
             can_holidays[dt], "Canterbury Anniversary Day", dt
         )
示例#15
0
class EventsOnDay(namedtuple("EODBase", "date days_events continuing_events")):
    aukHols = holidays.NZ(prov="Auckland")

    @property
    def weekday(self):
        return calendar.day_abbr[self.date.weekday()].lower()

    @property
    def holiday(self):
        return self.aukHols.get(self.date)
 def test_waitangi_day(self):
     ntl_holidays = holidays.NZ(prov="Northland")
     for year, day in enumerate([3, 8, 7, 6, 5], 1964):
         dt = date(year, 2, day)
         self.assertIn(dt, ntl_holidays, dt)
         self.assertEqual(ntl_holidays[dt][:8], "Waitangi")
     for year in range(1900, 1974):
         dt = date(year, 2, 6)
         self.assertNotIn(dt, self.holidays)
     for year in range(1974, 2100):
         dt = date(year, 2, 6)
         self.assertIn(dt, self.holidays)
     for year, day in enumerate(
         [
             6,
             6,
             6,
             6,
             6,  # 2001-05
             6,
             6,
             6,
             6,
             6,  # 2006-10
             6,
             6,
             6,
             6,
             6,  # 2011-15
             8,
             6,
             6,
             6,
             6,
             8,
         ],  # 2016-21
         2001,
     ):
         dt = date(year, 2, day)
         self.assertIn(dt, self.holidays)
         self.assertEqual(self.holidays[dt][:8], "Waitangi")
     self.assertNotIn(date(2005, 2, 7), self.holidays)
     self.assertNotIn(date(2010, 2, 8), self.holidays)
     self.assertNotIn(date(2011, 2, 7), self.holidays)
示例#17
0
def load(country, region, observed, expand, years):
    # Erases existing holiday cache and makes a new one...
    global dates

    if country == "US":
        dates = holidays.US(state=region,
                            observed=observed,
                            expand=expand,
                            years=years)
    elif country == "CA":
        dates = holidays.CA(prov=region,
                            observed=observed,
                            expand=expand,
                            years=years)
    elif country == "MX":
        dates = holidays.MX(observed=observed, expand=expand, years=years)
    elif country == "NZ":
        dates = holidays.NZ(prov=region,
                            observed=observed,
                            expand=expand,
                            years=years)
    elif country == "AU":
        dates = holidays.AU(prov=region,
                            observed=observed,
                            expand=expand,
                            years=years)
    elif country == "AT":
        dates = holidays.AT(prov=region,
                            observed=observed,
                            expand=expand,
                            years=years)
    elif country == "DE":
        dates = holidays.DE(prov=region,
                            observed=observed,
                            expand=expand,
                            years=years)
    else:
        print "UNKNOWN COUNTRY ", country
示例#18
0
文件: convert.py 项目: tkosht/ds3.6
        df_list.append(d)
    df = pd.concat(df_list, axis=0)
    df = df.loc[:, ["Tamaki Drive EB", "Tamaki Drive WB"]]
    Tamaki = df.loc[:, "Tamaki Drive WB"] + df.loc[:, "Tamaki Drive EB"]
    Tamaki = Tamaki.loc["2013":"2018-06-01", ]
    Tamaki = Tamaki.to_frame(name="Tamaki Drive")
    dfc = Tamaki.copy()
    dfc.loc[:, "Tamaki Drive, Filtered"] = utils.median_filter(
        dfc, varname="Tamaki Drive")
    data = dfc.loc["2013":, ["Tamaki Drive, Filtered"]].resample("1D").sum()

    holidays_df = pd.DataFrame([], columns=["ds", "holiday"])
    ldates = []
    lnames = []
    for date, name in sorted(
            holidays.NZ(prov="AUK", years=np.arange(2013, 2018 + 1)).items()):
        ldates.append(date)
        lnames.append(name)
    ldates = np.array(ldates)
    lnames = np.array(lnames)
    holidays_df.loc[:, "ds"] = ldates
    holidays_df.loc[:, "holiday"] = lnames
    holidays_df.loc[:, "holiday"] = holidays_df.loc[:, "holiday"].apply(
        lambda x: x.replace(" (Observed)", ""))
    holidays_df.holiday.unique()
    data = data.rename({"Tamaki Drive, Filtered": "y"}, axis=1)
    data_train, data_test = utils.prepare_data(data, 2017)

    # weather data
    temp = pd.read_csv("./data/weather/hourly/commute/temp_day.csv",
                       index_col=0,
示例#19
0
        country_last = response.country
    except:
        pass

    settings["country_last_updated"] = now
    settings["country_last"] = country_last
    settings.flush()
    return country_last


country_holidays = {
    "CA": holidays.CA(),
    "CO": holidays.CO(),
    "MX": holidays.MX(),
    "US": holidays.US(),
    "NZ": holidays.NZ(),
    "AU": holidays.AU(),
    "DE": holidays.DE(),
    "AT": holidays.AT(),
    "DK": holidays.DK(),
    "UK": holidays.UK(),
    "IE": holidays.IE(),
    "ES": holidays.ES(),
    "CZ": holidays.CZ(),
    "SK": holidays.SK(),
    "PL": holidays.PL(),
    "PT": holidays.PT(),
    "NL": holidays.NL(),
    "NO": holidays.NO(),
    "IT": holidays.IT(),
    "SE": holidays.SE(),
 def setUp(self):
     self.holidays = holidays.NZ(observed=True)
示例#21
0
 def judge_local_holiday(self, df):
     country = df['geoNetwork_country']
     date = df['visitId'].apply(lambda x: x.date())
     judge_holiday = \
         np.where(country.isin(
                 ['United States','India','Canada','Germany',
                  'Japan','France','Mexico','Australia',
                  'Spain','Netherlands','Italy','Ireland',
                  'Sweden','Argentina','Colombia','Belgium',
                  'Switzerland','Czechia','Colombia','Belgium',
                  'New Zealand','South Africa','South Africa']),\
         np.where((country=='United States')&
                  (date.isin(holidays.US())),1,
                  np.where((country=='India')&
                           (date.isin(holidays.India())),1,
                           np.where((country=='Canada')&
                                    (date.isin(holidays.CA())),1,
                                    np.where((country=='Germany')&
                                             (date.isin(holidays.DE())),1,\
         np.where((country=='Japan')&
                  (date.isin(holidays.JP())),1,
                  np.where((country=='France')&
                           (date.isin(holidays.FRA())),1,
                           np.where((country=='Mexico')&
                                    (date.isin(holidays.MX())),1,
                                    np.where((country=='Australia')&
                                             (date.isin(holidays.AU())),1,\
         np.where((country=='Spain')&
                  (date.isin(holidays.ES())),1,
                  np.where((country=='Netherlands')&
                           (date.isin(holidays.NL())),1,
                           np.where((country=='Italy')&
                                    (date.isin(holidays.IT())),1,
                                    np.where((country=='Ireland')&
                                             (date.isin(holidays.IE())),1,\
         np.where((country=='Sweden')&
                  (date.isin(holidays.SE())),1,
                  np.where((country=='Argentina')&
                           (date.isin(holidays.AR())),1,
                           np.where((country=='Colombia')&
                                    (date.isin(holidays.CO())),1,
                                    np.where((country=='Belgium')&
                                             (date.isin(holidays.BE())),1,\
         np.where((country=='Switzerland')&
                  (date.isin(holidays.CH())),1,
                  np.where((country=='Czechia')&
                           (date.isin(holidays.CZ())),1,
                           np.where((country=='Denmark')&
                                    (date.isin(holidays.DK())),1,
                                    np.where((country=='Austria')&
                                             (date.isin(holidays.AT())),1,\
         np.where((country=='Hungary')&
                  (date.isin(holidays.HU())),1,
                  np.where((country=='Portugal')&
                           (date.isin(holidays.PT())),1,
                           np.where((country=='Norway')&
                                    (date.isin(holidays.NO())),1,
                                    np.where((country=='Portugal')&
                                             (date.isin(holidays.PT())),1,\
         np.where((country=='New Zealand')&
                  (date.isin(holidays.NZ())),1,
                  np.where((country=='South Africa')&
                           (date.isin(holidays.ZA())),1,
                           np.where((country=='South Africa')&
                                    (date.isin(holidays.ZA())),1,\
         0))))))))))))))))))))))))))),np.nan).astype(int)
     return judge_holiday