Skip to content

Commit 4cd7db1

Browse files
author
Si Wei How
committed
Edit comments and tests
1 parent 63f0b52 commit 4cd7db1

File tree

2 files changed

+56
-7
lines changed

2 files changed

+56
-7
lines changed

pandas/tests/tseries/offsets/test_offsets.py

+19-7
Original file line numberDiff line numberDiff line change
@@ -769,19 +769,31 @@ def setup_method(self, method):
769769

770770
def test_constructor_errors(self):
771771
from datetime import time as dt_time
772-
with pytest.raises(ValueError):
772+
with pytest.raises(ValueError,
773+
match='time data must be specified only with hour and minute'):
773774
BusinessHour(start=dt_time(11, 0, 5))
774-
with pytest.raises(ValueError):
775+
with pytest.raises(ValueError,
776+
match="time data must match '%H:%M' format"):
775777
BusinessHour(start='AAA')
776-
with pytest.raises(ValueError):
778+
with pytest.raises(ValueError,
779+
match="time data must match '%H:%M' format"):
777780
BusinessHour(start='14:00:05')
778-
with pytest.raises(ValueError):
781+
with pytest.raises(ValueError,
782+
match='number of starting time cannot be 0'):
779783
BusinessHour(start=[])
780-
with pytest.raises(ValueError):
784+
with pytest.raises(ValueError,
785+
match='number of ending time cannot be 0'):
786+
BusinessHour(end=[])
787+
with pytest.raises(ValueError,
788+
match='number of starting time and ending time '
789+
'must be the same'):
781790
BusinessHour(start=['09:00', '11:00'])
782-
with pytest.raises(ValueError):
791+
with pytest.raises(ValueError,
792+
match='number of starting time and ending time '
793+
'must be the same'):
783794
BusinessHour(start=['09:00', '11:00'], end=['10:00'])
784-
with pytest.raises(ValueError):
795+
with pytest.raises(ValueError,
796+
match=r'invalid starting and ending time\(s\)'):
785797
BusinessHour(start=['09:00', '11:00'], end=['12:00', '20:00'])
786798

787799
def test_different_normalize_equals(self):

pandas/tseries/offsets.py

+37
Original file line numberDiff line numberDiff line change
@@ -583,13 +583,21 @@ 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+
<<<<<<< HEAD
586587
raise ValueError('Must include at least 1 start time')
588+
=======
589+
raise ValueError('number of starting time cannot be 0')
590+
>>>>>>> Edit comments and tests
587591
else:
588592
start = np.array([start])
589593
if _iterable_not_string(end):
590594
end = np.asarray(end)
591595
if len(end) == 0:
596+
<<<<<<< HEAD
592597
raise ValueError('Must include at least 1 end time')
598+
=======
599+
raise ValueError('number of ending time cannot be 0')
600+
>>>>>>> Edit comments and tests
593601
else:
594602
end = np.array([end])
595603

@@ -645,10 +653,16 @@ def _get_daytime_flag(self, start, end):
645653

646654
def _next_opening_time(self, other, sign=1):
647655
"""
656+
<<<<<<< HEAD
648657
If self.n and sign have the same sign, return the earliest opening time
649658
later than or equal to current time.
650659
Otherwise the latest opening time earlier than or equal to current
651660
time.
661+
=======
662+
If self.n and dir have the same sign, return the earliest opening time
663+
later than or equal to current time.
664+
Otherwise the latest opening time earlier than or equal to current time.
665+
>>>>>>> Edit comments and tests
652666
653667
Opening time always locates on BusinessDay.
654668
However, closing time may not if business hour extends over midnight.
@@ -657,14 +671,20 @@ def _next_opening_time(self, other, sign=1):
657671
latest_start = self.start[-1]
658672
if not self.next_bday.onOffset(other):
659673
# today is not business day
674+
<<<<<<< HEAD
660675
other = other + sign * self.next_bday
661676
if self.n * sign >= 0:
677+
=======
678+
other = other + dir * self.next_bday
679+
if self.n * dir >= 0:
680+
>>>>>>> Edit comments and tests
662681
return datetime(other.year, other.month, other.day,
663682
earliest_start.hour, earliest_start.minute)
664683
else:
665684
return datetime(other.year, other.month, other.day,
666685
latest_start.hour, latest_start.minute)
667686
else:
687+
<<<<<<< HEAD
668688
if self.n * sign >= 0 and latest_start < other.time():
669689
# current time is after latest starting time in today
670690
other = other + sign * self.next_bday
@@ -676,6 +696,19 @@ def _next_opening_time(self, other, sign=1):
676696
return datetime(other.year, other.month, other.day,
677697
latest_start.hour, latest_start.minute)
678698
if self.n * sign >= 0:
699+
=======
700+
if self.n * dir >= 0 and latest_start < other.time():
701+
# current time is after latest starting time in today
702+
other = other + dir * self.next_bday
703+
return datetime(other.year, other.month, other.day,
704+
earliest_start.hour, earliest_start.minute)
705+
elif self.n * dir < 0 and other.time() < earliest_start:
706+
# current time is before earliest starting time in today
707+
other = other + dir * self.next_bday
708+
return datetime(other.year, other.month, other.day,
709+
latest_start.hour, latest_start.minute)
710+
if self.n * dir >= 0:
711+
>>>>>>> Edit comments and tests
679712
# find earliest starting time later than or equal to current time
680713
for st in self.start:
681714
if other.time() <= st:
@@ -692,8 +725,12 @@ def _prev_opening_time(self, other):
692725
"""
693726
If n is positive, return the latest opening time earlier than or equal
694727
to current time.
728+
<<<<<<< HEAD
695729
Otherwise the earliest opening time later than or equal to current
696730
time.
731+
=======
732+
Otherwise the earliest opening time later than or equal to current time.
733+
>>>>>>> Edit comments and tests
697734
698735
"""
699736
return self._next_opening_time(other, sign=-1)

0 commit comments

Comments
 (0)