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


Python operator.floordiv方法代碼示例

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


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

示例1: test_arith

# 需要導入模塊: import operator [as 別名]
# 或者: from operator import floordiv [as 別名]
def test_arith(self):
        self._test_op(self.panel, operator.add)
        self._test_op(self.panel, operator.sub)
        self._test_op(self.panel, operator.mul)
        self._test_op(self.panel, operator.truediv)
        self._test_op(self.panel, operator.floordiv)
        self._test_op(self.panel, operator.pow)

        self._test_op(self.panel, lambda x, y: y + x)
        self._test_op(self.panel, lambda x, y: y - x)
        self._test_op(self.panel, lambda x, y: y * x)
        self._test_op(self.panel, lambda x, y: y / x)
        self._test_op(self.panel, lambda x, y: y ** x)

        self._test_op(self.panel, lambda x, y: x + y)  # panel + 1
        self._test_op(self.panel, lambda x, y: x - y)  # panel - 1
        self._test_op(self.panel, lambda x, y: x * y)  # panel * 1
        self._test_op(self.panel, lambda x, y: x / y)  # panel / 1
        self._test_op(self.panel, lambda x, y: x ** y)  # panel ** 1

        pytest.raises(Exception, self.panel.__add__,
                      self.panel['ItemA']) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:24,代碼來源:test_panel.py

示例2: test_arith_flex_panel

# 需要導入模塊: import operator [as 別名]
# 或者: from operator import floordiv [as 別名]
def test_arith_flex_panel(self):
        ops = ['add', 'sub', 'mul', 'div',
               'truediv', 'pow', 'floordiv', 'mod']
        if not compat.PY3:
            aliases = {}
        else:
            aliases = {'div': 'truediv'}
        self.panel = self.panel.to_panel()

        for n in [np.random.randint(-50, -1), np.random.randint(1, 50), 0]:
            for op in ops:
                alias = aliases.get(op, op)
                f = getattr(operator, alias)
                exp = f(self.panel, n)
                result = getattr(self.panel, op)(n)
                assert_panel_equal(result, exp, check_panel_type=True)

                # rops
                r_f = lambda x, y: f(y, x)
                exp = r_f(self.panel, n)
                result = getattr(self.panel, 'r' + op)(n)
                assert_panel_equal(result, exp) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:24,代碼來源:test_panel.py

示例3: test_binary_operators

# 需要導入模塊: import operator [as 別名]
# 或者: from operator import floordiv [as 別名]
def test_binary_operators(self):

        # skipping for now #####
        import pytest
        pytest.skip("skipping sparse binary operators test")

        def _check_inplace_op(iop, op):
            tmp = self.bseries.copy()

            expected = op(tmp, self.bseries)
            iop(tmp, self.bseries)
            tm.assert_sp_series_equal(tmp, expected)

        inplace_ops = ['add', 'sub', 'mul', 'truediv', 'floordiv', 'pow']
        for op in inplace_ops:
            _check_inplace_op(getattr(operator, "i%s" % op),
                              getattr(operator, op)) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:19,代碼來源:test_series.py

示例4: _add_arithmetic_ops

# 需要導入模塊: import operator [as 別名]
# 或者: from operator import floordiv [as 別名]
def _add_arithmetic_ops(cls):
        cls.__add__ = cls._create_arithmetic_method(operator.add)
        cls.__radd__ = cls._create_arithmetic_method(ops.radd)
        cls.__sub__ = cls._create_arithmetic_method(operator.sub)
        cls.__rsub__ = cls._create_arithmetic_method(ops.rsub)
        cls.__mul__ = cls._create_arithmetic_method(operator.mul)
        cls.__rmul__ = cls._create_arithmetic_method(ops.rmul)
        cls.__pow__ = cls._create_arithmetic_method(operator.pow)
        cls.__rpow__ = cls._create_arithmetic_method(ops.rpow)
        cls.__mod__ = cls._create_arithmetic_method(operator.mod)
        cls.__rmod__ = cls._create_arithmetic_method(ops.rmod)
        cls.__floordiv__ = cls._create_arithmetic_method(operator.floordiv)
        cls.__rfloordiv__ = cls._create_arithmetic_method(ops.rfloordiv)
        cls.__truediv__ = cls._create_arithmetic_method(operator.truediv)
        cls.__rtruediv__ = cls._create_arithmetic_method(ops.rtruediv)
        if not PY3:
            cls.__div__ = cls._create_arithmetic_method(operator.div)
            cls.__rdiv__ = cls._create_arithmetic_method(ops.rdiv)

        cls.__divmod__ = cls._create_arithmetic_method(divmod)
        cls.__rdivmod__ = cls._create_arithmetic_method(ops.rdivmod) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:23,代碼來源:base.py

