Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce subdivisions aliases #1662

Merged
merged 38 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
a61806d
Adds aliases for subdivisions.
sphh Jan 23, 2024
228f2d3
Adds aliases for the Austrian holiday calendar.
sphh Jan 23, 2024
9561b47
Adds bank holidays to Austrian subdivisions.
sphh Jan 23, 2024
1fd4da4
Explains aliases in the README.rst
sphh Jan 24, 2024
917a1d8
Adds aliases for Austria in brackets to table with available countrie…
sphh Jan 25, 2024
9e8d747
Corrects "ISO3166-2" to "ISO 3166-2".
sphh Jan 25, 2024
3f42012
Updates doc string of utils/country_holidays to include subdivision a…
sphh Jan 25, 2024
aea4310
Adds 'list_supported_aliases' to utils.py.
sphh Jan 25, 2024
b0f641b
Fixes errors caught by 'make pre-commit'.
sphh Jan 25, 2024
71e1b09
Updates translation files and adds en_US translation for additional A…
sphh Jan 25, 2024
1061f37
Extents tests for Austrian holidays.
sphh Jan 25, 2024
a44dfb8
Updates test algorithm to cater for aliases.
sphh Jan 25, 2024
0e7c29a
Adds copyright notices.
sphh Jan 25, 2024
1fb9605
Update holidays/countries/austria.py
sphh Jan 26, 2024
337255d
Update holidays/countries/austria.py
sphh Jan 26, 2024
3c81441
Update holidays/countries/austria.py
sphh Jan 26, 2024
db41699
Update holidays/countries/austria.py
sphh Jan 26, 2024
dc65b99
Update holidays/locale/uk/LC_MESSAGES/AT.po
sphh Jan 26, 2024
755eb1a
Update holidays/locale/uk/LC_MESSAGES/AT.po
sphh Jan 26, 2024
ad331c1
Update holidays/locale/uk/LC_MESSAGES/AT.po
sphh Jan 26, 2024
d93b890
Update holidays/locale/uk/LC_MESSAGES/AT.po
sphh Jan 26, 2024
a67046c
Update holidays/locale/uk/LC_MESSAGES/AT.po
sphh Jan 26, 2024
ad9fa43
Update holidays/locale/uk/LC_MESSAGES/AT.po
sphh Jan 26, 2024
32917cd
Merge branch 'beta' into pr/sphh/1662
arkid15r Jan 27, 2024
a769350
Update PR
arkid15r Jan 28, 2024
d0cb109
Removes the default subdivision from Austrian holiday.
sphh Jan 28, 2024
a20a9e1
Adds new copyright notice according to #1672
sphh Jan 28, 2024
e472fcc
Merge branch 'beta' into subdivision-aliases
sphh Jan 28, 2024
4bee8af
Merge branch 'subdivision-aliases' of github.com:sphh/python-holidays…
arkid15r Jan 29, 2024
4e7650c
Merge branch 'beta' into pr/sphh/1662
arkid15r Jan 29, 2024
427ecf3
Merge branch 'beta' into pr/sphh/1662
arkid15r Jan 30, 2024
e779597
Refactor HolidayBase::get_subdivision_aliases
arkid15r Jan 30, 2024
ebf7f8d
Update PR:
arkid15r Feb 8, 2024
10c5a67
Merge branch 'beta' into pr/sphh/1662
arkid15r Feb 8, 2024
6e85ec6
Update PR:
arkid15r Feb 12, 2024
8a0004a
Merge branch 'beta' into subdivision-aliases
arkid15r Feb 12, 2024
07d3559
Merge branch 'subdivision-aliases' of github.com:sphh/python-holidays…
arkid15r Feb 13, 2024
c19c6fe
Add St. Florian's Day comment
arkid15r Feb 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,10 @@ Available Countries

We currently support 142 country codes. The standard way to refer to a country
is by using its `ISO 3166-1 alpha-2 code`_, the same used for domain names, and
for a subdivision its `ISO 3166-2 code`_. Some of the countries support more
than one language for holiday names output.
for a subdivision its `ISO 3166-2 code`_. Some countries have common or foreign
names or abbreviations as aliases for their subdivisions. These are defined in
the (optional) ``subdivisions_aliases`` attribute.
Some of the countries support more than one language for holiday names output.
A default language is defined by ``default_language`` (optional) attribute
for each entity and is used as a fallback when neither user specified
language nor user locale language available. The default language code is
Expand All @@ -158,8 +160,9 @@ bank holidays, school holidays, additional (paid or non-paid) holidays, holidays
public employees, religious holidays (valid only for these religions followers). A list of all
categories supported by country is defined by ``supported_categories`` (optional) attribute.

