當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。