Skip to content

Commit 500610a

Browse files
committed
changed days_of_week to raise ValueError and updated docstring
1 parent c067bcd commit 500610a

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
@@ -77,6 +77,7 @@ Other enhancements
7777
- :meth:`Series.map` now accepts an ``engine`` parameter to allow execution with a third-party execution engine (:issue:`61125`)
7878
- :meth:`Series.str.get_dummies` now accepts a ``dtype`` parameter to specify the dtype of the resulting DataFrame (:issue:`47872`)
7979
- :meth:`pandas.concat` will raise a ``ValueError`` when ``ignore_index=True`` and ``keys`` is not ``None`` (:issue:`59274`)
80+
- :class:`Holiday` constructor argument ``days_of_week`` will raise a ``ValueError`` when type is something other than ``None`` or ``tuple``
8081
- :py:class:`frozenset` elements in pandas objects are now natively printed (:issue:`60690`)
8182
- Add ``"delete_rows"`` option to ``if_exists`` argument in :meth:`DataFrame.to_sql` deleting all records of the table before inserting data (:issue:`37210`).
8283
- Added half-year offset classes :class:`HalfYearBegin`, :class:`HalfYearEnd`, :class:`BHalfYearBegin` and :class:`BHalfYearEnd` (:issue:`60928`)

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)