Skip to content

Commit 9f3b88e

Browse files
committed
Rewrite dict literal for files in tests/reshape/
1 parent 066a16c commit 9f3b88e

File tree

3 files changed

+93
-93
lines changed

3 files changed

+93
-93
lines changed

pandas/tests/reshape/concat/test_datetimes.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -373,10 +373,10 @@ def test_concat_tz_series_with_datetimelike(self):
373373

374374
def test_concat_tz_frame(self):
375375
df2 = DataFrame(
376-
dict(
377-
A=Timestamp("20130102", tz="US/Eastern"),
378-
B=Timestamp("20130603", tz="CET"),
379-
),
376+
{
377+
'A':Timestamp("20130102", tz="US/Eastern"),
378+
'B':Timestamp("20130603", tz="CET"),
379+
},
380380
index=range(5),
381381
)
382382

@@ -391,20 +391,20 @@ def test_concat_multiple_tzs(self):
391391
ts2 = Timestamp("2015-01-01", tz="UTC")
392392
ts3 = Timestamp("2015-01-01", tz="EST")
393393

394-
df1 = DataFrame(dict(time=[ts1]))
395-
df2 = DataFrame(dict(time=[ts2]))
396-
df3 = DataFrame(dict(time=[ts3]))
394+
df1 = DataFrame({'time':[ts1]})
395+
df2 = DataFrame({'time':[ts2]})
396+
df3 = DataFrame({'time':[ts3]})
397397

398398
results = pd.concat([df1, df2]).reset_index(drop=True)
399-
expected = DataFrame(dict(time=[ts1, ts2]), dtype=object)
399+
expected = DataFrame({'time':[ts1, ts2]}, dtype=object)
400400
tm.assert_frame_equal(results, expected)
401401

402402
results = pd.concat([df1, df3]).reset_index(drop=True)
403-
expected = DataFrame(dict(time=[ts1, ts3]), dtype=object)
403+
expected = DataFrame({'time':[ts1, ts3]}, dtype=object)
404404
tm.assert_frame_equal(results, expected)
405405

406406
results = pd.concat([df2, df3]).reset_index(drop=True)
407-
expected = DataFrame(dict(time=[ts2, ts3]))
407+
expected = DataFrame({'time':[ts2, ts3]})
408408
tm.assert_frame_equal(results, expected)
409409

410410
def test_concat_multiindex_with_tz(self):

pandas/tests/reshape/merge/test_merge.py

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -422,10 +422,10 @@ def test_left_merge_empty_dataframe(self):
422422
@pytest.mark.parametrize(
423423
"kwarg",
424424
[
425-
dict(left_index=True, right_index=True),
426-
dict(left_index=True, right_on="x"),
427-
dict(left_on="a", right_index=True),
428-
dict(left_on="a", right_on="x"),
425+
{'left_index':True, 'right_index':True},
426+
{'left_index':True, 'right_on':"x"},
427+
{'left_on':"a", 'right_index':True},
428+
{'left_on':"a", 'right_on':"x"},
429429
],
430430
)
431431
def test_merge_left_empty_right_empty(self, join_type, kwarg):
@@ -475,18 +475,18 @@ def check2(exp, kwarg):
475475
tm.assert_frame_equal(result, exp)
476476

477477
for kwarg in [
478-
dict(left_index=True, right_index=True),
479-
dict(left_index=True, right_on="x"),
478+
{'left_index':True, 'right_index':True},
479+
{'left_index':True, 'right_on':"x"},
480480
]:
481481
check1(exp_in, kwarg)
482482
check2(exp_out, kwarg)
483483

484-
kwarg = dict(left_on="a", right_index=True)
484+
kwarg = {'left_on':"a", 'right_index':True}
485485
check1(exp_in, kwarg)
486486
exp_out["a"] = [0, 1, 2]
487487
check2(exp_out, kwarg)
488488

489-
kwarg = dict(left_on="a", right_on="x")
489+
kwarg = {'left_on':"a", 'right_on':"x"}
490490
check1(exp_in, kwarg)
491491
exp_out["a"] = np.array([np.nan] * 3, dtype=object)
492492
check2(exp_out, kwarg)
@@ -524,10 +524,10 @@ def check2(exp, kwarg):
524524
tm.assert_frame_equal(result, exp)
525525

