test_formats.py 2.1 KB

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