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


Python tslib.OutOfBoundsDatetime方法代码示例

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


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

示例1: test_datetime_outofbounds_scalar

# 需要导入模块: from pandas._libs import tslib [as 别名]
# 或者: from pandas._libs.tslib 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: _set_axis

# 需要导入模块: from pandas._libs import tslib [as 别名]
# 或者: from pandas._libs.tslib import OutOfBoundsDatetime [as 别名]
def _set_axis(self, axis, labels, fastpath=False):
        """ override generic, we want to set the _typ here """

        if not fastpath:
            labels = _ensure_index(labels)

        is_all_dates = labels.is_all_dates
        if is_all_dates:
            if not isinstance(labels,
                              (DatetimeIndex, PeriodIndex, TimedeltaIndex)):
                try:
                    labels = DatetimeIndex(labels)
                    # need to set here becuase we changed the index
                    if fastpath:
                        self._data.set_axis(axis, labels)
                except (libts.OutOfBoundsDatetime, ValueError):
                    # labels may exceeds datetime bounds,
                    # or not be a DatetimeIndex
                    pass

        self._set_subtyp(is_all_dates)

        object.__setattr__(self, '_index', labels)
        if not fastpath:
            self._data.set_axis(axis, labels) 
开发者ID:nccgroup,项目名称:Splunking-Crime,代码行数:27,代码来源:series.py

示例3: test_to_datetime_barely_out_of_bounds

# 需要导入模块: from pandas._libs import tslib [as 别名]
# 或者: from pandas._libs.tslib 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

示例4: test_to_datetime_barely_out_of_bounds

# 需要导入模块: from pandas._libs import tslib [as 别名]
# 或者: from pandas._libs.tslib import OutOfBoundsDatetime [as 别名]
def test_to_datetime_barely_out_of_bounds():
    # see gh-19382, gh-19529
    #
    # 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)
    msg = "Out of bounds nanosecond timestamp: 2262-04-11 23:47:16"

    with pytest.raises(tslib.OutOfBoundsDatetime, match=msg):
        tslib.array_to_datetime(arr) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:12,代码来源:test_array_to_datetime.py

示例5: test_construction_outofbounds

# 需要导入模块: from pandas._libs import tslib [as 别名]
# 或者: from pandas._libs.tslib import OutOfBoundsDatetime [as 别名]
def test_construction_outofbounds(self):
        # GH 13663
        dates = [datetime(3000, 1, 1), datetime(4000, 1, 1),
                 datetime(5000, 1, 1), datetime(6000, 1, 1)]
        exp = Index(dates, dtype=object)
        # coerces to object
        tm.assert_index_equal(Index(dates), exp)

        with pytest.raises(OutOfBoundsDatetime):
            # can't create DatetimeIndex
            DatetimeIndex(dates) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:13,代码来源:test_construction.py

示例6: test_apply_out_of_range

# 需要导入模块: from pandas._libs import tslib [as 别名]
# 或者: from pandas._libs.tslib import OutOfBoundsDatetime [as 别名]
def test_apply_out_of_range(self, tz):
        if self._offset is None:
            return

        # try to create an out-of-bounds result timestamp; if we can't create
        # the offset skip
        try:
            if self._offset in (BusinessHour, CustomBusinessHour):
                # Using 10000 in BusinessHour fails in tz check because of DST
                # difference
                offset = self._get_offset(self._offset, value=100000)
            else:
                offset = self._get_offset(self._offset, value=10000)

            result = Timestamp('20080101') + offset
            assert isinstance(result, datetime)
            assert result.tzinfo is None

            # Check tz is preserved
            t = Timestamp('20080101', tz=tz)
            result = t + offset
            assert isinstance(result, datetime)
            assert t.tzinfo == result.tzinfo

        except tslib.OutOfBoundsDatetime:
            raise
        except (ValueError, KeyError):
            # we are creating an invalid offset
            # so ignore
            pass 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:32,代码来源:test_offsets.py

示例7: test_to_datetime_barely_out_of_bounds

# 需要导入模块: from pandas._libs import tslib [as 别名]
# 或者: from pandas._libs.tslib 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(tslib.OutOfBoundsDatetime):
            tslib.array_to_datetime(arr) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:9,代码来源:test_array_to_datetime.py

示例8: test_unit

# 需要导入模块: from pandas._libs import tslib [as 别名]
# 或者: from pandas._libs.tslib 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

示例9: test_unit

# 需要导入模块: from pandas._libs import tslib [as 别名]
# 或者: from pandas._libs.tslib 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, tslib.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, tslib.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:birforce,项目名称:vnpy_crypto,代码行数:49,代码来源:test_tools.py

示例10: test_unit

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

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

        values = [11111111, 1, 1.0, tslib.iNaT, NaT, np.nan,
                  'NaT', '']
        result = to_datetime(values, unit='D', errors='ignore')
        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')
        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')

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

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

        result = to_datetime(values, errors='coerce', unit='s')
        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')

        # 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')
            except tslib.OutOfBoundsDatetime:
                raise AssertionError("incorrect exception raised")
            except ValueError:
                pass 
开发者ID:securityclippy,项目名称:elasticintel,代码行数:49,代码来源:test_tools.py


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