526526
for kwarg in [
527-
dict(left_index=True, right_index=True),
528-
dict(left_index=True, right_on="x"),
529-
dict(left_on="a", right_index=True),
530-
dict(left_on="a", right_on="x"),
527+
{'left_index':True, 'right_index':True},
528+
{'left_index':True, 'right_on':"x"},
529+
{'left_on':"a", 'right_index':True},
530+
{'left_on':"a", 'right_on':"x"},
531531
]:
532532
check1(exp_in, kwarg)
533533
check2(exp_out, kwarg)
@@ -1999,19 +1999,19 @@ def test_merge_series(on, left_on, right_on, left_index, right_index, nm):
19991999
@pytest.mark.parametrize(
20002000
"col1, col2, kwargs, expected_cols",
20012001
[
2002-
(0, 0, dict(suffixes=("", "_dup")), ["0", "0_dup"]),
2003-
(0, 0, dict(suffixes=(None, "_dup")), [0, "0_dup"]),
2004-
(0, 0, dict(suffixes=("_x", "_y")), ["0_x", "0_y"]),
2005-
(0, 0, dict(suffixes=["_x", "_y"]), ["0_x", "0_y"]),
2006-
("a", 0, dict(suffixes=(None, "_y")), ["a", 0]),
2007-
(0.0, 0.0, dict(suffixes=("_x", None)), ["0.0_x", 0.0]),
2008-
("b", "b", dict(suffixes=(None, "_y")), ["b", "b_y"]),
2009-
("a", "a", dict(suffixes=("_x", None)), ["a_x", "a"]),
2010-
("a", "b", dict(suffixes=("_x", None)), ["a", "b"]),
2011-
("a", "a", dict(suffixes=(None, "_x")), ["a", "a_x"]),
2012-
(0, 0, dict(suffixes=("_a", None)), ["0_a", 0]),
2013-
("a", "a", dict(), ["a_x", "a_y"]),
2014-
(0, 0, dict(), ["0_x", "0_y"]),
2002+
(0, 0, {'suffixes':("", "_dup")}, ["0", "0_dup"]),
2003+
(0, 0, {'suffixes':(None, "_dup")}, [0, "0_dup"]),
2004+
(0, 0, {'suffixes':("_x", "_y")}, ["0_x", "0_y"]),
2005+
(0, 0, {'suffixes':["_x", "_y"]}, ["0_x", "0_y"]),
2006+
("a", 0, {'suffixes':(None, "_y")}, ["a", 0]),
2007+
(0.0, 0.0, {'suffixes':("_x", None)}, ["0.0_x", 0.0]),
2008+
("b", "b", {'suffixes':(None, "_y")}, ["b", "b_y"]),
2009+
("a", "a", {'suffixes':("_x", None)}, ["a_x", "a"]),
2010+
("a", "b", {'suffixes':("_x", None)}, ["a", "b"]),
2011+
("a", "a", {'suffixes':(None, "_x")}, ["a", "a_x"]),
2012+
(0, 0, {'suffixes':("_a", None)}, ["0_a", 0]),
2013+
("a", "a", {}, ["a_x", "a_y"]),
2014+
(0, 0, {}, ["0_x", "0_y"]),
20152015
],
20162016
)
20172017
def test_merge_suffix(col1, col2, kwargs, expected_cols):

pandas/tests/reshape/merge/test_multi.py

Lines changed: 58 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -36,27 +36,27 @@ def right():
3636
@pytest.fixture
3737
def left_multi():
3838
return DataFrame(
39-
dict(
40-
Origin=["A", "A", "B", "B", "C"],
41-
Destination=["A", "B", "A", "C", "A"],
42-
Period=["AM", "AM", "IP", "AM", "OP"],
43-
TripPurp=["hbw", "nhb", "hbo", "nhb", "hbw"],
44-
Trips=[1987, 3647, 2470, 4296, 4444],
45-
),
39+
{
40+
'Origin':["A", "A", "B", "B", "C"],
41+
'Destination':["A", "B", "A", "C", "A"],
42+
'Period':["AM", "AM", "IP", "AM", "OP"],
43+
'TripPurp':["hbw", "nhb", "hbo", "nhb", "hbw"],
44+
'Trips':[1987, 3647, 2470, 4296, 4444],
45+
},
4646
columns=["Origin", "Destination", "Period", "TripPurp", "Trips"],
4747
).set_index(["Origin", "Destination", "Period", "TripPurp"])
4848

4949

