Skip to content
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

CLN: replace %s syntax with .format in core.tools, algorithms.py, base.py #17305

Merged
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
10 changes: 5 additions & 5 deletions pandas/core/algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,12 +394,12 @@ def isin(comps, values):

if not is_list_like(comps):
raise TypeError("only list-like objects are allowed to be passed"
" to isin(), you passed a "
"[{0}]".format(type(comps).__name__))
" to isin(), you passed a [{comps_type}]"
.format(comps_type=type(comps).__name__))
if not is_list_like(values):
raise TypeError("only list-like objects are allowed to be passed"
" to isin(), you passed a "
"[{0}]".format(type(values).__name__))
" to isin(), you passed a [{values_type}]"
.format(values_type=type(values).__name__))

if not isinstance(values, (ABCIndex, ABCSeries, np.ndarray)):
values = lib.list_to_object_array(list(values))
Expand Down Expand Up @@ -674,7 +674,7 @@ def mode(values):
try:
result = np.sort(result)
except TypeError as e:
warn("Unable to sort modes: %s" % e)
warn("Unable to sort modes: {error}".format(error=e))

result = _reconstruct_data(result, original.dtype, original)
return Series(result)
Expand Down
19 changes: 10 additions & 9 deletions pandas/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,24 +342,25 @@ def _obj_with_exclusions(self):

def __getitem__(self, key):
if self._selection is not None:
raise Exception('Column(s) %s already selected' % self._selection)
raise Exception('Column(s) {selection} already selected'
.format(selection=self._selection))

if isinstance(key, (list, tuple, ABCSeries, ABCIndexClass,
np.ndarray)):
if len(self.obj.columns.intersection(key)) != len(key):
bad_keys = list(set(key).difference(self.obj.columns))
raise KeyError("Columns not found: %s"
% str(bad_keys)[1:-1])
raise KeyError("Columns not found: {missing}"
.format(missing=str(bad_keys)[1:-1]))
return self._gotitem(list(key), ndim=2)

elif not getattr(self, 'as_index', False):
if key not in self.obj.columns:
raise KeyError("Column not found: %s" % key)
raise KeyError("Column not found: {key}".format(key=key))
return self._gotitem(key, ndim=2)

else:
if key not in self.obj:
raise KeyError("Column not found: %s" % key)
raise KeyError("Column not found: {key}".format(key=key))
return self._gotitem(key, ndim=1)

def _gotitem(self, key, ndim, subset=None):
Expand Down Expand Up @@ -409,7 +410,7 @@ def _try_aggregate_string_function(self, arg, *args, **kwargs):
if f is not None:
return f(self, *args, **kwargs)

raise ValueError("{} is an unknown string function".format(arg))
raise ValueError("{arg} is an unknown string function".format(arg=arg))

