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


Python tslib.array_to_datetime方法代码示例

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


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

示例1: test_coerce_of_invalid_datetimes

# 需要导入模块: from pandas._libs import tslib [as 别名]
# 或者: from pandas._libs.tslib import array_to_datetime [as 别名]
def test_coerce_of_invalid_datetimes(errors):
    arr = np.array(["01-01-2013", "not_a_date", "1"], dtype=object)
    kwargs = dict(values=arr, errors=errors)

    if errors == "ignore":
        # Without coercing, the presence of any invalid
        # dates prevents any values from being converted.
        result, _ = tslib.array_to_datetime(**kwargs)
        tm.assert_numpy_array_equal(result, arr)
    else:  # coerce.
        # With coercing, the invalid dates becomes iNaT
        result, _ = tslib.array_to_datetime(arr, errors="coerce")
        expected = ["2013-01-01T00:00:00.000000000-0000",
                    iNaT,
                    iNaT]

        tm.assert_numpy_array_equal(
            result,
            np_array_datetime64_compat(expected, dtype="M8[ns]")) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:21,代码来源:test_array_to_datetime.py

示例2: test_parsing_valid_dates

# 需要导入模块: from pandas._libs import tslib [as 别名]
# 或者: from pandas._libs.tslib import array_to_datetime [as 别名]
def test_parsing_valid_dates(self):
        arr = np.array(['01-01-2013', '01-02-2013'], dtype=object)
        result = tslib.array_to_datetime(arr)
        expected = ['2013-01-01T00:00:00.000000000-0000',
                    '2013-01-02T00:00:00.000000000-0000']
        tm.assert_numpy_array_equal(
            result,
            np_array_datetime64_compat(expected, dtype='M8[ns]'))

        arr = np.array(['Mon Sep 16 2013', 'Tue Sep 17 2013'], dtype=object)
        result = tslib.array_to_datetime(arr)
        expected = ['2013-09-16T00:00:00.000000000-0000',
                    '2013-09-17T00:00:00.000000000-0000']
        tm.assert_numpy_array_equal(
            result,
            np_array_datetime64_compat(expected, dtype='M8[ns]')) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:18,代码来源:test_array_to_datetime.py

示例3: test_coerce_of_invalid_datetimes

# 需要导入模块: from pandas._libs import tslib [as 别名]
# 或者: from pandas._libs.tslib import array_to_datetime [as 别名]
def test_coerce_of_invalid_datetimes(self):
        arr = np.array(['01-01-2013', 'not_a_date', '1'], dtype=object)

        # Without coercing, the presence of any invalid dates prevents
        # any values from being converted
        result = tslib.array_to_datetime(arr, errors='ignore')
        tm.assert_numpy_array_equal(result, arr)

        # With coercing, the invalid dates becomes iNaT
        result = tslib.array_to_datetime(arr, errors='coerce')
        expected = ['2013-01-01T00:00:00.000000000-0000',
                    tslib.iNaT,
                    tslib.iNaT]

        tm.assert_numpy_array_equal(
            result,
            np_array_datetime64_compat(expected, dtype='M8[ns]')) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:19,代码来源:test_array_to_datetime.py

示例4: test_parsing_valid_dates

# 需要导入模块: from pandas._libs import tslib [as 别名]
# 或者: from pandas._libs.tslib import array_to_datetime [as 别名]
def test_parsing_valid_dates(self):
        arr = np.array(['01-01-2013', '01-02-2013'], dtype=object)
        tm.assert_numpy_array_equal(
            tslib.array_to_datetime(arr),
            np_array_datetime64_compat(
                [
                    '2013-01-01T00:00:00.000000000-0000',
                    '2013-01-02T00:00:00.000000000-0000'
                ],
                dtype='M8[ns]'
            )
        )

        arr = np.array(['Mon Sep 16 2013', 'Tue Sep 17 2013'], dtype=object)
        tm.assert_numpy_array_equal(
            tslib.array_to_datetime(arr),
            np_array_datetime64_compat(
                [
                    '2013-09-16T00:00:00.000000000-0000',
                    '2013-09-17T00:00:00.000000000-0000'
                ],
                dtype='M8[ns]'
            )
        ) 
