Skip to content

Commit 139f229

Browse files
author
Sylvain MARIE
committed
For the record: switching the repr in TimeDelta to old-style formatting
1 parent 01b9667 commit 139f229

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

pandas/_libs/tslibs/timedeltas.pyx

+9-9
Original file line numberDiff line numberDiff line change
@@ -1171,32 +1171,32 @@ cdef class _Timedelta(timedelta):
11711171
sign = " "
11721172

11731173
if format == 'all':
1174-
fmt = ("{days} days{sign}{hours:02}:{minutes:02}:{seconds:02}."
1175-
"{milliseconds:03}{microseconds:03}{nanoseconds:03}")
1174+
fmt = ("%(days)s days%(sign)s%(hours)02d:%(minutes)02d:%(seconds)02d."
1175+
"%(milliseconds)03d%(microseconds)03d%(nanoseconds)03d")
11761176
else:
11771177
# if we have a partial day
11781178
subs = (self._h or self._m or self._s or
11791179
self._ms or self._us or self._ns)
11801180

11811181
if self._ms or self._us or self._ns:
1182-
seconds_fmt = "{seconds:02}.{milliseconds:03}{microseconds:03}"
1182+
seconds_fmt = "%(seconds)02d.%(milliseconds)03d%(microseconds)03d"
11831183
if self._ns:
11841184
# GH#9309
1185-
seconds_fmt += "{nanoseconds:03}"
1185+
seconds_fmt += "%(nanoseconds)03d"
11861186
else:
1187-
seconds_fmt = "{seconds:02}"
1187+
seconds_fmt = "%(seconds)02d"
11881188

11891189
if format == 'sub_day' and not self._d:
1190-
fmt = "{hours:02}:{minutes:02}:" + seconds_fmt
1190+
fmt = "%(hours)02d:%(minutes)02d:" + seconds_fmt
11911191
elif subs or format == 'long':
1192-
fmt = "{days} days{sign}{hours:02}:{minutes:02}:" + seconds_fmt
1192+
fmt = "%(days)s days%(sign)s%(hours)02d:%(minutes)02d:" + seconds_fmt
11931193
else:
1194-
fmt = "{days} days"
1194+
fmt = "%(days)s days"
11951195

11961196
comp_dict = self.components._asdict()
11971197
comp_dict['sign'] = sign
11981198

1199-
return fmt.format(**comp_dict)
1199+
return fmt % comp_dict
12001200

12011201
def __repr__(self) -> str:
12021202
repr_based = self._repr_base(format='long')

0 commit comments

Comments
 (0)