From ccfc632234d51c38aa15f94ab541cff2e10fc3a3 Mon Sep 17 00:00:00 2001 From: VirosaLi <2EkF8qUgpNkj> Date: Sat, 5 Dec 2020 13:39:51 -0600 Subject: [PATCH] CLN: fix C408 #38138 --- pandas/core/arrays/base.py | 2 +- pandas/core/computation/expressions.py | 2 +- pandas/core/dtypes/dtypes.py | 2 +- pandas/core/generic.py | 16 ++--- pandas/core/indexes/base.py | 4 +- pandas/core/indexes/interval.py | 56 +++++++-------- pandas/core/indexes/multi.py | 20 +++--- pandas/core/series.py | 6 +- pandas/tests/dtypes/test_inference.py | 6 +- pandas/tests/frame/methods/test_to_records.py | 2 +- .../tests/groupby/transform/test_transform.py | 4 +- pandas/tests/io/formats/test_format.py | 6 +- pandas/tests/io/parser/test_c_parser_only.py | 8 +-- pandas/tests/io/parser/test_read_fwf.py | 6 +- pandas/tests/io/pytables/test_timezones.py | 71 ++++++++++--------- 15 files changed, 106 insertions(+), 105 deletions(-) diff --git a/pandas/core/arrays/base.py b/pandas/core/arrays/base.py index 77cd603cc6b8d..95470422f2ccd 100644 --- a/pandas/core/arrays/base.py +++ b/pandas/core/arrays/base.py @@ -952,7 +952,7 @@ def factorize(self, na_sentinel: int = -1) -> Tuple[np.ndarray, ExtensionArray]: @Substitution(klass="ExtensionArray") @Appender(_extension_array_shared_docs["repeat"]) def repeat(self, repeats, axis=None): - nv.validate_repeat(tuple(), {"axis": axis}) + nv.validate_repeat((), {"axis": axis}) ind = np.arange(len(self)).repeat(repeats) return self.take(ind) diff --git a/pandas/core/computation/expressions.py b/pandas/core/computation/expressions.py index 23cf3019df461..e5ede3cd885be 100644 --- a/pandas/core/computation/expressions.py +++ b/pandas/core/computation/expressions.py @@ -22,7 +22,7 @@ import numexpr as ne _TEST_MODE = None -_TEST_RESULT: List[bool] = list() +_TEST_RESULT: List[bool] = [] USE_NUMEXPR = NUMEXPR_INSTALLED _evaluate = None _where = None diff --git a/pandas/core/dtypes/dtypes.py b/pandas/core/dtypes/dtypes.py index 136c8032094b1..3c5421ae433b6 100644 --- a/pandas/core/dtypes/dtypes.py +++ b/pandas/core/dtypes/dtypes.py @@ -53,7 +53,7 @@ class PandasExtensionDtype(ExtensionDtype): subdtype = None str: str_type num = 100 - shape: Tuple[int, ...] = tuple() + shape: Tuple[int, ...] = () itemsize = 8 base = None isbuiltin = 0 diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 4a9e020a0fe46..c32269a75b3cf 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -3569,7 +3569,7 @@ class max_speed stacklevel=2, ) - nv.validate_take(tuple(), kwargs) + nv.validate_take((), kwargs) self._consolidate_inplace() @@ -10557,7 +10557,7 @@ def _agg_by_level(self, name, axis=0, level=0, skipna=True, **kwargs): def _logical_func( self, name: str, func, axis=0, bool_only=None, skipna=True, level=None, **kwargs ): - nv.validate_logical_func(tuple(), kwargs, fname=name) + nv.validate_logical_func((), kwargs, fname=name) if level is not None: if bool_only is not None: raise NotImplementedError( @@ -10644,7 +10644,7 @@ def _stat_function_ddof( numeric_only=None, **kwargs, ): - nv.validate_stat_ddof_func(tuple(), kwargs, fname=name) + nv.validate_stat_ddof_func((), kwargs, fname=name) if skipna is None: skipna = True if axis is None: @@ -10690,9 +10690,9 @@ def _stat_function( **kwargs, ): if name == "median": - nv.validate_median(tuple(), kwargs) + nv.validate_median((), kwargs) else: - nv.validate_stat_func(tuple(), kwargs, fname=name) + nv.validate_stat_func((), kwargs, fname=name) if skipna is None: skipna = True if axis is None: @@ -10748,11 +10748,11 @@ def _min_count_stat_function( **kwargs, ): if name == "sum": - nv.validate_sum(tuple(), kwargs) + nv.validate_sum((), kwargs) elif name == "prod": - nv.validate_prod(tuple(), kwargs) + nv.validate_prod((), kwargs) else: - nv.validate_stat_func(tuple(), kwargs, fname=name) + nv.validate_stat_func((), kwargs, fname=name) if skipna is None: skipna = True if axis is None: diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index ba958b23e81af..0f6aa36a4c082 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -742,7 +742,7 @@ def astype(self, dtype, copy=True): @Appender(_index_shared_docs["take"] % _index_doc_kwargs) def take(self, indices, axis=0, allow_fill=True, fill_value=None, **kwargs): if kwargs: - nv.validate_take(tuple(), kwargs) + nv.validate_take((), kwargs) indices = ensure_platform_int(indices) allow_fill = self._maybe_disallow_fill(allow_fill, fill_value, indices) @@ -817,7 +817,7 @@ def _maybe_disallow_fill(self, allow_fill: bool, fill_value, indices) -> bool: @Appender(_index_shared_docs["repeat"] % _index_doc_kwargs) def repeat(self, repeats, axis=None): repeats = ensure_platform_int(repeats) - nv.validate_repeat(tuple(), {"axis": axis}) + nv.validate_repeat((), {"axis": axis}) return self._shallow_copy(self._values.repeat(repeats)) # -------------------------------------------------------------------- diff --git a/pandas/core/indexes/interval.py b/pandas/core/indexes/interval.py index 2f86d9c20bfe8..fc3e46345e06c 100644 --- a/pandas/core/indexes/interval.py +++ b/pandas/core/indexes/interval.py @@ -65,17 +65,17 @@ _index_doc_kwargs = dict(ibase._index_doc_kwargs) _index_doc_kwargs.update( - dict( - klass="IntervalIndex", - qualname="IntervalIndex", - target_klass="IntervalIndex or list of Intervals", - name=textwrap.dedent( + { + "klass": "IntervalIndex", + "qualname": "IntervalIndex", + "target_klass": "IntervalIndex or list of Intervals", + "name": textwrap.dedent( """\ name : object, optional Name to be stored in the index. """ ), - ) + } ) @@ -141,14 +141,14 @@ def wrapped(self, other, sort=False): @Appender( _interval_shared_docs["class"] - % dict( - klass="IntervalIndex", - summary="Immutable index of intervals that are closed on the same side.", - name=_index_doc_kwargs["name"], - versionadded="0.20.0", - extra_attributes="is_overlapping\nvalues\n", - extra_methods="", - examples=textwrap.dedent( + % { + "klass": "IntervalIndex", + "summary": "Immutable index of intervals that are closed on the same side.", + "name": _index_doc_kwargs["name"], + "versionadded": "0.20.0", + "extra_attributes": "is_overlapping\nvalues\n", + "extra_methods": "", + "examples": textwrap.dedent( """\ Examples -------- @@ -168,7 +168,7 @@ def wrapped(self, other, sort=False): mentioned constructor methods. """ ), - ) + } ) @inherit_names(["set_closed", "to_tuples"], IntervalArray, wrap=True) @inherit_names(["__array__", "overlaps", "contains"], IntervalArray) @@ -234,9 +234,9 @@ def _simple_new(cls, array: IntervalArray, name: Label = None): @classmethod @Appender( _interval_shared_docs["from_breaks"] - % dict( - klass="IntervalIndex", - examples=textwrap.dedent( + % { + "klass": "IntervalIndex", + "examples": textwrap.dedent( """\ Examples -------- @@ -246,7 +246,7 @@ def _simple_new(cls, array: IntervalArray, name: Label = None): dtype='interval[int64]') """ ), - ) + } ) def from_breaks( cls, breaks, closed: str = "right", name=None, copy: bool = False, dtype=None @@ -260,9 +260,9 @@ def from_breaks( @classmethod @Appender( _interval_shared_docs["from_arrays"] - % dict( - klass="IntervalIndex", - examples=textwrap.dedent( + % { + "klass": "IntervalIndex", + "examples": textwrap.dedent( """\ Examples -------- @@ -272,7 +272,7 @@ def from_breaks( dtype='interval[int64]') """ ), - ) + } ) def from_arrays( cls, @@ -292,9 +292,9 @@ def from_arrays( @classmethod @Appender( _interval_shared_docs["from_tuples"] - % dict( - klass="IntervalIndex", - examples=textwrap.dedent( + % { + "klass": "IntervalIndex", + "examples": textwrap.dedent( """\ Examples -------- @@ -304,7 +304,7 @@ def from_arrays( dtype='interval[int64]') """ ), - ) + } ) def from_tuples( cls, data, closed: str = "right", name=None, copy: bool = False, dtype=None @@ -360,7 +360,7 @@ def __array_wrap__(self, result, context=None): return result def __reduce__(self): - d = dict(left=self.left, right=self.right) + d = {"left": self.left, "right": self.right} d.update(self._get_attributes_dict()) return _new_IntervalIndex, (type(self), d), None diff --git a/pandas/core/indexes/multi.py b/pandas/core/indexes/multi.py index fd47c23b7c92b..ce01346da0f98 100644 --- a/pandas/core/indexes/multi.py +++ b/pandas/core/indexes/multi.py @@ -74,7 +74,7 @@ _index_doc_kwargs = dict(ibase._index_doc_kwargs) _index_doc_kwargs.update( - dict(klass="MultiIndex", target_klass="MultiIndex or list of tuples") + {"klass": "MultiIndex", "target_klass": "MultiIndex or list of tuples"} ) @@ -2007,12 +2007,12 @@ def remove_unused_levels(self): def __reduce__(self): """Necessary for making this object picklable""" - d = dict( - levels=list(self.levels), - codes=list(self.codes), - sortorder=self.sortorder, - names=list(self.names), - ) + d = { + "levels": list(self.levels), + "codes": list(self.codes), + "sortorder": self.sortorder, + "names": list(self.names), + } return ibase._new_Index, (type(self), d), None # -------------------------------------------------------------------- @@ -2052,7 +2052,7 @@ def __getitem__(self, key): @Appender(_index_shared_docs["take"] % _index_doc_kwargs) def take(self, indices, axis=0, allow_fill=True, fill_value=None, **kwargs): - nv.validate_take(tuple(), kwargs) + nv.validate_take((), kwargs) indices = ensure_platform_int(indices) # only fill if we are passing a non-None fill_value @@ -2116,7 +2116,7 @@ def argsort(self, *args, **kwargs) -> np.ndarray: @Appender(_index_shared_docs["repeat"] % _index_doc_kwargs) def repeat(self, repeats, axis=None): - nv.validate_repeat(tuple(), dict(axis=axis)) + nv.validate_repeat((), {"axis": axis}) repeats = ensure_platform_int(repeats) return MultiIndex( levels=self.levels, @@ -3353,7 +3353,7 @@ def _reorder_indexer( return indexer n = len(self) - keys: Tuple[np.ndarray, ...] = tuple() + keys: Tuple[np.ndarray, ...] = () # For each level of the sequence in seq, map the level codes with the # order they appears in a list-like sequence # This mapping is then use to reorder the indexer diff --git a/pandas/core/series.py b/pandas/core/series.py index b20cf8eed9a2e..0e9476285c258 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -374,7 +374,7 @@ def _init_dict(self, data, index=None, dtype=None): values = na_value_for_dtype(dtype) keys = index else: - keys, values = tuple(), [] + keys, values = (), [] # Input is now list-like, so rely on "standard" construction: @@ -775,7 +775,7 @@ def take(self, indices, axis=0, is_copy=None, **kwargs) -> "Series": FutureWarning, stacklevel=2, ) - nv.validate_take(tuple(), kwargs) + nv.validate_take((), kwargs) indices = ensure_platform_int(indices) new_index = self.index.take(indices) @@ -1114,7 +1114,7 @@ def repeat(self, repeats, axis=None) -> "Series": 2 c dtype: object """ - nv.validate_repeat(tuple(), {"axis": axis}) + nv.validate_repeat((), {"axis": axis}) new_index = self.index.repeat(repeats) new_values = self._values.repeat(repeats) return self._constructor(new_values, index=new_index).__finalize__( diff --git a/pandas/tests/dtypes/test_inference.py b/pandas/tests/dtypes/test_inference.py index c9ca5cb34d271..ce9d5b1dca505 100644 --- a/pandas/tests/dtypes/test_inference.py +++ b/pandas/tests/dtypes/test_inference.py @@ -66,7 +66,7 @@ def coerce(request): ([1], True, "list"), ([], True, "list-empty"), ((1,), True, "tuple"), - (tuple(), True, "tuple-empty"), + ((), True, "tuple-empty"), ({"a": 1}, True, "dict"), ({}, True, "dict-empty"), ({"a", 1}, "set", "set"), @@ -161,7 +161,7 @@ class DtypeList(list): assert inference.is_array_like(DtypeList()) assert not inference.is_array_like([1, 2, 3]) - assert not inference.is_array_like(tuple()) + assert not inference.is_array_like(()) assert not inference.is_array_like("foo") assert not inference.is_array_like(123) @@ -326,7 +326,7 @@ class UnhashableClass2: def __hash__(self): raise TypeError("Not hashable") - hashable = (1, 3.14, np.float64(3.14), "a", tuple(), (1,), HashableClass()) + hashable = (1, 3.14, np.float64(3.14), "a", (), (1,), HashableClass()) not_hashable = ([], UnhashableClass1()) abc_hashable_not_really_hashable = (([],), UnhashableClass2()) diff --git a/pandas/tests/frame/methods/test_to_records.py b/pandas/tests/frame/methods/test_to_records.py index 4d40f191a904b..e83882be9c680 100644 --- a/pandas/tests/frame/methods/test_to_records.py +++ b/pandas/tests/frame/methods/test_to_records.py @@ -238,7 +238,7 @@ def test_to_records_with_categorical(self): ), # Invalid dype values. ( - {"index": False, "column_dtypes": list()}, + {"index": False, "column_dtypes": []}, (ValueError, "Invalid dtype \\[\\] specified for column A"), ), ( diff --git a/pandas/tests/groupby/transform/test_transform.py b/pandas/tests/groupby/transform/test_transform.py index 8acd051fbc643..72637400ff023 100644 --- a/pandas/tests/groupby/transform/test_transform.py +++ b/pandas/tests/groupby/transform/test_transform.py @@ -162,7 +162,7 @@ def test_transform_axis_1(transformation_func): # GH 36308 if transformation_func == "tshift": pytest.xfail("tshift is deprecated") - args = ("ffill",) if transformation_func == "fillna" else tuple() + args = ("ffill",) if transformation_func == "fillna" else () df = DataFrame({"a": [1, 2], "b": [3, 4], "c": [5, 6]}, index=["x", "y"]) result = df.groupby([0, 0, 1], axis=1).transform(transformation_func, *args) @@ -803,7 +803,7 @@ def test_group_fill_methods( keys = ["a", "b"] * len(vals) def interweave(list_obj): - temp = list() + temp = [] for x in list_obj: temp.extend([x, x]) diff --git a/pandas/tests/io/formats/test_format.py b/pandas/tests/io/formats/test_format.py index 4f2cd6d0f80fe..fe85849c6dcca 100644 --- a/pandas/tests/io/formats/test_format.py +++ b/pandas/tests/io/formats/test_format.py @@ -2908,11 +2908,11 @@ def test_too_long(self): with pd.option_context("display.precision", 4): # need both a number > 1e6 and something that normally formats to # having length > display.precision + 6 - df = DataFrame(dict(x=[12345.6789])) + df = DataFrame({"x": [12345.6789]}) assert str(df) == " x\n0 12345.6789" - df = DataFrame(dict(x=[2e6])) + df = DataFrame({"x": [2e6]}) assert str(df) == " x\n0 2000000.0" - df = DataFrame(dict(x=[12345.6789, 2e6])) + df = DataFrame({"x": [12345.6789, 2e6]}) assert str(df) == " x\n0 1.2346e+04\n1 2.0000e+06" diff --git a/pandas/tests/io/parser/test_c_parser_only.py b/pandas/tests/io/parser/test_c_parser_only.py index 06ccfa7f62863..81c75c29f88cf 100644 --- a/pandas/tests/io/parser/test_c_parser_only.py +++ b/pandas/tests/io/parser/test_c_parser_only.py @@ -117,20 +117,20 @@ def test_dtype_and_names_error(c_parser_only): "the dtype datetime64 is not supported for parsing, " "pass this column using parse_dates instead" ), - dict(dtype={"A": "datetime64", "B": "float64"}), + {"dtype": {"A": "datetime64", "B": "float64"}}, ), ( ( "the dtype datetime64 is not supported for parsing, " "pass this column using parse_dates instead" ), - dict(dtype={"A": "datetime64", "B": "float64"}, parse_dates=["B"]), + {"dtype": {"A": "datetime64", "B": "float64"}, "parse_dates": ["B"]}, ), ( "the dtype timedelta64 is not supported for parsing", - dict(dtype={"A": "timedelta64", "B": "float64"}), + {"dtype": {"A": "timedelta64", "B": "float64"}}, ), - ("the dtype