Skip to content

Commit ecf5410

Browse files
committed
CLN: Clean uses of super, part II
1 parent 64104ec commit ecf5410

File tree

13 files changed

+38
-42
lines changed

13 files changed

+38
-42
lines changed

ci/code_checks.sh

+5-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,11 @@ if [[ -z "$CHECK" || "$CHECK" == "patterns" ]]; then
141141
RET=$(($RET + $?)) ; echo $MSG "DONE"
142142

143143
MSG='Check for python2 new-style classes' ; echo $MSG
144-
invgrep -R --include="*.py" --include="*.pyx" -E "class\s\S*\(object\):" pandas scripts
144+
invgrep -R --include="*.py" --include="*.pyx" -E "class\s\S*\(object\):" pandas
145+
RET=$(($RET + $?)) ; echo $MSG "DONE"
146+
147+
MSG='Check for python2-style super usage' ; echo $MSG
148+
invgrep -R --include="*.py" --include="*.pyx" -E "super\(\w*, (self|cls)\)" pandas
145149
RET=$(($RET + $?)) ; echo $MSG "DONE"
146150

147151
MSG='Check for backticks incorrectly rendering because of missing spaces' ; echo $MSG

pandas/_libs/index.pyx

+9-10
Original file line numberDiff line numberDiff line change
@@ -483,44 +483,43 @@ cdef class TimedeltaEngine(DatetimeEngine):
483483
cdef class PeriodEngine(Int64Engine):
484484

485485
cdef _get_index_values(self):
486-
return super(PeriodEngine, self).vgetter()
486+
return super().vgetter()
487487

488488
cpdef _call_map_locations(self, values):
489-
super(PeriodEngine, self)._call_map_locations(values.view('i8'))
489+
super()._call_map_locations(values.view('i8'))
490490

491491
def _call_monotonic(self, values):
492-
return super(PeriodEngine, self)._call_monotonic(values.view('i8'))
492+
return super()._call_monotonic(values.view('i8'))
493493

494494
def get_indexer(self, values):
495495
cdef ndarray[int64_t, ndim=1] ordinals
496496

497-
super(PeriodEngine, self)._ensure_mapping_populated()
497+
super()._ensure_mapping_populated()
498498

499-
freq = super(PeriodEngine, self).vgetter().freq
499+
freq = super().vgetter().freq
500500
ordinals = periodlib.extract_ordinals(values, freq)
501501

502502
return self.mapping.lookup(ordinals)
503503

504504
def get_pad_indexer(self, other, limit=None):
505-
freq = super(PeriodEngine, self).vgetter().freq
505+
freq = super().vgetter().freq
506506
ordinal = periodlib.extract_ordinals(other, freq)
507507

508508
return algos.pad(self._get_index_values(),
509509
np.asarray(ordinal), limit=limit)
510510

511511
def get_backfill_indexer(self, other, limit=None):
512-
freq = super(PeriodEngine, self).vgetter().freq
512+
freq = super().vgetter().freq
513513
ordinal = periodlib.extract_ordinals(other, freq)
514514

515515
return algos.backfill(self._get_index_values(),
516516
np.asarray(ordinal), limit=limit)
517517

518518
def get_indexer_non_unique(self, targets):
519-
freq = super(PeriodEngine, self).vgetter().freq
519+
freq = super().vgetter().freq
520520
ordinal = periodlib.extract_ordinals(targets, freq)
521521
ordinal_array = np.asarray(ordinal)
522-
523-
return super(PeriodEngine, self).get_indexer_non_unique(ordinal_array)
522+
return super().get_indexer_non_unique(ordinal_array)
524523

525524

526525
cpdef convert_scalar(ndarray arr, object value):

pandas/_libs/tslibs/timestamps.pyx

+1-1
Original file line numberDiff line numberDiff line change
@@ -983,7 +983,7 @@ default 'raise'
983983
return create_timestamp_from_ts(value, dts, _tzinfo, self.freq)
984984

985985
def isoformat(self, sep='T'):
986-
base = super(_Timestamp, self).isoformat(sep=sep)
986+
base = super().isoformat(sep=sep)
987987
if self.nanosecond == 0:
988988
return base
989989

pandas/core/arrays/categorical.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -2010,9 +2010,6 @@ def _get_repr(self, length=True, na_rep='NaN', footer=True):
20102010
return str(result)
20112011

20122012
def __unicode__(self):
2013-
"""
2014-
Unicode representation.
2015-
"""
20162013
_maxlen = 10
20172014
if len(self._codes) > _maxlen:
20182015
result = self._tidy_repr(_maxlen)
@@ -2025,8 +2022,8 @@ def __unicode__(self):
20252022
return result
20262023

20272024
def __repr__(self):
2028-
# We want PandasObject.__repr__, which dispatches to __unicode__
2029-
return super(ExtensionArray, self).__repr__()
2025+
# We want to bypass ExtensionArray.__repr__.
2026+
return str(self)
20302027

20312028
def _maybe_coerce_indexer(self, indexer):
20322029
"""

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
@@ -6330,8 +6330,7 @@ def _aggregate(self, arg, axis=0, *args, **kwargs):
63306330
if axis == 1:
63316331
# NDFrame.aggregate returns a tuple, and we need to transpose
63326332
# only result
6333-
result, how = (super(DataFrame, self.T)
6334-
._aggregate(arg, *args, **kwargs))
6333+
result, how = self.T._aggregate(arg, *args, axis=0, **kwargs)
63356334
result = result.T if result is not None else result
63366335
return result, how
63376336
return super()._aggregate(arg, *args, **kwargs)
@@ -6342,7 +6341,7 @@ def _aggregate(self, arg, axis=0, *args, **kwargs):
63426341
def transform(self, func, axis=0, *args, **kwargs):
63436342
axis = self._get_axis_number(axis)
63446343
if axis == 1:
6345-
return super(DataFrame, self.T).transform(func, *args, **kwargs).T
6344+
return self.T.transform(func, *args, axis=0, **kwargs).T
63466345
return super().transform(func, *args, **kwargs)
63476346

63486347
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/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
@@ -694,7 +694,7 @@ class TestDataFrameQueryNumExprPython(TestDataFrameQueryNumExprPandas):
694694

695695
@classmethod
696696
def setup_class(cls):
697-
super(TestDataFrameQueryNumExprPython, cls).setup_class()
697+
super().setup_class()
698698
cls.engine = 'numexpr'
699699
cls.parser = 'python'
700700
cls.frame = TestData().frame
@@ -794,7 +794,7 @@ class TestDataFrameQueryPythonPandas(TestDataFrameQueryNumExprPandas):
794794

795795
@classmethod
796796
def setup_class(cls):
797-
super(TestDataFrameQueryPythonPandas, cls).setup_class()
797+
super().setup_class()
798798
cls.engine = 'python'
799799
cls.parser = 'pandas'
800800
cls.frame = TestData().frame
@@ -815,7 +815,7 @@ class TestDataFrameQueryPythonPython(TestDataFrameQueryNumExprPython):
815815

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

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)