示例5: _add_numeric_methods_binary

# 需要導入模塊: import operator [as 別名]
# 或者: from operator import floordiv [as 別名]
def _add_numeric_methods_binary(cls):
        """
        Add in numeric methods.
        """
        cls.__add__ = _make_arithmetic_op(operator.add, cls)
        cls.__radd__ = _make_arithmetic_op(ops.radd, cls)
        cls.__sub__ = _make_arithmetic_op(operator.sub, cls)
        cls.__rsub__ = _make_arithmetic_op(ops.rsub, cls)
        cls.__rpow__ = _make_arithmetic_op(ops.rpow, cls)
        cls.__pow__ = _make_arithmetic_op(operator.pow, cls)

        cls.__truediv__ = _make_arithmetic_op(operator.truediv, cls)
        cls.__rtruediv__ = _make_arithmetic_op(ops.rtruediv, cls)
        if not compat.PY3:
            cls.__div__ = _make_arithmetic_op(operator.div, cls)
            cls.__rdiv__ = _make_arithmetic_op(ops.rdiv, cls)

        # TODO: rmod? rdivmod?
        cls.__mod__ = _make_arithmetic_op(operator.mod, cls)
        cls.__floordiv__ = _make_arithmetic_op(operator.floordiv, cls)
        cls.__rfloordiv__ = _make_arithmetic_op(ops.rfloordiv, cls)
        cls.__divmod__ = _make_arithmetic_op(divmod, cls)
        cls.__mul__ = _make_arithmetic_op(operator.mul, cls)
        cls.__rmul__ = _make_arithmetic_op(ops.rmul, cls) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:26,代碼來源:base.py

示例6: _gen_fill_zeros

# 需要導入模塊: import operator [as 別名]
# 或者: from operator import floordiv [as 別名]
def _gen_fill_zeros(name):
    """
    Find the appropriate fill value to use when filling in undefined values
    in the results of the given operation caused by operating on
    (generally dividing by) zero.

    Parameters
    ----------
    name : str

    Returns
    -------
    fill_value : {None, np.nan, np.inf}
    """
    name = name.strip('__')
    if 'div' in name:
        # truediv, floordiv, div, and reversed variants
        fill_value = np.inf
    elif 'mod' in name:
        # mod, rmod
        fill_value = np.nan
    else:
        fill_value = None
    return fill_value 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:26,代碼來源:ops.py

示例7: test_modulus_basic

# 需要導入模塊: import operator [as 別名]
# 或者: from operator import floordiv [as 別名]
def test_modulus_basic(self):
        dt = np.typecodes['AllInteger'] + np.typecodes['Float']
        for dt1, dt2 in itertools.product(dt, dt):
            for sg1, sg2 in itertools.product((+1, -1), (+1, -1)):
                if sg1 == -1 and dt1 in np.typecodes['UnsignedInteger']:
                    continue
                if sg2 == -1 and dt2 in np.typecodes['UnsignedInteger']:
                    continue
                fmt = 'dt1: %s, dt2: %s, sg1: %s, sg2: %s'
                msg = fmt % (dt1, dt2, sg1, sg2)
                a = np.array(sg1*71, dtype=dt1)[()]
                b = np.array(sg2*19, dtype=dt2)[()]
                div = self.floordiv(a, b)
                rem = self.mod(a, b)
                assert_equal(div*b + rem, a, err_msg=msg)
                if sg2 == -1:
                    assert_(b < rem <= 0, msg)
                else:
                    assert_(b > rem >= 0, msg) 
開發者ID:abhisuri97,項目名稱:auto-alt-text-lambda-api,代碼行數:21,代碼來源:test_scalarmath.py

示例8: test_float_modulus_roundoff