开发者ID:securityclippy,项目名称:elasticintel,代码行数:26,代码来源:test_tools.py

示例5: test_parsing_timezone_offsets

# 需要导入模块: from pandas._libs import tslib [as 别名]
# 或者: from pandas._libs.tslib import array_to_datetime [as 别名]
def test_parsing_timezone_offsets(self):
        # All of these datetime strings with offsets are equivalent
        # to the same datetime after the timezone offset is added
        dt_strings = [
            '01-01-2013 08:00:00+08:00',
            '2013-01-01T08:00:00.000000000+0800',
            '2012-12-31T16:00:00.000000000-0800',
            '12-31-2012 23:00:00-01:00'
        ]

        expected_output = tslib.array_to_datetime(np.array(
            ['01-01-2013 00:00:00'], dtype=object))

        for dt_string in dt_strings:
            tm.assert_numpy_array_equal(
                tslib.array_to_datetime(
                    np.array([dt_string], dtype=object)
                ),
                expected_output
            ) 
开发者ID:securityclippy,项目名称:elasticintel,代码行数:22,代码来源:test_tools.py

示例6: test_parsing_valid_dates

# 需要导入模块: from pandas._libs import tslib [as 别名]
# 或者: from pandas._libs.tslib import array_to_datetime [as 别名]
def test_parsing_valid_dates(data, expected):
    arr = np.array(data, dtype=object)
    result, _ = tslib.array_to_datetime(arr)

    expected = np_array_datetime64_compat(expected, dtype="M8[ns]")
    tm.assert_numpy_array_equal(result, expected) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:8,代码来源:test_array_to_datetime.py

示例7: test_parsing_timezone_offsets

# 需要导入模块: from pandas._libs import tslib [as 别名]
# 或者: from pandas._libs.tslib import array_to_datetime [as 别名]
def test_parsing_timezone_offsets(dt_string, expected_tz):
    # All of these datetime strings with offsets are equivalent
    # to the same datetime after the timezone offset is added.
    arr = np.array(["01-01-2013 00:00:00"], dtype=object)
    expected, _ = tslib.array_to_datetime(arr)

    arr = np.array([dt_string], dtype=object)
    result, result_tz = tslib.array_to_datetime(arr)

    tm.assert_numpy_array_equal(result, expected)
    assert result_tz is pytz.FixedOffset(expected_tz) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:13,代码来源:test_array_to_datetime.py

示例8: test_parsing_non_iso_timezone_offset

# 需要导入模块: from pandas._libs import tslib [as 别名]
# 或者: from pandas._libs.tslib import array_to_datetime [as 别名]
def test_parsing_non_iso_timezone_offset():
    dt_string = "01-01-2013T00:00:00.000000000+0000"
    arr = np.array([dt_string], dtype=object)

    result, result_tz = tslib.array_to_datetime(arr)
    expected = np.array([np.datetime64("2013-01-01 00:00:00.000000000")])

    tm.assert_numpy_array_equal(result, expected)
    assert result_tz is pytz.FixedOffset(0) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:11,代码来源:test_array_to_datetime.py

示例9: test_parsing_different_timezone_offsets

# 需要导入模块: from pandas._libs import tslib [as 别名]
# 或者: from pandas._libs.tslib import array_to_datetime [as 别名]
def test_parsing_different_timezone_offsets():
    # see gh-17697
    data = ["2015-11-18 15:30:00+05:30", "2015-11-18 15:30:00+06:30"]
    data = np.array(data, dtype=object)

    result, result_tz = tslib.array_to_datetime(data)
    expected = np.array([datetime(2015, 11, 18, 15, 30,
                                  tzinfo=tzoffset(None, 19800)),
                         datetime(2015, 11, 18, 15, 30,
                                  tzinfo=tzoffset(None, 23400))],
                        dtype=object)

    tm.assert_numpy_array_equal(result, expected)
    assert result_tz is None 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:16,代码来源:test_array_to_datetime.py

