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


Python errors.OutOfBoundsDatetime方法代码示例

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


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

示例1: test_datetime_outofbounds_scalar

# 需要导入模块: from pandas import errors [as 别名]
# 或者: from pandas.errors import OutOfBoundsDatetime [as 别名]
def test_datetime_outofbounds_scalar(self, value, format, infer):
        # GH24763
        res = pd.to_datetime(value, errors='ignore', format=format,
                             infer_datetime_format=infer)
        assert res == value

        res = pd.to_datetime(value, errors='coerce', format=format,
                             infer_datetime_format=infer)
        assert res is pd.NaT

        if format is not None:
            with pytest.raises(ValueError):
                pd.to_datetime(value, errors='raise', format=format,
                               infer_datetime_format=infer)
        else:
            with pytest.raises(OutOfBoundsDatetime):
                pd.to_datetime(value, errors='raise', format=format,
                               infer_datetime_format=infer) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:20,代码来源:test_tools.py

示例2: test_to_datetime_barely_out_of_bounds

# 需要导入模块: from pandas import errors [as 别名]
# 或者: from pandas.errors import OutOfBoundsDatetime [as 别名]
def test_to_datetime_barely_out_of_bounds(self):
        # GH#19529
        # GH#19382 close enough to bounds that dropping nanos would result
        # in an in-bounds datetime
        arr = np.array(['2262-04-11 23:47:16.854775808'], dtype=object)

        with pytest.raises(OutOfBoundsDatetime):
            to_datetime(arr) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:10,代码来源:test_tools.py

示例3: test_date_range_multiplication_overflow

# 需要导入模块: from pandas import errors [as 别名]
# 或者: from pandas.errors import OutOfBoundsDatetime [as 别名]
def test_date_range_multiplication_overflow(self):
        # GH#24255
        # check that overflows in calculating `addend = periods * stride`
        #  are caught
        with tm.assert_produces_warning(None):
            # we should _not_ be seeing a overflow RuntimeWarning
            dti = date_range(start='1677-09-22', periods=213503, freq='D')

        assert dti[0] == Timestamp('1677-09-22')
        assert len(dti) == 213503

        msg = "Cannot generate range with"
        with pytest.raises(OutOfBoundsDatetime, match=msg):
            date_range('1969-05-04', periods=200000000, freq='30000D') 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:16,代码来源:test_date_range.py

示例4: test_date_range_int64_overflow_non_recoverable

# 需要导入模块: from pandas import errors [as 别名]
# 或者: from pandas.errors import OutOfBoundsDatetime [as 别名]
def test_date_range_int64_overflow_non_recoverable(self):
        # GH#24255
        # case with start later than 1970-01-01, overflow int64 but not uint64
        msg = "Cannot generate range with"
        with pytest.raises(OutOfBoundsDatetime, match=msg):
            date_range(start='1970-02-01', periods=106752 * 24, freq='H')

        # case with end before 1970-01-01, overflow int64 but not uint64
        with pytest.raises(OutOfBoundsDatetime, match=msg):
            date_range(end='1969-11-14', periods=106752 * 24, freq='H') 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:12,代码来源:test_date_range.py

示例5: test_catch_oob

# 需要导入模块: from pandas import errors [as 别名]
# 或者: from pandas.errors import OutOfBoundsDatetime [as 别名]
def test_catch_oob():
    from pandas import errors

    try:
        pd.Timestamp('15000101')
    except errors.OutOfBoundsDatetime:
        pass 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:9,代码来源:test_errors.py

示例6: test_tz_localize_pushes_out_of_bounds

