Skip to content

Commit 4e9c0d1

Browse files
jschendeljreback
authored andcommitted
CLN: replace %s syntax with .format in pandas.tseries (#17290)
1 parent 7818486 commit 4e9c0d1

File tree

3 files changed

+105
-84
lines changed

3 files changed

+105
-84
lines changed

pandas/tseries/frequencies.py

+21-17
Original file line numberDiff line numberDiff line change
@@ -409,16 +409,17 @@ def _get_freq_str(base, mult=1):
409409
need_suffix = ['QS', 'BQ', 'BQS', 'YS', 'AS', 'BY', 'BA', 'BYS', 'BAS']
410410
for __prefix in need_suffix:
411411
for _m in tslib._MONTHS:
412-
_offset_to_period_map['%s-%s' % (__prefix, _m)] = \
413-
_offset_to_period_map[__prefix]
412+
_alias = '{prefix}-{month}'.format(prefix=__prefix, month=_m)
413+
_offset_to_period_map[_alias] = _offset_to_period_map[__prefix]
414414
for __prefix in ['A', 'Q']:
415415
for _m in tslib._MONTHS:
416-
_alias = '%s-%s' % (__prefix, _m)
416+
_alias = '{prefix}-{month}'.format(prefix=__prefix, month=_m)
417417
_offset_to_period_map[_alias] = _alias
418418

419419
_days = ['MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT', 'SUN']
420420
for _d in _days:
421-
_offset_to_period_map['W-%s' % _d] = 'W-%s' % _d
421+
_alias = 'W-{day}'.format(day=_d)
422+
_offset_to_period_map[_alias] = _alias
422423

423424

424425
def get_period_alias(offset_str):
@@ -587,7 +588,7 @@ def _base_and_stride(freqstr):
587588
groups = opattern.match(freqstr)
588589

589590
if not groups:
590-
raise ValueError("Could not evaluate %s" % freqstr)
591+
raise ValueError("Could not evaluate {freq}".format(freq=freqstr))
591592

592593
stride = groups.group(1)
593594

@@ -775,8 +776,8 @@ def infer_freq(index, warn=True):
775776
if not (is_datetime64_dtype(values) or
776777
is_timedelta64_dtype(values) or
777778
values.dtype == object):
778-
raise TypeError("cannot infer freq from a non-convertible "
779-
"dtype on a Series of {0}".format(index.dtype))
779+
raise TypeError("cannot infer freq from a non-convertible dtype "
780+
"on a Series of {dtype}".format(dtype=index.dtype))
780781
index = values
781782

782783
if is_period_arraylike(index):
@@ -789,7 +790,7 @@ def infer_freq(index, warn=True):
789790
if isinstance(index, pd.Index) and not isinstance(index, pd.DatetimeIndex):
790791
if isinstance(index, (pd.Int64Index, pd.Float64Index)):
791792
raise TypeError("cannot infer freq from a non-convertible index "
792-
"type {0}".format(type(index)))
793+
"type {type}".format(type=type(index)))
793794
index = index.values
794795

795796
if not isinstance(index, pd.DatetimeIndex):
@@ -956,15 +957,17 @@ def _infer_daily_rule(self):
956957
if annual_rule:
957958
nyears = self.ydiffs[0]
958959
month = _month_aliases[self.rep_stamp.month]
959-
return _maybe_add_count('%s-%s' % (annual_rule, month), nyears)
960+
alias = '{prefix}-{month}'.format(prefix=annual_rule, month=month)
961+
return _maybe_add_count(alias, nyears)
960962

961963
quarterly_rule = self._get_quarterly_rule()
962964
if quarterly_rule:
963965
nquarters = self.mdiffs[0] / 3
964966
mod_dict = {0: 12, 2: 11, 1: 10}
965967
month = _month_aliases[mod_dict[self.rep_stamp.month % 3]]
966-
return _maybe_add_count('%s-%s' % (quarterly_rule, month),
967-
nquarters)
968+
alias = '{prefix}-{month}'.format(prefix=quarterly_rule,
969+
month=month)
970+
return _maybe_add_count(alias, nquarters)
968971

969972
monthly_rule = self._get_monthly_rule()
970973
if monthly_rule:
@@ -974,8 +977,8 @@ def _infer_daily_rule(self):
974977
days = self.deltas[0] / _ONE_DAY
975978
if days % 7 == 0:
976979
# Weekly
977-
alias = _weekday_rule_aliases[self.rep_stamp.weekday()]
978-
return _maybe_add_count('W-%s' % alias, days / 7)
980+
day = _weekday_rule_aliases[self.rep_stamp.weekday()]
981+
return _maybe_add_count('W-{day}'.format(day=day), days / 7)
979982
else:
980983
return _maybe_add_count('D', days)
981984

@@ -1048,7 +1051,7 @@ def _get_wom_rule(self):
10481051
week = week_of_months[0] + 1
10491052
wd = _weekday_rule_aliases[weekdays[0]]
10501053

1051-
return 'WOM-%d%s' % (week, wd)
1054+
return 'WOM-{week}{weekday}'.format(week=week, weekday=wd)
10521055

10531056

10541057
class _TimedeltaFrequencyInferer(_FrequencyInferer):
@@ -1058,15 +1061,16 @@ def _infer_daily_rule(self):
10581061
days = self.deltas[0] / _ONE_DAY
10591062
if days % 7 == 0:
10601063
# Weekly
1061-
alias = _weekday_rule_aliases[self.rep_stamp.weekday()]
1062-
return _maybe_add_count('W-%s' % alias, days / 7)
1064+
wd = _weekday_rule_aliases[self.rep_stamp.weekday()]
1065+
alias = 'W-{weekday}'.format(weekday=wd)
1066+
return _maybe_add_count(alias, days / 7)
10631067
else:
10641068
return _maybe_add_count('D', days)
10651069

10661070

10671071
def _maybe_add_count(base, count):
10681072
if count != 1:
1069-
return '%d%s' % (count, base)
1073+
return '{count}{base}'.format(count=int(count), base=base)
10701074
else:
10711075
return base
10721076

pandas/tseries/holiday.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -174,16 +174,16 @@ class from pandas.tseries.offsets
174174
def __repr__(self):
175175
info = ''
176176
if self.year is not None:
177-
info += 'year=%s, ' % self.year
178-
info += 'month=%s, day=%s, ' % (self.month, self.day)
177+
info += 'year={year}, '.format(year=self.year)
178+
info += 'month={mon}, day={day}, '.format(mon=self.month, day=self.day)
179179

180180
if self.offset is not None:
181-
info += 'offset=%s' % self.offset
181+
info += 'offset={offset}'.format(offset=self.offset)
182182

183183
if self.observance is not None:
184-
info += 'observance=%s' % self.observance
184+
info += 'observance={obs}'.format(obs=self.observance)
185185

186-
repr = 'Holiday: %s (%s)' % (self.name, info)
186+
repr = 'Holiday: {name} ({info})'.format(name=self.name, info=info)
187187
return repr
188188

189189
def dates(self, start_date, end_date, return_name=False):
@@ -374,8 +374,8 @@ def holidays(self, start=None, end=None, return_name=False):
374374
DatetimeIndex of holidays
375375
"""
376376
if self.rules is None:
377-
raise Exception('Holiday Calendar %s does not have any '
378-
'rules specified' % self.name)
377+
raise Exception('Holiday Calendar {name} does not have any '
378+
'rules specified'.format(name=self.name))
379379

380380
if start is None:
381381
start = AbstractHolidayCalendar.start_date

0 commit comments

Comments
 (0)