예제 #1
0
def _compare_local_to_utc(tz_didx, naive_didx):
    # Check that tz_localize behaves the same vectorized and pointwise.
    err1 = err2 = None
    try:
        result = tzconversion.tz_localize_to_utc(naive_didx.asi8, tz_didx.tz)
        err1 = None
    except Exception as err:
        err1 = err

    try:
        expected = naive_didx.map(lambda x: x.tz_localize(tz_didx.tz)).asi8
    except Exception as err:
        err2 = err

    if err1 is not None:
        assert type(err1) == type(err2)
    else:
        assert err2 is None
        tm.assert_numpy_array_equal(result, expected)
예제 #2
0
    def test_tz_localize_to_utc_ambiguous_infer(self):
        # val is a timestamp that is ambiguous when localized to US/Eastern
        val = 1_320_541_200_000_000_000
        vals = np.array([val, val - 1, val], dtype=np.int64)

        with pytest.raises(pytz.AmbiguousTimeError,
                           match="2011-11-06 01:00:00"):
            tz_localize_to_utc(vals,
                               pytz.timezone("US/Eastern"),
                               ambiguous="infer")

        with pytest.raises(pytz.AmbiguousTimeError,
                           match="are no repeated times"):
            tz_localize_to_utc(vals[:1],
                               pytz.timezone("US/Eastern"),
                               ambiguous="infer")

        vals[1] += 1
        msg = "There are 2 dst switches when there should only be 1"
        with pytest.raises(pytz.AmbiguousTimeError, match=msg):
            tz_localize_to_utc(vals,
                               pytz.timezone("US/Eastern"),
                               ambiguous="infer")
예제 #3
0
 def time_tz_localize_to_utc(self, size, tz):
     # effectively:
     #  dti = DatetimeIndex(self.i8data)
     #  dti.tz_localize(tz, ambiguous="NaT", nonexistent="NaT")
     tz_localize_to_utc(self.i8data, tz, ambiguous="NaT", nonexistent="NaT")