Skip to content

Commit 4ed3070

Browse files
harisbalharisbal
authored and
harisbal
committed
Style fixes (pep8)
1 parent 75dea48 commit 4ed3070

File tree

2 files changed

+80
-79
lines changed

2 files changed

+80
-79
lines changed

pandas/core/indexes/base.py

+16-16
Original file line numberDiff line numberDiff line change
@@ -3033,7 +3033,7 @@ def _complete_join():
30333033
new_lvls = join_index.levels
30343034
new_lbls = join_index.labels
30353035
new_nms = join_index.names
3036-
3036+
30373037
for n in not_overlap:
30383038
if n in self_names:
30393039
idx = lidx
@@ -3043,16 +3043,16 @@ def _complete_join():
30433043
idx = ridx
30443044
lvls = other.levels[other_names.index(n)].values
30453045
lbls = other.labels[other_names.index(n)]
3046-
3046+
30473047
new_lvls = new_lvls.__add__([lvls])
30483048
new_nms = new_nms.__add__([n])
30493049

3050-
# Return the label on match else -1
3051-
l = [lbls[i] if i!=-1 else -1 for i in idx]
3050+
# Return the label on match else -1
3051+
l = [lbls[i] if i != -1 else -1 for i in idx]
30523052
new_lbls = new_lbls.__add__([l])
3053-
3054-
return new_lvls, new_lbls, new_nms
3055-
3053+
3054+
return new_lvls, new_lbls, new_nms
3055+
30563056
# figure out join names
30573057
self_names = [n for n in self.names if n is not None]
30583058
other_names = [n for n in other.names if n is not None]
@@ -3065,7 +3065,7 @@ def _complete_join():
30653065
self_is_mi = isinstance(self, MultiIndex)
30663066
other_is_mi = isinstance(other, MultiIndex)
30673067

3068-
# need at least 1 in common, but not more than 1
3068+
# need at least 1 in common
30693069
if not len(overlap):
30703070
raise ValueError("cannot join with no overlapping index names")
30713071

@@ -3075,31 +3075,31 @@ def _complete_join():
30753075

30763076
if not (other_tmp.is_unique and self_tmp.is_unique):
30773077
raise TypeError(" The index resulting from the overlapping "
3078-
"levels is not unique")
3079-
3078+
" levels is not unique ")
3079+
30803080
join_index, lidx, ridx = self_tmp.join(other_tmp, how=how,
30813081
return_indexers=True)
3082-
3083-
# Append to the returned Index the non-overlapping levels
3082+
3083+
# Append to the returned Index the non-overlapping levels
30843084
not_overlap = ldrop_levels + rdrop_levels
3085-
3085+
30863086
if how == 'left':
30873087
join_index = self
30883088
elif how == 'right':
30893089
join_index = other
30903090
else:
30913091
join_index = join_index
3092-
3092+
30933093
if how == 'outer':
30943094
new_levels, new_labels, new_names = _complete_join()
30953095
else:
30963096
new_levels = join_index.levels
30973097
new_labels = join_index.labels
30983098
new_names = join_index.names
3099-
3099+
31003100
join_index = MultiIndex(levels=new_levels, labels=new_labels,
31013101
names=new_names, verify_integrity=False)
3102-
3102+
31033103
return join_index, lidx, ridx
31043104

31053105
else:

pandas/tests/reshape/test_merge.py

+64-63
Original file line numberDiff line numberDiff line change
@@ -1208,8 +1208,8 @@ def test_join_multi_levels2(self):
12081208
.reindex(columns=['share', 'log_return']))
12091209

12101210
result = (merge(household.reset_index(), log_return.reset_index(),
1211-
on=['asset_id'], how='outer')
1212-
.set_index(['household_id', 'asset_id', 't']))
1211+
on=['asset_id'], how='outer')
1212+
.set_index(['household_id', 'asset_id', 't']))
12131213

12141214
assert_frame_equal(result, expected)
12151215

