Skip to content

DOC/ENH: Holiday exclusion argument #61600

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

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

sharkipelago
Copy link

@sharkipelago sharkipelago commented Jun 7, 2025

@sharkipelago sharkipelago changed the title Holiday exclusion argument DOC/ENH: Holiday exclusion argument Jun 8, 2025
@@ -27,6 +27,7 @@ Other enhancements
- :meth:`Series.str.decode` result now has :class:`StringDtype` when ``future.infer_string`` is True (:issue:`60709`)
- :meth:`~Series.to_hdf` and :meth:`~DataFrame.to_hdf` now round-trip with :class:`StringDtype` (:issue:`60663`)
- Improved ``repr`` of :class:`.NumpyExtensionArray` to account for NEP51 (:issue:`61085`)
- The :class:`Holiday` has gained the constructor argument and field ``exclude_dates`` to exclude specific datetimes from a custom holiday calendar (:issue:`54382`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you move this to v3.0.0.rst?

@@ -169,6 +172,7 @@ def __init__(
start_date=None,
end_date=None,
days_of_week: tuple | None = None,
exclude_dates: list[Any] | None = None,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
exclude_dates: list[Any] | None = None,
exclude_dates: list[Timestamp] | None = None,

Let's make the users do the Timestamp conversion before passing into this object

Comment on lines 267 to 271
self.exclude_dates = (
[Timestamp(ex) for ex in exclude_dates]
if exclude_dates is not None
else exclude_dates
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the constructor argument being stricter, we can just validate the arguments are all Timestamp

Comment on lines 345 to 347
holiday_dates = DatetimeIndex(
[hd for hd in holiday_dates if hd not in self.exclude_dates]
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Conversion to DatetimeIndex should be done in __init__
  2. Probably better to use .difference or releated method instead

@mroeschke mroeschke added the Frequency DateOffsets label Jun 9, 2025
Comment on lines 7 to 9
from typing import (
TYPE_CHECKING,
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
from typing import (
TYPE_CHECKING,
)
from typing import TYPE_CHECKING

@@ -169,6 +171,7 @@ def __init__(
start_date=None,
end_date=None,
days_of_week: tuple | None = None,
exclude_dates: list[Timestamp] | None = None,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, can we type this as exclude_dates: DatetimeIndex | None = None,?

Comment on lines 266 to 268
assert exclude_dates is None or all(
type(ex) == Timestamp for ex in exclude_dates
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you raise a ValueError if exclude_dates is not a DatetimeIndex or None?

@@ -257,6 +260,9 @@ class from pandas.tseries.offsets, default None
self.observance = observance
assert days_of_week is None or type(days_of_week) == tuple
Copy link
Author

@sharkipelago sharkipelago Jun 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I also switch this to throw a ValueError on failing? Or would that be a separate PR?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A separate PR would be better, thanks.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this, should I open a new issue? Or just make another PR?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just another PR is fine

@@ -257,6 +260,9 @@ class from pandas.tseries.offsets, default None
self.observance = observance
assert days_of_week is None or type(days_of_week) == tuple
self.days_of_week = days_of_week
if exclude_dates is not None and type(exclude_dates) != DatetimeIndex:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if exclude_dates is not None and type(exclude_dates) != DatetimeIndex:
if not (exclude_dates is None or isinstance(exclude_dates, DatetimeIndex):

@@ -257,6 +260,9 @@ class from pandas.tseries.offsets, default None
self.observance = observance
assert days_of_week is None or type(days_of_week) == tuple
self.days_of_week = days_of_week
if exclude_dates is not None and type(exclude_dates) != DatetimeIndex:
raise ValueError("exclude_dates must be None or of type DatetimeIndex.")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a test that checks this exception?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Frequency DateOffsets
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DOC/ENH: Holiday documentation is missing or hard to find for re-arranged national holidays.
2 participants