当前位置: 首页>>代码示例>>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;未经允许,请勿转载。