Skip to content

Commit 88062f7

Browse files
topper-123jreback
authored andcommitted
CLN: Cleanup use of super() in instance methods. (#26177)
1 parent 4d9de8d commit 88062f7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+421
-520
lines changed

asv_bench/benchmarks/io/stata.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def time_write_stata(self, convert_dates):
3838

3939
class StataMissing(Stata):
4040
def setup(self, convert_dates):
41-
super(StataMissing, self).setup(convert_dates)
41+
super().setup(convert_dates)
4242
for i in range(10):
4343
missing_data = np.random.randn(self.N)
4444
missing_data[missing_data < 0] = np.nan

pandas/_libs/tslibs/strptime.pyx

+1-1
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ class TimeRE(dict):
528528
self.locale_time = locale_time
529529
else:
530530
self.locale_time = LocaleTime()
531-
base = super(TimeRE, self)
531+
base = super()
532532
base.__init__({
533533
# The " \d" part of the regex is to make %c from ANSI C work
534534
'd': r"(?P<d>3[0-1]|[1-2]\d|0[1-9]|[1-9]| [1-9])",

pandas/compat/pickle_compat.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def find_class(self, module, name):
144144
# override superclass
145145
key = (module, name)
146146
module, name = _class_locations_map.get(key, key)
147-
return super(Unpickler, self).find_class(module, name)
147+
return super().find_class(module, name)
148148

149149

150150
Unpickler.dispatch = copy.copy(Unpickler.dispatch)

pandas/core/algorithms.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1159,7 +1159,7 @@ class SelectNFrame(SelectN):
11591159
"""
11601160

11611161
def __init__(self, obj, n, keep, columns):
1162-
super(SelectNFrame, self).__init__(obj, n, keep)
1162+
super().__init__(obj, n, keep)
11631163
if not is_list_like(columns) or isinstance(columns, tuple):
11641164
columns = [columns]
11651165
columns = list(columns)

pandas/core/apply.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ class FrameRowApply(FrameApply):
317317
axis = 0
318318

319319
def apply_broadcast(self):
320-
return super(FrameRowApply, self).apply_broadcast(self.obj)
320+
return super().apply_broadcast(self.obj)
321321

322322
@property
323323
def series_generator(self):
@@ -356,7 +356,7 @@ class FrameColumnApply(FrameApply):
356356
axis = 1
357357

358358
def apply_broadcast(self):
359-
result = super(FrameColumnApply, self).apply_broadcast(self.obj.T)
359+
result = super().apply_broadcast(self.obj.T)
360360
return result.T
361361

362362
@property

pandas/core/arrays/categorical.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1549,7 +1549,7 @@ def argsort(self, *args, **kwargs):
15491549
array([3, 0, 1, 2])
15501550
"""
15511551
# Keep the implementation here just for the docstring.
1552-
return super(Categorical, self).argsort(*args, **kwargs)
1552+
return super().argsort(*args, **kwargs)
15531553

15541554
def sort_values(self, inplace=False, ascending=True, na_position='last'):
15551555
"""

pandas/core/arrays/datetimelike.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -1381,9 +1381,7 @@ def _reduce(self, name, axis=0, skipna=True, **kwargs):
13811381
if op:
13821382
return op(axis=axis, skipna=skipna, **kwargs)
13831383
else:
1384-
return super(DatetimeLikeArrayMixin, self)._reduce(
1385-
name, skipna, **kwargs
1386-
)
1384+
return super()._reduce(name, skipna, **kwargs)
13871385

13881386
def min(self, axis=None, skipna=True, *args, **kwargs):
13891387
"""

pandas/core/arrays/datetimes.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ def __array__(self, dtype=None):
580580
# The default for tz-aware is object, to preserve tz info
581581
dtype = object
582582

583-
return super(DatetimeArray, self).__array__(dtype=dtype)
583+
return super().__array__(dtype=dtype)
584584

585585
def __iter__(self):
586586
"""
@@ -771,7 +771,7 @@ def _add_delta(self, delta):
771771
-------
772772
result : DatetimeArray
773773
"""
774-
new_values = super(DatetimeArray, self)._add_delta(delta)
774+
new_values = super()._add_delta(delta)
775775
return type(self)._from_sequence(new_values, tz=self.tz, freq='infer')
776776

777777
# -----------------------------------------------------------------

pandas/core/arrays/period.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ def astype(self, dtype, copy=True):
505505

506506
if is_period_dtype(dtype):
507507
return self.asfreq(dtype.freq)
508-
return super(PeriodArray, self).astype(dtype, copy=copy)
508+
return super().astype(dtype, copy=copy)
509509

510510
@property
511511
def flags(self):
@@ -560,7 +560,7 @@ def _add_offset(self, other):
560560
# Note: when calling parent class's _add_timedeltalike_scalar,
561561
# it will call delta_to_nanoseconds(delta). Because delta here
562562
# is an integer, delta_to_nanoseconds will return it unchanged.
563-
result = super(PeriodArray, self)._add_timedeltalike_scalar(other.n)
563+
result = super()._add_timedeltalike_scalar(other.n)
564564
return type(self)(result, freq=self.freq)
565565

566566
def _add_timedeltalike_scalar(self, other):
@@ -584,7 +584,7 @@ def _add_timedeltalike_scalar(self, other):
584584
# Note: when calling parent class's _add_timedeltalike_scalar,
585585
# it will call delta_to_nanoseconds(delta). Because delta here
586586
# is an integer, delta_to_nanoseconds will return it unchanged.
587-
ordinals = super(PeriodArray, self)._add_timedeltalike_scalar(other)
587+
ordinals = super()._add_timedeltalike_scalar(other)
588588
return ordinals
589589

590590
def _add_delta_tdi(self, other):
@@ -620,7 +620,7 @@ def _add_delta(self, other):
620620
# We cannot add timedelta-like to non-tick PeriodArray
621621
_raise_on_incompatible(self, other)
622622

623-
new_ordinals = super(PeriodArray, self)._add_delta(other)
623+
new_ordinals = super()._add_delta(other)
624624
return type(self)(new_ordinals, freq=self.freq)
625625

626626
def _check_timedeltalike_freq_compat(self, other):

pandas/core/arrays/sparse.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def __init__(
118118
def __hash__(self):
119119
# Python3 doesn't inherit __hash__ when a base class overrides
120120
# __eq__, so we explicitly do it here.
121-
return super(SparseDtype, self).__hash__()
121+
return super().__hash__()
122122

123123
def __eq__(self, other):
124124
# We have to override __eq__ to handle NA values in _metadata.

pandas/core/arrays/timedeltas.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ def _add_delta(self, delta):
387387
-------
388388
result : TimedeltaArray
389389
"""
390-
new_values = super(TimedeltaArray, self)._add_delta(delta)
390+
new_values = super()._add_delta(delta)
391391
return type(self)._from_sequence(new_values, freq='infer')
392392

393393
def _add_datetime_arraylike(self, other):
@@ -427,9 +427,7 @@ def _addsub_offset_array(self, other, op):
427427
# TimedeltaIndex can only operate with a subset of DateOffset
428428
# subclasses. Incompatible classes will raise AttributeError,
429429
# which we re-raise as TypeError
430-
return super(TimedeltaArray, self)._addsub_offset_array(
431-
other, op
432-
)
430+
return super()._addsub_offset_array(other, op)
433431
except AttributeError:
434432
raise TypeError("Cannot add/subtract non-tick DateOffset to {cls}"
435433
.format(cls=type(self).__name__))

pandas/core/base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def __sizeof__(self):
107107

108108
# no memory_usage attribute, so fall back to
109109
# object's 'sizeof'
110-
return super(PandasObject, self).__sizeof__()
110+
return super().__sizeof__()
111111

112112

113113
class NoNewAttributesMixin:

pandas/core/computation/engines.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,10 @@ class NumExprEngine(AbstractEngine):
9898
has_neg_frac = True
9999

100100
def __init__(self, expr):
101-
super(NumExprEngine, self).__init__(expr)
101+
super().__init__(expr)
102102

103103
def convert(self):
104-
return str(super(NumExprEngine, self).convert())
104+
return str(super().convert())
105105

106106
def _evaluate(self):
107107
import numexpr as ne
@@ -133,7 +133,7 @@ class PythonEngine(AbstractEngine):
133133
has_neg_frac = False
134134

135135
def __init__(self, expr):
136-
super(PythonEngine, self).__init__(expr)
136+
super().__init__(expr)
137137

138138
def evaluate(self):
139139
return self.expr()

pandas/core/computation/expr.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -694,15 +694,14 @@ def __init__(self, env, engine, parser,
694694
preparser=partial(_preparse, f=_compose(
695695
_replace_locals, _replace_booleans,
696696
_clean_spaces_backtick_quoted_names))):
697-
super(PandasExprVisitor, self).__init__(env, engine, parser, preparser)
697+
super().__init__(env, engine, parser, preparser)
698698

699699

700700
@disallow(_unsupported_nodes | _python_not_supported | frozenset(['Not']))
701701
class PythonExprVisitor(BaseExprVisitor):
702702

703703
def __init__(self, env, engine, parser, preparser=lambda x: x):
704-
super(PythonExprVisitor, self).__init__(env, engine, parser,
705-
preparser=preparser)
704+
super().__init__(env, engine, parser, preparser=preparser)
706705

707706

708707
class Expr(StringMixin):

pandas/core/computation/ops.py

+6-7
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def __init__(self, name, is_local):
4343
msg = 'local variable {0!r} is not defined'
4444
else:
4545
msg = 'name {0!r} is not defined'
46-
super(UndefinedVariableError, self).__init__(msg.format(name))
46+
super().__init__(msg.format(name))
4747

4848

4949
class Term(StringMixin):
@@ -161,8 +161,7 @@ def ndim(self):
161161
class Constant(Term):
162162

163163
def __init__(self, value, env, side=None, encoding=None):
164-
super(Constant, self).__init__(value, env, side=side,
165-
encoding=encoding)
164+
super().__init__(value, env, side=side, encoding=encoding)
166165

167166
def _resolve_name(self):
168167
return self._name
@@ -329,7 +328,7 @@ class BinOp(Op):
329328
"""
330329

331330
def __init__(self, op, lhs, rhs, **kwargs):
332-
super(BinOp, self).__init__(op, (lhs, rhs))
331+
super().__init__(op, (lhs, rhs))
333332
self.lhs = lhs
334333
self.rhs = rhs
335334

@@ -462,7 +461,7 @@ class Div(BinOp):
462461
"""
463462

464463
def __init__(self, lhs, rhs, truediv, *args, **kwargs):
465-
super(Div, self).__init__('/', lhs, rhs, *args, **kwargs)
464+
super().__init__('/', lhs, rhs, *args, **kwargs)
466465

467466
if not isnumeric(lhs.return_type) or not isnumeric(rhs.return_type):
468467
raise TypeError("unsupported operand type(s) for {0}:"
@@ -498,7 +497,7 @@ class UnaryOp(Op):
498497
"""
499498

500499
def __init__(self, op, operand):
501-
super(UnaryOp, self).__init__(op, (operand,))
500+
super().__init__(op, (operand,))
502501
self.operand = operand
503502

504503
try:
@@ -528,7 +527,7 @@ def return_type(self):
528527
class MathCall(Op):
529528

530529
def __init__(self, func, args):
531-
super(MathCall, self).__init__(func.name, args)
530+
super().__init__(func.name, args)
532531
self.func = func
533532

534533
def __call__(self, env):

pandas/core/computation/pytables.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ class Scope(expr.Scope):
2626

2727
def __init__(self, level, global_dict=None, local_dict=None,
2828
queryables=None):
29-
super(Scope, self).__init__(level + 1, global_dict=global_dict,
30-
local_dict=local_dict)
29+
super().__init__(level + 1,
30+
global_dict=global_dict,
31+
local_dict=local_dict)
3132
self.queryables = queryables or dict()
3233

3334

@@ -39,7 +40,7 @@ def __new__(cls, name, env, side=None, encoding=None):
3940
return supr_new(klass)
4041

4142
def __init__(self, name, env, side=None, encoding=None):
42-
super(Term, self).__init__(name, env, side=side, encoding=encoding)
43+
super().__init__(name, env, side=side, encoding=encoding)
4344

4445
def _resolve_name(self):
4546
# must be a queryables
@@ -63,8 +64,7 @@ def value(self):
6364
class Constant(Term):
6465

6566
def __init__(self, value, env, side=None, encoding=None):
66-
super(Constant, self).__init__(value, env, side=side,
67-
encoding=encoding)
67+
super().__init__(value, env, side=side, encoding=encoding)
6868

6969
def _resolve_name(self):
7070
return self._name
@@ -75,7 +75,7 @@ class BinOp(ops.BinOp):
7575
_max_selectors = 31
7676

7777
def __init__(self, op, lhs, rhs, queryables, encoding):
78-
super(BinOp, self).__init__(op, lhs, rhs)
78+
super().__init__(op, lhs, rhs)
7979
self.queryables = queryables
8080
self.encoding = encoding
8181
self.filter = None
@@ -385,7 +385,7 @@ class ExprVisitor(BaseExprVisitor):
385385
term_type = Term
386386

387387
def __init__(self, env, engine, parser, **kwargs):
388-
super(ExprVisitor, self).__init__(env, engine, parser)
388+
super().__init__(env, engine, parser)
389389
for bin_op in self.binary_ops:
390390
bin_node = self.binary_op_nodes_map[bin_op]
391391
setattr(self, 'visit_{node}'.format(node=bin_node),

0 commit comments

Comments
 (0)