Python operator.is_not() Examples
The following are 28
code examples of operator.is_not().
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_bool.py From ironpython2 with Apache License 2.0 | 7 votes |
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)
Example #2
Source File: base.py From aswan with GNU Lesser General Public License v2.1 | 6 votes |
def trans_result(self, rv, op_name, threshold): """ 对结果进行转化,最后结果为 True/False 标识是否命中 :param bool|None rv: 内置函数返回值 :param str|unicode op_name: 操作符 :param object threshold: 阈值 :return: """ # 若想忽略op码永远通过则设置rv为None if rv is None: return False if op_name in {'is', 'is_not'}: threshold = True elif self.threshold_trans_func: threshold = self.threshold_trans_func(threshold) method = self.op_map.get(op_name, None) return method(rv, threshold) if method else False
Example #3
Source File: test_bool.py From CTFCrackTools with GNU General Public License v3.0 | 6 votes |
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)
Example #4
Source File: test_bool.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 6 votes |
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)
Example #5
Source File: type.py From aries-staticagent-python with Apache License 2.0 | 6 votes |
def from_str(cls, version_str): """ Parse version information from a string. """ matches = Semver.SEMVER_RE.match(version_str) if matches: args = list(matches.groups()) if not matches.group(3): args.append('0') return Semver(*map(int, filter(partial(is_not, None), args))) parts = parse(version_str) return cls( parts['major'], parts['minor'], parts['patch'], parts['prerelease'], parts['build'] )
Example #6
Source File: expressions.py From PeekabooAV with GNU General Public License v3.0 | 6 votes |
def __init__(self, tokens): super().__init__(tokens) self.operator_map = { "<": operator.lt, "<=": operator.le, ">": operator.gt, ">=": operator.ge, "==": operator.eq, "!=": operator.ne, "in": EvalLogic.in_, "not in": EvalLogic.not_in, "is": operator.is_, "is not": operator.is_not, "isdisjoint": lambda a, b: a.isdisjoint(b), "and": operator.and_, "or": operator.or_, }
Example #7
Source File: test_operator.py From gcblue with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_is_not(self): a = b = 'xyzpdq' c = a[:3] + b[3:] self.assertRaises(TypeError, operator.is_not) self.assertFalse(operator.is_not(a, b)) self.assertTrue(operator.is_not(a,c))
Example #8
Source File: api.py From hepdata with GNU General Public License v2.0 | 5 votes |
def get_records_subscribed_by_current_user(): subscriptions = Subscribers.query.filter(Subscribers.subscribers.contains(current_user)).all() if subscriptions: records = [get_record_contents(x.publication_recid) for x in subscriptions] return list(filter(partial(is_not, None), records)) else: return []
Example #9
Source File: api.py From hepdata with GNU General Public License v2.0 | 5 votes |
def get_records_participated_in_by_user(): _current_user_id = int(current_user.get_id()) as_uploader = SubmissionParticipant.query.filter_by(user_account=_current_user_id, role='uploader').order_by( SubmissionParticipant.id.desc()).all() as_reviewer = SubmissionParticipant.query.filter_by(user_account=_current_user_id, role='reviewer').order_by( SubmissionParticipant.id.desc()).all() as_coordinator_query = HEPSubmission.query.filter_by(coordinator=_current_user_id).order_by( HEPSubmission.created.desc()) # special case, since this user ID is the one used for loading all submissions, which is in the 1000s. if _current_user_id == 1: as_coordinator_query = as_coordinator_query.limit(5) as_coordinator = as_coordinator_query.all() result = {'uploader': [], 'reviewer': [], 'coordinator': []} if as_uploader: _uploader = [get_record_contents(x.publication_recid) for x in as_uploader] result['uploader'] = filter(partial(is_not, None), _uploader) if as_reviewer: _uploader = [get_record_contents(x.publication_recid) for x in as_reviewer] result['reviewer'] = filter(partial(is_not, None), _uploader) if as_coordinator: _coordinator = [get_record_contents(x.publication_recid) for x in as_coordinator] result['coordinator'] = filter(partial(is_not, None), _coordinator) return list(result)
Example #10
Source File: test_operator.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def test_is_not(self): a = b = 'xyzpdq' c = a[:3] + b[3:] self.failUnlessRaises(TypeError, operator.is_not) self.failIf(operator.is_not(a, b)) self.failUnless(operator.is_not(a,c))
Example #11
Source File: vampire.py From vampire with Apache License 2.0 | 5 votes |
def compute_npmi(self, topics, num_words=10): """ Compute global NPMI across topics Parameters ---------- topics: ``List[Tuple[str, List[int]]]`` list of learned topics num_words: ``int`` number of words to compute npmi over """ topics_idx = [[self._ref_vocab_index.get(word) for word in topic[1][:num_words]] for topic in topics] rows = [] cols = [] res_rows = [] res_cols = [] max_seq_len = max([len(topic) for topic in topics_idx]) for index, topic in enumerate(topics_idx): topic = list(filter(partial(is_not, None), topic)) if len(topic) > 1: _rows, _cols = zip(*combinations(topic, 2)) res_rows.extend([index] * len(_rows)) res_cols.extend(range(len(_rows))) rows.extend(_rows) cols.extend(_cols) npmi_data = ((np.log10(self.n_docs) + self._npmi_numerator[rows, cols]) / (np.log10(self.n_docs) - self._npmi_denominator[rows, cols])) npmi_data[npmi_data == 1.0] = 0.0 npmi_shape = (len(topics), len(list(combinations(range(max_seq_len), 2)))) npmi = sparse.csr_matrix((npmi_data.tolist()[0], (res_rows, res_cols)), shape=npmi_shape) return npmi.mean()
Example #12
Source File: test_operator.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def test_is_not(self): a = b = 'xyzpdq' c = a[:3] + b[3:] self.failUnlessRaises(TypeError, operator.is_not) self.failIf(operator.is_not(a, b)) self.failUnless(operator.is_not(a,c))
Example #13
Source File: test_bool.py From medicare-demo with Apache License 2.0 | 5 votes |
def test_operator(self): import operator self.assertIs(operator.truth(0), False) self.assertIs(operator.truth(1), True) 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)
Example #14
Source File: test_operator.py From medicare-demo with Apache License 2.0 | 5 votes |
def test_is_not(self): a = b = 'xyzpdq' c = a[:3] + b[3:] self.failUnlessRaises(TypeError, operator.is_not) self.failIf(operator.is_not(a, b)) self.failUnless(operator.is_not(a,c))
Example #15
Source File: test_bool.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_operator(self): import operator self.assertIs(operator.truth(0), False) self.assertIs(operator.truth(1), True) self.assertIs(operator.not_(1), False) self.assertIs(operator.not_(0), True) self.assertIs(operator.contains([], 1), False) self.assertIs(operator.contains([1], 1), 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)
Example #16
Source File: test_bool.py From gcblue with BSD 3-Clause "New" or "Revised" License | 5 votes |
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)
Example #17
Source File: runtests.py From udger-python with MIT License | 5 votes |
def iter_compare_dicts(dict1, dict2, only_common_keys=False, comparison_op=operator.ne): """ A generator for comparation of values in the given two dicts. Yields the tuples (key, pair of values positively compared). By default, the *difference* of values is evaluated using the usual != op, but can be changed by passing other comparison_op (a function of two arguments returning True/False). For example: operator.eq for equal values, operator.is_not for not identical objects. You can also require comparison only over keys existing in both dicts (only_common_keys=True). Otherwise, you will get the pair with the Python built-in Ellipsis placed for dict with that key missing. (Be sure to test for Ellipsis using the 'is' operator.) >>> d1 = dict(a=1, b=2, c=3) >>> d2 = dict(a=1, b=20, d=4) >>> dict(iter_compare_dicts(d1, d2, only_common_keys=True)) {'b': (2, 20)} >>> dict(iter_compare_dicts(d1, d2, only_common_keys=True, comparison_op=operator.eq)) {'a': (1, 1)} >>> dict(iter_compare_dicts(d1, d2)) {'c': (3, Ellipsis), 'b': (2, 20), 'd': (Ellipsis, 4)} >>> dict(iter_compare_dicts(d1, d2, comparison_op=operator.eq)) {'a': (1, 1), 'c': (3, Ellipsis), 'd': (Ellipsis, 4)} """ keyset1, keyset2 = set(dict1), set(dict2) for key in (keyset1 & keyset2): pair = (dict1[key], dict2[key]) if reduce(comparison_op, pair): yield key, pair if not only_common_keys: for key in (keyset1 - keyset2): yield key, (dict1[key], Ellipsis) for key in (keyset2 - keyset1): yield key, (Ellipsis, dict2[key])
Example #18
Source File: converter.py From storops with Apache License 2.0 | 5 votes |
def to_int_arr(inputs): if inputs is not None: if isinstance(inputs, six.string_types): inputs = re.split(',| ', inputs) ints = map(to_int, inputs) ret = list(filter(partial(is_not, None), ints)) else: ret = [] return ret
Example #19
Source File: op_is_not.py From myia with MIT License | 5 votes |
def is_not(x, y): """Implementation of the `is not` operator.""" return not (x is y)
Example #20
Source File: agent_executor.py From clai with MIT License | 5 votes |
def execute_agents(self, command: State, agents: List[Agent]) -> List[Union[Action, List[Action]]]: with futures.ThreadPoolExecutor(max_workers=self.NUM_WORKERS) as executor: done, _ = futures.wait( [executor.submit(plugin_instance.execute, command) for plugin_instance in agents], timeout=self.MAX_TIME_PLUGIN_EXECUTION) if not done: return [] results = map(lambda future: future.result(), done) candidate_actions = list(filter(partial(is_not, None), results)) return candidate_actions # pylint: disable= invalid-name
Example #21
Source File: test_bool.py From ironpython3 with Apache License 2.0 | 5 votes |
def test_operator(self): import operator self.assertIs(operator.truth(0), False) self.assertIs(operator.truth(1), True) self.assertIs(operator.not_(1), False) self.assertIs(operator.not_(0), True) self.assertIs(operator.contains([], 1), False) self.assertIs(operator.contains([1], 1), 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)
Example #22
Source File: test_bool.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def test_operator(self): import operator self.assertIs(operator.truth(0), False) self.assertIs(operator.truth(1), True) self.assertIs(operator.not_(1), False) self.assertIs(operator.not_(0), True) self.assertIs(operator.contains([], 1), False) self.assertIs(operator.contains([1], 1), 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)
Example #23
Source File: eggroll.py From FATE with Apache License 2.0 | 5 votes |
def reduce(self, func): rs = [r.result() for r in self._submit_to_pool(func, do_reduce)] rs = [r for r in filter(partial(is_not, None), rs)] if len(rs) <= 0: return None rtn = rs[0] for r in rs[1:]: rtn = func(rtn, r) return rtn
Example #24
Source File: test_bool.py From oss-ftp with MIT License | 5 votes |
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)
Example #25
Source File: test_operator.py From oss-ftp with MIT License | 5 votes |
def test_is_not(self): a = b = 'xyzpdq' c = a[:3] + b[3:] self.assertRaises(TypeError, operator.is_not) self.assertFalse(operator.is_not(a, b)) self.assertTrue(operator.is_not(a,c))
Example #26
Source File: test_bool.py From BinderFilter with MIT License | 5 votes |
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)
Example #27
Source File: test_operator.py From BinderFilter with MIT License | 5 votes |
def test_is_not(self): a = b = 'xyzpdq' c = a[:3] + b[3:] self.assertRaises(TypeError, operator.is_not) self.assertFalse(operator.is_not(a, b)) self.assertTrue(operator.is_not(a,c))
Example #28
Source File: test_operator.py From ironpython2 with Apache License 2.0 | 5 votes |
def test_is_not(self): a = b = 'xyzpdq' c = a[:3] + b[3:] self.assertRaises(TypeError, operator.is_not) self.assertFalse(operator.is_not(a, b)) self.assertTrue(operator.is_not(a,c))