Skip to content

Commit

Permalink
Merge pull request #1450 from vacanza/beta
Browse files Browse the repository at this point in the history
v.0.32
  • Loading branch information
arkid15r authored Sep 4, 2023
2 parents f8c9095 + 0bdd9c7 commit 7519898
Show file tree
Hide file tree
Showing 13 changed files with 920 additions and 735 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/pre-commit-autoupdate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Pre-commit hooks autoupdate

on:
schedule:
- cron: "0 0 * * *"
workflow_dispatch:

jobs:
auto-update:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/[email protected]
- uses: browniebroke/[email protected]
- uses: peter-evans/[email protected]
with:
base: beta
branch: update/pre-commit-hooks
title: Update pre-commit hooks
author: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
commit-message: "Chore: Update pre-commit hooks"
committer: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
body: Update versions of pre-commit hooks to latest version.
token: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ repos:
exclude: ^(docs)

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.5.0
rev: v1.5.1
hooks:
- id: mypy
additional_dependencies: [types-all]
Expand Down
13 changes: 13 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
Version 0.32
============

Released September 4, 2023

- Add subdivision category holidays support (#1446 by @KJhellico)
- Fix months imports (#1442 by @KJhellico)
- Improve code owners transparency (#1440 by @arkid15r)
- Update HolidayBase tests (#1447 by @arkid15r)
- Update documentation: correct inheritance example (#1438 by @arkid15r)
- Add CODEOWNERS (#1436 by @arkid15r)
- Add pre-commit hooks autoupdate workflow (#1441 by @KJhellico)

Version 0.31
============

Expand Down
6 changes: 6 additions & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# People marked here will be automatically requested for a review.
#
# For more information on CODEOWNERS, see:
# https://help.github.com/en/articles/about-code-owners

* @arkid15r @KJhellico
26 changes: 14 additions & 12 deletions docs/source/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -182,27 +182,29 @@ Creating custom holidays (or augmenting existing ones with private ones)

Sometimes we may not be able to use the official federal statutory
holiday list in our code. Let's pretend we work for a company that
does not include Columbus Day as a statutory holiday but does include
does not include New Year's Day as a statutory holiday but does include
"Ninja Turtle Day" on July 13th. We can create a new class that inherits
the US and the only method we need to override is :py:meth:`_populate`:
the US (please note the base class import path) and the only method we need
to override is :py:meth:`_populate`:

.. code-block:: python
>>> class CorporateHolidays(holidays.US):
>>> from holidays.countries import US
>>> class CorporateHolidays(US):
>>> def _populate(self, year):
>>> # Populate the holiday list with the default US holidays
>>> holidays.US._populate(self, year)
>>> # Remove Columbus Day
>>> self.pop_named("Columbus Day")
>>> # Add Ninja Turtle Day
>>> self[date(year, 7, 13)] = "Ninja Turtle Day"
>>> date(2014, 10, 14) in holidays.country_holidays(country="US")
>>> # Populate the holiday list with the default US holidays.
>>> super()._populate(year)
>>> # Remove New Year's Day.
>>> self.pop_named("New Year's Day")
>>> # Add Ninja Turtle Day.
>>> self._add_holiday_jul_13("Ninja Turtle Day")
>>> date(2014, 1, 1) in holidays.country_holidays(country="US")
True
>>> date(2014, 10, 14) in CorporateHolidays()
>>> date(2014, 1, 1) in CorporateHolidays()
False
>>> date(2014, 7, 13) in holidays.country_holidays(country="US")
False
>>> date(2014 ,7, 13) in CorporateHolidays()
>>> date(2014, 7, 13) in CorporateHolidays()
True
We can also inherit from the HolidayBase class which has an empty
Expand Down
2 changes: 1 addition & 1 deletion holidays/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from holidays.registry import EntityLoader
from holidays.utils import *

__version__ = "0.31"
__version__ = "0.32"


EntityLoader.load("countries", globals())
Expand Down
17 changes: 15 additions & 2 deletions holidays/countries/bosnia_and_herzegovina.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,22 @@
from gettext import gettext as tr

from holidays.calendars import _CustomIslamicCalendar
from holidays.calendars.gregorian import GREGORIAN_CALENDAR
from holidays.calendars.gregorian import (
GREGORIAN_CALENDAR,
JAN,
FEB,
MAR,
APR,
MAY,
JUN,
JUL,
AUG,
SEP,
OCT,
NOV,
DEC,
)
from holidays.calendars.julian import JULIAN_CALENDAR
from holidays.constants import JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC
from holidays.groups import ChristianHolidays, IslamicHolidays, InternationalHolidays
from holidays.holiday_base import HolidayBase

Expand Down
2 changes: 1 addition & 1 deletion holidays/countries/latvia.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from datetime import timedelta as td
from gettext import gettext as tr

from holidays.constants import MAY, JUL, SEP
from holidays.calendars.gregorian import MAY, JUL, SEP
from holidays.groups import ChristianHolidays, InternationalHolidays
from holidays.holiday_base import HolidayBase

Expand Down
17 changes: 13 additions & 4 deletions holidays/holiday_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,13 +577,14 @@ def __repr__(self) -> str:
parts = []
if hasattr(self, "market"):
parts.append(f"holidays.financial_holidays({self.market!r}")
parts.append(")")
elif hasattr(self, "country"):
if parts:
parts.append(" + ")
parts.append(f"holidays.country_holidays({self.country!r}")
if self.subdiv:
parts.append(f", subdiv={self.subdiv!r}")
parts.append(")")
parts.append(")")

return "".join(parts)

Expand Down Expand Up @@ -648,14 +649,19 @@ def _add_holiday(self, name: str, *args) -> Optional[date]:
self[dt] = self.tr(name)
return dt

def _add_subdiv_holidays(self):
"""Populate subdivision holidays."""
def _add_subdiv_category_holidays(self, category: str = None):
"""Populate subdivision holidays by category."""
if self.subdiv is not None:
subdiv = self.subdiv.replace("-", "_").replace(" ", "_").lower()
add_subdiv_holidays = getattr(self, f"_add_subdiv_{subdiv}_holidays", None)
method_name = f"_add_subdiv_{subdiv}{f'_{category}' if category else ''}_holidays"
add_subdiv_holidays = getattr(self, method_name, None)
if add_subdiv_holidays and callable(add_subdiv_holidays):
add_subdiv_holidays()

def _add_subdiv_holidays(self):
"""Populate subdivision holidays."""
self._add_subdiv_category_holidays()

def _add_substituted_holidays(self):
"""Populate substituted holidays."""
if len(self.substituted_holidays) == 0:
Expand Down Expand Up @@ -758,6 +764,9 @@ def _populate_categories(self):
if populate_category_holidays and callable(populate_category_holidays):
populate_category_holidays()

# Populate subdivision holidays for all categories.
self._add_subdiv_category_holidays(category)

def append(self, *args: Union[Dict[DateLike, str], List[DateLike], DateLike]) -> None:
"""Alias for :meth:`update` to mimic list type."""
return self.update(*args)
Expand Down
2 changes: 1 addition & 1 deletion scripts/generate_release_notes.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
Released {month} {day}, {year}
"""
IGNORED_CONTRIBUTORS = {"dependabot[bot]"}
IGNORED_CONTRIBUTORS = {"dependabot[bot]", "github-actions[bot]"}
REPOSITORY_NAME = "vacanza/python-holidays"


Expand Down
Loading

0 comments on commit 7519898

Please sign in to comment.