当前位置: 首页>>代码示例>>Python>>正文


Python exceptions.NonExistentTimeError方法代码示例

本文整理汇总了Python中pytz.exceptions.NonExistentTimeError方法的典型用法代码示例。如果您正苦于以下问题:Python exceptions.NonExistentTimeError方法的具体用法?Python exceptions.NonExistentTimeError怎么用?Python exceptions.NonExistentTimeError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pytz.exceptions的用法示例。


在下文中一共展示了exceptions.NonExistentTimeError方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_localize_utc_conversion

# 需要导入模块: from pytz import exceptions [as 别名]
# 或者: from pytz.exceptions import NonExistentTimeError [as 别名]
def test_localize_utc_conversion(self):
        # Localizing to time zone should:
        #  1) check for DST ambiguities
        #  2) convert to UTC

        rng = date_range('3/10/2012', '3/11/2012', freq='30T')

        converted = rng.tz_localize(self.tzstr('US/Eastern'))
        expected_naive = rng + offsets.Hour(5)
        tm.assert_numpy_array_equal(converted.asi8, expected_naive.asi8)

        # DST ambiguity, this should fail
        rng = date_range('3/11/2012', '3/12/2012', freq='30T')
        # Is this really how it should fail??
        pytest.raises(NonExistentTimeError, rng.tz_localize,
                      self.tzstr('US/Eastern')) 
开发者ID:securityclippy,项目名称:elasticintel,代码行数:18,代码来源:test_timezones.py

示例2: test_tz_localize_dti

# 需要导入模块: from pytz import exceptions [as 别名]
# 或者: from pytz.exceptions import NonExistentTimeError [as 别名]
def test_tz_localize_dti(self):
        dti = DatetimeIndex(start='1/1/2005', end='1/1/2005 0:00:30.256',
                            freq='L')
        dti2 = dti.tz_localize(self.tzstr('US/Eastern'))

        dti_utc = DatetimeIndex(start='1/1/2005 05:00',
                                end='1/1/2005 5:00:30.256', freq='L', tz='utc')

        tm.assert_numpy_array_equal(dti2.values, dti_utc.values)

        dti3 = dti2.tz_convert(self.tzstr('US/Pacific'))
        tm.assert_numpy_array_equal(dti3.values, dti_utc.values)

        dti = DatetimeIndex(start='11/6/2011 1:59', end='11/6/2011 2:00',
                            freq='L')
        pytest.raises(pytz.AmbiguousTimeError, dti.tz_localize,
                      self.tzstr('US/Eastern'))

        dti = DatetimeIndex(start='3/13/2011 1:59', end='3/13/2011 2:00',
                            freq='L')
        pytest.raises(pytz.NonExistentTimeError, dti.tz_localize,
                      self.tzstr('US/Eastern')) 
开发者ID:securityclippy,项目名称:elasticintel,代码行数:24,代码来源:test_timezones.py

示例3: test_with_tz_ambiguous_times

# 需要导入模块: from pytz import exceptions [as 别名]
# 或者: from pytz.exceptions import NonExistentTimeError [as 别名]
def test_with_tz_ambiguous_times(self):
        tz = self.tz('US/Eastern')

        # March 13, 2011, spring forward, skip from 2 AM to 3 AM
        dr = date_range(datetime(2011, 3, 13, 1, 30), periods=3,
                        freq=offsets.Hour())
        pytest.raises(pytz.NonExistentTimeError, dr.tz_localize, tz)

        # after dst transition, it works
        dr = date_range(datetime(2011, 3, 13, 3, 30), periods=3,
                        freq=offsets.Hour(), tz=tz)

        # November 6, 2011, fall back, repeat 2 AM hour
        dr = date_range(datetime(2011, 11, 6, 1, 30), periods=3,
                        freq=offsets.Hour())
        pytest.raises(pytz.AmbiguousTimeError, dr.tz_localize, tz)

        # UTC is OK
        dr = date_range(datetime(2011, 3, 13), periods=48,
                        freq=offsets.Minute(30), tz=pytz.utc) 
开发者ID:securityclippy,项目名称:elasticintel,代码行数:22,代码来源:test_timezones.py

示例4: test_tz_localize_nonexistent