def _aggregate(self, arg, *args, **kwargs):
"""
Expand Down Expand Up @@ -484,9 +485,9 @@ def nested_renaming_depr(level=4):
is_nested_renamer = True

if k not in obj.columns:
raise SpecificationError('cannot perform renaming '
'for {0} with a nested '
'dictionary'.format(k))
msg = ('cannot perform renaming for {key} with a '
'nested dictionary').format(key=k)
raise SpecificationError(msg)
nested_renaming_depr(4 + (_level or 0))

elif isinstance(obj, ABCSeries):
Expand Down
32 changes: 18 additions & 14 deletions pandas/core/tools/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ def _infer(a, b):
if b and b.tzinfo:
if not (tslib.get_timezone(tz) == tslib.get_timezone(b.tzinfo)):
raise AssertionError('Inputs must both have the same timezone,'
' {0} != {1}'.format(tz, b.tzinfo))
' {timezone1} != {timezone2}'
.format(timezone1=tz, timezone2=b.tzinfo))
return tz

tz = None
Expand Down Expand Up @@ -491,10 +492,10 @@ def _convert_listlike(arg, box, format, name=None, tz=tz):
offset = tslib.Timestamp(origin) - tslib.Timestamp(0)
except tslib.OutOfBoundsDatetime:
raise tslib.OutOfBoundsDatetime(
"origin {} is Out of Bounds".format(origin))
"origin {origin} is Out of Bounds".format(origin=origin))
except ValueError:
raise ValueError("origin {} cannot be converted "
"to a Timestamp".format(origin))
raise ValueError("origin {origin} cannot be converted "
"to a Timestamp".format(origin=origin))

# convert the offset to the unit of the arg
# this should be lossless in terms of precision
Expand Down Expand Up @@ -590,16 +591,16 @@ def f(value):
required = ['year', 'month', 'day']
req = sorted(list(set(required) - set(unit_rev.keys())))
if len(req):
raise ValueError("to assemble mappings requires at "
"least that [year, month, day] be specified: "
"[{0}] is missing".format(','.join(req)))
raise ValueError("to assemble mappings requires at least that "
"[year, month, day] be specified: [{required}] "
"is missing".format(required=','.join(req)))

# keys we don't recognize
excess = sorted(list(set(unit_rev.keys()) - set(_unit_map.values())))
if len(excess):
raise ValueError("extra keys have been passed "
"to the datetime assemblage: "
"[{0}]".format(','.join(excess)))
"[{excess}]".format(','.join(excess=excess)))

def coerce(values):
# we allow coercion to if errors allows
Expand All @@ -617,7 +618,7 @@ def coerce(values):
values = to_datetime(values, format='%Y%m%d', errors=errors)
except (TypeError, ValueError) as e:
raise ValueError("cannot assemble the "
"datetimes: {0}".format(e))
"datetimes: {error}".format(error=e))

for u in ['h', 'm', 's', 'ms', 'us', 'ns']:
value = unit_rev.get(u)
Expand All @@ -627,8 +628,8 @@ def coerce(values):
unit=u,
errors=errors)
except (TypeError, ValueError) as e:
raise ValueError("cannot assemble the datetimes "
"[{0}]: {1}".format(value, e))
raise ValueError("cannot assemble the datetimes [{value}]: "
"{error}".format(value=value, error=e))

return values

Expand Down Expand Up @@ -810,8 +811,10 @@ def _convert_listlike(arg, format):
times.append(datetime.strptime(element, format).time())
except (ValueError, TypeError):
if errors == 'raise':
raise ValueError("Cannot convert %s to a time with "
"given format %s" % (element, format))
msg = ("Cannot convert {element} to a time with given "
"format {format}").format(element=element,
format=format)
raise ValueError(msg)
elif errors == 'ignore':
return arg
else:
Expand Down Expand Up @@ -876,6 +879,7 @@ def ole2datetime(oledt):
# Excel has a bug where it thinks the date 2/29/1900 exists
# we just reject any date before 3/1/1900.
if val < 61:
raise ValueError("Value is outside of acceptable range: %s " % val)
msg = "Value is outside of acceptable range: {value}".format(value=val)
raise ValueError(msg)

return OLE_TIME_ZERO + timedelta(days=val)
7 changes: 4 additions & 3 deletions pandas/core/tools/timedeltas.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ def _validate_timedelta_unit(arg):
except:
if arg is None:
return 'ns'
raise ValueError("invalid timedelta unit {0} provided".format(arg))
raise ValueError("invalid timedelta unit {arg} provided"
.format(arg=arg))


def _coerce_scalar_to_timedelta_type(r, unit='ns', box=True, errors='raise'):
Expand Down Expand Up @@ -161,8 +162,8 @@ def _convert_listlike(arg, unit='ns', box=True, errors='raise', name=None):
if is_timedelta64_dtype(arg):
value = arg.astype('timedelta64[ns]')
elif is_integer_dtype(arg):
value = arg.astype('timedelta64[{0}]'.format(
unit)).astype('timedelta64[ns]', copy=False)
value = arg.astype('timedelta64[{unit}]'.format(unit=unit)).astype(
'timedelta64[ns]', copy=False)
else:
try:
value = tslib.array_to_timedelta64(_ensure_object(arg),
Expand Down