Skip to content

Commit c4397e5

Browse files
authored
Support time start/end for BusinessHour & CustomBusinessHour (#428)
1 parent 2a2291b commit c4397e5

File tree

2 files changed

+46
-4
lines changed

2 files changed

+46
-4
lines changed

pandas-stubs/_libs/tslibs/offsets.pyi

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from datetime import (
22
date,
33
datetime,
4+
time,
45
timedelta,
56
)
67
from typing import (
@@ -131,8 +132,8 @@ class BusinessHour(BusinessMixin):
131132
self,
132133
n: int = ...,
133134
normalize: bool = ...,
134-
start: str | Collection[str] = ...,
135-
end: str | Collection[str] = ...,
135+
start: str | time | Collection[str | time] = ...,
136+
end: str | time | Collection[str | time] = ...,
136137
offset: timedelta = ...,
137138
): ...
138139

@@ -217,8 +218,8 @@ class CustomBusinessHour(BusinessHour):
217218
self,
218219
n: int = ...,
219220
normalize: bool = ...,
220-
start: str = ...,
221-
end: str = ...,
221+
start: str | time | Collection[str | time] = ...,
222+
end: str | time | Collection[str | time] = ...,
222223
offset: timedelta = ...,
223224
holidays: list | None = ...,
224225
): ...

tests/test_timefuncs.py

+41
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@
3131
from pandas.tseries.holiday import USFederalHolidayCalendar
3232
from pandas.tseries.offsets import (
3333
BusinessDay,
34+
BusinessHour,
3435
CustomBusinessDay,
36+
CustomBusinessHour,
3537
Day,
3638
)
3739

@@ -595,6 +597,45 @@ def test_some_offsets() -> None:
595597
check(assert_type(tswm1, pd.Timestamp), pd.Timestamp)
596598
tswm2 = pd.Timestamp("9/23/2022") + pd.offsets.LastWeekOfMonth(2, 3)
597599
check(assert_type(tswm2, pd.Timestamp), pd.Timestamp)
600+
# GH 396
601+
check(
602+
assert_type(
603+
BusinessHour(start=dt.time(9, 30), end=dt.time(16, 0)), BusinessHour
604+
),
605+
BusinessHour,
606+
)
607+
check(
608+
assert_type(BusinessHour(start="9:30", end="16:00"), BusinessHour), BusinessHour
609+
)
610+
check(
611+
assert_type(
612+
BusinessHour(
613+
start=["9:30", dt.time(11, 30)], end=[dt.time(10, 30), "13:00"]
614+
),
615+
BusinessHour,
616+
),
617+
BusinessHour,
618+
)
619+
check(
620+
assert_type(
621+
CustomBusinessHour(start=dt.time(9, 30), end=dt.time(16, 0)),
622+
CustomBusinessHour,
623+
),
624+
CustomBusinessHour,
625+
)
626+
check(
627+
assert_type(CustomBusinessHour(start="9:30", end="16:00"), CustomBusinessHour),
628+
CustomBusinessHour,
629+
)
630+
check(
631+
assert_type(
632+
CustomBusinessHour(
633+
start=["9:30", dt.time(11, 30)], end=[dt.time(10, 30), "13:00"]
634+
),
635+
CustomBusinessHour,
636+
),
637+
CustomBusinessHour,
638+
)
598639

599640

600641
def test_types_to_numpy() -> None:

0 commit comments

Comments
 (0)