# 需要导入模块: from pytz import exceptions [as 别名]
# 或者: from pytz.exceptions import NonExistentTimeError [as 别名]
def test_tz_localize_nonexistent(self, stamp, tz):
        # GH#13057
        ts = Timestamp(stamp)
        with pytest.raises(NonExistentTimeError):
            ts.tz_localize(tz)
        # GH 22644
        with pytest.raises(NonExistentTimeError):
            with tm.assert_produces_warning(FutureWarning):
                ts.tz_localize(tz, errors='raise')
        with tm.assert_produces_warning(FutureWarning):
            assert ts.tz_localize(tz, errors='coerce') is NaT 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:13,代码来源:test_timezones.py

示例5: test_timestamp_tz_localize_nonexistent_raise

# 需要导入模块: from pytz import exceptions [as 别名]
# 或者: from pytz.exceptions import NonExistentTimeError [as 别名]
def test_timestamp_tz_localize_nonexistent_raise(self, tz):
        # GH 8917
        ts = Timestamp('2015-03-29 02:20:00')
        with pytest.raises(pytz.NonExistentTimeError):
            ts.tz_localize(tz, nonexistent='raise')
        with pytest.raises(ValueError):
            ts.tz_localize(tz, nonexistent='foo')

    # ------------------------------------------------------------------
    # Timestamp.tz_convert 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:12,代码来源:test_timezones.py

示例6: test_tz_localize_nonexistent

# 需要导入模块: from pytz import exceptions [as 别名]
# 或者: from pytz.exceptions import NonExistentTimeError [as 别名]
def test_tz_localize_nonexistent(self, stamp, tz):
        # GH#13057
        ts = Timestamp(stamp)
        with pytest.raises(NonExistentTimeError):
            ts.tz_localize(tz)
        with pytest.raises(NonExistentTimeError):
            ts.tz_localize(tz, errors='raise')
        assert ts.tz_localize(tz, errors='coerce') is NaT 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:10,代码来源:test_timezones.py

示例7: test_localize_utc_conversion_explicit

# 需要导入模块: from pytz import exceptions [as 别名]
# 或者: from pytz.exceptions import NonExistentTimeError [as 别名]
def test_localize_utc_conversion_explicit(self):
        # Localizing to time zone should:
        #  1) check for DST ambiguities
        #  2) convert to UTC

        rng = date_range('3/10/2012', '3/11/2012', freq='30T')
        converted = rng.tz_localize(self.tz('US/Eastern'))
        expected_naive = rng + offsets.Hour(5)
        assert np.array_equal(converted.asi8, expected_naive.asi8)

        # DST ambiguity, this should fail
        rng = date_range('3/11/2012', '3/12/2012', freq='30T')
        # Is this really how it should fail??
        pytest.raises(NonExistentTimeError, rng.tz_localize,
                      self.tz('US/Eastern')) 
开发者ID:securityclippy,项目名称:elasticintel,代码行数:17,代码来源:test_timezones.py

示例8: test_tz_localize_nonexistent

# 需要导入模块: from pytz import exceptions [as 别名]
# 或者: from pytz.exceptions import NonExistentTimeError [as 别名]
def test_tz_localize_nonexistent(self):
        # see gh-13057
        times = ['2015-03-08 02:00', '2015-03-08 02:30',
                 '2015-03-29 02:00', '2015-03-29 02:30']
        timezones = ['US/Eastern', 'US/Pacific',
                     'Europe/Paris', 'Europe/Belgrade']
        for t, tz in zip(times, timezones):
            ts = Timestamp(t)
            pytest.raises(NonExistentTimeError, ts.tz_localize,
                          tz)
            pytest.raises(NonExistentTimeError, ts.tz_localize,
                          tz, errors='raise')
            assert ts.tz_localize(tz, errors='coerce') is NaT 
开发者ID:securityclippy,项目名称:elasticintel,代码行数:15,代码来源:test_timestamp.py

示例9: test_timestamp_constructor_near_dst_boundary

