Skip to content

Commit b9ea320

Browse files
committed
CLN: clean more uses of super
1 parent 80be9b5 commit b9ea320

File tree

13 files changed

+29
-29
lines changed

13 files changed

+29
-29
lines changed

ci/code_checks.sh

+4
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@ if [[ -z "$CHECK" || "$CHECK" == "patterns" ]]; then
130130
invgrep -R --include="*.py" --include="*.pyx" -E "# -\*- coding: utf-8 -\*-" pandas scripts
131131
RET=$(($RET + $?)) ; echo $MSG "DONE"
132132

133+
MSG='Check for python2-style super usage' ; echo $MSG
134+
invgrep -R --include="*.py" -E "super\(\w*, (self|cls)\)" pandas
135+
RET=$(($RET + $?)) ; echo $MSG "DONE"
136+
133137
# Check for the following code in testing: `np.testing` and `np.array_equal`
134138
MSG='Check for invalid testing' ; echo $MSG
135139
invgrep -r -E --include '*.py' --exclude testing.py '(numpy|np)(\.testing|\.array_equal)' pandas/tests/

pandas/core/arrays/categorical.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2025,8 +2025,8 @@ def __unicode__(self):
20252025
return result
20262026

20272027
def __repr__(self):
2028-
# We want PandasObject.__repr__, which dispatches to __unicode__
2029-
return super(ExtensionArray, self).__repr__()
2028+
# We want to bypass the ExtensionArray.__repr__
2029+
return str(self)
20302030

20312031
def _maybe_coerce_indexer(self, indexer):
20322032
"""

pandas/core/arrays/sparse.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1769,7 +1769,7 @@ def _add_unary_ops(cls):
17691769
def _add_comparison_ops(cls):
17701770
cls.__and__ = cls._create_comparison_method(operator.and_)
17711771
cls.__or__ = cls._create_comparison_method(operator.or_)
1772-
super(SparseArray, cls)._add_comparison_ops()
1772+
super()._add_comparison_ops()
17731773

17741774
# ----------
17751775
# Formatting

pandas/core/dtypes/dtypes.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -879,7 +879,7 @@ def is_dtype(cls, dtype):
879879
return False
880880
else:
881881
return False
882-
return super(PeriodDtype, cls).is_dtype(dtype)
882+
return super().is_dtype(dtype)
883883

884884
@classmethod
885885
def construct_array_type(cls):
@@ -1047,4 +1047,4 @@ def is_dtype(cls, dtype):
10471047
return False
10481048
else:
10491049
return False
1050-
return super(IntervalDtype, cls).is_dtype(dtype)
1050+
return super().is_dtype(dtype)

pandas/core/frame.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -6336,8 +6336,7 @@ def _aggregate(self, arg, axis=0, *args, **kwargs):
63366336
if axis == 1:
63376337
# NDFrame.aggregate returns a tuple, and we need to transpose
63386338
# only result
6339-
result, how = (super(DataFrame, self.T)
6340-
._aggregate(arg, *args, **kwargs))
6339+
result, how = self.T._aggregate(arg, *args, **kwargs)
63416340
result = result.T if result is not None else result
63426341
return result, how
63436342
return super()._aggregate(arg, *args, **kwargs)
@@ -6348,7 +6347,7 @@ def _aggregate(self, arg, axis=0, *args, **kwargs):
63486347
def transform(self, func, axis=0, *args, **kwargs):
63496348
axis = self._get_axis_number(axis)
63506349
if axis == 1:
6351-
return super(DataFrame, self.T).transform(func, *args, **kwargs).T
6350+
return self.T.transform(func, *args, **kwargs).T
63526351
return super().transform(func, *args, **kwargs)
63536352

63546353
def apply(self, func, axis=0, broadcast=None, raw=False, reduce=None,

pandas/core/groupby/grouper.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def __new__(cls, *args, **kwargs):
9090
if kwargs.get('freq') is not None:
9191
from pandas.core.resample import TimeGrouper
9292
cls = TimeGrouper
93-
return super(Grouper, cls).__new__(cls)
93+
return super().__new__(cls)
9494

9595
def __init__(self, key=None, level=None, freq=None, axis=0, sort=False):
9696
self.key = key

pandas/core/indexes/datetimes.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ def intersection(self, other, sort=False):
629629
-------
630630
y : Index or DatetimeIndex or TimedeltaIndex
631631
"""
632-
return super(DatetimeIndex, self).intersection(other, sort=sort)
632+
return super().intersection(other, sort=sort)
633633

634634
def _wrap_setop_result(self, other, result):
635635
name = get_op_result_name(self, other)

