Python operator.invert() Examples

The following are 30 code examples of operator.invert(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module operator , or try the search function .
Example #1
Source File: test_series.py    From recruit with Apache License 2.0 6 votes vote down vote up
def test_unary_operators(self, values, op, fill_value):
        # https://github.com/pandas-dev/pandas/issues/22835
        values = np.asarray(values)
        if op is operator.invert:
            new_fill_value = not fill_value
        else:
            new_fill_value = op(fill_value)
        s = SparseSeries(values,
                         fill_value=fill_value,
                         index=['a', 'b', 'c', 'd'],
                         name='name')
        result = op(s)
        expected = SparseSeries(op(values),
                                fill_value=new_fill_value,
                                index=['a', 'b', 'c', 'd'],
                                name='name')
        tm.assert_sp_series_equal(result, expected) 
Example #2
Source File: test_series.py    From coffeegrindsize with MIT License 6 votes vote down vote up
def test_unary_operators(self, values, op, fill_value):
        # https://github.com/pandas-dev/pandas/issues/22835
        values = np.asarray(values)
        if op is operator.invert:
            new_fill_value = not fill_value
        else:
            new_fill_value = op(fill_value)
        s = SparseSeries(values,
                         fill_value=fill_value,
                         index=['a', 'b', 'c', 'd'],
                         name='name')
        result = op(s)
        expected = SparseSeries(op(values),
                                fill_value=new_fill_value,
                                index=['a', 'b', 'c', 'd'],
                                name='name')
        tm.assert_sp_series_equal(result, expected) 
Example #3
Source File: elastic_grammar_query.py    From texta with GNU General Public License v3.0 6 votes vote down vote up
def _build_logical_expression(self, grammar, terminal_component_names):
        terminal_component_symbols = eval("symbols('%s')"%(' '.join(terminal_component_names)))
        if isinstance(terminal_component_symbols, Symbol):
            terminal_component_symbols = [terminal_component_symbols]
        name_to_symbol = {terminal_component_names[i]:symbol for i, symbol in enumerate(terminal_component_symbols)}
        terminal_component_names = set(terminal_component_names)

        op_to_symbolic_operation = {'not':operator.invert, 'concat':operator.and_, 'gap':operator.and_, 'union':operator.or_, 'intersect':operator.and_}

        def logical_expression_builder(component):
            if component['id'] in terminal_component_names:
                return name_to_symbol[component['id']]
            else:
                children = component['components']
                return reduce(op_to_symbolic_operation[component['operation']],[logical_expression_builder(child) for child in children])

        return simplify(logical_expression_builder(grammar)) 
Example #4
Source File: test_series.py    From predictive-maintenance-using-machine-learning with Apache License 2.0 6 votes vote down vote up
def test_unary_operators(self, values, op, fill_value):
        # https://github.com/pandas-dev/pandas/issues/22835
        values = np.asarray(values)
        if op is operator.invert:
            new_fill_value = not fill_value
        else:
            new_fill_value = op(fill_value)
        s = SparseSeries(values,
                         fill_value=fill_value,
                         index=['a', 'b', 'c', 'd'],
                         name='name')
        result = op(s)
        expected = SparseSeries(op(values),
                                fill_value=new_fill_value,
                                index=['a', 'b', 'c', 'd'],
                                name='name')
        tm.assert_sp_series_equal(result, expected) 
Example #5
Source File: test_util.py    From luci-py with Apache License 2.0 5 votes vote down vote up
def __invert__(self):
    return NonStandardInteger(operator.invert(self.val)) 
Example #6
Source File: core_test.py    From keras-lambda with MIT License 5 votes vote down vote up
def setUp(self):
    super(LogicalNotTest, self).setUp()
    self.ops = [('logical_not', operator.invert, math_ops.logical_not,
                 core.logical_not),]
    self.test_lt = self.original_lt < 10 
Example #7
Source File: test_util.py    From luci-py with Apache License 2.0 5 votes vote down vote up
def __invert__(self):
    return NonStandardInteger(operator.invert(self.val)) 
Example #8
Source File: test_operator.py    From gcblue with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_invert(self):
        self.assertRaises(TypeError, operator.invert)
        self.assertRaises(TypeError, operator.invert, None)
        self.assertTrue(operator.inv(4) == -5) 
Example #9
Source File: test_number.py    From hpy with MIT License 5 votes vote down vote up
def test_unary(self):
        import pytest
        import operator
        for c_name, op in [
                ('Negative', operator.neg),
                ('Positive', operator.pos),
                ('Absolute', abs),
                ('Invert', operator.invert),
                ('Index', operator.index),
                ('Long', int),
                ('Float', float),
                ]:
            mod = self.make_module("""
                HPyDef_METH(f, "f", f_impl, HPyFunc_O)
                static HPy f_impl(HPyContext ctx, HPy self, HPy arg)
                {
                    return HPy_%s(ctx, arg);
                }
                @EXPORT(f)
                @INIT
            """ % (c_name,), name='number_'+c_name)
            assert mod.f(-5) == op(-5)
            assert mod.f(6) == op(6)
            try:
                res = op(4.75)
            except Exception as e:
                with pytest.raises(e.__class__):
                    mod.f(4.75)
            else:
                assert mod.f(4.75) == res 
Example #10
Source File: expr.py    From owasp-pysec with Apache License 2.0 5 votes vote down vote up
def __invert__(self):
        return Expression((self,), operator.invert) 
Example #11
Source File: expr.py    From owasp-pysec with Apache License 2.0 5 votes vote down vote up
def __inv__(self):
        return Expression((self,), operator.invert) 
Example #12
Source File: test_operator.py    From medicare-demo with Apache License 2.0 5 votes vote down vote up
def test_invert(self):
        self.failUnlessRaises(TypeError, operator.invert)
        self.failUnlessRaises(TypeError, operator.invert, None)
        self.failUnless(operator.inv(4) == -5) 
Example #13
Source File: test_mixins.py    From elasticintel with GNU General Public License v3.0 5 votes vote down vote up
def test_unary_methods(self):
        array = np.array([-1, 0, 1, 2])
        array_like = ArrayLike(array)
        for op in [operator.neg,
                   operator.pos,
                   abs,
                   operator.invert]:
            _assert_equal_type_and_value(op(array_like), ArrayLike(op(array))) 
Example #14
Source File: test_operator.py    From CTFCrackTools-V2 with GNU General Public License v3.0 5 votes vote down vote up
def test_invert(self):
        self.failUnlessRaises(TypeError, operator.invert)
        self.failUnlessRaises(TypeError, operator.invert, None)
        self.failUnless(operator.inv(4) == -5) 
Example #15
Source File: TLorentzVector.py    From uproot-methods with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def __invert__(self):
        return self._unary(operator.invert) 
Example #16
Source File: TVector.py    From uproot-methods with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def __invert__(self):
        return self._unary(operator.invert) 
Example #17
Source File: test_mixins.py    From coffeegrindsize with MIT License 5 votes vote down vote up
def test_unary_methods(self):
        array = np.array([-1, 0, 1, 2])
        array_like = ArrayLike(array)
        for op in [operator.neg,
                   operator.pos,
                   abs,
                   operator.invert]:
            _assert_equal_type_and_value(op(array_like), ArrayLike(op(array))) 
Example #18
Source File: nodes.py    From hyper-engine with Apache License 2.0 5 votes vote down vote up
def __invert__(self):  return _op1(self, operator.invert) 
Example #19
Source File: block.py    From capytaine with GNU General Public License v3.0 5 votes vote down vote up
def __invert__(self) -> 'BlockMatrix':
        """Boolean not (~)"""
        from operator import invert
        return self._apply_unary_op(invert) 
Example #20
Source File: test_mixins.py    From Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda with MIT License 5 votes vote down vote up
def test_unary_methods(self):
        array = np.array([-1, 0, 1, 2])
        array_like = ArrayLike(array)
        for op in [operator.neg,
                   operator.pos,
                   abs,
                   operator.invert]:
            _assert_equal_type_and_value(op(array_like), ArrayLike(op(array))) 
Example #21
Source File: test_util.py    From Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda with MIT License 5 votes vote down vote up
def __invert__(self):
    return NonStandardInteger(operator.invert(self.val)) 
Example #22
Source File: test_operator.py    From CTFCrackTools with GNU General Public License v3.0 5 votes vote down vote up
def test_invert(self):
        self.failUnlessRaises(TypeError, operator.invert)
        self.failUnlessRaises(TypeError, operator.invert, None)
        self.failUnless(operator.inv(4) == -5) 
Example #23
Source File: test_mixins.py    From twitter-stock-recommendation with MIT License 5 votes vote down vote up
def test_unary_methods(self):
        array = np.array([-1, 0, 1, 2])
        array_like = ArrayLike(array)
        for op in [operator.neg,
                   operator.pos,
                   abs,
                   operator.invert]:
            _assert_equal_type_and_value(op(array_like), ArrayLike(op(array))) 
Example #24
Source File: test_mixins.py    From recruit with Apache License 2.0 5 votes vote down vote up
def test_unary_methods(self):
        array = np.array([-1, 0, 1, 2])
        array_like = ArrayLike(array)
        for op in [operator.neg,
                   operator.pos,
                   abs,
                   operator.invert]:
            _assert_equal_type_and_value(op(array_like), ArrayLike(op(array))) 
Example #25
Source File: test_mixins.py    From predictive-maintenance-using-machine-learning with Apache License 2.0 5 votes vote down vote up
def test_unary_methods(self):
        array = np.array([-1, 0, 1, 2])
        array_like = ArrayLike(array)
        for op in [operator.neg,
                   operator.pos,
                   abs,
                   operator.invert]:
            _assert_equal_type_and_value(op(array_like), ArrayLike(op(array))) 
Example #26
Source File: sparse.py    From recruit with Apache License 2.0 5 votes vote down vote up
def _add_unary_ops(cls):
        cls.__pos__ = cls._create_unary_method(operator.pos)
        cls.__neg__ = cls._create_unary_method(operator.neg)
        cls.__invert__ = cls._create_unary_method(operator.invert) 
Example #27
Source File: test_util.py    From lambda-packs with MIT License 5 votes vote down vote up
def __invert__(self):
    return NonStandardInteger(operator.invert(self.val)) 
Example #28
Source File: test_operator.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def test_invert(self):
        self.assertRaises(TypeError, operator.invert)
        self.assertRaises(TypeError, operator.invert, None)
        self.assertTrue(operator.inv(4) == -5) 
Example #29
Source File: core_test.py    From auto-alt-text-lambda-api with MIT License 5 votes vote down vote up
def setUp(self):
    super(LogicalNotTest, self).setUp()
    self.ops = [('logical_not', operator.invert, math_ops.logical_not,
                 core.logical_not),]
    self.test_lt = self.original_lt < 10 
Example #30
Source File: test_mixins.py    From vnpy_crypto with MIT License 5 votes vote down vote up
def test_unary_methods(self):
        array = np.array([-1, 0, 1, 2])
        array_like = ArrayLike(array)
        for op in [operator.neg,
                   operator.pos,
                   abs,
                   operator.invert]:
            _assert_equal_type_and_value(op(array_like), ArrayLike(op(array)))