# 需要導入模塊: import operator [as 別名]
# 或者: from operator import floordiv [as 別名]
def test_float_modulus_roundoff(self):
        # gh-6127
        dt = np.typecodes['Float']
        for dt1, dt2 in itertools.product(dt, dt):
            for sg1, sg2 in itertools.product((+1, -1), (+1, -1)):
                fmt = 'dt1: %s, dt2: %s, sg1: %s, sg2: %s'
                msg = fmt % (dt1, dt2, sg1, sg2)
                a = np.array(sg1*78*6e-8, dtype=dt1)[()]
                b = np.array(sg2*6e-8, dtype=dt2)[()]
                div = self.floordiv(a, b)
                rem = self.mod(a, b)
                # Equal assertion should hold when fmod is used
                assert_equal(div*b + rem, a, err_msg=msg)
                if sg2 == -1:
                    assert_(b < rem <= 0, msg)
                else:
                    assert_(b > rem >= 0, msg) 
開發者ID:abhisuri97,項目名稱:auto-alt-text-lambda-api,代碼行數:19,代碼來源:test_scalarmath.py

示例9: test_arith

# 需要導入模塊: import operator [as 別名]
# 或者: from operator import floordiv [as 別名]
def test_arith(self):
        with catch_warnings(record=True):
            self._test_op(self.panel, operator.add)
            self._test_op(self.panel, operator.sub)
            self._test_op(self.panel, operator.mul)
            self._test_op(self.panel, operator.truediv)
            self._test_op(self.panel, operator.floordiv)
            self._test_op(self.panel, operator.pow)

            self._test_op(self.panel, lambda x, y: y + x)
            self._test_op(self.panel, lambda x, y: y - x)
            self._test_op(self.panel, lambda x, y: y * x)
            self._test_op(self.panel, lambda x, y: y / x)
            self._test_op(self.panel, lambda x, y: y ** x)

            self._test_op(self.panel, lambda x, y: x + y)  # panel + 1
            self._test_op(self.panel, lambda x, y: x - y)  # panel - 1
            self._test_op(self.panel, lambda x, y: x * y)  # panel * 1
            self._test_op(self.panel, lambda x, y: x / y)  # panel / 1
            self._test_op(self.panel, lambda x, y: x ** y)  # panel ** 1

            pytest.raises(Exception, self.panel.__add__,
                          self.panel['ItemA']) 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:25,代碼來源:test_panel.py

示例10: test_arith_flex_panel

# 需要導入模塊: import operator [as 別名]
# 或者: from operator import floordiv [as 別名]
def test_arith_flex_panel(self):
        with catch_warnings(record=True):
            ops = ['add', 'sub', 'mul', 'div',
                   'truediv', 'pow', 'floordiv', 'mod']
            if not compat.PY3:
                aliases = {}
            else:
                aliases = {'div': 'truediv'}
            self.panel = self.panel.to_panel()

            for n in [np.random.randint(-50, -1), np.random.randint(1, 50), 0]:
                for op in ops:
                    alias = aliases.get(op, op)
                    f = getattr(operator, alias)
                    exp = f(self.panel, n)
                    result = getattr(self.panel, op)(n)
                    assert_panel_equal(result, exp, check_panel_type=True)

                    # rops
                    r_f = lambda x, y: f(y, x)
                    exp = r_f(self.panel, n)
                    result = getattr(self.panel, 'r' + op)(n)
                    assert_panel_equal(result, exp) 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:25,代碼來源:test_panel.py

示例11: _add_numeric_methods_binary

# 需要導入模塊: import operator [as 別名]
# 或者: from operator import floordiv [as 別名]
def _add_numeric_methods_binary(cls):
        """ add in numeric methods """
        cls.__add__ = _make_arithmetic_op(operator.add, cls)
        cls.__radd__ = _make_arithmetic_op(ops.radd, cls)
        cls.__sub__ = _make_arithmetic_op(operator.sub, cls)
        cls.__rsub__ = _make_arithmetic_op(ops.rsub, cls)
        cls.__mul__ = _make_arithmetic_op(operator.mul, cls)
        cls.__rmul__ = _make_arithmetic_op(ops.rmul, cls)
        cls.__rpow__ = _make_arithmetic_op(ops.rpow, cls)
        cls.__pow__ = _make_arithmetic_op(operator.pow, cls)
        cls.__mod__ = _make_arithmetic_op(operator.mod, cls)
        cls.__floordiv__ = _make_arithmetic_op(operator.floordiv, cls)
        cls.__rfloordiv__ = _make_arithmetic_op(ops.rfloordiv, cls)
        cls.__truediv__ = _make_arithmetic_op(operator.truediv, cls)
        cls.__rtruediv__ = _make_arithmetic_op(ops.rtruediv, cls)
        if not compat.PY3:
            cls.__div__ = _make_arithmetic_op(operator.div, cls)
            cls.__rdiv__ = _make_arithmetic_op(ops.rdiv, cls)

        cls.__divmod__ = _make_arithmetic_op(divmod, cls) 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:22,代碼來源:base.py

