當前位置: 首頁>>代碼示例>>Python>>正文


Python lib.map_infer_mask方法代碼示例

本文整理匯總了Python中pandas._libs.lib.map_infer_mask方法的典型用法代碼示例。如果您正苦於以下問題:Python lib.map_infer_mask方法的具體用法?Python lib.map_infer_mask怎麽用?Python lib.map_infer_mask使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pandas._libs.lib的用法示例。


在下文中一共展示了lib.map_infer_mask方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _map

# 需要導入模塊: from pandas._libs import lib [as 別名]
# 或者: from pandas._libs.lib import map_infer_mask [as 別名]
def _map(f, arr, na_mask=False, na_value=np.nan, dtype=object):
    if not len(arr):
        return np.ndarray(0, dtype=dtype)

    if isinstance(arr, ABCSeries):
        arr = arr.values
    if not isinstance(arr, np.ndarray):
        arr = np.asarray(arr, dtype=object)
    if na_mask:
        mask = isna(arr)
        try:
            convert = not all(mask)
            result = lib.map_infer_mask(arr, f, mask.view(np.uint8), convert)
        except (TypeError, AttributeError) as e:
            # Reraise the exception if callable `f` got wrong number of args.
            # The user may want to be warned by this, instead of getting NaN
            if compat.PY2:
                p_err = r'takes (no|(exactly|at (least|most)) ?\d+) arguments?'
            else:
                p_err = (r'((takes)|(missing)) (?(2)from \d+ to )?\d+ '
                         r'(?(3)required )positional arguments?')

            if len(e.args) >= 1 and re.search(p_err, e.args[0]):
                raise e

            def g(x):
                try:
                    return f(x)
                except (TypeError, AttributeError):
                    return na_value

            return _map(g, arr, dtype=dtype)
        if na_value is not np.nan:
            np.putmask(result, mask, na_value)
            if result.dtype == object:
                result = lib.maybe_convert_objects(result)
        return result
    else:
        return lib.map_infer(arr, f) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:41,代碼來源:strings.py

示例2: _convert_to_ndarrays

# 需要導入模塊: from pandas._libs import lib [as 別名]
# 或者: from pandas._libs.lib import map_infer_mask [as 別名]
def _convert_to_ndarrays(self, dct, na_values, na_fvalues, verbose=False,
                             converters=None, dtypes=None):
        result = {}
        for c, values in compat.iteritems(dct):
            conv_f = None if converters is None else converters.get(c, None)
            if isinstance(dtypes, dict):
                cast_type = dtypes.get(c, None)
            else:
                # single dtype or None
                cast_type = dtypes

            if self.na_filter:
                col_na_values, col_na_fvalues = _get_na_values(
                    c, na_values, na_fvalues, self.keep_default_na)
            else:
                col_na_values, col_na_fvalues = set(), set()

            if conv_f is not None:
                # conv_f applied to data before inference
                if cast_type is not None:
                    warnings.warn(("Both a converter and dtype were specified "
                                   "for column {0} - only the converter will "
                                   "be used").format(c), ParserWarning,
                                  stacklevel=7)

                try:
                    values = lib.map_infer(values, conv_f)
                except ValueError:
                    mask = algorithms.isin(
                        values, list(na_values)).view(np.uint8)
                    values = lib.map_infer_mask(values, conv_f, mask)

                cvals, na_count = self._infer_types(
                    values, set(col_na_values) | col_na_fvalues,
                    try_num_bool=False)
            else:
                # skip inference if specified dtype is object
                try_num_bool = not (cast_type and is_string_dtype(cast_type))

                # general type inference and conversion
                cvals, na_count = self._infer_types(
                    values, set(col_na_values) | col_na_fvalues,
                    try_num_bool)

                # type specified in dtype param
                if cast_type and not is_dtype_equal(cvals, cast_type):
                    cvals = self._cast_types(cvals, cast_type, c)

            result[c] = cvals
            if verbose and na_count:
                print('Filled %d NA values in column %s' % (na_count, str(c)))
        return result 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:54,代碼來源:parsers.py

示例3: _convert_to_ndarrays

# 需要導入模塊: from pandas._libs import lib [as 別名]
# 或者: from pandas._libs.lib import map_infer_mask [as 別名]
def _convert_to_ndarrays(self, dct, na_values, na_fvalues, verbose=False,
                             converters=None, dtypes=None):
        result = {}
        for c, values in compat.iteritems(dct):
            conv_f = None if converters is None else converters.get(c, None)
            if isinstance(dtypes, dict):
                cast_type = dtypes.get(c, None)
            else:
                # single dtype or None
                cast_type = dtypes

            if self.na_filter:
                col_na_values, col_na_fvalues = _get_na_values(
                    c, na_values, na_fvalues)
            else:
                col_na_values, col_na_fvalues = set(), set()

            if conv_f is not None:
                # conv_f applied to data before inference
                if cast_type is not None:
                    warnings.warn(("Both a converter and dtype were specified "
                                   "for column {0} - only the converter will "
                                   "be used").format(c), ParserWarning,
                                  stacklevel=7)

                try:
                    values = lib.map_infer(values, conv_f)
                except ValueError:
                    mask = algorithms.isin(
                        values, list(na_values)).view(np.uint8)
                    values = lib.map_infer_mask(values, conv_f, mask)

                cvals, na_count = self._infer_types(
                    values, set(col_na_values) | col_na_fvalues,
                    try_num_bool=False)
            else:
                # skip inference if specified dtype is object
                try_num_bool = not (cast_type and is_string_dtype(cast_type))

                # general type inference and conversion
                cvals, na_count = self._infer_types(
                    values, set(col_na_values) | col_na_fvalues,
                    try_num_bool)

                # type specificed in dtype param
                if cast_type and not is_dtype_equal(cvals, cast_type):
                    cvals = self._cast_types(cvals, cast_type, c)

            if issubclass(cvals.dtype.type, np.integer) and self.compact_ints:
                cvals = lib.downcast_int64(
                    cvals, parsers.na_values,
                    self.use_unsigned)

            result[c] = cvals
            if verbose and na_count:
                print('Filled %d NA values in column %s' % (na_count, str(c)))
        return result 
開發者ID:nccgroup,項目名稱:Splunking-Crime,代碼行數:59,代碼來源:parsers.py


注:本文中的pandas._libs.lib.map_infer_mask方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。