From 6151e4ae0592961059a924f1b248d6db7867c8b5 Mon Sep 17 00:00:00 2001 From: Jonathan Shreckengost Date: Sat, 29 Aug 2020 00:36:25 -0400 Subject: [PATCH 1/4] Comma cleanup --- pandas/tests/frame/test_analytics.py | 20 ++++++------ pandas/tests/frame/test_constructors.py | 28 ++++++++--------- pandas/tests/frame/test_reshape.py | 32 ++++++++++---------- pandas/tests/generic/test_finalize.py | 12 ++++---- pandas/tests/groupby/aggregate/test_numba.py | 2 +- 5 files changed, 47 insertions(+), 47 deletions(-) diff --git a/pandas/tests/frame/test_analytics.py b/pandas/tests/frame/test_analytics.py index 52a1e3aae9058..90cccb41d8b47 100644 --- a/pandas/tests/frame/test_analytics.py +++ b/pandas/tests/frame/test_analytics.py @@ -406,7 +406,7 @@ def test_stat_operators_attempt_obj_array(self, method): 0.00031111847529610595, 0.0014902627951905339, -0.00094099200035979691, - ], + ] } df1 = DataFrame(data, index=["foo", "bar", "baz"], dtype="O") @@ -593,7 +593,7 @@ def test_kurt(self): "E": Categorical(["a"], categories=["a"]), "F": to_datetime(["2000-1-2"]), "G": to_timedelta(["1 days"]), - }, + } ), ( False, @@ -605,7 +605,7 @@ def test_kurt(self): "E": Categorical([np.nan], categories=["a"]), "F": [pd.NaT], "G": to_timedelta([pd.NaT]), - }, + } ), ( True, @@ -617,7 +617,7 @@ def test_kurt(self): "L": to_datetime(["2000-1-2", "NaT", "NaT", "NaT"]), "M": to_timedelta(["1 days", "nan", "nan", "nan"]), "N": [0, 1, 2, 3], - }, + } ), ( False, @@ -629,9 +629,9 @@ def test_kurt(self): "L": to_datetime(["NaT", "2000-1-2", "NaT", "NaT"]), "M": to_timedelta(["nan", "1 days", "nan", "nan"]), "N": [0, 1, 2, 3], - }, - ), - ], + } + ) + ] ) def test_mode_dropna(self, dropna, expected): @@ -1126,8 +1126,8 @@ def test_any_all_bool_only(self): True, # In 1.13.3 and 1.14 np.all(df) returns a Timedelta here marks=[td.skip_if_np_lt("1.15")], - ), - ], + ) + ] ) def test_any_all_np_func(self, func, data, expected): # GH 19976 @@ -1155,7 +1155,7 @@ def test_any_all_level_axis_none_raises(self, method): {"A": 1}, index=MultiIndex.from_product( [["A", "B"], ["a", "b"]], names=["out", "in"] - ), + ) ) xpr = "Must specify 'axis' when aggregating by level." with pytest.raises(ValueError, match=xpr): diff --git a/pandas/tests/frame/test_constructors.py b/pandas/tests/frame/test_constructors.py index c8f5b2b0f6364..d5ab7a8132395 100644 --- a/pandas/tests/frame/test_constructors.py +++ b/pandas/tests/frame/test_constructors.py @@ -79,7 +79,7 @@ def test_series_with_name_not_matching_column(self): lambda: DataFrame(data=[]), lambda: DataFrame(data=(_ for _ in [])), lambda: DataFrame(data=range(0)), - ], + ] ) def test_empty_constructor(self, constructor): expected = DataFrame() @@ -94,7 +94,7 @@ def test_empty_constructor(self, constructor): ([[]], RangeIndex(1), RangeIndex(0)), ([[], []], RangeIndex(2), RangeIndex(0)), ([(_ for _ in [])], RangeIndex(1), RangeIndex(0)), - ], + ] ) def test_emptylike_constructor(self, emptylike, expected_index, expected_columns): expected = DataFrame(index=expected_index, columns=expected_columns) @@ -276,7 +276,7 @@ def test_constructor_overflow_int64(self): np.array([-(2 ** 63) - 4], dtype=object), np.array([-(2 ** 64) - 1]), [-(2 ** 65) - 2], - ], + ] ) def test_constructor_int_overflow(self, values): # see gh-18584 @@ -725,8 +725,8 @@ def test_constructor_period_dict(self): ( Timestamp("2011-01-01", tz="US/Eastern"), DatetimeTZDtype(tz="US/Eastern"), - ), - ], + ) + ] ) def test_constructor_extension_scalar_data(self, data, dtype): # GH 34832 @@ -980,7 +980,7 @@ def test_constructor_corner_shape(self): (None, list(range(10)), ["a", "b"], int, np.dtype("float64")), ({}, None, ["foo", "bar"], None, np.object_), ({"b": 1}, list(range(10)), list("abc"), int, np.dtype("float64")), - ], + ] ) def test_constructor_dtype(self, data, index, columns, dtype, expected): df = DataFrame(data, index, columns, dtype) @@ -1390,7 +1390,7 @@ def test_constructor_mixed_type_rows(self): (([], []), [[], []]), (([1], [2]), [[1], [2]]), # GH 32776 (([1, 2, 3], [4, 5, 6]), [[1, 2, 3], [4, 5, 6]]), - ], + ] ) def test_constructor_tuple(self, tuples, lists): # GH 25691 @@ -1532,7 +1532,7 @@ def test_from_dict_columns_parameter(self): ([{("a",): 1}, {("a",): 2}], [("a",)], "columns"), ([OrderedDict([(("a",), 1), (("b",), 2)])], [("a",), ("b",)], "columns"), ([{("a", "b"): 1}], [("a", "b")], "columns"), - ], + ] ) def test_constructor_from_dict_tuples(self, data_dict, keys, orient): # GH 16769 @@ -1625,7 +1625,7 @@ def test_constructor_Series_differently_indexed(self): ("idx1", "idx1", "idx2", None), ("idx1", "idx2", "idx3", None), (None, None, None, None), - ], + ] ) def test_constructor_index_names(self, name_in1, name_in2, name_in3, name_out): # GH13475 @@ -1728,7 +1728,7 @@ def test_constructor_single_value(self): np.array([["a", "a"], ["a", "a"]], dtype=object), index=[1, 2], columns=["a", "c"], - ), + ) ) msg = "DataFrame constructor not properly called!" @@ -1891,7 +1891,7 @@ def test_constructor_with_datetimes(self): [[None], [pd.NaT]], [[pd.NaT], [np.datetime64("NaT")]], [[pd.NaT], [None]], - ], + ] ) def test_constructor_datetimes_with_nulls(self, arr): # gh-15869, GH#11220 @@ -2151,7 +2151,7 @@ def test_from_records_iterator(self): ("u", np.float32), ("y", np.int64), ("z", np.int32), - ], + ] ) df = DataFrame.from_records(iter(arr), nrows=2) xp = DataFrame( @@ -2598,7 +2598,7 @@ class List(list): SparseArray([1, np.nan, np.nan, np.nan]), IntervalArray([pd.Interval(0, 1), pd.Interval(1, 5)]), PeriodArray(pd.period_range(start="1/1/2017", end="1/1/2018", freq="M")), - ], + ] ) def test_constructor_with_extension_array(self, extension_arr): # GH11363 @@ -2772,7 +2772,7 @@ def test_from_tzaware_mixed_object_array(self): Timestamp("2013-01-01 00:00:00+0100", tz="CET"), pd.NaT, Timestamp("2013-01-03 00:00:00+0100", tz="CET"), - ], + ] ], dtype=object, ).T diff --git a/pandas/tests/frame/test_reshape.py b/pandas/tests/frame/test_reshape.py index 6a8f1e7c1aca2..40551ae21d0d7 100644 --- a/pandas/tests/frame/test_reshape.py +++ b/pandas/tests/frame/test_reshape.py @@ -384,7 +384,7 @@ def test_unstack_tuplename_in_multiindex(self): pd.MultiIndex.from_tuples( [("d", "a"), ("d", "b"), ("e", "a"), ("e", "b")], names=[None, ("A", "a")], - ), + ) ), ( (("A", "a"), "B"), @@ -402,9 +402,9 @@ def test_unstack_tuplename_in_multiindex(self): ("e", "b", 2), ], names=[None, ("A", "a"), "B"], - ), - ), - ], + ) + ) + ] ) def test_unstack_mixed_type_name_in_multiindex( self, unstack_idx, expected_values, expected_index, expected_columns @@ -650,7 +650,7 @@ def test_unstack_dtypes(self): [np.dtype("int64")] * 4, index=pd.MultiIndex.from_arrays( [["C", "C", "D", "D"], [1, 2, 1, 2]], names=(None, "B") - ), + ) ) tm.assert_series_equal(result, expected) @@ -663,7 +663,7 @@ def test_unstack_dtypes(self): [np.dtype("float64")] * 2 + [np.dtype("int64")] * 2, index=pd.MultiIndex.from_arrays( [["C", "C", "D", "D"], [1, 2, 1, 2]], names=(None, "B") - ), + ) ) tm.assert_series_equal(result, expected) df2["D"] = "foo" @@ -673,7 +673,7 @@ def test_unstack_dtypes(self): [np.dtype("float64")] * 2 + [np.dtype("object")] * 2, index=pd.MultiIndex.from_arrays( [["C", "C", "D", "D"], [1, 2, 1, 2]], names=(None, "B") - ), + ) ) tm.assert_series_equal(result, expected) @@ -786,7 +786,7 @@ def test_unstack_long_index(self): index=pd.MultiIndex.from_tuples( [[0, 0, 1, 0, 0, 0, 1]], names=["i1", "i2", "i3", "i4", "i5", "i6", "i7"], - ), + ) ) result = df.unstack(["i2", "i3", "i4", "i5", "i6", "i7"]) expected = pd.DataFrame( @@ -808,7 +808,7 @@ def test_unstack_multi_level_cols(self): ), index=pd.MultiIndex.from_tuples( [[10, 20, 30], [10, 20, 40]], names=["i1", "i2", "i3"], - ), + ) ) assert df.unstack(["i2", "i1"]).columns.names[-2:] == ["i2", "i1"] @@ -825,7 +825,7 @@ def test_unstack_multi_level_rows_and_cols(self): ["m2", "A5", 111], ], names=["i1", "i2", "i3"], - ), + ) ) result = df.unstack(["i3", "i2"]) expected = df.unstack(["i3"]).unstack(["i2"]) @@ -900,7 +900,7 @@ def verify(df): 53, 60, 51, - ], + ] } ) @@ -1155,7 +1155,7 @@ def test_stack_preserve_categorical_dtype_values(self): ([0, 0, 1, 1], pd.MultiIndex.from_product([[1, 2], ["a", "b"]])), ([0, 0, 2, 3], pd.MultiIndex.from_product([[1, 2], ["a", "b"]])), ([0, 1, 2, 3], pd.MultiIndex.from_product([[1, 2], ["a", "b"]])), - ], + ] ) def test_stack_multi_columns_non_unique_index(self, index, columns): # GH-28301 @@ -1203,7 +1203,7 @@ def test_unstack_swaplevel_sortlevel(self, level): [[3, 1, 2, 0]], columns=pd.MultiIndex.from_tuples( [("c", "A"), ("c", "B"), ("d", "A"), ("d", "B")], names=["baz", "foo"] - ), + ) ) expected.index.name = "bar" @@ -1252,7 +1252,7 @@ def test_unstack_timezone_aware_values(): levels=[["timestamp", "c"], ["b"]], codes=[[0, 1], [0, 0]], names=[None, "b"], - ), + ) ) tm.assert_frame_equal(result, expected) @@ -1268,7 +1268,7 @@ def test_stack_timezone_aware_values(): ts, index=pd.MultiIndex( levels=[["a", "b", "c"], ["A"]], codes=[[0, 1, 2], [0, 0, 0]] - ), + ) ) tm.assert_series_equal(result, expected) @@ -1299,6 +1299,6 @@ def test_unstacking_multi_index_df(): ("score", "male", True, 0), ], names=[None, "gender", "employed", "kids"], - ), + ) ) tm.assert_frame_equal(result, expected) diff --git a/pandas/tests/generic/test_finalize.py b/pandas/tests/generic/test_finalize.py index 4d0f1a326225d..7d9cf295ebc31 100644 --- a/pandas/tests/generic/test_finalize.py +++ b/pandas/tests/generic/test_finalize.py @@ -234,7 +234,7 @@ marks=[ not_implemented_mark, pytest.mark.filterwarnings("ignore::RuntimeWarning"), - ], + ] ), pytest.param( ( @@ -522,7 +522,7 @@ pytest.param( (pd.DataFrame, frame_data, operator.methodcaller("mean")), marks=not_implemented_mark, - ), + ) ] @@ -569,7 +569,7 @@ def test_finalize_called(ndframe_method): (pd.DataFrame({"A": [1]}), pd.DataFrame({"A": [1]})), (pd.Series([1]), pd.DataFrame({"A": [1]})), (pd.DataFrame({"A": [1]}), pd.Series([1])), - ], + ] ) def test_binops(args, annotate, all_arithmetic_functions): # This generates 326 tests... Is that needed? @@ -712,7 +712,7 @@ def test_datetime_method(method): "is_leap_year", "daysinmonth", "days_in_month", - ], + ] ) @not_implemented_mark def test_datetime_property(attr): @@ -756,7 +756,7 @@ def test_timedelta_methods(method): operator.methodcaller("rename_categories", {"a": "A", "b": "B"}), operator.methodcaller("reorder_categories", ["b", "a"]), operator.methodcaller("set_categories", ["A", "B"]), - ], + ] ) @not_implemented_mark def test_categorical_accessor(method): @@ -781,7 +781,7 @@ def test_categorical_accessor(method): lambda x: x.agg(["sum", "count"]), lambda x: x.transform(lambda y: y), lambda x: x.apply(lambda y: y), - ], + ] ) @not_implemented_mark def test_groupby(obj, method): diff --git a/pandas/tests/groupby/aggregate/test_numba.py b/pandas/tests/groupby/aggregate/test_numba.py index 29e65e938f6f9..af5089ae3ac21 100644 --- a/pandas/tests/groupby/aggregate/test_numba.py +++ b/pandas/tests/groupby/aggregate/test_numba.py @@ -138,7 +138,7 @@ def func_1(values, index): "min", {"B": ["min", "max"], "C": "sum"}, NamedAgg(column="B", aggfunc="min"), - ], + ] ) def test_multifunc_notimplimented(agg_func): data = DataFrame( From 99ffa1f7113f66c0a94fd57437f2eb7f093dac99 Mon Sep 17 00:00:00 2001 From: Jonathan Shreckengost Date: Sat, 29 Aug 2020 20:24:26 -0400 Subject: [PATCH 2/4] Comma cleanup attempt #2 --- pandas/tests/frame/test_analytics.py | 26 +++++++------ pandas/tests/frame/test_constructors.py | 32 ++++++++-------- pandas/tests/frame/test_reshape.py | 39 +++++++++++--------- pandas/tests/generic/test_finalize.py | 27 +++++++++----- pandas/tests/groupby/aggregate/test_numba.py | 14 ++++--- 5 files changed, 80 insertions(+), 58 deletions(-) diff --git a/pandas/tests/frame/test_analytics.py b/pandas/tests/frame/test_analytics.py index 90cccb41d8b47..9bfc7d593c702 100644 --- a/pandas/tests/frame/test_analytics.py +++ b/pandas/tests/frame/test_analytics.py @@ -116,7 +116,11 @@ def wrapper(x): if opname in ["sum", "prod"]: expected = frame.apply(skipna_wrapper, axis=1) tm.assert_series_equal( - result1, expected, check_dtype=False, rtol=rtol, atol=atol, + result1, + expected, + check_dtype=False, + rtol=rtol, + atol=atol, ) # check dtypes @@ -406,7 +410,7 @@ def test_stat_operators_attempt_obj_array(self, method): 0.00031111847529610595, 0.0014902627951905339, -0.00094099200035979691, - ] + ], } df1 = DataFrame(data, index=["foo", "bar", "baz"], dtype="O") @@ -593,7 +597,7 @@ def test_kurt(self): "E": Categorical(["a"], categories=["a"]), "F": to_datetime(["2000-1-2"]), "G": to_timedelta(["1 days"]), - } + }, ), ( False, @@ -605,7 +609,7 @@ def test_kurt(self): "E": Categorical([np.nan], categories=["a"]), "F": [pd.NaT], "G": to_timedelta([pd.NaT]), - } + }, ), ( True, @@ -617,7 +621,7 @@ def test_kurt(self): "L": to_datetime(["2000-1-2", "NaT", "NaT", "NaT"]), "M": to_timedelta(["1 days", "nan", "nan", "nan"]), "N": [0, 1, 2, 3], - } + }, ), ( False, @@ -629,9 +633,9 @@ def test_kurt(self): "L": to_datetime(["NaT", "2000-1-2", "NaT", "NaT"]), "M": to_timedelta(["nan", "1 days", "nan", "nan"]), "N": [0, 1, 2, 3], - } - ) - ] + }, + ), + ], ) def test_mode_dropna(self, dropna, expected): @@ -1126,8 +1130,8 @@ def test_any_all_bool_only(self): True, # In 1.13.3 and 1.14 np.all(df) returns a Timedelta here marks=[td.skip_if_np_lt("1.15")], - ) - ] + ), + ], ) def test_any_all_np_func(self, func, data, expected): # GH 19976 @@ -1155,7 +1159,7 @@ def test_any_all_level_axis_none_raises(self, method): {"A": 1}, index=MultiIndex.from_product( [["A", "B"], ["a", "b"]], names=["out", "in"] - ) + ), ) xpr = "Must specify 'axis' when aggregating by level." with pytest.raises(ValueError, match=xpr): diff --git a/pandas/tests/frame/test_constructors.py b/pandas/tests/frame/test_constructors.py index d5ab7a8132395..ad88ed5f90494 100644 --- a/pandas/tests/frame/test_constructors.py +++ b/pandas/tests/frame/test_constructors.py @@ -79,7 +79,7 @@ def test_series_with_name_not_matching_column(self): lambda: DataFrame(data=[]), lambda: DataFrame(data=(_ for _ in [])), lambda: DataFrame(data=range(0)), - ] + ], ) def test_empty_constructor(self, constructor): expected = DataFrame() @@ -94,7 +94,7 @@ def test_empty_constructor(self, constructor): ([[]], RangeIndex(1), RangeIndex(0)), ([[], []], RangeIndex(2), RangeIndex(0)), ([(_ for _ in [])], RangeIndex(1), RangeIndex(0)), - ] + ], ) def test_emptylike_constructor(self, emptylike, expected_index, expected_columns): expected = DataFrame(index=expected_index, columns=expected_columns) @@ -276,7 +276,7 @@ def test_constructor_overflow_int64(self): np.array([-(2 ** 63) - 4], dtype=object), np.array([-(2 ** 64) - 1]), [-(2 ** 65) - 2], - ] + ], ) def test_constructor_int_overflow(self, values): # see gh-18584 @@ -725,8 +725,8 @@ def test_constructor_period_dict(self): ( Timestamp("2011-01-01", tz="US/Eastern"), DatetimeTZDtype(tz="US/Eastern"), - ) - ] + ), + ], ) def test_constructor_extension_scalar_data(self, data, dtype): # GH 34832 @@ -932,7 +932,9 @@ def test_constructor_mrecarray(self): # from GH3479 assert_fr_equal = functools.partial( - tm.assert_frame_equal, check_index_type=True, check_column_type=True, + tm.assert_frame_equal, + check_index_type=True, + check_column_type=True, ) arrays = [ ("float", np.array([1.5, 2.0])), @@ -980,7 +982,7 @@ def test_constructor_corner_shape(self): (None, list(range(10)), ["a", "b"], int, np.dtype("float64")), ({}, None, ["foo", "bar"], None, np.object_), ({"b": 1}, list(range(10)), list("abc"), int, np.dtype("float64")), - ] + ], ) def test_constructor_dtype(self, data, index, columns, dtype, expected): df = DataFrame(data, index, columns, dtype) @@ -1390,7 +1392,7 @@ def test_constructor_mixed_type_rows(self): (([], []), [[], []]), (([1], [2]), [[1], [2]]), # GH 32776 (([1, 2, 3], [4, 5, 6]), [[1, 2, 3], [4, 5, 6]]), - ] + ], ) def test_constructor_tuple(self, tuples, lists): # GH 25691 @@ -1532,7 +1534,7 @@ def test_from_dict_columns_parameter(self): ([{("a",): 1}, {("a",): 2}], [("a",)], "columns"), ([OrderedDict([(("a",), 1), (("b",), 2)])], [("a",), ("b",)], "columns"), ([{("a", "b"): 1}], [("a", "b")], "columns"), - ] + ], ) def test_constructor_from_dict_tuples(self, data_dict, keys, orient): # GH 16769 @@ -1625,7 +1627,7 @@ def test_constructor_Series_differently_indexed(self): ("idx1", "idx1", "idx2", None), ("idx1", "idx2", "idx3", None), (None, None, None, None), - ] + ], ) def test_constructor_index_names(self, name_in1, name_in2, name_in3, name_out): # GH13475 @@ -1728,7 +1730,7 @@ def test_constructor_single_value(self): np.array([["a", "a"], ["a", "a"]], dtype=object), index=[1, 2], columns=["a", "c"], - ) + ), ) msg = "DataFrame constructor not properly called!" @@ -1891,7 +1893,7 @@ def test_constructor_with_datetimes(self): [[None], [pd.NaT]], [[pd.NaT], [np.datetime64("NaT")]], [[pd.NaT], [None]], - ] + ], ) def test_constructor_datetimes_with_nulls(self, arr): # gh-15869, GH#11220 @@ -2151,7 +2153,7 @@ def test_from_records_iterator(self): ("u", np.float32), ("y", np.int64), ("z", np.int32), - ] + ], ) df = DataFrame.from_records(iter(arr), nrows=2) xp = DataFrame( @@ -2598,7 +2600,7 @@ class List(list): SparseArray([1, np.nan, np.nan, np.nan]), IntervalArray([pd.Interval(0, 1), pd.Interval(1, 5)]), PeriodArray(pd.period_range(start="1/1/2017", end="1/1/2018", freq="M")), - ] + ], ) def test_constructor_with_extension_array(self, extension_arr): # GH11363 @@ -2772,7 +2774,7 @@ def test_from_tzaware_mixed_object_array(self): Timestamp("2013-01-01 00:00:00+0100", tz="CET"), pd.NaT, Timestamp("2013-01-03 00:00:00+0100", tz="CET"), - ] + ], ], dtype=object, ).T diff --git a/pandas/tests/frame/test_reshape.py b/pandas/tests/frame/test_reshape.py index 40551ae21d0d7..5dd5fe51d8dd8 100644 --- a/pandas/tests/frame/test_reshape.py +++ b/pandas/tests/frame/test_reshape.py @@ -384,7 +384,7 @@ def test_unstack_tuplename_in_multiindex(self): pd.MultiIndex.from_tuples( [("d", "a"), ("d", "b"), ("e", "a"), ("e", "b")], names=[None, ("A", "a")], - ) + ), ), ( (("A", "a"), "B"), @@ -402,9 +402,9 @@ def test_unstack_tuplename_in_multiindex(self): ("e", "b", 2), ], names=[None, ("A", "a"), "B"], - ) - ) - ] + ), + ), + ], ) def test_unstack_mixed_type_name_in_multiindex( self, unstack_idx, expected_values, expected_index, expected_columns @@ -417,7 +417,9 @@ def test_unstack_mixed_type_name_in_multiindex( result = df.unstack(unstack_idx) expected = pd.DataFrame( - expected_values, columns=expected_columns, index=expected_index, + expected_values, + columns=expected_columns, + index=expected_index, ) tm.assert_frame_equal(result, expected) @@ -650,7 +652,7 @@ def test_unstack_dtypes(self): [np.dtype("int64")] * 4, index=pd.MultiIndex.from_arrays( [["C", "C", "D", "D"], [1, 2, 1, 2]], names=(None, "B") - ) + ), ) tm.assert_series_equal(result, expected) @@ -663,7 +665,7 @@ def test_unstack_dtypes(self): [np.dtype("float64")] * 2 + [np.dtype("int64")] * 2, index=pd.MultiIndex.from_arrays( [["C", "C", "D", "D"], [1, 2, 1, 2]], names=(None, "B") - ) + ), ) tm.assert_series_equal(result, expected) df2["D"] = "foo" @@ -673,7 +675,7 @@ def test_unstack_dtypes(self): [np.dtype("float64")] * 2 + [np.dtype("object")] * 2, index=pd.MultiIndex.from_arrays( [["C", "C", "D", "D"], [1, 2, 1, 2]], names=(None, "B") - ) + ), ) tm.assert_series_equal(result, expected) @@ -786,7 +788,7 @@ def test_unstack_long_index(self): index=pd.MultiIndex.from_tuples( [[0, 0, 1, 0, 0, 0, 1]], names=["i1", "i2", "i3", "i4", "i5", "i6", "i7"], - ) + ), ) result = df.unstack(["i2", "i3", "i4", "i5", "i6", "i7"]) expected = pd.DataFrame( @@ -807,8 +809,9 @@ def test_unstack_multi_level_cols(self): [["B", "C"], ["B", "D"]], names=["c1", "c2"] ), index=pd.MultiIndex.from_tuples( - [[10, 20, 30], [10, 20, 40]], names=["i1", "i2", "i3"], - ) + [[10, 20, 30], [10, 20, 40]], + names=["i1", "i2", "i3"], + ), ) assert df.unstack(["i2", "i1"]).columns.names[-2:] == ["i2", "i1"] @@ -825,7 +828,7 @@ def test_unstack_multi_level_rows_and_cols(self): ["m2", "A5", 111], ], names=["i1", "i2", "i3"], - ) + ), ) result = df.unstack(["i3", "i2"]) expected = df.unstack(["i3"]).unstack(["i2"]) @@ -900,7 +903,7 @@ def verify(df): 53, 60, 51, - ] + ], } ) @@ -1155,7 +1158,7 @@ def test_stack_preserve_categorical_dtype_values(self): ([0, 0, 1, 1], pd.MultiIndex.from_product([[1, 2], ["a", "b"]])), ([0, 0, 2, 3], pd.MultiIndex.from_product([[1, 2], ["a", "b"]])), ([0, 1, 2, 3], pd.MultiIndex.from_product([[1, 2], ["a", "b"]])), - ] + ], ) def test_stack_multi_columns_non_unique_index(self, index, columns): # GH-28301 @@ -1203,7 +1206,7 @@ def test_unstack_swaplevel_sortlevel(self, level): [[3, 1, 2, 0]], columns=pd.MultiIndex.from_tuples( [("c", "A"), ("c", "B"), ("d", "A"), ("d", "B")], names=["baz", "foo"] - ) + ), ) expected.index.name = "bar" @@ -1252,7 +1255,7 @@ def test_unstack_timezone_aware_values(): levels=[["timestamp", "c"], ["b"]], codes=[[0, 1], [0, 0]], names=[None, "b"], - ) + ), ) tm.assert_frame_equal(result, expected) @@ -1268,7 +1271,7 @@ def test_stack_timezone_aware_values(): ts, index=pd.MultiIndex( levels=[["a", "b", "c"], ["A"]], codes=[[0, 1, 2], [0, 0, 0]] - ) + ), ) tm.assert_series_equal(result, expected) @@ -1299,6 +1302,6 @@ def test_unstacking_multi_index_df(): ("score", "male", True, 0), ], names=[None, "gender", "employed", "kids"], - ) + ), ) tm.assert_frame_equal(result, expected) diff --git a/pandas/tests/generic/test_finalize.py b/pandas/tests/generic/test_finalize.py index 7d9cf295ebc31..c534ecf24e189 100644 --- a/pandas/tests/generic/test_finalize.py +++ b/pandas/tests/generic/test_finalize.py @@ -123,7 +123,11 @@ (pd.DataFrame, frame_data, operator.methodcaller("sort_index")), (pd.DataFrame, frame_data, operator.methodcaller("nlargest", 1, "A")), (pd.DataFrame, frame_data, operator.methodcaller("nsmallest", 1, "A")), - (pd.DataFrame, frame_mi_data, operator.methodcaller("swaplevel"),), + ( + pd.DataFrame, + frame_mi_data, + operator.methodcaller("swaplevel"), + ), pytest.param( ( pd.DataFrame, @@ -178,7 +182,11 @@ marks=not_implemented_mark, ), pytest.param( - (pd.DataFrame, frame_mi_data, operator.methodcaller("unstack"),), + ( + pd.DataFrame, + frame_mi_data, + operator.methodcaller("unstack"), + ), marks=not_implemented_mark, ), pytest.param( @@ -234,7 +242,7 @@ marks=[ not_implemented_mark, pytest.mark.filterwarnings("ignore::RuntimeWarning"), - ] + ], ), pytest.param( ( @@ -522,7 +530,7 @@ pytest.param( (pd.DataFrame, frame_data, operator.methodcaller("mean")), marks=not_implemented_mark, - ) + ), ] @@ -569,7 +577,7 @@ def test_finalize_called(ndframe_method): (pd.DataFrame({"A": [1]}), pd.DataFrame({"A": [1]})), (pd.Series([1]), pd.DataFrame({"A": [1]})), (pd.DataFrame({"A": [1]}), pd.Series([1])), - ] + ], ) def test_binops(args, annotate, all_arithmetic_functions): # This generates 326 tests... Is that needed? @@ -712,7 +720,7 @@ def test_datetime_method(method): "is_leap_year", "daysinmonth", "days_in_month", - ] + ], ) @not_implemented_mark def test_datetime_property(attr): @@ -734,7 +742,8 @@ def test_timedelta_property(attr): @pytest.mark.parametrize( - "method", [operator.methodcaller("total_seconds")], + "method", + [operator.methodcaller("total_seconds")], ) @not_implemented_mark def test_timedelta_methods(method): @@ -756,7 +765,7 @@ def test_timedelta_methods(method): operator.methodcaller("rename_categories", {"a": "A", "b": "B"}), operator.methodcaller("reorder_categories", ["b", "a"]), operator.methodcaller("set_categories", ["A", "B"]), - ] + ], ) @not_implemented_mark def test_categorical_accessor(method): @@ -781,7 +790,7 @@ def test_categorical_accessor(method): lambda x: x.agg(["sum", "count"]), lambda x: x.transform(lambda y: y), lambda x: x.apply(lambda y: y), - ] + ], ) @not_implemented_mark def test_groupby(obj, method): diff --git a/pandas/tests/groupby/aggregate/test_numba.py b/pandas/tests/groupby/aggregate/test_numba.py index af5089ae3ac21..30ec718fe9203 100644 --- a/pandas/tests/groupby/aggregate/test_numba.py +++ b/pandas/tests/groupby/aggregate/test_numba.py @@ -57,7 +57,8 @@ def func_numba(values, index): func_numba = numba.jit(func_numba) data = DataFrame( - {0: ["a", "a", "b", "b", "a"], 1: [1.0, 2.0, 3.0, 4.0, 5.0]}, columns=[0, 1], + {0: ["a", "a", "b", "b", "a"], 1: [1.0, 2.0, 3.0, 4.0, 5.0]}, + columns=[0, 1], ) engine_kwargs = {"nogil": nogil, "parallel": parallel, "nopython": nopython} grouped = data.groupby(0) @@ -90,7 +91,8 @@ def func_2(values, index): func_2 = numba.jit(func_2) data = DataFrame( - {0: ["a", "a", "b", "b", "a"], 1: [1.0, 2.0, 3.0, 4.0, 5.0]}, columns=[0, 1], + {0: ["a", "a", "b", "b", "a"], 1: [1.0, 2.0, 3.0, 4.0, 5.0]}, + columns=[0, 1], ) engine_kwargs = {"nogil": nogil, "parallel": parallel, "nopython": nopython} grouped = data.groupby(0) @@ -121,7 +123,8 @@ def func_1(values, index): return np.mean(values) - 3.4 data = DataFrame( - {0: ["a", "a", "b", "b", "a"], 1: [1.0, 2.0, 3.0, 4.0, 5.0]}, columns=[0, 1], + {0: ["a", "a", "b", "b", "a"], 1: [1.0, 2.0, 3.0, 4.0, 5.0]}, + columns=[0, 1], ) grouped = data.groupby(0) expected = grouped.agg(func_1, engine="numba") @@ -138,11 +141,12 @@ def func_1(values, index): "min", {"B": ["min", "max"], "C": "sum"}, NamedAgg(column="B", aggfunc="min"), - ] + ], ) def test_multifunc_notimplimented(agg_func): data = DataFrame( - {0: ["a", "a", "b", "b", "a"], 1: [1.0, 2.0, 3.0, 4.0, 5.0]}, columns=[0, 1], + {0: ["a", "a", "b", "b", "a"], 1: [1.0, 2.0, 3.0, 4.0, 5.0]}, + columns=[0, 1], ) grouped = data.groupby(0) with pytest.raises(NotImplementedError, match="Numba engine can"): From d097609cb42e8341ee137db3b63e0ebed2fbcca5 Mon Sep 17 00:00:00 2001 From: Jonathan Shreckengost Date: Sat, 29 Aug 2020 20:24:26 -0400 Subject: [PATCH 3/4] Comma cleanup for #35925 --- pandas/tests/frame/test_analytics.py | 26 +++++++------ pandas/tests/frame/test_constructors.py | 32 ++++++++-------- pandas/tests/frame/test_reshape.py | 39 +++++++++++--------- pandas/tests/generic/test_finalize.py | 27 +++++++++----- pandas/tests/groupby/aggregate/test_numba.py | 14 ++++--- 5 files changed, 80 insertions(+), 58 deletions(-) diff --git a/pandas/tests/frame/test_analytics.py b/pandas/tests/frame/test_analytics.py index 90cccb41d8b47..9bfc7d593c702 100644 --- a/pandas/tests/frame/test_analytics.py +++ b/pandas/tests/frame/test_analytics.py @@ -116,7 +116,11 @@ def wrapper(x): if opname in ["sum", "prod"]: expected = frame.apply(skipna_wrapper, axis=1) tm.assert_series_equal( - result1, expected, check_dtype=False, rtol=rtol, atol=atol, + result1, + expected, + check_dtype=False, + rtol=rtol, + atol=atol, ) # check dtypes @@ -406,7 +410,7 @@ def test_stat_operators_attempt_obj_array(self, method): 0.00031111847529610595, 0.0014902627951905339, -0.00094099200035979691, - ] + ], } df1 = DataFrame(data, index=["foo", "bar", "baz"], dtype="O") @@ -593,7 +597,7 @@ def test_kurt(self): "E": Categorical(["a"], categories=["a"]), "F": to_datetime(["2000-1-2"]), "G": to_timedelta(["1 days"]), - } + }, ), ( False, @@ -605,7 +609,7 @@ def test_kurt(self): "E": Categorical([np.nan], categories=["a"]), "F": [pd.NaT], "G": to_timedelta([pd.NaT]), - } + }, ), ( True, @@ -617,7 +621,7 @@ def test_kurt(self): "L": to_datetime(["2000-1-2", "NaT", "NaT", "NaT"]), "M": to_timedelta(["1 days", "nan", "nan", "nan"]), "N": [0, 1, 2, 3], - } + }, ), ( False, @@ -629,9 +633,9 @@ def test_kurt(self): "L": to_datetime(["NaT", "2000-1-2", "NaT", "NaT"]), "M": to_timedelta(["nan", "1 days", "nan", "nan"]), "N": [0, 1, 2, 3], - } - ) - ] + }, + ), + ], ) def test_mode_dropna(self, dropna, expected): @@ -1126,8 +1130,8 @@ def test_any_all_bool_only(self): True, # In 1.13.3 and 1.14 np.all(df) returns a Timedelta here marks=[td.skip_if_np_lt("1.15")], - ) - ] + ), + ], ) def test_any_all_np_func(self, func, data, expected): # GH 19976 @@ -1155,7 +1159,7 @@ def test_any_all_level_axis_none_raises(self, method): {"A": 1}, index=MultiIndex.from_product( [["A", "B"], ["a", "b"]], names=["out", "in"] - ) + ), ) xpr = "Must specify 'axis' when aggregating by level." with pytest.raises(ValueError, match=xpr): diff --git a/pandas/tests/frame/test_constructors.py b/pandas/tests/frame/test_constructors.py index d5ab7a8132395..ad88ed5f90494 100644 --- a/pandas/tests/frame/test_constructors.py +++ b/pandas/tests/frame/test_constructors.py @@ -79,7 +79,7 @@ def test_series_with_name_not_matching_column(self): lambda: DataFrame(data=[]), lambda: DataFrame(data=(_ for _ in [])), lambda: DataFrame(data=range(0)), - ] + ], ) def test_empty_constructor(self, constructor): expected = DataFrame() @@ -94,7 +94,7 @@ def test_empty_constructor(self, constructor): ([[]], RangeIndex(1), RangeIndex(0)), ([[], []], RangeIndex(2), RangeIndex(0)), ([(_ for _ in [])], RangeIndex(1), RangeIndex(0)), - ] + ], ) def test_emptylike_constructor(self, emptylike, expected_index, expected_columns): expected = DataFrame(index=expected_index, columns=expected_columns) @@ -276,7 +276,7 @@ def test_constructor_overflow_int64(self): np.array([-(2 ** 63) - 4], dtype=object), np.array([-(2 ** 64) - 1]), [-(2 ** 65) - 2], - ] + ], ) def test_constructor_int_overflow(self, values): # see gh-18584 @@ -725,8 +725,8 @@ def test_constructor_period_dict(self): ( Timestamp("2011-01-01", tz="US/Eastern"), DatetimeTZDtype(tz="US/Eastern"), - ) - ] + ), + ], ) def test_constructor_extension_scalar_data(self, data, dtype): # GH 34832 @@ -932,7 +932,9 @@ def test_constructor_mrecarray(self): # from GH3479 assert_fr_equal = functools.partial( - tm.assert_frame_equal, check_index_type=True, check_column_type=True, + tm.assert_frame_equal, + check_index_type=True, + check_column_type=True, ) arrays = [ ("float", np.array([1.5, 2.0])), @@ -980,7 +982,7 @@ def test_constructor_corner_shape(self): (None, list(range(10)), ["a", "b"], int, np.dtype("float64")), ({}, None, ["foo", "bar"], None, np.object_), ({"b": 1}, list(range(10)), list("abc"), int, np.dtype("float64")), - ] + ], ) def test_constructor_dtype(self, data, index, columns, dtype, expected): df = DataFrame(data, index, columns, dtype) @@ -1390,7 +1392,7 @@ def test_constructor_mixed_type_rows(self): (([], []), [[], []]), (([1], [2]), [[1], [2]]), # GH 32776 (([1, 2, 3], [4, 5, 6]), [[1, 2, 3], [4, 5, 6]]), - ] + ], ) def test_constructor_tuple(self, tuples, lists): # GH 25691 @@ -1532,7 +1534,7 @@ def test_from_dict_columns_parameter(self): ([{("a",): 1}, {("a",): 2}], [("a",)], "columns"), ([OrderedDict([(("a",), 1), (("b",), 2)])], [("a",), ("b",)], "columns"), ([{("a", "b"): 1}], [("a", "b")], "columns"), - ] + ], ) def test_constructor_from_dict_tuples(self, data_dict, keys, orient): # GH 16769 @@ -1625,7 +1627,7 @@ def test_constructor_Series_differently_indexed(self): ("idx1", "idx1", "idx2", None), ("idx1", "idx2", "idx3", None), (None, None, None, None), - ] + ], ) def test_constructor_index_names(self, name_in1, name_in2, name_in3, name_out): # GH13475 @@ -1728,7 +1730,7 @@ def test_constructor_single_value(self): np.array([["a", "a"], ["a", "a"]], dtype=object), index=[1, 2], columns=["a", "c"], - ) + ), ) msg = "DataFrame constructor not properly called!" @@ -1891,7 +1893,7 @@ def test_constructor_with_datetimes(self): [[None], [pd.NaT]], [[pd.NaT], [np.datetime64("NaT")]], [[pd.NaT], [None]], - ] + ], ) def test_constructor_datetimes_with_nulls(self, arr): # gh-15869, GH#11220 @@ -2151,7 +2153,7 @@ def test_from_records_iterator(self): ("u", np.float32), ("y", np.int64), ("z", np.int32), - ] + ], ) df = DataFrame.from_records(iter(arr), nrows=2) xp = DataFrame( @@ -2598,7 +2600,7 @@ class List(list): SparseArray([1, np.nan, np.nan, np.nan]), IntervalArray([pd.Interval(0, 1), pd.Interval(1, 5)]), PeriodArray(pd.period_range(start="1/1/2017", end="1/1/2018", freq="M")), - ] + ], ) def test_constructor_with_extension_array(self, extension_arr): # GH11363 @@ -2772,7 +2774,7 @@ def test_from_tzaware_mixed_object_array(self): Timestamp("2013-01-01 00:00:00+0100", tz="CET"), pd.NaT, Timestamp("2013-01-03 00:00:00+0100", tz="CET"), - ] + ], ], dtype=object, ).T diff --git a/pandas/tests/frame/test_reshape.py b/pandas/tests/frame/test_reshape.py index 40551ae21d0d7..5dd5fe51d8dd8 100644 --- a/pandas/tests/frame/test_reshape.py +++ b/pandas/tests/frame/test_reshape.py @@ -384,7 +384,7 @@ def test_unstack_tuplename_in_multiindex(self): pd.MultiIndex.from_tuples( [("d", "a"), ("d", "b"), ("e", "a"), ("e", "b")], names=[None, ("A", "a")], - ) + ), ), ( (("A", "a"), "B"), @@ -402,9 +402,9 @@ def test_unstack_tuplename_in_multiindex(self): ("e", "b", 2), ], names=[None, ("A", "a"), "B"], - ) - ) - ] + ), + ), + ], ) def test_unstack_mixed_type_name_in_multiindex( self, unstack_idx, expected_values, expected_index, expected_columns @@ -417,7 +417,9 @@ def test_unstack_mixed_type_name_in_multiindex( result = df.unstack(unstack_idx) expected = pd.DataFrame( - expected_values, columns=expected_columns, index=expected_index, + expected_values, + columns=expected_columns, + index=expected_index, ) tm.assert_frame_equal(result, expected) @@ -650,7 +652,7 @@ def test_unstack_dtypes(self): [np.dtype("int64")] * 4, index=pd.MultiIndex.from_arrays( [["C", "C", "D", "D"], [1, 2, 1, 2]], names=(None, "B") - ) + ), ) tm.assert_series_equal(result, expected) @@ -663,7 +665,7 @@ def test_unstack_dtypes(self): [np.dtype("float64")] * 2 + [np.dtype("int64")] * 2, index=pd.MultiIndex.from_arrays( [["C", "C", "D", "D"], [1, 2, 1, 2]], names=(None, "B") - ) + ), ) tm.assert_series_equal(result, expected) df2["D"] = "foo" @@ -673,7 +675,7 @@ def test_unstack_dtypes(self): [np.dtype("float64")] * 2 + [np.dtype("object")] * 2, index=pd.MultiIndex.from_arrays( [["C", "C", "D", "D"], [1, 2, 1, 2]], names=(None, "B") - ) + ), ) tm.assert_series_equal(result, expected) @@ -786,7 +788,7 @@ def test_unstack_long_index(self): index=pd.MultiIndex.from_tuples( [[0, 0, 1, 0, 0, 0, 1]], names=["i1", "i2", "i3", "i4", "i5", "i6", "i7"], - ) + ), ) result = df.unstack(["i2", "i3", "i4", "i5", "i6", "i7"]) expected = pd.DataFrame( @@ -807,8 +809,9 @@ def test_unstack_multi_level_cols(self): [["B", "C"], ["B", "D"]], names=["c1", "c2"] ), index=pd.MultiIndex.from_tuples( - [[10, 20, 30], [10, 20, 40]], names=["i1", "i2", "i3"], - ) + [[10, 20, 30], [10, 20, 40]], + names=["i1", "i2", "i3"], + ), ) assert df.unstack(["i2", "i1"]).columns.names[-2:] == ["i2", "i1"] @@ -825,7 +828,7 @@ def test_unstack_multi_level_rows_and_cols(self): ["m2", "A5", 111], ], names=["i1", "i2", "i3"], - ) + ), ) result = df.unstack(["i3", "i2"]) expected = df.unstack(["i3"]).unstack(["i2"]) @@ -900,7 +903,7 @@ def verify(df): 53, 60, 51, - ] + ], } ) @@ -1155,7 +1158,7 @@ def test_stack_preserve_categorical_dtype_values(self): ([0, 0, 1, 1], pd.MultiIndex.from_product([[1, 2], ["a", "b"]])), ([0, 0, 2, 3], pd.MultiIndex.from_product([[1, 2], ["a", "b"]])), ([0, 1, 2, 3], pd.MultiIndex.from_product([[1, 2], ["a", "b"]])), - ] + ], ) def test_stack_multi_columns_non_unique_index(self, index, columns): # GH-28301 @@ -1203,7 +1206,7 @@ def test_unstack_swaplevel_sortlevel(self, level): [[3, 1, 2, 0]], columns=pd.MultiIndex.from_tuples( [("c", "A"), ("c", "B"), ("d", "A"), ("d", "B")], names=["baz", "foo"] - ) + ), ) expected.index.name = "bar" @@ -1252,7 +1255,7 @@ def test_unstack_timezone_aware_values(): levels=[["timestamp", "c"], ["b"]], codes=[[0, 1], [0, 0]], names=[None, "b"], - ) + ), ) tm.assert_frame_equal(result, expected) @@ -1268,7 +1271,7 @@ def test_stack_timezone_aware_values(): ts, index=pd.MultiIndex( levels=[["a", "b", "c"], ["A"]], codes=[[0, 1, 2], [0, 0, 0]] - ) + ), ) tm.assert_series_equal(result, expected) @@ -1299,6 +1302,6 @@ def test_unstacking_multi_index_df(): ("score", "male", True, 0), ], names=[None, "gender", "employed", "kids"], - ) + ), ) tm.assert_frame_equal(result, expected) diff --git a/pandas/tests/generic/test_finalize.py b/pandas/tests/generic/test_finalize.py index 7d9cf295ebc31..c534ecf24e189 100644 --- a/pandas/tests/generic/test_finalize.py +++ b/pandas/tests/generic/test_finalize.py @@ -123,7 +123,11 @@ (pd.DataFrame, frame_data, operator.methodcaller("sort_index")), (pd.DataFrame, frame_data, operator.methodcaller("nlargest", 1, "A")), (pd.DataFrame, frame_data, operator.methodcaller("nsmallest", 1, "A")), - (pd.DataFrame, frame_mi_data, operator.methodcaller("swaplevel"),), + ( + pd.DataFrame, + frame_mi_data, + operator.methodcaller("swaplevel"), + ), pytest.param( ( pd.DataFrame, @@ -178,7 +182,11 @@ marks=not_implemented_mark, ), pytest.param( - (pd.DataFrame, frame_mi_data, operator.methodcaller("unstack"),), + ( + pd.DataFrame, + frame_mi_data, + operator.methodcaller("unstack"), + ), marks=not_implemented_mark, ), pytest.param( @@ -234,7 +242,7 @@ marks=[ not_implemented_mark, pytest.mark.filterwarnings("ignore::RuntimeWarning"), - ] + ], ), pytest.param( ( @@ -522,7 +530,7 @@ pytest.param( (pd.DataFrame, frame_data, operator.methodcaller("mean")), marks=not_implemented_mark, - ) + ), ] @@ -569,7 +577,7 @@ def test_finalize_called(ndframe_method): (pd.DataFrame({"A": [1]}), pd.DataFrame({"A": [1]})), (pd.Series([1]), pd.DataFrame({"A": [1]})), (pd.DataFrame({"A": [1]}), pd.Series([1])), - ] + ], ) def test_binops(args, annotate, all_arithmetic_functions): # This generates 326 tests... Is that needed? @@ -712,7 +720,7 @@ def test_datetime_method(method): "is_leap_year", "daysinmonth", "days_in_month", - ] + ], ) @not_implemented_mark def test_datetime_property(attr): @@ -734,7 +742,8 @@ def test_timedelta_property(attr): @pytest.mark.parametrize( - "method", [operator.methodcaller("total_seconds")], + "method", + [operator.methodcaller("total_seconds")], ) @not_implemented_mark def test_timedelta_methods(method): @@ -756,7 +765,7 @@ def test_timedelta_methods(method): operator.methodcaller("rename_categories", {"a": "A", "b": "B"}), operator.methodcaller("reorder_categories", ["b", "a"]), operator.methodcaller("set_categories", ["A", "B"]), - ] + ], ) @not_implemented_mark def test_categorical_accessor(method): @@ -781,7 +790,7 @@ def test_categorical_accessor(method): lambda x: x.agg(["sum", "count"]), lambda x: x.transform(lambda y: y), lambda x: x.apply(lambda y: y), - ] + ], ) @not_implemented_mark def test_groupby(obj, method): diff --git a/pandas/tests/groupby/aggregate/test_numba.py b/pandas/tests/groupby/aggregate/test_numba.py index af5089ae3ac21..30ec718fe9203 100644 --- a/pandas/tests/groupby/aggregate/test_numba.py +++ b/pandas/tests/groupby/aggregate/test_numba.py @@ -57,7 +57,8 @@ def func_numba(values, index): func_numba = numba.jit(func_numba) data = DataFrame( - {0: ["a", "a", "b", "b", "a"], 1: [1.0, 2.0, 3.0, 4.0, 5.0]}, columns=[0, 1], + {0: ["a", "a", "b", "b", "a"], 1: [1.0, 2.0, 3.0, 4.0, 5.0]}, + columns=[0, 1], ) engine_kwargs = {"nogil": nogil, "parallel": parallel, "nopython": nopython} grouped = data.groupby(0) @@ -90,7 +91,8 @@ def func_2(values, index): func_2 = numba.jit(func_2) data = DataFrame( - {0: ["a", "a", "b", "b", "a"], 1: [1.0, 2.0, 3.0, 4.0, 5.0]}, columns=[0, 1], + {0: ["a", "a", "b", "b", "a"], 1: [1.0, 2.0, 3.0, 4.0, 5.0]}, + columns=[0, 1], ) engine_kwargs = {"nogil": nogil, "parallel": parallel, "nopython": nopython} grouped = data.groupby(0) @@ -121,7 +123,8 @@ def func_1(values, index): return np.mean(values) - 3.4 data = DataFrame( - {0: ["a", "a", "b", "b", "a"], 1: [1.0, 2.0, 3.0, 4.0, 5.0]}, columns=[0, 1], + {0: ["a", "a", "b", "b", "a"], 1: [1.0, 2.0, 3.0, 4.0, 5.0]}, + columns=[0, 1], ) grouped = data.groupby(0) expected = grouped.agg(func_1, engine="numba") @@ -138,11 +141,12 @@ def func_1(values, index): "min", {"B": ["min", "max"], "C": "sum"}, NamedAgg(column="B", aggfunc="min"), - ] + ], ) def test_multifunc_notimplimented(agg_func): data = DataFrame( - {0: ["a", "a", "b", "b", "a"], 1: [1.0, 2.0, 3.0, 4.0, 5.0]}, columns=[0, 1], + {0: ["a", "a", "b", "b", "a"], 1: [1.0, 2.0, 3.0, 4.0, 5.0]}, + columns=[0, 1], ) grouped = data.groupby(0) with pytest.raises(NotImplementedError, match="Numba engine can"): From 26c8c234410c6c93daad93ea0a472dba667163f2 Mon Sep 17 00:00:00 2001 From: Jonathan Shreckengost Date: Mon, 31 Aug 2020 22:27:21 -0400 Subject: [PATCH 4/4] Comma cleanup for #35925 --- pandas/tests/frame/test_analytics.py | 8 ++------ pandas/tests/frame/test_constructors.py | 2 +- pandas/tests/frame/test_reshape.py | 6 ++++-- pandas/tests/generic/test_finalize.py | 18 ++++++++++++------ pandas/tests/generic/test_to_xarray.py | 4 +--- pandas/tests/groupby/aggregate/test_numba.py | 8 ++++---- pandas/tests/groupby/test_apply.py | 4 +--- pandas/tests/groupby/test_categorical.py | 4 ++-- 8 files changed, 27 insertions(+), 27 deletions(-) diff --git a/pandas/tests/frame/test_analytics.py b/pandas/tests/frame/test_analytics.py index 52a1e3aae9058..b0ba0d991c9b0 100644 --- a/pandas/tests/frame/test_analytics.py +++ b/pandas/tests/frame/test_analytics.py @@ -86,11 +86,7 @@ def wrapper(x): result0 = f(axis=0, skipna=False) result1 = f(axis=1, skipna=False) tm.assert_series_equal( - result0, - frame.apply(wrapper), - check_dtype=check_dtype, - rtol=rtol, - atol=atol, + result0, frame.apply(wrapper), check_dtype=check_dtype, rtol=rtol, atol=atol ) # HACK: win32 tm.assert_series_equal( @@ -116,7 +112,7 @@ def wrapper(x): if opname in ["sum", "prod"]: expected = frame.apply(skipna_wrapper, axis=1) tm.assert_series_equal( - result1, expected, check_dtype=False, rtol=rtol, atol=atol, + result1, expected, check_dtype=False, rtol=rtol, atol=atol ) # check dtypes diff --git a/pandas/tests/frame/test_constructors.py b/pandas/tests/frame/test_constructors.py index c8f5b2b0f6364..0d1004809f7f1 100644 --- a/pandas/tests/frame/test_constructors.py +++ b/pandas/tests/frame/test_constructors.py @@ -932,7 +932,7 @@ def test_constructor_mrecarray(self): # from GH3479 assert_fr_equal = functools.partial( - tm.assert_frame_equal, check_index_type=True, check_column_type=True, + tm.assert_frame_equal, check_index_type=True, check_column_type=True ) arrays = [ ("float", np.array([1.5, 2.0])), diff --git a/pandas/tests/frame/test_reshape.py b/pandas/tests/frame/test_reshape.py index 6a8f1e7c1aca2..a0ada65dc6f2c 100644 --- a/pandas/tests/frame/test_reshape.py +++ b/pandas/tests/frame/test_reshape.py @@ -417,7 +417,9 @@ def test_unstack_mixed_type_name_in_multiindex( result = df.unstack(unstack_idx) expected = pd.DataFrame( - expected_values, columns=expected_columns, index=expected_index, + expected_values, + columns=expected_columns, + index=expected_index, ) tm.assert_frame_equal(result, expected) @@ -807,7 +809,7 @@ def test_unstack_multi_level_cols(self): [["B", "C"], ["B", "D"]], names=["c1", "c2"] ), index=pd.MultiIndex.from_tuples( - [[10, 20, 30], [10, 20, 40]], names=["i1", "i2", "i3"], + [[10, 20, 30], [10, 20, 40]], names=["i1", "i2", "i3"] ), ) assert df.unstack(["i2", "i1"]).columns.names[-2:] == ["i2", "i1"] diff --git a/pandas/tests/generic/test_finalize.py b/pandas/tests/generic/test_finalize.py index 4d0f1a326225d..32d6866cff822 100644 --- a/pandas/tests/generic/test_finalize.py +++ b/pandas/tests/generic/test_finalize.py @@ -123,7 +123,11 @@ (pd.DataFrame, frame_data, operator.methodcaller("sort_index")), (pd.DataFrame, frame_data, operator.methodcaller("nlargest", 1, "A")), (pd.DataFrame, frame_data, operator.methodcaller("nsmallest", 1, "A")), - (pd.DataFrame, frame_mi_data, operator.methodcaller("swaplevel"),), + ( + pd.DataFrame, + frame_mi_data, + operator.methodcaller("swaplevel"), + ), pytest.param( ( pd.DataFrame, @@ -178,7 +182,11 @@ marks=not_implemented_mark, ), pytest.param( - (pd.DataFrame, frame_mi_data, operator.methodcaller("unstack"),), + ( + pd.DataFrame, + frame_mi_data, + operator.methodcaller("unstack"), + ), marks=not_implemented_mark, ), pytest.param( @@ -317,7 +325,7 @@ marks=not_implemented_mark, ), pytest.param( - (pd.Series, ([1, 2],), operator.methodcaller("squeeze")), + (pd.Series, ([1, 2],), operator.methodcaller("squeeze")) # marks=not_implemented_mark, ), (pd.Series, ([1, 2],), operator.methodcaller("rename_axis", index="a")), @@ -733,9 +741,7 @@ def test_timedelta_property(attr): assert result.attrs == {"a": 1} -@pytest.mark.parametrize( - "method", [operator.methodcaller("total_seconds")], -) +@pytest.mark.parametrize("method", [operator.methodcaller("total_seconds")]) @not_implemented_mark def test_timedelta_methods(method): s = pd.Series(pd.timedelta_range("2000", periods=4)) diff --git a/pandas/tests/generic/test_to_xarray.py b/pandas/tests/generic/test_to_xarray.py index ab56a752f7e90..a85d7ddc1ea53 100644 --- a/pandas/tests/generic/test_to_xarray.py +++ b/pandas/tests/generic/test_to_xarray.py @@ -47,9 +47,7 @@ def test_to_xarray_index_types(self, index): expected = df.copy() expected["f"] = expected["f"].astype(object) expected.columns.name = None - tm.assert_frame_equal( - result.to_dataframe(), expected, - ) + tm.assert_frame_equal(result.to_dataframe(), expected) @td.skip_if_no("xarray", min_version="0.7.0") def test_to_xarray(self): diff --git a/pandas/tests/groupby/aggregate/test_numba.py b/pandas/tests/groupby/aggregate/test_numba.py index 29e65e938f6f9..c4266996748c2 100644 --- a/pandas/tests/groupby/aggregate/test_numba.py +++ b/pandas/tests/groupby/aggregate/test_numba.py @@ -57,7 +57,7 @@ def func_numba(values, index): func_numba = numba.jit(func_numba) data = DataFrame( - {0: ["a", "a", "b", "b", "a"], 1: [1.0, 2.0, 3.0, 4.0, 5.0]}, columns=[0, 1], + {0: ["a", "a", "b", "b", "a"], 1: [1.0, 2.0, 3.0, 4.0, 5.0]}, columns=[0, 1] ) engine_kwargs = {"nogil": nogil, "parallel": parallel, "nopython": nopython} grouped = data.groupby(0) @@ -90,7 +90,7 @@ def func_2(values, index): func_2 = numba.jit(func_2) data = DataFrame( - {0: ["a", "a", "b", "b", "a"], 1: [1.0, 2.0, 3.0, 4.0, 5.0]}, columns=[0, 1], + {0: ["a", "a", "b", "b", "a"], 1: [1.0, 2.0, 3.0, 4.0, 5.0]}, columns=[0, 1] ) engine_kwargs = {"nogil": nogil, "parallel": parallel, "nopython": nopython} grouped = data.groupby(0) @@ -121,7 +121,7 @@ def func_1(values, index): return np.mean(values) - 3.4 data = DataFrame( - {0: ["a", "a", "b", "b", "a"], 1: [1.0, 2.0, 3.0, 4.0, 5.0]}, columns=[0, 1], + {0: ["a", "a", "b", "b", "a"], 1: [1.0, 2.0, 3.0, 4.0, 5.0]}, columns=[0, 1] ) grouped = data.groupby(0) expected = grouped.agg(func_1, engine="numba") @@ -142,7 +142,7 @@ def func_1(values, index): ) def test_multifunc_notimplimented(agg_func): data = DataFrame( - {0: ["a", "a", "b", "b", "a"], 1: [1.0, 2.0, 3.0, 4.0, 5.0]}, columns=[0, 1], + {0: ["a", "a", "b", "b", "a"], 1: [1.0, 2.0, 3.0, 4.0, 5.0]}, columns=[0, 1] ) grouped = data.groupby(0) with pytest.raises(NotImplementedError, match="Numba engine can"): diff --git a/pandas/tests/groupby/test_apply.py b/pandas/tests/groupby/test_apply.py index a1dcb28a32c6c..3183305fe2933 100644 --- a/pandas/tests/groupby/test_apply.py +++ b/pandas/tests/groupby/test_apply.py @@ -946,9 +946,7 @@ def fct(group): tm.assert_series_equal(result, expected) -@pytest.mark.parametrize( - "function", [lambda gr: gr.index, lambda gr: gr.index + 1 - 1], -) +@pytest.mark.parametrize("function", [lambda gr: gr.index, lambda gr: gr.index + 1 - 1]) def test_apply_function_index_return(function): # GH: 22541 df = pd.DataFrame([1, 2, 2, 2, 1, 2, 3, 1, 3, 1], columns=["id"]) diff --git a/pandas/tests/groupby/test_categorical.py b/pandas/tests/groupby/test_categorical.py index 13a32e285e70a..711daf7fe415d 100644 --- a/pandas/tests/groupby/test_categorical.py +++ b/pandas/tests/groupby/test_categorical.py @@ -17,7 +17,7 @@ def cartesian_product_for_groupers(result, args, names, fill_value=np.NaN): - """ Reindex to a cartesian production for the groupers, + """Reindex to a cartesian production for the groupers, preserving the nature (Categorical) of each grouper """ @@ -1449,7 +1449,7 @@ def test_groupby_agg_categorical_columns(func, expected_values): result = df.groupby("groups").agg(func) expected = pd.DataFrame( - {"value": expected_values}, index=pd.Index([0, 1, 2], name="groups"), + {"value": expected_values}, index=pd.Index([0, 1, 2], name="groups") ) tm.assert_frame_equal(result, expected)