|
5 | 5 | import nose
|
6 | 6 |
|
7 | 7 | import numpy as np
|
| 8 | +from numpy.testing import assert_almost_equal as np_assert_almost_equal |
| 9 | +from pandas import Timestamp |
8 | 10 | from pandas.compat import u
|
9 | 11 | import pandas.util.testing as tm
|
| 12 | +from pandas.tseries.offsets import Second, Milli, Micro |
10 | 13 |
|
11 | 14 | try:
|
12 | 15 | import pandas.tseries.converter as converter
|
@@ -46,9 +49,48 @@ def test_conversion(self):
|
46 | 49 | rs = self.dtc.convert('2012-1-1', None, None)
|
47 | 50 | self.assertEqual(rs, xp)
|
48 | 51 |
|
| 52 | + rs = self.dtc.convert(Timestamp('2012-1-1'), None, None) |
| 53 | + self.assertEqual(rs, xp) |
| 54 | + |
| 55 | + def test_conversion_float(self): |
| 56 | + decimals = 9 |
| 57 | + |
| 58 | + rs = self.dtc.convert(Timestamp('2012-1-1 01:02:03', tz='UTC'), None, None) |
| 59 | + xp = converter.dates.date2num(Timestamp('2012-1-1 01:02:03', tz='UTC')) |
| 60 | + np_assert_almost_equal(rs, xp, decimals) |
| 61 | + |
| 62 | + rs = self.dtc.convert(Timestamp('2012-1-1 09:02:03', tz='Asia/Hong_Kong'), None, None) |
| 63 | + np_assert_almost_equal(rs, xp, decimals) |
| 64 | + |
| 65 | + rs = self.dtc.convert(datetime(2012, 1, 1, 1, 2, 3), None, None) |
| 66 | + np_assert_almost_equal(rs, xp, decimals) |
| 67 | + |
49 | 68 | def test_time_formatter(self):
|
50 | 69 | self.tc(90000)
|
51 | 70 |
|
| 71 | + def test_dateindex_conversion(self): |
| 72 | + decimals = 9 |
| 73 | + |
| 74 | + for freq in ('B', 'L', 'S'): |
| 75 | + dateindex = tm.makeDateIndex(k = 10, freq = freq) |
| 76 | + rs = self.dtc.convert(dateindex, None, None) |
| 77 | + xp = converter.dates.date2num(dateindex) |
| 78 | + np_assert_almost_equal(rs, xp, decimals) |
| 79 | + |
| 80 | + def test_resolution(self): |
| 81 | + def _assert_less(ts1, ts2): |
| 82 | + val1 = self.dtc.convert(ts1, None, None) |
| 83 | + val2 = self.dtc.convert(ts2, None, None) |
| 84 | + if not val1 < val2: |
| 85 | + raise AssertionError('{0} is not less than {1}.'.format(val1, val2)) |
| 86 | + |
| 87 | + # Matplotlib's time representation using floats cannot distinguish intervals smaller |
| 88 | + # than ~10 microsecond in the common range of years. |
| 89 | + ts = Timestamp('2012-1-1') |
| 90 | + _assert_less(ts, ts + Second()) |
| 91 | + _assert_less(ts, ts + Milli()) |
| 92 | + _assert_less(ts, ts + Micro(50)) |
| 93 | + |
52 | 94 |
|
53 | 95 | if __name__ == '__main__':
|
54 | 96 | import nose
|
|
0 commit comments