def test_timedelta_format():
x = [timedelta(days=7*i) for i in range(5)]
labels = timedelta_format()(x)
assert labels == ['0', '1 week', '2 weeks', '3 weeks', '4 weeks']
x = [pd.Timedelta(seconds=600*i) for i in range(5)]
labels = timedelta_format()(x)
assert labels == \
['0', '10 minutes', '20 minutes', '30 minutes', '40 minutes']
# specific units
labels = timedelta_format(units='h')(x)
assert labels == \
['0', '0.1667 hours', '0.3333 hours', '0.5000 hours',
'0.6667 hours']
# usetex
x = [timedelta(microseconds=7*i) for i in range(5)]
labels = timedelta_format(units='us', usetex=True)(x)
assert labels == \
['0', '7$\\mu s$', '14$\\mu s$', '21$\\mu s$', '28$\\mu s$']
评论列表
文章目录