5050
@pytest.fixture
5151
def right_multi():
5252
return DataFrame(
53-
dict(
54-
Origin=["A", "A", "B", "B", "C", "C", "E"],
55-
Destination=["A", "B", "A", "B", "A", "B", "F"],
56-
Period=["AM", "AM", "IP", "AM", "OP", "IP", "AM"],
57-
LinkType=["a", "b", "c", "b", "a", "b", "a"],
58-
Distance=[100, 80, 90, 80, 75, 35, 55],
59-
),
53+
{
54+
'Origin':["A", "A", "B", "B", "C", "C", "E"],
55+
'Destination':["A", "B", "A", "B", "A", "B", "F"],
56+
'Period':["AM", "AM", "IP", "AM", "OP", "IP", "AM"],
57+
'LinkType':["a", "b", "c", "b", "a", "b", "a"],
58+
'Distance':[100, 80, 90, 80, 75, 35, 55],
59+
},
6060
columns=["Origin", "Destination", "Period", "LinkType", "Distance"],
6161
).set_index(["Origin", "Destination", "Period", "LinkType"])
6262

@@ -533,17 +533,17 @@ def test_join_multi_levels(self):
533533
# GH 3662
534534
# merge multi-levels
535535
household = DataFrame(
536-
dict(
537-
household_id=[1, 2, 3],
538-
male=[0, 1, 0],
539-
wealth=[196087.3, 316478.7, 294750],
540-
),
536+
{
537+
'household_id':[1, 2, 3],
538+
'male':[0, 1, 0],
539+
'wealth':[196087.3, 316478.7, 294750],
540+
},
541541
columns=["household_id", "male", "wealth"],
542542
).set_index("household_id")
543543
portfolio = DataFrame(
544-
dict(
545-
household_id=[1, 2, 2, 3, 3, 3, 4],
546-
asset_id=[
544+
{
545+
'household_id':[1, 2, 2, 3, 3, 3, 4],
546+
'asset_id':[
547547
"nl0000301109",
548548
"nl0000289783",
549549
"gb00b03mlx29",
@@ -552,7 +552,7 @@ def test_join_multi_levels(self):
552552
"nl0000289965",
553553
np.nan,
554554
],
555-
name=[
555+
'name':[
556556
"ABN Amro",
557557
"Robeco",
558558
"Royal Dutch Shell",
@@ -561,35 +561,35 @@ def test_join_multi_levels(self):
561561
"Postbank BioTech Fonds",
562562
np.nan,
563563
],
564-
share=[1.0, 0.4, 0.6, 0.15, 0.6, 0.25, 1.0],
565-
),
564+
'share':[1.0, 0.4, 0.6, 0.15, 0.6, 0.25, 1.0],
565+
},
566566
columns=["household_id", "asset_id", "name", "share"],
567567
).set_index(["household_id", "asset_id"])
568568
result = household.join(portfolio, how="inner")
569569
expected = (
570570
DataFrame(
571-
dict(
572-
male=[0, 1, 1, 0, 0, 0],
573-
wealth=[196087.3, 316478.7, 316478.7, 294750.0, 294750.0, 294750.0],
574-
name=[
571+
{
572+
'male':[0, 1, 1, 0, 0, 0],
573+
'wealth':[196087.3, 316478.7, 316478.7, 294750.0, 294750.0, 294750.0],
574+
'name':[
575575
"ABN Amro",
576576
"Robeco",
577577
"Royal Dutch Shell",
578578
"Royal Dutch Shell",
579579
"AAB Eastern Europe Equity Fund",
580580
"Postbank BioTech Fonds",
581581
],
582-
share=[1.00, 0.40, 0.60, 0.15, 0.60, 0.25],
583-
household_id=[1, 2, 2, 3, 3, 3],
584-
asset_id=[
582+
'share':[1.00, 0.40, 0.60, 0.15, 0.60, 0.25],
583+
'household_id':[1, 2, 2, 3, 3, 3],
584+
'asset_id':[
585585
"nl0000301109",
586586
"nl0000289783",
587587
"gb00b03mlx29",
588588
"gb00b03mlx29",
589589
"lu0197800237",
590590
"nl0000289965",
591591
],
592-
)
592+
}
593593
)
594594
.set_index(["household_id", "asset_id"])
595595
.reindex(columns=["male", "wealth", "name", "share"])
@@ -611,7 +611,7 @@ def test_join_multi_levels(self):
611611
expected,
612612
(
613613
DataFrame(
614-
dict(share=[1.00]),
614+
{'share':[1.00]},
615615
index=MultiIndex.from_tuples(
616616
[(4, np.nan)], names=["household_id", "asset_id"]
617617
),
@@ -642,9 +642,9 @@ def test_join_multi_levels2(self):
642642
# some more advanced merges
643643
# GH6360
644644
household = DataFrame(
645-
dict(
646-
household_id=[1, 2, 2, 3, 3, 3, 4],
647-
asset_id=[
645+
{
646+
'household_id':[1, 2, 2, 3, 3, 3, 4],
647+
'asset_id':[
648648
"nl0000301109",
649649
"nl0000301109",
650650
"gb00b03mlx29",
@@ -653,30 +653,30 @@ def test_join_multi_levels2(self):
653653
"nl0000289965",
654654
np.nan,
655655
],
656-
share=[1.0, 0.4, 0.6, 0.15, 0.6, 0.25, 1.0],
657-
),
656+
'share':[1.0, 0.4, 0.6, 0.15, 0.6, 0.25, 1.0],
657+
},
658658
columns=["household_id", "asset_id", "share"],
659659
).set_index(["household_id", "asset_id"])
660660

661661
log_return = DataFrame(
662-
dict(
663-
asset_id=[
662+
{
663+
'asset_id':[
664664
"gb00b03mlx29",
665665
"gb00b03mlx29",
666666
"gb00b03mlx29",
667667
"lu0197800237",
668668
"lu0197800237",
669669
],
670-
t=[233, 234, 235, 180, 181],
671-
log_return=[0.09604978, -0.06524096, 0.03532373, 0.03025441, 0.036997],
672-
)
670+
't':[233, 234, 235, 180, 181],
671+
'log_return':[0.09604978, -0.06524096, 0.03532373, 0.03025441, 0.036997],
672+
}
673673
).set_index(["asset_id", "t"])
674674

675675
expected = (
676676
DataFrame(
677-
dict(
678-
household_id=[2, 2, 2, 3, 3, 3, 3, 3],
679-
asset_id=[
677+
{
678+
'household_id':[2, 2, 2, 3, 3, 3, 3, 3],
679+
'asset_id':[
680680
"gb00b03mlx29",
681681
"gb00b03mlx29",
682682
"gb00b03mlx29",
@@ -686,9 +686,9 @@ def test_join_multi_levels2(self):
686686
"lu0197800237",
687687
"lu0197800237",
688688
],
689-
t=[233, 234, 235, 233, 234, 235, 180, 181],
690-
share=[0.6, 0.6, 0.6, 0.15, 0.15, 0.15, 0.6, 0.6],
691-
log_return=[
689+
't':[233, 234, 235, 233, 234, 235, 180, 181],
690+
'share':[0.6, 0.6, 0.6, 0.15, 0.15, 0.15, 0.6, 0.6],
691+
'log_return':[
692692
0.09604978,
693693
-0.06524096,
694694
0.03532373,
@@ -698,7 +698,7 @@ def test_join_multi_levels2(self):
698698
0.03025441,
699699
0.036997,
700700
],
701-
)
701+
}
702702
)
703703
.set_index(["household_id", "asset_id", "t"])
704704
.reindex(columns=["share", "log_return"])
@@ -715,9 +715,9 @@ def test_join_multi_levels2(self):
715715

716716
expected = (
717717
DataFrame(
718-
dict(
719-
household_id=[1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4],
720-
asset_id=[
718+
{
719+
'household_id':[1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4],
720+
'asset_id':[
721721
"nl0000301109",
722722
"nl0000301109",
723723
"gb00b03mlx29",
@@ -731,8 +731,8 @@ def test_join_multi_levels2(self):
731731
"nl0000289965",
732732
None,
733733
],
734-
t=[None, None, 233, 234, 235, 233, 234, 235, 180, 181, None, None],
735-
share=[
734+
't':[None, None, 233, 234, 235, 233, 234, 235, 180, 181, None, None],
735+
'share':[
736736
1.0,
737737
0.4,
738738
0.6,
@@ -746,7 +746,7 @@ def test_join_multi_levels2(self):
746746
0.25,
747747
1.0,
748748
],
749-
log_return=[
749+
'log_return':[
750750
None,
751751
None,
752752
0.09604978,
@@ -760,7 +760,7 @@ def test_join_multi_levels2(self):
760760
None,
761761
None,
762762
],
763-
)
763+
}
764764
)
765765
.set_index(["household_id", "asset_id", "t"])
766766
.reindex(columns=["share", "log_return"])

0 commit comments

Comments
 (0)