Skip to content

Commit

Permalink
Restore Malaysia's 3-letter code as subdivisions aliases (#1946)
Browse files Browse the repository at this point in the history
  • Loading branch information
PPsyrius committed Aug 23, 2024
1 parent ad0928a commit b9c9d5f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 71 deletions.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ All other default values are highlighted with bold:
-
* - Malaysia
- MY
- States and federal territories: 01 (Johor), 02 (Kedah), 03 (Kelantan), 04 (Melaka), 05 (Negeri Sembilan), 06 (Pahang), 07 (Pulau Pinang), 08 (Perak), 09 (Perlis), 10 (Selangor), 11 (Terengganu), 12 (Sabah), 13 (Sarawak), 14 (WP Kuala Lumpur), 15 (WP Labuan), 16 (WP Putrajaya)
- States and federal territories: 01 (Johor, JHR), 02 (Kedah, KDH), 03 (Kelantan, KTN), 04 (Melaka, MLK), 05 (Negeri Sembilan, NSN), 06 (Pahang, PHG), 07 (Pulau Pinang, PNG), 08 (Perak, PRK), 09 (Perlis, PLS), 10 (Selangor, SGR), 11 (Terengganu, TRG), 12 (Sabah, SBH), 13 (Sarawak, SWK), 14 (WP Kuala Lumpur, KUL), 15 (WP Labuan, LBN), 16 (WP Putrajaya, PJY)
- en_US, **ms_MY**
-
* - Maldives
Expand Down
54 changes: 16 additions & 38 deletions holidays/countries/malaysia.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,41 +87,39 @@ class Malaysia(
"15",
"16",
)
_deprecated_subdivisions = (
"JHR",
"KDH",
"KTN",
"KUL",
"LBN",
"MLK",
"NSN",
"PHG",
"PJY",
"PLS",
"PNG",
"PRK",
"SBH",
"SGR",
"SWK",
"TRG",
)
subdivisions_aliases = {
"Johor": "01",
"JHR": "01",
"Kedah": "02",
"KDH": "02",
"Kelantan": "03",
"KTN": "03",
"Melaka": "04",
"MLK": "04",
"Negeri Sembilan": "05",
"NSN": "05",
"Pahang": "06",
"PHG": "06",
"Pulau Pinang": "07",
"PNG": "07",
"Perak": "08",
"PRK": "08",
"Perlis": "09",
"PLS": "09",
"Selangor": "10",
"SGR": "10",
"Terengganu": "11",
"TRG": "11",
"Sabah": "12",
"SBH": "12",
"Sarawak": "13",
"SWK": "13",
"WP Kuala Lumpur": "14",
"KUL": "14",
"WP Labuan": "15",
"LBN": "15",
"WP Putrajaya": "16",
"PJY": "16",
}
supported_languages = ("en_US", "ms_MY")

Expand Down Expand Up @@ -216,26 +214,6 @@ def _populate_subdiv_holidays(self):
if self._year <= 1951:
return None

deprecated_mapping = {
"JHR": "01",
"KDH": "02",
"KTN": "03",
"KUL": "14",
"LBN": "15",
"MLK": "04",
"NSN": "05",
"PHG": "06",
"PJY": "16",
"PLS": "09",
"PNG": "07",
"PRK": "08",
"SBH": "12",
"SGR": "10",
"SWK": "13",
"TRG": "11",
}
self.subdiv = deprecated_mapping.get(self.subdiv, self.subdiv)

if self.subdiv and self.subdiv not in {"13", "15"}:
# Deepavali.
self.dts_observed.add(self._add_diwali(tr("Hari Deepavali")))
Expand Down
32 changes: 0 additions & 32 deletions tests/countries/test_malaysia.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
# Website: https://github.com/vacanza/python-holidays
# License: MIT (see LICENSE file)

import warnings
from unittest import TestCase

from holidays.countries.malaysia import Malaysia, MY, MYS
Expand All @@ -26,40 +25,9 @@ def setUpClass(cls):
for subdiv in Malaysia.subdivisions
}

def setUp(self):
super().setUp()
warnings.simplefilter("ignore", category=DeprecationWarning)

def test_country_aliases(self):
self.assertAliases(Malaysia, MY, MYS)

def test_subdiv_deprecation(self):
self.assertDeprecatedSubdivisions("This subdivision is deprecated and will be removed")

def test_deprecated(self):
for subdiv1, subdiv2 in (
("JHR", "01"),
("KDH", "02"),
("KTN", "03"),
("KUL", "14"),
("LBN", "15"),
("MLK", "04"),
("NSN", "05"),
("PHG", "06"),
("PJY", "16"),
("PLS", "09"),
("PNG", "07"),
("PRK", "08"),
("SBH", "12"),
("SGR", "10"),
("SWK", "13"),
("TRG", "11"),
):
self.assertEqual(
sorted(Malaysia(subdiv=subdiv1, years=2023).keys()),
sorted(Malaysia(subdiv=subdiv2, years=2023).keys()),
)

def test_no_holidays(self):
self.assertNoHolidays(Malaysia(years=1951))

Expand Down

0 comments on commit b9c9d5f

Please sign in to comment.