From 500610ae442448a84cc15eeb28e99159585e4090 Mon Sep 17 00:00:00 2001 From: sharkipelago Date: Sat, 14 Jun 2025 08:41:04 -0400 Subject: [PATCH 1/3] changed days_of_week to raise ValueError and updated docstring --- doc/source/whatsnew/v3.0.0.rst | 1 + pandas/tests/tseries/holiday/test_holiday.py | 7 +++++++ pandas/tseries/holiday.py | 6 ++++-- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/doc/source/whatsnew/v3.0.0.rst b/doc/source/whatsnew/v3.0.0.rst index 5160d2ea8b8fe..8d7e8b280b666 100644 --- a/doc/source/whatsnew/v3.0.0.rst +++ b/doc/source/whatsnew/v3.0.0.rst @@ -77,6 +77,7 @@ Other enhancements - :meth:`Series.map` now accepts an ``engine`` parameter to allow execution with a third-party execution engine (:issue:`61125`) - :meth:`Series.str.get_dummies` now accepts a ``dtype`` parameter to specify the dtype of the resulting DataFrame (:issue:`47872`) - :meth:`pandas.concat` will raise a ``ValueError`` when ``ignore_index=True`` and ``keys`` is not ``None`` (:issue:`59274`) +- :class:`Holiday` constructor argument ``days_of_week`` will raise a ``ValueError`` when type is something other than ``None`` or ``tuple`` - :py:class:`frozenset` elements in pandas objects are now natively printed (:issue:`60690`) - Add ``"delete_rows"`` option to ``if_exists`` argument in :meth:`DataFrame.to_sql` deleting all records of the table before inserting data (:issue:`37210`). - Added half-year offset classes :class:`HalfYearBegin`, :class:`HalfYearEnd`, :class:`BHalfYearBegin` and :class:`BHalfYearEnd` (:issue:`60928`) diff --git a/pandas/tests/tseries/holiday/test_holiday.py b/pandas/tests/tseries/holiday/test_holiday.py index 37e029f31b1fd..054fc07e4180f 100644 --- a/pandas/tests/tseries/holiday/test_holiday.py +++ b/pandas/tests/tseries/holiday/test_holiday.py @@ -454,3 +454,10 @@ def test_exclude_date_value_error(): Timestamp("2026-06-10"), ] Holiday("National Ice Tea Day", month=6, day=10, exclude_dates=exclude) + + +def test_days_of_week_value_error(): + msg = "days_of_week must be None or tuple." + + with pytest.raises(ValueError, match=msg): + Holiday("World Blood Donor Day", month=6, day=14, days_of_week=[0, 1]) diff --git a/pandas/tseries/holiday.py b/pandas/tseries/holiday.py index 8ad2541d2e58d..e61fd6594ea84 100644 --- a/pandas/tseries/holiday.py +++ b/pandas/tseries/holiday.py @@ -192,8 +192,9 @@ class from pandas.tseries.offsets, default None end_date : datetime-like, default None Last date the holiday is observed days_of_week : tuple of int or dateutil.relativedelta weekday strs, default None - Provide a tuple of days e.g (0,1,2,3,) for Monday Through Thursday + Provide a tuple of days e.g (0,1,2,3,) for Monday through Thursday Monday=0,..,Sunday=6 + Only instances of the holiday included in days_of_week will be computed exclude_dates : DatetimeIndex or default None Specific dates to exclude e.g. skipping a specific year's holiday @@ -258,7 +259,8 @@ class from pandas.tseries.offsets, default None ) self.end_date = Timestamp(end_date) if end_date is not None else end_date self.observance = observance - assert days_of_week is None or type(days_of_week) == tuple + if not (days_of_week is None or isinstance(days_of_week, tuple)): + raise ValueError("days_of_week must be None or tuple.") self.days_of_week = days_of_week if not (exclude_dates is None or isinstance(exclude_dates, DatetimeIndex)): raise ValueError("exclude_dates must be None or of type DatetimeIndex.") From 05dade3da6a2dbb5b7cddd3e829ade30b53a483f Mon Sep 17 00:00:00 2001 From: sharkipelago Date: Sat, 14 Jun 2025 08:42:15 -0400 Subject: [PATCH 2/3] moved whatsnew entry to be next to relevant holiday entry --- doc/source/whatsnew/v3.0.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v3.0.0.rst b/doc/source/whatsnew/v3.0.0.rst index 8d7e8b280b666..fed22fc8217db 100644 --- a/doc/source/whatsnew/v3.0.0.rst +++ b/doc/source/whatsnew/v3.0.0.rst @@ -65,6 +65,7 @@ Other enhancements - :class:`ArrowDtype` now supports ``pyarrow.JsonType`` (:issue:`60958`) - :class:`DataFrameGroupBy` and :class:`SeriesGroupBy` methods ``sum``, ``mean``, ``median``, ``prod``, ``min``, ``max``, ``std``, ``var`` and ``sem`` now accept ``skipna`` parameter (:issue:`15675`) - :class:`Holiday` has gained the constructor argument and field ``exclude_dates`` to exclude specific datetimes from a custom holiday calendar (:issue:`54382`) +- :class:`Holiday` constructor argument ``days_of_week`` will raise a ``ValueError`` when type is something other than ``None`` or ``tuple`` - :class:`Rolling` and :class:`Expanding` now support ``nunique`` (:issue:`26958`) - :class:`Rolling` and :class:`Expanding` now support aggregations ``first`` and ``last`` (:issue:`33155`) - :func:`read_parquet` accepts ``to_pandas_kwargs`` which are forwarded to :meth:`pyarrow.Table.to_pandas` which enables passing additional keywords to customize the conversion to pandas, such as ``maps_as_pydicts`` to read the Parquet map data type as python dictionaries (:issue:`56842`) @@ -77,7 +78,6 @@ Other enhancements - :meth:`Series.map` now accepts an ``engine`` parameter to allow execution with a third-party execution engine (:issue:`61125`) - :meth:`Series.str.get_dummies` now accepts a ``dtype`` parameter to specify the dtype of the resulting DataFrame (:issue:`47872`) - :meth:`pandas.concat` will raise a ``ValueError`` when ``ignore_index=True`` and ``keys`` is not ``None`` (:issue:`59274`) -- :class:`Holiday` constructor argument ``days_of_week`` will raise a ``ValueError`` when type is something other than ``None`` or ``tuple`` - :py:class:`frozenset` elements in pandas objects are now natively printed (:issue:`60690`) - Add ``"delete_rows"`` option to ``if_exists`` argument in :meth:`DataFrame.to_sql` deleting all records of the table before inserting data (:issue:`37210`). - Added half-year offset classes :class:`HalfYearBegin`, :class:`HalfYearEnd`, :class:`BHalfYearBegin` and :class:`BHalfYearEnd` (:issue:`60928`) From 960c1194f9927388a333dc1bf4bb405c6e292d4f Mon Sep 17 00:00:00 2001 From: sharkipelago Date: Mon, 16 Jun 2025 18:32:59 -0400 Subject: [PATCH 3/3] updated rst to link relevant issue --- doc/source/whatsnew/v3.0.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v3.0.0.rst b/doc/source/whatsnew/v3.0.0.rst index 6775dada68ea9..0f487711bc794 100644 --- a/doc/source/whatsnew/v3.0.0.rst +++ b/doc/source/whatsnew/v3.0.0.rst @@ -65,8 +65,8 @@ Other enhancements - :class:`ArrowDtype` now supports ``pyarrow.JsonType`` (:issue:`60958`) - :class:`DataFrameGroupBy` and :class:`SeriesGroupBy` methods ``sum``, ``mean``, ``median``, ``prod``, ``min``, ``max``, ``std``, ``var`` and ``sem`` now accept ``skipna`` parameter (:issue:`15675`) - :class:`Easter` has gained a new constructor argument ``method`` which specifies the method used to calculate Easter — for example, Orthodox Easter (:issue:`61665`) +- :class:`Holiday` constructor argument ``days_of_week`` will raise a ``ValueError`` when type is something other than ``None`` or ``tuple`` (:issue:`61658`) - :class:`Holiday` has gained the constructor argument and field ``exclude_dates`` to exclude specific datetimes from a custom holiday calendar (:issue:`54382`) -- :class:`Holiday` constructor argument ``days_of_week`` will raise a ``ValueError`` when type is something other than ``None`` or ``tuple`` - :class:`Rolling` and :class:`Expanding` now support ``nunique`` (:issue:`26958`) - :class:`Rolling` and :class:`Expanding` now support aggregations ``first`` and ``last`` (:issue:`33155`) - :func:`read_parquet` accepts ``to_pandas_kwargs`` which are forwarded to :meth:`pyarrow.Table.to_pandas` which enables passing additional keywords to customize the conversion to pandas, such as ``maps_as_pydicts`` to read the Parquet map data type as python dictionaries (:issue:`56842`)