Skip to content

Commit 9efa68c

Browse files
committed
Fix TimeFormatter for fractional seconds
1 parent 0303d0d commit 9efa68c

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

pandas/plotting/_converter.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,19 +190,20 @@ def __init__(self, locs):
190190
self.locs = locs
191191

192192
def __call__(self, x, pos=0):
193-
fmt = '%H:%M:%S'
193+
fmt = '%H:%M:%S.%f'
194194
s = int(x)
195195
ms = int((x - s) * 1e3)
196-
us = int((x - s) * 1e6 - ms)
196+
us = int((x - s) * 1e6 - ms * 1e3)
197+
msus = int((x - s) * 1e6)
197198
m, s = divmod(s, 60)
198199
h, m = divmod(m, 60)
199200
_, h = divmod(h, 24)
200201
if us != 0:
201-
fmt += '.%6f'
202+
return pydt.time(h, m, s, msus).strftime(fmt)
202203
elif ms != 0:
203-
fmt += '.%3f'
204+
return pydt.time(h, m, s, msus).strftime(fmt)[:-3]
204205

205-
return pydt.time(h, m, s, us).strftime(fmt)
206+
return pydt.time(h, m, s).strftime('%H:%M:%S')
206207

207208

208209
# Period Conversion

0 commit comments

Comments
 (0)