|
| 1 | +import pytest |
| 2 | + |
| 3 | +from pandas import Timestamp |
| 4 | + |
| 5 | +ts_no_ns = Timestamp( |
| 6 | + year=2019, |
| 7 | + month=5, |
| 8 | + day=18, |
| 9 | + hour=15, |
| 10 | + minute=17, |
| 11 | + second=8, |
| 12 | + microsecond=132263, |
| 13 | +) |
| 14 | +ts_ns = Timestamp( |
| 15 | + year=2019, |
| 16 | + month=5, |
| 17 | + day=18, |
| 18 | + hour=15, |
| 19 | + minute=17, |
| 20 | + second=8, |
| 21 | + microsecond=132263, |
| 22 | + nanosecond=123, |
| 23 | +) |
| 24 | +ts_ns_tz = Timestamp( |
| 25 | + year=2019, |
| 26 | + month=5, |
| 27 | + day=18, |
| 28 | + hour=15, |
| 29 | + minute=17, |
| 30 | + second=8, |
| 31 | + microsecond=132263, |
| 32 | + nanosecond=123, |
| 33 | + tz="UTC", |
| 34 | +) |
| 35 | +ts_no_us = Timestamp( |
| 36 | + year=2019, |
| 37 | + month=5, |
| 38 | + day=18, |
| 39 | + hour=15, |
| 40 | + minute=17, |
| 41 | + second=8, |
| 42 | + microsecond=0, |
| 43 | + nanosecond=123, |
| 44 | +) |
| 45 | + |
| 46 | + |
| 47 | +@pytest.mark.parametrize( |
| 48 | + "ts, timespec, expected_iso", |
| 49 | + [ |
| 50 | + (ts_no_ns, "auto", "2019-05-18T15:17:08.132263"), |
| 51 | + (ts_no_ns, "seconds", "2019-05-18T15:17:08"), |
| 52 | + (ts_no_ns, "nanoseconds", "2019-05-18T15:17:08.132263000"), |
| 53 | + (ts_ns, "auto", "2019-05-18T15:17:08.132263123"), |
| 54 | + (ts_ns, "hours", "2019-05-18T15"), |
| 55 | + (ts_ns, "minutes", "2019-05-18T15:17"), |
| 56 | + (ts_ns, "seconds", "2019-05-18T15:17:08"), |
| 57 | + (ts_ns, "milliseconds", "2019-05-18T15:17:08.132"), |
| 58 | + (ts_ns, "microseconds", "2019-05-18T15:17:08.132263"), |
| 59 | + (ts_ns, "nanoseconds", "2019-05-18T15:17:08.132263123"), |
| 60 | + (ts_ns_tz, "auto", "2019-05-18T15:17:08.132263123+00:00"), |
| 61 | + (ts_ns_tz, "hours", "2019-05-18T15+00:00"), |
| 62 | + (ts_ns_tz, "minutes", "2019-05-18T15:17+00:00"), |
| 63 | + (ts_ns_tz, "seconds", "2019-05-18T15:17:08+00:00"), |
| 64 | + (ts_ns_tz, "milliseconds", "2019-05-18T15:17:08.132+00:00"), |
| 65 | + (ts_ns_tz, "microseconds", "2019-05-18T15:17:08.132263+00:00"), |
| 66 | + (ts_ns_tz, "nanoseconds", "2019-05-18T15:17:08.132263123+00:00"), |
| 67 | + (ts_no_us, "auto", "2019-05-18T15:17:08.000000123"), |
| 68 | + ], |
| 69 | +) |
| 70 | +def test_isoformat(ts, timespec, expected_iso): |
| 71 | + assert ts.isoformat(timespec=timespec) == expected_iso |
0 commit comments