Skip to content

Commit 3f5c3bc

Browse files
author
Si Wei How
committed
Fix style issues
1 parent 0ba25af commit 3f5c3bc

File tree

2 files changed

+70
-39
lines changed

2 files changed

+70
-39
lines changed

pandas/tests/tseries/offsets/test_offsets.py

Lines changed: 53 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -760,9 +760,12 @@ def setup_method(self, method):
760760
self.offset6 = BusinessHour(start='20:00', end='05:00')
761761
self.offset7 = BusinessHour(n=-2, start=dt_time(21, 30),
762762
end=dt_time(6, 30))
763-
self.offset8 = BusinessHour(start=['09:00', '13:00'], end=['12:00', '17:00'])
764-
self.offset9 = BusinessHour(n=3, start=['09:00', '22:00'], end=['13:00', '03:00'])
765-
self.offset10 = BusinessHour(n=-1, start=['23:00', '13:00'], end=['02:00', '17:00'])
763+
self.offset8 = BusinessHour(start=['09:00', '13:00'],
764+
end=['12:00', '17:00'])
765+
self.offset9 = BusinessHour(n=3, start=['09:00', '22:00'],
766+
end=['13:00', '03:00'])
767+
self.offset10 = BusinessHour(n=-1, start=['23:00', '13:00'],
768+
end=['02:00', '17:00'])
766769

767770
def test_constructor_errors(self):
768771
from datetime import time as dt_time
@@ -796,9 +799,12 @@ def test_repr(self):
796799
assert repr(self.offset5) == '<BusinessHour: BH=11:00-14:30>'
797800
assert repr(self.offset6) == '<BusinessHour: BH=20:00-05:00>'
798801
assert repr(self.offset7) == '<-2 * BusinessHours: BH=21:30-06:30>'
799-
assert repr(self.offset8) == '<BusinessHour: BH=09:00,13:00-12:00,17:00>'
800-
assert repr(self.offset9) == '<3 * BusinessHours: BH=09:00,22:00-13:00,03:00>'
801-
assert repr(self.offset10) == '<-1 * BusinessHour: BH=13:00,23:00-17:00,02:00>'
802+
assert (repr(self.offset8) ==
803+
'<BusinessHour: BH=09:00,13:00-12:00,17:00>')
804+
assert (repr(self.offset9) ==
805+
'<3 * BusinessHours: BH=09:00,22:00-13:00,03:00>')
806+
assert (repr(self.offset10) ==
807+
'<-1 * BusinessHour: BH=13:00,23:00-17:00,02:00>')
802808

803809
def test_with_offset(self):
804810
expected = Timestamp('2014-07-01 13:00')
@@ -808,7 +814,7 @@ def test_with_offset(self):
808814

809815
def test_eq(self):
810816
for offset in [self.offset1, self.offset2, self.offset3, self.offset4,
811-
self.offset8, self.offset9, self.offset10]:
817+
self.offset8, self.offset9, self.offset10]:
812818
assert offset == offset
813819

814820
assert BusinessHour() != BusinessHour(-1)
@@ -817,14 +823,18 @@ def test_eq(self):
817823
assert (BusinessHour(start='09:00', end='17:00') !=
818824
BusinessHour(start='17:00', end='09:01'))
819825

820-
assert (BusinessHour(start=['23:00', '13:00'], end=['12:00', '17:00']) ==
821-
BusinessHour(start=['13:00', '23:00'], end=['17:00', '12:00']))
822-
assert (BusinessHour(start=['13:00', '23:00'], end=['18:00', '07:00']) !=
823-
BusinessHour(start=['13:00', '23:00'], end=['17:00', '12:00']))
826+
assert (BusinessHour(start=['23:00', '13:00'],
827+
end=['12:00', '17:00']) ==
828+
BusinessHour(start=['13:00', '23:00'],
829+
end=['17:00', '12:00']))
830+
assert (BusinessHour(start=['13:00', '23:00'],
831+
end=['18:00', '07:00']) !=
832+
BusinessHour(start=['13:00', '23:00'],
833+
end=['17:00', '12:00']))
824834

825835
def test_hash(self):
826836
for offset in [self.offset1, self.offset2, self.offset3, self.offset4,
827-
self.offset8, self.offset9, self.offset10]:
837+
self.offset8, self.offset9, self.offset10]:
828838
assert hash(offset) == hash(offset)
829839

830840
def test_call(self):
@@ -997,7 +1007,8 @@ def test_normalize(self, case):
9971007
datetime(2014, 7, 6, 23, 0): False,
9981008
datetime(2014, 7, 7, 3, 0): False}))
9991009

