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


Python lib.values_from_object方法代碼示例

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


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

示例1: _addsub_offset_array

# 需要導入模塊: from pandas._libs import lib [as 別名]
# 或者: from pandas._libs.lib import values_from_object [as 別名]
def _addsub_offset_array(self, other, op):
        """
        Add or subtract array-like of DateOffset objects

        Parameters
        ----------
        other : Index, np.ndarray
            object-dtype containing pd.DateOffset objects
        op : {operator.add, operator.sub}

        Returns
        -------
        result : same class as self
        """
        assert op in [operator.add, operator.sub]
        if len(other) == 1:
            return op(self, other[0])

        warnings.warn("Adding/subtracting array of DateOffsets to "
                      "{cls} not vectorized"
                      .format(cls=type(self).__name__), PerformanceWarning)

        # For EA self.astype('O') returns a numpy array, not an Index
        left = lib.values_from_object(self.astype('O'))

        res_values = op(left, np.array(other))
        kwargs = {}
        if not is_period_dtype(self):
            kwargs['freq'] = 'infer'
        return self._from_sequence(res_values, **kwargs) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:32,代碼來源:datetimelike.py

示例2: remove_na_arraylike

# 需要導入模塊: from pandas._libs import lib [as 別名]
# 或者: from pandas._libs.lib import values_from_object [as 別名]
def remove_na_arraylike(arr):
    """
    Return array-like containing only true/non-NaN values, possibly empty.
    """
    if is_extension_array_dtype(arr):
        return arr[notna(arr)]
    else:
        return arr[notna(lib.values_from_object(arr))] 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:10,代碼來源:missing.py

示例3: remove_na_arraylike

# 需要導入模塊: from pandas._libs import lib [as 別名]
# 或者: from pandas._libs.lib import values_from_object [as 別名]
def remove_na_arraylike(arr):
    """
    Return array-like containing only true/non-NaN values, possibly empty.
    """
    return arr[notna(lib.values_from_object(arr))] 
開發者ID:nccgroup,項目名稱:Splunking-Crime,代碼行數:7,代碼來源:missing.py

示例4: is_bool_indexer

# 需要導入模塊: from pandas._libs import lib [as 別名]
# 或者: from pandas._libs.lib import values_from_object [as 別名]
def is_bool_indexer(key):
    # type: (Any) -> bool
    """
    Check whether `key` is a valid boolean indexer.

    Parameters
    ----------
    key : Any
        Only list-likes may be considered boolean indexers.
        All other types are not considered a boolean indexer.
        For array-like input, boolean ndarrays or ExtensionArrays
        with ``_is_boolean`` set are considered boolean indexers.

    Returns
    -------
    bool

    Raises
    ------
    ValueError
        When the array is an object-dtype ndarray or ExtensionArray
        and contains missing values.
    """
    na_msg = 'cannot index with vector containing NA / NaN values'
    if (isinstance(key, (ABCSeries, np.ndarray, ABCIndex)) or
            (is_array_like(key) and is_extension_array_dtype(key.dtype))):
        if key.dtype == np.object_:
            key = np.asarray(values_from_object(key))

            if not lib.is_bool_array(key):
                if isna(key).any():
                    raise ValueError(na_msg)
                return False
            return True
        elif is_bool_dtype(key.dtype):
            # an ndarray with bool-dtype by definition has no missing values.
            # So we only need to check for NAs in ExtensionArrays
            if is_extension_array_dtype(key.dtype):
                if np.any(key.isna()):
                    raise ValueError(na_msg)
            return True
    elif isinstance(key, list):
        try:
            arr = np.asarray(key)
            return arr.dtype == np.bool_ and len(arr) == len(key)
        except TypeError:  # pragma: no cover
            return False

    return False 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:51,代碼來源:common.py


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