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


Python ops._comp_method_OBJECT_ARRAY方法代碼示例

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


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

示例1: _make_comparison_op

# 需要導入模塊: from pandas.core import ops [as 別名]
# 或者: from pandas.core.ops import _comp_method_OBJECT_ARRAY [as 別名]
def _make_comparison_op(op, cls):
    def cmp_method(self, other):
        if isinstance(other, (np.ndarray, Index, ABCSeries)):
            if other.ndim > 0 and len(self) != len(other):
                raise ValueError('Lengths must match to compare')

        if is_object_dtype(self) and not isinstance(self, ABCMultiIndex):
            # don't pass MultiIndex
            with np.errstate(all='ignore'):
                result = ops._comp_method_OBJECT_ARRAY(op, self.values, other)

        else:

            # numpy will show a DeprecationWarning on invalid elementwise
            # comparisons, this will raise in the future
            with warnings.catch_warnings(record=True):
                warnings.filterwarnings("ignore", "elementwise", FutureWarning)
                with np.errstate(all='ignore'):
                    result = op(self.values, np.asarray(other))

        # technically we could support bool dtyped Index
        # for now just return the indexing array directly
        if is_bool_dtype(result):
            return result
        try:
            return Index(result)
        except TypeError:
            return result

    name = '__{name}__'.format(name=op.__name__)
    # TODO: docstring?
    return set_function_name(cmp_method, name, cls) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:34,代碼來源:base.py

示例2: _make_comparison_op

# 需要導入模塊: from pandas.core import ops [as 別名]
# 或者: from pandas.core.ops import _comp_method_OBJECT_ARRAY [as 別名]
def _make_comparison_op(op, cls):
    def cmp_method(self, other):
        if isinstance(other, (np.ndarray, Index, ABCSeries)):
            if other.ndim > 0 and len(self) != len(other):
                raise ValueError('Lengths must match to compare')

        # we may need to directly compare underlying
        # representations
        if needs_i8_conversion(self) and needs_i8_conversion(other):
            return self._evaluate_compare(other, op)

        from .multi import MultiIndex
        if is_object_dtype(self) and not isinstance(self, MultiIndex):
            # don't pass MultiIndex
            with np.errstate(all='ignore'):
                result = ops._comp_method_OBJECT_ARRAY(op, self.values, other)

        else:

            # numpy will show a DeprecationWarning on invalid elementwise
            # comparisons, this will raise in the future
            with warnings.catch_warnings(record=True):
                with np.errstate(all='ignore'):
                    result = op(self.values, np.asarray(other))

        # technically we could support bool dtyped Index
        # for now just return the indexing array directly
        if is_bool_dtype(result):
            return result
        try:
            return Index(result)
        except TypeError:
            return result

    name = '__{name}__'.format(name=op.__name__)
    # TODO: docstring?
    return set_function_name(cmp_method, name, cls) 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:39,代碼來源:base.py

示例3: _add_comparison_methods

# 需要導入模塊: from pandas.core import ops [as 別名]
# 或者: from pandas.core.ops import _comp_method_OBJECT_ARRAY [as 別名]
def _add_comparison_methods(cls):
        """ add in comparison methods """

        def _make_compare(op):
            def _evaluate_compare(self, other):
                if isinstance(other, (np.ndarray, Index, ABCSeries)):
                    if other.ndim > 0 and len(self) != len(other):
                        raise ValueError('Lengths must match to compare')

                # we may need to directly compare underlying
                # representations
                if needs_i8_conversion(self) and needs_i8_conversion(other):
                    return self._evaluate_compare(other, op)

                if (is_object_dtype(self) and
                        self.nlevels == 1):

                    # don't pass MultiIndex
                    with np.errstate(all='ignore'):
                        result = _comp_method_OBJECT_ARRAY(
                            op, self.values, other)
                else:
                    with np.errstate(all='ignore'):
                        result = op(self.values, np.asarray(other))

                # technically we could support bool dtyped Index
                # for now just return the indexing array directly
                if is_bool_dtype(result):
                    return result
                try:
                    return Index(result)
                except TypeError:
                    return result

            return _evaluate_compare

        cls.__eq__ = _make_compare(operator.eq)
        cls.__ne__ = _make_compare(operator.ne)
        cls.__lt__ = _make_compare(operator.lt)
        cls.__gt__ = _make_compare(operator.gt)
        cls.__le__ = _make_compare(operator.le)
        cls.__ge__ = _make_compare(operator.ge) 
開發者ID:nccgroup,項目名稱:Splunking-Crime,代碼行數:44,代碼來源:base.py


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