def month_and_festivals(data): """ DOCSTRING: Creates a 'Month' column along with a list of feativals based on 'Purchase UTC DateTime', with reference to 'Purchase Date'. Additionally 'Holiday' column gets created with national holidays currently for India and North America. INPUT: > data : Only accepts Pandas DataFrame or TextParser. OUTPUT: Pandas DataFrame or TextParser with 2 new columns encompassing Months of respective year and Festivals. """ # Extracting Month name (not localized): data["Month"] = data["Purchase UTC DateTime"].dt.month_name() # Acknowledging Global Festivities and Holidays for Customers on Purchase Date. Countries covered include: [India and North America]: data["Holiday"] = np.nan # Dictionary items would require update down the lane: country_iso_codes = holidays.IND() + holidays.US() for i, v in data["Purchase Date"].iteritems(): if v in country_iso_codes: data.loc[i, "Holiday"] = country_iso_codes[v] """ # [INFO] Failed to use personalized 'indian_days' and 'american_days' list of holidays: for i,v in data["Purchase Date"].iteritems(): if data.loc[i, "Country"] == "IN": if v in indian_days: data.loc[i, "Holiday"] = indian_days[v] elif data.loc[i, "Country"] == "US": if v in american_days: data.loc[i, "Holiday"] = american_days[v] else: country_iso_codes = holidays.IND() + holidays.US() + holidays.CA() if v in country_iso_codes: data.loc[i, "Holiday"] = country_iso_codes[v] """ return data
def checkPrev(self): import pandas as pd import datetime import holidays #var = datetime.datetime.now() #var1= var.strftime('%Y') var1 = datetime.datetime.strptime(str(self.leave_date), '%d-%m-%Y') var1 = str(var1.strftime("%Y")) L=[] for ptr in holidays.IND(years = int(var1)).items(): L.append(ptr[0].strftime('%d-%m-%Y')) #d3 = var.strftime("%A") #if...and holidays print(var1) s=datetime.datetime.now() s1=s.strftime('%d-%m-%Y') d1 = datetime.datetime.strptime(s1, '%d-%m-%Y') d2 = datetime.datetime.strptime(str(self.leave_date), '%d-%m-%Y') d22 = d2.strftime('%d-%m-%Y') d3 = str(d2.strftime('%A')) print(d3) print(type(d2)) print(str(d2)) if d1<d2 and d3 != "Sunday" and str(d22) not in L: return True elif d3 == "Sunday": return "Cant Apply Leave on Sunday" elif str(d22) in L: return "Cant Apply Leave on public holidays"
from datetime import date import holidays #help(holidays) print(holidays.IND()) date(2014, 1, 1) in holidays.IND() True date(2014, 1, 2) in holidays.IND() False IND_holidays = holidays.IND() date(2014, 1, 1) in IND_holidays True date(2014, 1, 2) in IND_holidays False holidays.IND() == holidays.IND() True for date, name in sorted(holidays.IND(state='AP', years=2014).items()): print(date, name)
def holiday(): holy=[] for date in sorted(holidays.IND(years=2019).items()): holy.append(date[0]) return holy
def isHoliday(u, m, yearex): h = holidays.IND() holidaydate = '' + u + '-' + m + '-' + yearex if (holidaydate in h): return True return False
def test_2018(self): self.assertIn(date(2018, 1, 14), self.holidays) self.assertIn(date(2018, 1, 26), self.holidays) self.assertIn(date(2018, 10, 2), self.holidays) self.assertIn(date(2018, 5, 1), self.holidays) self.assertIn(date(2018, 8, 15), self.holidays) self.assertIn(date(2018, 10, 2), self.holidays) self.assertIn(date(2018, 12, 25), self.holidays) gj_holidays = holidays.IND(prov="GJ") as_holidays = holidays.IND(prov="AS") tn_holidays = holidays.IND(prov="TN") wb_holidays = holidays.IND(prov="WB") cg_holidays = holidays.IND(prov="CG") sk_holidays = holidays.IND(prov="SK") ka_holidays = holidays.IND(prov="KA") br_holidays = holidays.IND(prov="BR") rj_holidays = holidays.IND(prov="RJ") od_holidays = holidays.IND(prov="OD") ap_holidays = holidays.IND(prov="AP") kl_holidays = holidays.IND(prov="KL") hr_holidays = holidays.IND(prov="HR") mh_holidays = holidays.IND(prov="MH") mp_holidays = holidays.IND(prov="MP") up_holidays = holidays.IND(prov="UP") uk_holidays = holidays.IND(prov="UK") ts_holidays = holidays.IND(prov="TS") for dt in [date(2018, 1, 14), date(2018, 5, 1), date(2018, 10, 31)]: self.assertIn(dt, gj_holidays) for dt in [date(2018, 4, 15), date(2018, 4, 14)]: self.assertIn(dt, tn_holidays) self.assertIn(dt, wb_holidays) for dt in [date(2018, 1, 14), date(2018, 5, 1), date(2018, 10, 31)]: self.assertIn(dt, gj_holidays) self.assertIn(date(2018, 3, 22), br_holidays) self.assertIn(date(2018, 3, 30), rj_holidays) self.assertIn(date(2018, 6, 15), rj_holidays) self.assertIn(date(2018, 4, 1), od_holidays) self.assertIn(date(2018, 4, 6), ts_holidays) self.assertIn(date(2018, 4, 15), od_holidays) self.assertIn(date(2018, 4, 14), od_holidays) self.assertIn(date(2018, 4, 14), br_holidays) self.assertIn(date(2018, 4, 14), kl_holidays) self.assertIn(date(2018, 4, 14), up_holidays) self.assertIn(date(2018, 4, 14), uk_holidays) self.assertIn(date(2018, 4, 14), hr_holidays) self.assertIn(date(2018, 4, 14), mh_holidays) self.assertIn(date(2018, 4, 14), wb_holidays) self.assertIn(date(2018, 5, 9), wb_holidays) self.assertIn(date(2018, 4, 15), as_holidays) self.assertIn(date(2018, 5, 1), mh_holidays) self.assertIn(date(2018, 5, 16), sk_holidays) self.assertIn(date(2018, 10, 6), ts_holidays) self.assertIn(date(2018, 11, 1), ka_holidays) self.assertIn(date(2018, 11, 1), ap_holidays) self.assertIn(date(2018, 11, 1), hr_holidays) self.assertIn(date(2018, 11, 1), mp_holidays) self.assertIn(date(2018, 11, 1), kl_holidays) self.assertIn(date(2018, 11, 1), cg_holidays)
def setUp(self): self.holidays = holidays.IND()