From 8839e1bafccc796ca41617af02c12aa68c452378 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Fri, 13 Dec 2019 16:09:11 +0000 Subject: [PATCH] CLN: various lgtm.com cleanups --- pandas/core/apply.py | 1 - pandas/core/arrays/datetimes.py | 1 - pandas/core/arrays/integer.py | 3 ++- pandas/core/arrays/numpy_.py | 8 ++++++++ pandas/core/arrays/sparse/dtype.py | 7 +++++++ pandas/core/arrays/timedeltas.py | 1 - pandas/core/dtypes/base.py | 2 +- pandas/core/dtypes/dtypes.py | 15 +++++++++++---- pandas/core/frame.py | 1 - pandas/core/generic.py | 2 -- pandas/core/groupby/grouper.py | 2 +- pandas/core/indexes/base.py | 2 -- pandas/core/internals/blocks.py | 1 - pandas/core/reshape/reshape.py | 2 -- pandas/plotting/_matplotlib/hist.py | 2 +- pandas/tests/arrays/test_array.py | 7 +++++++ pandas/tests/extension/arrow/arrays.py | 14 ++++++++++++++ pandas/tests/extension/decimal/array.py | 3 ++- pandas/tests/extension/json/array.py | 3 ++- 19 files changed, 56 insertions(+), 21 deletions(-) diff --git a/pandas/core/apply.py b/pandas/core/apply.py index ef3d8cd53596b..14a3c3c008e92 100644 --- a/pandas/core/apply.py +++ b/pandas/core/apply.py @@ -320,7 +320,6 @@ def apply_series_generator(self) -> Tuple[ResType, "Index"]: series_gen = self.series_generator res_index = self.result_index - i = None keys = [] results = {} if self.ignore_failures: diff --git a/pandas/core/arrays/datetimes.py b/pandas/core/arrays/datetimes.py index 2cd8aafe00f37..e41f2a840d151 100644 --- a/pandas/core/arrays/datetimes.py +++ b/pandas/core/arrays/datetimes.py @@ -2109,7 +2109,6 @@ def _validate_dt64_dtype(dtype): dtype = pandas_dtype(dtype) if is_dtype_equal(dtype, np.dtype("M8")): # no precision, disallowed GH#24806 - dtype = _NS_DTYPE msg = ( "Passing in 'datetime64' dtype with no precision is not allowed. " "Please pass in 'datetime64[ns]' instead." diff --git a/pandas/core/arrays/integer.py b/pandas/core/arrays/integer.py index d47e7e3df27e1..c0ca30be34ad5 100644 --- a/pandas/core/arrays/integer.py +++ b/pandas/core/arrays/integer.py @@ -78,7 +78,8 @@ def itemsize(self): @classmethod def construct_array_type(cls): - """Return the array type associated with this dtype + """ + Return the array type associated with this dtype. Returns ------- diff --git a/pandas/core/arrays/numpy_.py b/pandas/core/arrays/numpy_.py index 13748e03e856d..deec30dfe34ff 100644 --- a/pandas/core/arrays/numpy_.py +++ b/pandas/core/arrays/numpy_.py @@ -79,7 +79,15 @@ def construct_from_string(cls, string): f"Cannot construct a 'PandasDtype' from '{string}'" ) from err + @classmethod def construct_array_type(cls): + """ + Return the array type associated with this dtype. + + Returns + ------- + type + """ return PandasArray @property diff --git a/pandas/core/arrays/sparse/dtype.py b/pandas/core/arrays/sparse/dtype.py index a295dfed2cf96..935f657416396 100644 --- a/pandas/core/arrays/sparse/dtype.py +++ b/pandas/core/arrays/sparse/dtype.py @@ -168,6 +168,13 @@ def __repr__(self) -> str: @classmethod def construct_array_type(cls): + """ + Return the array type associated with this dtype. + + Returns + ------- + type + """ from .array import SparseArray return SparseArray diff --git a/pandas/core/arrays/timedeltas.py b/pandas/core/arrays/timedeltas.py index b51773961811b..db4effa608582 100644 --- a/pandas/core/arrays/timedeltas.py +++ b/pandas/core/arrays/timedeltas.py @@ -1122,7 +1122,6 @@ def _validate_td64_dtype(dtype): dtype = pandas_dtype(dtype) if is_dtype_equal(dtype, np.dtype("timedelta64")): # no precision disallowed GH#24806 - dtype = _TD_DTYPE msg = ( "Passing in 'timedelta' dtype with no precision is not allowed. " "Please pass in 'timedelta64[ns]' instead." diff --git a/pandas/core/dtypes/base.py b/pandas/core/dtypes/base.py index ae544376c452e..1dda51da49ffb 100644 --- a/pandas/core/dtypes/base.py +++ b/pandas/core/dtypes/base.py @@ -183,7 +183,7 @@ def names(self) -> Optional[List[str]]: @classmethod def construct_array_type(cls): """ - Return the array type associated with this dtype + Return the array type associated with this dtype. Returns ------- diff --git a/pandas/core/dtypes/dtypes.py b/pandas/core/dtypes/dtypes.py index 4421fad5f19d1..77ec182be5ed4 100644 --- a/pandas/core/dtypes/dtypes.py +++ b/pandas/core/dtypes/dtypes.py @@ -486,7 +486,7 @@ def _hash_categories(categories, ordered: Ordered = True) -> int: @classmethod def construct_array_type(cls): """ - Return the array type associated with this dtype + Return the array type associated with this dtype. Returns ------- @@ -668,7 +668,7 @@ def __init__(self, unit="ns", tz=None): unit = result.unit tz = result.tz msg = ( - "Passing a dtype alias like 'datetime64[ns, {tz}]' " + f"Passing a dtype alias like 'datetime64[ns, {tz}]' " "to DatetimeTZDtype is no longer supported. Use " "'DatetimeTZDtype.construct_from_string()' instead." ) @@ -704,7 +704,7 @@ def tz(self): @classmethod def construct_array_type(cls): """ - Return the array type associated with this dtype + Return the array type associated with this dtype. Returns ------- @@ -936,6 +936,13 @@ def is_dtype(cls, dtype) -> bool: @classmethod def construct_array_type(cls): + """ + Return the array type associated with this dtype. + + Returns + ------- + type + """ from pandas.core.arrays import PeriodArray return PeriodArray @@ -1030,7 +1037,7 @@ def subtype(self): @classmethod def construct_array_type(cls): """ - Return the array type associated with this dtype + Return the array type associated with this dtype. Returns ------- diff --git a/pandas/core/frame.py b/pandas/core/frame.py index fa85c54eb42fa..0c5caac36054e 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -2606,7 +2606,6 @@ def _ixs(self, i: int, axis: int = 0): """ # irow if axis == 0: - label = self.index[i] new_values = self._data.fast_xs(i) # if we are a copy, mark as such diff --git a/pandas/core/generic.py b/pandas/core/generic.py index cf2244b4df4d2..4508f02757def 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -5746,8 +5746,6 @@ def __deepcopy__(self: FrameOrSeries, memo=None) -> FrameOrSeries: memo, default None Standard signature. Unused """ - if memo is None: - memo = {} return self.copy(deep=True) def _convert( diff --git a/pandas/core/groupby/grouper.py b/pandas/core/groupby/grouper.py index b0df04f18ff1d..63d6e88850cdd 100644 --- a/pandas/core/groupby/grouper.py +++ b/pandas/core/groupby/grouper.py @@ -131,7 +131,7 @@ def _get_grouper(self, obj, validate: bool = True): """ self._set_grouper(obj) - self.grouper, exclusions, self.obj = get_grouper( + self.grouper, _, self.obj = get_grouper( self.obj, [self.key], axis=self.axis, diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index fc2412ceaca0e..22dd25c0448d2 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -910,8 +910,6 @@ def __deepcopy__(self, memo=None): memo, default None Standard signature. Unused """ - if memo is None: - memo = {} return self.copy(deep=True) # -------------------------------------------------------------------- diff --git a/pandas/core/internals/blocks.py b/pandas/core/internals/blocks.py index 8a543832b50fe..610a39a05148b 100644 --- a/pandas/core/internals/blocks.py +++ b/pandas/core/internals/blocks.py @@ -3024,7 +3024,6 @@ def _merge_blocks(blocks, dtype=None, _can_consolidate=True): if dtype is None: if len({b.dtype for b in blocks}) != 1: raise AssertionError("_merge_blocks are invalid!") - dtype = blocks[0].dtype # FIXME: optimization potential in case all mgrs contain slices and # combination of those slices is a slice, too. diff --git a/pandas/core/reshape/reshape.py b/pandas/core/reshape/reshape.py index a8dcc995e48da..b74eda38a08fe 100644 --- a/pandas/core/reshape/reshape.py +++ b/pandas/core/reshape/reshape.py @@ -230,11 +230,9 @@ def get_new_values(self): if needs_i8_conversion(values): sorted_values = sorted_values.view("i8") new_values = new_values.view("i8") - name = "int64" elif is_bool_dtype(values): sorted_values = sorted_values.astype("object") new_values = new_values.astype("object") - name = "object" else: sorted_values = sorted_values.astype(name, copy=False) diff --git a/pandas/plotting/_matplotlib/hist.py b/pandas/plotting/_matplotlib/hist.py index dc9eede7e4d52..8957389ac2b13 100644 --- a/pandas/plotting/_matplotlib/hist.py +++ b/pandas/plotting/_matplotlib/hist.py @@ -27,7 +27,7 @@ def _args_adjust(self): values = np.ravel(values) values = values[~isna(values)] - hist, self.bins = np.histogram( + _, self.bins = np.histogram( values, bins=self.bins, range=self.kwds.get("range", None), diff --git a/pandas/tests/arrays/test_array.py b/pandas/tests/arrays/test_array.py index 479f8dbad0418..f2a4e73e7b6ad 100644 --- a/pandas/tests/arrays/test_array.py +++ b/pandas/tests/arrays/test_array.py @@ -287,6 +287,13 @@ class DecimalDtype2(DecimalDtype): @classmethod def construct_array_type(cls): + """ + Return the array type associated with this dtype. + + Returns + ------- + type + """ return DecimalArray2 diff --git a/pandas/tests/extension/arrow/arrays.py b/pandas/tests/extension/arrow/arrays.py index 86e23b3264456..b0e5a6f85feeb 100644 --- a/pandas/tests/extension/arrow/arrays.py +++ b/pandas/tests/extension/arrow/arrays.py @@ -37,6 +37,13 @@ def construct_from_string(cls, string): @classmethod def construct_array_type(cls): + """ + Return the array type associated with this dtype. + + Returns + ------- + type + """ return ArrowBoolArray def _is_boolean(self): @@ -60,6 +67,13 @@ def construct_from_string(cls, string): @classmethod def construct_array_type(cls): + """ + Return the array type associated with this dtype. + + Returns + ------- + type + """ return ArrowStringArray diff --git a/pandas/tests/extension/decimal/array.py b/pandas/tests/extension/decimal/array.py index 0b0865c424f34..74f1e3cfbaf20 100644 --- a/pandas/tests/extension/decimal/array.py +++ b/pandas/tests/extension/decimal/array.py @@ -27,7 +27,8 @@ def __repr__(self) -> str: @classmethod def construct_array_type(cls): - """Return the array type associated with this dtype + """ + Return the array type associated with this dtype. Returns ------- diff --git a/pandas/tests/extension/json/array.py b/pandas/tests/extension/json/array.py index 28929d50718b6..46ca7bd8f760a 100644 --- a/pandas/tests/extension/json/array.py +++ b/pandas/tests/extension/json/array.py @@ -31,7 +31,8 @@ class JSONDtype(ExtensionDtype): @classmethod def construct_array_type(cls): - """Return the array type associated with this dtype + """ + Return the array type associated with this dtype. Returns -------