@@ -1220,132 +1220,133 @@ def test_join_multi_levels3(self):
12201220
pd.DataFrame(
12211221
dict(Origin=[1, 1, 2, 2, 3],
12221222
Destination=[1, 2, 1, 3, 1],
1223-
Period=['AM','PM','IP','AM','OP'],
1223+
Period=['AM', 'PM', 'IP', 'AM', 'OP'],
12241224
TripPurp=['hbw', 'nhb', 'hbo', 'nhb', 'hbw'],
12251225
Trips=[1987, 3647, 2470, 4296, 4444]),
12261226
columns=['Origin', 'Destination', 'Period',
12271227
'TripPurp', 'Trips'])
12281228
.set_index(['Origin', 'Destination', 'Period', 'TripPurp']))
1229-
1229+
12301230
distances = (
12311231
pd.DataFrame(
1232-
dict(Origin= [1, 1, 2, 2, 3, 3, 5],
1232+
dict(Origin=[1, 1, 2, 2, 3, 3, 5],
12331233
Destination=[1, 2, 1, 2, 1, 2, 6],
1234-
Period=['AM','PM','IP','AM','OP','IP', 'AM'],
1234+
Period=['AM', 'PM', 'IP', 'AM', 'OP', 'IP', 'AM'],
12351235
LinkType=['a', 'a', 'c', 'b', 'a', 'b', 'a'],
12361236
Distance=[100, 80, 90, 80, 75, 35, 55]),
1237-
columns=['Origin', 'Destination', 'Period',
1237+
columns=['Origin', 'Destination', 'Period',
12381238
'LinkType', 'Distance'])
1239-
.set_index(['Origin', 'Destination','Period', 'LinkType']))
1240-
1239+
.set_index(['Origin', 'Destination', 'Period', 'LinkType']))
1240+
12411241
expected = (
12421242
pd.DataFrame(
12431243
dict(Origin=[1, 1, 2, 2, 3],
12441244
Destination=[1, 2, 1, 3, 1],
1245-
Period=['AM','PM','IP','AM','OP'],
1245+
Period=['AM', 'PM', 'IP', 'AM', 'OP'],
12461246
TripPurp=['hbw', 'nhb', 'hbo', 'nhb', 'hbw'],
12471247
Trips=[1987, 3647, 2470, 4296, 4444],
12481248
Trips_joined=[1987, 3647, 2470, 4296, 4444]),
12491249
columns=['Origin', 'Destination', 'Period',
12501250
'TripPurp', 'Trips', 'Trips_joined'])
12511251
.set_index(['Origin', 'Destination', 'Period', 'TripPurp']))
1252-
1253-
result = matrix.join(matrix, how='inner', rsuffix='_joined')
1252+
1253+
result = matrix.join(matrix, how='inner', rsuffix='_joined')
12541254
assert_frame_equal(result, expected)
1255-
1256-
#Left join
1255+
1256+
# Left join
12571257
expected = (
12581258
pd.DataFrame(
1259-
dict(Origin= [1, 1, 2, 2, 3],
1259+
dict(Origin=[1, 1, 2, 2, 3],
12601260
Destination=[1, 2, 1, 3, 1],
1261-
Period=['AM','PM','IP', 'AM', 'OP'],
1261+
Period=['AM', 'PM', 'IP', 'AM', 'OP'],
12621262
TripPurp=['hbw', 'nhb', 'hbo', 'nhb', 'hbw'],
12631263
Trips=[1987, 3647, 2470, 4296, 4444],
12641264
Distance=[100, 80, 90, np.nan, 75]),
1265-
columns=['Origin', 'Destination', 'Period', 'TripPurp',
1265+
columns=['Origin', 'Destination', 'Period', 'TripPurp',
12661266
'Trips', 'Distance'])
12671267
.set_index(['Origin', 'Destination', 'Period', 'TripPurp']))
1268-
1268+
12691269
result = matrix.join(distances, how='left')
12701270
assert_frame_equal(result, expected)
1271-
1272-
#Right join
1271+
1272+
# Right join
12731273
expected = (
12741274
pd.DataFrame(
1275-
dict(Origin= [1, 1, 2, 2, 3, 3, 5],
1275+
dict(Origin=[1, 1, 2, 2, 3, 3, 5],
12761276
Destination=[1, 2, 1, 2, 1, 2, 6],
1277-
Period=['AM','PM','IP','AM','OP','IP', 'AM'],
1277+
Period=['AM', 'PM', 'IP', 'AM', 'OP', 'IP', 'AM'],
12781278
LinkType=['a', 'a', 'c', 'b', 'a', 'b', 'a'],
12791279
Trips=[1987, 3647, 2470, np.nan, 4444, np.nan, np.nan],
12801280
Distance=[100, 80, 90, 80, 75, 35, 55]),
1281-
columns=['Origin', 'Destination', 'Period',
1281+
columns=['Origin', 'Destination', 'Period',
12821282
'LinkType', 'Trips', 'Distance'])
1283-
.set_index(['Origin', 'Destination','Period', 'LinkType']))
1284-
1283+
.set_index(['Origin', 'Destination', 'Period', 'LinkType']))
1284+
12851285
result = matrix.join(distances, how='right')
12861286
assert_frame_equal(result, expected)
1287-
1288-
#Inner join
1287+
1288+
# Inner join
12891289
expected = (
12901290
pd.DataFrame(
1291-
dict(Origin= [1, 1, 2, 3],
1291+
dict(Origin=[1, 1, 2, 3],
12921292
Destination=[1, 2, 1, 1],
1293-
Period=['AM','PM','IP', 'OP'],
1293+
Period=['AM', 'PM', 'IP', 'OP'],
12941294
Trips=[1987, 3647, 2470, 4444],
12951295
Distance=[100, 80, 90, 75]),
1296-
columns=['Origin', 'Destination', 'Period', 'Trips', 'Distance'])
1296+
columns=['Origin', 'Destination', 'Period',
1297+
'Trips', 'Distance'])
12971298
.set_index(['Origin', 'Destination', 'Period']))
1298-
1299+
12991300
result = matrix.join(distances, how='inner')
13001301
assert_frame_equal(result, expected)
13011302

1302-
#Outer join
1303+
# Outer join
13031304
expected = (
13041305
pd.DataFrame(
1305-
dict(Origin= [1, 1, 2, 2, 2, 3, 3, 5],
1306+
dict(Origin=[1, 1, 2, 2, 2, 3, 3, 5],
13061307
Destination=[1, 2, 1, 2, 3, 1, 2, 6],
1307-
Period=['AM','PM','IP', 'AM', 'AM', 'OP', 'IP', 'AM'],
1308+
Period=['AM', 'PM', 'IP', 'AM', 'AM', 'OP', 'IP', 'AM'],
13081309
TripPurp=['hbw', 'nhb', 'hbo', np.nan, 'nhb',
13091310
'hbw', np.nan, np.nan],
13101311
LinkType=['a', 'a', 'c', 'b', np.nan, 'a', 'b', 'a'],
1311-
Trips=[1987, 3647, 2470, np.nan, 4296, 4444, np.nan, np.nan],
1312+
Trips=[1987, 3647, 2470, np.nan,
1313+
4296, 4444, np.nan, np.nan],
13121314
Distance=[100, 80, 90, 80, np.nan, 75, 35, 55]),
1313-
columns=['Origin', 'Destination', 'Period', 'TripPurp', 'LinkType',
1314-
'Trips', 'Distance'])
1315-
.set_index(['Origin', 'Destination', 'Period', 'TripPurp', 'LinkType']))
1316-
1317-
1315+
columns=['Origin', 'Destination', 'Period', 'TripPurp',
1316+
'LinkType', 'Trips', 'Distance'])
1317+
.set_index(['Origin', 'Destination', 'Period',
1318+
'TripPurp', 'LinkType']))
1319+
13181320
result = matrix.join(distances, how='outer')
13191321
assert_frame_equal(result, expected)
1320-
1321-
#Non-unique resulting index
1322+
1323+
# Non-unique resulting index
13221324
distances2 = (
13231325
pd.DataFrame(
1324-
dict(Origin= [1, 1, 2],
1326+
dict(Origin=[1, 1, 2],
13251327
Destination=[1, 1, 1],
1326-
Period=['AM','AM', 'PM'],
1328+
Period=['AM', 'AM', 'PM'],
13271329
LinkType=['a', 'b', 'a'],
13281330
Distance=[100, 110, 120]),
1329-
columns=['Origin', 'Destination', 'Period',
1331+
columns=['Origin', 'Destination', 'Period',
13301332
'LinkType', 'Distance'])
1331-
.set_index(['Origin', 'Destination','Period', 'LinkType']))
1332-
1333+
.set_index(['Origin', 'Destination', 'Period', 'LinkType']))
1334+
13331335
def f():
13341336
matrix.join(distances2, how='left')
13351337
pytest.raises(TypeError, f)
1336-
1337-
#No-overlapping level names
1338+
1339+
# No-overlapping level names
13381340
distances2 = (
13391341
pd.DataFrame(
1340-
dict(Orig= [1, 1, 2, 2, 3, 3, 5],
1342+
dict(Orig=[1, 1, 2, 2, 3, 3, 5],
13411343
Dest=[1, 2, 1, 2, 1, 2, 6],
1342-
Per=['AM','PM','IP','AM','OP','IP', 'AM'],
1344+
Per=['AM', 'PM', 'IP', 'AM', 'OP', 'IP', 'AM'],
13431345
LinkTyp=['a', 'a', 'c', 'b', 'a', 'b', 'a'],
13441346
Dist=[100, 80, 90, 80, 75, 35, 55]),
1345-
columns=['Orig', 'Dest', 'Per',
1346-
'LinkTyp', 'Dist'])
1347-
.set_index(['Orig', 'Dest','Per', 'LinkTyp']))
1348-
1347+
columns=['Orig', 'Dest', 'Per', 'LinkTyp', 'Dist'])
1348+
.set_index(['Orig', 'Dest', 'Per', 'LinkTyp']))
1349+
13491350
def f():
13501351
matrix.join(distances2, how='left')
13511352
pytest.raises(ValueError, f)
@@ -1355,29 +1356,29 @@ def f():
13551356
pd.DataFrame(
13561357
dict(Origin=[1, 1, 2, 2, 3, 3, 5],
13571358
Destination=[1, 2, 1, 2, 1, 2, 6],
1358-
Period=[np.nan,np.nan,np.nan,np.nan,np.nan,np.nan,np.nan],
1359+
Period=[np.nan] * 7,
13591360
LinkType=['a', 'a', 'c', 'b', 'a', 'b', 'a'],
13601361
Distance=[100, 80, 90, 80, 75, 35, 55]),
1361-
columns=['Origin', 'Destination', 'Period',
1362+
columns=['Origin', 'Destination', 'Period',
13621363
'LinkType', 'Distance'])
1363-
.set_index(['Origin', 'Destination','Period', 'LinkType']))
1364-
1365-
1364+
.set_index(['Origin', 'Destination', 'Period', 'LinkType']))
1365+
13661366
expected = (
13671367
pd.DataFrame(
13681368
dict(Origin=[1, 1, 2, 2, 3],
13691369
Destination=[1, 2, 1, 3, 1],
1370-
Period=['AM','PM','IP','AM','OP'],
1370+
Period=['AM', 'PM', 'IP', 'AM', 'OP'],
13711371
TripPurp=['hbw', 'nhb', 'hbo', 'nhb', 'hbw'],
13721372
Trips=[1987, 3647, 2470, 4296, 4444],
1373-
Distance=[np.nan, np.nan, np.nan, np.nan, np.nan]),
1373+
Distance=[np.nan] * 5),
13741374
columns=['Origin', 'Destination', 'Period',
13751375
'TripPurp', 'Trips', 'Distance'])
13761376
.set_index(['Origin', 'Destination', 'Period', 'TripPurp']))
1377-
1377+
13781378
result = matrix.join(distances2, how='left')
13791379
assert_frame_equal(result, expected)
13801380

1381+
13811382
@pytest.fixture
13821383
def df():
13831384
return DataFrame(

0 commit comments

Comments
 (0)