Skip to content

Commit ccfa548

Browse files
author
Si Wei How
committed
improve input argument preprocessing
1 parent 7b04e97 commit ccfa548

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

pandas/tseries/offsets.py

+15-8
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from pandas.util._decorators import Appender, Substitution, cache_readonly
1818

1919
from pandas.core.dtypes.generic import ABCPeriod
20+
from pandas.core.dtypes.inference import _iterable_not_string
2021

2122
from pandas.core.tools.datetimes import to_datetime
2223

@@ -579,12 +580,18 @@ class BusinessHourMixin(BusinessMixin):
579580

580581
def __init__(self, start='09:00', end='17:00', offset=timedelta(0)):
581582
# must be validated here to equality check
582-
if not isinstance(start, (tuple, list)):
583-
start = (start,)
584-
if not isinstance(end, (tuple, list)):
585-
end = (end,)
586-
start = tuple(map(liboffsets._validate_business_time, start))
587-
end = tuple(map(liboffsets._validate_business_time, end))
583+
if _iterable_not_string(start):
584+
start = np.asarray(start)
585+
else:
586+
start = np.array([start])
587+
if _iterable_not_string(end):
588+
end = np.asarray(end)
589+
else:
590+
end = np.array([end])
591+
592+
vliboffsets = np.vectorize(liboffsets._validate_business_time)
593+
start = vliboffsets(start)
594+
end = vliboffsets(end)
588595

589596
# Validation of input
590597
if len(start) != len(end):
@@ -594,8 +601,8 @@ def __init__(self, start='09:00', end='17:00', offset=timedelta(0)):
594601

595602
# sort starting and ending time by starting time
596603
index = np.argsort(start)
597-
start = tuple(np.array(start)[index])
598-
end = tuple(np.array(end)[index])
604+
start = tuple(start[index])
605+
end = tuple(end[index])
599606

600607
total_secs = 0
601608
for i in range(num_openings):

0 commit comments

Comments
 (0)