# 需要导入模块: from pandas import errors [as 别名]
# 或者: from pandas.errors import OutOfBoundsDatetime [as 别名]
def test_tz_localize_pushes_out_of_bounds(self):
        # GH#12677
        # tz_localize that pushes away from the boundary is OK
        pac = Timestamp.min.tz_localize('US/Pacific')
        assert pac.value > Timestamp.min.value
        pac.tz_convert('Asia/Tokyo')  # tz_convert doesn't change value
        with pytest.raises(OutOfBoundsDatetime):
            Timestamp.min.tz_localize('Asia/Tokyo')

        # tz_localize that pushes away from the boundary is OK
        tokyo = Timestamp.max.tz_localize('Asia/Tokyo')
        assert tokyo.value < Timestamp.max.value
        tokyo.tz_convert('US/Pacific')  # tz_convert doesn't change value
        with pytest.raises(OutOfBoundsDatetime):
            Timestamp.max.tz_localize('US/Pacific') 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:17,代码来源:test_timezones.py

示例7: test_barely_out_of_bounds

# 需要导入模块: from pandas import errors [as 别名]
# 或者: from pandas.errors import OutOfBoundsDatetime [as 别名]
def test_barely_out_of_bounds(self):
        # GH#19529
        # GH#19382 close enough to bounds that dropping nanos would result
        # in an in-bounds datetime
        with pytest.raises(OutOfBoundsDatetime):
            Timestamp('2262-04-11 23:47:16.854775808') 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:8,代码来源:test_timestamp.py

示例8: test_to_timestamp_out_of_bounds

# 需要导入模块: from pandas import errors [as 别名]
# 或者: from pandas.errors import OutOfBoundsDatetime [as 别名]
def test_to_timestamp_out_of_bounds(self):
        # GH#19643, currently gives Timestamp('1754-08-30 22:43:41.128654848')
        per = Period('0001-01-01', freq='B')
        with pytest.raises(OutOfBoundsDatetime):
            per.to_timestamp() 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:7,代码来源:test_asfreq.py

示例9: test_unit

# 需要导入模块: from pandas import errors [as 别名]
# 或者: from pandas.errors import OutOfBoundsDatetime [as 别名]
def test_unit(self, cache):
        # GH 11758
        # test proper behavior with erros

        with pytest.raises(ValueError):
            to_datetime([1], unit='D', format='%Y%m%d', cache=cache)

        values = [11111111, 1, 1.0, iNaT, NaT, np.nan,
                  'NaT', '']
        result = to_datetime(values, unit='D', errors='ignore', cache=cache)
        expected = Index([11111111, Timestamp('1970-01-02'),
                          Timestamp('1970-01-02'), NaT,
                          NaT, NaT, NaT, NaT],
                         dtype=object)
        tm.assert_index_equal(result, expected)

        result = to_datetime(values, unit='D', errors='coerce', cache=cache)
        expected = DatetimeIndex(['NaT', '1970-01-02', '1970-01-02',
                                  'NaT', 'NaT', 'NaT', 'NaT', 'NaT'])
        tm.assert_index_equal(result, expected)

        with pytest.raises(tslib.OutOfBoundsDatetime):
            to_datetime(values, unit='D', errors='raise', cache=cache)

        values = [1420043460000, iNaT, NaT, np.nan, 'NaT']

        result = to_datetime(values, errors='ignore', unit='s', cache=cache)
        expected = Index([1420043460000, NaT, NaT,
                          NaT, NaT], dtype=object)
        tm.assert_index_equal(result, expected)

        result = to_datetime(values, errors='coerce', unit='s', cache=cache)
        expected = DatetimeIndex(['NaT', 'NaT', 'NaT', 'NaT', 'NaT'])
        tm.assert_index_equal(result, expected)

        with pytest.raises(tslib.OutOfBoundsDatetime):
            to_datetime(values, errors='raise', unit='s', cache=cache)

        # if we have a string, then we raise a ValueError
        # and NOT an OutOfBoundsDatetime
        for val in ['foo', Timestamp('20130101')]:
            try:
                to_datetime(val, errors='raise', unit='s', cache=cache)
            except tslib.OutOfBoundsDatetime:
                raise AssertionError("incorrect exception raised")
            except ValueError:
                pass 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:49,代码来源:test_tools.py


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