The following is a list of supported countries, their subdivisions, available languages and
additional categories. All countries support **PUBLIC** holidays category by default.
The following is a list of supported countries, their subdivisions followed by their
aliases (if any) in brackets, available languages and additional holiday categories.
All countries support **PUBLIC** holidays category by default.
All other default values are highlighted with bold:


Expand Down Expand Up @@ -220,7 +223,7 @@ All other default values are highlighted with bold:
-
* - Austria
- AT
- States: 1, 2, 3, 4, 5, 6, 7, 8, **9**
- States: 1 (Burgenland, Bgld), 2 (Kärnten, Ktn), 3 (Niederösterreich, NÖ), 4 (Oberösterreich, OÖ), 5 (Salzburg, Sbg), 6 (Steiermark, Stmk), 7 (Tirol, T), 8 (Vorarlberg, Vbg), 9 (Wien, W)
- **de**, en_US, uk
- BANK
* - Azerbaijan
Expand Down Expand Up @@ -441,7 +444,7 @@ All other default values are highlighted with bold:
* - Ghana
- GH
-
-
-
-
* - Greece
- GR
Expand Down
84 changes: 75 additions & 9 deletions holidays/countries/austria.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,41 @@ class Austria(HolidayBase, ChristianHolidays, InternationalHolidays):
default_language = "de"
supported_categories = (BANK, PUBLIC)
supported_languages = ("de", "en_US", "uk")
subdivisions = ("1", "2", "3", "4", "5", "6", "7", "8", "9")
subdivisions = (
"1", # Burgenland.
"2", # Kärnten.
"3", # Niederösterreich.
"4", # Oberösterreich.
"5", # Salzburg.
"6", # Steiermark.
"7", # Tirol.
"8", # Vorarlberg.
"9", # Wien.
)
subdivisions_aliases = {
"Burgenland": "1",
"Bgld": "1",
"Kärnten": "2",
"Ktn": "2",
"Niederösterreich": "3",
"NÖ": "3",
"Oberösterreich": "4",
"OÖ": "4",
"Salzburg": "5",
"Sbg": "5",
"Steiermark": "6",
"Stmk": "6",
"Tirol": "7",
"T": "7",
"Vorarlberg": "8",
"Vbg": "8",
"Wien": "9",
"W": "9",
}

def __init__(self, *args, **kwargs) -> None:
ChristianHolidays.__init__(self)
InternationalHolidays.__init__(self)

# Set the default subdivision.
if not kwargs.get("subdiv", kwargs.get("state")):
kwargs["subdiv"] = "9"

super().__init__(*args, **kwargs)

def _populate_public_holidays(self):
Expand Down Expand Up @@ -58,11 +83,12 @@ def _populate_public_holidays(self):
# Assumption Day.
self._add_assumption_of_mary_day(tr("Mariä Himmelfahrt"))

# National Day.
national_day = tr("Nationalfeiertag")
if 1919 <= self._year <= 1934:
# National Day.
self._add_holiday_nov_12(tr("Nationalfeiertag"))
self._add_holiday_nov_12(national_day)
if self._year >= 1967:
self._add_holiday_oct_26(tr("Nationalfeiertag"))
self._add_holiday_oct_26(national_day)

# All Saints' Day.
self._add_all_saints_day(tr("Allerheiligen"))
Expand All @@ -86,6 +112,46 @@ def _populate_bank_holidays(self):
# New Year's Eve.
self._add_new_years_eve(tr("Silvester"))

def _populate_subdiv_1_bank_holidays(self):
# St. Martin's Day.
self._add_holiday_nov_11(tr("Hl. Martin"))

def _populate_subdiv_2_bank_holidays(self):
# St. Joseph's Day.
self._add_saint_josephs_day(tr("Hl. Josef"))

# 1920 Carinthian plebiscite.
self._add_holiday_oct_10(tr("Tag der Volksabstimmung"))

def _populate_subdiv_3_bank_holidays(self):
# St. Leopold's Day.
self._add_holiday_nov_15(tr("Hl. Leopold"))

