diff --git a/ci/code_checks.sh b/ci/code_checks.sh index 51edc218cc2bd..856c0f5936079 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -130,6 +130,10 @@ if [[ -z "$CHECK" || "$CHECK" == "patterns" ]]; then invgrep -R --include="*.py" --include="*.pyx" -E "# -\*- coding: utf-8 -\*-" pandas scripts RET=$(($RET + $?)) ; echo $MSG "DONE" + MSG='Check for python2-style super usage' ; echo $MSG + invgrep -R --include="*.py" -E "super\(\w*, (self|cls)\)" pandas + RET=$(($RET + $?)) ; echo $MSG "DONE" + # Check for the following code in testing: `np.testing` and `np.array_equal` MSG='Check for invalid testing' ; echo $MSG invgrep -r -E --include '*.py' --exclude testing.py '(numpy|np)(\.testing|\.array_equal)' pandas/tests/ diff --git a/pandas/core/arrays/categorical.py b/pandas/core/arrays/categorical.py index 9c2aa03102533..d0daaf0dc3400 100644 --- a/pandas/core/arrays/categorical.py +++ b/pandas/core/arrays/categorical.py @@ -2025,8 +2025,8 @@ def __unicode__(self): return result def __repr__(self): - # We want PandasObject.__repr__, which dispatches to __unicode__ - return super(ExtensionArray, self).__repr__() + # We want to bypass the ExtensionArray.__repr__ + return str(self) def _maybe_coerce_indexer(self, indexer): """ diff --git a/pandas/core/arrays/sparse.py b/pandas/core/arrays/sparse.py index d01aac9a8750c..6f3e39c79c68e 100644 --- a/pandas/core/arrays/sparse.py +++ b/pandas/core/arrays/sparse.py @@ -1769,7 +1769,7 @@ def _add_unary_ops(cls): def _add_comparison_ops(cls): cls.__and__ = cls._create_comparison_method(operator.and_) cls.__or__ = cls._create_comparison_method(operator.or_) - super(SparseArray, cls)._add_comparison_ops() + super()._add_comparison_ops() # ---------- # Formatting diff --git a/pandas/core/dtypes/dtypes.py b/pandas/core/dtypes/dtypes.py index 417683ad54420..a11773f4d6b70 100644 --- a/pandas/core/dtypes/dtypes.py +++ b/pandas/core/dtypes/dtypes.py @@ -879,7 +879,7 @@ def is_dtype(cls, dtype): return False else: return False - return super(PeriodDtype, cls).is_dtype(dtype) + return super().is_dtype(dtype) @classmethod def construct_array_type(cls): @@ -1047,4 +1047,4 @@ def is_dtype(cls, dtype): return False else: return False - return super(IntervalDtype, cls).is_dtype(dtype) + return super().is_dtype(dtype) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index ba58382db4e76..09f5726e6341f 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -6336,8 +6336,7 @@ def _aggregate(self, arg, axis=0, *args, **kwargs): if axis == 1: # NDFrame.aggregate returns a tuple, and we need to transpose # only result - result, how = (super(DataFrame, self.T) - ._aggregate(arg, *args, **kwargs)) + result, how = self.T._aggregate(arg, *args, **kwargs) result = result.T if result is not None else result return result, how return super()._aggregate(arg, *args, **kwargs) @@ -6348,7 +6347,7 @@ def _aggregate(self, arg, axis=0, *args, **kwargs): def transform(self, func, axis=0, *args, **kwargs): axis = self._get_axis_number(axis) if axis == 1: - return super(DataFrame, self.T).transform(func, *args, **kwargs).T + return self.T.transform(func, *args, **kwargs).T return super().transform(func, *args, **kwargs) def apply(self, func, axis=0, broadcast=None, raw=False, reduce=None, diff --git a/pandas/core/groupby/grouper.py b/pandas/core/groupby/grouper.py index 4cc7329aca322..5733586770441 100644 --- a/pandas/core/groupby/grouper.py +++ b/pandas/core/groupby/grouper.py @@ -90,7 +90,7 @@ def __new__(cls, *args, **kwargs): if kwargs.get('freq') is not None: from pandas.core.resample import TimeGrouper cls = TimeGrouper - return super(Grouper, cls).__new__(cls) + return super().__new__(cls) def __init__(self, key=None, level=None, freq=None, axis=0, sort=False): self.key = key diff --git a/pandas/core/indexes/datetimes.py b/pandas/core/indexes/datetimes.py index 2e819765bb045..dba7dae2251be 100644 --- a/pandas/core/indexes/datetimes.py +++ b/pandas/core/indexes/datetimes.py @@ -629,7 +629,7 @@ def intersection(self, other, sort=False): ------- y : Index or DatetimeIndex or TimedeltaIndex """ - return super(DatetimeIndex, self).intersection(other, sort=sort) + return super().intersection(other, sort=sort) def _wrap_setop_result(self, other, result): name = get_op_result_name(self, other) diff --git a/pandas/core/indexes/timedeltas.py b/pandas/core/indexes/timedeltas.py index 8a7047beea84c..fd283ffd17e9b 100644 --- a/pandas/core/indexes/timedeltas.py +++ b/pandas/core/indexes/timedeltas.py @@ -405,7 +405,7 @@ def intersection(self, other, sort=False): ------- y : Index or TimedeltaIndex """ - return super(TimedeltaIndex, self).intersection(other, sort=sort) + return super().intersection(other, sort=sort) def _wrap_joined_index(self, joined, other): name = get_op_result_name(self, other) diff --git a/pandas/io/msgpack/__init__.py b/pandas/io/msgpack/__init__.py index 984e90ee03e69..f8feffcf49240 100644 --- a/pandas/io/msgpack/__init__.py +++ b/pandas/io/msgpack/__init__.py @@ -15,7 +15,7 @@ def __new__(cls, code, data): raise TypeError("data must be bytes") if not 0 <= code <= 127: raise ValueError("code must be 0~127") - return super(ExtType, cls).__new__(cls, code, data) + return super().__new__(cls, code, data) import os # noqa diff --git a/pandas/tests/arrays/test_array.py b/pandas/tests/arrays/test_array.py index cca421482bb66..d097141cd8c73 100644 --- a/pandas/tests/arrays/test_array.py +++ b/pandas/tests/arrays/test_array.py @@ -222,9 +222,7 @@ def _from_sequence(cls, scalars, dtype=None, copy=False): if isinstance(scalars, (pd.Series, pd.Index)): raise TypeError - return super(DecimalArray2, cls)._from_sequence( - scalars, dtype=dtype, copy=copy - ) + return super()._from_sequence(scalars, dtype=dtype, copy=copy) @pytest.mark.parametrize("box", [pd.Series, pd.Index]) diff --git a/pandas/tests/computation/test_eval.py b/pandas/tests/computation/test_eval.py index 00e95da123f54..69c05ccfe9818 100644 --- a/pandas/tests/computation/test_eval.py +++ b/pandas/tests/computation/test_eval.py @@ -712,7 +712,7 @@ class TestEvalNumexprPython(TestEvalNumexprPandas): @classmethod def setup_class(cls): - super(TestEvalNumexprPython, cls).setup_class() + super().setup_class() import numexpr as ne cls.ne = ne cls.engine = 'numexpr' @@ -738,7 +738,7 @@ class TestEvalPythonPython(TestEvalNumexprPython): @classmethod def setup_class(cls): - super(TestEvalPythonPython, cls).setup_class() + super().setup_class() cls.engine = 'python' cls.parser = 'python' @@ -768,7 +768,7 @@ class TestEvalPythonPandas(TestEvalPythonPython): @classmethod def setup_class(cls): - super(TestEvalPythonPandas, cls).setup_class() + super().setup_class() cls.engine = 'python' cls.parser = 'pandas' @@ -1494,7 +1494,7 @@ class TestOperationsNumExprPython(TestOperationsNumExprPandas): @classmethod def setup_class(cls): - super(TestOperationsNumExprPython, cls).setup_class() + super().setup_class() cls.engine = 'numexpr' cls.parser = 'python' cls.arith_ops = expr._arith_ops_syms + expr._cmp_ops_syms @@ -1570,7 +1570,7 @@ class TestOperationsPythonPython(TestOperationsNumExprPython): @classmethod def setup_class(cls): - super(TestOperationsPythonPython, cls).setup_class() + super().setup_class() cls.engine = cls.parser = 'python' cls.arith_ops = expr._arith_ops_syms + expr._cmp_ops_syms cls.arith_ops = filter(lambda x: x not in ('in', 'not in'), @@ -1581,7 +1581,7 @@ class TestOperationsPythonPandas(TestOperationsNumExprPandas): @classmethod def setup_class(cls): - super(TestOperationsPythonPandas, cls).setup_class() + super().setup_class() cls.engine = 'python' cls.parser = 'pandas' cls.arith_ops = expr._arith_ops_syms + expr._cmp_ops_syms @@ -1708,7 +1708,7 @@ class TestMathPythonPandas(TestMathPythonPython): @classmethod def setup_class(cls): - super(TestMathPythonPandas, cls).setup_class() + super().setup_class() cls.engine = 'python' cls.parser = 'pandas' @@ -1717,7 +1717,7 @@ class TestMathNumExprPandas(TestMathPythonPython): @classmethod def setup_class(cls): - super(TestMathNumExprPandas, cls).setup_class() + super().setup_class() cls.engine = 'numexpr' cls.parser = 'pandas' @@ -1726,7 +1726,7 @@ class TestMathNumExprPython(TestMathPythonPython): @classmethod def setup_class(cls): - super(TestMathNumExprPython, cls).setup_class() + super().setup_class() cls.engine = 'numexpr' cls.parser = 'python' diff --git a/pandas/tests/frame/test_query_eval.py b/pandas/tests/frame/test_query_eval.py index c05c7c4d18d13..c8d43501753e2 100644 --- a/pandas/tests/frame/test_query_eval.py +++ b/pandas/tests/frame/test_query_eval.py @@ -693,7 +693,7 @@ class TestDataFrameQueryNumExprPython(TestDataFrameQueryNumExprPandas): @classmethod def setup_class(cls): - super(TestDataFrameQueryNumExprPython, cls).setup_class() + super().setup_class() cls.engine = 'numexpr' cls.parser = 'python' cls.frame = TestData().frame @@ -793,7 +793,7 @@ class TestDataFrameQueryPythonPandas(TestDataFrameQueryNumExprPandas): @classmethod def setup_class(cls): - super(TestDataFrameQueryPythonPandas, cls).setup_class() + super().setup_class() cls.engine = 'python' cls.parser = 'pandas' cls.frame = TestData().frame @@ -814,7 +814,7 @@ class TestDataFrameQueryPythonPython(TestDataFrameQueryNumExprPython): @classmethod def setup_class(cls): - super(TestDataFrameQueryPythonPython, cls).setup_class() + super().setup_class() cls.engine = cls.parser = 'python' cls.frame = TestData().frame diff --git a/pandas/tseries/holiday.py b/pandas/tseries/holiday.py index ae080803ba764..030d2744cd7f5 100644 --- a/pandas/tseries/holiday.py +++ b/pandas/tseries/holiday.py @@ -317,8 +317,7 @@ def get_calendar(name): class HolidayCalendarMetaClass(type): def __new__(cls, clsname, bases, attrs): - calendar_class = super(HolidayCalendarMetaClass, cls).__new__( - cls, clsname, bases, attrs) + calendar_class = super().__new__(cls, clsname, bases, attrs) register(calendar_class) return calendar_class