Skip to content

CLN: clean more uses of python2-style super() #26261

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ci/code_checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/arrays/categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/arrays/sparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/dtypes/dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)
5 changes: 2 additions & 3 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is more readable IMO.

result = result.T if result is not None else result
return result, how
return super()._aggregate(arg, *args, **kwargs)
Expand All @@ -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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is more readable IMO.

return super().transform(func, *args, **kwargs)

def apply(self, func, axis=0, broadcast=None, raw=False, reduce=None,
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/groupby/grouper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/indexes/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/indexes/timedeltas.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pandas/io/msgpack/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 1 addition & 3 deletions pandas/tests/arrays/test_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
18 changes: 9 additions & 9 deletions pandas/tests/computation/test_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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'

Expand Down Expand Up @@ -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'

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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'),
Expand All @@ -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
Expand Down Expand Up @@ -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'

Expand All @@ -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'

Expand All @@ -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'

Expand Down
6 changes: 3 additions & 3 deletions pandas/tests/frame/test_query_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down
3 changes: 1 addition & 2 deletions pandas/tseries/holiday.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down