Skip to content

Commit 8a1d5a0

Browse files
authored
DOC/ENH: Holiday days_of_week value error (#61658)
* changed days_of_week to raise ValueError and updated docstring * moved whatsnew entry to be next to relevant holiday entry * updated rst to link relevant issue
1 parent 0238efa commit 8a1d5a0

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

doc/source/whatsnew/v3.0.0.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ Other enhancements
6565
- :class:`ArrowDtype` now supports ``pyarrow.JsonType`` (:issue:`60958`)
6666
- :class:`DataFrameGroupBy` and :class:`SeriesGroupBy` methods ``sum``, ``mean``, ``median``, ``prod``, ``min``, ``max``, ``std``, ``var`` and ``sem`` now accept ``skipna`` parameter (:issue:`15675`)
6767
- :class:`Easter` has gained a new constructor argument ``method`` which specifies the method used to calculate Easter — for example, Orthodox Easter (:issue:`61665`)
68+
- :class:`Holiday` constructor argument ``days_of_week`` will raise a ``ValueError`` when type is something other than ``None`` or ``tuple`` (:issue:`61658`)
6869
- :class:`Holiday` has gained the constructor argument and field ``exclude_dates`` to exclude specific datetimes from a custom holiday calendar (:issue:`54382`)
6970
- :class:`Rolling` and :class:`Expanding` now support ``nunique`` (:issue:`26958`)
7071
- :class:`Rolling` and :class:`Expanding` now support aggregations ``first`` and ``last`` (:issue:`33155`)

pandas/tests/tseries/holiday/test_holiday.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,3 +454,10 @@ def test_exclude_date_value_error():
454454
Timestamp("2026-06-10"),
455455
]
456456
Holiday("National Ice Tea Day", month=6, day=10, exclude_dates=exclude)
457+
458+
459+
def test_days_of_week_value_error():
460+
msg = "days_of_week must be None or tuple."
461+
462+
with pytest.raises(ValueError, match=msg):
463+
Holiday("World Blood Donor Day", month=6, day=14, days_of_week=[0, 1])

pandas/tseries/holiday.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,9 @@ class from pandas.tseries.offsets, default None
192192
end_date : datetime-like, default None
193193
Last date the holiday is observed
194194
days_of_week : tuple of int or dateutil.relativedelta weekday strs, default None
195-
Provide a tuple of days e.g (0,1,2,3,) for Monday Through Thursday
195+
Provide a tuple of days e.g (0,1,2,3,) for Monday through Thursday
196196
Monday=0,..,Sunday=6
197+
Only instances of the holiday included in days_of_week will be computed
197198
exclude_dates : DatetimeIndex or default None
198199
Specific dates to exclude e.g. skipping a specific year's holiday
199200
@@ -258,7 +259,8 @@ class from pandas.tseries.offsets, default None
258259
)
259260
self.end_date = Timestamp(end_date) if end_date is not None else end_date
260261
self.observance = observance
261-
assert days_of_week is None or type(days_of_week) == tuple
262+
if not (days_of_week is None or isinstance(days_of_week, tuple)):
263+
raise ValueError("days_of_week must be None or tuple.")
262264
self.days_of_week = days_of_week
263265
if not (exclude_dates is None or isinstance(exclude_dates, DatetimeIndex)):
264266
raise ValueError("exclude_dates must be None or of type DatetimeIndex.")

0 commit comments

Comments
 (0)