当前位置: 首页>>代码示例>>Python>>正文


Python operator.ne方法代码示例

本文整理汇总了Python中operator.ne方法的典型用法代码示例。如果您正苦于以下问题:Python operator.ne方法的具体用法?Python operator.ne怎么用?Python operator.ne使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在operator的用法示例。


在下文中一共展示了operator.ne方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_richcompare_crash

# 需要导入模块: import operator [as 别名]
# 或者: from operator import ne [as 别名]
def test_richcompare_crash(self):
        # gh-4613
        import operator as op

        # dummy class where __array__ throws exception
        class Foo(object):
            __array_priority__ = 1002

            def __array__(self, *args, **kwargs):
                raise Exception()

        rhs = Foo()
        lhs = np.array(1)
        for f in [op.lt, op.le, op.gt, op.ge]:
            if sys.version_info[0] >= 3:
                assert_raises(TypeError, f, lhs, rhs)
            elif not sys.py3kwarning:
                # With -3 switch in python 2, DeprecationWarning is raised
                # which we are not interested in
                f(lhs, rhs)
        assert_(not op.eq(lhs, rhs))
        assert_(op.ne(lhs, rhs)) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:24,代码来源:test_regression.py

示例2: test_compare_frame

# 需要导入模块: import operator [as 别名]
# 或者: from operator import ne [as 别名]
def test_compare_frame(self):
        # GH#24282 check that Categorical.__cmp__(DataFrame) defers to frame
        data = ["a", "b", 2, "a"]
        cat = Categorical(data)

        df = DataFrame(cat)

        for op in [operator.eq, operator.ne, operator.ge,
                   operator.gt, operator.le, operator.lt]:
            with pytest.raises(ValueError):
                # alignment raises unless we transpose
                op(cat, df)

        result = cat == df.T
        expected = DataFrame([[True, True, True, True]])
        tm.assert_frame_equal(result, expected)

        result = cat[::-1] != df.T
        expected = DataFrame([[False, True, True, False]])
        tm.assert_frame_equal(result, expected) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:22,代码来源:test_operators.py

示例3: xorLst

# 需要导入模块: import operator [as 别名]
# 或者: from operator import ne [as 别名]
def xorLst(lst):
    """
    Essentially does what any() and all() do for OR and AND, except for XOR now

    :param lst: A list of booleans
    :type lst: list
    :rtype: bool
    """
    if len(lst) > 1:
        res = lst[0] ^ lst[1]
        lst = lst[2:]
        for b in lst:
            res ^= b
    elif len(lst) == 1:
        res = lst[0]
    else:
        res = False
    return res


# The following functions are made to get around the fact that lambdas and builtin functions on str like str.endswith
# are not pickleable. Operator functions like operator.ne are pickleable though...weird. 
开发者ID:NSchrading,项目名称:redditDataExtractor,代码行数:24,代码来源:redditDataExtractor.py

示例4: get_op

# 需要导入模块: import operator [as 别名]
# 或者: from operator import ne [as 别名]
def get_op(cls, op):
        ops = {
            symbol.test: cls.test,
            symbol.and_test: cls.and_test,
            symbol.atom: cls.atom,
            symbol.comparison: cls.comparison,
            'not in': lambda x, y: x not in y,
            'in': lambda x, y: x in y,
            '==': operator.eq,
            '!=': operator.ne,
            '<':  operator.lt,
            '>':  operator.gt,
            '<=': operator.le,
            '>=': operator.ge,
        }
        if hasattr(symbol, 'or_test'):
            ops[symbol.or_test] = cls.test
        return ops[op] 
开发者ID:jpush,项目名称:jbox,代码行数:20,代码来源:__init__.py

示例5: test_values