示例10: test_coerce_outside_ns_bounds

# 需要导入模块: from pandas._libs import tslib [as 别名]
# 或者: from pandas._libs.tslib import array_to_datetime [as 别名]
def test_coerce_outside_ns_bounds(invalid_date, errors):
    arr = np.array([invalid_date], dtype="object")
    kwargs = dict(values=arr, errors=errors)

    if errors == "raise":
        msg = "Out of bounds nanosecond timestamp"

        with pytest.raises(ValueError, match=msg):
            tslib.array_to_datetime(**kwargs)
    else:  # coerce.
        result, _ = tslib.array_to_datetime(**kwargs)
        expected = np.array([iNaT], dtype="M8[ns]")

        tm.assert_numpy_array_equal(result, expected) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:16,代码来源:test_array_to_datetime.py

示例11: test_coerce_outside_ns_bounds_one_valid

# 需要导入模块: from pandas._libs import tslib [as 别名]
# 或者: from pandas._libs.tslib import array_to_datetime [as 别名]
def test_coerce_outside_ns_bounds_one_valid():
    arr = np.array(["1/1/1000", "1/1/2000"], dtype=object)
    result, _ = tslib.array_to_datetime(arr, errors="coerce")

    expected = [iNaT, "2000-01-01T00:00:00.000000000-0000"]
    expected = np_array_datetime64_compat(expected, dtype="M8[ns]")

    tm.assert_numpy_array_equal(result, expected) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:10,代码来源:test_array_to_datetime.py

示例12: test_to_datetime_barely_out_of_bounds

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

示例13: test_parsing_timezone_offsets

# 需要导入模块: from pandas._libs import tslib [as 别名]
# 或者: from pandas._libs.tslib import array_to_datetime [as 别名]
def test_parsing_timezone_offsets(self, dt_string):
        # All of these datetime strings with offsets are equivalent
        # to the same datetime after the timezone offset is added
        arr = np.array(['01-01-2013 00:00:00'], dtype=object)
        expected = tslib.array_to_datetime(arr)

        arr = np.array([dt_string], dtype=object)
        result = tslib.array_to_datetime(arr)
        tm.assert_numpy_array_equal(result, expected) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:11,代码来源:test_array_to_datetime.py

示例14: test_number_looking_strings_not_into_datetime

# 需要导入模块: from pandas._libs import tslib [as 别名]
# 或者: from pandas._libs.tslib import array_to_datetime [as 别名]
def test_number_looking_strings_not_into_datetime(self):
        # GH#4601
        # These strings don't look like datetimes so they shouldn't be
        # attempted to be converted
        arr = np.array(['-352.737091', '183.575577'], dtype=object)
        result = tslib.array_to_datetime(arr, errors='ignore')
        tm.assert_numpy_array_equal(result, arr)

        arr = np.array(['1', '2', '3', '4', '5'], dtype=object)
        result = tslib.array_to_datetime(arr, errors='ignore')
        tm.assert_numpy_array_equal(result, arr) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:13,代码来源:test_array_to_datetime.py

示例15: test_coerce_outside_ns_bounds

# 需要导入模块: from pandas._libs import tslib [as 别名]
# 或者: from pandas._libs.tslib import array_to_datetime [as 别名]
def test_coerce_outside_ns_bounds(self, invalid_date):
        arr = np.array([invalid_date], dtype='object')
        with pytest.raises(ValueError):
            tslib.array_to_datetime(arr, errors='raise')

        result = tslib.array_to_datetime(arr, errors='coerce')
        expected = np.array([tslib.iNaT], dtype='M8[ns]')
        tm.assert_numpy_array_equal(result, expected) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:10,代码来源:test_array_to_datetime.py


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