From de149314a58cec300bafbe80565d45d17b0477ab Mon Sep 17 00:00:00 2001 From: satrio Date: Mon, 7 Sep 2020 22:31:35 +0700 Subject: [PATCH 1/3] CLN:#35925 --- .../tests/arrays/categorical/test_replace.py | 8 +- pandas/tests/arrays/sparse/test_array.py | 70 +++++++-------- pandas/tests/arrays/test_array.py | 86 +++++++++---------- pandas/tests/arrays/test_timedeltas.py | 12 +-- pandas/tests/base/test_conversion.py | 82 +++++++++--------- pandas/tests/dtypes/test_missing.py | 62 ++++++------- pandas/tests/extension/base/methods.py | 16 ++-- pandas/tests/extension/test_sparse.py | 8 +- pandas/tests/frame/indexing/test_setitem.py | 24 +++--- 9 files changed, 184 insertions(+), 184 deletions(-) diff --git a/pandas/tests/arrays/categorical/test_replace.py b/pandas/tests/arrays/categorical/test_replace.py index b9ac3ce9a37ae..afb8a4beeeee6 100644 --- a/pandas/tests/arrays/categorical/test_replace.py +++ b/pandas/tests/arrays/categorical/test_replace.py @@ -24,8 +24,8 @@ ([1, 4], [5, 2], [5, 2, 3], True), # check_categorical sorts categories, which crashes on mixed dtypes (3, "4", [1, 2, "4"], False), - ([1, 2, "3"], "5", ["5", "5", 3], True), - ], + ([1, 2, "3"], "5", ["5", "5", 3], True) + ] ) def test_replace(to_replace, value, expected, flip_categories): # GH 31720 @@ -44,8 +44,8 @@ def test_replace(to_replace, value, expected, flip_categories): expected = pd.Series(np.asarray(expected)) tm.assert_series_equal( - expected, result, check_category_order=False, + expected, result, check_category_order=False ) tm.assert_series_equal( - expected, s, check_category_order=False, + expected, s, check_category_order=False ) diff --git a/pandas/tests/arrays/sparse/test_array.py b/pandas/tests/arrays/sparse/test_array.py index ece9367cea7fe..999fdde4949a9 100644 --- a/pandas/tests/arrays/sparse/test_array.py +++ b/pandas/tests/arrays/sparse/test_array.py @@ -125,7 +125,7 @@ def test_constructor_spindex_dtype(self): data=[1, 2, 3], sparse_index=IntIndex(4, [1, 2, 3]), dtype=np.int64, - fill_value=0, + fill_value=0 ) exp = SparseArray([0, 1, 2, 3], dtype=np.int64, fill_value=0) tm.assert_sp_array_equal(arr, exp) @@ -144,7 +144,7 @@ def test_constructor_spindex_dtype(self): data=[1, 2, 3], sparse_index=IntIndex(4, [1, 2, 3]), dtype=None, - fill_value=0, + fill_value=0 ) exp = SparseArray([0, 1, 2, 3], dtype=None) tm.assert_sp_array_equal(arr, exp) @@ -181,8 +181,8 @@ def test_constructor_spindex_dtype_scalar_broadcasts(self): (np.array([1, 2]), 0), (np.array([1.0, 2.0]), np.nan), ([True, False], False), - ([pd.Timestamp("2017-01-01")], pd.NaT), - ], + ([pd.Timestamp("2017-01-01")], pd.NaT) + ] ) def test_constructor_inferred_fill_value(self, data, fill_value): result = SparseArray(data).fill_value @@ -194,7 +194,7 @@ def test_constructor_inferred_fill_value(self, data, fill_value): @pytest.mark.parametrize("format", ["coo", "csc", "csr"]) @pytest.mark.parametrize( - "size", [0, 10], + "size", [0, 10] ) @td.skip_if_no_scipy def test_from_spmatrix(self, size, format): @@ -235,8 +235,8 @@ def test_from_spmatrix_raises(self): (False, SparseDtype(bool, False)), (0.0, SparseDtype("float64", 0)), (1, SparseDtype("int64", 1)), - ("z", SparseDtype("object", "z")), - ], + ("z", SparseDtype("object", "z")) + ] ) def test_scalar_with_index_infer_dtype(self, scalar, dtype): # GH 19163 @@ -531,35 +531,35 @@ def test_astype_all(self, any_real_dtype): ( SparseArray([0, 1]), "float", - SparseArray([0.0, 1.0], dtype=SparseDtype(float, 0.0)), + SparseArray([0.0, 1.0], dtype=SparseDtype(float, 0.0)) ), (SparseArray([0, 1]), bool, SparseArray([False, True])), ( SparseArray([0, 1], fill_value=1), bool, - SparseArray([False, True], dtype=SparseDtype(bool, True)), + SparseArray([False, True], dtype=SparseDtype(bool, True)) ), pytest.param( SparseArray([0, 1]), "datetime64[ns]", SparseArray( np.array([0, 1], dtype="datetime64[ns]"), - dtype=SparseDtype("datetime64[ns]", pd.Timestamp("1970")), + dtype=SparseDtype("datetime64[ns]", pd.Timestamp("1970")) ), - marks=[pytest.mark.xfail(reason="NumPy-7619")], + marks=[pytest.mark.xfail(reason="NumPy-7619")] ), ( SparseArray([0, 1, 10]), str, - SparseArray(["0", "1", "10"], dtype=SparseDtype(str, "0")), + SparseArray(["0", "1", "10"], dtype=SparseDtype(str, "0")) ), (SparseArray(["10", "20"]), float, SparseArray([10.0, 20.0])), ( SparseArray([0, 1, 0]), object, - SparseArray([0, 1, 0], dtype=SparseDtype(object, 0)), + SparseArray([0, 1, 0], dtype=SparseDtype(object, 0)) ), - ], + ] ) def test_astype_more(self, array, dtype, expected): result = array.astype(dtype) @@ -629,8 +629,8 @@ def test_values_asarray(self): ([0, 0, 0, 0, 0], (5,), None), ([], (0,), None), ([0], (1,), None), - (["A", "A", np.nan, "B"], (4,), object), - ], + (["A", "A", np.nan, "B"], (4,), object) + ] ) def test_shape(self, data, shape, dtype): # GH 21126 @@ -642,8 +642,8 @@ def test_shape(self, data, shape, dtype): [ [np.nan, np.nan, np.nan, np.nan, np.nan], [1, np.nan, np.nan, 3, np.nan], - [1, np.nan, 0, 3, 0], - ], + [1, np.nan, 0, 3, 0] + ] ) @pytest.mark.parametrize("fill_value", [None, 0]) def test_dense_repr(self, vals, fill_value): @@ -877,8 +877,8 @@ class TestSparseArrayAnalytics: [ ([True, True, True], True, False), ([1, 2, 1], 1, 0), - ([1.0, 2.0, 1.0], 1.0, 0.0), - ], + ([1.0, 2.0, 1.0], 1.0, 0.0) + ] ) def test_all(self, data, pos, neg): # GH 17570 @@ -900,8 +900,8 @@ def test_all(self, data, pos, neg): [ ([True, True, True], True, False), ([1, 2, 1], 1, 0), - ([1.0, 2.0, 1.0], 1.0, 0.0), - ], + ([1.0, 2.0, 1.0], 1.0, 0.0) + ] ) def test_numpy_all(self, data, pos, neg): # GH 17570 @@ -928,8 +928,8 @@ def test_numpy_all(self, data, pos, neg): [ ([False, True, False], True, False), ([0, 2, 0], 2, 0), - ([0.0, 2.0, 0.0], 2.0, 0.0), - ], + ([0.0, 2.0, 0.0], 2.0, 0.0) + ] ) def test_any(self, data, pos, neg): # GH 17570 @@ -951,8 +951,8 @@ def test_any(self, data, pos, neg): [ ([False, True, False], True, False), ([0, 2, 0], 2, 0), - ([0.0, 2.0, 0.0], 2.0, 0.0), - ], + ([0.0, 2.0, 0.0], 2.0, 0.0) + ] ) def test_numpy_any(self, data, pos, neg): # GH 17570 @@ -990,8 +990,8 @@ def test_sum(self): [ np.array([0, 1, np.nan, 1]), np.array([0, 1, 1]), - np.array([True, True, False]), - ], + np.array([True, True, False]) + ] ) @pytest.mark.parametrize("fill_value", [0, 1, np.nan, True, False]) @pytest.mark.parametrize("min_count, expected", [(3, 2), (4, np.nan)]) @@ -1029,13 +1029,13 @@ def test_numpy_sum(self): [ ( np.array([1, 2, 3, 4, 5], dtype=float), # non-null data - SparseArray(np.array([1.0, 3.0, 6.0, 10.0, 15.0])), + SparseArray(np.array([1.0, 3.0, 6.0, 10.0, 15.0])) ), ( np.array([1, 2, np.nan, 4, 5], dtype=float), # null data - SparseArray(np.array([1.0, 3.0, np.nan, 7.0, 12.0])), + SparseArray(np.array([1.0, 3.0, np.nan, 7.0, 12.0])) ), - ], + ] ) @pytest.mark.parametrize("numpy", [True, False]) def test_cumsum(self, data, expected, numpy): @@ -1199,7 +1199,7 @@ def test_to_coo(self): ser = pd.Series( [1, 2, 3], index=pd.MultiIndex.from_product([[0], [1, 2, 3]], names=["a", "b"]), - dtype="Sparse[int]", + dtype="Sparse[int]" ) A, _, _ = ser.sparse.to_coo() assert isinstance(A, scipy.sparse.coo.coo_matrix) @@ -1232,7 +1232,7 @@ def test_setting_fill_value_updates(): expected = SparseArray._simple_new( sparse_array=np.array([np.nan]), sparse_index=IntIndex(2, [1]), - dtype=SparseDtype(float, np.nan), + dtype=SparseDtype(float, np.nan) ) tm.assert_sp_array_equal(arr, expected) @@ -1245,8 +1245,8 @@ def test_setting_fill_value_updates(): ([0, 1, None], 2), ([0, 1, 1, None, None], 3), ([1, 1, 1, 2], -1), - ([], -1), - ], + ([], -1) + ] ) def test_first_fill_value_loc(arr, loc): result = SparseArray(arr)._first_fill_value_loc() diff --git a/pandas/tests/arrays/test_array.py b/pandas/tests/arrays/test_array.py index a0525aa511ee2..3eea90b6e4cc9 100644 --- a/pandas/tests/arrays/test_array.py +++ b/pandas/tests/arrays/test_array.py @@ -18,7 +18,7 @@ IntervalArray, SparseArray, StringArray, - TimedeltaArray, + TimedeltaArray ) from pandas.core.arrays import PandasArray, integer_array, period_array from pandas.tests.extension.decimal import DecimalArray, DecimalDtype, to_decimal @@ -33,48 +33,48 @@ ( [1, 2], np.dtype("float32"), - PandasArray(np.array([1.0, 2.0], dtype=np.dtype("float32"))), + PandasArray(np.array([1.0, 2.0], dtype=np.dtype("float32"))) ), - (np.array([1, 2], dtype="int64"), None, IntegerArray._from_sequence([1, 2]),), + (np.array([1, 2], dtype="int64"), None, IntegerArray._from_sequence([1, 2])), # String alias passes through to NumPy ([1, 2], "float32", PandasArray(np.array([1, 2], dtype="float32"))), # Period alias ( [pd.Period("2000", "D"), pd.Period("2001", "D")], "Period[D]", - period_array(["2000", "2001"], freq="D"), + period_array(["2000", "2001"], freq="D") ), # Period dtype ( [pd.Period("2000", "D")], pd.PeriodDtype("D"), - period_array(["2000"], freq="D"), + period_array(["2000"], freq="D") ), # Datetime (naive) ( [1, 2], np.dtype("datetime64[ns]"), - DatetimeArray._from_sequence(np.array([1, 2], dtype="datetime64[ns]")), + DatetimeArray._from_sequence(np.array([1, 2], dtype="datetime64[ns]")) ), ( np.array([1, 2], dtype="datetime64[ns]"), None, - DatetimeArray._from_sequence(np.array([1, 2], dtype="datetime64[ns]")), + DatetimeArray._from_sequence(np.array([1, 2], dtype="datetime64[ns]")) ), ( pd.DatetimeIndex(["2000", "2001"]), np.dtype("datetime64[ns]"), - DatetimeArray._from_sequence(["2000", "2001"]), + DatetimeArray._from_sequence(["2000", "2001"]) ), ( pd.DatetimeIndex(["2000", "2001"]), None, - DatetimeArray._from_sequence(["2000", "2001"]), + DatetimeArray._from_sequence(["2000", "2001"]) ), ( ["2000", "2001"], np.dtype("datetime64[ns]"), - DatetimeArray._from_sequence(["2000", "2001"]), + DatetimeArray._from_sequence(["2000", "2001"]) ), # Datetime (tz-aware) ( @@ -82,36 +82,36 @@ pd.DatetimeTZDtype(tz="CET"), DatetimeArray._from_sequence( ["2000", "2001"], dtype=pd.DatetimeTZDtype(tz="CET") - ), + ) ), # Timedelta ( ["1H", "2H"], np.dtype("timedelta64[ns]"), - TimedeltaArray._from_sequence(["1H", "2H"]), + TimedeltaArray._from_sequence(["1H", "2H"]) ), ( pd.TimedeltaIndex(["1H", "2H"]), np.dtype("timedelta64[ns]"), - TimedeltaArray._from_sequence(["1H", "2H"]), + TimedeltaArray._from_sequence(["1H", "2H"]) ), ( pd.TimedeltaIndex(["1H", "2H"]), None, - TimedeltaArray._from_sequence(["1H", "2H"]), + TimedeltaArray._from_sequence(["1H", "2H"]) ), # Category (["a", "b"], "category", pd.Categorical(["a", "b"])), ( ["a", "b"], pd.CategoricalDtype(None, ordered=True), - pd.Categorical(["a", "b"], ordered=True), + pd.Categorical(["a", "b"], ordered=True) ), # Interval ( [pd.Interval(1, 2), pd.Interval(3, 4)], "interval", - IntervalArray.from_tuples([(1, 2), (3, 4)]), + IntervalArray.from_tuples([(1, 2), (3, 4)]) ), # Sparse ([0, 1], "Sparse[int64]", SparseArray([0, 1], dtype="int64")), @@ -120,17 +120,17 @@ (pd.Series([1, 2]), None, PandasArray(np.array([1, 2], dtype=np.int64))), # String (["a", None], "string", StringArray._from_sequence(["a", None])), - (["a", None], pd.StringDtype(), StringArray._from_sequence(["a", None]),), + (["a", None], pd.StringDtype(), StringArray._from_sequence(["a", None])), # Boolean ([True, None], "boolean", BooleanArray._from_sequence([True, None])), - ([True, None], pd.BooleanDtype(), BooleanArray._from_sequence([True, None]),), + ([True, None], pd.BooleanDtype(), BooleanArray._from_sequence([True, None])), # Index (pd.Index([1, 2]), None, PandasArray(np.array([1, 2], dtype=np.int64))), # Series[EA] returns the EA ( pd.Series(pd.Categorical(["a", "b"], categories=["a", "b", "c"])), None, - pd.Categorical(["a", "b"], categories=["a", "b", "c"]), + pd.Categorical(["a", "b"], categories=["a", "b", "c"]) ), # "3rd party" EAs work ([decimal.Decimal(0), decimal.Decimal(1)], "decimal", to_decimal([0, 1])), @@ -138,9 +138,9 @@ ( period_array(["2000", "2001"], freq="D"), "category", - pd.Categorical([pd.Period("2000", "D"), pd.Period("2001", "D")]), - ), - ], + pd.Categorical([pd.Period("2000", "D"), pd.Period("2001", "D")]) + ) + ] ) def test_array(data, dtype, expected): result = pd.array(data, dtype=dtype) @@ -171,53 +171,53 @@ def test_array_copy(): # period ( [pd.Period("2000", "D"), pd.Period("2001", "D")], - period_array(["2000", "2001"], freq="D"), + period_array(["2000", "2001"], freq="D") ), # interval - ([pd.Interval(0, 1), pd.Interval(1, 2)], IntervalArray.from_breaks([0, 1, 2]),), + ([pd.Interval(0, 1), pd.Interval(1, 2)], IntervalArray.from_breaks([0, 1, 2])), # datetime ( [pd.Timestamp("2000"), pd.Timestamp("2001")], - DatetimeArray._from_sequence(["2000", "2001"]), + DatetimeArray._from_sequence(["2000", "2001"]) ), ( [datetime.datetime(2000, 1, 1), datetime.datetime(2001, 1, 1)], - DatetimeArray._from_sequence(["2000", "2001"]), + DatetimeArray._from_sequence(["2000", "2001"]) ), ( np.array([1, 2], dtype="M8[ns]"), - DatetimeArray(np.array([1, 2], dtype="M8[ns]")), + DatetimeArray(np.array([1, 2], dtype="M8[ns]")) ), ( np.array([1, 2], dtype="M8[us]"), - DatetimeArray(np.array([1000, 2000], dtype="M8[ns]")), + DatetimeArray(np.array([1000, 2000], dtype="M8[ns]")) ), # datetimetz ( [pd.Timestamp("2000", tz="CET"), pd.Timestamp("2001", tz="CET")], DatetimeArray._from_sequence( ["2000", "2001"], dtype=pd.DatetimeTZDtype(tz="CET") - ), + ) ), ( [ datetime.datetime(2000, 1, 1, tzinfo=cet), - datetime.datetime(2001, 1, 1, tzinfo=cet), + datetime.datetime(2001, 1, 1, tzinfo=cet) ], - DatetimeArray._from_sequence(["2000", "2001"], tz=cet), + DatetimeArray._from_sequence(["2000", "2001"], tz=cet) ), # timedelta ( [pd.Timedelta("1H"), pd.Timedelta("2H")], - TimedeltaArray._from_sequence(["1H", "2H"]), + TimedeltaArray._from_sequence(["1H", "2H"]) ), ( np.array([1, 2], dtype="m8[ns]"), - TimedeltaArray(np.array([1, 2], dtype="m8[ns]")), + TimedeltaArray(np.array([1, 2], dtype="m8[ns]")) ), ( np.array([1, 2], dtype="m8[us]"), - TimedeltaArray(np.array([1000, 2000], dtype="m8[ns]")), + TimedeltaArray(np.array([1000, 2000], dtype="m8[ns]")) ), # integer ([1, 2], IntegerArray._from_sequence([1, 2])), @@ -229,8 +229,8 @@ def test_array_copy(): (["a", None], StringArray._from_sequence(["a", None])), # Boolean ([True, False], BooleanArray._from_sequence([True, False])), - ([True, None], BooleanArray._from_sequence([True, None])), - ], + ([True, None], BooleanArray._from_sequence([True, None])) + ] ) def test_array_inference(data, expected): result = pd.array(data) @@ -248,8 +248,8 @@ def test_array_inference(data, expected): [pd.Timestamp("2000", tz="CET"), pd.Timestamp("2000", tz="UTC")], # Mix of tz-aware and tz-naive [pd.Timestamp("2000", tz="CET"), pd.Timestamp("2000")], - np.array([pd.Timestamp("2000"), pd.Timestamp("2000", tz="CET")]), - ], + np.array([pd.Timestamp("2000"), pd.Timestamp("2000", tz="CET")]) + ] ) def test_array_inference_fails(data): result = pd.array(data) @@ -364,17 +364,17 @@ def test_searchsorted_numeric_dtypes_vector(self, any_real_dtype): [ [ pd.date_range("20120101", periods=10, freq="2D"), - pd.Timestamp("20120102"), + pd.Timestamp("20120102") ], [ pd.date_range("20120101", periods=10, freq="2D", tz="Asia/Hong_Kong"), - pd.Timestamp("20120102", tz="Asia/Hong_Kong"), + pd.Timestamp("20120102", tz="Asia/Hong_Kong") ], [ pd.timedelta_range(start="1 day", end="10 days", periods=10), - pd.Timedelta("2 days"), - ], - ], + pd.Timedelta("2 days") + ] + ] ) def test_search_sorted_datetime64_scalar(self, arr, val): arr = pd.array(arr) diff --git a/pandas/tests/arrays/test_timedeltas.py b/pandas/tests/arrays/test_timedeltas.py index c86b4f71ee592..5651f72f2e297 100644 --- a/pandas/tests/arrays/test_timedeltas.py +++ b/pandas/tests/arrays/test_timedeltas.py @@ -46,7 +46,7 @@ def test_incorrect_dtype_raises(self): TimedeltaArray(np.array([1, 2, 3], dtype="i8"), dtype="category") with pytest.raises( - ValueError, match=r"dtype int64 cannot be converted to timedelta64\[ns\]", + ValueError, match=r"dtype int64 cannot be converted to timedelta64\[ns\]" ): TimedeltaArray(np.array([1, 2, 3], dtype="i8"), dtype=np.dtype("int64")) @@ -129,8 +129,8 @@ def test_setitem_clears_freq(self): [ pd.Timedelta(seconds=1), pd.Timedelta(seconds=1).to_timedelta64(), - pd.Timedelta(seconds=1).to_pytimedelta(), - ], + pd.Timedelta(seconds=1).to_pytimedelta() + ] ) def test_setitem_objects(self, obj): # make sure we accept timedelta64 and timedelta in addition to Timedelta @@ -151,8 +151,8 @@ def test_setitem_objects(self, obj): "invalid", np.arange(10, dtype="i8") * 24 * 3600 * 10 ** 9, (np.arange(10) * 24 * 3600 * 10 ** 9).view("datetime64[ns]"), - pd.Timestamp.now().to_period("D"), - ], + pd.Timestamp.now().to_period("D") + ] ) @pytest.mark.parametrize("index", [True, False]) def test_searchsorted_invalid_types(self, other, index): @@ -164,7 +164,7 @@ def test_searchsorted_invalid_types(self, other, index): msg = "|".join( [ "searchsorted requires compatible dtype or scalar", - "Unexpected type for 'value'", + "Unexpected type for 'value'" ] ) with pytest.raises(TypeError, match=msg): diff --git a/pandas/tests/base/test_conversion.py b/pandas/tests/base/test_conversion.py index b688a048cbe8e..f2a93df92cbc0 100644 --- a/pandas/tests/base/test_conversion.py +++ b/pandas/tests/base/test_conversion.py @@ -13,7 +13,7 @@ PandasArray, PeriodArray, SparseArray, - TimedeltaArray, + TimedeltaArray ) @@ -34,7 +34,7 @@ class TestToIterable: ("float64", float), ("datetime64[ns]", Timestamp), ("datetime64[ns, US/Eastern]", Timestamp), - ("timedelta64[ns]", Timedelta), + ("timedelta64[ns]", Timedelta) ] @pytest.mark.parametrize("dtype, rdtype", dtypes) @@ -44,9 +44,9 @@ class TestToIterable: lambda x: x.tolist(), lambda x: x.to_list(), lambda x: list(x), - lambda x: list(x.__iter__()), + lambda x: list(x.__iter__()) ], - ids=["tolist", "to_list", "list", "iter"], + ids=["tolist", "to_list", "list", "iter"] ) def test_iterable(self, index_or_series, method, dtype, rdtype): # gh-10904 @@ -63,8 +63,8 @@ def test_iterable(self, index_or_series, method, dtype, rdtype): ("object", object, "a"), ("object", int, 1), ("category", object, "a"), - ("category", int, 1), - ], + ("category", int, 1) + ] ) @pytest.mark.parametrize( "method", @@ -72,9 +72,9 @@ def test_iterable(self, index_or_series, method, dtype, rdtype): lambda x: x.tolist(), lambda x: x.to_list(), lambda x: list(x), - lambda x: list(x.__iter__()), + lambda x: list(x.__iter__()) ], - ids=["tolist", "to_list", "list", "iter"], + ids=["tolist", "to_list", "list", "iter"] ) def test_iterable_object_and_category( self, index_or_series, method, dtype, rdtype, obj @@ -118,9 +118,9 @@ def test_iterable_map(self, index_or_series, dtype, rdtype): lambda x: x.tolist(), lambda x: x.to_list(), lambda x: list(x), - lambda x: list(x.__iter__()), + lambda x: list(x.__iter__()) ], - ids=["tolist", "to_list", "list", "iter"], + ids=["tolist", "to_list", "list", "iter"] ) def test_categorial_datetimelike(self, method): i = CategoricalIndex([Timestamp("1999-12-31"), Timestamp("2000-12-31")]) @@ -139,7 +139,7 @@ def test_iter_box(self): vals = [ Timestamp("2011-01-01", tz="US/Eastern"), - Timestamp("2011-01-02", tz="US/Eastern"), + Timestamp("2011-01-02", tz="US/Eastern") ] s = Series(vals) @@ -176,14 +176,14 @@ def test_iter_box(self): ( pd.DatetimeIndex(["2017", "2018"], tz="US/Central"), DatetimeArray, - "datetime64[ns, US/Central]", + "datetime64[ns, US/Central]" ), ( pd.PeriodIndex([2018, 2019], freq="A"), PeriodArray, - pd.core.dtypes.dtypes.PeriodDtype("A-DEC"), + pd.core.dtypes.dtypes.PeriodDtype("A-DEC") ), - (pd.IntervalIndex.from_breaks([0, 1, 2]), IntervalArray, "interval",), + (pd.IntervalIndex.from_breaks([0, 1, 2]), IntervalArray, "interval"), # This test is currently failing for datetime64[ns] and timedelta64[ns]. # The NumPy type system is sufficient for representing these types, so # we just use NumPy for Series / DataFrame columns of these types (so @@ -197,15 +197,15 @@ def test_iter_box(self): pd.DatetimeIndex(["2017", "2018"]), np.ndarray, "datetime64[ns]", - marks=[pytest.mark.xfail(reason="datetime _values", strict=True)], + marks=[pytest.mark.xfail(reason="datetime _values", strict=True)] ), pytest.param( pd.TimedeltaIndex([10 ** 10]), np.ndarray, "m8[ns]", - marks=[pytest.mark.xfail(reason="timedelta _values", strict=True)], - ), - ], + marks=[pytest.mark.xfail(reason="timedelta _values", strict=True)] + ) + ] ) def test_values_consistent(array, expected_type, dtype): l_values = pd.Series(array)._values @@ -250,11 +250,11 @@ def test_numpy_array_all_dtypes(any_numpy_dtype): np.array( ["2000-01-01T12:00:00", "2000-01-02T12:00:00"], dtype="M8[ns]" ), - dtype=DatetimeTZDtype(tz="US/Central"), + dtype=DatetimeTZDtype(tz="US/Central") ), - "_data", - ), - ], + "_data" + ) + ] ) def test_array(array, attr, index_or_series): box = index_or_series @@ -283,21 +283,21 @@ def test_array_multiindex_raises(): (pd.Categorical(["a", "b"]), np.array(["a", "b"], dtype=object)), ( pd.core.arrays.period_array(["2000", "2001"], freq="D"), - np.array([pd.Period("2000", freq="D"), pd.Period("2001", freq="D")]), + np.array([pd.Period("2000", freq="D"), pd.Period("2001", freq="D")]) ), ( pd.core.arrays.integer_array([0, np.nan]), - np.array([0, pd.NA], dtype=object), + np.array([0, pd.NA], dtype=object) ), ( IntervalArray.from_breaks([0, 1, 2]), - np.array([pd.Interval(0, 1), pd.Interval(1, 2)], dtype=object), + np.array([pd.Interval(0, 1), pd.Interval(1, 2)], dtype=object) ), (SparseArray([0, 1]), np.array([0, 1], dtype=np.int64)), # tz-naive datetime ( DatetimeArray(np.array(["2000", "2001"], dtype="M8[ns]")), - np.array(["2000", "2001"], dtype="M8[ns]"), + np.array(["2000", "2001"], dtype="M8[ns]") ), # tz-aware stays tz`-aware ( @@ -305,21 +305,21 @@ def test_array_multiindex_raises(): np.array( ["2000-01-01T06:00:00", "2000-01-02T06:00:00"], dtype="M8[ns]" ), - dtype=DatetimeTZDtype(tz="US/Central"), + dtype=DatetimeTZDtype(tz="US/Central") ), np.array( [ pd.Timestamp("2000-01-01", tz="US/Central"), - pd.Timestamp("2000-01-02", tz="US/Central"), + pd.Timestamp("2000-01-02", tz="US/Central") ] - ), + ) ), # Timedelta ( TimedeltaArray(np.array([0, 3600000000000], dtype="i8"), freq="H"), - np.array([0, 3600000000000], dtype="m8[ns]"), - ), - ], + np.array([0, 3600000000000], dtype="m8[ns]") + ) + ] ) def test_to_numpy(array, expected, index_or_series): box = index_or_series @@ -383,9 +383,9 @@ def test_to_numpy_dtype(as_series): [pd.Timestamp("2000"), pd.Timestamp("2000"), pd.NaT], None, pd.Timestamp("2000"), - [np.datetime64("2000-01-01T00:00:00.000000000")] * 3, - ), - ], + [np.datetime64("2000-01-01T00:00:00.000000000")] * 3 + ) + ] ) def test_to_numpy_na_value_numpy_dtype( index_or_series, values, dtype, na_value, expected @@ -414,8 +414,8 @@ def test_to_numpy_kwargs_raises(): [ {"a": [1, 2, 3], "b": [1, 2, None]}, {"a": np.array([1, 2, 3]), "b": np.array([1, 2, np.nan])}, - {"a": pd.array([1, 2, 3]), "b": pd.array([1, 2, None])}, - ], + {"a": pd.array([1, 2, 3]), "b": pd.array([1, 2, None])} + ] ) @pytest.mark.parametrize("dtype, na_value", [(float, np.nan), (object, None)]) def test_to_numpy_dataframe_na_value(data, dtype, na_value): @@ -431,13 +431,13 @@ def test_to_numpy_dataframe_na_value(data, dtype, na_value): [ ( {"a": pd.array([1, 2, None])}, - np.array([[1.0], [2.0], [np.nan]], dtype=float), + np.array([[1.0], [2.0], [np.nan]], dtype=float) ), ( {"a": [1, 2, 3], "b": [1, 2, 3]}, - np.array([[1, 1], [2, 2], [3, 3]], dtype=float), - ), - ], + np.array([[1, 1], [2, 2], [3, 3]], dtype=float) + ) + ] ) def test_to_numpy_dataframe_single_block(data, expected): # https://github.com/pandas-dev/pandas/issues/33820 diff --git a/pandas/tests/dtypes/test_missing.py b/pandas/tests/dtypes/test_missing.py index 04dde08de082d..76fea9add5fe0 100644 --- a/pandas/tests/dtypes/test_missing.py +++ b/pandas/tests/dtypes/test_missing.py @@ -17,7 +17,7 @@ isnull, na_value_for_dtype, notna, - notnull, + notnull ) import pandas as pd @@ -56,7 +56,7 @@ def test_notna_notnull(notna_f): tm.makeStringSeries(), tm.makeObjectSeries(), tm.makeTimeSeries(), - tm.makePeriodSeries(), + tm.makePeriodSeries() ]: assert isinstance(notna_f(s), Series) @@ -99,7 +99,7 @@ def test_isna_isnull(self, isna_f): tm.makeStringSeries(), tm.makeObjectSeries(), tm.makeTimeSeries(), - tm.makePeriodSeries(), + tm.makePeriodSeries() ]: assert isinstance(isna_f(s), Series) @@ -107,7 +107,7 @@ def test_isna_isnull(self, isna_f): for df in [ tm.makeTimeDataFrame(), tm.makePeriodFrame(), - tm.makeMixedDataFrame(), + tm.makeMixedDataFrame() ]: result = isna_f(df) expected = df.apply(isna_f) @@ -151,7 +151,7 @@ def test_isna_numpy_nat(self): NaT, np.datetime64("NaT"), np.timedelta64("NaT"), - np.datetime64("NaT", "s"), + np.datetime64("NaT", "s") ] ) result = isna(arr) @@ -208,13 +208,13 @@ def test_isna_old_datetimelike(self): (np.array([1, 1 + 0j, np.nan, 3]), np.array([False, False, True, False])), ( np.array([1, 1 + 0j, np.nan, 3], dtype=object), - np.array([False, False, True, False]), + np.array([False, False, True, False]) ), ( np.array([1, 1 + 0j, np.nan, 3]).astype(object), - np.array([False, False, True, False]), - ), - ], + np.array([False, False, True, False]) + ) + ] ) def test_complex(self, value, expected): result = isna(value) @@ -238,7 +238,7 @@ def test_datetime_other_units(self): "datetime64[s]", "datetime64[ms]", "datetime64[us]", - "datetime64[ns]", + "datetime64[ns]" ]: values = idx.values.astype(dtype) @@ -269,7 +269,7 @@ def test_timedelta_other_units(self): "timedelta64[s]", "timedelta64[ms]", "timedelta64[us]", - "timedelta64[ns]", + "timedelta64[ns]" ]: values = idx.values.astype(dtype) @@ -308,33 +308,33 @@ def test_array_equivalent(dtype_equal): assert array_equivalent( np.array([np.nan, 1, np.nan]), np.array([np.nan, 1, np.nan]), - dtype_equal=dtype_equal, + dtype_equal=dtype_equal ) assert array_equivalent( np.array([np.nan, None], dtype="object"), np.array([np.nan, None], dtype="object"), - dtype_equal=dtype_equal, + dtype_equal=dtype_equal ) # Check the handling of nested arrays in array_equivalent_object assert array_equivalent( np.array([np.array([np.nan, None], dtype="object"), None], dtype="object"), np.array([np.array([np.nan, None], dtype="object"), None], dtype="object"), - dtype_equal=dtype_equal, + dtype_equal=dtype_equal ) assert array_equivalent( np.array([np.nan, 1 + 1j], dtype="complex"), np.array([np.nan, 1 + 1j], dtype="complex"), - dtype_equal=dtype_equal, + dtype_equal=dtype_equal ) assert not array_equivalent( np.array([np.nan, 1 + 1j], dtype="complex"), np.array([np.nan, 1 + 2j], dtype="complex"), - dtype_equal=dtype_equal, + dtype_equal=dtype_equal ) assert not array_equivalent( np.array([np.nan, 1, np.nan]), np.array([np.nan, 2, np.nan]), - dtype_equal=dtype_equal, + dtype_equal=dtype_equal ) assert not array_equivalent( np.array(["a", "b", "c", "d"]), np.array(["e", "e"]), dtype_equal=dtype_equal @@ -354,30 +354,30 @@ def test_array_equivalent(dtype_equal): assert array_equivalent( TimedeltaIndex([0, np.nan]), TimedeltaIndex([0, np.nan]), - dtype_equal=dtype_equal, + dtype_equal=dtype_equal ) assert not array_equivalent( TimedeltaIndex([0, np.nan]), TimedeltaIndex([1, np.nan]), - dtype_equal=dtype_equal, + dtype_equal=dtype_equal ) assert array_equivalent( DatetimeIndex([0, np.nan], tz="US/Eastern"), DatetimeIndex([0, np.nan], tz="US/Eastern"), - dtype_equal=dtype_equal, + dtype_equal=dtype_equal ) assert not array_equivalent( DatetimeIndex([0, np.nan], tz="US/Eastern"), DatetimeIndex([1, np.nan], tz="US/Eastern"), - dtype_equal=dtype_equal, + dtype_equal=dtype_equal ) # The rest are not dtype_equal assert not array_equivalent( - DatetimeIndex([0, np.nan]), DatetimeIndex([0, np.nan], tz="US/Eastern"), + DatetimeIndex([0, np.nan]), DatetimeIndex([0, np.nan], tz="US/Eastern") ) assert not array_equivalent( DatetimeIndex([0, np.nan], tz="CET"), - DatetimeIndex([0, np.nan], tz="US/Eastern"), + DatetimeIndex([0, np.nan], tz="US/Eastern") ) assert not array_equivalent(DatetimeIndex([0, np.nan]), TimedeltaIndex([0, np.nan])) @@ -399,8 +399,8 @@ def test_array_equivalent_different_dtype_but_equal(): (now.to_pydatetime(), utcnow), (now, utcnow), (now.to_datetime64(), utcnow.to_pydatetime()), - (now.to_pydatetime(), utcnow.to_pydatetime()), - ], + (now.to_pydatetime(), utcnow.to_pydatetime()) + ] ) def test_array_equivalent_tzawareness(lvalue, rvalue): # we shouldn't raise if comparing tzaware and tznaive datetimes @@ -479,8 +479,8 @@ def test_array_equivalent_nested(): # Object ("O", np.nan), # Interval - (IntervalDtype(), np.nan), - ], + (IntervalDtype(), np.nan) + ] ) def test_na_value_for_dtype(dtype, na_value): result = na_value_for_dtype(dtype) @@ -550,7 +550,7 @@ def test_empty_like(self): np.complex64(np.nan), np.complex128(np.nan), np.datetime64("NaT"), - np.timedelta64("NaT"), + np.timedelta64("NaT") ] + [np.datetime64("NaT", unit) for unit in m8_units] + [np.timedelta64("NaT", unit) for unit in m8_units] @@ -562,13 +562,13 @@ def test_empty_like(self): complex("inf"), complex("-inf"), np.inf, - np.NINF, + np.NINF ] int_na_vals = [ # Values that match iNaT, which we treat as null in specific cases np.int64(NaT.value), - int(NaT.value), + int(NaT.value) ] sometimes_na_vals = [Decimal("NaN")] @@ -578,7 +578,7 @@ def test_empty_like(self): -0.0, np.float64("-0.0"), -0j, - np.complex64(-0j), + np.complex64(-0j) ] diff --git a/pandas/tests/extension/base/methods.py b/pandas/tests/extension/base/methods.py index 5e1cf30efd534..5e487a5db971d 100644 --- a/pandas/tests/extension/base/methods.py +++ b/pandas/tests/extension/base/methods.py @@ -93,7 +93,7 @@ def test_argmin_argmax(self, data_for_sorting, data_missing_for_sorting, na_valu assert data_missing_for_sorting.argmin() == 2 @pytest.mark.parametrize( - "method", ["argmax", "argmin"], + "method", ["argmax", "argmin"] ) def test_argmin_argmax_empty_array(self, method, data): # GH 24382 @@ -102,7 +102,7 @@ def test_argmin_argmax_empty_array(self, method, data): getattr(data[:0], method)() @pytest.mark.parametrize( - "method", ["argmax", "argmin"], + "method", ["argmax", "argmin"] ) def test_argmin_argmax_all_na(self, method, data, na_value): # all missing with skipna=True is the same as emtpy @@ -115,8 +115,8 @@ def test_argmin_argmax_all_na(self, method, data, na_value): "na_position, expected", [ ("last", np.array([2, 0, 1], dtype=np.dtype("intp"))), - ("first", np.array([1, 2, 0], dtype=np.dtype("intp"))), - ], + ("first", np.array([1, 2, 0], dtype=np.dtype("intp"))) + ] ) def test_nargsort(self, data_missing_for_sorting, na_position, expected): # GH 25439 @@ -267,7 +267,7 @@ def test_combine_first(self, data): @pytest.mark.parametrize("frame", [True, False]) @pytest.mark.parametrize( "periods, indices", - [(-2, [2, 3, 4, -1, -1]), (0, [0, 1, 2, 3, 4]), (2, [-1, -1, 0, 1, 2])], + [(-2, [2, 3, 4, -1, -1]), (0, [0, 1, 2, 3, 4]), (2, [-1, -1, 0, 1, 2])] ) def test_container_shift(self, data, frame, periods, indices): # https://github.com/pandas-dev/pandas/issues/22386 @@ -322,7 +322,7 @@ def test_diff(self, data, periods): @pytest.mark.parametrize( "periods, indices", - [[-4, [-1, -1]], [-1, [1, -1]], [0, [0, 1]], [1, [-1, 0]], [4, [-1, -1]]], + [[-4, [-1, -1]], [-1, [1, -1]], [0, [0, 1]], [1, [-1, 0]], [4, [-1, -1]]] ) def test_shift_non_empty_array(self, data, periods, indices): # https://github.com/pandas-dev/pandas/issues/23911 @@ -450,8 +450,8 @@ def test_repeat(self, data, repeats, as_series, use_numpy): (2, dict(axis=1), ValueError, "'axis"), (-1, dict(), ValueError, "negative"), ([1, 2], dict(), ValueError, "shape"), - (2, dict(foo="bar"), TypeError, "'foo'"), - ], + (2, dict(foo="bar"), TypeError, "'foo'") + ] ) def test_repeat_raises(self, data, repeats, kwargs, error, msg, use_numpy): with pytest.raises(error, match=msg): diff --git a/pandas/tests/extension/test_sparse.py b/pandas/tests/extension/test_sparse.py index b411ca1c482a4..0aa56cfb30d75 100644 --- a/pandas/tests/extension/test_sparse.py +++ b/pandas/tests/extension/test_sparse.py @@ -221,7 +221,7 @@ def test_fillna_frame(self, data_missing): expected = pd.DataFrame( { "A": data_missing._from_sequence([fill_value, fill_value], dtype=dtype), - "B": [1, 2], + "B": [1, 2] } ) @@ -240,7 +240,7 @@ def test_combine_le(self, data_repeated): expected = pd.Series( SparseArray( [a <= b for (a, b) in zip(list(orig_data1), list(orig_data2))], - fill_value=False, + fill_value=False ) ) self.assert_series_equal(result, expected) @@ -317,7 +317,7 @@ def test_shift_0_periods(self, data): assert result._sparse_values[0] != result._sparse_values[1] @pytest.mark.parametrize( - "method", ["argmax", "argmin"], + "method", ["argmax", "argmin"] ) def test_argmin_argmax_all_na(self, method, data, na_value): # overriding because Sparse[int64, 0] cannot handle na_value @@ -403,7 +403,7 @@ def _compare_other(self, s, data, op_name, other): expected = pd.Series( SparseArray( op(np.asarray(data), np.asarray(other)), - fill_value=result.values.fill_value, + fill_value=result.values.fill_value ) ) diff --git a/pandas/tests/frame/indexing/test_setitem.py b/pandas/tests/frame/indexing/test_setitem.py index c5945edfd3127..89591d4c8dc9c 100644 --- a/pandas/tests/frame/indexing/test_setitem.py +++ b/pandas/tests/frame/indexing/test_setitem.py @@ -11,7 +11,7 @@ Period, Series, Timestamp, - date_range, + date_range ) import pandas._testing as tm from pandas.core.arrays import SparseArray @@ -23,12 +23,12 @@ def test_setitem_error_msmgs(self): # GH 7432 df = DataFrame( {"bar": [1, 2, 3], "baz": ["d", "e", "f"]}, - index=Index(["a", "b", "c"], name="foo"), + index=Index(["a", "b", "c"], name="foo") ) ser = Series( ["g", "h", "i", "j"], index=Index(["a", "b", "c", "a"], name="foo"), - name="fiz", + name="fiz" ) msg = "cannot reindex from a duplicate axis" with pytest.raises(ValueError, match=msg): @@ -66,7 +66,7 @@ def test_setitem_different_dtype(self): result = df.dtypes expected = Series( [np.dtype("float64")] * 5 + [np.dtype("float32")], - index=["foo", "c", "bar", "b", "a", "x"], + index=["foo", "c", "bar", "b", "a", "x"] ) tm.assert_series_equal(result, expected) @@ -75,7 +75,7 @@ def test_setitem_different_dtype(self): result = df.dtypes expected = Series( [np.dtype("float64")] * 4 + [np.dtype("float32")] * 2, - index=["foo", "c", "bar", "b", "a", "x"], + index=["foo", "c", "bar", "b", "a", "x"] ) tm.assert_series_equal(result, expected) @@ -83,7 +83,7 @@ def test_setitem_different_dtype(self): result = df.dtypes expected = Series( [np.dtype("float64")] * 4 + [np.dtype("float32")] * 2 + [np.dtype("int32")], - index=["foo", "c", "bar", "b", "a", "x", "y"], + index=["foo", "c", "bar", "b", "a", "x", "y"] ) tm.assert_series_equal(result, expected) @@ -108,7 +108,7 @@ def test_setitem_timestamp_empty_columns(self): df["now"] = Timestamp("20130101", tz="UTC") expected = DataFrame( - [[Timestamp("20130101", tz="UTC")]] * 3, index=[0, 1, 2], columns=["now"], + [[Timestamp("20130101", tz="UTC")]] * 3, index=[0, 1, 2], columns=["now"] ) tm.assert_frame_equal(df, expected) @@ -147,21 +147,21 @@ def test_setitem_dict_preserves_dtypes(self): { "a": Series([0, 1, 2], dtype="int64"), "b": Series([1, 2, 3], dtype=float), - "c": Series([1, 2, 3], dtype=float), + "c": Series([1, 2, 3], dtype=float) } ) df = DataFrame( { "a": Series([], dtype="int64"), "b": Series([], dtype=float), - "c": Series([], dtype=float), + "c": Series([], dtype=float) } ) for idx, b in enumerate([1, 2, 3]): df.loc[df.shape[0]] = { "a": int(idx), "b": float(b), - "c": float(b), + "c": float(b) } tm.assert_frame_equal(df, expected) @@ -173,8 +173,8 @@ def test_setitem_dict_preserves_dtypes(self): ( Timestamp("2011-01-01", tz="US/Eastern"), DatetimeTZDtype(tz="US/Eastern"), - ), - ], + ) + ] ) def test_setitem_extension_types(self, obj, dtype): # GH: 34832 From 12ad53f44041453135853c6b57a6a8d63bf55819 Mon Sep 17 00:00:00 2001 From: satrio Date: Tue, 8 Sep 2020 05:35:47 +0700 Subject: [PATCH 2/3] rerun black on modified files --- .../tests/arrays/categorical/test_replace.py | 12 +-- pandas/tests/arrays/sparse/test_array.py | 85 ++++++++++--------- pandas/tests/arrays/test_array.py | 78 ++++++++--------- pandas/tests/arrays/test_timedeltas.py | 10 +-- pandas/tests/base/test_conversion.py | 83 +++++++++--------- pandas/tests/dtypes/test_missing.py | 60 ++++++------- pandas/tests/extension/base/methods.py | 20 ++--- pandas/tests/extension/test_sparse.py | 10 +-- pandas/tests/frame/indexing/test_setitem.py | 26 +++--- 9 files changed, 187 insertions(+), 197 deletions(-) diff --git a/pandas/tests/arrays/categorical/test_replace.py b/pandas/tests/arrays/categorical/test_replace.py index afb8a4beeeee6..8b784fde1d3c5 100644 --- a/pandas/tests/arrays/categorical/test_replace.py +++ b/pandas/tests/arrays/categorical/test_replace.py @@ -24,8 +24,8 @@ ([1, 4], [5, 2], [5, 2, 3], True), # check_categorical sorts categories, which crashes on mixed dtypes (3, "4", [1, 2, "4"], False), - ([1, 2, "3"], "5", ["5", "5", 3], True) - ] + ([1, 2, "3"], "5", ["5", "5", 3], True), + ], ) def test_replace(to_replace, value, expected, flip_categories): # GH 31720 @@ -43,9 +43,5 @@ def test_replace(to_replace, value, expected, flip_categories): # the replace call loses categorical dtype expected = pd.Series(np.asarray(expected)) - tm.assert_series_equal( - expected, result, check_category_order=False - ) - tm.assert_series_equal( - expected, s, check_category_order=False - ) + tm.assert_series_equal(expected, result, check_category_order=False) + tm.assert_series_equal(expected, s, check_category_order=False) diff --git a/pandas/tests/arrays/sparse/test_array.py b/pandas/tests/arrays/sparse/test_array.py index 999fdde4949a9..b4e4647c9bf35 100644 --- a/pandas/tests/arrays/sparse/test_array.py +++ b/pandas/tests/arrays/sparse/test_array.py @@ -125,7 +125,7 @@ def test_constructor_spindex_dtype(self): data=[1, 2, 3], sparse_index=IntIndex(4, [1, 2, 3]), dtype=np.int64, - fill_value=0 + fill_value=0, ) exp = SparseArray([0, 1, 2, 3], dtype=np.int64, fill_value=0) tm.assert_sp_array_equal(arr, exp) @@ -144,7 +144,7 @@ def test_constructor_spindex_dtype(self): data=[1, 2, 3], sparse_index=IntIndex(4, [1, 2, 3]), dtype=None, - fill_value=0 + fill_value=0, ) exp = SparseArray([0, 1, 2, 3], dtype=None) tm.assert_sp_array_equal(arr, exp) @@ -181,8 +181,8 @@ def test_constructor_spindex_dtype_scalar_broadcasts(self): (np.array([1, 2]), 0), (np.array([1.0, 2.0]), np.nan), ([True, False], False), - ([pd.Timestamp("2017-01-01")], pd.NaT) - ] + ([pd.Timestamp("2017-01-01")], pd.NaT), + ], ) def test_constructor_inferred_fill_value(self, data, fill_value): result = SparseArray(data).fill_value @@ -193,9 +193,7 @@ def test_constructor_inferred_fill_value(self, data, fill_value): assert result == fill_value @pytest.mark.parametrize("format", ["coo", "csc", "csr"]) - @pytest.mark.parametrize( - "size", [0, 10] - ) + @pytest.mark.parametrize("size", [0, 10]) @td.skip_if_no_scipy def test_from_spmatrix(self, size, format): import scipy.sparse @@ -235,8 +233,8 @@ def test_from_spmatrix_raises(self): (False, SparseDtype(bool, False)), (0.0, SparseDtype("float64", 0)), (1, SparseDtype("int64", 1)), - ("z", SparseDtype("object", "z")) - ] + ("z", SparseDtype("object", "z")), + ], ) def test_scalar_with_index_infer_dtype(self, scalar, dtype): # GH 19163 @@ -531,35 +529,35 @@ def test_astype_all(self, any_real_dtype): ( SparseArray([0, 1]), "float", - SparseArray([0.0, 1.0], dtype=SparseDtype(float, 0.0)) + SparseArray([0.0, 1.0], dtype=SparseDtype(float, 0.0)), ), (SparseArray([0, 1]), bool, SparseArray([False, True])), ( SparseArray([0, 1], fill_value=1), bool, - SparseArray([False, True], dtype=SparseDtype(bool, True)) + SparseArray([False, True], dtype=SparseDtype(bool, True)), ), pytest.param( SparseArray([0, 1]), "datetime64[ns]", SparseArray( np.array([0, 1], dtype="datetime64[ns]"), - dtype=SparseDtype("datetime64[ns]", pd.Timestamp("1970")) + dtype=SparseDtype("datetime64[ns]", pd.Timestamp("1970")), ), - marks=[pytest.mark.xfail(reason="NumPy-7619")] + marks=[pytest.mark.xfail(reason="NumPy-7619")], ), ( SparseArray([0, 1, 10]), str, - SparseArray(["0", "1", "10"], dtype=SparseDtype(str, "0")) + SparseArray(["0", "1", "10"], dtype=SparseDtype(str, "0")), ), (SparseArray(["10", "20"]), float, SparseArray([10.0, 20.0])), ( SparseArray([0, 1, 0]), object, - SparseArray([0, 1, 0], dtype=SparseDtype(object, 0)) + SparseArray([0, 1, 0], dtype=SparseDtype(object, 0)), ), - ] + ], ) def test_astype_more(self, array, dtype, expected): result = array.astype(dtype) @@ -629,8 +627,8 @@ def test_values_asarray(self): ([0, 0, 0, 0, 0], (5,), None), ([], (0,), None), ([0], (1,), None), - (["A", "A", np.nan, "B"], (4,), object) - ] + (["A", "A", np.nan, "B"], (4,), object), + ], ) def test_shape(self, data, shape, dtype): # GH 21126 @@ -642,8 +640,8 @@ def test_shape(self, data, shape, dtype): [ [np.nan, np.nan, np.nan, np.nan, np.nan], [1, np.nan, np.nan, 3, np.nan], - [1, np.nan, 0, 3, 0] - ] + [1, np.nan, 0, 3, 0], + ], ) @pytest.mark.parametrize("fill_value", [None, 0]) def test_dense_repr(self, vals, fill_value): @@ -696,14 +694,23 @@ def test_getslice_tuple(self): res = sparse[ 4:, ] # noqa: E231 - exp = SparseArray(dense[4:,]) # noqa: E231 + exp = SparseArray( + dense[ + 4:, + ] + ) # noqa: E231 tm.assert_sp_array_equal(res, exp) sparse = SparseArray(dense, fill_value=0) res = sparse[ 4:, ] # noqa: E231 - exp = SparseArray(dense[4:,], fill_value=0) # noqa: E231 + exp = SparseArray( + dense[ + 4:, + ], + fill_value=0, + ) # noqa: E231 tm.assert_sp_array_equal(res, exp) msg = "too many indices for array" @@ -877,8 +884,8 @@ class TestSparseArrayAnalytics: [ ([True, True, True], True, False), ([1, 2, 1], 1, 0), - ([1.0, 2.0, 1.0], 1.0, 0.0) - ] + ([1.0, 2.0, 1.0], 1.0, 0.0), + ], ) def test_all(self, data, pos, neg): # GH 17570 @@ -900,8 +907,8 @@ def test_all(self, data, pos, neg): [ ([True, True, True], True, False), ([1, 2, 1], 1, 0), - ([1.0, 2.0, 1.0], 1.0, 0.0) - ] + ([1.0, 2.0, 1.0], 1.0, 0.0), + ], ) def test_numpy_all(self, data, pos, neg): # GH 17570 @@ -928,8 +935,8 @@ def test_numpy_all(self, data, pos, neg): [ ([False, True, False], True, False), ([0, 2, 0], 2, 0), - ([0.0, 2.0, 0.0], 2.0, 0.0) - ] + ([0.0, 2.0, 0.0], 2.0, 0.0), + ], ) def test_any(self, data, pos, neg): # GH 17570 @@ -951,8 +958,8 @@ def test_any(self, data, pos, neg): [ ([False, True, False], True, False), ([0, 2, 0], 2, 0), - ([0.0, 2.0, 0.0], 2.0, 0.0) - ] + ([0.0, 2.0, 0.0], 2.0, 0.0), + ], ) def test_numpy_any(self, data, pos, neg): # GH 17570 @@ -990,8 +997,8 @@ def test_sum(self): [ np.array([0, 1, np.nan, 1]), np.array([0, 1, 1]), - np.array([True, True, False]) - ] + np.array([True, True, False]), + ], ) @pytest.mark.parametrize("fill_value", [0, 1, np.nan, True, False]) @pytest.mark.parametrize("min_count, expected", [(3, 2), (4, np.nan)]) @@ -1029,13 +1036,13 @@ def test_numpy_sum(self): [ ( np.array([1, 2, 3, 4, 5], dtype=float), # non-null data - SparseArray(np.array([1.0, 3.0, 6.0, 10.0, 15.0])) + SparseArray(np.array([1.0, 3.0, 6.0, 10.0, 15.0])), ), ( np.array([1, 2, np.nan, 4, 5], dtype=float), # null data - SparseArray(np.array([1.0, 3.0, np.nan, 7.0, 12.0])) + SparseArray(np.array([1.0, 3.0, np.nan, 7.0, 12.0])), ), - ] + ], ) @pytest.mark.parametrize("numpy", [True, False]) def test_cumsum(self, data, expected, numpy): @@ -1199,7 +1206,7 @@ def test_to_coo(self): ser = pd.Series( [1, 2, 3], index=pd.MultiIndex.from_product([[0], [1, 2, 3]], names=["a", "b"]), - dtype="Sparse[int]" + dtype="Sparse[int]", ) A, _, _ = ser.sparse.to_coo() assert isinstance(A, scipy.sparse.coo.coo_matrix) @@ -1232,7 +1239,7 @@ def test_setting_fill_value_updates(): expected = SparseArray._simple_new( sparse_array=np.array([np.nan]), sparse_index=IntIndex(2, [1]), - dtype=SparseDtype(float, np.nan) + dtype=SparseDtype(float, np.nan), ) tm.assert_sp_array_equal(arr, expected) @@ -1245,8 +1252,8 @@ def test_setting_fill_value_updates(): ([0, 1, None], 2), ([0, 1, 1, None, None], 3), ([1, 1, 1, 2], -1), - ([], -1) - ] + ([], -1), + ], ) def test_first_fill_value_loc(arr, loc): result = SparseArray(arr)._first_fill_value_loc() diff --git a/pandas/tests/arrays/test_array.py b/pandas/tests/arrays/test_array.py index 3eea90b6e4cc9..304e1c80a3f77 100644 --- a/pandas/tests/arrays/test_array.py +++ b/pandas/tests/arrays/test_array.py @@ -18,7 +18,7 @@ IntervalArray, SparseArray, StringArray, - TimedeltaArray + TimedeltaArray, ) from pandas.core.arrays import PandasArray, integer_array, period_array from pandas.tests.extension.decimal import DecimalArray, DecimalDtype, to_decimal @@ -33,7 +33,7 @@ ( [1, 2], np.dtype("float32"), - PandasArray(np.array([1.0, 2.0], dtype=np.dtype("float32"))) + PandasArray(np.array([1.0, 2.0], dtype=np.dtype("float32"))), ), (np.array([1, 2], dtype="int64"), None, IntegerArray._from_sequence([1, 2])), # String alias passes through to NumPy @@ -42,39 +42,39 @@ ( [pd.Period("2000", "D"), pd.Period("2001", "D")], "Period[D]", - period_array(["2000", "2001"], freq="D") + period_array(["2000", "2001"], freq="D"), ), # Period dtype ( [pd.Period("2000", "D")], pd.PeriodDtype("D"), - period_array(["2000"], freq="D") + period_array(["2000"], freq="D"), ), # Datetime (naive) ( [1, 2], np.dtype("datetime64[ns]"), - DatetimeArray._from_sequence(np.array([1, 2], dtype="datetime64[ns]")) + DatetimeArray._from_sequence(np.array([1, 2], dtype="datetime64[ns]")), ), ( np.array([1, 2], dtype="datetime64[ns]"), None, - DatetimeArray._from_sequence(np.array([1, 2], dtype="datetime64[ns]")) + DatetimeArray._from_sequence(np.array([1, 2], dtype="datetime64[ns]")), ), ( pd.DatetimeIndex(["2000", "2001"]), np.dtype("datetime64[ns]"), - DatetimeArray._from_sequence(["2000", "2001"]) + DatetimeArray._from_sequence(["2000", "2001"]), ), ( pd.DatetimeIndex(["2000", "2001"]), None, - DatetimeArray._from_sequence(["2000", "2001"]) + DatetimeArray._from_sequence(["2000", "2001"]), ), ( ["2000", "2001"], np.dtype("datetime64[ns]"), - DatetimeArray._from_sequence(["2000", "2001"]) + DatetimeArray._from_sequence(["2000", "2001"]), ), # Datetime (tz-aware) ( @@ -82,36 +82,36 @@ pd.DatetimeTZDtype(tz="CET"), DatetimeArray._from_sequence( ["2000", "2001"], dtype=pd.DatetimeTZDtype(tz="CET") - ) + ), ), # Timedelta ( ["1H", "2H"], np.dtype("timedelta64[ns]"), - TimedeltaArray._from_sequence(["1H", "2H"]) + TimedeltaArray._from_sequence(["1H", "2H"]), ), ( pd.TimedeltaIndex(["1H", "2H"]), np.dtype("timedelta64[ns]"), - TimedeltaArray._from_sequence(["1H", "2H"]) + TimedeltaArray._from_sequence(["1H", "2H"]), ), ( pd.TimedeltaIndex(["1H", "2H"]), None, - TimedeltaArray._from_sequence(["1H", "2H"]) + TimedeltaArray._from_sequence(["1H", "2H"]), ), # Category (["a", "b"], "category", pd.Categorical(["a", "b"])), ( ["a", "b"], pd.CategoricalDtype(None, ordered=True), - pd.Categorical(["a", "b"], ordered=True) + pd.Categorical(["a", "b"], ordered=True), ), # Interval ( [pd.Interval(1, 2), pd.Interval(3, 4)], "interval", - IntervalArray.from_tuples([(1, 2), (3, 4)]) + IntervalArray.from_tuples([(1, 2), (3, 4)]), ), # Sparse ([0, 1], "Sparse[int64]", SparseArray([0, 1], dtype="int64")), @@ -130,7 +130,7 @@ ( pd.Series(pd.Categorical(["a", "b"], categories=["a", "b", "c"])), None, - pd.Categorical(["a", "b"], categories=["a", "b", "c"]) + pd.Categorical(["a", "b"], categories=["a", "b", "c"]), ), # "3rd party" EAs work ([decimal.Decimal(0), decimal.Decimal(1)], "decimal", to_decimal([0, 1])), @@ -138,9 +138,9 @@ ( period_array(["2000", "2001"], freq="D"), "category", - pd.Categorical([pd.Period("2000", "D"), pd.Period("2001", "D")]) - ) - ] + pd.Categorical([pd.Period("2000", "D"), pd.Period("2001", "D")]), + ), + ], ) def test_array(data, dtype, expected): result = pd.array(data, dtype=dtype) @@ -171,53 +171,53 @@ def test_array_copy(): # period ( [pd.Period("2000", "D"), pd.Period("2001", "D")], - period_array(["2000", "2001"], freq="D") + period_array(["2000", "2001"], freq="D"), ), # interval ([pd.Interval(0, 1), pd.Interval(1, 2)], IntervalArray.from_breaks([0, 1, 2])), # datetime ( [pd.Timestamp("2000"), pd.Timestamp("2001")], - DatetimeArray._from_sequence(["2000", "2001"]) + DatetimeArray._from_sequence(["2000", "2001"]), ), ( [datetime.datetime(2000, 1, 1), datetime.datetime(2001, 1, 1)], - DatetimeArray._from_sequence(["2000", "2001"]) + DatetimeArray._from_sequence(["2000", "2001"]), ), ( np.array([1, 2], dtype="M8[ns]"), - DatetimeArray(np.array([1, 2], dtype="M8[ns]")) + DatetimeArray(np.array([1, 2], dtype="M8[ns]")), ), ( np.array([1, 2], dtype="M8[us]"), - DatetimeArray(np.array([1000, 2000], dtype="M8[ns]")) + DatetimeArray(np.array([1000, 2000], dtype="M8[ns]")), ), # datetimetz ( [pd.Timestamp("2000", tz="CET"), pd.Timestamp("2001", tz="CET")], DatetimeArray._from_sequence( ["2000", "2001"], dtype=pd.DatetimeTZDtype(tz="CET") - ) + ), ), ( [ datetime.datetime(2000, 1, 1, tzinfo=cet), - datetime.datetime(2001, 1, 1, tzinfo=cet) + datetime.datetime(2001, 1, 1, tzinfo=cet), ], - DatetimeArray._from_sequence(["2000", "2001"], tz=cet) + DatetimeArray._from_sequence(["2000", "2001"], tz=cet), ), # timedelta ( [pd.Timedelta("1H"), pd.Timedelta("2H")], - TimedeltaArray._from_sequence(["1H", "2H"]) + TimedeltaArray._from_sequence(["1H", "2H"]), ), ( np.array([1, 2], dtype="m8[ns]"), - TimedeltaArray(np.array([1, 2], dtype="m8[ns]")) + TimedeltaArray(np.array([1, 2], dtype="m8[ns]")), ), ( np.array([1, 2], dtype="m8[us]"), - TimedeltaArray(np.array([1000, 2000], dtype="m8[ns]")) + TimedeltaArray(np.array([1000, 2000], dtype="m8[ns]")), ), # integer ([1, 2], IntegerArray._from_sequence([1, 2])), @@ -229,8 +229,8 @@ def test_array_copy(): (["a", None], StringArray._from_sequence(["a", None])), # Boolean ([True, False], BooleanArray._from_sequence([True, False])), - ([True, None], BooleanArray._from_sequence([True, None])) - ] + ([True, None], BooleanArray._from_sequence([True, None])), + ], ) def test_array_inference(data, expected): result = pd.array(data) @@ -248,8 +248,8 @@ def test_array_inference(data, expected): [pd.Timestamp("2000", tz="CET"), pd.Timestamp("2000", tz="UTC")], # Mix of tz-aware and tz-naive [pd.Timestamp("2000", tz="CET"), pd.Timestamp("2000")], - np.array([pd.Timestamp("2000"), pd.Timestamp("2000", tz="CET")]) - ] + np.array([pd.Timestamp("2000"), pd.Timestamp("2000", tz="CET")]), + ], ) def test_array_inference_fails(data): result = pd.array(data) @@ -364,17 +364,17 @@ def test_searchsorted_numeric_dtypes_vector(self, any_real_dtype): [ [ pd.date_range("20120101", periods=10, freq="2D"), - pd.Timestamp("20120102") + pd.Timestamp("20120102"), ], [ pd.date_range("20120101", periods=10, freq="2D", tz="Asia/Hong_Kong"), - pd.Timestamp("20120102", tz="Asia/Hong_Kong") + pd.Timestamp("20120102", tz="Asia/Hong_Kong"), ], [ pd.timedelta_range(start="1 day", end="10 days", periods=10), - pd.Timedelta("2 days") - ] - ] + pd.Timedelta("2 days"), + ], + ], ) def test_search_sorted_datetime64_scalar(self, arr, val): arr = pd.array(arr) diff --git a/pandas/tests/arrays/test_timedeltas.py b/pandas/tests/arrays/test_timedeltas.py index 5651f72f2e297..a32529cb58ba3 100644 --- a/pandas/tests/arrays/test_timedeltas.py +++ b/pandas/tests/arrays/test_timedeltas.py @@ -129,8 +129,8 @@ def test_setitem_clears_freq(self): [ pd.Timedelta(seconds=1), pd.Timedelta(seconds=1).to_timedelta64(), - pd.Timedelta(seconds=1).to_pytimedelta() - ] + pd.Timedelta(seconds=1).to_pytimedelta(), + ], ) def test_setitem_objects(self, obj): # make sure we accept timedelta64 and timedelta in addition to Timedelta @@ -151,8 +151,8 @@ def test_setitem_objects(self, obj): "invalid", np.arange(10, dtype="i8") * 24 * 3600 * 10 ** 9, (np.arange(10) * 24 * 3600 * 10 ** 9).view("datetime64[ns]"), - pd.Timestamp.now().to_period("D") - ] + pd.Timestamp.now().to_period("D"), + ], ) @pytest.mark.parametrize("index", [True, False]) def test_searchsorted_invalid_types(self, other, index): @@ -164,7 +164,7 @@ def test_searchsorted_invalid_types(self, other, index): msg = "|".join( [ "searchsorted requires compatible dtype or scalar", - "Unexpected type for 'value'" + "Unexpected type for 'value'", ] ) with pytest.raises(TypeError, match=msg): diff --git a/pandas/tests/base/test_conversion.py b/pandas/tests/base/test_conversion.py index f2a93df92cbc0..b5595ba220a15 100644 --- a/pandas/tests/base/test_conversion.py +++ b/pandas/tests/base/test_conversion.py @@ -13,7 +13,7 @@ PandasArray, PeriodArray, SparseArray, - TimedeltaArray + TimedeltaArray, ) @@ -34,7 +34,7 @@ class TestToIterable: ("float64", float), ("datetime64[ns]", Timestamp), ("datetime64[ns, US/Eastern]", Timestamp), - ("timedelta64[ns]", Timedelta) + ("timedelta64[ns]", Timedelta), ] @pytest.mark.parametrize("dtype, rdtype", dtypes) @@ -44,9 +44,9 @@ class TestToIterable: lambda x: x.tolist(), lambda x: x.to_list(), lambda x: list(x), - lambda x: list(x.__iter__()) + lambda x: list(x.__iter__()), ], - ids=["tolist", "to_list", "list", "iter"] + ids=["tolist", "to_list", "list", "iter"], ) def test_iterable(self, index_or_series, method, dtype, rdtype): # gh-10904 @@ -63,8 +63,8 @@ def test_iterable(self, index_or_series, method, dtype, rdtype): ("object", object, "a"), ("object", int, 1), ("category", object, "a"), - ("category", int, 1) - ] + ("category", int, 1), + ], ) @pytest.mark.parametrize( "method", @@ -72,9 +72,9 @@ def test_iterable(self, index_or_series, method, dtype, rdtype): lambda x: x.tolist(), lambda x: x.to_list(), lambda x: list(x), - lambda x: list(x.__iter__()) + lambda x: list(x.__iter__()), ], - ids=["tolist", "to_list", "list", "iter"] + ids=["tolist", "to_list", "list", "iter"], ) def test_iterable_object_and_category( self, index_or_series, method, dtype, rdtype, obj @@ -118,9 +118,9 @@ def test_iterable_map(self, index_or_series, dtype, rdtype): lambda x: x.tolist(), lambda x: x.to_list(), lambda x: list(x), - lambda x: list(x.__iter__()) + lambda x: list(x.__iter__()), ], - ids=["tolist", "to_list", "list", "iter"] + ids=["tolist", "to_list", "list", "iter"], ) def test_categorial_datetimelike(self, method): i = CategoricalIndex([Timestamp("1999-12-31"), Timestamp("2000-12-31")]) @@ -139,7 +139,7 @@ def test_iter_box(self): vals = [ Timestamp("2011-01-01", tz="US/Eastern"), - Timestamp("2011-01-02", tz="US/Eastern") + Timestamp("2011-01-02", tz="US/Eastern"), ] s = Series(vals) @@ -176,12 +176,12 @@ def test_iter_box(self): ( pd.DatetimeIndex(["2017", "2018"], tz="US/Central"), DatetimeArray, - "datetime64[ns, US/Central]" + "datetime64[ns, US/Central]", ), ( pd.PeriodIndex([2018, 2019], freq="A"), PeriodArray, - pd.core.dtypes.dtypes.PeriodDtype("A-DEC") + pd.core.dtypes.dtypes.PeriodDtype("A-DEC"), ), (pd.IntervalIndex.from_breaks([0, 1, 2]), IntervalArray, "interval"), # This test is currently failing for datetime64[ns] and timedelta64[ns]. @@ -197,15 +197,15 @@ def test_iter_box(self): pd.DatetimeIndex(["2017", "2018"]), np.ndarray, "datetime64[ns]", - marks=[pytest.mark.xfail(reason="datetime _values", strict=True)] + marks=[pytest.mark.xfail(reason="datetime _values", strict=True)], ), pytest.param( pd.TimedeltaIndex([10 ** 10]), np.ndarray, "m8[ns]", - marks=[pytest.mark.xfail(reason="timedelta _values", strict=True)] - ) - ] + marks=[pytest.mark.xfail(reason="timedelta _values", strict=True)], + ), + ], ) def test_values_consistent(array, expected_type, dtype): l_values = pd.Series(array)._values @@ -250,11 +250,11 @@ def test_numpy_array_all_dtypes(any_numpy_dtype): np.array( ["2000-01-01T12:00:00", "2000-01-02T12:00:00"], dtype="M8[ns]" ), - dtype=DatetimeTZDtype(tz="US/Central") + dtype=DatetimeTZDtype(tz="US/Central"), ), - "_data" - ) - ] + "_data", + ), + ], ) def test_array(array, attr, index_or_series): box = index_or_series @@ -283,21 +283,18 @@ def test_array_multiindex_raises(): (pd.Categorical(["a", "b"]), np.array(["a", "b"], dtype=object)), ( pd.core.arrays.period_array(["2000", "2001"], freq="D"), - np.array([pd.Period("2000", freq="D"), pd.Period("2001", freq="D")]) - ), - ( - pd.core.arrays.integer_array([0, np.nan]), - np.array([0, pd.NA], dtype=object) + np.array([pd.Period("2000", freq="D"), pd.Period("2001", freq="D")]), ), + (pd.core.arrays.integer_array([0, np.nan]), np.array([0, pd.NA], dtype=object)), ( IntervalArray.from_breaks([0, 1, 2]), - np.array([pd.Interval(0, 1), pd.Interval(1, 2)], dtype=object) + np.array([pd.Interval(0, 1), pd.Interval(1, 2)], dtype=object), ), (SparseArray([0, 1]), np.array([0, 1], dtype=np.int64)), # tz-naive datetime ( DatetimeArray(np.array(["2000", "2001"], dtype="M8[ns]")), - np.array(["2000", "2001"], dtype="M8[ns]") + np.array(["2000", "2001"], dtype="M8[ns]"), ), # tz-aware stays tz`-aware ( @@ -305,21 +302,21 @@ def test_array_multiindex_raises(): np.array( ["2000-01-01T06:00:00", "2000-01-02T06:00:00"], dtype="M8[ns]" ), - dtype=DatetimeTZDtype(tz="US/Central") + dtype=DatetimeTZDtype(tz="US/Central"), ), np.array( [ pd.Timestamp("2000-01-01", tz="US/Central"), - pd.Timestamp("2000-01-02", tz="US/Central") + pd.Timestamp("2000-01-02", tz="US/Central"), ] - ) + ), ), # Timedelta ( TimedeltaArray(np.array([0, 3600000000000], dtype="i8"), freq="H"), - np.array([0, 3600000000000], dtype="m8[ns]") - ) - ] + np.array([0, 3600000000000], dtype="m8[ns]"), + ), + ], ) def test_to_numpy(array, expected, index_or_series): box = index_or_series @@ -383,9 +380,9 @@ def test_to_numpy_dtype(as_series): [pd.Timestamp("2000"), pd.Timestamp("2000"), pd.NaT], None, pd.Timestamp("2000"), - [np.datetime64("2000-01-01T00:00:00.000000000")] * 3 - ) - ] + [np.datetime64("2000-01-01T00:00:00.000000000")] * 3, + ), + ], ) def test_to_numpy_na_value_numpy_dtype( index_or_series, values, dtype, na_value, expected @@ -414,8 +411,8 @@ def test_to_numpy_kwargs_raises(): [ {"a": [1, 2, 3], "b": [1, 2, None]}, {"a": np.array([1, 2, 3]), "b": np.array([1, 2, np.nan])}, - {"a": pd.array([1, 2, 3]), "b": pd.array([1, 2, None])} - ] + {"a": pd.array([1, 2, 3]), "b": pd.array([1, 2, None])}, + ], ) @pytest.mark.parametrize("dtype, na_value", [(float, np.nan), (object, None)]) def test_to_numpy_dataframe_na_value(data, dtype, na_value): @@ -431,13 +428,13 @@ def test_to_numpy_dataframe_na_value(data, dtype, na_value): [ ( {"a": pd.array([1, 2, None])}, - np.array([[1.0], [2.0], [np.nan]], dtype=float) + np.array([[1.0], [2.0], [np.nan]], dtype=float), ), ( {"a": [1, 2, 3], "b": [1, 2, 3]}, - np.array([[1, 1], [2, 2], [3, 3]], dtype=float) - ) - ] + np.array([[1, 1], [2, 2], [3, 3]], dtype=float), + ), + ], ) def test_to_numpy_dataframe_single_block(data, expected): # https://github.com/pandas-dev/pandas/issues/33820 diff --git a/pandas/tests/dtypes/test_missing.py b/pandas/tests/dtypes/test_missing.py index 76fea9add5fe0..a642b23379c6f 100644 --- a/pandas/tests/dtypes/test_missing.py +++ b/pandas/tests/dtypes/test_missing.py @@ -17,7 +17,7 @@ isnull, na_value_for_dtype, notna, - notnull + notnull, ) import pandas as pd @@ -56,7 +56,7 @@ def test_notna_notnull(notna_f): tm.makeStringSeries(), tm.makeObjectSeries(), tm.makeTimeSeries(), - tm.makePeriodSeries() + tm.makePeriodSeries(), ]: assert isinstance(notna_f(s), Series) @@ -99,7 +99,7 @@ def test_isna_isnull(self, isna_f): tm.makeStringSeries(), tm.makeObjectSeries(), tm.makeTimeSeries(), - tm.makePeriodSeries() + tm.makePeriodSeries(), ]: assert isinstance(isna_f(s), Series) @@ -107,7 +107,7 @@ def test_isna_isnull(self, isna_f): for df in [ tm.makeTimeDataFrame(), tm.makePeriodFrame(), - tm.makeMixedDataFrame() + tm.makeMixedDataFrame(), ]: result = isna_f(df) expected = df.apply(isna_f) @@ -151,7 +151,7 @@ def test_isna_numpy_nat(self): NaT, np.datetime64("NaT"), np.timedelta64("NaT"), - np.datetime64("NaT", "s") + np.datetime64("NaT", "s"), ] ) result = isna(arr) @@ -208,13 +208,13 @@ def test_isna_old_datetimelike(self): (np.array([1, 1 + 0j, np.nan, 3]), np.array([False, False, True, False])), ( np.array([1, 1 + 0j, np.nan, 3], dtype=object), - np.array([False, False, True, False]) + np.array([False, False, True, False]), ), ( np.array([1, 1 + 0j, np.nan, 3]).astype(object), - np.array([False, False, True, False]) - ) - ] + np.array([False, False, True, False]), + ), + ], ) def test_complex(self, value, expected): result = isna(value) @@ -238,7 +238,7 @@ def test_datetime_other_units(self): "datetime64[s]", "datetime64[ms]", "datetime64[us]", - "datetime64[ns]" + "datetime64[ns]", ]: values = idx.values.astype(dtype) @@ -269,7 +269,7 @@ def test_timedelta_other_units(self): "timedelta64[s]", "timedelta64[ms]", "timedelta64[us]", - "timedelta64[ns]" + "timedelta64[ns]", ]: values = idx.values.astype(dtype) @@ -308,33 +308,33 @@ def test_array_equivalent(dtype_equal): assert array_equivalent( np.array([np.nan, 1, np.nan]), np.array([np.nan, 1, np.nan]), - dtype_equal=dtype_equal + dtype_equal=dtype_equal, ) assert array_equivalent( np.array([np.nan, None], dtype="object"), np.array([np.nan, None], dtype="object"), - dtype_equal=dtype_equal + dtype_equal=dtype_equal, ) # Check the handling of nested arrays in array_equivalent_object assert array_equivalent( np.array([np.array([np.nan, None], dtype="object"), None], dtype="object"), np.array([np.array([np.nan, None], dtype="object"), None], dtype="object"), - dtype_equal=dtype_equal + dtype_equal=dtype_equal, ) assert array_equivalent( np.array([np.nan, 1 + 1j], dtype="complex"), np.array([np.nan, 1 + 1j], dtype="complex"), - dtype_equal=dtype_equal + dtype_equal=dtype_equal, ) assert not array_equivalent( np.array([np.nan, 1 + 1j], dtype="complex"), np.array([np.nan, 1 + 2j], dtype="complex"), - dtype_equal=dtype_equal + dtype_equal=dtype_equal, ) assert not array_equivalent( np.array([np.nan, 1, np.nan]), np.array([np.nan, 2, np.nan]), - dtype_equal=dtype_equal + dtype_equal=dtype_equal, ) assert not array_equivalent( np.array(["a", "b", "c", "d"]), np.array(["e", "e"]), dtype_equal=dtype_equal @@ -354,22 +354,22 @@ def test_array_equivalent(dtype_equal): assert array_equivalent( TimedeltaIndex([0, np.nan]), TimedeltaIndex([0, np.nan]), - dtype_equal=dtype_equal + dtype_equal=dtype_equal, ) assert not array_equivalent( TimedeltaIndex([0, np.nan]), TimedeltaIndex([1, np.nan]), - dtype_equal=dtype_equal + dtype_equal=dtype_equal, ) assert array_equivalent( DatetimeIndex([0, np.nan], tz="US/Eastern"), DatetimeIndex([0, np.nan], tz="US/Eastern"), - dtype_equal=dtype_equal + dtype_equal=dtype_equal, ) assert not array_equivalent( DatetimeIndex([0, np.nan], tz="US/Eastern"), DatetimeIndex([1, np.nan], tz="US/Eastern"), - dtype_equal=dtype_equal + dtype_equal=dtype_equal, ) # The rest are not dtype_equal assert not array_equivalent( @@ -377,7 +377,7 @@ def test_array_equivalent(dtype_equal): ) assert not array_equivalent( DatetimeIndex([0, np.nan], tz="CET"), - DatetimeIndex([0, np.nan], tz="US/Eastern") + DatetimeIndex([0, np.nan], tz="US/Eastern"), ) assert not array_equivalent(DatetimeIndex([0, np.nan]), TimedeltaIndex([0, np.nan])) @@ -399,8 +399,8 @@ def test_array_equivalent_different_dtype_but_equal(): (now.to_pydatetime(), utcnow), (now, utcnow), (now.to_datetime64(), utcnow.to_pydatetime()), - (now.to_pydatetime(), utcnow.to_pydatetime()) - ] + (now.to_pydatetime(), utcnow.to_pydatetime()), + ], ) def test_array_equivalent_tzawareness(lvalue, rvalue): # we shouldn't raise if comparing tzaware and tznaive datetimes @@ -479,8 +479,8 @@ def test_array_equivalent_nested(): # Object ("O", np.nan), # Interval - (IntervalDtype(), np.nan) - ] + (IntervalDtype(), np.nan), + ], ) def test_na_value_for_dtype(dtype, na_value): result = na_value_for_dtype(dtype) @@ -550,7 +550,7 @@ def test_empty_like(self): np.complex64(np.nan), np.complex128(np.nan), np.datetime64("NaT"), - np.timedelta64("NaT") + np.timedelta64("NaT"), ] + [np.datetime64("NaT", unit) for unit in m8_units] + [np.timedelta64("NaT", unit) for unit in m8_units] @@ -562,13 +562,13 @@ def test_empty_like(self): complex("inf"), complex("-inf"), np.inf, - np.NINF + np.NINF, ] int_na_vals = [ # Values that match iNaT, which we treat as null in specific cases np.int64(NaT.value), - int(NaT.value) + int(NaT.value), ] sometimes_na_vals = [Decimal("NaN")] @@ -578,7 +578,7 @@ def test_empty_like(self): -0.0, np.float64("-0.0"), -0j, - np.complex64(-0j) + np.complex64(-0j), ] diff --git a/pandas/tests/extension/base/methods.py b/pandas/tests/extension/base/methods.py index 5e487a5db971d..23e20a2c0903a 100644 --- a/pandas/tests/extension/base/methods.py +++ b/pandas/tests/extension/base/methods.py @@ -92,18 +92,14 @@ def test_argmin_argmax(self, data_for_sorting, data_missing_for_sorting, na_valu assert data_missing_for_sorting.argmax() == 0 assert data_missing_for_sorting.argmin() == 2 - @pytest.mark.parametrize( - "method", ["argmax", "argmin"] - ) + @pytest.mark.parametrize("method", ["argmax", "argmin"]) def test_argmin_argmax_empty_array(self, method, data): # GH 24382 err_msg = "attempt to get" with pytest.raises(ValueError, match=err_msg): getattr(data[:0], method)() - @pytest.mark.parametrize( - "method", ["argmax", "argmin"] - ) + @pytest.mark.parametrize("method", ["argmax", "argmin"]) def test_argmin_argmax_all_na(self, method, data, na_value): # all missing with skipna=True is the same as emtpy err_msg = "attempt to get" @@ -115,8 +111,8 @@ def test_argmin_argmax_all_na(self, method, data, na_value): "na_position, expected", [ ("last", np.array([2, 0, 1], dtype=np.dtype("intp"))), - ("first", np.array([1, 2, 0], dtype=np.dtype("intp"))) - ] + ("first", np.array([1, 2, 0], dtype=np.dtype("intp"))), + ], ) def test_nargsort(self, data_missing_for_sorting, na_position, expected): # GH 25439 @@ -267,7 +263,7 @@ def test_combine_first(self, data): @pytest.mark.parametrize("frame", [True, False]) @pytest.mark.parametrize( "periods, indices", - [(-2, [2, 3, 4, -1, -1]), (0, [0, 1, 2, 3, 4]), (2, [-1, -1, 0, 1, 2])] + [(-2, [2, 3, 4, -1, -1]), (0, [0, 1, 2, 3, 4]), (2, [-1, -1, 0, 1, 2])], ) def test_container_shift(self, data, frame, periods, indices): # https://github.com/pandas-dev/pandas/issues/22386 @@ -322,7 +318,7 @@ def test_diff(self, data, periods): @pytest.mark.parametrize( "periods, indices", - [[-4, [-1, -1]], [-1, [1, -1]], [0, [0, 1]], [1, [-1, 0]], [4, [-1, -1]]] + [[-4, [-1, -1]], [-1, [1, -1]], [0, [0, 1]], [1, [-1, 0]], [4, [-1, -1]]], ) def test_shift_non_empty_array(self, data, periods, indices): # https://github.com/pandas-dev/pandas/issues/23911 @@ -450,8 +446,8 @@ def test_repeat(self, data, repeats, as_series, use_numpy): (2, dict(axis=1), ValueError, "'axis"), (-1, dict(), ValueError, "negative"), ([1, 2], dict(), ValueError, "shape"), - (2, dict(foo="bar"), TypeError, "'foo'") - ] + (2, dict(foo="bar"), TypeError, "'foo'"), + ], ) def test_repeat_raises(self, data, repeats, kwargs, error, msg, use_numpy): with pytest.raises(error, match=msg): diff --git a/pandas/tests/extension/test_sparse.py b/pandas/tests/extension/test_sparse.py index 0aa56cfb30d75..d11cfd219a443 100644 --- a/pandas/tests/extension/test_sparse.py +++ b/pandas/tests/extension/test_sparse.py @@ -221,7 +221,7 @@ def test_fillna_frame(self, data_missing): expected = pd.DataFrame( { "A": data_missing._from_sequence([fill_value, fill_value], dtype=dtype), - "B": [1, 2] + "B": [1, 2], } ) @@ -240,7 +240,7 @@ def test_combine_le(self, data_repeated): expected = pd.Series( SparseArray( [a <= b for (a, b) in zip(list(orig_data1), list(orig_data2))], - fill_value=False + fill_value=False, ) ) self.assert_series_equal(result, expected) @@ -316,9 +316,7 @@ def test_shift_0_periods(self, data): data._sparse_values[0] = data._sparse_values[1] assert result._sparse_values[0] != result._sparse_values[1] - @pytest.mark.parametrize( - "method", ["argmax", "argmin"] - ) + @pytest.mark.parametrize("method", ["argmax", "argmin"]) def test_argmin_argmax_all_na(self, method, data, na_value): # overriding because Sparse[int64, 0] cannot handle na_value self._check_unsupported(data) @@ -403,7 +401,7 @@ def _compare_other(self, s, data, op_name, other): expected = pd.Series( SparseArray( op(np.asarray(data), np.asarray(other)), - fill_value=result.values.fill_value + fill_value=result.values.fill_value, ) ) diff --git a/pandas/tests/frame/indexing/test_setitem.py b/pandas/tests/frame/indexing/test_setitem.py index 89591d4c8dc9c..8313ab0b99bac 100644 --- a/pandas/tests/frame/indexing/test_setitem.py +++ b/pandas/tests/frame/indexing/test_setitem.py @@ -11,7 +11,7 @@ Period, Series, Timestamp, - date_range + date_range, ) import pandas._testing as tm from pandas.core.arrays import SparseArray @@ -23,12 +23,12 @@ def test_setitem_error_msmgs(self): # GH 7432 df = DataFrame( {"bar": [1, 2, 3], "baz": ["d", "e", "f"]}, - index=Index(["a", "b", "c"], name="foo") + index=Index(["a", "b", "c"], name="foo"), ) ser = Series( ["g", "h", "i", "j"], index=Index(["a", "b", "c", "a"], name="foo"), - name="fiz" + name="fiz", ) msg = "cannot reindex from a duplicate axis" with pytest.raises(ValueError, match=msg): @@ -66,7 +66,7 @@ def test_setitem_different_dtype(self): result = df.dtypes expected = Series( [np.dtype("float64")] * 5 + [np.dtype("float32")], - index=["foo", "c", "bar", "b", "a", "x"] + index=["foo", "c", "bar", "b", "a", "x"], ) tm.assert_series_equal(result, expected) @@ -75,7 +75,7 @@ def test_setitem_different_dtype(self): result = df.dtypes expected = Series( [np.dtype("float64")] * 4 + [np.dtype("float32")] * 2, - index=["foo", "c", "bar", "b", "a", "x"] + index=["foo", "c", "bar", "b", "a", "x"], ) tm.assert_series_equal(result, expected) @@ -83,7 +83,7 @@ def test_setitem_different_dtype(self): result = df.dtypes expected = Series( [np.dtype("float64")] * 4 + [np.dtype("float32")] * 2 + [np.dtype("int32")], - index=["foo", "c", "bar", "b", "a", "x", "y"] + index=["foo", "c", "bar", "b", "a", "x", "y"], ) tm.assert_series_equal(result, expected) @@ -147,22 +147,18 @@ def test_setitem_dict_preserves_dtypes(self): { "a": Series([0, 1, 2], dtype="int64"), "b": Series([1, 2, 3], dtype=float), - "c": Series([1, 2, 3], dtype=float) + "c": Series([1, 2, 3], dtype=float), } ) df = DataFrame( { "a": Series([], dtype="int64"), "b": Series([], dtype=float), - "c": Series([], dtype=float) + "c": Series([], dtype=float), } ) for idx, b in enumerate([1, 2, 3]): - df.loc[df.shape[0]] = { - "a": int(idx), - "b": float(b), - "c": float(b) - } + df.loc[df.shape[0]] = {"a": int(idx), "b": float(b), "c": float(b)} tm.assert_frame_equal(df, expected) @pytest.mark.parametrize( @@ -173,8 +169,8 @@ def test_setitem_dict_preserves_dtypes(self): ( Timestamp("2011-01-01", tz="US/Eastern"), DatetimeTZDtype(tz="US/Eastern"), - ) - ] + ), + ], ) def test_setitem_extension_types(self, obj, dtype): # GH: 34832 From 02ef6146c69102207c9f9f72083acfa8f1d972ab Mon Sep 17 00:00:00 2001 From: satrio Date: Tue, 8 Sep 2020 18:34:25 +0700 Subject: [PATCH 3/3] overwrite back pandas/tests/arrays/sparse/test_array.py with master --- pandas/tests/arrays/sparse/test_array.py | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/pandas/tests/arrays/sparse/test_array.py b/pandas/tests/arrays/sparse/test_array.py index b4e4647c9bf35..ece9367cea7fe 100644 --- a/pandas/tests/arrays/sparse/test_array.py +++ b/pandas/tests/arrays/sparse/test_array.py @@ -193,7 +193,9 @@ def test_constructor_inferred_fill_value(self, data, fill_value): assert result == fill_value @pytest.mark.parametrize("format", ["coo", "csc", "csr"]) - @pytest.mark.parametrize("size", [0, 10]) + @pytest.mark.parametrize( + "size", [0, 10], + ) @td.skip_if_no_scipy def test_from_spmatrix(self, size, format): import scipy.sparse @@ -694,23 +696,14 @@ def test_getslice_tuple(self): res = sparse[ 4:, ] # noqa: E231 - exp = SparseArray( - dense[ - 4:, - ] - ) # noqa: E231 + exp = SparseArray(dense[4:,]) # noqa: E231 tm.assert_sp_array_equal(res, exp) sparse = SparseArray(dense, fill_value=0) res = sparse[ 4:, ] # noqa: E231 - exp = SparseArray( - dense[ - 4:, - ], - fill_value=0, - ) # noqa: E231 + exp = SparseArray(dense[4:,], fill_value=0) # noqa: E231 tm.assert_sp_array_equal(res, exp) msg = "too many indices for array"