Skip to content
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v2.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ Timezones
^^^^^^^^^
- Bug in :meth:`Series.astype` and :meth:`DataFrame.astype` with object-dtype containing multiple timezone-aware ``datetime`` objects with heterogeneous timezones to a :class:`DatetimeTZDtype` incorrectly raising (:issue:`32581`)
- Bug in :func:`to_datetime` was failing to parse date strings with timezone name when ``format`` was specified with ``%Z`` (:issue:`49748`)
-
- Bug in :meth:`dates` was trying to access an DatetimeIndex attribute on an Index object when holiday landed outside of date range provided (:issue:`49925`)
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 write out the full class.method name, otherwise not clear what "dates" refers to


Numeric
^^^^^^^
Expand Down
15 changes: 15 additions & 0 deletions pandas/tests/tseries/holiday/test_holiday.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,21 @@ def test_holidays_within_dates(holiday, start, expected):
) == [utc.localize(dt) for dt in expected]


def test_holidays_outside_dates():
hol = Holiday(
"Dec 25",
month=12,
day=25,
observance=next_monday,
days_of_week=(5, 6),
end_date=Timestamp("2013-01-01"),
)
expected = hol.dates(Timestamp("2010-01-01"), Timestamp("2023-01-01"))
assert isinstance(
hol.dates(Timestamp("2020-01-01"), Timestamp("2023-01-01")), type(expected)
)


@pytest.mark.parametrize(
"transform", [lambda x: x.strftime("%Y-%m-%d"), lambda x: Timestamp(x)]
)
Expand Down
9 changes: 6 additions & 3 deletions pandas/tseries/holiday.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,12 @@ def dates(self, start_date, end_date, return_name: bool = False):
dates = self._reference_dates(start_date, end_date)
holiday_dates = self._apply_rule(dates)
if self.days_of_week is not None:
holiday_dates = holiday_dates[
np.in1d(holiday_dates.dayofweek, self.days_of_week)
]
if len(holiday_dates) != 0:
holiday_dates = holiday_dates[
np.in1d(holiday_dates.dayofweek, self.days_of_week)
]
else:
holiday_dates = date_range(start=start_date, end=end_date)

if self.start_date is not None:
filter_start_date = max(
Expand Down