Skip to content

CLN: Clean-up use of super() in instance methods. #26177

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
Apr 24, 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
2 changes: 1 addition & 1 deletion asv_bench/benchmarks/io/stata.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def time_write_stata(self, convert_dates):

class StataMissing(Stata):
def setup(self, convert_dates):
super(StataMissing, self).setup(convert_dates)
super().setup(convert_dates)
for i in range(10):
missing_data = np.random.randn(self.N)
missing_data[missing_data < 0] = np.nan
Expand Down
2 changes: 1 addition & 1 deletion pandas/_libs/tslibs/strptime.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ class TimeRE(dict):
self.locale_time = locale_time
else:
self.locale_time = LocaleTime()
base = super(TimeRE, self)
base = super()
base.__init__({
# The " \d" part of the regex is to make %c from ANSI C work
'd': r"(?P<d>3[0-1]|[1-2]\d|0[1-9]|[1-9]| [1-9])",
Expand Down
2 changes: 1 addition & 1 deletion pandas/compat/pickle_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def find_class(self, module, name):
# override superclass
key = (module, name)
module, name = _class_locations_map.get(key, key)
return super(Unpickler, self).find_class(module, name)
return super().find_class(module, name)


Unpickler.dispatch = copy.copy(Unpickler.dispatch)
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -1159,7 +1159,7 @@ class SelectNFrame(SelectN):
"""

def __init__(self, obj, n, keep, columns):
super(SelectNFrame, self).__init__(obj, n, keep)
super().__init__(obj, n, keep)
if not is_list_like(columns) or isinstance(columns, tuple):
columns = [columns]
columns = list(columns)
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ class FrameRowApply(FrameApply):
axis = 0

def apply_broadcast(self):
return super(FrameRowApply, self).apply_broadcast(self.obj)
return super().apply_broadcast(self.obj)

@property
def series_generator(self):
Expand Down Expand Up @@ -356,7 +356,7 @@ class FrameColumnApply(FrameApply):
axis = 1

def apply_broadcast(self):
result = super(FrameColumnApply, self).apply_broadcast(self.obj.T)
result = super().apply_broadcast(self.obj.T)
return result.T

@property
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/arrays/categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -1549,7 +1549,7 @@ def argsort(self, *args, **kwargs):
array([3, 0, 1, 2])
"""
# Keep the implementation here just for the docstring.
return super(Categorical, self).argsort(*args, **kwargs)
return super().argsort(*args, **kwargs)

def sort_values(self, inplace=False, ascending=True, na_position='last'):
"""
Expand Down
4 changes: 1 addition & 3 deletions pandas/core/arrays/datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -1381,9 +1381,7 @@ def _reduce(self, name, axis=0, skipna=True, **kwargs):
if op:
return op(axis=axis, skipna=skipna, **kwargs)
else:
return super(DatetimeLikeArrayMixin, self)._reduce(
name, skipna, **kwargs
)
return super()._reduce(name, skipna, **kwargs)

def min(self, axis=None, skipna=True, *args, **kwargs):
"""
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/arrays/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ def __array__(self, dtype=None):
# The default for tz-aware is object, to preserve tz info
dtype = object

return super(DatetimeArray, self).__array__(dtype=dtype)
return super().__array__(dtype=dtype)

def __iter__(self):
"""
Expand Down Expand Up @@ -771,7 +771,7 @@ def _add_delta(self, delta):
-------
result : DatetimeArray
"""
new_values = super(DatetimeArray, self)._add_delta(delta)
new_values = super()._add_delta(delta)
return type(self)._from_sequence(new_values, tz=self.tz, freq='infer')

# -----------------------------------------------------------------
Expand Down
8 changes: 4 additions & 4 deletions pandas/core/arrays/period.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ def astype(self, dtype, copy=True):

if is_period_dtype(dtype):
return self.asfreq(dtype.freq)
return super(PeriodArray, self).astype(dtype, copy=copy)
return super().astype(dtype, copy=copy)

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

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

def _add_delta_tdi(self, other):
Expand Down Expand Up @@ -620,7 +620,7 @@ def _add_delta(self, other):
# We cannot add timedelta-like to non-tick PeriodArray
_raise_on_incompatible(self, other)

new_ordinals = super(PeriodArray, self)._add_delta(other)
new_ordinals = super()._add_delta(other)
return type(self)(new_ordinals, freq=self.freq)

def _check_timedeltalike_freq_compat(self, other):
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 @@ -118,7 +118,7 @@ def __init__(
def __hash__(self):
# Python3 doesn't inherit __hash__ when a base class overrides
# __eq__, so we explicitly do it here.
return super(SparseDtype, self).__hash__()
return super().__hash__()

def __eq__(self, other):
# We have to override __eq__ to handle NA values in _metadata.
Expand Down
6 changes: 2 additions & 4 deletions pandas/core/arrays/timedeltas.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ def _add_delta(self, delta):
-------
result : TimedeltaArray
"""
new_values = super(TimedeltaArray, self)._add_delta(delta)
new_values = super()._add_delta(delta)
return type(self)._from_sequence(new_values, freq='infer')

def _add_datetime_arraylike(self, other):
Expand Down Expand Up @@ -427,9 +427,7 @@ def _addsub_offset_array(self, other, op):
# TimedeltaIndex can only operate with a subset of DateOffset
# subclasses. Incompatible classes will raise AttributeError,
# which we re-raise as TypeError
return super(TimedeltaArray, self)._addsub_offset_array(
other, op
)
return super()._addsub_offset_array(other, op)
except AttributeError:
raise TypeError("Cannot add/subtract non-tick DateOffset to {cls}"
.format(cls=type(self).__name__))
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def __sizeof__(self):

# no memory_usage attribute, so fall back to
# object's 'sizeof'
return super(PandasObject, self).__sizeof__()
return super().__sizeof__()


class NoNewAttributesMixin:
Expand Down
6 changes: 3 additions & 3 deletions pandas/core/computation/engines.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,10 @@ class NumExprEngine(AbstractEngine):
has_neg_frac = True

def __init__(self, expr):
super(NumExprEngine, self).__init__(expr)
super().__init__(expr)

def convert(self):
return str(super(NumExprEngine, self).convert())
return str(super().convert())

def _evaluate(self):
import numexpr as ne
Expand Down Expand Up @@ -133,7 +133,7 @@ class PythonEngine(AbstractEngine):
has_neg_frac = False

def __init__(self, expr):
super(PythonEngine, self).__init__(expr)
super().__init__(expr)

def evaluate(self):
return self.expr()
Expand Down
5 changes: 2 additions & 3 deletions pandas/core/computation/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -694,15 +694,14 @@ def __init__(self, env, engine, parser,
preparser=partial(_preparse, f=_compose(
_replace_locals, _replace_booleans,
_clean_spaces_backtick_quoted_names))):
super(PandasExprVisitor, self).__init__(env, engine, parser, preparser)
super().__init__(env, engine, parser, preparser)


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

def __init__(self, env, engine, parser, preparser=lambda x: x):
super(PythonExprVisitor, self).__init__(env, engine, parser,
preparser=preparser)
super().__init__(env, engine, parser, preparser=preparser)


class Expr(StringMixin):
Expand Down
13 changes: 6 additions & 7 deletions pandas/core/computation/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def __init__(self, name, is_local):
msg = 'local variable {0!r} is not defined'
else:
msg = 'name {0!r} is not defined'
super(UndefinedVariableError, self).__init__(msg.format(name))
super().__init__(msg.format(name))


class Term(StringMixin):
Expand Down Expand Up @@ -161,8 +161,7 @@ def ndim(self):
class Constant(Term):

def __init__(self, value, env, side=None, encoding=None):
super(Constant, self).__init__(value, env, side=side,
encoding=encoding)
super().__init__(value, env, side=side, encoding=encoding)

def _resolve_name(self):
return self._name
Expand Down Expand Up @@ -329,7 +328,7 @@ class BinOp(Op):
"""

def __init__(self, op, lhs, rhs, **kwargs):
super(BinOp, self).__init__(op, (lhs, rhs))
super().__init__(op, (lhs, rhs))
self.lhs = lhs
self.rhs = rhs

Expand Down Expand Up @@ -462,7 +461,7 @@ class Div(BinOp):
"""

def __init__(self, lhs, rhs, truediv, *args, **kwargs):
super(Div, self).__init__('/', lhs, rhs, *args, **kwargs)
super().__init__('/', lhs, rhs, *args, **kwargs)

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

def __init__(self, op, operand):
super(UnaryOp, self).__init__(op, (operand,))
super().__init__(op, (operand,))
self.operand = operand

try:
Expand Down Expand Up @@ -528,7 +527,7 @@ def return_type(self):
class MathCall(Op):

def __init__(self, func, args):
super(MathCall, self).__init__(func.name, args)
super().__init__(func.name, args)
self.func = func

def __call__(self, env):
Expand Down
14 changes: 7 additions & 7 deletions pandas/core/computation/pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ class Scope(expr.Scope):

def __init__(self, level, global_dict=None, local_dict=None,
queryables=None):
super(Scope, self).__init__(level + 1, global_dict=global_dict,
local_dict=local_dict)
super().__init__(level + 1,
global_dict=global_dict,
local_dict=local_dict)
self.queryables = queryables or dict()


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

def __init__(self, name, env, side=None, encoding=None):
super(Term, self).__init__(name, env, side=side, encoding=encoding)
super().__init__(name, env, side=side, encoding=encoding)

def _resolve_name(self):
# must be a queryables
Expand All @@ -63,8 +64,7 @@ def value(self):
class Constant(Term):

def __init__(self, value, env, side=None, encoding=None):
super(Constant, self).__init__(value, env, side=side,
encoding=encoding)
super().__init__(value, env, side=side, encoding=encoding)

def _resolve_name(self):
return self._name
Expand All @@ -75,7 +75,7 @@ class BinOp(ops.BinOp):
_max_selectors = 31

def __init__(self, op, lhs, rhs, queryables, encoding):
super(BinOp, self).__init__(op, lhs, rhs)
super().__init__(op, lhs, rhs)
self.queryables = queryables
self.encoding = encoding
self.filter = None
Expand Down Expand Up @@ -385,7 +385,7 @@ class ExprVisitor(BaseExprVisitor):
term_type = Term

def __init__(self, env, engine, parser, **kwargs):
super(ExprVisitor, self).__init__(env, engine, parser)
super().__init__(env, engine, parser)
for bin_op in self.binary_ops:
bin_node = self.binary_op_nodes_map[bin_op]
setattr(self, 'visit_{node}'.format(node=bin_node),
Expand Down
Loading