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


Python lib.maybe_convert_numeric方法代码示例

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


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

示例1: test_maybe_convert_numeric_infinities

# 需要导入模块: from pandas._libs import lib [as 别名]
# 或者: from pandas._libs.lib import maybe_convert_numeric [as 别名]
def test_maybe_convert_numeric_infinities(self):
        # see gh-13274
        infinities = ['inf', 'inF', 'iNf', 'Inf',
                      'iNF', 'InF', 'INf', 'INF']
        na_values = {'', 'NULL', 'nan'}

        pos = np.array(['inf'], dtype=np.float64)
        neg = np.array(['-inf'], dtype=np.float64)

        msg = "Unable to parse string"

        for infinity in infinities:
            for maybe_int in (True, False):
                out = lib.maybe_convert_numeric(
                    np.array([infinity], dtype=object),
                    na_values, maybe_int)
                tm.assert_numpy_array_equal(out, pos)

                out = lib.maybe_convert_numeric(
                    np.array(['-' + infinity], dtype=object),
                    na_values, maybe_int)
                tm.assert_numpy_array_equal(out, neg)

                out = lib.maybe_convert_numeric(
                    np.array([u(infinity)], dtype=object),
                    na_values, maybe_int)
                tm.assert_numpy_array_equal(out, pos)

                out = lib.maybe_convert_numeric(
                    np.array(['+' + infinity], dtype=object),
                    na_values, maybe_int)
                tm.assert_numpy_array_equal(out, pos)

                # too many characters
                with pytest.raises(ValueError, match=msg):
                    lib.maybe_convert_numeric(
                        np.array(['foo_' + infinity], dtype=object),
                        na_values, maybe_int) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:40,代码来源:test_inference.py

示例2: test_maybe_convert_numeric_post_floatify_nan

# 需要导入模块: from pandas._libs import lib [as 别名]
# 或者: from pandas._libs.lib import maybe_convert_numeric [as 别名]
def test_maybe_convert_numeric_post_floatify_nan(self, coerce):
        # see gh-13314
        data = np.array(['1.200', '-999.000', '4.500'], dtype=object)
        expected = np.array([1.2, np.nan, 4.5], dtype=np.float64)
        nan_values = {-999, -999.0}

        out = lib.maybe_convert_numeric(data, nan_values, coerce)
        tm.assert_numpy_array_equal(out, expected) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:10,代码来源:test_inference.py

示例3: test_convert_infs

# 需要导入模块: from pandas._libs import lib [as 别名]
# 或者: from pandas._libs.lib import maybe_convert_numeric [as 别名]
def test_convert_infs(self):
        arr = np.array(['inf', 'inf', 'inf'], dtype='O')
        result = lib.maybe_convert_numeric(arr, set(), False)
        assert result.dtype == np.float64

        arr = np.array(['-inf', '-inf', '-inf'], dtype='O')
        result = lib.maybe_convert_numeric(arr, set(), False)
        assert result.dtype == np.float64 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:10,代码来源:test_inference.py

示例4: test_scientific_no_exponent

# 需要导入模块: from pandas._libs import lib [as 别名]
# 或者: from pandas._libs.lib import maybe_convert_numeric [as 别名]
def test_scientific_no_exponent(self):
        # See PR 12215
        arr = np.array(['42E', '2E', '99e', '6e'], dtype='O')
        result = lib.maybe_convert_numeric(arr, set(), False, True)
        assert np.all(np.isnan(result)) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:7,代码来源:test_inference.py

示例5: test_convert_non_hashable

# 需要导入模块: from pandas._libs import lib [as 别名]
# 或者: from pandas._libs.lib import maybe_convert_numeric [as 别名]
def test_convert_non_hashable(self):
        # GH13324
        # make sure that we are handing non-hashables
        arr = np.array([[10.0, 2], 1.0, 'apple'])
        result = lib.maybe_convert_numeric(arr, set(), False, True)
        tm.assert_numpy_array_equal(result, np.array([np.nan, 1.0, np.nan])) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:8,代码来源:test_inference.py

示例6: test_convert_numeric_uint64_nan

# 需要导入模块: from pandas._libs import lib [as 别名]
# 或者: from pandas._libs.lib import maybe_convert_numeric [as 别名]
def test_convert_numeric_uint64_nan(self, coerce, arr):
        expected = arr.astype(float) if coerce else arr.copy()
        result = lib.maybe_convert_numeric(arr, set(),
                                           coerce_numeric=coerce)
        tm.assert_almost_equal(result, expected) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:7,代码来源:test_inference.py

示例7: test_convert_numeric_uint64_nan_values