# 需要导入模块: from pytz import exceptions [as 别名]
# 或者: from pytz.exceptions import NonExistentTimeError [as 别名]
def test_timestamp_constructor_near_dst_boundary(self):
        # GH#11481 & GH#15777
        # Naive string timestamps were being localized incorrectly
        # with tz_convert_single instead of tz_localize_to_utc

        for tz in ['Europe/Brussels', 'Europe/Prague']:
            result = Timestamp('2015-10-25 01:00', tz=tz)
            expected = Timestamp('2015-10-25 01:00').tz_localize(tz)
            assert result == expected

            with pytest.raises(pytz.AmbiguousTimeError):
                Timestamp('2015-10-25 02:00', tz=tz)

        result = Timestamp('2017-03-26 01:00', tz='Europe/Paris')
        expected = Timestamp('2017-03-26 01:00').tz_localize('Europe/Paris')
        assert result == expected

        with pytest.raises(pytz.NonExistentTimeError):
            Timestamp('2017-03-26 02:00', tz='Europe/Paris')

        # GH#11708
        naive = Timestamp('2015-11-18 10:00:00')
        result = naive.tz_localize('UTC').tz_convert('Asia/Kolkata')
        expected = Timestamp('2015-11-18 15:30:00+0530', tz='Asia/Kolkata')
        assert result == expected

        # GH#15823
        result = Timestamp('2017-03-26 00:00', tz='Europe/Paris')
        expected = Timestamp('2017-03-26 00:00:00+0100', tz='Europe/Paris')
        assert result == expected

        result = Timestamp('2017-03-26 01:00', tz='Europe/Paris')
        expected = Timestamp('2017-03-26 01:00:00+0100', tz='Europe/Paris')
        assert result == expected

        with pytest.raises(pytz.NonExistentTimeError):
            Timestamp('2017-03-26 02:00', tz='Europe/Paris')

        result = Timestamp('2017-03-26 02:00:00+0100', tz='Europe/Paris')
        naive = Timestamp(result.value)
        expected = naive.tz_localize('UTC').tz_convert('Europe/Paris')
        assert result == expected

        result = Timestamp('2017-03-26 03:00', tz='Europe/Paris')
        expected = Timestamp('2017-03-26 03:00:00+0200', tz='Europe/Paris')
        assert result == expected 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:48,代码来源:test_timezones.py

示例10: test_timestamp_constructor_near_dst_boundary

# 需要导入模块: from pytz import exceptions [as 别名]
# 或者: from pytz.exceptions import NonExistentTimeError [as 别名]
def test_timestamp_constructor_near_dst_boundary(self):
        # GH 11481 & 15777
        # Naive string timestamps were being localized incorrectly
        # with tz_convert_single instead of tz_localize_to_utc

        for tz in ['Europe/Brussels', 'Europe/Prague']:
            result = Timestamp('2015-10-25 01:00', tz=tz)
            expected = Timestamp('2015-10-25 01:00').tz_localize(tz)
            assert result == expected

            with pytest.raises(pytz.AmbiguousTimeError):
                Timestamp('2015-10-25 02:00', tz=tz)

        result = Timestamp('2017-03-26 01:00', tz='Europe/Paris')
        expected = Timestamp('2017-03-26 01:00').tz_localize('Europe/Paris')
        assert result == expected

        with pytest.raises(pytz.NonExistentTimeError):
            Timestamp('2017-03-26 02:00', tz='Europe/Paris')

        # GH 11708
        result = to_datetime("2015-11-18 15:30:00+05:30").tz_localize(
            'UTC').tz_convert('Asia/Kolkata')
        expected = Timestamp('2015-11-18 15:30:00+0530', tz='Asia/Kolkata')
        assert result == expected

        # GH 15823
        result = Timestamp('2017-03-26 00:00', tz='Europe/Paris')
        expected = Timestamp('2017-03-26 00:00:00+0100', tz='Europe/Paris')
        assert result == expected

        result = Timestamp('2017-03-26 01:00', tz='Europe/Paris')
        expected = Timestamp('2017-03-26 01:00:00+0100', tz='Europe/Paris')
        assert result == expected

        with pytest.raises(pytz.NonExistentTimeError):
            Timestamp('2017-03-26 02:00', tz='Europe/Paris')
        result = Timestamp('2017-03-26 02:00:00+0100', tz='Europe/Paris')
        expected = Timestamp(result.value).tz_localize(
            'UTC').tz_convert('Europe/Paris')
        assert result == expected

        result = Timestamp('2017-03-26 03:00', tz='Europe/Paris')
        expected = Timestamp('2017-03-26 03:00:00+0200', tz='Europe/Paris')
        assert result == expected 
开发者ID:securityclippy,项目名称:elasticintel,代码行数:47,代码来源:test_timezones.py


注:本文中的pytz.exceptions.NonExistentTimeError方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。