# 需要导入模块: import operator [as 别名]
# 或者: from operator import ne [as 别名]
def test_values(self):
        # check all operators and all comparison results
        self.checkvalue("lt", 0, 0, False)
        self.checkvalue("le", 0, 0, True )
        self.checkvalue("eq", 0, 0, True )
        self.checkvalue("ne", 0, 0, False)
        self.checkvalue("gt", 0, 0, False)
        self.checkvalue("ge", 0, 0, True )

        self.checkvalue("lt", 0, 1, True )
        self.checkvalue("le", 0, 1, True )
        self.checkvalue("eq", 0, 1, False)
        self.checkvalue("ne", 0, 1, True )
        self.checkvalue("gt", 0, 1, False)
        self.checkvalue("ge", 0, 1, False)

        self.checkvalue("lt", 1, 0, False)
        self.checkvalue("le", 1, 0, False)
        self.checkvalue("eq", 1, 0, False)
        self.checkvalue("ne", 1, 0, True )
        self.checkvalue("gt", 1, 0, True )
        self.checkvalue("ge", 1, 0, True ) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:24,代码来源:test_richcmp.py

示例6: test_richcompare_crash

# 需要导入模块: import operator [as 别名]
# 或者: from operator import ne [as 别名]
def test_richcompare_crash(self):
        # gh-4613
        import operator as op

        # dummy class where __array__ throws exception
        class Foo(object):
            __array_priority__ = 1002

            def __array__(self,*args,**kwargs):
                raise Exception()

        rhs = Foo()
        lhs = np.array(1)
        for f in [op.lt, op.le, op.gt, op.ge]:
            if sys.version_info[0] >= 3:
                assert_raises(TypeError, f, lhs, rhs)
            else:
                f(lhs, rhs)
        assert_(not op.eq(lhs, rhs))
        assert_(op.ne(lhs, rhs)) 
开发者ID:abhisuri97,项目名称:auto-alt-text-lambda-api,代码行数:22,代码来源:test_regression.py

示例7: op

# 需要导入模块: import operator [as 别名]
# 或者: from operator import ne [as 别名]
def op(operation, column):
    if operation == 'in':
        def comparator(column, v):
            return column.in_(v)
    elif operation == 'like':
        def comparator(column, v):
            return column.like(v + '%')
    elif operation == 'eq':
        comparator = _operator.eq
    elif operation == 'ne':
        comparator = _operator.ne
    elif operation == 'le':
        comparator = _operator.le
    elif operation == 'lt':
        comparator = _operator.lt
    elif operation == 'ge':
        comparator = _operator.ge
    elif operation == 'gt':
        comparator = _operator.gt
    else:
        raise ValueError('Operation {} not supported'.format(operation))
    return comparator


# TODO: fix comparators, keys should be something better 
开发者ID:aio-libs,项目名称:aiohttp_admin,代码行数:27,代码来源:sa_utils.py

示例8: not_null

# 需要导入模块: import operator [as 别名]
# 或者: from operator import ne [as 别名]
def not_null(self, variable):
        """Validate that a variable is not empty/null"""
        # Could do something like self.ne(variable, None), but want to be pretty specific on
        # the errors on this one
        variable_data = self.provider.tcex.playbook.read(variable)
        self.log.data('validate', 'Variable', variable)
        self.log.data('validate', 'DB Data', variable_data)
        if not variable:
            self.log.data(
                'validate', 'None Error', f'Redis variable not provided', 'error',
            )
            return False

        if not variable_data:
            self.log.data(
                'validate', 'None Found', f'Redis variable {variable} was not found', 'error',
            )
            return False

        return True 
开发者ID:ThreatConnect-Inc,项目名称:tcex,代码行数:22,代码来源:validate_data.py

示例9: test_timestamp_compare

# 需要导入模块: import operator [as 别名]
# 或者: from operator import ne [as 别名]
def test_timestamp_compare(self):
        # make sure we can compare Timestamps on the right AND left hand side
        # GH4982
        df = DataFrame({'dates1': date_range('20010101', periods=10),
                        'dates2': date_range('20010102', periods=10),
                        'intcol': np.random.randint(1000000000, size=10),
                        'floatcol': np.random.randn(10),
                        'stringcol': list(tm.rands(10))})
        df.loc[np.random.rand(len(df)) > 0.5, 'dates2'] = pd.NaT
        ops = {'gt': 'lt', 'lt': 'gt', 'ge': 'le', 'le': 'ge', 'eq': 'eq',
               'ne': 'ne'}

        for left, right in ops.items():
            left_f = getattr(operator, left)
            right_f = getattr(operator, right)

            # no nats
            expected = left_f(df, Timestamp('20010109'))
            result = right_f(Timestamp('20010109'), df)
            assert_frame_equal(result, expected)

            # nats
            expected = left_f(df, Timestamp('nat'))
            result = right_f(Timestamp('nat'), df)
            assert_frame_equal(result, expected) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:27,代码来源:test_operators.py

