test_tzconversion.py 953 B

1234567891011121314151617181920212223
  1. import numpy as np
  2. import pytest
  3. import pytz
  4. from pandas._libs.tslibs.tzconversion import tz_localize_to_utc
  5. class TestTZLocalizeToUTC:
  6. def test_tz_localize_to_utc_ambiguous_infer(self):
  7. # val is a timestamp that is ambiguous when localized to US/Eastern
  8. val = 1_320_541_200_000_000_000
  9. vals = np.array([val, val - 1, val], dtype=np.int64)
  10. with pytest.raises(pytz.AmbiguousTimeError, match="2011-11-06 01:00:00"):
  11. tz_localize_to_utc(vals, pytz.timezone("US/Eastern"), ambiguous="infer")
  12. with pytest.raises(pytz.AmbiguousTimeError, match="are no repeated times"):
  13. tz_localize_to_utc(vals[:1], pytz.timezone("US/Eastern"), ambiguous="infer")
  14. vals[1] += 1
  15. msg = "There are 2 dst switches when there should only be 1"
  16. with pytest.raises(pytz.AmbiguousTimeError, match=msg):
  17. tz_localize_to_utc(vals, pytz.timezone("US/Eastern"), ambiguous="infer")