# 需要导入模块: from pandas._libs import lib [as 别名]
# 或者: from pandas._libs.lib import maybe_convert_numeric [as 别名]
def test_convert_numeric_uint64_nan_values(self, coerce):
        arr = np.array([2**63, 2**63 + 1], dtype=object)
        na_values = {2**63}

        expected = (np.array([np.nan, 2**63 + 1], dtype=float)
                    if coerce else arr.copy())
        result = lib.maybe_convert_numeric(arr, na_values,
                                           coerce_numeric=coerce)
        tm.assert_almost_equal(result, expected) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:11,代码来源:test_inference.py

示例8: test_convert_numeric_int64_uint64

# 需要导入模块: from pandas._libs import lib [as 别名]
# 或者: from pandas._libs.lib import maybe_convert_numeric [as 别名]
def test_convert_numeric_int64_uint64(self, case, coerce):
        expected = case.astype(float) if coerce else case.copy()
        result = lib.maybe_convert_numeric(case, set(), coerce_numeric=coerce)
        tm.assert_almost_equal(result, expected) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:6,代码来源:test_inference.py

示例9: test_maybe_convert_numeric_infinities

# 需要导入模块: from pandas._libs import lib [as 别名]
# 或者: from pandas._libs.lib import maybe_convert_numeric [as 别名]
def test_maybe_convert_numeric_infinities(self):
        # see gh-13274
        infinities = ['inf', 'inF', 'iNf', 'Inf',
                      'iNF', 'InF', 'INf', 'INF']
        na_values = set(['', 'NULL', 'nan'])

        pos = np.array(['inf'], dtype=np.float64)
        neg = np.array(['-inf'], dtype=np.float64)

        msg = "Unable to parse string"

        for infinity in infinities:
            for maybe_int in (True, False):
                out = lib.maybe_convert_numeric(
                    np.array([infinity], dtype=object),
                    na_values, maybe_int)
                tm.assert_numpy_array_equal(out, pos)

                out = lib.maybe_convert_numeric(
                    np.array(['-' + infinity], dtype=object),
                    na_values, maybe_int)
                tm.assert_numpy_array_equal(out, neg)

                out = lib.maybe_convert_numeric(
                    np.array([u(infinity)], dtype=object),
                    na_values, maybe_int)
                tm.assert_numpy_array_equal(out, pos)

                out = lib.maybe_convert_numeric(
                    np.array(['+' + infinity], dtype=object),
                    na_values, maybe_int)
                tm.assert_numpy_array_equal(out, pos)

                # too many characters
                with tm.assert_raises_regex(ValueError, msg):
                    lib.maybe_convert_numeric(
                        np.array(['foo_' + infinity], dtype=object),
                        na_values, maybe_int) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:40,代码来源:test_inference.py

示例10: test_maybe_convert_numeric_post_floatify_nan

# 需要导入模块: from pandas._libs import lib [as 别名]
# 或者: from pandas._libs.lib import maybe_convert_numeric [as 别名]
def test_maybe_convert_numeric_post_floatify_nan(self, coerce):
        # see gh-13314
        data = np.array(['1.200', '-999.000', '4.500'], dtype=object)
        expected = np.array([1.2, np.nan, 4.5], dtype=np.float64)
        nan_values = set([-999, -999.0])

        out = lib.maybe_convert_numeric(data, nan_values, coerce)
        tm.assert_numpy_array_equal(out, expected) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:10,代码来源:test_inference.py

示例11: test_convert_numeric_uint64_nan_values

# 需要导入模块: from pandas._libs import lib [as 别名]
# 或者: from pandas._libs.lib import maybe_convert_numeric [as 别名]
def test_convert_numeric_uint64_nan_values(self, coerce):
        arr = np.array([2**63, 2**63 + 1], dtype=object)
        na_values = set([2**63])

        expected = (np.array([np.nan, 2**63 + 1], dtype=float)
                    if coerce else arr.copy())
        result = lib.maybe_convert_numeric(arr, na_values,
                                           coerce_numeric=coerce)
        tm.assert_almost_equal(result, expected) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:11,代码来源:test_inference.py

示例12: test_maybe_convert_numeric_post_floatify_nan

# 需要导入模块: from pandas._libs import lib [as 别名]
# 或者: from pandas._libs.lib import maybe_convert_numeric [as 别名]
def test_maybe_convert_numeric_post_floatify_nan(self):
        # see gh-13314
        data = np.array(['1.200', '-999.000', '4.500'], dtype=object)
        expected = np.array([1.2, np.nan, 4.5], dtype=np.float64)
        nan_values = set([-999, -999.0])

        for coerce_type in (True, False):
            out = lib.maybe_convert_numeric(data, nan_values, coerce_type)
            tm.assert_numpy_array_equal(out, expected) 
开发者ID:securityclippy,项目名称:elasticintel,代码行数:11,代码来源:test_inference.py


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