Skip to content

CLN: timeseries in plotting clean up #28020

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

Merged
merged 8 commits into from
Sep 11, 2019
Merged
17 changes: 0 additions & 17 deletions pandas/plotting/_matplotlib/timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,23 +304,6 @@ def _maybe_convert_index(ax, data):
# Do we need the rest for convenience?


def format_timedelta_ticks(x, pos, n_decimals):
"""
Convert seconds to 'D days HH:MM:SS.F'
"""
s, ns = divmod(x, 1e9)
m, s = divmod(s, 60)
h, m = divmod(m, 60)
d, h = divmod(h, 24)
decimals = int(ns * 10 ** (n_decimals - 9))
s = r"{:02d}:{:02d}:{:02d}".format(int(h), int(m), int(s))
if n_decimals > 0:
s += ".{{:0{:0d}d}}".format(n_decimals).format(decimals)
if d != 0:
s = "{:d} days ".format(int(d)) + s
return s


def _format_coord(freq, t, y):
return "t = {0} y = {1:8f}".format(Period(ordinal=int(t), freq=freq), y)

Expand Down
19 changes: 19 additions & 0 deletions pandas/tests/plotting/test_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,3 +373,22 @@ def test_convert_nested(self):
r1 = self.pc.convert([data, data], None, self.axis)
r2 = [self.pc.convert(data, None, self.axis) for _ in range(2)]
assert r1 == r2


class TestTimeDeltaConverter:
def setup_method(self, method):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're trying to move away from the setup_-style of tests. Can you use the full name in the test?

self.tdc = converter.TimeSeries_TimedeltaFormatter

@pytest.mark.parametrize(
"x, decimal, format_expected",
[
(0.0, 0, "00:00:00"),
(3972320000000, 1, "01:06:12.3"),
(713233432000000, 2, "8 days 06:07:13.43"),
(32423432000000, 4, "09:00:23.4320"),
],
)
def test_format_timedelta_ticks(self, x, decimal, format_expected):

result = self.tdc.format_timedelta_ticks(x, pos=None, n_decimals=decimal)
assert result == format_expected