Skip to content

CLN: replace %s syntax with .format in core.panel #18315

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
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
99 changes: 53 additions & 46 deletions pandas/core/panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@
klass="Panel",
axes_single_arg="{0, 1, 2, 'items', 'major_axis', 'minor_axis'}",
optional_mapper='', optional_axis='', optional_labels='')
_shared_doc_kwargs['args_transpose'] = ("three positional arguments: each one"
"of\n%s" %
_shared_doc_kwargs['axes_single_arg'])
_shared_doc_kwargs['args_transpose'] = (
"three positional arguments: each one of\n{ax_single}".format(
ax_single=_shared_doc_kwargs['axes_single_arg']))


def _ensure_like_indices(time, panels):
Expand Down Expand Up @@ -311,7 +311,8 @@ def _init_matrix(self, data, axes, dtype=None, copy=False):
try:
values = values.astype(dtype)
except Exception:
raise ValueError('failed to cast to %s' % dtype)
raise ValueError('failed to cast to '
'{datatype}'.format(datatype=dtype))

shape = values.shape
fixed_axes = []
Expand Down Expand Up @@ -352,18 +353,18 @@ def __unicode__(self):

class_name = str(self.__class__)

shape = self.shape
dims = u('Dimensions: %s') % ' x '.join(
["%d (%s)" % (s, a) for a, s in zip(self._AXIS_ORDERS, shape)])
dims = u('Dimensions: {dimensions}'.format(dimensions=' x '.join(
["{shape} ({axis})".format(shape=shape, axis=axis) for axis, shape
in zip(self._AXIS_ORDERS, self.shape)])))

def axis_pretty(a):
v = getattr(self, a)
if len(v) > 0:
return u('%s axis: %s to %s') % (a.capitalize(),
pprint_thing(v[0]),
pprint_thing(v[-1]))
return u('{ax} axis: {x} to {y}'.format(ax=a.capitalize(),
x=pprint_thing(v[0]),
y=pprint_thing(v[-1])))
else:
return u('%s axis: None') % a.capitalize()
return u('{ax} axis: None'.format(ax=a.capitalize()))

output = '\n'.join(
[class_name, dims] + [axis_pretty(a) for a in self._AXIS_ORDERS])
Expand Down Expand Up @@ -610,7 +611,8 @@ def __setitem__(self, key, value):
elif is_scalar(value):
mat = cast_scalar_to_array(shape[1:], value)
else:
raise TypeError('Cannot set item of type: %s' % str(type(value)))
raise TypeError('Cannot set item of '
'type: {dtype!s}'.format(dtype=type(value)))

mat = mat.reshape(tuple([1]) + shape[1:])
NDFrame._set_item(self, key, mat)
Expand Down Expand Up @@ -739,9 +741,9 @@ def _combine(self, other, func, axis=0):
elif is_scalar(other):
return self._combine_const(other, func)
else:
raise NotImplementedError("%s is not supported in combine "
"operation with %s" %
(str(type(other)), str(type(self))))
raise NotImplementedError(
"{otype!s} is not supported in combine operation with "
"{selftype!s}".format(otype=type(other), selftype=type(self)))

def _combine_const(self, other, func, try_cast=True):
with np.errstate(all='ignore'):
Expand Down Expand Up @@ -1188,8 +1190,8 @@ def _construct_return_type(self, result, axes=None):
return self._constructor_sliced(
result, **self._extract_axes_for_slice(self, axes))

raise ValueError('invalid _construct_return_type [self->%s] '
'[result->%s]' % (self, result))
raise ValueError('invalid _construct_return_type [self->{self}] '
'[result->{result}]'.format(self=self, result=result))

def _wrap_result(self, result, axis):
axis = self._get_axis_name(axis)
Expand Down Expand Up @@ -1508,7 +1510,8 @@ def _extract_axis(self, data, axis=0, intersect=False):
if have_raw_arrays:
lengths = list(set(raw_lengths))
if len(lengths) > 1:
raise ValueError('ndarrays must match shape on axis %d' % axis)
raise ValueError('ndarrays must match shape on '
'axis {ax}'.format(ax=axis))

if have_frames:
if lengths[0] != len(index):
Expand All @@ -1525,20 +1528,6 @@ def _extract_axis(self, data, axis=0, intersect=False):
def _add_aggregate_operations(cls, use_numexpr=True):
""" add the operations to the cls; evaluate the doc strings again """

# doc strings substitors
Copy link
Contributor

Choose a reason for hiding this comment

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

is this replaced by something else?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added it back in @ L1580 😄

_agg_doc = """
Wrapper method for %%s

Parameters
----------
other : %s or %s""" % (cls._constructor_sliced.__name__, cls.__name__) + """
axis : {""" + ', '.join(cls._AXIS_ORDERS) + "}" + """
Axis to broadcast over

Returns
-------
""" + cls.__name__ + "\n"

def _panel_arith_method(op, name, str_rep=None, default_axis=None,
fill_zeros=None, **eval_kwargs):
def na_op(x, y):
Expand Down Expand Up @@ -1566,27 +1555,45 @@ def na_op(x, y):
equiv = 'panel ' + op_desc['op'] + ' other'

_op_doc = """
%%s of series and other, element-wise (binary operator `%%s`).
Equivalent to ``%%s``.
{desc} of series and other, element-wise (binary operator `{op_name}`).
Equivalent to ``{equiv}``.

Parameters
----------
other : {construct} or {cls_name}
axis : {{{axis_order}}}
Axis to broadcast over

Returns
-------
{cls_name}

See also
--------
{cls_name}.{reverse}\n"""
doc = _op_doc.format(
desc=op_desc['desc'], op_name=op_name, equiv=equiv,
construct=cls._constructor_sliced.__name__,
cls_name=cls.__name__, reverse=op_desc['reverse'],
axis_order=', '.join(cls._AXIS_ORDERS))
else:
# doc strings substitors
_agg_doc = """
Wrapper method for {wrp_method}

Parameters
----------
other : %s or %s""" % (cls._constructor_sliced.__name__,
cls.__name__) + """
axis : {""" + ', '.join(cls._AXIS_ORDERS) + "}" + """
other : {construct} or {cls_name}
axis : {{{axis_order}}}
Axis to broadcast over

Returns
-------
""" + cls.__name__ + """

See also
--------
""" + cls.__name__ + ".%s\n"
doc = _op_doc % (op_desc['desc'], op_name, equiv,
op_desc['reverse'])
else:
doc = _agg_doc % name
{cls_name}\n"""
doc = _agg_doc.format(
construct=cls._constructor_sliced.__name__,
cls_name=cls.__name__, wrp_method=name,
axis_order=', '.join(cls._AXIS_ORDERS))

@Appender(doc)
def f(self, other, axis=0):
Expand Down