def _populate_subdiv_4_bank_holidays(self):
# St. Florian's Day.
if self._year >= 2004:
self._add_holiday_may_4(tr("Hl. Florian"))
arkid15r marked this conversation as resolved.
Show resolved Hide resolved

def _populate_subdiv_5_bank_holidays(self):
# St. Rupert's Day.
self._add_holiday_sep_24(tr("Hl. Rupert"))

def _populate_subdiv_6_bank_holidays(self):
# St. Joseph's Day.
self._add_saint_josephs_day(tr("Hl. Josef"))

def _populate_subdiv_7_bank_holidays(self):
# St. Joseph's Day.
self._add_saint_josephs_day(tr("Hl. Josef"))

def _populate_subdiv_8_bank_holidays(self):
# St. Joseph's Day.
self._add_saint_josephs_day(tr("Hl. Josef"))

def _populate_subdiv_9_bank_holidays(self):
# St. Leopold's Day.
self._add_holiday_nov_15(tr("Hl. Leopold"))


class AT(Austria):
pass
Expand Down
48 changes: 34 additions & 14 deletions holidays/holiday_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,9 @@ def _populate(self, year):
"""The market's ISO 3166-1 alpha-2 code."""
subdivisions: Tuple[str, ...] = ()
"""The subdivisions supported for this country (see documentation)."""
subdivisions_aliases: Dict[str, str] = {}
"""Aliases for the ISO 3166-2 subdivision codes with the key as alias and
the value the ISO 3166-2 subdivision code."""
years: Set[int]
"""The years calculated."""
expand: bool
Expand All @@ -217,7 +220,7 @@ def _populate(self, year):
observed: bool
"""Whether dates when public holiday are observed are included."""
subdiv: Optional[str] = None
"""The subdiv requested."""
"""The subdiv requested as ISO 3166-2 code or one of the aliases."""
special_holidays: Dict[int, Union[SpecialHoliday, SubstitutedHoliday]] = {}
"""A list of the country-wide special (as opposite to regular) holidays for
a specific year."""
Expand Down Expand Up @@ -262,8 +265,8 @@ def __init__(
following Monday). This doesn't work for all countries.

:param subdiv:
The subdivision (e.g. state or province); not implemented for all
countries (see documentation).
The subdivision (e.g. state or province) as a ISO 3166-2 code
or its alias; not implemented for all countries (see documentation).

