Skip to content

Commit 0707478

Browse files
committed
fixed type errors in tests
1 parent e911f60 commit 0707478

File tree

5 files changed

+21
-16
lines changed

5 files changed

+21
-16
lines changed

doc/source/user_guide/timeseries.rst

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,9 +1065,9 @@ Holiday calendars can be used to provide the list of holidays. See the
10651065

10661066
.. ipython:: python
10671067
1068-
from pandas.tseries.holiday import USFederalHolidayCalendar
1068+
calendar = np.busdaycalendar(holidays=['2014-01-01', '2014-01-20'])
10691069
1070-
bday_us = pd.offsets.CustomBusinessDay(calendar=USFederalHolidayCalendar())
1070+
bday_us = pd.offsets.CustomBusinessDay(calendar=calendar)
10711071
10721072
# Friday before MLK Day
10731073
dt = datetime.datetime(2014, 1, 17)
@@ -1080,7 +1080,8 @@ in the usual way.
10801080

10811081
.. ipython:: python
10821082
1083-
bmth_us = pd.offsets.CustomBusinessMonthBegin(calendar=USFederalHolidayCalendar())
1083+
bdd = np.busdaycalendar(holidays=['2011-07-01', '2011-07-04', '2011-07-17'])
1084+
bmth_us = pd.offsets.CustomBusinessMonthBegin(calendar=bdd)
10841085
10851086
# Skip new years
10861087
dt = datetime.datetime(2013, 12, 17)
@@ -1210,9 +1211,9 @@ as ``BusinessHour`` except that it skips specified custom holidays.
12101211

12111212
.. ipython:: python
12121213
1213-
from pandas.tseries.holiday import USFederalHolidayCalendar
1214+
calendar = np.busdaycalendar(holidays=['2014-01-01', '2014-01-20'])
12141215
1215-
bhour_us = pd.offsets.CustomBusinessHour(calendar=USFederalHolidayCalendar())
1216+
bhour_us = pd.offsets.CustomBusinessHour(calendar=calendar)
12161217
# Friday before MLK Day
12171218
dt = datetime.datetime(2014, 1, 17, 15)
12181219

pandas/_libs/tslibs/offsets.pyx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4827,6 +4827,11 @@ cdef class CustomBusinessHour(BusinessHour):
48274827
offset=timedelta(0),
48284828
):
48294829
BusinessHour.__init__(self, n, normalize, start=start, end=end, offset=offset)
4830+
if calendar is not None and not isinstance(calendar, np.busdaycalendar):
4831+
raise TypeError(
4832+
f"Only np.busdaycalendar is supported for calendar, "
4833+
f"got {type(calendar).__name__} instead"
4834+
)
48304835
self._init_custom(weekmask, holidays, calendar)
48314836

48324837

@@ -4845,6 +4850,11 @@ cdef class _CustomBusinessMonth(BusinessMixin):
48454850
offset=timedelta(0),
48464851
):
48474852
BusinessMixin.__init__(self, n, normalize, offset)
4853+
if calendar is not None and not isinstance(calendar, np.busdaycalendar):
4854+
raise TypeError(
4855+
f"Only np.busdaycalendar is supported for calendar, "
4856+
f"got {type(calendar).__name__} instead"
4857+
)
48484858
self._init_custom(weekmask, holidays, calendar)
48494859

48504860
@cache_readonly

pandas/tests/tseries/holiday/test_calendar.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from datetime import datetime
22

3+
import numpy as np
34
import pytest
45

56
from pandas import (
@@ -14,7 +15,6 @@
1415
Holiday,
1516
Timestamp,
1617
USFederalHolidayCalendar,
17-
USLaborDay,
1818
USThanksgivingDay,
1919
get_calendar,
2020
)
@@ -97,10 +97,7 @@ def test_calendar_2031():
9797
# Labor Day 2031 is on September 1. Saturday before is August 30.
9898
# Next working day after August 30 ought to be Tuesday, September 2.
9999

100-
class testCalendar(AbstractHolidayCalendar):
101-
rules = [USLaborDay]
102-
103-
cal = testCalendar()
100+
cal = np.busdaycalendar(holidays=["2031-09-01"])
104101
workDay = offsets.CustomBusinessDay(calendar=cal)
105102
Sat_before_Labor_Day_2031 = to_datetime("2031-08-30")
106103
next_working_day = Sat_before_Labor_Day_2031 + 0 * workDay

pandas/tests/tseries/offsets/test_custom_business_day.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
)
2323
from pandas.tests.tseries.offsets.common import assert_offset_equal
2424

25-
from pandas.tseries.holiday import USFederalHolidayCalendar
26-
2725

2826
@pytest.fixture
2927
def offset():
@@ -82,7 +80,7 @@ def test_weekmask_and_holidays(self):
8280

8381
@pytest.mark.filterwarnings("ignore:Non:pandas.errors.PerformanceWarning")
8482
def test_calendar(self):
85-
calendar = USFederalHolidayCalendar()
83+
calendar = np.busdaycalendar(holidays=["2014-01-01", "2014-01-20"])
8684
dt = datetime(2014, 1, 17)
8785
assert_offset_equal(CDay(calendar=calendar), dt, datetime(2014, 1, 21))
8886

pandas/tests/tseries/offsets/test_custom_business_hour.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121

2222
from pandas.tests.tseries.offsets.common import assert_offset_equal
2323

24-
from pandas.tseries.holiday import USFederalHolidayCalendar
25-
2624
holidays = ["2014-06-27", datetime(2014, 6, 30), np.datetime64("2014-07-02")]
2725

2826

@@ -299,7 +297,8 @@ def test_apply_nanoseconds(self, nano_case):
299297

300298
def test_us_federal_holiday_with_datetime(self):
301299
# GH 16867
302-
bhour_us = CustomBusinessHour(calendar=USFederalHolidayCalendar())
300+
calendar = np.busdaycalendar(holidays=["2014-01-01", "2014-01-20"])
301+
bhour_us = CustomBusinessHour(calendar=calendar)
303302
t0 = datetime(2014, 1, 17, 15)
304303
result = t0 + bhour_us * 8
305304
expected = Timestamp("2014-01-21 15:00:00")

0 commit comments

Comments
 (0)