diff --git a/pandas/tests/frame/test_analytics.py b/pandas/tests/frame/test_analytics.py index 52a1e3aae9058..aa20887dc9549 100644 --- a/pandas/tests/frame/test_analytics.py +++ b/pandas/tests/frame/test_analytics.py @@ -18,7 +18,7 @@ isna, notna, to_datetime, - to_timedelta, + to_timedelta ) import pandas._testing as tm import pandas.core.algorithms as algorithms @@ -34,7 +34,7 @@ def assert_stat_op_calc( check_dates=False, rtol=1e-5, atol=1e-8, - skipna_alternative=None, + skipna_alternative=None ): """ Check that operator opname works as advertised on frame @@ -90,7 +90,7 @@ def wrapper(x): frame.apply(wrapper), check_dtype=check_dtype, rtol=rtol, - atol=atol, + atol=atol ) # HACK: win32 tm.assert_series_equal( @@ -98,7 +98,7 @@ def wrapper(x): frame.apply(wrapper, axis=1), check_dtype=False, rtol=rtol, - atol=atol, + atol=atol ) else: skipna_wrapper = alternative @@ -110,13 +110,13 @@ def wrapper(x): frame.apply(skipna_wrapper), check_dtype=check_dtype, rtol=rtol, - atol=atol, + atol=atol ) 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 @@ -333,7 +333,7 @@ def kurt(x): float_frame_with_na, has_skipna=False, check_dtype=False, - check_dates=True, + check_dates=True ) # GH#32571 check_less_precise is needed on apparently-random @@ -344,7 +344,7 @@ def kurt(x): np.sum, mixed_float_frame.astype("float32"), check_dtype=False, - rtol=1e-3, + rtol=1e-3 ) assert_stat_op_calc( @@ -366,7 +366,7 @@ def kurt(x): float_frame_with_na, has_skipna=False, check_dtype=False, - check_dates=True, + check_dates=True ) try: @@ -399,14 +399,14 @@ def test_stat_operators_attempt_obj_array(self, method): "a": [ -0.00049987540199591344, -0.0016467257772919831, - 0.00067695870775883013, + 0.00067695870775883013 ], "b": [-0, -0, 0.0], "c": [ 0.00031111847529610595, 0.0014902627951905339, - -0.00094099200035979691, - ], + -0.00094099200035979691 + ] } df1 = DataFrame(data, index=["foo", "bar", "baz"], dtype="O") @@ -427,7 +427,7 @@ def test_mixed_ops(self, op): { "int": [1, 2, 3, 4], "float": [1.0, 2.0, 3.0, 4.0], - "str": ["a", "b", "c", "d"], + "str": ["a", "b", "c", "d"] } ) @@ -444,7 +444,7 @@ def test_reduce_mixed_frame(self): { "bool_data": [True, True, False, False, False], "int_data": [10, 20, 30, 40, 50], - "string_data": ["a", "b", "c", "d", "e"], + "string_data": ["a", "b", "c", "d", "e"] } ) df.reindex(columns=["bool_data", "int_data", "string_data"]) @@ -500,7 +500,7 @@ def test_mean_mixed_string_decimal(self): {"A": 2, "B": None, "C": Decimal("572.00")}, {"A": 4, "B": None, "C": Decimal("609.00")}, {"A": 3, "B": None, "C": Decimal("820.00")}, - {"A": 5, "B": None, "C": Decimal("1223.00")}, + {"A": 5, "B": None, "C": Decimal("1223.00")} ] df = pd.DataFrame(d) @@ -570,7 +570,7 @@ def test_sem(self, datetime_frame): def test_kurt(self): index = MultiIndex( levels=[["bar"], ["one", "two", "three"], [0, 1]], - codes=[[0, 0, 0, 0, 0, 0], [0, 1, 2, 0, 1, 2], [0, 1, 0, 1, 0, 1]], + codes=[[0, 0, 0, 0, 0, 0], [0, 1, 2, 0, 1, 2], [0, 1, 0, 1, 0, 1]] ) df = DataFrame(np.random.randn(6, 3), index=index) @@ -592,8 +592,8 @@ def test_kurt(self): "D": ["a"], "E": Categorical(["a"], categories=["a"]), "F": to_datetime(["2000-1-2"]), - "G": to_timedelta(["1 days"]), - }, + "G": to_timedelta(["1 days"]) + } ), ( False, @@ -604,8 +604,8 @@ def test_kurt(self): "D": np.array([np.nan], dtype=object), "E": Categorical([np.nan], categories=["a"]), "F": [pd.NaT], - "G": to_timedelta([pd.NaT]), - }, + "G": to_timedelta([pd.NaT]) + } ), ( True, @@ -616,8 +616,8 @@ def test_kurt(self): "K": Categorical(["a", np.nan, np.nan, np.nan], categories=["a"]), "L": to_datetime(["2000-1-2", "NaT", "NaT", "NaT"]), "M": to_timedelta(["1 days", "nan", "nan", "nan"]), - "N": [0, 1, 2, 3], - }, + "N": [0, 1, 2, 3] + } ), ( False, @@ -628,10 +628,10 @@ def test_kurt(self): "K": Categorical([np.nan, "a", np.nan, np.nan], categories=["a"]), "L": to_datetime(["NaT", "2000-1-2", "NaT", "NaT"]), "M": to_timedelta(["nan", "1 days", "nan", "nan"]), - "N": [0, 1, 2, 3], - }, - ), - ], + "N": [0, 1, 2, 3] + } + ) + ] ) def test_mode_dropna(self, dropna, expected): @@ -650,7 +650,7 @@ def test_mode_dropna(self, dropna, expected): "K": Categorical(["a", np.nan, "a", np.nan]), "L": to_datetime(["2000-1-2", "2000-1-2", "NaT", "NaT"]), "M": to_timedelta(["1 days", "nan", "1 days", "nan"]), - "N": np.arange(4, dtype="int64"), + "N": np.arange(4, dtype="int64") } ) @@ -676,7 +676,7 @@ def test_operators_timedelta64(self): dict( A=date_range("2012-1-1", periods=3, freq="D"), B=date_range("2012-1-2", periods=3, freq="D"), - C=Timestamp("20120101") - timedelta(minutes=5, seconds=5), + C=Timestamp("20120101") - timedelta(minutes=5, seconds=5) ) ) @@ -721,9 +721,9 @@ def test_operators_timedelta64(self): "foo", 1, 1.0, - Timestamp("20130101"), + Timestamp("20130101") ], - index=mixed.columns, + index=mixed.columns ) tm.assert_series_equal(result, expected) @@ -747,7 +747,7 @@ def test_operators_timedelta64(self): df = DataFrame( { "time": date_range("20130102", periods=5), - "time2": date_range("20130105", periods=5), + "time2": date_range("20130105", periods=5) } ) df["off1"] = df["time2"] - df["time"] @@ -871,7 +871,7 @@ def test_mean_datetimelike(self): "A": np.arange(3), "B": pd.date_range("2016-01-01", periods=3), "C": pd.timedelta_range("1D", periods=3), - "D": pd.period_range("2016", periods=3, freq="A"), + "D": pd.period_range("2016", periods=3, freq="A") } ) result = df.mean(numeric_only=True) @@ -889,7 +889,7 @@ def test_mean_datetimelike_numeric_only_false(self): { "A": np.arange(3), "B": pd.date_range("2016-01-01", periods=3), - "C": pd.timedelta_range("1D", periods=3), + "C": pd.timedelta_range("1D", periods=3) } ) @@ -974,9 +974,9 @@ def test_any_all_extra(self): { "A": [True, False, False], "B": [True, True, False], - "C": [True, True, True], + "C": [True, True, True] }, - index=["a", "b", "c"], + index=["a", "b", "c"] ) result = df[["A", "B"]].any(1) expected = Series([True, True, False], index=["a", "b", "c"]) @@ -1010,7 +1010,7 @@ def test_any_datetime(self): pd.Timestamp("1960-02-15"), pd.Timestamp("1960-02-16"), pd.NaT, - pd.NaT, + pd.NaT ] df = DataFrame({"A": float_data, "B": datetime_data}) @@ -1034,7 +1034,7 @@ def test_any_all_bool_only(self): "col1": [1, 2, 3], "col2": [4, 5, 6], "col3": [None, None, None], - "col4": [False, False, True], + "col4": [False, False, True] } ) @@ -1125,9 +1125,9 @@ 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")], - ), - ], + 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): @@ -1293,7 +1293,7 @@ def test_min_max_dt64_api_consistency_empty_df(self): @pytest.mark.parametrize( "initial", - ["2018-10-08 13:36:45+00:00", "2018-10-08 13:36:45+03:00"], # Non-UTC timezone + ["2018-10-08 13:36:45+00:00", "2018-10-08 13:36:45+03:00"] # Non-UTC timezone ) @pytest.mark.parametrize("method", ["min", "max"]) def test_preserve_timezone(self, initial: str, method): diff --git a/pandas/tests/frame/test_constructors.py b/pandas/tests/frame/test_constructors.py index c8f5b2b0f6364..5a63108684436 100644 --- a/pandas/tests/frame/test_constructors.py +++ b/pandas/tests/frame/test_constructors.py @@ -30,7 +30,7 @@ Timedelta, Timestamp, date_range, - isna, + isna ) import pandas._testing as tm from pandas.arrays import IntervalArray, PeriodArray, SparseArray @@ -45,7 +45,7 @@ "int8", "int16", "int32", - "int64", + "int64" ] @@ -78,8 +78,8 @@ def test_series_with_name_not_matching_column(self): lambda: DataFrame(data=()), lambda: DataFrame(data=[]), lambda: DataFrame(data=(_ for _ in [])), - lambda: DataFrame(data=range(0)), - ], + lambda: DataFrame(data=range(0)) + ] ) def test_empty_constructor(self, constructor): expected = DataFrame() @@ -93,8 +93,8 @@ def test_empty_constructor(self, constructor): [ ([[]], RangeIndex(1), RangeIndex(0)), ([[], []], RangeIndex(2), RangeIndex(0)), - ([(_ for _ in [])], RangeIndex(1), 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) @@ -259,7 +259,7 @@ def test_constructor_overflow_int64(self): (2685045978526272070, 23), (8921811264899370420, 45), (17019687244989530680, 270), - (9930107427299601010, 273), + (9930107427299601010, 273) ] dtype = [("uid", "u8"), ("score", "u8")] data = np.zeros((len(data_scores),), dtype=dtype) @@ -275,8 +275,8 @@ def test_constructor_overflow_int64(self): [2 ** 64 + 1], np.array([-(2 ** 63) - 4], dtype=object), np.array([-(2 ** 64) - 1]), - [-(2 ** 65) - 2], - ], + [-(2 ** 65) - 2] + ] ) def test_constructor_int_overflow(self, values): # see gh-18584 @@ -312,13 +312,13 @@ def test_constructor_dict(self): exp = Series( np.concatenate([[np.nan] * 5, datetime_series_short.values]), index=datetime_series.index, - name="col2", + name="col2" ) tm.assert_series_equal(exp, frame["col2"]) frame = DataFrame( {"col1": datetime_series, "col2": datetime_series_short}, - columns=["col2", "col3", "col4"], + columns=["col2", "col3", "col4"] ) assert len(frame) == len(datetime_series_short) @@ -453,7 +453,7 @@ def test_constructor_2d_index(self): expected = DataFrame( [1, 1], index=pd.Int64Index([1, 2], dtype="int64"), - columns=MultiIndex(levels=[[1]], codes=[[0]]), + columns=MultiIndex(levels=[[1]], codes=[[0]]) ) tm.assert_frame_equal(df, expected) @@ -461,7 +461,7 @@ def test_constructor_2d_index(self): expected = DataFrame( [1, 1], index=MultiIndex(levels=[[1, 2]], codes=[[0, 1]]), - columns=MultiIndex(levels=[[1]], codes=[[0]]), + columns=MultiIndex(levels=[[1]], codes=[[0]]) ) tm.assert_frame_equal(df, expected) @@ -482,7 +482,7 @@ def test_constructor_error_msgs(self): DataFrame( np.arange(12).reshape((4, 3)), columns=["foo", "bar", "baz"], - index=date_range("2000-01-01", periods=3), + index=date_range("2000-01-01", periods=3) ) arr = np.array([[4, 5, 6]]) @@ -548,7 +548,7 @@ def test_constructor_dict_block(self): expected = np.array([[4.0, 3.0, 2.0, 1.0]]) df = DataFrame( {"d": [4.0], "c": [3.0], "b": [2.0], "a": [1.0]}, - columns=["d", "c", "b", "a"], + columns=["d", "c", "b", "a"] ) tm.assert_numpy_array_equal(df.values, expected) @@ -568,7 +568,7 @@ def test_constructor_dict_cast(self): # can't cast to float test_data = { "A": dict(zip(range(20), tm.makeStringIndex(20))), - "B": dict(zip(range(15), np.random.randn(15))), + "B": dict(zip(range(15), np.random.randn(15))) } frame = DataFrame(test_data, dtype=float) assert len(frame) == 20 @@ -622,13 +622,13 @@ def check(result, expected): check_dtype=True, check_index_type=True, check_column_type=True, - check_names=True, + check_names=True ) d = { ("a", "a"): {("i", "i"): 0, ("i", "j"): 1, ("j", "i"): 2}, ("b", "a"): {("i", "i"): 6, ("i", "j"): 5, ("j", "i"): 4}, - ("b", "c"): {("i", "i"): 7, ("i", "j"): 8, ("j", "i"): 9}, + ("b", "c"): {("i", "i"): 7, ("i", "j"): 8, ("j", "i"): 9} } _d = sorted(d.items()) df = DataFrame(d) @@ -664,9 +664,9 @@ def create_data(constructor): {0: 0, 1: None, 2: None, 3: None}, {0: None, 1: 2, 2: None, 3: None}, {0: None, 1: None, 2: 4, 3: None}, - {0: None, 1: None, 2: None, 3: 6}, + {0: None, 1: None, 2: None, 3: 6} ], - index=[Timestamp(dt) for dt in dates_as_str], + index=[Timestamp(dt) for dt in dates_as_str] ) result_datetime64 = DataFrame(data_datetime64) @@ -692,7 +692,7 @@ def create_data(constructor): {0: 0, 1: None, 2: None, 3: None}, {0: None, 1: 2, 2: None, 3: None}, {0: None, 1: None, 2: 4, 3: None}, - {0: None, 1: None, 2: None, 3: 6}, + {0: None, 1: None, 2: None, 3: 6} ], index=[Timedelta(td, "D") for td in td_as_int], ) @@ -724,9 +724,9 @@ def test_constructor_period_dict(self): (Interval(left=0, right=5), IntervalDtype("int64")), ( Timestamp("2011-01-01", tz="US/Eastern"), - DatetimeTZDtype(tz="US/Eastern"), - ), - ], + DatetimeTZDtype(tz="US/Eastern") + ) + ] ) def test_constructor_extension_scalar_data(self, data, dtype): # GH 34832 @@ -903,7 +903,7 @@ def test_constructor_maskedarray_hardened(self): {"A": [np.nan, np.nan], "B": [np.nan, np.nan]}, columns=["A", "B"], index=[1, 2], - dtype=float, + dtype=float ) tm.assert_frame_equal(result, expected) # Check case where mask is hard but no data are masked @@ -913,7 +913,7 @@ def test_constructor_maskedarray_hardened(self): {"A": [1.0, 1.0], "B": [1.0, 1.0]}, columns=["A", "B"], index=[1, 2], - dtype=float, + dtype=float ) tm.assert_frame_equal(result, expected) @@ -932,12 +932,12 @@ 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])), ("int", np.array([1, 2])), - ("str", np.array(["abc", "def"])), + ("str", np.array(["abc", "def"])) ] for name, arr in arrays[:]: arrays.append( @@ -979,8 +979,8 @@ def test_constructor_corner_shape(self): (None, None, ["a", "b"], "int64", np.dtype("int64")), (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")), - ], + ({"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) @@ -1043,7 +1043,7 @@ def test_constructor_more(self, float_frame): # int cast dm = DataFrame( {"A": np.ones(10, dtype=int), "B": np.ones(10, dtype=np.float64)}, - index=np.arange(10), + index=np.arange(10) ) assert len(dm.columns) == 2 @@ -1192,7 +1192,7 @@ def test_constructor_list_of_odicts(self): OrderedDict([["a", 1.5], ["d", 6]]), OrderedDict(), OrderedDict([["a", 1.5], ["b", 3], ["c", 4]]), - OrderedDict([["b", 3], ["c", 4], ["d", 6]]), + OrderedDict([["b", 3], ["c", 4], ["d", 6]]) ] result = DataFrame(data) @@ -1256,7 +1256,7 @@ def test_constructor_ordered_dict_conflicting_orders(self): def test_constructor_list_of_series(self): data = [ OrderedDict([["a", 1.5], ["b", 3.0], ["c", 4.0]]), - OrderedDict([["a", 1.5], ["b", 3.0], ["c", 6.0]]), + OrderedDict([["a", 1.5], ["b", 3.0], ["c", 6.0]]) ] sdict = OrderedDict(zip(["x", "y"], data)) idx = Index(["a", "b", "c"]) @@ -1264,7 +1264,7 @@ def test_constructor_list_of_series(self): # all named data2 = [ Series([1.5, 3, 4], idx, dtype="O", name="x"), - Series([1.5, 3, 6], idx, name="y"), + Series([1.5, 3, 6], idx, name="y") ] result = DataFrame(data2) expected = DataFrame.from_dict(sdict, orient="index") @@ -1273,7 +1273,7 @@ def test_constructor_list_of_series(self): # some unnamed data2 = [ Series([1.5, 3, 4], idx, dtype="O", name="x"), - Series([1.5, 3, 6], idx), + Series([1.5, 3, 6], idx) ] result = DataFrame(data2) @@ -1288,7 +1288,7 @@ def test_constructor_list_of_series(self): OrderedDict([["a", 1.5], ["d", 6]]), OrderedDict(), OrderedDict([["a", 1.5], ["b", 3], ["c", 4]]), - OrderedDict([["b", 3], ["c", 4], ["d", 6]]), + OrderedDict([["b", 3], ["c", 4], ["d", 6]]) ] data = [ create_series_with_explicit_dtype(d, dtype_if_empty=object) for d in data @@ -1308,7 +1308,7 @@ def test_constructor_list_of_series(self): data = [ OrderedDict([["a", 1.5], ["b", 3.0], ["c", 4.0]]), - OrderedDict([["a", 1.5], ["b", 3.0], ["c", 6.0]]), + OrderedDict([["a", 1.5], ["b", 3.0], ["c", 6.0]]) ] sdict = OrderedDict(zip(range(len(data)), data)) @@ -1324,7 +1324,7 @@ def test_constructor_list_of_series_aligned_index(self): expected = DataFrame( {"b": [0, 1, 2], "a": [0, 1, 2], "c": [0, 1, 2]}, columns=["b", "a", "c"], - index=["0", "1", "2"], + index=["0", "1", "2"] ) tm.assert_frame_equal(result, expected) @@ -1389,8 +1389,8 @@ 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]]), - ], + (([1, 2, 3], [4, 5, 6]), [[1, 2, 3], [4, 5, 6]]) + ] ) def test_constructor_tuple(self, tuples, lists): # GH 25691 @@ -1461,7 +1461,7 @@ def test_constructor_list_of_dict_order(self): data = [ {"First": 1, "Second": 4, "Third": 7, "Fourth": 10}, {"Second": 5, "First": 2, "Fourth": 11, "Third": 8}, - {"Second": 6, "First": 3, "Fourth": 12, "Third": 9, "YYY": 14, "XXX": 13}, + {"Second": 6, "First": 3, "Fourth": 12, "Third": 9, "YYY": 14, "XXX": 13} ] expected = DataFrame( { @@ -1470,7 +1470,7 @@ def test_constructor_list_of_dict_order(self): "Third": [7, 8, 9], "Fourth": [10, 11, 12], "YYY": [None, None, 14], - "XXX": [None, None, 13], + "XXX": [None, None, 13] } ) result = DataFrame(data) @@ -1494,7 +1494,7 @@ def test_constructor_from_ordered_dict(self): [ ("one", OrderedDict([("col_a", "foo1"), ("col_b", "bar1")])), ("two", OrderedDict([("col_a", "foo2"), ("col_b", "bar2")])), - ("three", OrderedDict([("col_a", "foo3"), ("col_b", "bar3")])), + ("three", OrderedDict([("col_a", "foo3"), ("col_b", "bar3")])) ] ) expected = DataFrame.from_dict(a, orient="columns").T @@ -1508,7 +1508,7 @@ def test_from_dict_columns_parameter(self): result = DataFrame.from_dict( OrderedDict([("A", [1, 2]), ("B", [4, 5])]), orient="index", - columns=["one", "two"], + columns=["one", "two"] ) expected = DataFrame([[1, 2], [4, 5]], index=["A", "B"], columns=["one", "two"]) tm.assert_frame_equal(result, expected) @@ -1518,7 +1518,7 @@ def test_from_dict_columns_parameter(self): DataFrame.from_dict( dict([("A", [1, 2]), ("B", [4, 5])]), orient="columns", - columns=["one", "two"], + columns=["one", "two"] ) with pytest.raises(ValueError, match=msg): DataFrame.from_dict( @@ -1531,8 +1531,8 @@ def test_from_dict_columns_parameter(self): ({}, [], "index"), ([{("a",): 1}, {("a",): 2}], [("a",)], "columns"), ([OrderedDict([(("a",), 1), (("b",), 2)])], [("a",), ("b",)], "columns"), - ([{("a", "b"): 1}], [("a", "b")], "columns"), - ], + ([{("a", "b"): 1}], [("a", "b")], "columns") + ] ) def test_constructor_from_dict_tuples(self, data_dict, keys, orient): # GH 16769 @@ -1624,15 +1624,15 @@ def test_constructor_Series_differently_indexed(self): ("idx1", "idx2", None, None), ("idx1", "idx1", "idx2", None), ("idx1", "idx2", "idx3", None), - (None, None, None, None), - ], + (None, None, None, None) + ] ) def test_constructor_index_names(self, name_in1, name_in2, name_in3, name_out): # GH13475 indices = [ pd.Index(["a", "b", "c"], name=name_in1), pd.Index(["b", "c", "d"], name=name_in2), - pd.Index(["c", "d", "e"], name=name_in3), + pd.Index(["c", "d", "e"], name=name_in3) ] series = { c: pd.Series([0, 1, 2], index=i) for i, c in zip(indices, ["x", "y", "z"]) @@ -1644,9 +1644,9 @@ def test_constructor_index_names(self, name_in1, name_in2, name_in3, name_out): { "x": [0, 1, 2, np.nan, np.nan], "y": [np.nan, 0, 1, 2, np.nan], - "z": [np.nan, np.nan, 0, 1, 2], + "z": [np.nan, np.nan, 0, 1, 2] }, - index=exp_ind, + index=exp_ind ) tm.assert_frame_equal(result, expected) @@ -1727,8 +1727,8 @@ def test_constructor_single_value(self): DataFrame( np.array([["a", "a"], ["a", "a"]], dtype=object), index=[1, 2], - columns=["a", "c"], - ), + columns=["a", "c"] + ) ) msg = "DataFrame constructor not properly called!" @@ -1754,16 +1754,16 @@ def test_constructor_with_datetimes(self): "B": "foo", "C": "bar", "D": Timestamp("20010101"), - "E": datetime(2001, 1, 2, 0, 0), + "E": datetime(2001, 1, 2, 0, 0) }, - index=np.arange(10), + index=np.arange(10) ) result = df.dtypes expected = Series( [np.dtype("int64")] + [np.dtype(objectname)] * 2 + [np.dtype(datetime64name)] * 2, - index=list("ABCDE"), + index=list("ABCDE") ) tm.assert_series_equal(result, expected) @@ -1775,9 +1775,9 @@ def test_constructor_with_datetimes(self): "b": 2, "c": "foo", floatname: np.array(1.0, dtype=floatname), - intname: np.array(1, dtype=intname), + intname: np.array(1, dtype=intname) }, - index=np.arange(10), + index=np.arange(10) ) result = df.dtypes expected = Series( @@ -1786,7 +1786,7 @@ def test_constructor_with_datetimes(self): + [np.dtype("object")] + [np.dtype("float64")] + [np.dtype(intname)], - index=["a", "b", "c", floatname, intname], + index=["a", "b", "c", floatname, intname] ) tm.assert_series_equal(result, expected) @@ -1797,9 +1797,9 @@ def test_constructor_with_datetimes(self): "b": 2, "c": "foo", floatname: np.array([1.0] * 10, dtype=floatname), - intname: np.array([1] * 10, dtype=intname), + intname: np.array([1] * 10, dtype=intname) }, - index=np.arange(10), + index=np.arange(10) ) result = df.dtypes expected = Series( @@ -1808,7 +1808,7 @@ def test_constructor_with_datetimes(self): + [np.dtype("object")] + [np.dtype("float64")] + [np.dtype(intname)], - index=["a", "b", "c", floatname, intname], + index=["a", "b", "c", floatname, intname] ) tm.assert_series_equal(result, expected) @@ -1827,7 +1827,7 @@ def test_constructor_with_datetimes(self): result = df.dtypes expected = Series( [np.dtype("datetime64[ns]"), np.dtype("object")], - index=["datetimes", "dates"], + index=["datetimes", "dates"] ) tm.assert_series_equal(result, expected) @@ -1890,8 +1890,8 @@ def test_constructor_with_datetimes(self): [[None], [np.datetime64("NaT")]], [[None], [pd.NaT]], [[pd.NaT], [np.datetime64("NaT")]], - [[pd.NaT], [None]], - ], + [[pd.NaT], [None]] + ] ) def test_constructor_datetimes_with_nulls(self, arr): # gh-15869, GH#11220 @@ -1942,7 +1942,7 @@ def test_constructor_for_list_with_dtypes(self): "b": [1.2, 2.3, 5.1, 6.3], "c": list("abcd"), "d": [datetime(2000, 1, 1) for i in range(4)], - "e": [1.0, 2, 4.0, 7], + "e": [1.0, 2, 4.0, 7] } ) result = df.dtypes @@ -1952,9 +1952,9 @@ def test_constructor_for_list_with_dtypes(self): np.dtype("float64"), np.dtype("object"), np.dtype("datetime64[ns]"), - np.dtype("float64"), + np.dtype("float64") ], - index=list("abcde"), + index=list("abcde") ) tm.assert_series_equal(result, expected) @@ -2059,9 +2059,9 @@ def test_constructor_categorical(self): expected = DataFrame( { 0: Series(list("abc"), dtype="category"), - 1: Series(list("abd"), dtype="category"), + 1: Series(list("abd"), dtype="category") }, - columns=[0, 1], + columns=[0, 1] ) tm.assert_frame_equal(df, expected) @@ -2150,8 +2150,8 @@ def test_from_records_iterator(self): ("x", np.float64), ("u", np.float32), ("y", np.int64), - ("z", np.int32), - ], + ("z", np.int32) + ] ) df = DataFrame.from_records(iter(arr), nrows=2) xp = DataFrame( @@ -2159,7 +2159,7 @@ def test_from_records_iterator(self): "x": np.array([1.0, 3.0], dtype=np.float64), "u": np.array([1.0, 3.0], dtype=np.float32), "y": np.array([2, 4], dtype=np.int64), - "z": np.array([2, 4], dtype=np.int32), + "z": np.array([2, 4], dtype=np.int32) } ) tm.assert_frame_equal(df.reindex_like(xp), xp) @@ -2237,7 +2237,7 @@ def create_dict(order_id): return { "order_id": order_id, "quantity": np.random.randint(1, 10), - "price": np.random.randint(1, 10), + "price": np.random.randint(1, 10) } documents = [create_dict(i) for i in range(10)] @@ -2319,7 +2319,7 @@ def test_from_records_empty_with_nonempty_fields_gh3682(self): + tm.COMPLEX_DTYPES + tm.DATETIME64_DTYPES + tm.TIMEDELTA64_DTYPES - + tm.BOOL_DTYPES, + + tm.BOOL_DTYPES ) def test_check_dtype_empty_numeric_column(self, dtype): # GH24386: Ensure dtypes are set correctly for an empty DataFrame. @@ -2377,7 +2377,7 @@ def test_from_records_sequencelike(self): "D": np.array([True, False] * 3, dtype=bool), "E": np.array(np.random.randn(6), dtype=np.float32), "E1": np.array(np.random.randn(6), dtype=np.float32), - "F": np.array(np.arange(6), dtype=np.int32), + "F": np.array(np.arange(6), dtype=np.int32) } ) @@ -2458,7 +2458,7 @@ def test_from_records_dictlike(self): "D": np.array([True, False] * 3, dtype=bool), "E": np.array(np.random.randn(6), dtype=np.float32), "E1": np.array(np.random.randn(6), dtype=np.float32), - "F": np.array(np.arange(6), dtype=np.int32), + "F": np.array(np.arange(6), dtype=np.int32) } ) @@ -2597,8 +2597,8 @@ class List(list): Categorical(list("aabbc")), 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")), - ], + PeriodArray(pd.period_range(start="1/1/2017", end="1/1/2018", freq="M")) + ] ) def test_constructor_with_extension_array(self, extension_arr): # GH11363 @@ -2621,14 +2621,14 @@ def test_construct_with_two_categoricalindex_series(self): ) s2 = Series( [2, 152, 2, 242, 150], - index=pd.CategoricalIndex(["f", "female", "m", "male", "unknown"]), + index=pd.CategoricalIndex(["f", "female", "m", "male", "unknown"]) ) result = DataFrame([s1, s2]) expected = DataFrame( np.array( [[np.nan, 39.0, np.nan, 6.0, 4.0], [2.0, 152.0, 2.0, 242.0, 150.0]] ), - columns=["f", "female", "m", "male", "unknown"], + columns=["f", "female", "m", "male", "unknown"] ) tm.assert_frame_equal(result, expected) @@ -2724,7 +2724,7 @@ def test_frame_timeseries_column(self): "timestamps": [ Timestamp("20130101T10:00:00", tz="US/Eastern"), Timestamp("20130101T10:01:00", tz="US/Eastern"), - Timestamp("20130101T10:02:00", tz="US/Eastern"), + Timestamp("20130101T10:02:00", tz="US/Eastern") ] } ) @@ -2735,13 +2735,13 @@ def test_nested_dict_construction(self): columns = ["Nevada", "Ohio"] pop = { "Nevada": {2001: 2.4, 2002: 2.9}, - "Ohio": {2000: 1.5, 2001: 1.7, 2002: 3.6}, + "Ohio": {2000: 1.5, 2001: 1.7, 2002: 3.6} } result = DataFrame(pop, index=[2001, 2002, 2003], columns=columns) expected = DataFrame( [(2.4, 1.7), (2.9, 3.6), (np.nan, np.nan)], columns=columns, - index=Index([2001, 2002, 2003]), + index=Index([2001, 2002, 2003]) ) tm.assert_frame_equal(result, expected) @@ -2761,27 +2761,27 @@ def test_from_tzaware_mixed_object_array(self): [ Timestamp("2013-01-01 00:00:00"), Timestamp("2013-01-02 00:00:00"), - Timestamp("2013-01-03 00:00:00"), + Timestamp("2013-01-03 00:00:00") ], [ Timestamp("2013-01-01 00:00:00-0500", tz="US/Eastern"), pd.NaT, - Timestamp("2013-01-03 00:00:00-0500", tz="US/Eastern"), + Timestamp("2013-01-03 00:00:00-0500", tz="US/Eastern") ], [ Timestamp("2013-01-01 00:00:00+0100", tz="CET"), pd.NaT, - Timestamp("2013-01-03 00:00:00+0100", tz="CET"), - ], + Timestamp("2013-01-03 00:00:00+0100", tz="CET") + ] ], - dtype=object, + dtype=object ).T res = DataFrame(arr, columns=["A", "B", "C"]) expected_dtypes = [ "datetime64[ns]", "datetime64[ns, US/Eastern]", - "datetime64[ns, CET]", + "datetime64[ns, CET]" ] assert (res.dtypes == expected_dtypes).all() diff --git a/pandas/tests/frame/test_reshape.py b/pandas/tests/frame/test_reshape.py index 6a8f1e7c1aca2..d344ff55d84c6 100644 --- a/pandas/tests/frame/test_reshape.py +++ b/pandas/tests/frame/test_reshape.py @@ -14,7 +14,7 @@ def test_pivot(self): data = { "index": ["A", "B", "C", "C", "B", "A"], "columns": ["One", "One", "One", "Two", "Two", "Two"], - "values": [1.0, 2.0, 3.0, 3.0, 2.0, 1.0], + "values": [1.0, 2.0, 3.0, 3.0, 2.0, 1.0] } frame = DataFrame(data) @@ -23,7 +23,7 @@ def test_pivot(self): expected = DataFrame( { "One": {"A": 1.0, "B": 2.0, "C": 3.0}, - "Two": {"A": 1.0, "B": 2.0, "C": 3.0}, + "Two": {"A": 1.0, "B": 2.0, "C": 3.0} } ) @@ -44,7 +44,7 @@ def test_pivot_duplicates(self): { "a": ["bar", "bar", "foo", "foo", "foo"], "b": ["one", "two", "one", "one", "two"], - "c": [1.0, 2.0, 3.0, 3.0, 4.0], + "c": [1.0, 2.0, 3.0, 3.0, 4.0] } ) with pytest.raises(ValueError, match="duplicate entries"): @@ -68,7 +68,7 @@ def test_pivot_index_none(self): data = { "index": ["A", "B", "C", "C", "B", "A"], "columns": ["One", "One", "One", "Two", "Two", "Two"], - "values": [1.0, 2.0, 3.0, 3.0, 2.0, 1.0], + "values": [1.0, 2.0, 3.0, 3.0, 2.0, 1.0] } frame = DataFrame(data).set_index("index") @@ -76,7 +76,7 @@ def test_pivot_index_none(self): expected = DataFrame( { "One": {"A": 1.0, "B": 2.0, "C": 3.0}, - "Two": {"A": 1.0, "B": 2.0, "C": 3.0}, + "Two": {"A": 1.0, "B": 2.0, "C": 3.0} } ) @@ -247,14 +247,14 @@ def test_unstack_fill_frame_datetime(self): result = data.unstack() expected = DataFrame( {"a": [dv[0], pd.NaT, dv[3]], "b": [dv[1], dv[2], pd.NaT]}, - index=["x", "y", "z"], + index=["x", "y", "z"] ) tm.assert_frame_equal(result, expected) result = data.unstack(fill_value=dv[0]) expected = DataFrame( {"a": [dv[0], dv[0], dv[3]], "b": [dv[1], dv[2], dv[0]]}, - index=["x", "y", "z"], + index=["x", "y", "z"] ) tm.assert_frame_equal(result, expected) @@ -270,14 +270,14 @@ def test_unstack_fill_frame_timedelta(self): result = data.unstack() expected = DataFrame( {"a": [td[0], pd.NaT, td[3]], "b": [td[1], td[2], pd.NaT]}, - index=["x", "y", "z"], + index=["x", "y", "z"] ) tm.assert_frame_equal(result, expected) result = data.unstack(fill_value=td[1]) expected = DataFrame( {"a": [td[0], td[1], td[3]], "b": [td[1], td[2], td[1]]}, - index=["x", "y", "z"], + index=["x", "y", "z"] ) tm.assert_frame_equal(result, expected) @@ -288,7 +288,7 @@ def test_unstack_fill_frame_period(self): Period("2012-01"), Period("2012-02"), Period("2012-03"), - Period("2012-04"), + Period("2012-04") ] data = Series(periods) data.index = MultiIndex.from_tuples( @@ -298,7 +298,7 @@ def test_unstack_fill_frame_period(self): result = data.unstack() expected = DataFrame( {"a": [periods[0], None, periods[3]], "b": [periods[1], periods[2], None]}, - index=["x", "y", "z"], + index=["x", "y", "z"] ) tm.assert_frame_equal(result, expected) @@ -306,9 +306,9 @@ def test_unstack_fill_frame_period(self): expected = DataFrame( { "a": [periods[0], periods[1], periods[3]], - "b": [periods[1], periods[2], periods[1]], + "b": [periods[1], periods[2], periods[1]] }, - index=["x", "y", "z"], + index=["x", "y", "z"] ) tm.assert_frame_equal(result, expected) @@ -325,9 +325,9 @@ def test_unstack_fill_frame_categorical(self): expected = DataFrame( { "a": pd.Categorical(list("axa"), categories=list("abc")), - "b": pd.Categorical(list("bcx"), categories=list("abc")), + "b": pd.Categorical(list("bcx"), categories=list("abc")) }, - index=list("xyz"), + index=list("xyz") ) tm.assert_frame_equal(result, expected) @@ -341,9 +341,9 @@ def test_unstack_fill_frame_categorical(self): expected = DataFrame( { "a": pd.Categorical(list("aca"), categories=list("abc")), - "b": pd.Categorical(list("bcc"), categories=list("abc")), + "b": pd.Categorical(list("bcc"), categories=list("abc")) }, - index=list("xyz"), + index=list("xyz") ) tm.assert_frame_equal(result, expected) @@ -364,11 +364,11 @@ def test_unstack_tuplename_in_multiindex(self): ("d", "c"), ("e", "a"), ("e", "b"), - ("e", "c"), + ("e", "c") ], - names=[None, ("A", "a")], + names=[None, ("A", "a")] ), - index=pd.Index([1, 2, 3], name=("B", "b")), + index=pd.Index([1, 2, 3], name=("B", "b")) ) tm.assert_frame_equal(result, expected) @@ -383,8 +383,8 @@ def test_unstack_tuplename_in_multiindex(self): ), pd.MultiIndex.from_tuples( [("d", "a"), ("d", "b"), ("e", "a"), ("e", "b")], - names=[None, ("A", "a")], - ), + names=[None, ("A", "a")] + ) ), ( (("A", "a"), "B"), @@ -399,12 +399,12 @@ def test_unstack_tuplename_in_multiindex(self): ("e", "a", 1), ("e", "a", 2), ("e", "b", 1), - ("e", "b", 2), + ("e", "b", 2) ], - names=[None, ("A", "a"), "B"], - ), - ), - ], + 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,7 @@ 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) @@ -435,7 +435,7 @@ def test_unstack_preserve_dtypes(self): E=pd.Series([1.0, 50.0, 100.0]).astype("float32"), F=pd.Series([3.0, 4.0, 5.0]).astype("float64"), G=False, - H=pd.Series([1, 200, 923442], dtype="int8"), + H=pd.Series([1, 200, 923442], dtype="int8") ) ) @@ -486,9 +486,9 @@ def test_stack_mixed_levels(self): ("A", "cat", "long"), ("B", "cat", "long"), ("A", "dog", "short"), - ("B", "dog", "short"), + ("B", "dog", "short") ], - names=["exp", "animal", "hair_length"], + names=["exp", "animal", "hair_length"] ) df = DataFrame(np.random.randn(4, 4), columns=columns) @@ -530,9 +530,9 @@ def test_stack_int_level_names(self): ("A", "cat", "long"), ("B", "cat", "long"), ("A", "dog", "short"), - ("B", "dog", "short"), + ("B", "dog", "short") ], - names=["exp", "animal", "hair_length"], + names=["exp", "animal", "hair_length"] ) df = DataFrame(np.random.randn(4, 4), columns=columns) @@ -569,13 +569,13 @@ def test_unstack_bool(self): df = DataFrame( [False, False], index=MultiIndex.from_arrays([["a", "b"], ["c", "l"]]), - columns=["col"], + columns=["col"] ) rs = df.unstack() xp = DataFrame( np.array([[False, np.nan], [np.nan, False]], dtype=object), index=["a", "b"], - columns=MultiIndex.from_arrays([["col", "col"], ["c", "l"]]), + columns=MultiIndex.from_arrays([["col", "col"], ["c", "l"]]) ) tm.assert_frame_equal(rs, xp) @@ -584,7 +584,7 @@ def test_unstack_level_binding(self): mi = pd.MultiIndex( levels=[["foo", "bar"], ["one", "two"], ["a", "b"]], codes=[[0, 0, 1, 1], [0, 1, 0, 1], [1, 0, 1, 0]], - names=["first", "second", "third"], + names=["first", "second", "third"] ) s = pd.Series(0, index=mi) result = s.unstack([1, 2]).stack(0) @@ -592,7 +592,7 @@ def test_unstack_level_binding(self): expected_mi = pd.MultiIndex( levels=[["foo", "bar"], ["one", "two"]], codes=[[0, 0, 1, 1], [0, 1, 0, 1]], - names=["first", "second"], + names=["first", "second"] ) expected = pd.DataFrame( @@ -600,7 +600,7 @@ def test_unstack_level_binding(self): [[np.nan, 0], [0, np.nan], [np.nan, 0], [0, np.nan]], dtype=np.float64 ), index=expected_mi, - columns=pd.Index(["a", "b"], name="third"), + columns=pd.Index(["a", "b"], name="third") ) tm.assert_frame_equal(result, expected) @@ -620,7 +620,7 @@ def test_unstack_to_series(self, float_frame): midx = MultiIndex( levels=[["x", "y"], ["a", "b", "c"]], - codes=[[0, 0, 0, 1, 1, 1], [0, 1, 2, 0, 1, 2]], + codes=[[0, 0, 0, 1, 1, 1], [0, 1, 2, 0, 1, 2]] ) expected = Series([1, 2, np.NaN, 3, 4, np.NaN], index=midx) @@ -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,14 +673,14 @@ 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) # GH7405 for c, d in ( (np.zeros(5), np.zeros(5)), - (np.arange(5, dtype="f8"), np.arange(5, 10, dtype="f8")), + (np.arange(5, dtype="f8"), np.arange(5, 10, dtype="f8")) ): df = DataFrame( @@ -688,7 +688,7 @@ def test_unstack_dtypes(self): "A": ["a"] * 5, "C": c, "D": d, - "B": pd.date_range("2012-01-01", periods=5), + "B": pd.date_range("2012-01-01", periods=5) } ) @@ -747,7 +747,7 @@ def test_unstack_unused_levels(self): cases = ( (0, [13, 16, 6, 9, 2, 5, 8, 11], [np.nan, "a", 2], [np.nan, 5, 1]), - (1, [8, 11, 1, 4, 12, 15, 13, 16], [np.nan, 5, 1], [np.nan, "a", 2]), + (1, [8, 11, 1, 4, 12, 15, 13, 16], [np.nan, 5, 1], [np.nan, "a", 2]) ) for level, idces, col_level, idx_level in cases: result = df.unstack(level=level) @@ -785,17 +785,17 @@ def test_unstack_long_index(self): columns=pd.MultiIndex.from_tuples([[0]], names=["c1"]), index=pd.MultiIndex.from_tuples( [[0, 0, 1, 0, 0, 0, 1]], - names=["i1", "i2", "i3", "i4", "i5", "i6", "i7"], - ), + names=["i1", "i2", "i3", "i4", "i5", "i6", "i7"] + ) ) result = df.unstack(["i2", "i3", "i4", "i5", "i6", "i7"]) expected = pd.DataFrame( [[1]], columns=pd.MultiIndex.from_tuples( [[0, 0, 1, 0, 0, 0, 1]], - names=["c1", "i2", "i3", "i4", "i5", "i6", "i7"], + names=["c1", "i2", "i3", "i4", "i5", "i6", "i7"] ), - index=pd.Index([0], name="i1"), + index=pd.Index([0], name="i1") ) tm.assert_frame_equal(result, expected) @@ -807,8 +807,8 @@ 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"] @@ -822,10 +822,10 @@ def test_unstack_multi_level_rows_and_cols(self): ["m1", "P3", 222], ["m1", "A5", 111], ["m2", "P3", 222], - ["m2", "A5", 111], + ["m2", "A5", 111] ], - names=["i1", "i2", "i3"], - ), + names=["i1", "i2", "i3"] + ) ) result = df.unstack(["i3", "i2"]) expected = df.unstack(["i3"]).unstack(["i2"]) @@ -849,7 +849,7 @@ def verify(df): { "jim": ["a", "b", np.nan, "d"], "joe": ["w", "x", "y", "z"], - "jolie": ["a.w", "b.x", " .y", "d.z"], + "jolie": ["a.w", "b.x", " .y", "d.z"] } ) @@ -899,14 +899,14 @@ def verify(df): 14, 53, 60, - 51, - ], + 51 + ] } ) df["4th"], df["5th"] = ( df.apply(lambda r: ".".join(map(cast, r)), axis=1), - df.apply(lambda r: ".".join(map(cast, r.iloc[::-1])), axis=1), + df.apply(lambda r: ".".join(map(cast, r.iloc[::-1])), axis=1) ) for idx in itertools.permutations(["1st", "2nd", "3rd"]): @@ -924,7 +924,7 @@ def verify(df): vals = [ [3, 0, 1, 2, np.nan, np.nan, np.nan, np.nan], - [np.nan, np.nan, np.nan, np.nan, 4, 5, 6, 7], + [np.nan, np.nan, np.nan, np.nan, 4, 5, 6, 7] ] vals = list(map(list, zip(*vals))) idx = Index([np.nan, 0, 1, 2, 4, 5, 6, 7], name="B") @@ -966,7 +966,7 @@ def verify(df): { "A": list("aaaaabbbbb"), "B": (date_range("2012-01-01", periods=5).tolist() * 2), - "C": np.arange(10), + "C": np.arange(10) } ) @@ -978,7 +978,7 @@ def verify(df): cols = MultiIndex( levels=[["C"], date_range("2012-01-01", periods=5)], codes=[[0, 0, 0, 0, 0, 0], [-1, 0, 1, 2, 3, 4]], - names=[None, "B"], + names=[None, "B"] ) right = DataFrame(vals, columns=cols, index=idx) @@ -991,31 +991,31 @@ def verify(df): ["Pb", 7.07e-06, np.nan, 680585148], ["Sn", 2.3614e-05, 0.0133, 680607017], ["Ag", 0.0, 0.0133, 680607017], - ["Hg", -0.00015, 0.0133, 680607017], + ["Hg", -0.00015, 0.0133, 680607017] ] df = DataFrame( vals, columns=["agent", "change", "dosage", "s_id"], - index=[17263, 17264, 17265, 17266, 17267, 17268], + index=[17263, 17264, 17265, 17266, 17267, 17268] ) left = df.copy().set_index(["s_id", "dosage", "agent"]).unstack() vals = [ [np.nan, np.nan, 7.07e-06, np.nan, 0.0], - [0.0, -0.00015, np.nan, 2.3614e-05, np.nan], + [0.0, -0.00015, np.nan, 2.3614e-05, np.nan] ] idx = MultiIndex( levels=[[680585148, 680607017], [0.0133]], codes=[[0, 1], [-1, 0]], - names=["s_id", "dosage"], + names=["s_id", "dosage"] ) cols = MultiIndex( levels=[["change"], ["Ag", "Hg", "Pb", "Sn", "U"]], codes=[[0, 0, 0, 0, 0], [0, 1, 2, 3, 4]], - names=[None, "agent"], + names=[None, "agent"] ) right = DataFrame(vals, columns=cols, index=idx) @@ -1030,7 +1030,7 @@ def verify(df): "1st": [1, 2, 1, 2, 1, 2], "2nd": pd.date_range("2014-02-01", periods=6, freq="D"), "jim": 100 + np.arange(6), - "joe": (np.random.randn(6) * 10).round(2), + "joe": (np.random.randn(6) * 10).round(2) } ) @@ -1062,7 +1062,7 @@ def test_stack_partial_multiIndex(self): def _test_stack_with_multiindex(multiindex): df = DataFrame( np.arange(3 * len(multiindex)).reshape(3, len(multiindex)), - columns=multiindex, + columns=multiindex ) for level in (-1, 0, 1, [0, 1], [1, 0]): result = df.stack(level=level, dropna=False) @@ -1088,7 +1088,7 @@ def _test_stack_with_multiindex(multiindex): full_multiindex = MultiIndex.from_tuples( [("B", "x"), ("B", "z"), ("A", "y"), ("C", "x"), ("C", "u")], - names=["Upper", "Lower"], + names=["Upper", "Lower"] ) for multiindex_columns in ( [0, 1, 2, 3, 4], @@ -1102,7 +1102,7 @@ def _test_stack_with_multiindex(multiindex): [0, 3], [0], [2], - [4], + [4] ): _test_stack_with_multiindex(full_multiindex[multiindex_columns]) if len(multiindex_columns) > 1: @@ -1116,10 +1116,10 @@ def _test_stack_with_multiindex(multiindex): index=MultiIndex( levels=[[0, 1], ["u", "x", "y", "z"]], codes=[[0, 0, 1, 1], [1, 3, 1, 3]], - names=[None, "Lower"], + names=[None, "Lower"] ), columns=Index(["B", "C"], name="Upper"), - dtype=df.dtypes[0], + dtype=df.dtypes[0] ) tm.assert_frame_equal(result, expected) @@ -1154,8 +1154,8 @@ 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"]])), - ], + ([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 @@ -1178,9 +1178,9 @@ def test_unstack_mixed_extension_types(self, level): df = pd.DataFrame( { "A": pd.core.arrays.integer_array([0, 1, None]), - "B": pd.Categorical(["a", "a", "b"]), + "B": pd.Categorical(["a", "a", "b"]) }, - index=index, + index=index ) result = df.unstack(level=level) @@ -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" @@ -1240,9 +1240,9 @@ def test_unstack_timezone_aware_values(): "timestamp": [pd.Timestamp("2017-08-27 01:00:00.709949+0000", tz="UTC")], "a": ["a"], "b": ["b"], - "c": ["c"], + "c": ["c"] }, - columns=["timestamp", "a", "b", "c"], + columns=["timestamp", "a", "b", "c"] ) result = df.set_index(["a", "b"]).unstack() expected = pd.DataFrame( @@ -1251,8 +1251,8 @@ def test_unstack_timezone_aware_values(): columns=pd.MultiIndex( levels=[["timestamp", "c"], ["b"]], codes=[[0, 1], [0, 0]], - names=[None, "b"], - ), + 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) @@ -1281,7 +1281,7 @@ def test_unstacking_multi_index_df(): "score": [9.5, 8], "employed": [False, True], "kids": [0, 0], - "gender": ["female", "male"], + "gender": ["female", "male"] } ) df = df.set_index(["name", "employed", "kids", "gender"]) @@ -1296,9 +1296,9 @@ def test_unstacking_multi_index_df(): ("score", "female", False, 0), ("score", "female", True, 0), ("score", "male", False, 0), - ("score", "male", True, 0), + ("score", "male", True, 0) ], - names=[None, "gender", "employed", "kids"], - ), + 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..6e6d25a67c50f 100644 --- a/pandas/tests/generic/test_finalize.py +++ b/pandas/tests/generic/test_finalize.py @@ -33,14 +33,14 @@ ( pd.Series, (np.array([0], dtype="float64")), - operator.methodcaller("view", "int64"), + operator.methodcaller("view", "int64") ), (pd.Series, ([0],), operator.methodcaller("take", [])), (pd.Series, ([0],), operator.methodcaller("__getitem__", [True])), (pd.Series, ([0],), operator.methodcaller("repeat", 2)), pytest.param( (pd.Series, ([0],), operator.methodcaller("reset_index")), - marks=pytest.mark.xfail, + marks=pytest.mark.xfail ), (pd.Series, ([0],), operator.methodcaller("reset_index", drop=True)), pytest.param( @@ -69,25 +69,25 @@ ( pd.Series, ([0], pd.period_range("2000", periods=1)), - operator.methodcaller("to_timestamp"), + operator.methodcaller("to_timestamp") ), ( pd.Series, ([0], pd.date_range("2000", periods=1)), - operator.methodcaller("to_period"), + operator.methodcaller("to_period") ), pytest.param( ( pd.DataFrame, frame_data, - operator.methodcaller("dot", pd.DataFrame(index=["A"])), + operator.methodcaller("dot", pd.DataFrame(index=["A"])) ), - marks=pytest.mark.xfail(reason="Implement binary finalize"), + marks=pytest.mark.xfail(reason="Implement binary finalize") ), (pd.DataFrame, frame_data, operator.methodcaller("transpose")), pytest.param( (pd.DataFrame, frame_data, operator.methodcaller("__getitem__", "A")), - marks=not_implemented_mark, + marks=not_implemented_mark ), (pd.DataFrame, frame_data, operator.methodcaller("__getitem__", ["A"])), (pd.DataFrame, frame_data, operator.methodcaller("__getitem__", np.array([True]))), @@ -95,7 +95,7 @@ (pd.DataFrame, frame_data, operator.methodcaller("query", "A == 1")), pytest.param( (pd.DataFrame, frame_data, operator.methodcaller("eval", "A + 1")), - marks=not_implemented_mark, + marks=not_implemented_mark ), (pd.DataFrame, frame_data, operator.methodcaller("select_dtypes", include="int")), (pd.DataFrame, frame_data, operator.methodcaller("assign", b=1)), @@ -117,7 +117,7 @@ (pd.DataFrame, frame_data, operator.methodcaller("drop_duplicates")), pytest.param( (pd.DataFrame, frame_data, operator.methodcaller("duplicated")), - marks=not_implemented_mark, + marks=not_implemented_mark ), (pd.DataFrame, frame_data, operator.methodcaller("sort_values", by="A")), (pd.DataFrame, frame_data, operator.methodcaller("sort_index")), @@ -128,193 +128,193 @@ ( pd.DataFrame, frame_data, - operator.methodcaller("add", pd.DataFrame(*frame_data)), + operator.methodcaller("add", pd.DataFrame(*frame_data)) ), - marks=not_implemented_mark, + marks=not_implemented_mark ), # TODO: div, mul, etc. pytest.param( ( pd.DataFrame, frame_data, - operator.methodcaller("combine", pd.DataFrame(*frame_data), operator.add), + operator.methodcaller("combine", pd.DataFrame(*frame_data), operator.add) ), - marks=not_implemented_mark, + marks=not_implemented_mark ), pytest.param( ( pd.DataFrame, frame_data, - operator.methodcaller("combine_first", pd.DataFrame(*frame_data)), + operator.methodcaller("combine_first", pd.DataFrame(*frame_data)) ), - marks=not_implemented_mark, + marks=not_implemented_mark ), pytest.param( ( pd.DataFrame, frame_data, - operator.methodcaller("update", pd.DataFrame(*frame_data)), + operator.methodcaller("update", pd.DataFrame(*frame_data)) ), - marks=not_implemented_mark, + marks=not_implemented_mark ), pytest.param( (pd.DataFrame, frame_data, operator.methodcaller("pivot", columns="A")), - marks=not_implemented_mark, + marks=not_implemented_mark ), pytest.param( ( pd.DataFrame, {"A": [1], "B": [1]}, - operator.methodcaller("pivot_table", columns="A"), + operator.methodcaller("pivot_table", columns="A") ), - marks=not_implemented_mark, + marks=not_implemented_mark ), pytest.param( (pd.DataFrame, frame_data, operator.methodcaller("stack")), - marks=not_implemented_mark, + marks=not_implemented_mark ), pytest.param( (pd.DataFrame, frame_data, operator.methodcaller("explode", "A")), - marks=not_implemented_mark, + marks=not_implemented_mark ), pytest.param( (pd.DataFrame, frame_mi_data, operator.methodcaller("unstack"),), - marks=not_implemented_mark, + marks=not_implemented_mark ), pytest.param( ( pd.DataFrame, ({"A": ["a", "b", "c"], "B": [1, 3, 5], "C": [2, 4, 6]},), - operator.methodcaller("melt", id_vars=["A"], value_vars=["B"]), + operator.methodcaller("melt", id_vars=["A"], value_vars=["B"]) ), - marks=not_implemented_mark, + marks=not_implemented_mark ), pytest.param( (pd.DataFrame, frame_data, operator.methodcaller("diff")), - marks=not_implemented_mark, + marks=not_implemented_mark ), pytest.param( (pd.DataFrame, frame_data, operator.methodcaller("applymap", lambda x: x)), - marks=not_implemented_mark, + marks=not_implemented_mark ), pytest.param( ( pd.DataFrame, frame_data, - operator.methodcaller("append", pd.DataFrame({"A": [1]})), + operator.methodcaller("append", pd.DataFrame({"A": [1]})) ), - marks=not_implemented_mark, + marks=not_implemented_mark ), pytest.param( ( pd.DataFrame, frame_data, - operator.methodcaller("append", pd.DataFrame({"B": [1]})), + operator.methodcaller("append", pd.DataFrame({"B": [1]})) ), - marks=not_implemented_mark, + marks=not_implemented_mark ), pytest.param( ( pd.DataFrame, frame_data, - operator.methodcaller("merge", pd.DataFrame({"A": [1]})), + operator.methodcaller("merge", pd.DataFrame({"A": [1]})) ), - marks=not_implemented_mark, + marks=not_implemented_mark ), pytest.param( (pd.DataFrame, frame_data, operator.methodcaller("round", 2)), - marks=not_implemented_mark, + marks=not_implemented_mark ), pytest.param( (pd.DataFrame, frame_data, operator.methodcaller("corr")), - marks=not_implemented_mark, + marks=not_implemented_mark ), pytest.param( (pd.DataFrame, frame_data, operator.methodcaller("cov")), marks=[ not_implemented_mark, - pytest.mark.filterwarnings("ignore::RuntimeWarning"), - ], + pytest.mark.filterwarnings("ignore::RuntimeWarning") + ] ), pytest.param( ( pd.DataFrame, frame_data, - operator.methodcaller("corrwith", pd.DataFrame(*frame_data)), + operator.methodcaller("corrwith", pd.DataFrame(*frame_data)) ), - marks=not_implemented_mark, + marks=not_implemented_mark ), pytest.param( (pd.DataFrame, frame_data, operator.methodcaller("count")), - marks=not_implemented_mark, + marks=not_implemented_mark ), pytest.param( (pd.DataFrame, frame_mi_data, operator.methodcaller("count", level="A")), - marks=not_implemented_mark, + marks=not_implemented_mark ), pytest.param( (pd.DataFrame, frame_data, operator.methodcaller("nunique")), - marks=not_implemented_mark, + marks=not_implemented_mark ), pytest.param( (pd.DataFrame, frame_data, operator.methodcaller("idxmin")), - marks=not_implemented_mark, + marks=not_implemented_mark ), pytest.param( (pd.DataFrame, frame_data, operator.methodcaller("idxmax")), - marks=not_implemented_mark, + marks=not_implemented_mark ), pytest.param( (pd.DataFrame, frame_data, operator.methodcaller("mode")), - marks=not_implemented_mark, + marks=not_implemented_mark ), pytest.param( (pd.DataFrame, frame_data, operator.methodcaller("quantile")), - marks=not_implemented_mark, + marks=not_implemented_mark ), pytest.param( (pd.DataFrame, frame_data, operator.methodcaller("quantile", q=[0.25, 0.75])), - marks=not_implemented_mark, + marks=not_implemented_mark ), pytest.param( (pd.DataFrame, frame_data, operator.methodcaller("quantile")), - marks=not_implemented_mark, + marks=not_implemented_mark ), ( pd.DataFrame, ({"A": [1]}, [pd.Period("2000", "D")]), - operator.methodcaller("to_timestamp"), + operator.methodcaller("to_timestamp") ), ( pd.DataFrame, ({"A": [1]}, [pd.Timestamp("2000")]), - operator.methodcaller("to_period", freq="D"), + operator.methodcaller("to_period", freq="D") ), pytest.param( (pd.DataFrame, frame_mi_data, operator.methodcaller("isin", [1])), - marks=not_implemented_mark, + marks=not_implemented_mark ), pytest.param( (pd.DataFrame, frame_mi_data, operator.methodcaller("isin", pd.Series([1]))), - marks=not_implemented_mark, + marks=not_implemented_mark ), pytest.param( ( pd.DataFrame, frame_mi_data, - operator.methodcaller("isin", pd.DataFrame({"A": [1]})), + operator.methodcaller("isin", pd.DataFrame({"A": [1]})) ), - marks=not_implemented_mark, + marks=not_implemented_mark ), (pd.DataFrame, frame_data, operator.methodcaller("swapaxes", 0, 1)), (pd.DataFrame, frame_mi_data, operator.methodcaller("droplevel", "A")), pytest.param( (pd.DataFrame, frame_data, operator.methodcaller("pop", "A")), - marks=not_implemented_mark, + marks=not_implemented_mark ), pytest.param( (pd.DataFrame, frame_data, operator.methodcaller("squeeze")), - marks=not_implemented_mark, + marks=not_implemented_mark ), pytest.param( (pd.Series, ([1, 2],), operator.methodcaller("squeeze")), @@ -338,17 +338,17 @@ (pd.Series, (1, mi), operator.methodcaller("xs", "a")), pytest.param( (pd.DataFrame, frame_data, operator.methodcaller("get", "A")), - marks=not_implemented_mark, + marks=not_implemented_mark ), ( pd.DataFrame, frame_data, - operator.methodcaller("reindex_like", pd.DataFrame({"A": [1, 2, 3]})), + operator.methodcaller("reindex_like", pd.DataFrame({"A": [1, 2, 3]})) ), ( pd.Series, frame_data, - operator.methodcaller("reindex_like", pd.Series([0, 1, 2])), + operator.methodcaller("reindex_like", pd.Series([0, 1, 2])) ), (pd.DataFrame, frame_data, operator.methodcaller("add_prefix", "_")), (pd.DataFrame, frame_data, operator.methodcaller("add_suffix", "_")), @@ -369,12 +369,12 @@ ( pd.DataFrame, ({"A": np.array([1, 2], dtype=object)},), - operator.methodcaller("infer_objects"), + operator.methodcaller("infer_objects") ), (pd.Series, ([1, 2],), operator.methodcaller("convert_dtypes")), pytest.param( (pd.DataFrame, frame_data, operator.methodcaller("convert_dtypes")), - marks=not_implemented_mark, + marks=not_implemented_mark ), (pd.Series, ([1, None, 3],), operator.methodcaller("interpolate")), (pd.DataFrame, ({"A": [1, None, 3]},), operator.methodcaller("interpolate")), @@ -383,52 +383,52 @@ ( pd.Series, (1, pd.date_range("2000", periods=4)), - operator.methodcaller("asfreq", "H"), + operator.methodcaller("asfreq", "H") ), ( pd.DataFrame, ({"A": [1, 1, 1, 1]}, pd.date_range("2000", periods=4)), - operator.methodcaller("asfreq", "H"), + operator.methodcaller("asfreq", "H") ), ( pd.Series, (1, pd.date_range("2000", periods=4)), - operator.methodcaller("at_time", "12:00"), + operator.methodcaller("at_time", "12:00") ), ( pd.DataFrame, ({"A": [1, 1, 1, 1]}, pd.date_range("2000", periods=4)), - operator.methodcaller("at_time", "12:00"), + operator.methodcaller("at_time", "12:00") ), ( pd.Series, (1, pd.date_range("2000", periods=4)), - operator.methodcaller("between_time", "12:00", "13:00"), + operator.methodcaller("between_time", "12:00", "13:00") ), ( pd.DataFrame, ({"A": [1, 1, 1, 1]}, pd.date_range("2000", periods=4)), - operator.methodcaller("between_time", "12:00", "13:00"), + operator.methodcaller("between_time", "12:00", "13:00") ), ( pd.Series, (1, pd.date_range("2000", periods=4)), - operator.methodcaller("first", "3D"), + operator.methodcaller("first", "3D") ), ( pd.DataFrame, ({"A": [1, 1, 1, 1]}, pd.date_range("2000", periods=4)), - operator.methodcaller("first", "3D"), + operator.methodcaller("first", "3D") ), ( pd.Series, (1, pd.date_range("2000", periods=4)), - operator.methodcaller("last", "3D"), + operator.methodcaller("last", "3D") ), ( pd.DataFrame, ({"A": [1, 1, 1, 1]}, pd.date_range("2000", periods=4)), - operator.methodcaller("last", "3D"), + operator.methodcaller("last", "3D") ), (pd.Series, ([1, 2],), operator.methodcaller("rank")), (pd.DataFrame, frame_data, operator.methodcaller("rank")), @@ -442,66 +442,66 @@ ( pd.Series, (1, pd.date_range("2000", periods=4)), - operator.methodcaller("tshift"), + operator.methodcaller("tshift") ), - marks=pytest.mark.filterwarnings("ignore::FutureWarning"), + marks=pytest.mark.filterwarnings("ignore::FutureWarning") ), pytest.param( ( pd.DataFrame, ({"A": [1, 1, 1, 1]}, pd.date_range("2000", periods=4)), - operator.methodcaller("tshift"), + operator.methodcaller("tshift") ), - marks=pytest.mark.filterwarnings("ignore::FutureWarning"), + marks=pytest.mark.filterwarnings("ignore::FutureWarning") ), (pd.Series, ([1, 2],), operator.methodcaller("truncate", before=0)), (pd.DataFrame, frame_data, operator.methodcaller("truncate", before=0)), ( pd.Series, (1, pd.date_range("2000", periods=4, tz="UTC")), - operator.methodcaller("tz_convert", "CET"), + operator.methodcaller("tz_convert", "CET") ), ( pd.DataFrame, ({"A": [1, 1, 1, 1]}, pd.date_range("2000", periods=4, tz="UTC")), - operator.methodcaller("tz_convert", "CET"), + operator.methodcaller("tz_convert", "CET") ), ( pd.Series, (1, pd.date_range("2000", periods=4)), - operator.methodcaller("tz_localize", "CET"), + operator.methodcaller("tz_localize", "CET") ), ( pd.DataFrame, ({"A": [1, 1, 1, 1]}, pd.date_range("2000", periods=4)), - operator.methodcaller("tz_localize", "CET"), + operator.methodcaller("tz_localize", "CET") ), pytest.param( (pd.Series, ([1, 2],), operator.methodcaller("describe")), - marks=not_implemented_mark, + marks=not_implemented_mark ), pytest.param( (pd.DataFrame, frame_data, operator.methodcaller("describe")), - marks=not_implemented_mark, + marks=not_implemented_mark ), (pd.Series, ([1, 2],), operator.methodcaller("pct_change")), pytest.param( (pd.DataFrame, frame_data, operator.methodcaller("pct_change")), - marks=not_implemented_mark, + marks=not_implemented_mark ), (pd.Series, ([1],), operator.methodcaller("transform", lambda x: x - x.min())), pytest.param( ( pd.DataFrame, frame_mi_data, - operator.methodcaller("transform", lambda x: x - x.min()), + operator.methodcaller("transform", lambda x: x - x.min()) ), - marks=not_implemented_mark, + marks=not_implemented_mark ), (pd.Series, ([1],), operator.methodcaller("apply", lambda x: x)), pytest.param( (pd.DataFrame, frame_mi_data, operator.methodcaller("apply", lambda x: x)), - marks=not_implemented_mark, + marks=not_implemented_mark ), # Cumulative reductions (pd.Series, ([1],), operator.methodcaller("cumsum")), @@ -509,19 +509,19 @@ # Reductions pytest.param( (pd.DataFrame, frame_data, operator.methodcaller("any")), - marks=not_implemented_mark, + marks=not_implemented_mark ), pytest.param( (pd.DataFrame, frame_data, operator.methodcaller("sum")), - marks=not_implemented_mark, + marks=not_implemented_mark ), pytest.param( (pd.DataFrame, frame_data, operator.methodcaller("std")), - marks=not_implemented_mark, + marks=not_implemented_mark ), pytest.param( (pd.DataFrame, frame_data, operator.methodcaller("mean")), - marks=not_implemented_mark, + marks=not_implemented_mark ), ] @@ -568,8 +568,8 @@ def test_finalize_called(ndframe_method): (pd.Series([1]), pd.Series([1])), (pd.DataFrame({"A": [1]}), pd.DataFrame({"A": [1]})), (pd.Series([1]), pd.DataFrame({"A": [1]})), - (pd.DataFrame({"A": [1]}), pd.Series([1])), - ], + (pd.DataFrame({"A": [1]}), pd.Series([1])) + ] ) def test_binops(args, annotate, all_arithmetic_functions): # This generates 326 tests... Is that needed? @@ -600,7 +600,7 @@ def test_binops(args, annotate, all_arithmetic_functions): operator.methodcaller("casefold"), pytest.param( operator.methodcaller("cat", ["a"]), - marks=pytest.mark.xfail(reason="finalize not called."), + marks=pytest.mark.xfail(reason="finalize not called.") ), operator.methodcaller("contains", "a"), operator.methodcaller("count", "a"), @@ -608,11 +608,11 @@ def test_binops(args, annotate, all_arithmetic_functions): operator.methodcaller("endswith", "a"), pytest.param( operator.methodcaller("extract", r"(\w)(\d)"), - marks=pytest.mark.xfail(reason="finalize not called."), + marks=pytest.mark.xfail(reason="finalize not called.") ), pytest.param( operator.methodcaller("extract", r"(\w)(\d)"), - marks=pytest.mark.xfail(reason="finalize not called."), + marks=pytest.mark.xfail(reason="finalize not called.") ), operator.methodcaller("find", "a"), operator.methodcaller("findall", "a"), @@ -651,9 +651,9 @@ def test_binops(args, annotate, all_arithmetic_functions): operator.methodcaller("istitle"), operator.methodcaller("isnumeric"), operator.methodcaller("isdecimal"), - operator.methodcaller("get_dummies"), + operator.methodcaller("get_dummies") ], - ids=idfn, + ids=idfn ) @not_implemented_mark def test_string_method(method): @@ -674,9 +674,9 @@ def test_string_method(method): operator.methodcaller("floor", "H"), operator.methodcaller("ceil", "H"), operator.methodcaller("month_name"), - operator.methodcaller("day_name"), + operator.methodcaller("day_name") ], - ids=idfn, + ids=idfn ) @not_implemented_mark def test_datetime_method(method): @@ -711,8 +711,8 @@ def test_datetime_method(method): "is_year_end", "is_leap_year", "daysinmonth", - "days_in_month", - ], + "days_in_month" + ] ) @not_implemented_mark def test_datetime_property(attr): @@ -734,7 +734,7 @@ 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): @@ -755,8 +755,8 @@ def test_timedelta_methods(method): operator.methodcaller("remove_unused_categories"), operator.methodcaller("rename_categories", {"a": "A", "b": "B"}), operator.methodcaller("reorder_categories", ["b", "a"]), - operator.methodcaller("set_categories", ["A", "B"]), - ], + operator.methodcaller("set_categories", ["A", "B"]) + ] ) @not_implemented_mark def test_categorical_accessor(method): @@ -780,8 +780,8 @@ def test_categorical_accessor(method): lambda x: x.agg("sum"), lambda x: x.agg(["sum", "count"]), lambda x: x.transform(lambda y: y), - lambda x: x.apply(lambda y: y), - ], + lambda x: x.apply(lambda y: y) + ] ) @not_implemented_mark def test_groupby(obj, method): diff --git a/pandas/tests/generic/test_to_xarray.py b/pandas/tests/generic/test_to_xarray.py index ab56a752f7e90..88bf10eec1d2c 100644 --- a/pandas/tests/generic/test_to_xarray.py +++ b/pandas/tests/generic/test_to_xarray.py @@ -27,7 +27,7 @@ def test_to_xarray_index_types(self, index): "e": [True, False, True], "f": pd.Categorical(list("abc")), "g": pd.date_range("20130101", periods=3), - "h": pd.date_range("20130101", periods=3, tz="US/Eastern"), + "h": pd.date_range("20130101", periods=3, tz="US/Eastern") } ) @@ -48,7 +48,7 @@ def test_to_xarray_index_types(self, index): expected["f"] = expected["f"].astype(object) expected.columns.name = None tm.assert_frame_equal( - result.to_dataframe(), expected, + result.to_dataframe(), expected ) @td.skip_if_no("xarray", min_version="0.7.0") @@ -64,7 +64,7 @@ def test_to_xarray(self): "e": [True, False, True], "f": pd.Categorical(list("abc")), "g": pd.date_range("20130101", periods=3), - "h": pd.date_range("20130101", periods=3, tz="US/Eastern"), + "h": pd.date_range("20130101", periods=3, tz="US/Eastern") } ) diff --git a/pandas/tests/groupby/aggregate/test_numba.py b/pandas/tests/groupby/aggregate/test_numba.py index 29e65e938f6f9..e8c2a91916b6c 100644 --- a/pandas/tests/groupby/aggregate/test_numba.py +++ b/pandas/tests/groupby/aggregate/test_numba.py @@ -16,7 +16,7 @@ def incorrect_function(x): data = DataFrame( {"key": ["a", "a", "b", "b", "a"], "data": [1.0, 2.0, 3.0, 4.0, 5.0]}, - columns=["key", "data"], + columns=["key", "data"] ) with pytest.raises(NumbaUtilError, match="The first 2"): data.groupby("key").agg(incorrect_function, engine="numba") @@ -32,7 +32,7 @@ def incorrect_function(x, **kwargs): data = DataFrame( {"key": ["a", "a", "b", "b", "a"], "data": [1.0, 2.0, 3.0, 4.0, 5.0]}, - columns=["key", "data"], + columns=["key", "data"] ) with pytest.raises(NumbaUtilError, match="numba does not support"): data.groupby("key").agg(incorrect_function, engine="numba", a=1) @@ -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") @@ -137,12 +137,12 @@ def func_1(values, index): ["min", "max"], "min", {"B": ["min", "max"], "C": "sum"}, - NamedAgg(column="B", aggfunc="min"), - ], + 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"):