Use holidays package for Turkey

This commit is contained in:
Ben Letham 2020-08-17 14:24:47 -07:00
parent c7c63ff568
commit 6ec0a90a60
2 changed files with 5 additions and 61 deletions

View file

@ -525,7 +525,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"The holidays for each country are provided by the `holidays` package in Python. A list of available countries, and the country name to use, is available on their page: https://github.com/dr-prodigy/python-holidays. In addition to those countries, Prophet includes holidays for these countries: Brazil (BR), Indonesia (ID), India (IN), Malaysia (MY), Vietnam (VN), Thailand (TH), Philippines (PH), Turkey (TU), Pakistan (PK), Bangladesh (BD), Egypt (EG), China (CN), and Russian (RU), Korea (KR), Belarus (BY), and United Arab Emirates (AE).\n",
"The holidays for each country are provided by the `holidays` package in Python. A list of available countries, and the country name to use, is available on their page: https://github.com/dr-prodigy/python-holidays. In addition to those countries, Prophet includes holidays for these countries: Brazil (BR), Indonesia (ID), India (IN), Malaysia (MY), Vietnam (VN), Thailand (TH), Philippines (PH), Pakistan (PK), Bangladesh (BD), Egypt (EG), China (CN), and Russian (RU), Korea (KR), Belarus (BY), and United Arab Emirates (AE).\n",
"\n",
"In Python, most holidays are computed deterministically and so are available for any date range; a warning will be raised if dates fall outside the range supported by that country. In R, holiday dates are computed for 1995 through 2044 and stored in the package as `data-raw/generated_holidays.csv`. If a wider date range is needed, this script can be used to replace that file with a different date range: https://github.com/facebook/prophet/blob/master/python/scripts/generate_holidays_file.py.\n",
"\n",
@ -1220,7 +1220,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
"version": "3.7.8"
}
},
"nbformat": 4,

View file

@ -14,7 +14,7 @@ from convertdate.islamic import from_gregorian, to_gregorian
from lunarcalendar import Lunar, Converter
from lunarcalendar.converter import DateNotExist
from holidays import WEEKEND, HolidayBase
from holidays import WEEKEND, HolidayBase, Turkey
from dateutil.easter import easter, EASTER_ORTHODOX
from dateutil.relativedelta import relativedelta as rd
@ -918,64 +918,8 @@ class PH(Philippines):
# ------------ Holidays in Turkey---------------------
class Turkey(HolidayBase):
"""
Implement public holidays in Turkey
Reference:
https://en.wikipedia.org/wiki/Public_holidays_in_Turkey
"""
def __init__(self, **kwargs):
self.country = "TU"
HolidayBase.__init__(self, **kwargs)
def _populate(self, year):
# New Year's Day
name = "New Year's Day"
self[date(year, 1, 1)] = name
# National Sovereignty and Children's Day
name = "National Sovereignty and Children's Day "
self[date(year, 4, 23)] = name
# Labor Day
name = "Labor Day"
self[date(year, 5, 1)] = name
# Commemoration of Atatürk, Youth and Sports Day
name = u"Commemoration of Atatürk, Youth and Sports Day"
self[date(year, 5, 19)] = name
# Democracy and National Unity Day
name = "Democracy and National Unity Day"
self[date(year, 7, 15)] = name
# Victory Day
name = "Victory Day"
self[date(year, 8, 30)] = name
# Republic Day
name = "Republic Day"
self[date(year, 10, 29)] = name
# Eid al-Fitr
name = "Eid al-Fitr"
for offset in range(-1, 2, 1):
islam_year = from_gregorian(year + offset, 6, 15)[0]
y, m, d = to_gregorian(islam_year, 10, 1)
ds = date(y, m, d) - timedelta(days=1)
if ds.year == year:
self[ds] = name
# Eid al-Adha, i.e., Feast of the Sacrifice
name = "Feast of the Sacrifice"
for offset in range(-1, 2, 1):
islam_year = from_gregorian(year + offset, 8, 22)[0]
y, m, d = to_gregorian(islam_year, 12, 10)
if y == year:
self[date(y, m, d)] = name
# This is now in Holidays, but with alias TR instead of the TU that we used.
# Include TU as an alias for backwards compatibility.
class TU(Turkey):
pass