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


Python operator.lt方法代碼示例

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


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

示例1: test_richcompare_crash

# 需要導入模塊: import operator [as 別名]
# 或者: from operator import lt [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 lt [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: test_comparison_flex_basic

# 需要導入模塊: import operator [as 別名]
# 或者: from operator import lt [as 別名]
def test_comparison_flex_basic(self):
        left = pd.Series(np.random.randn(10))
        right = pd.Series(np.random.randn(10))

        tm.assert_series_equal(left.eq(right), left == right)
        tm.assert_series_equal(left.ne(right), left != right)
        tm.assert_series_equal(left.le(right), left < right)
        tm.assert_series_equal(left.lt(right), left <= right)
        tm.assert_series_equal(left.gt(right), left > right)
        tm.assert_series_equal(left.ge(right), left >= right)

        # axis
        for axis in [0, None, 'index']:
            tm.assert_series_equal(left.eq(right, axis=axis), left == right)
            tm.assert_series_equal(left.ne(right, axis=axis), left != right)
            tm.assert_series_equal(left.le(right, axis=axis), left < right)
            tm.assert_series_equal(left.lt(right, axis=axis), left <= right)
            tm.assert_series_equal(left.gt(right, axis=axis), left > right)
            tm.assert_series_equal(left.ge(right, axis=axis), left >= right)

        #
        msg = 'No axis named 1 for object type'
        for op in ['eq', 'ne', 'le', 'le', 'gt', 'ge']:
            with pytest.raises(ValueError, match=msg):
                getattr(left, op)(right, axis=1) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:27,代碼來源:test_arithmetic.py

示例4: is_sorted

# 需要導入模塊: import operator [as 別名]
# 或者: from operator import lt [as 別名]
def is_sorted(iterable, key=None, reverse=False, distinct=False):
    if key is None:
        key = identity
    if reverse:
        if distinct:
            if isinstance(iterable, range) and iterable.step < 0:
                return True
            op = operator.gt
        else:
            op = operator.ge
    else:
        if distinct:
            if isinstance(iterable, range) and iterable.step > 0:
                return True
            if isinstance(iterable, SortedFrozenSet):
                return True
            op = operator.lt
        else:
            op = operator.le
    return all(op(a, b) for a, b in pairwise(map(key, iterable))) 
開發者ID:sixty-north,項目名稱:segpy,代碼行數:22,代碼來源:util.py

示例5: get_op

# 需要導入模塊: import operator [as 別名]
# 或者: from operator import lt [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

示例6: _filter_range_index

# 需要導入模塊: import operator [as 別名]
# 或者: from operator import lt [as 別名]
def _filter_range_index(pd_range_index, min_val, min_val_close, max_val, max_val_close):
    if is_pd_range_empty(pd_range_index):
        return pd_range_index

    raw_min, raw_max, step = pd_range_index.min(), pd_range_index.max(), _get_range_index_step(pd_range_index)

    # seek min range
    greater_func = operator.gt if min_val_close else operator.ge
    actual_min = raw_min
    while greater_func(min_val, actual_min):
        actual_min += abs(step)
    if step < 0:
        actual_min += step  # on the right side

    # seek max range
    less_func = operator.lt if max_val_close else operator.le
    actual_max = raw_max
    while less_func(max_val, actual_max):
        actual_max -= abs(step)
    if step > 0:
        actual_max += step  # on the right side

    if step > 0:
        return pd.RangeIndex(actual_min, actual_max, step)
    return pd.RangeIndex(actual_max, actual_min, step) 
開發者ID:mars-project,項目名稱:mars,代碼行數:27,代碼來源:utils.py

示例7: testBigComplexComparisons

# 需要導入模塊: import operator [as 別名]
# 或者: from operator import lt [as 別名]
def testBigComplexComparisons(self):
        self.assertFalse(F(10**23) == complex(10**23))
        self.assertRaises(TypeError, operator.gt, F(10**23), complex(10**23))
        self.assertRaises(TypeError, operator.le, F(10**23), complex(10**23))

        x = F(3, 8)
        z = complex(0.375, 0.0)
        w = complex(0.375, 0.2)
        self.assertTrue(x == z)
        self.assertFalse(x != z)
        self.assertFalse(x == w)
        self.assertTrue(x != w)
        for op in operator.lt, operator.le, operator.gt, operator.ge:
            self.assertRaises(TypeError, op, x, z)
            self.assertRaises(TypeError, op, z, x)
            self.assertRaises(TypeError, op, x, w)
            self.assertRaises(TypeError, op, w, x) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:19,代碼來源:test_fractions.py

示例8: test_dicts

# 需要導入模塊: import operator [as 別名]
# 或者: from operator import lt [as 別名]
def test_dicts(self):
        # Verify that __eq__ and __ne__ work for dicts even if the keys and
        # values don't support anything other than __eq__ and __ne__ (and
        # __hash__).  Complex numbers are a fine example of that.
        import random
        imag1a = {}
        for i in range(50):
            imag1a[random.randrange(100)*1j] = random.randrange(100)*1j
        items = imag1a.items()
        random.shuffle(items)
        imag1b = {}
        for k, v in items:
            imag1b[k] = v
        imag2 = imag1b.copy()
        imag2[k] = v + 1.0
        self.assertTrue(imag1a == imag1a)
        self.assertTrue(imag1a == imag1b)
        self.assertTrue(imag2 == imag2)
        self.assertTrue(imag1a != imag2)
        for opname in ("lt", "le", "gt", "ge"):
            for op in opmap[opname]:
                self.assertRaises(TypeError, op, imag1a, imag2) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:24,代碼來源:test_richcmp.py

