Skip to content

Commit 27e7196

Browse files
author
Si Wei How
committed
Edit error messages
1 parent d38da2f commit 27e7196

File tree

2 files changed

+26
-19
lines changed

2 files changed

+26
-19
lines changed

pandas/tests/tseries/offsets/test_offsets.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -770,7 +770,8 @@ def setup_method(self, method):
770770
def test_constructor_errors(self):
771771
from datetime import time as dt_time
772772
with pytest.raises(ValueError,
773-
match='time data must be specified only with hour and minute'):
773+
match='time data must be specified only with hour '
774+
'and minute'):
774775
BusinessHour(start=dt_time(11, 0, 5))
775776
with pytest.raises(ValueError,
776777
match="time data must match '%H:%M' format"):
@@ -779,10 +780,10 @@ def test_constructor_errors(self):
779780
match="time data must match '%H:%M' format"):
780781
BusinessHour(start='14:00:05')
781782
with pytest.raises(ValueError,
782-
match='number of starting time cannot be 0'):
783+
match='Must include at least 1 start time'):
783784
BusinessHour(start=[])
784785
with pytest.raises(ValueError,
785-
match='number of ending time cannot be 0'):
786+
match='Must include at least 1 end time'):
786787
BusinessHour(end=[])
787788
with pytest.raises(ValueError,
788789
match='number of starting time and ending time '
@@ -793,7 +794,9 @@ def test_constructor_errors(self):
793794
'must be the same'):
794795
BusinessHour(start=['09:00', '11:00'], end=['10:00'])
795796
with pytest.raises(ValueError,
796-
match=r'invalid starting and ending time\(s\)'):
797+
match=r'invalid starting and ending time\(s\): '
798+
'opening hours should not touch or overlap with '
799+
'one another'):
797800
BusinessHour(start=['09:00', '11:00'], end=['12:00', '20:00'])
798801

799802
def test_different_normalize_equals(self):

pandas/tseries/offsets.py

+19-15
Original file line numberDiff line numberDiff line change
@@ -583,13 +583,13 @@ def __init__(self, start='09:00', end='17:00', offset=timedelta(0)):
583583
if _iterable_not_string(start):
584584
start = np.asarray(start)
585585
if len(start) == 0:
586-
raise ValueError('number of starting time cannot be 0')
586+
raise ValueError('Must include at least 1 start time')
587587
else:
588588
start = np.array([start])
589589
if _iterable_not_string(end):
590590
end = np.asarray(end)
591591
if len(end) == 0:
592-
raise ValueError('number of ending time cannot be 0')
592+
raise ValueError('Must include at least 1 end time')
593593
else:
594594
end = np.array([end])
595595

@@ -614,7 +614,9 @@ def __init__(self, start='09:00', end='17:00', offset=timedelta(0)):
614614
total_secs += self._get_business_hours_by_sec(
615615
end[i], start[(i + 1) % num_openings])
616616
if total_secs != 24 * 60 * 60:
617-
raise ValueError('invalid starting and ending time(s)')
617+
raise ValueError('invalid starting and ending time(s): '
618+
'opening hours should not touch or overlap with '
619+
'one another')
618620

619621
object.__setattr__(self, "start", start)
620622
object.__setattr__(self, "end", end)
@@ -641,11 +643,12 @@ def next_bday(self):
641643
def _get_daytime_flag(self, start, end):
642644
return start < end
643645

644-
def _next_opening_time(self, other, dir=1):
646+
def _next_opening_time(self, other, sign=1):
645647
"""
646-
If self.n and dir have the same sign, return the earliest opening time
648+
If self.n and sign have the same sign, return the earliest opening time
647649
later than or equal to current time.
648-
Otherwise the latest opening time earlier than or equal to current time.
650+
Otherwise the latest opening time earlier than or equal to current
651+
time.
649652
650653
Opening time always locates on BusinessDay.
651654
However, closing time may not if business hour extends over midnight.
@@ -654,25 +657,25 @@ def _next_opening_time(self, other, dir=1):
654657
latest_start = self.start[-1]
655658
if not self.next_bday.onOffset(other):
656659
# today is not business day
657-
other = other + dir * self.next_bday
658-
if self.n * dir >= 0:
660+
other = other + sign * self.next_bday
661+
if self.n * sign >= 0:
659662
return datetime(other.year, other.month, other.day,
660663
earliest_start.hour, earliest_start.minute)
661664
else:
662665
return datetime(other.year, other.month, other.day,
663666
latest_start.hour, latest_start.minute)
664667
else:
665-
if self.n * dir >= 0 and latest_start < other.time():
668+
if self.n * sign >= 0 and latest_start < other.time():
666669
# current time is after latest starting time in today
667-
other = other + dir * self.next_bday
670+
other = other + sign * self.next_bday
668671
return datetime(other.year, other.month, other.day,
669672
earliest_start.hour, earliest_start.minute)
670-
elif self.n * dir < 0 and other.time() < earliest_start:
673+
elif self.n * sign < 0 and other.time() < earliest_start:
671674
# current time is before earliest starting time in today
672-
other = other + dir * self.next_bday
675+
other = other + sign * self.next_bday
673676
return datetime(other.year, other.month, other.day,
674677
latest_start.hour, latest_start.minute)
675-
if self.n * dir >= 0:
678+
if self.n * sign >= 0:
676679
# find earliest starting time later than or equal to current time
677680
for st in self.start:
678681
if other.time() <= st:
@@ -689,10 +692,11 @@ def _prev_opening_time(self, other):
689692
"""
690693
If n is positive, return the latest opening time earlier than or equal
691694
to current time.
692-
Otherwise the earliest opening time later than or equal to current time.
695+
Otherwise the earliest opening time later than or equal to current
696+
time.
693697
694698
"""
695-
return self._next_opening_time(other, dir=-1)
699+
return self._next_opening_time(other, sign=-1)
696700

697701
def _get_business_hours_by_sec(self, start, end):
698702
"""

0 commit comments

Comments
 (0)