From 9f3b88e5bd5ab92de897cba6cccca73d3c6d0902 Mon Sep 17 00:00:00 2001 From: Rahul Sathanapalli Date: Mon, 30 Nov 2020 15:13:18 +0530 Subject: [PATCH 1/2] Rewrite dict literal for files in tests/reshape/ --- pandas/tests/reshape/concat/test_datetimes.py | 20 +-- pandas/tests/reshape/merge/test_merge.py | 50 ++++---- pandas/tests/reshape/merge/test_multi.py | 116 +++++++++--------- 3 files changed, 93 insertions(+), 93 deletions(-) diff --git a/pandas/tests/reshape/concat/test_datetimes.py b/pandas/tests/reshape/concat/test_datetimes.py index a4d6b58307523..96e8e4da89ff2 100644 --- a/pandas/tests/reshape/concat/test_datetimes.py +++ b/pandas/tests/reshape/concat/test_datetimes.py @@ -373,10 +373,10 @@ def test_concat_tz_series_with_datetimelike(self): def test_concat_tz_frame(self): df2 = DataFrame( - dict( - A=Timestamp("20130102", tz="US/Eastern"), - B=Timestamp("20130603", tz="CET"), - ), + { + 'A':Timestamp("20130102", tz="US/Eastern"), + 'B':Timestamp("20130603", tz="CET"), + }, index=range(5), ) @@ -391,20 +391,20 @@ def test_concat_multiple_tzs(self): ts2 = Timestamp("2015-01-01", tz="UTC") ts3 = Timestamp("2015-01-01", tz="EST") - df1 = DataFrame(dict(time=[ts1])) - df2 = DataFrame(dict(time=[ts2])) - df3 = DataFrame(dict(time=[ts3])) + df1 = DataFrame({'time':[ts1]}) + df2 = DataFrame({'time':[ts2]}) + df3 = DataFrame({'time':[ts3]}) results = pd.concat([df1, df2]).reset_index(drop=True) - expected = DataFrame(dict(time=[ts1, ts2]), dtype=object) + expected = DataFrame({'time':[ts1, ts2]}, dtype=object) tm.assert_frame_equal(results, expected) results = pd.concat([df1, df3]).reset_index(drop=True) - expected = DataFrame(dict(time=[ts1, ts3]), dtype=object) + expected = DataFrame({'time':[ts1, ts3]}, dtype=object) tm.assert_frame_equal(results, expected) results = pd.concat([df2, df3]).reset_index(drop=True) - expected = DataFrame(dict(time=[ts2, ts3])) + expected = DataFrame({'time':[ts2, ts3]}) tm.assert_frame_equal(results, expected) def test_concat_multiindex_with_tz(self): diff --git a/pandas/tests/reshape/merge/test_merge.py b/pandas/tests/reshape/merge/test_merge.py index 40ba62a27aa68..43eb21477545a 100644 --- a/pandas/tests/reshape/merge/test_merge.py +++ b/pandas/tests/reshape/merge/test_merge.py @@ -422,10 +422,10 @@ def test_left_merge_empty_dataframe(self): @pytest.mark.parametrize( "kwarg", [ - dict(left_index=True, right_index=True), - dict(left_index=True, right_on="x"), - dict(left_on="a", right_index=True), - dict(left_on="a", right_on="x"), + {'left_index':True, 'right_index':True}, + {'left_index':True, 'right_on':"x"}, + {'left_on':"a", 'right_index':True}, + {'left_on':"a", 'right_on':"x"}, ], ) def test_merge_left_empty_right_empty(self, join_type, kwarg): @@ -475,18 +475,18 @@ def check2(exp, kwarg): tm.assert_frame_equal(result, exp) for kwarg in [ - dict(left_index=True, right_index=True), - dict(left_index=True, right_on="x"), + {'left_index':True, 'right_index':True}, + {'left_index':True, 'right_on':"x"}, ]: check1(exp_in, kwarg) check2(exp_out, kwarg) - kwarg = dict(left_on="a", right_index=True) + kwarg = {'left_on':"a", 'right_index':True} check1(exp_in, kwarg) exp_out["a"] = [0, 1, 2] check2(exp_out, kwarg) - kwarg = dict(left_on="a", right_on="x") + kwarg = {'left_on':"a", 'right_on':"x"} check1(exp_in, kwarg) exp_out["a"] = np.array([np.nan] * 3, dtype=object) check2(exp_out, kwarg) @@ -524,10 +524,10 @@ def check2(exp, kwarg): tm.assert_frame_equal(result, exp) for kwarg in [ - dict(left_index=True, right_index=True), - dict(left_index=True, right_on="x"), - dict(left_on="a", right_index=True), - dict(left_on="a", right_on="x"), + {'left_index':True, 'right_index':True}, + {'left_index':True, 'right_on':"x"}, + {'left_on':"a", 'right_index':True}, + {'left_on':"a", 'right_on':"x"}, ]: check1(exp_in, kwarg) check2(exp_out, kwarg) @@ -1999,19 +1999,19 @@ def test_merge_series(on, left_on, right_on, left_index, right_index, nm): @pytest.mark.parametrize( "col1, col2, kwargs, expected_cols", [ - (0, 0, dict(suffixes=("", "_dup")), ["0", "0_dup"]), - (0, 0, dict(suffixes=(None, "_dup")), [0, "0_dup"]), - (0, 0, dict(suffixes=("_x", "_y")), ["0_x", "0_y"]), - (0, 0, dict(suffixes=["_x", "_y"]), ["0_x", "0_y"]), - ("a", 0, dict(suffixes=(None, "_y")), ["a", 0]), - (0.0, 0.0, dict(suffixes=("_x", None)), ["0.0_x", 0.0]), - ("b", "b", dict(suffixes=(None, "_y")), ["b", "b_y"]), - ("a", "a", dict(suffixes=("_x", None)), ["a_x", "a"]), - ("a", "b", dict(suffixes=("_x", None)), ["a", "b"]), - ("a", "a", dict(suffixes=(None, "_x")), ["a", "a_x"]), - (0, 0, dict(suffixes=("_a", None)), ["0_a", 0]), - ("a", "a", dict(), ["a_x", "a_y"]), - (0, 0, dict(), ["0_x", "0_y"]), + (0, 0, {'suffixes':("", "_dup")}, ["0", "0_dup"]), + (0, 0, {'suffixes':(None, "_dup")}, [0, "0_dup"]), + (0, 0, {'suffixes':("_x", "_y")}, ["0_x", "0_y"]), + (0, 0, {'suffixes':["_x", "_y"]}, ["0_x", "0_y"]), + ("a", 0, {'suffixes':(None, "_y")}, ["a", 0]), + (0.0, 0.0, {'suffixes':("_x", None)}, ["0.0_x", 0.0]), + ("b", "b", {'suffixes':(None, "_y")}, ["b", "b_y"]), + ("a", "a", {'suffixes':("_x", None)}, ["a_x", "a"]), + ("a", "b", {'suffixes':("_x", None)}, ["a", "b"]), + ("a", "a", {'suffixes':(None, "_x")}, ["a", "a_x"]), + (0, 0, {'suffixes':("_a", None)}, ["0_a", 0]), + ("a", "a", {}, ["a_x", "a_y"]), + (0, 0, {}, ["0_x", "0_y"]), ], ) def test_merge_suffix(col1, col2, kwargs, expected_cols): diff --git a/pandas/tests/reshape/merge/test_multi.py b/pandas/tests/reshape/merge/test_multi.py index 260a0e9d486b2..b615d3ce10905 100644 --- a/pandas/tests/reshape/merge/test_multi.py +++ b/pandas/tests/reshape/merge/test_multi.py @@ -36,13 +36,13 @@ def right(): @pytest.fixture def left_multi(): return DataFrame( - dict( - Origin=["A", "A", "B", "B", "C"], - Destination=["A", "B", "A", "C", "A"], - Period=["AM", "AM", "IP", "AM", "OP"], - TripPurp=["hbw", "nhb", "hbo", "nhb", "hbw"], - Trips=[1987, 3647, 2470, 4296, 4444], - ), + { + 'Origin':["A", "A", "B", "B", "C"], + 'Destination':["A", "B", "A", "C", "A"], + 'Period':["AM", "AM", "IP", "AM", "OP"], + 'TripPurp':["hbw", "nhb", "hbo", "nhb", "hbw"], + 'Trips':[1987, 3647, 2470, 4296, 4444], + }, columns=["Origin", "Destination", "Period", "TripPurp", "Trips"], ).set_index(["Origin", "Destination", "Period", "TripPurp"]) @@ -50,13 +50,13 @@ def left_multi(): @pytest.fixture def right_multi(): return DataFrame( - dict( - Origin=["A", "A", "B", "B", "C", "C", "E"], - Destination=["A", "B", "A", "B", "A", "B", "F"], - Period=["AM", "AM", "IP", "AM", "OP", "IP", "AM"], - LinkType=["a", "b", "c", "b", "a", "b", "a"], - Distance=[100, 80, 90, 80, 75, 35, 55], - ), + { + 'Origin':["A", "A", "B", "B", "C", "C", "E"], + 'Destination':["A", "B", "A", "B", "A", "B", "F"], + 'Period':["AM", "AM", "IP", "AM", "OP", "IP", "AM"], + 'LinkType':["a", "b", "c", "b", "a", "b", "a"], + 'Distance':[100, 80, 90, 80, 75, 35, 55], + }, columns=["Origin", "Destination", "Period", "LinkType", "Distance"], ).set_index(["Origin", "Destination", "Period", "LinkType"]) @@ -533,17 +533,17 @@ def test_join_multi_levels(self): # GH 3662 # merge multi-levels household = DataFrame( - dict( - household_id=[1, 2, 3], - male=[0, 1, 0], - wealth=[196087.3, 316478.7, 294750], - ), + { + 'household_id':[1, 2, 3], + 'male':[0, 1, 0], + 'wealth':[196087.3, 316478.7, 294750], + }, columns=["household_id", "male", "wealth"], ).set_index("household_id") portfolio = DataFrame( - dict( - household_id=[1, 2, 2, 3, 3, 3, 4], - asset_id=[ + { + 'household_id':[1, 2, 2, 3, 3, 3, 4], + 'asset_id':[ "nl0000301109", "nl0000289783", "gb00b03mlx29", @@ -552,7 +552,7 @@ def test_join_multi_levels(self): "nl0000289965", np.nan, ], - name=[ + 'name':[ "ABN Amro", "Robeco", "Royal Dutch Shell", @@ -561,17 +561,17 @@ def test_join_multi_levels(self): "Postbank BioTech Fonds", np.nan, ], - share=[1.0, 0.4, 0.6, 0.15, 0.6, 0.25, 1.0], - ), + 'share':[1.0, 0.4, 0.6, 0.15, 0.6, 0.25, 1.0], + }, columns=["household_id", "asset_id", "name", "share"], ).set_index(["household_id", "asset_id"]) result = household.join(portfolio, how="inner") expected = ( DataFrame( - dict( - male=[0, 1, 1, 0, 0, 0], - wealth=[196087.3, 316478.7, 316478.7, 294750.0, 294750.0, 294750.0], - name=[ + { + 'male':[0, 1, 1, 0, 0, 0], + 'wealth':[196087.3, 316478.7, 316478.7, 294750.0, 294750.0, 294750.0], + 'name':[ "ABN Amro", "Robeco", "Royal Dutch Shell", @@ -579,9 +579,9 @@ def test_join_multi_levels(self): "AAB Eastern Europe Equity Fund", "Postbank BioTech Fonds", ], - share=[1.00, 0.40, 0.60, 0.15, 0.60, 0.25], - household_id=[1, 2, 2, 3, 3, 3], - asset_id=[ + 'share':[1.00, 0.40, 0.60, 0.15, 0.60, 0.25], + 'household_id':[1, 2, 2, 3, 3, 3], + 'asset_id':[ "nl0000301109", "nl0000289783", "gb00b03mlx29", @@ -589,7 +589,7 @@ def test_join_multi_levels(self): "lu0197800237", "nl0000289965", ], - ) + } ) .set_index(["household_id", "asset_id"]) .reindex(columns=["male", "wealth", "name", "share"]) @@ -611,7 +611,7 @@ def test_join_multi_levels(self): expected, ( DataFrame( - dict(share=[1.00]), + {'share':[1.00]}, index=MultiIndex.from_tuples( [(4, np.nan)], names=["household_id", "asset_id"] ), @@ -642,9 +642,9 @@ def test_join_multi_levels2(self): # some more advanced merges # GH6360 household = DataFrame( - dict( - household_id=[1, 2, 2, 3, 3, 3, 4], - asset_id=[ + { + 'household_id':[1, 2, 2, 3, 3, 3, 4], + 'asset_id':[ "nl0000301109", "nl0000301109", "gb00b03mlx29", @@ -653,30 +653,30 @@ def test_join_multi_levels2(self): "nl0000289965", np.nan, ], - share=[1.0, 0.4, 0.6, 0.15, 0.6, 0.25, 1.0], - ), + 'share':[1.0, 0.4, 0.6, 0.15, 0.6, 0.25, 1.0], + }, columns=["household_id", "asset_id", "share"], ).set_index(["household_id", "asset_id"]) log_return = DataFrame( - dict( - asset_id=[ + { + 'asset_id':[ "gb00b03mlx29", "gb00b03mlx29", "gb00b03mlx29", "lu0197800237", "lu0197800237", ], - t=[233, 234, 235, 180, 181], - log_return=[0.09604978, -0.06524096, 0.03532373, 0.03025441, 0.036997], - ) + 't':[233, 234, 235, 180, 181], + 'log_return':[0.09604978, -0.06524096, 0.03532373, 0.03025441, 0.036997], + } ).set_index(["asset_id", "t"]) expected = ( DataFrame( - dict( - household_id=[2, 2, 2, 3, 3, 3, 3, 3], - asset_id=[ + { + 'household_id':[2, 2, 2, 3, 3, 3, 3, 3], + 'asset_id':[ "gb00b03mlx29", "gb00b03mlx29", "gb00b03mlx29", @@ -686,9 +686,9 @@ def test_join_multi_levels2(self): "lu0197800237", "lu0197800237", ], - t=[233, 234, 235, 233, 234, 235, 180, 181], - share=[0.6, 0.6, 0.6, 0.15, 0.15, 0.15, 0.6, 0.6], - log_return=[ + 't':[233, 234, 235, 233, 234, 235, 180, 181], + 'share':[0.6, 0.6, 0.6, 0.15, 0.15, 0.15, 0.6, 0.6], + 'log_return':[ 0.09604978, -0.06524096, 0.03532373, @@ -698,7 +698,7 @@ def test_join_multi_levels2(self): 0.03025441, 0.036997, ], - ) + } ) .set_index(["household_id", "asset_id", "t"]) .reindex(columns=["share", "log_return"]) @@ -715,9 +715,9 @@ def test_join_multi_levels2(self): expected = ( DataFrame( - dict( - household_id=[1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4], - asset_id=[ + { + 'household_id':[1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4], + 'asset_id':[ "nl0000301109", "nl0000301109", "gb00b03mlx29", @@ -731,8 +731,8 @@ def test_join_multi_levels2(self): "nl0000289965", None, ], - t=[None, None, 233, 234, 235, 233, 234, 235, 180, 181, None, None], - share=[ + 't':[None, None, 233, 234, 235, 233, 234, 235, 180, 181, None, None], + 'share':[ 1.0, 0.4, 0.6, @@ -746,7 +746,7 @@ def test_join_multi_levels2(self): 0.25, 1.0, ], - log_return=[ + 'log_return':[ None, None, 0.09604978, @@ -760,7 +760,7 @@ def test_join_multi_levels2(self): None, None, ], - ) + } ) .set_index(["household_id", "asset_id", "t"]) .reindex(columns=["share", "log_return"]) From f1d1e207c2b2fecc491bb20181f3d88cb1e34a94 Mon Sep 17 00:00:00 2001 From: Rahul Sathanapalli Date: Mon, 30 Nov 2020 15:15:31 +0530 Subject: [PATCH 2/2] Run black --- pandas/tests/reshape/concat/test_datetimes.py | 16 +-- pandas/tests/reshape/merge/test_merge.py | 46 ++++---- pandas/tests/reshape/merge/test_multi.py | 106 +++++++++++------- 3 files changed, 97 insertions(+), 71 deletions(-) diff --git a/pandas/tests/reshape/concat/test_datetimes.py b/pandas/tests/reshape/concat/test_datetimes.py index 96e8e4da89ff2..44a5e7f806309 100644 --- a/pandas/tests/reshape/concat/test_datetimes.py +++ b/pandas/tests/reshape/concat/test_datetimes.py @@ -374,8 +374,8 @@ def test_concat_tz_series_with_datetimelike(self): def test_concat_tz_frame(self): df2 = DataFrame( { - 'A':Timestamp("20130102", tz="US/Eastern"), - 'B':Timestamp("20130603", tz="CET"), + "A": Timestamp("20130102", tz="US/Eastern"), + "B": Timestamp("20130603", tz="CET"), }, index=range(5), ) @@ -391,20 +391,20 @@ def test_concat_multiple_tzs(self): ts2 = Timestamp("2015-01-01", tz="UTC") ts3 = Timestamp("2015-01-01", tz="EST") - df1 = DataFrame({'time':[ts1]}) - df2 = DataFrame({'time':[ts2]}) - df3 = DataFrame({'time':[ts3]}) + df1 = DataFrame({"time": [ts1]}) + df2 = DataFrame({"time": [ts2]}) + df3 = DataFrame({"time": [ts3]}) results = pd.concat([df1, df2]).reset_index(drop=True) - expected = DataFrame({'time':[ts1, ts2]}, dtype=object) + expected = DataFrame({"time": [ts1, ts2]}, dtype=object) tm.assert_frame_equal(results, expected) results = pd.concat([df1, df3]).reset_index(drop=True) - expected = DataFrame({'time':[ts1, ts3]}, dtype=object) + expected = DataFrame({"time": [ts1, ts3]}, dtype=object) tm.assert_frame_equal(results, expected) results = pd.concat([df2, df3]).reset_index(drop=True) - expected = DataFrame({'time':[ts2, ts3]}) + expected = DataFrame({"time": [ts2, ts3]}) tm.assert_frame_equal(results, expected) def test_concat_multiindex_with_tz(self): diff --git a/pandas/tests/reshape/merge/test_merge.py b/pandas/tests/reshape/merge/test_merge.py index 43eb21477545a..f43ae58fbcc2f 100644 --- a/pandas/tests/reshape/merge/test_merge.py +++ b/pandas/tests/reshape/merge/test_merge.py @@ -422,10 +422,10 @@ def test_left_merge_empty_dataframe(self): @pytest.mark.parametrize( "kwarg", [ - {'left_index':True, 'right_index':True}, - {'left_index':True, 'right_on':"x"}, - {'left_on':"a", 'right_index':True}, - {'left_on':"a", 'right_on':"x"}, + {"left_index": True, "right_index": True}, + {"left_index": True, "right_on": "x"}, + {"left_on": "a", "right_index": True}, + {"left_on": "a", "right_on": "x"}, ], ) def test_merge_left_empty_right_empty(self, join_type, kwarg): @@ -475,18 +475,18 @@ def check2(exp, kwarg): tm.assert_frame_equal(result, exp) for kwarg in [ - {'left_index':True, 'right_index':True}, - {'left_index':True, 'right_on':"x"}, + {"left_index": True, "right_index": True}, + {"left_index": True, "right_on": "x"}, ]: check1(exp_in, kwarg) check2(exp_out, kwarg) - kwarg = {'left_on':"a", 'right_index':True} + kwarg = {"left_on": "a", "right_index": True} check1(exp_in, kwarg) exp_out["a"] = [0, 1, 2] check2(exp_out, kwarg) - kwarg = {'left_on':"a", 'right_on':"x"} + kwarg = {"left_on": "a", "right_on": "x"} check1(exp_in, kwarg) exp_out["a"] = np.array([np.nan] * 3, dtype=object) check2(exp_out, kwarg) @@ -524,10 +524,10 @@ def check2(exp, kwarg): tm.assert_frame_equal(result, exp) for kwarg in [ - {'left_index':True, 'right_index':True}, - {'left_index':True, 'right_on':"x"}, - {'left_on':"a", 'right_index':True}, - {'left_on':"a", 'right_on':"x"}, + {"left_index": True, "right_index": True}, + {"left_index": True, "right_on": "x"}, + {"left_on": "a", "right_index": True}, + {"left_on": "a", "right_on": "x"}, ]: check1(exp_in, kwarg) check2(exp_out, kwarg) @@ -1999,17 +1999,17 @@ def test_merge_series(on, left_on, right_on, left_index, right_index, nm): @pytest.mark.parametrize( "col1, col2, kwargs, expected_cols", [ - (0, 0, {'suffixes':("", "_dup")}, ["0", "0_dup"]), - (0, 0, {'suffixes':(None, "_dup")}, [0, "0_dup"]), - (0, 0, {'suffixes':("_x", "_y")}, ["0_x", "0_y"]), - (0, 0, {'suffixes':["_x", "_y"]}, ["0_x", "0_y"]), - ("a", 0, {'suffixes':(None, "_y")}, ["a", 0]), - (0.0, 0.0, {'suffixes':("_x", None)}, ["0.0_x", 0.0]), - ("b", "b", {'suffixes':(None, "_y")}, ["b", "b_y"]), - ("a", "a", {'suffixes':("_x", None)}, ["a_x", "a"]), - ("a", "b", {'suffixes':("_x", None)}, ["a", "b"]), - ("a", "a", {'suffixes':(None, "_x")}, ["a", "a_x"]), - (0, 0, {'suffixes':("_a", None)}, ["0_a", 0]), + (0, 0, {"suffixes": ("", "_dup")}, ["0", "0_dup"]), + (0, 0, {"suffixes": (None, "_dup")}, [0, "0_dup"]), + (0, 0, {"suffixes": ("_x", "_y")}, ["0_x", "0_y"]), + (0, 0, {"suffixes": ["_x", "_y"]}, ["0_x", "0_y"]), + ("a", 0, {"suffixes": (None, "_y")}, ["a", 0]), + (0.0, 0.0, {"suffixes": ("_x", None)}, ["0.0_x", 0.0]), + ("b", "b", {"suffixes": (None, "_y")}, ["b", "b_y"]), + ("a", "a", {"suffixes": ("_x", None)}, ["a_x", "a"]), + ("a", "b", {"suffixes": ("_x", None)}, ["a", "b"]), + ("a", "a", {"suffixes": (None, "_x")}, ["a", "a_x"]), + (0, 0, {"suffixes": ("_a", None)}, ["0_a", 0]), ("a", "a", {}, ["a_x", "a_y"]), (0, 0, {}, ["0_x", "0_y"]), ], diff --git a/pandas/tests/reshape/merge/test_multi.py b/pandas/tests/reshape/merge/test_multi.py index b615d3ce10905..673c97740594f 100644 --- a/pandas/tests/reshape/merge/test_multi.py +++ b/pandas/tests/reshape/merge/test_multi.py @@ -37,11 +37,11 @@ def right(): def left_multi(): return DataFrame( { - 'Origin':["A", "A", "B", "B", "C"], - 'Destination':["A", "B", "A", "C", "A"], - 'Period':["AM", "AM", "IP", "AM", "OP"], - 'TripPurp':["hbw", "nhb", "hbo", "nhb", "hbw"], - 'Trips':[1987, 3647, 2470, 4296, 4444], + "Origin": ["A", "A", "B", "B", "C"], + "Destination": ["A", "B", "A", "C", "A"], + "Period": ["AM", "AM", "IP", "AM", "OP"], + "TripPurp": ["hbw", "nhb", "hbo", "nhb", "hbw"], + "Trips": [1987, 3647, 2470, 4296, 4444], }, columns=["Origin", "Destination", "Period", "TripPurp", "Trips"], ).set_index(["Origin", "Destination", "Period", "TripPurp"]) @@ -51,11 +51,11 @@ def left_multi(): def right_multi(): return DataFrame( { - 'Origin':["A", "A", "B", "B", "C", "C", "E"], - 'Destination':["A", "B", "A", "B", "A", "B", "F"], - 'Period':["AM", "AM", "IP", "AM", "OP", "IP", "AM"], - 'LinkType':["a", "b", "c", "b", "a", "b", "a"], - 'Distance':[100, 80, 90, 80, 75, 35, 55], + "Origin": ["A", "A", "B", "B", "C", "C", "E"], + "Destination": ["A", "B", "A", "B", "A", "B", "F"], + "Period": ["AM", "AM", "IP", "AM", "OP", "IP", "AM"], + "LinkType": ["a", "b", "c", "b", "a", "b", "a"], + "Distance": [100, 80, 90, 80, 75, 35, 55], }, columns=["Origin", "Destination", "Period", "LinkType", "Distance"], ).set_index(["Origin", "Destination", "Period", "LinkType"]) @@ -534,16 +534,16 @@ def test_join_multi_levels(self): # merge multi-levels household = DataFrame( { - 'household_id':[1, 2, 3], - 'male':[0, 1, 0], - 'wealth':[196087.3, 316478.7, 294750], + "household_id": [1, 2, 3], + "male": [0, 1, 0], + "wealth": [196087.3, 316478.7, 294750], }, columns=["household_id", "male", "wealth"], ).set_index("household_id") portfolio = DataFrame( { - 'household_id':[1, 2, 2, 3, 3, 3, 4], - 'asset_id':[ + "household_id": [1, 2, 2, 3, 3, 3, 4], + "asset_id": [ "nl0000301109", "nl0000289783", "gb00b03mlx29", @@ -552,7 +552,7 @@ def test_join_multi_levels(self): "nl0000289965", np.nan, ], - 'name':[ + "name": [ "ABN Amro", "Robeco", "Royal Dutch Shell", @@ -561,7 +561,7 @@ def test_join_multi_levels(self): "Postbank BioTech Fonds", np.nan, ], - 'share':[1.0, 0.4, 0.6, 0.15, 0.6, 0.25, 1.0], + "share": [1.0, 0.4, 0.6, 0.15, 0.6, 0.25, 1.0], }, columns=["household_id", "asset_id", "name", "share"], ).set_index(["household_id", "asset_id"]) @@ -569,9 +569,16 @@ def test_join_multi_levels(self): expected = ( DataFrame( { - 'male':[0, 1, 1, 0, 0, 0], - 'wealth':[196087.3, 316478.7, 316478.7, 294750.0, 294750.0, 294750.0], - 'name':[ + "male": [0, 1, 1, 0, 0, 0], + "wealth": [ + 196087.3, + 316478.7, + 316478.7, + 294750.0, + 294750.0, + 294750.0, + ], + "name": [ "ABN Amro", "Robeco", "Royal Dutch Shell", @@ -579,9 +586,9 @@ def test_join_multi_levels(self): "AAB Eastern Europe Equity Fund", "Postbank BioTech Fonds", ], - 'share':[1.00, 0.40, 0.60, 0.15, 0.60, 0.25], - 'household_id':[1, 2, 2, 3, 3, 3], - 'asset_id':[ + "share": [1.00, 0.40, 0.60, 0.15, 0.60, 0.25], + "household_id": [1, 2, 2, 3, 3, 3], + "asset_id": [ "nl0000301109", "nl0000289783", "gb00b03mlx29", @@ -611,7 +618,7 @@ def test_join_multi_levels(self): expected, ( DataFrame( - {'share':[1.00]}, + {"share": [1.00]}, index=MultiIndex.from_tuples( [(4, np.nan)], names=["household_id", "asset_id"] ), @@ -643,8 +650,8 @@ def test_join_multi_levels2(self): # GH6360 household = DataFrame( { - 'household_id':[1, 2, 2, 3, 3, 3, 4], - 'asset_id':[ + "household_id": [1, 2, 2, 3, 3, 3, 4], + "asset_id": [ "nl0000301109", "nl0000301109", "gb00b03mlx29", @@ -653,30 +660,36 @@ def test_join_multi_levels2(self): "nl0000289965", np.nan, ], - 'share':[1.0, 0.4, 0.6, 0.15, 0.6, 0.25, 1.0], + "share": [1.0, 0.4, 0.6, 0.15, 0.6, 0.25, 1.0], }, columns=["household_id", "asset_id", "share"], ).set_index(["household_id", "asset_id"]) log_return = DataFrame( { - 'asset_id':[ + "asset_id": [ "gb00b03mlx29", "gb00b03mlx29", "gb00b03mlx29", "lu0197800237", "lu0197800237", ], - 't':[233, 234, 235, 180, 181], - 'log_return':[0.09604978, -0.06524096, 0.03532373, 0.03025441, 0.036997], + "t": [233, 234, 235, 180, 181], + "log_return": [ + 0.09604978, + -0.06524096, + 0.03532373, + 0.03025441, + 0.036997, + ], } ).set_index(["asset_id", "t"]) expected = ( DataFrame( { - 'household_id':[2, 2, 2, 3, 3, 3, 3, 3], - 'asset_id':[ + "household_id": [2, 2, 2, 3, 3, 3, 3, 3], + "asset_id": [ "gb00b03mlx29", "gb00b03mlx29", "gb00b03mlx29", @@ -686,9 +699,9 @@ def test_join_multi_levels2(self): "lu0197800237", "lu0197800237", ], - 't':[233, 234, 235, 233, 234, 235, 180, 181], - 'share':[0.6, 0.6, 0.6, 0.15, 0.15, 0.15, 0.6, 0.6], - 'log_return':[ + "t": [233, 234, 235, 233, 234, 235, 180, 181], + "share": [0.6, 0.6, 0.6, 0.15, 0.15, 0.15, 0.6, 0.6], + "log_return": [ 0.09604978, -0.06524096, 0.03532373, @@ -716,8 +729,8 @@ def test_join_multi_levels2(self): expected = ( DataFrame( { - 'household_id':[1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4], - 'asset_id':[ + "household_id": [1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4], + "asset_id": [ "nl0000301109", "nl0000301109", "gb00b03mlx29", @@ -731,8 +744,21 @@ def test_join_multi_levels2(self): "nl0000289965", None, ], - 't':[None, None, 233, 234, 235, 233, 234, 235, 180, 181, None, None], - 'share':[ + "t": [ + None, + None, + 233, + 234, + 235, + 233, + 234, + 235, + 180, + 181, + None, + None, + ], + "share": [ 1.0, 0.4, 0.6, @@ -746,7 +772,7 @@ def test_join_multi_levels2(self): 0.25, 1.0, ], - 'log_return':[ + "log_return": [ None, None, 0.09604978,