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