pandas/core/indexes/timedeltas.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ def intersection(self, other, sort=False):
405405
-------
406406
y : Index or TimedeltaIndex
407407
"""
408-
return super(TimedeltaIndex, self).intersection(other, sort=sort)
408+
return super().intersection(other, sort=sort)
409409

410410
def _wrap_joined_index(self, joined, other):
411411
name = get_op_result_name(self, other)

pandas/io/msgpack/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def __new__(cls, code, data):
1515
raise TypeError("data must be bytes")
1616
if not 0 <= code <= 127:
1717
raise ValueError("code must be 0~127")
18-
return super(ExtType, cls).__new__(cls, code, data)
18+
return super().__new__(cls, code, data)
1919

2020
import os # noqa
2121

pandas/tests/arrays/test_array.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,7 @@ def _from_sequence(cls, scalars, dtype=None, copy=False):
222222
if isinstance(scalars, (pd.Series, pd.Index)):
223223
raise TypeError
224224

225-
return super(DecimalArray2, cls)._from_sequence(
226-
scalars, dtype=dtype, copy=copy
227-
)
225+
return super()._from_sequence(scalars, dtype=dtype, copy=copy)
228226

229227

230228
@pytest.mark.parametrize("box", [pd.Series, pd.Index])

pandas/tests/computation/test_eval.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,7 @@ class TestEvalNumexprPython(TestEvalNumexprPandas):
712712

713713
@classmethod
714714
def setup_class(cls):
715-
super(TestEvalNumexprPython, cls).setup_class()
715+
super().setup_class()
716716
import numexpr as ne
717717
cls.ne = ne
718718
cls.engine = 'numexpr'
@@ -738,7 +738,7 @@ class TestEvalPythonPython(TestEvalNumexprPython):
738738

739739
@classmethod
740740
def setup_class(cls):
741-
super(TestEvalPythonPython, cls).setup_class()
741+
super().setup_class()
742742
cls.engine = 'python'
743743
cls.parser = 'python'
744744

@@ -768,7 +768,7 @@ class TestEvalPythonPandas(TestEvalPythonPython):
768768

769769
@classmethod
770770
def setup_class(cls):
771-
super(TestEvalPythonPandas, cls).setup_class()
771+
super().setup_class()
772772
cls.engine = 'python'
773773
cls.parser = 'pandas'
774774

@@ -1494,7 +1494,7 @@ class TestOperationsNumExprPython(TestOperationsNumExprPandas):
14941494

14951495
@classmethod
14961496
def setup_class(cls):
1497-
super(TestOperationsNumExprPython, cls).setup_class()
1497+
super().setup_class()
14981498
cls.engine = 'numexpr'
14991499
cls.parser = 'python'
15001500
cls.arith_ops = expr._arith_ops_syms + expr._cmp_ops_syms
@@ -1570,7 +1570,7 @@ class TestOperationsPythonPython(TestOperationsNumExprPython):
15701570

15711571
@classmethod
15721572
def setup_class(cls):
1573-
super(TestOperationsPythonPython, cls).setup_class()
1573+
super().setup_class()
15741574
cls.engine = cls.parser = 'python'
15751575
cls.arith_ops = expr._arith_ops_syms + expr._cmp_ops_syms
15761576
cls.arith_ops = filter(lambda x: x not in ('in', 'not in'),
@@ -1581,7 +1581,7 @@ class TestOperationsPythonPandas(TestOperationsNumExprPandas):
15811581

15821582
@classmethod
15831583
def setup_class(cls):
1584-
super(TestOperationsPythonPandas, cls).setup_class()
1584+
super().setup_class()
15851585
cls.engine = 'python'
15861586
cls.parser = 'pandas'
15871587
cls.arith_ops = expr._arith_ops_syms + expr._cmp_ops_syms
@@ -1708,7 +1708,7 @@ class TestMathPythonPandas(TestMathPythonPython):
17081708

17091709
@classmethod
17101710
def setup_class(cls):
1711-
super(TestMathPythonPandas, cls).setup_class()
1711+
super().setup_class()
17121712
cls.engine = 'python'
17131713
cls.parser = 'pandas'
17141714

@@ -1717,7 +1717,7 @@ class TestMathNumExprPandas(TestMathPythonPython):
17171717

17181718
@classmethod
17191719
def setup_class(cls):
1720-
super(TestMathNumExprPandas, cls).setup_class()
1720+
super().setup_class()
17211721
cls.engine = 'numexpr'
17221722
cls.parser = 'pandas'
17231723

@@ -1726,7 +1726,7 @@ class TestMathNumExprPython(TestMathPythonPython):
17261726

17271727
@classmethod
17281728
def setup_class(cls):
1729-
super(TestMathNumExprPython, cls).setup_class()
1729+
super().setup_class()
17301730
cls.engine = 'numexpr'
17311731
cls.parser = 'python'
17321732

pandas/tests/frame/test_query_eval.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,7 @@ class TestDataFrameQueryNumExprPython(TestDataFrameQueryNumExprPandas):
693693

694694
@classmethod
695695
def setup_class(cls):
696-
super(TestDataFrameQueryNumExprPython, cls).setup_class()
696+
super().setup_class()
697697
cls.engine = 'numexpr'
698698
cls.parser = 'python'
699699
cls.frame = TestData().frame
@@ -793,7 +793,7 @@ class TestDataFrameQueryPythonPandas(TestDataFrameQueryNumExprPandas):
793793

794794
@classmethod
795795
def setup_class(cls):
796-
super(TestDataFrameQueryPythonPandas, cls).setup_class()
796+
super().setup_class()
797797
cls.engine = 'python'
798798
cls.parser = 'pandas'
799799
cls.frame = TestData().frame
@@ -814,7 +814,7 @@ class TestDataFrameQueryPythonPython(TestDataFrameQueryNumExprPython):
814814

815815
@classmethod
816816
def setup_class(cls):
817-
super(TestDataFrameQueryPythonPython, cls).setup_class()
817+
super().setup_class()
818818
cls.engine = cls.parser = 'python'
819819
cls.frame = TestData().frame
820820

pandas/tseries/holiday.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,7 @@ def get_calendar(name):
317317
class HolidayCalendarMetaClass(type):
318318

319319
def __new__(cls, clsname, bases, attrs):
320-
calendar_class = super(HolidayCalendarMetaClass, cls).__new__(
321-
cls, clsname, bases, attrs)
320+
calendar_class = super().__new__(cls, clsname, bases, attrs)
322321
register(calendar_class)
323322
return calendar_class
324323

0 commit comments

Comments
 (0)