Skip to content

Commit f7cf9ea

Browse files
charlesdong1991proost
authored andcommitted
CLN: timeseries in plotting clean up (pandas-dev#28020)
1 parent 0999fe3 commit f7cf9ea

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

pandas/plotting/_matplotlib/timeseries.py

-17
Original file line numberDiff line numberDiff line change
@@ -304,23 +304,6 @@ def _maybe_convert_index(ax, data):
304304
# Do we need the rest for convenience?
305305

306306

307-
def format_timedelta_ticks(x, pos, n_decimals):
308-
"""
309-
Convert seconds to 'D days HH:MM:SS.F'
310-
"""
311-
s, ns = divmod(x, 1e9)
312-
m, s = divmod(s, 60)
313-
h, m = divmod(m, 60)
314-
d, h = divmod(h, 24)
315-
decimals = int(ns * 10 ** (n_decimals - 9))
316-
s = r"{:02d}:{:02d}:{:02d}".format(int(h), int(m), int(s))
317-
if n_decimals > 0:
318-
s += ".{{:0{:0d}d}}".format(n_decimals).format(decimals)
319-
if d != 0:
320-
s = "{:d} days ".format(int(d)) + s
321-
return s
322-
323-
324307
def _format_coord(freq, t, y):
325308
return "t = {0} y = {1:8f}".format(Period(ordinal=int(t), freq=freq), y)
326309

pandas/tests/plotting/test_converter.py

+18
Original file line numberDiff line numberDiff line change
@@ -388,3 +388,21 @@ def test_convert_nested(self):
388388
r1 = self.pc.convert([data, data], None, self.axis)
389389
r2 = [self.pc.convert(data, None, self.axis) for _ in range(2)]
390390
assert r1 == r2
391+
392+
393+
class TestTimeDeltaConverter:
394+
"""Test timedelta converter"""
395+
396+
@pytest.mark.parametrize(
397+
"x, decimal, format_expected",
398+
[
399+
(0.0, 0, "00:00:00"),
400+
(3972320000000, 1, "01:06:12.3"),
401+
(713233432000000, 2, "8 days 06:07:13.43"),
402+
(32423432000000, 4, "09:00:23.4320"),
403+
],
404+
)
405+
def test_format_timedelta_ticks(self, x, decimal, format_expected):
406+
tdc = converter.TimeSeries_TimedeltaFormatter
407+
result = tdc.format_timedelta_ticks(x, pos=None, n_decimals=decimal)
408+
assert result == format_expected

0 commit comments

Comments
 (0)