示例10: _rules_pass

# 需要导入模块: import operator [as 别名]
# 或者: from operator import ne [as 别名]
def _rules_pass(obj, rules, compare=operator.eq):

    for key, expected_value in rules.items():

        if isinstance(expected_value, dict):

            if key.endswith('NotEqual'):
                nested_compare = operator.ne
                key = key[:-len('NotEqual')]
            else:
                nested_compare = compare

            nested_rules_passed = _rules_pass(
                obj=obj.get(key) or {},
                rules=expected_value,
                compare=nested_compare,
            )
            if not nested_rules_passed:
                return False

        elif not compare(obj.get(key), expected_value):
            return False

    return True 
开发者ID:claranet,项目名称:ssha,代码行数:26,代码来源:ec2.py

示例11: _evaluate_operator

# 需要导入模块: import operator [as 别名]
# 或者: from operator import ne [as 别名]
def _evaluate_operator(result, operation=None, value=None):
    # used to evaluate the operation results

    # if number 6 operations 
    if isinstance(value, (float, int)) and isinstance(result, (float, int)):
        dict_of_ops = {'==': operator.eq, '>=':operator.ge,
         '>': operator.gt, '<=':operator.le, '<':operator.le,
         '!=':operator.ne}
    elif isinstance(result, (float, int)) and isinstance(value, range):

        # just check if the first argument is within the second argument,
        # changing the operands order of contains function (in)
        dict_of_ops = {'within': lambda item, container: item in container}
    elif isinstance(result, str) and isinstance(value, str):
        # if strings just check equal or not equal or inclusion
        dict_of_ops = {'==': operator.eq, '!=':operator.ne, 'in': operator.contains}
    else:
        # if any other type return error
        return False

    # if the operation is not valid errors the testcase
    if not operation in dict_of_ops.keys():
        raise Exception('Operator {} is not supported'.format(operation))
    
    return dict_of_ops[operation](result, value) 
开发者ID:CiscoTestAutomation,项目名称:genielibs,代码行数:27,代码来源:actions_helper.py

示例12: _filter_checks

# 需要导入模块: import operator [as 别名]
# 或者: from operator import ne [as 别名]
def _filter_checks(checks, type=None, context=None, inverse=False):
    result = []
    comparator = operator.eq if inverse else operator.ne
    for check in checks:
        if type and comparator(check['type'], type):
            continue
        if context and comparator(check['context'], context):
            continue
        result.append(check)
    return result 
开发者ID:frictionlessdata,项目名称:goodtables-py,代码行数:12,代码来源:inspector.py

示例13: testNe

# 需要导入模块: import operator [as 别名]
# 或者: from operator import ne [as 别名]
def testNe(self):
        self.comparisonCheck(operator.ne) 
开发者ID:myhdl,项目名称:myhdl,代码行数:4,代码来源:test_Signal.py

示例14: __ne__

# 需要导入模块: import operator [as 别名]
# 或者: from operator import ne [as 别名]
def __ne__(self, other: Union['Quantity', float, int]) -> bool:
        return Quantity._bool_operation(self, other, operator.ne) 
开发者ID:tensortrade-org,项目名称:tensortrade,代码行数:4,代码来源:quantity.py

示例15: _compare

# 需要导入模块: import operator [as 别名]
# 或者: from operator import ne [as 别名]
def _compare(self, op, other):
        if isinstance(other, SplitKey):
            if self.sampling != other.sampling:
                if op == operator.eq:
                    return False
                if op == operator.ne:
                    return True
                raise TypeError(
                    "Cannot compare %s with different sampling" %
                    self.__class__.__name__)
            return op(self.key, other.key)
        if isinstance(other, numpy.datetime64):
            return op(self.key, other)
        raise TypeError("Cannot compare %r with %r" % (self, other)) 
开发者ID:gnocchixyz,项目名称:gnocchi,代码行数:16,代码来源:carbonara.py


注:本文中的operator.ne方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。