:param prov:
*deprecated* use subdiv instead.
Expand Down Expand Up @@ -304,10 +307,10 @@ def __init__(
if isinstance(subdiv, int):
subdiv = str(subdiv)

subdivisions_aliases = tuple(sorted(self.subdivisions_aliases))
# Unsupported subdivisions.
if (
not isinstance(self, HolidaySum)
and subdiv not in self.subdivisions + self._deprecated_subdivisions
if not isinstance(self, HolidaySum) and subdiv not in (
self.subdivisions + subdivisions_aliases + self._deprecated_subdivisions
):
raise NotImplementedError(
f"Entity `{self._entity_code}` does not have subdivision {subdiv}"
Expand All @@ -326,7 +329,9 @@ def __init__(
warnings.warn(
"This subdivision is deprecated and will be removed after "
"Dec, 1 2023. The list of supported subdivisions: "
f"{', '.join(sorted(self.subdivisions))}.",
f"{', '.join(sorted(self.subdivisions))}; "
"the list of supported subdivisions aliases: "
f"{', '.join(subdivisions_aliases)}.",
DeprecationWarning,
)

Expand Down Expand Up @@ -658,19 +663,34 @@ def _entity_code(self):

@cached_property
def _normalized_subdiv(self):
return self.subdiv.translate(
str.maketrans(
{
"-": "_",
" ": "_",
}
return (
self.subdivisions_aliases.get(self.subdiv, self.subdiv)
.translate(
str.maketrans(
{
"-": "_",
" ": "_",
}
)
)
).lower()
.lower()
)

@cached_property
def _sorted_categories(self):
return sorted(self.categories)

@classmethod
def get_subdivision_aliases(cls) -> Dict[str, List]:
"""Get subdivision aliases."""
subdivision_aliases: Dict[str, List] = {}
for alias, subdivision in cls.subdivisions_aliases.items():
if subdivision not in subdivision_aliases:
subdivision_aliases[subdivision] = []
subdivision_aliases[subdivision].append(alias)

return subdivision_aliases

def _is_leap_year(self) -> bool:
"""
Returns True if the year is leap. Returns False otherwise.
Expand Down
25 changes: 24 additions & 1 deletion holidays/locale/de/LC_MESSAGES/AT.po
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Authors: ~Jhellico <[email protected]>, (c) 2023.
msgid ""
msgstr ""
"Project-Id-Version: Python Holidays 0.28\n"
"Project-Id-Version: Python Holidays 0.42\n"
"POT-Creation-Date: 2023-04-01 17:13+0300\n"
"PO-Revision-Date: 2023-04-01 17:15+0300\n"
"Last-Translator: ~Jhellico <[email protected]>\n"
Expand Down Expand Up @@ -78,3 +78,26 @@ msgstr ""
#. New Year's Eve.
msgid "Silvester"
msgstr ""

#. St. Martin's Day.
msgid "Hl. Martin"
msgstr ""

#. St. Joseph's Day.
msgid "Hl. Josef"
msgstr ""

#. 1920 Carinthian plebiscite.
msgid "Tag der Volksabstimmung"
msgstr ""

#. St. Leopold's Day.
msgid "Hl. Leopold"
msgstr ""

msgid "Hl. Florian"
msgstr ""

#. St. Rupert's Day.
msgid "Hl. Rupert"
msgstr ""
25 changes: 24 additions & 1 deletion holidays/locale/en_US/LC_MESSAGES/AT.po
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
msgid ""
msgstr ""
"Project-Id-Version: Python Holidays 0.28\n"
"Project-Id-Version: Python Holidays 0.42\n"
"POT-Creation-Date: 2023-04-01 17:13+0300\n"
"PO-Revision-Date: 2023-04-01 17:18+0300\n"
"Last-Translator: ~Jhellico <[email protected]>\n"
Expand Down Expand Up @@ -79,3 +79,26 @@ msgstr "Christmas Eve"
#. New Year's Eve.
msgid "Silvester"
msgstr "New Year's Eve"

#. St. Martin's Day.
msgid "Hl. Martin"
msgstr "St. Martin's Day"

#. St. Joseph's Day.
msgid "Hl. Josef"
msgstr "St. Joseph's Day"

#. 1920 Carinthian plebiscite.
msgid "Tag der Volksabstimmung"
msgstr "1920 Carinthian plebiscite"

#. St. Leopold's Day.
msgid "Hl. Leopold"
msgstr "St. Leopold's Day"

msgid "Hl. Florian"
msgstr "St. Florian's Day"

#. St. Rupert's Day.
msgid "Hl. Rupert"
msgstr "St. Rupert's Day"
25 changes: 24 additions & 1 deletion holidays/locale/uk/LC_MESSAGES/AT.po
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
msgid ""
msgstr ""
"Project-Id-Version: Python Holidays 0.28\n"
"Project-Id-Version: Python Holidays 0.42\n"
"POT-Creation-Date: 2023-04-01 17:13+0300\n"
"PO-Revision-Date: 2023-04-01 17:27+0300\n"
"Last-Translator: ~Jhellico <[email protected]>\n"
Expand Down Expand Up @@ -79,3 +79,26 @@ msgstr "Святий вечір"
#. New Year's Eve.
msgid "Silvester"
msgstr "Переддень Нового року"

#. St. Martin's Day.
msgid "Hl. Martin"
msgstr "День Святого Мартина"

#. St. Joseph's Day.
msgid "Hl. Josef"
msgstr "День Святого Йосипа"

#. 1920 Carinthian plebiscite.
msgid "Tag der Volksabstimmung"
msgstr "Річниця референдуму 1920 року в Карінтії"

#. St. Leopold's Day.
msgid "Hl. Leopold"
msgstr "День Святого Леопольда"

msgid "Hl. Florian"
msgstr "День Святого Флоріана"

#. St. Rupert's Day.
msgid "Hl. Rupert"
msgstr "День Святого Руперта"
4 changes: 2 additions & 2 deletions holidays/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ def country_holidays(
An ISO 3166-1 Alpha-2 country code.

:param subdiv:
The subdivision (e.g. state or province); not implemented for all
countries (see documentation).
The subdivision (e.g. state or province) as a ISO 3166-2 code
or its alias; not implemented for all countries (see documentation).

:param years:
The year(s) to pre-calculate public holidays for at instantiation.
Expand Down
Loading