1000-
on_offset_cases.append((BusinessHour(start=['09:00', '13:00'], end=['12:00', '17:00']), {
1010+
on_offset_cases.append((BusinessHour(start=['09:00', '13:00'],
1011+
end=['12:00', '17:00']), {
10011012
datetime(2014, 7, 1, 9): True,
10021013
datetime(2014, 7, 1, 8, 59): False,
10031014
datetime(2014, 7, 1, 8): False,
@@ -1008,7 +1019,8 @@ def test_normalize(self, case):
10081019
datetime(2014, 7, 6, 12): False,
10091020
datetime(2014, 7, 1, 12, 30): False}))
10101021

1011-
on_offset_cases.append((BusinessHour(start=['19:00', '23:00'], end=['21:00', '05:00']), {
1022+
on_offset_cases.append((BusinessHour(start=['19:00', '23:00'],
1023+
end=['21:00', '05:00']), {
10121024
datetime(2014, 7, 1, 9, 0): False,
10131025
datetime(2014, 7, 1, 10, 0): False,
10141026
datetime(2014, 7, 1, 15): False,
@@ -1189,11 +1201,16 @@ def test_onOffset(self, case):
11891201
datetime(2014, 7, 7, 18): (datetime(2014, 7, 7, 17),
11901202
datetime(2014, 7, 8, 17))}))
11911203

1192-
opening_time_cases.append(([BusinessHour(start=['11:15', '15:00'], end=['13:00', '20:00']),
1193-
BusinessHour(n=3, start=['11:15', '15:00'], end=['12:00', '20:00']),
1194-
BusinessHour(start=['11:15', '15:00'], end=['13:00', '17:00']),
1195-
BusinessHour(n=2, start=['11:15', '15:00'], end=['12:00', '03:00']),
1196-
BusinessHour(n=3, start=['11:15', '15:00'], end=['13:00', '16:00'])], {
1204+
opening_time_cases.append(([BusinessHour(start=['11:15', '15:00'],
1205+
end=['13:00', '20:00']),
1206+
BusinessHour(n=3, start=['11:15', '15:00'],
1207+
end=['12:00', '20:00']),
1208+
BusinessHour(start=['11:15', '15:00'],
1209+
end=['13:00', '17:00']),
1210+
BusinessHour(n=2, start=['11:15', '15:00'],
1211+
end=['12:00', '03:00']),
1212+
BusinessHour(n=3, start=['11:15', '15:00'],
1213+
end=['13:00', '16:00'])], {
11971214
datetime(2014, 7, 1, 11): (datetime(2014, 7, 1, 11, 15),
11981215
datetime(2014, 6, 30, 15)),
11991216
datetime(2014, 7, 1, 18): (datetime(2014, 7, 2, 11, 15),
@@ -1223,10 +1240,12 @@ def test_onOffset(self, case):
12231240
datetime(2014, 7, 7, 9, 1): (datetime(2014, 7, 7, 11, 15),
12241241
datetime(2014, 7, 4, 15)),
12251242
datetime(2014, 7, 7, 12): (datetime(2014, 7, 7, 15),
1226-
datetime(2014, 7, 7, 11, 15))}))
1243+
datetime(2014, 7, 7, 11, 15))}))
12271244

1228-
opening_time_cases.append(([BusinessHour(-1, start=['17:00', '08:00'], end=['05:00', '10:00']),
1229-
BusinessHour(n=-2, start=['08:00', '17:00'], end=['10:00', '03:00'])], {
1245+
opening_time_cases.append(([BusinessHour(n=-1, start=['17:00', '08:00'],
1246+
end=['05:00', '10:00']),
1247+
BusinessHour(n=-2, start=['08:00', '17:00'],
1248+
end=['10:00', '03:00'])], {
12301249
datetime(2014, 7, 1, 11): (datetime(2014, 7, 1, 8),
12311250
datetime(2014, 7, 1, 17)),
12321251
datetime(2014, 7, 1, 18): (datetime(2014, 7, 1, 17),
@@ -1414,7 +1433,8 @@ def test_opening_time(self, case):
14141433
datetime(2014, 7, 7, 19, 30, 30): datetime(2014, 7, 5, 4, 30, 30)}))
14151434

14161435
# multiple business hours
1417-
apply_cases.append((BusinessHour(start=['09:00', '14:00'], end=['12:00', '18:00']), {
1436+
apply_cases.append((BusinessHour(start=['09:00', '14:00'],
1437+
end=['12:00', '18:00']), {
14181438
datetime(2014, 7, 1, 11): datetime(2014, 7, 1, 14),
14191439
datetime(2014, 7, 1, 15): datetime(2014, 7, 1, 16),
14201440
datetime(2014, 7, 1, 19): datetime(2014, 7, 2, 10),
@@ -1434,7 +1454,8 @@ def test_opening_time(self, case):
14341454
datetime(2014, 7, 4, 17, 30): datetime(2014, 7, 7, 9, 30),
14351455
datetime(2014, 7, 4, 17, 30, 30): datetime(2014, 7, 7, 9, 30, 30)}))
14361456

1437-
apply_cases.append((BusinessHour(n=4, start=['09:00', '14:00'], end=['12:00', '18:00']), {
1457+
apply_cases.append((BusinessHour(n=4, start=['09:00', '14:00'],
1458+
end=['12:00', '18:00']), {
14381459
datetime(2014, 7, 1, 11): datetime(2014, 7, 1, 17),
14391460
datetime(2014, 7, 1, 13): datetime(2014, 7, 2, 9),
14401461
datetime(2014, 7, 1, 15): datetime(2014, 7, 2, 10),
@@ -1450,7 +1471,8 @@ def test_opening_time(self, case):
14501471
datetime(2014, 7, 4, 16, 30): datetime(2014, 7, 7, 11, 30),
14511472
datetime(2014, 7, 4, 16, 30, 30): datetime(2014, 7, 7, 11, 30, 30)}))
14521473

1453-
apply_cases.append((BusinessHour(n=-4, start=['09:00', '14:00'], end=['12:00', '18:00']), {
1474+
apply_cases.append((BusinessHour(n=-4, start=['09:00', '14:00'],
1475+
end=['12:00', '18:00']), {
14541476
datetime(2014, 7, 1, 11): datetime(2014, 6, 30, 16),
14551477
datetime(2014, 7, 1, 13): datetime(2014, 6, 30, 17),
14561478
datetime(2014, 7, 1, 15): datetime(2014, 6, 30, 18),
@@ -1466,7 +1488,8 @@ def test_opening_time(self, case):
14661488
datetime(2014, 7, 7, 9, 30): datetime(2014, 7, 4, 14, 30),
14671489
datetime(2014, 7, 7, 9, 30, 30): datetime(2014, 7, 4, 14, 30, 30)}))
14681490

1469-
apply_cases.append((BusinessHour(n=-1, start=['19:00', '03:00'], end=['01:00', '05:00']), {
1491+
apply_cases.append((BusinessHour(n=-1, start=['19:00', '03:00'],
1492+
end=['01:00', '05:00']), {
14701493
datetime(2014, 7, 1, 17): datetime(2014, 7, 1, 4),
14711494
datetime(2014, 7, 2, 14): datetime(2014, 7, 2, 4),
14721495
datetime(2014, 7, 2, 8): datetime(2014, 7, 2, 4),
@@ -1541,7 +1564,8 @@ def test_apply(self, case):
15411564
datetime(2014, 7, 7, 23, 30): datetime(2014, 7, 15, 21, 30)}))
15421565

15431566
# large n for multiple opening hours (3 days and 1 hour before)
1544-
apply_large_n_cases.append((BusinessHour(n=-25, start=['09:00', '14:00'], end=['12:00', '19:00']), {
1567+
apply_large_n_cases.append((BusinessHour(n=-25, start=['09:00', '14:00'],
1568+
end=['12:00', '19:00']), {
15451569
datetime(2014, 7, 1, 11): datetime(2014, 6, 26, 10),
15461570
datetime(2014, 7, 1, 13): datetime(2014, 6, 26, 11),
15471571
datetime(2014, 7, 1, 9): datetime(2014, 6, 25, 18),
@@ -1557,7 +1581,8 @@ def test_apply(self, case):
15571581
datetime(2014, 7, 7, 10, 30, 30): datetime(2014, 7, 2, 9, 30, 30)}))
15581582

15591583
# 5 days and 3 hours later
1560-
apply_large_n_cases.append((BusinessHour(28, start=['21:00', '03:00'], end=['01:00', '04:00']), {
1584+
apply_large_n_cases.append((BusinessHour(28, start=['21:00', '03:00'],
1585+
end=['01:00', '04:00']), {
15611586
datetime(2014, 7, 1, 11): datetime(2014, 7, 9, 0),
15621587
datetime(2014, 7, 1, 22): datetime(2014, 7, 9, 3),
15631588
datetime(2014, 7, 1, 23): datetime(2014, 7, 9, 21),

pandas/tseries/offsets.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -588,15 +588,17 @@ def __init__(self, start='09:00', end='17:00', offset=timedelta(0)):
588588

589589
# Validation of input
590590
if len(start) != len(end):
591-
raise ValueError('number of starting time and ending time must be the same')
591+
raise ValueError('number of starting time and ending time'
592+
'must be the same')
592593
num_openings = len(start)
593594
openings = sorted(zip(start, end))
594595
start = tuple(x for x, _ in openings)
595596
end = tuple(x for _, x in openings)
596597
total_secs = 0
597598
for i in range(num_openings):
598599
total_secs += self._get_business_hours_by_sec(start[i], end[i])
599-
total_secs += self._get_business_hours_by_sec(end[i], start[(i + 1) % num_openings])
600+
total_secs += self._get_business_hours_by_sec(
601+
end[i], start[(i + 1) % num_openings])
600602
if total_secs != 24 * 60 * 60:
601603
raise ValueError('invalid starting and ending time(s)')
602604

@@ -740,7 +742,8 @@ def rollforward(self, dt):
740742
def _get_closing_time(self, dt):
741743
for i, st in enumerate(self.start):
742744
if st.hour == dt.hour and st.minute == dt.minute:
743-
return dt + timedelta(seconds=self._get_business_hours_by_sec(st, self.end[i]))
745+
return dt + timedelta(
746+
seconds=self._get_business_hours_by_sec(st, self.end[i]))
744747
raise ValueError("dt should be a starting time")
745748

746749
@apply_wraps
@@ -751,8 +754,8 @@ def apply(self, other):
751754
# reset timezone and nanosecond
752755
# other may be a Timestamp, thus not use replace
753756
other = datetime(other.year, other.month, other.day,
754-
other.hour, other.minute,
755-
other.second, other.microsecond)
757+
other.hour, other.minute,
758+
other.second, other.microsecond)
756759
n = self.n
757760
if n >= 0:
758761
if (other.time() in self.end or
@@ -767,7 +770,7 @@ def apply(self, other):
767770
other = self._get_closing_time(other)
768771

769772
businesshours = sum(self._get_business_hours_by_sec(st, en)
770-
for st, en in zip(self.start, self.end))
773+
for st, en in zip(self.start, self.end))
771774
bd, r = divmod(abs(n * 60), businesshours // 60)
772775
if n < 0:
773776
bd, r = -bd, -r
@@ -788,7 +791,8 @@ def apply(self, other):
788791
# because of previous adjustment, time will be larger than start
789792
if n >= 0:
790793
while rem != timedelta(0):
791-
bhour_left = self._get_closing_time(self._prev_opening_time(other)) - other
794+
bhour_left = self._get_closing_time(
795+
self._prev_opening_time(other)) - other
792796
if bhour_left >= rem:
793797
other = other + rem
794798
rem = timedelta(0)
@@ -804,7 +808,8 @@ def apply(self, other):
804808
else:
805809
rem = rem - bhour_left
806810
other = self._get_closing_time(
807-
self._next_opening_time(other + bhour_left - timedelta(seconds=1)))
811+
self._next_opening_time(
812+
other + bhour_left - timedelta(seconds=1)))
808813

809814
# edge handling
810815
if n >= 0:
@@ -814,12 +819,12 @@ def apply(self, other):
814819
if other.time() in self.start and nanosecond == 0:
815820
# adjustment to move to previous business day
816821
other = self._get_closing_time(self._next_opening_time(
817-
other - timedelta(seconds=1)))
822+
other - timedelta(seconds=1)))
818823

819824
return other
820825
else:
821826
raise ApplyTypeError(
822-
'Only know how to combine business hour with datetime')
827+
'Only know how to combine business hour with datetime')
823828

824829
def onOffset(self, dt):
825830
if self.normalize and not _is_normalized(dt):
@@ -848,7 +853,8 @@ def _onOffset(self, dt):
848853
businesshours = 0
849854
for i, st in enumerate(self.start):
850855
if op.hour == st.hour and op.minute == st.minute:
851-
businesshours = self._get_business_hours_by_sec(st, self.end[i])
856+
businesshours = self._get_business_hours_by_sec(
857+
st, self.end[i])
852858
if span <= businesshours:
853859
return True
854860
else:

0 commit comments

Comments
 (0)