Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
8281084
GH49075 looks weird. Let's add a test and go from there.
roadswitcher Oct 15, 2022
8d1b868
Some cleanup.
roadswitcher Oct 15, 2022
eb5c8a8
First pass at the fix.
roadswitcher Oct 15, 2022
b00c83f
Missed a space, failed formatting check.
roadswitcher Oct 15, 2022
1720600
pre-commit would have caught that, eh.
roadswitcher Oct 15, 2022
d87891f
Missed a spot.
roadswitcher Oct 15, 2022
ad0a017
Update test_federal.py
roadswitcher Oct 15, 2022
d8e9f9d
Merge branch 'pandas-dev:main' into odd_calendar_behavior
roadswitcher Oct 16, 2022
c07f068
Well, that was subtle.
roadswitcher Oct 16, 2022
b423bb7
Changed the test.
roadswitcher Oct 16, 2022
9f89326
Git mistake.
roadswitcher Oct 16, 2022
992143c
Backing away from keyboard now.
roadswitcher Oct 16, 2022
8e516f3
Merge branch 'pandas-dev:main' into odd_calendar_behavior
roadswitcher Oct 29, 2022
7486888
next: write more tests.
roadswitcher Oct 29, 2022
d63ea70
precommit local run.
roadswitcher Oct 29, 2022
e40ce4d
User specified half-open date intervals can return inconsistent results.
roadswitcher Oct 29, 2022
c953651
Added logic to close open time intervals into AbstractHolidayCalender
roadswitcher Oct 30, 2022
68f8db4
OK, I've learned pre-commit doesn't pass wildcards all the way down a…
roadswitcher Oct 30, 2022
344238e
Merge branch 'pandas-dev:main' into odd_calendar_behavior
roadswitcher Oct 30, 2022
3172392
Ensure DatetimeIndex returned in _apply_rule
roadswitcher Oct 30, 2022
824abb6
Merge branch 'odd_calendar_behavior' of github.com:roadswitcher/panda…
roadswitcher Oct 30, 2022
cb6ab53
Ensure DatetimeIndex returned in _apply_rule
roadswitcher Oct 30, 2022
b865481
Caught formatting.
roadswitcher Oct 30, 2022
0c8e325
Missed running isort locally.
roadswitcher Oct 30, 2022
718daa0
Merge branch 'main' into odd_calendar_behavior
roadswitcher Oct 30, 2022
5aca82d
Well, that was subtle.
roadswitcher Nov 1, 2022
c6b2d5b
Changed URL to current OPM source-of-record, updated whatsnew
roadswitcher Nov 1, 2022
da6c1a3
Merge branch 'main' into odd_calendar_behavior
roadswitcher Nov 1, 2022
a8a6244
Update v2.0.0.rst
roadswitcher Nov 1, 2022
ec087a3
Add dtype to empty index ( caught by mypy in CI, not part of pre-comm…
roadswitcher Nov 1, 2022
a6242a9
Updated holiday.py
roadswitcher Nov 1, 2022
8922123
... and forgot to pre-commit run black
roadswitcher Nov 1, 2022
592f705
Merge branch 'main' into odd_calendar_behavior
roadswitcher Nov 1, 2022
cd848c1
Merge branch 'main' into odd_calendar_behavior
roadswitcher Nov 1, 2022
a502a06
Update pandas/tseries/holiday.py
roadswitcher Nov 1, 2022
67c83b8
Update v2.0.0.rst
roadswitcher Nov 1, 2022
1ae7c11
Merge branch 'main' into odd_calendar_behavior
roadswitcher Nov 1, 2022
6188c80
Added test to test_federal.py to ensure comparison against known-good…
roadswitcher Nov 1, 2022
4283115
Add change to test_federal to compare against constructed DatetimeInd…
roadswitcher Nov 2, 2022
6122af8
Merge branch 'main' into odd_calendar_behavior
roadswitcher Nov 2, 2022
ad311f0
Merge branch 'main' into odd_calendar_behavior
roadswitcher Nov 2, 2022
176f3e3
Merge branch 'main' into odd_calendar_behavior
roadswitcher Nov 2, 2022
45521a7
Update doc/source/whatsnew/v2.0.0.rst
mroeschke Nov 2, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Well, that was subtle.
  • Loading branch information
roadswitcher committed Nov 1, 2022
commit 5aca82dcbcf994f814ea7d584900b47d07fa77e2
4 changes: 3 additions & 1 deletion pandas/tests/tseries/holiday/test_federal.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from datetime import datetime

import pandas._testing as tm

from pandas.tseries.holiday import (
AbstractHolidayCalendar,
USFederalHolidayCalendar,
Expand Down Expand Up @@ -48,4 +50,4 @@ def test_federal_holiday_inconsistent_returntype():
results_2018 = cal1.holidays(start=datetime(2018, 8, 1), end=datetime(2018, 8, 31))
results_2019 = cal2.holidays(start=datetime(2019, 8, 1), end=datetime(2019, 8, 31))

assert type(results_2018) == type(results_2019)
tm.assert_index_equal(results_2018, results_2019)
Copy link
Member

Choose a reason for hiding this comment

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

One last item: Could you assert that results_2018 and results_2019 equal manually constructed DatetimeIndex? Just in case a future change affects both in bad way

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  • Replaced the comparisons here with separate comparisons against a constructed DatetimeIndex
  • Cleaned up the longer checks in test_holiday and replaced with comparison against constructed DatetimeIndex

Ran precommit, fixed black/isort/flake8 warnings, re-ran pre-commit, and off we go.

24 changes: 14 additions & 10 deletions pandas/tests/tseries/holiday/test_holiday.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,11 @@ def test_both_offset_observance_raises():


def test_half_open_interval_with_observance():
# See GH 49075.
# Prompted by GH 49075
# Given holidays with a half-open date interval and a defined
# observance pattern, we check to make sure that the return type
# for Holiday.dates() remains consistent before/after the date that
# marks the 'edge' of the half-open date interval
holiday_1 = Holiday(
"Arbitrary Holiday - start 2022-03-14",
start_date=datetime(2022, 3, 14),
Expand All @@ -291,17 +295,17 @@ class TestHolidayCalendar(AbstractHolidayCalendar):
USLaborDay,
]

start_datum = Timestamp("2022-08-01")
end_datum = Timestamp("2022-08-31")
start = Timestamp("2022-08-01")
end = Timestamp("2022-08-31")
test_cal = TestHolidayCalendar()

three_years_before = test_cal.holidays(
start_datum - DateOffset(years=3), end_datum - DateOffset(years=3)
check_before_edge = test_cal.holidays(
start - DateOffset(years=3), end - DateOffset(years=3)
)
year_of = test_cal.holidays(start_datum, end_datum)
three_years_after = test_cal.holidays(
start_datum + DateOffset(years=3), end_datum + DateOffset(years=3)
check_year_of = test_cal.holidays(start, end)
check_after_edge = test_cal.holidays(
start + DateOffset(years=3), end + DateOffset(years=3)
)

assert type(three_years_after) == type(year_of)
assert type(three_years_before) == type(year_of)
tm.assert_index_equal(check_after_edge, check_year_of)
tm.assert_index_equal(check_before_edge, check_year_of)
13 changes: 3 additions & 10 deletions pandas/tseries/holiday.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ def _reference_dates(self, start_date, end_date):

return dates

def _apply_rule(self, dates):
def _apply_rule(self, dates: DatetimeIndex) -> DatetimeIndex:
"""
Apply the given offset/observance to a DatetimeIndex of dates.

Expand All @@ -335,15 +335,8 @@ def _apply_rule(self, dates):
-------
Dates with rules applied
"""
# GH 49075
# If we have a half-open date interval with observance,
# ensure we return a DatetimeIndex
if (
self.observance is not None
and (self.start_date is not None and self.end_date is None)
or (self.end_date is not None and self.start_date is None)
):
return DatetimeIndex([dates.map(lambda d: self.observance(d))])
if dates.empty:
return DatetimeIndex([])

if self.observance is not None:
return dates.map(lambda d: self.observance(d))
Expand Down