示例9: test_operator

# 需要導入模塊: import operator [as 別名]
# 或者: from operator import lt [as 別名]
def test_operator(self):
        import operator
        self.assertIs(operator.truth(0), False)
        self.assertIs(operator.truth(1), True)
        with test_support.check_py3k_warnings():
            self.assertIs(operator.isCallable(0), False)
            self.assertIs(operator.isCallable(len), True)
        self.assertIs(operator.isNumberType(None), False)
        self.assertIs(operator.isNumberType(0), True)
        self.assertIs(operator.not_(1), False)
        self.assertIs(operator.not_(0), True)
        self.assertIs(operator.isSequenceType(0), False)
        self.assertIs(operator.isSequenceType([]), True)
        self.assertIs(operator.contains([], 1), False)
        self.assertIs(operator.contains([1], 1), True)
        self.assertIs(operator.isMappingType(1), False)
        self.assertIs(operator.isMappingType({}), True)
        self.assertIs(operator.lt(0, 0), False)
        self.assertIs(operator.lt(0, 1), True)
        self.assertIs(operator.is_(True, True), True)
        self.assertIs(operator.is_(True, False), False)
        self.assertIs(operator.is_not(True, True), False)
        self.assertIs(operator.is_not(True, False), True) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:25,代碼來源:test_bool.py

示例10: test_richcompare_crash

# 需要導入模塊: import operator [as 別名]
# 或者: from operator import lt [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

示例11: __init__

# 需要導入模塊: import operator [as 別名]
# 或者: from operator import lt [as 別名]
def __init__(self, actor, osc_position, distance, along_route=False,
                 comparison_operator=operator.lt, name="InTriggerDistanceToOSCPosition"):
        """
        Setup parameters
        """
        super(InTriggerDistanceToOSCPosition, self).__init__(name)
        self._actor = actor
        self._osc_position = osc_position
        self._distance = distance
        self._along_route = along_route
        self._comparison_operator = comparison_operator
        self._map = CarlaDataProvider.get_map()

        if self._along_route:
            # Get the global route planner, used to calculate the route
            dao = GlobalRoutePlannerDAO(self._map, 0.5)
            grp = GlobalRoutePlanner(dao)
            grp.setup()
            self._grp = grp
        else:
            self._grp = None 
開發者ID:carla-simulator,項目名稱:scenario_runner,代碼行數:23,代碼來源:atomic_trigger_conditions.py

示例12: binary_search

# 需要導入模塊: import operator [as 別名]
# 或者: from operator import lt [as 別名]
def binary_search(f, g, f_type, y_target, y_target_eps, x_min, x_max, x_eps, max_num_iter=1000, log=True):
    """ does binary search on f :: X -> Z by calculating z = f(x) and using g :: Z -> Y to get y = g(z) = g(f(x)).
    (g . f) is assumed to be monotonically increasing iff f_tpye == 'increasing' and monotonically decreasing iff
    f_type == 'decreasing'.
    Returns first (x, z) for which |y_target - g(f(x))| < y_target_eps. x_min, x_max specifiy initial search interval for x.
    Stops if x_max - x_min < x_eps. Raises BinarySearchFailedException when x interval too small or if search takes
    more than max_num_iter iterations. The expection has a field `discovered_values` which is a list of checked
    (x, y) coordinates. """
    def _print(s):
        if log:
            print(s)
    assert f_type in ('increasing', 'decreasing')
    cmp_op = operator.gt if f_type == 'increasing' else operator.lt
    discovered_values = []
    print_col_width = len(str(x_max)) + 3
    for _ in range(max_num_iter):
        x = x_min + (x_max - x_min) / 2
        z = f(x)
        y = g(z)
        discovered_values.append((x, y))
        _print('[{:{width}.2f}, {:{width}.2f}] -- g(f({:{width}.2f})) = {:.2f}'.format(
            x_min, x_max, x, y, width=print_col_width))
        if abs(y_target - y) < y_target_eps:
            return z, x
        if cmp_op(y, y_target):
            x_max = x
        else:
            x_min = x
        if x_max - x_min < x_eps:
            _print('Stopping, interval too close!')
            break
    sorted_discovered_values = sorted(discovered_values)
    first_y, last_y = sorted_discovered_values[0][1], sorted_discovered_values[-1][1]
    if (f_type == 'increasing' and first_y > last_y) or (f_type == 'decreasing' and first_y < last_y):
        raise ValueError('Got f_type == {}, but first_y, last_y = {}, {}'.format(
            f_type, first_y, last_y))
    raise BinarySearchFailedException(discovered_values)



# ------------------------------------------------------------------------------ 
開發者ID:fab-jul,項目名稱:imgcomp-cvpr,代碼行數:43,代碼來源:other_codecs.py

示例13: testLt

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

示例14: __lt__

# 需要導入模塊: import operator [as 別名]
# 或者: from operator import lt [as 別名]
def __lt__(self, other: Union['Quantity', float, int]) -> bool:
        return Quantity._bool_operation(self, other, operator.lt) 
開發者ID:tensortrade-org,項目名稱:tensortrade,代碼行數:4,代碼來源:quantity.py

示例15: __lt__

# 需要導入模塊: import operator [as 別名]
# 或者: from operator import lt [as 別名]
def __lt__(self, other):
        return self._compare(operator.lt, other) 
開發者ID:gnocchixyz,項目名稱:gnocchi,代碼行數:4,代碼來源:carbonara.py


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