示例12: test_quaternion_divide_ufunc

# 需要導入模塊: import operator [as 別名]
# 或者: from operator import floordiv [as 別名]
def test_quaternion_divide_ufunc(Qs):
    ufunc_binary_utility(np.array([quaternion.one]), Qs[Qs_finitenonzero], operator.truediv)
    ufunc_binary_utility(Qs[Qs_finite], np.array([quaternion.one]), operator.truediv)
    ufunc_binary_utility(np.array([1.0]), Qs[Qs_finitenonzero], operator.truediv)
    ufunc_binary_utility(Qs[Qs_finite], np.array([1.0]), operator.truediv)
    ufunc_binary_utility(np.array([1]), Qs[Qs_finitenonzero], operator.truediv)
    ufunc_binary_utility(Qs[Qs_finite], np.array([1]), operator.truediv)
    ufunc_binary_utility(np.array([0.0]), Qs[Qs_finitenonzero], operator.truediv)
    ufunc_binary_utility(np.array([0]), Qs[Qs_finitenonzero], operator.truediv)

    ufunc_binary_utility(np.array([-3, -2.3, -1.2, -1.0, 0.0, 0, 1.0, 1, 1.2, 2.3, 3]),
                         Qs[Qs_finitenonzero], operator.truediv)
    ufunc_binary_utility(Qs[Qs_finitenonzero],
                         np.array([-3, -2.3, -1.2, -1.0, 1.0, 1, 1.2, 2.3, 3]), operator.truediv)

    ufunc_binary_utility(Qs[Qs_finite], Qs[Qs_finitenonzero], operator.truediv)
    ufunc_binary_utility(Qs[Qs_finite], Qs[Qs_finitenonzero], operator.floordiv)

    ufunc_binary_utility(Qs[Qs_finitenonzero], Qs[Qs_finitenonzero], operator.truediv)
    ufunc_binary_utility(Qs[Qs_finitenonzero], Qs[Qs_finitenonzero], operator.floordiv) 
開發者ID:moble,項目名稱:quaternion,代碼行數:22,代碼來源:test_quaternion.py

示例13: test_binary_operators

# 需要導入模塊: import operator [as 別名]
# 或者: from operator import floordiv [as 別名]
def test_binary_operators(self):

        # skipping for now #####
        raise nose.SkipTest("skipping sparse binary operators test")

        def _check_inplace_op(iop, op):
            tmp = self.bseries.copy()

            expected = op(tmp, self.bseries)
            iop(tmp, self.bseries)
            assert_sp_series_equal(tmp, expected)

        inplace_ops = ['add', 'sub', 'mul', 'truediv', 'floordiv', 'pow']
        for op in inplace_ops:
            _check_inplace_op(
                getattr(operator, "i%s" % op), getattr(operator, op)) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:18,代碼來源:test_sparse.py

示例14: test_binary_arithmetic_operations

# 需要導入模塊: import operator [as 別名]
# 或者: from operator import floordiv [as 別名]
def test_binary_arithmetic_operations(backend, alltypes, df, op):
    smallint_col = alltypes.smallint_col + 1  # make it nonzero
    smallint_series = df.smallint_col + 1

    expr = op(alltypes.double_col, smallint_col)

    result = expr.execute()
    expected = op(df.double_col, smallint_series)
    if op is operator.floordiv:
        # defined in ops.FloorDivide.output_type
        # -> returns int64 whereas pandas float64
        result = result.astype('float64')

    expected = backend.default_series_rename(expected)
    backend.assert_series_equal(
        result, expected, check_exact=False, check_less_precise=True
    ) 
開發者ID:ibis-project,項目名稱:ibis,代碼行數:19,代碼來源:test_numeric.py

示例15: testFloorDiv

# 需要導入模塊: import operator [as 別名]
# 或者: from operator import floordiv [as 別名]
def testFloorDiv(self):
        self.binaryCheck(operator.floordiv, jmin=1) 
開發者ID:myhdl,項目名稱:myhdl,代碼行數:4,代碼來源:test_Signal.py


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