Python builtins.map() Examples
The following are 30
code examples of builtins.map().
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
builtins
, or try the search function
.
Example #1
Source File: dataframes.py From eht-imaging with GNU General Public License v3.0 | 6 votes |
def make_cphase_df(obs,band='unknown',polarization='unknown',mode='all',count='max',round_s=0.1,snrcut=0.,uv_min=False): """generate DataFrame of closure phases Args: obs: ObsData object round_s: accuracy of datetime object in seconds Returns: df: closure phase data in DataFrame format """ data=obs.c_phases(mode=mode,count=count,snrcut=snrcut,uv_min=uv_min) sour=obs.source df = pd.DataFrame(data=data).copy() df['fmjd'] = df['time']/24. df['mjd'] = obs.mjd + df['fmjd'] df['triangle'] = list(map(lambda x: x[0]+'-'+x[1]+'-'+x[2],zip(df['t1'],df['t2'],df['t3']))) df['datetime'] = Time(df['mjd'], format='mjd').datetime df['datetime'] =list(map(lambda x: round_time(x,round_s=round_s),df['datetime'])) df['jd'] = Time(df['mjd'], format='mjd').jd df['polarization'] = polarization df['band'] = band df['source'] = sour return df
Example #2
Source File: __init__.py From riko with MIT License | 6 votes |
def get_broadcast_funcs(**kwargs): kw = Objectify(kwargs, conf={}) pieces = kw.conf[kw.extract] if kw.extract else kw.conf no_conf = remove_keys(kwargs, 'conf') noop = partial(cast, _type='none') if kw.listize: listed = listize(pieces) piece_defs = map(DotDict, listed) if kw.pdictize else listed parser = partial(parse_conf, **no_conf) pfuncs = [partial(parser, conf=conf) for conf in piece_defs] get_pieces = lambda item: broadcast(item, *pfuncs) elif kw.ptype != 'none': conf = DotDict(pieces) if kw.pdictize and pieces else pieces get_pieces = partial(parse_conf, conf=conf, **no_conf) else: get_pieces = noop ffunc = noop if kw.ftype == 'none' else partial(get_field, **kwargs) return (ffunc, get_pieces)
Example #3
Source File: models.py From osler with GNU General Public License v3.0 | 6 votes |
def short_text(self): """Return a short text description of this followup and what happened. Used on the patient chart view as the text in the list of followups. """ text = "" locations = " ,".join(map(str, self.appointment_location.all())) if self.pt_showed == self.PTSHOW_YES: text = "Patient went to appointment at " + locations + "." else: if self.has_appointment == self.PTSHOW_YES: text = ("Patient made appointment at " + locations + "but has not yet gone.") else: if self.contact_status.patient_reached: text = ("Successfully contacted patient but the " "patient has not made an appointment yet.") else: text = "Did not successfully contact patient" return text
Example #4
Source File: utils.py From clusterfuzz with Apache License 2.0 | 6 votes |
def is_binary_file(file_path, bytes_to_read=1024): """Return true if the file looks like a binary file.""" file_extension = os.path.splitext(file_path)[1].lower() if file_extension in BINARY_EXTENSIONS: return True if file_extension in TEXT_EXTENSIONS: return False text_characters = list(map(chr, list(range(32, 128)))) + ['\r', '\n', '\t'] try: with open(file_path, 'rb') as file_handle: data = file_handle.read(bytes_to_read) except: logs.log_error('Could not read file %s in is_binary_file.' % file_path) return None binary_data = [char for char in data if char not in text_characters] return len(binary_data) > len(data) * 0.1
Example #5
Source File: utils.py From clusterfuzz with Apache License 2.0 | 6 votes |
def filter_file_list(file_list): """Filters file list by removing duplicates, non-existent files and directories.""" filtered_file_list = [] for file_path in file_list: if not os.path.exists(file_path): continue if os.path.isdir(file_path): continue # Do a os specific case normalization before comparison. if (os.path.normcase(file_path) in list( map(os.path.normcase, filtered_file_list))): continue filtered_file_list.append(file_path) if len(filtered_file_list) != len(file_list): logs.log('Filtered file list (%s) from (%s).' % (str(filtered_file_list), str(file_list))) return filtered_file_list
Example #6
Source File: axes.py From ngraph-python with Apache License 2.0 | 6 votes |
def _assert_valid_axes_map(self): """ Ensure that there are no axis which map to the same axis and raise a helpful error message. """ duplicate_axis_names = self._duplicate_axis_names() # if there are duplicate_axis_names throw an exception if duplicate_axis_names: message = 'AxesMap was can not have duplicate names, but found:' for target_axis, source_axes in duplicate_axis_names.items(): message += '\n {} maps to {}'.format( target_axis, ', '.join(source_axes) ) raise DuplicateAxisNames(message, duplicate_axis_names)
Example #7
Source File: testlib.py From clonedigger with GNU General Public License v3.0 | 6 votes |
def run(self, test): "Run the given test case or test suite." result = self._makeResult() startTime = time.time() test(result, self._runcondition, self.options) stopTime = time.time() timeTaken = stopTime - startTime result.printErrors() self.stream.writeln(result.separator2) run = result.testsRun self.stream.writeln("Ran %d test%s in %.3fs" % (run, run != 1 and "s" or "", timeTaken)) self.stream.writeln() if not result.wasSuccessful(): self.stream.write("FAILED (") failed, errored = list(map(len, (result.failures, result.errors))) if failed: self.stream.write("failures=%d" % failed) if errored: if failed: self.stream.write(", ") self.stream.write("errors=%d" % errored) self.stream.writeln(")") else: self.stream.writeln("OK") return result
Example #8
Source File: node.py From aerospike-admin with Apache License 2.0 | 6 votes |
def info_namespace_statistics(self, namespace): """ Get statistics for a namespace. Returns: dict -- {stat_name : stat_value, ...} """ ns_stat = util.info_to_dict(self.info("namespace/%s" % namespace)) # Due to new server feature namespace add/remove with rolling restart, # there is possibility that different nodes will have different namespaces. # type = unknown means namespace is not available on this node, so just return empty map. if ns_stat and not isinstance(ns_stat, Exception) and "type" in ns_stat and ns_stat["type"] == "unknown": ns_stat = {} return ns_stat
Example #9
Source File: serde.py From ngraph-python with Apache License 2.0 | 6 votes |
def protobuf_scalar_to_python(val): assert isinstance(val, ops_pb.Scalar) scalar_key = val.WhichOneof('value') if scalar_key == 'uuid_val': raise ValueError("During deserialization, no attributes should reference UUIDs.") elif scalar_key == 'map_val': return pb_to_dict(val.map_val.map) elif scalar_key == 'null_val': return None elif scalar_key == 'slice_val': val = val.slice_val return slice(val.start.value if val.HasField('start') else None, val.stop.value if val.HasField('stop') else None, val.step.value if val.HasField('step') else None) elif scalar_key == 'dtype_val': return pb_to_dtype(val.dtype_val) elif scalar_key == 'axis': return pb_to_axis(val.axis) elif scalar_key == 'axes_map': return pb_to_axes_map(val.axes_map) return getattr(val, scalar_key)
Example #10
Source File: serde.py From ngraph-python with Apache License 2.0 | 6 votes |
def protobuf_attr_to_python(val): if val.HasField('scalar'): return protobuf_scalar_to_python(val.scalar) if val.HasField('tensor'): return pb_to_tensor(val.tensor) elif val.HasField('repeated_scalar'): if len(val.repeated_scalar.val) == 1 and \ val.repeated_scalar.val[0].string_val == '_ngraph_iter_sentinel_': return () else: return list(map(protobuf_scalar_to_python, val.repeated_scalar.val)) elif val.HasField('axes'): return protobuf_to_axes(val.axes) else: raise ValueError("Cannot convert {} to python attribute value".format(val))
Example #11
Source File: table.py From aerospike-admin with Apache License 2.0 | 6 votes |
def _update_column_metadata(self, row, header=False): if self._style == Styles.HORIZONTAL: for i in range(len(self._column_names)): if not header: cell_format, cell = row[i] else: cell = row[i] # TODO - never used cell_format = self._no_alert_style if header: max_length = max(list(map(len, cell.split(' ')))) else: max_length = len(cell) if self._column_widths[i] < max_length: self._column_widths[i] = max_length if not header: if not filesize.isfilesize(cell): if cell != self._no_entry: self._column_types[i] = "string" elif self._style == Styles.VERTICAL: length = max( [len(r[1]) if type(r) is tuple else len(r) for r in row]) self._column_widths.append(length) else: raise ValueError("Style must be either HORIZONAL or VERTICAL")
Example #12
Source File: util.py From ektelo with Apache License 2.0 | 6 votes |
def standardize(item): """This method attempts to return common python objects to a standard form. It is typically used for post- processing output from json.loads. """ if type(item) == tuple or type(item) == list: return list(map(standardize, item)) elif type(item) == str: return str(item) elif type(item) == np.ndarray: return standardize(list(item)) elif type(item) == dict: replacement = {} for k, v in item.items(): replacement[str(k)] = standardize(v) return replacement else: # attempt to coerce numpy scalars try: return float(item) except: pass return item
Example #13
Source File: dataframes.py From eht-imaging with GNU General Public License v3.0 | 6 votes |
def match_multiple_frames(frames, what_is_same, dt = 0,uniquely=True): if dt > 0: for frame in frames: frame['round_time'] = list(map(lambda x: np.round((x- datetime.datetime(2017,4,4)).total_seconds()/dt),frame['datetime'])) what_is_same += ['round_time'] frames_common = {} for frame in frames: frame['all_ind'] = list(zip(*[frame[x] for x in what_is_same])) if frames_common != {}: frames_common = frames_common&set(frame['all_ind']) else: frames_common = set(frame['all_ind']) frames_out = [] for frame in frames: frame = frame[list(map(lambda x: x in frames_common, frame.all_ind))].copy() if uniquely: frame.drop_duplicates(subset=['all_ind'], keep='first', inplace=True) frame = frame.sort_values('all_ind').reset_index(drop=True) frame.drop('all_ind', axis=1,inplace=True) frames_out.append(frame.copy()) return frames_out
Example #14
Source File: decompile.py From dcc with Apache License 2.0 | 6 votes |
def get_ast(self): fields = [get_field_ast(f) for f in self.fields] methods = [] for m in self.methods: if isinstance(m, DvMethod) and m.ast: methods.append(m.get_ast()) isInterface = 'interface' in self.access return { 'rawname': self.thisclass[1:-1], 'name': parse_descriptor(self.thisclass), 'super': parse_descriptor(self.superclass), 'flags': self.access, 'isInterface': isInterface, 'interfaces': list(map(parse_descriptor, self.interfaces)), 'fields': fields, 'methods': methods, }
Example #15
Source File: config.py From recordlinkage with BSD 3-Clause "New" or "Revised" License | 6 votes |
def is_instance_factory(_type): """ Parameters ---------- `_type` - the type to be checked against Returns ------- validator - a function of a single argument x , which raises ValueError if x is not an instance of `_type` """ if isinstance(_type, (tuple, list)): _type = tuple(_type) type_repr = "|".join(map(lambda x: x.__name__, _type)) else: type_repr = "'{typ}'".format(typ=_type.__name__) def inner(x): if not isinstance(x, _type): msg = "Value must be an instance of {type_repr}" raise ValueError(msg.format(type_repr=type_repr)) return inner
Example #16
Source File: yara_support.py From rekall with GNU General Public License v2.0 | 6 votes |
def anything_beetween(opener_and_closer): """Builds a (pyparsing) parser for the content inside delimiters. Args: opener_and_closer: a string containing two elements: opener and closer Returns: A (pyparsing) parser for the content inside delimiters. """ opener = pyparsing.Literal(opener_and_closer[0]) closer = pyparsing.Literal(opener_and_closer[1]) char_removal_mapping = dict.fromkeys(list(map(ord, opener_and_closer))) other_chars = str(string.printable).translate(char_removal_mapping) word_without_delimiters = pyparsing.Word(other_chars).setName( "other_chars") anything = pyparsing.Forward() delimited_block = opener + anything + closer # pylint: disable=expression-not-assigned anything << pyparsing.ZeroOrMore( word_without_delimiters.setName("word_without_delimiters") | delimited_block.setName("delimited_block") ) # Combine all the parts into a single string. return pyparsing.Combine(anything)
Example #17
Source File: dataframes.py From eht-imaging with GNU General Public License v3.0 | 6 votes |
def make_bsp_df(obs,band='unknown',polarization='unknown',mode='all',count='min',round_s=0.1,snrcut=0., uv_min=False): """generate DataFrame of bispectra Args: obs: ObsData object round_s: accuracy of datetime object in seconds Returns: df: bispectra data in DataFrame format """ data = obs.bispectra(mode=mode,count=count,snrcut=snrcut,uv_min=uv_min) sour=obs.source df = pd.DataFrame(data=data).copy() df['fmjd'] = df['time']/24. df['mjd'] = obs.mjd + df['fmjd'] df['triangle'] = list(map(lambda x: x[0]+'-'+x[1]+'-'+x[2],zip(df['t1'],df['t2'],df['t3']))) df['datetime'] = Time(df['mjd'], format='mjd').datetime df['datetime'] =list(map(lambda x: round_time(x,round_s=round_s),df['datetime'])) df['jd'] = Time(df['mjd'], format='mjd').jd df['polarization'] = polarization df['band'] = band df['source'] = sour return df
Example #18
Source File: debugging.py From miasm with GNU General Public License v2.0 | 6 votes |
def print_registers(self): regs = self.dbg.get_gpreg_all() # Display settings title1 = "Registers" title2 = "Values" max_name_len = max(map(len, list(regs) + [title1])) # Print value table s = "%s%s | %s" % ( title1, " " * (max_name_len - len(title1)), title2) print(s) print("-" * len(s)) for name, value in sorted(viewitems(regs), key=lambda x: x[0]): print( "%s%s | %s" % ( name, " " * (max_name_len - len(name)), hex(value).replace("L", "") ) )
Example #19
Source File: pandas_py3k.py From kgsgo-dataset-preprocessor with Mozilla Public License 2.0 | 5 votes |
def __repr__(self): if not self: return '%s()' % self.__class__.__name__ items = ', '.join(map('%r: %r'.__mod__, self.most_common())) return '%s({%s})' % (self.__class__.__name__, items) # Multiset-style mathematical operations discussed in: # Knuth TAOCP Volume II section 4.6.3 exercise 19 # and at http://en.wikipedia.org/wiki/Multiset # # Outputs guaranteed to only include positive counts. # # To strip negative and zero counts, add-in an empty counter: # c += Counter()
Example #20
Source File: miasm_ir.py From miasm with GNU General Public License v2.0 | 5 votes |
def from_ExprOp(self, expr): return "ExprOp(%s, %s)" % ( repr(expr.op), ", ".join(map(self.from_expr, expr.args)) )
Example #21
Source File: depgraph.py From miasm with GNU General Public License v2.0 | 5 votes |
def treat_element(): "Display an element" global graphs, comments, sol_nb, settings, addr, ir_arch, ircfg try: graph = next(graphs) except StopIteration: comments = {} print("Done: %d solutions" % (sol_nb)) return sol_nb += 1 print("Get graph number %02d" % sol_nb) filename = os.path.join(tempfile.gettempdir(), "solution_0x%08x_%02d.dot" % (addr, sol_nb)) print("Dump the graph to %s" % filename) open(filename, "w").write(graph.graph.dot()) for node in graph.relevant_nodes: try: offset = ircfg.blocks[node.loc_key][node.line_nb].instr.offset except IndexError: print("Unable to highlight %s" % node) continue comments[offset] = comments.get(offset, []) + [node.element] idc.set_color(offset, idc.CIC_ITEM, settings.color) if graph.has_loop: print('Graph has dependency loop: symbolic execution is inexact') else: print("Possible value: %s" % next(iter(viewvalues(graph.emul(ir_arch))))) for offset, elements in viewitems(comments): idc.set_cmt(offset, ", ".join(map(str, elements)), 0)
Example #22
Source File: utils.py From miasm with GNU General Public License v2.0 | 5 votes |
def from_ExprAssign(self, expr): return "%s = %s" % tuple(map(expr.from_expr, (expr.dst, expr.src)))
Example #23
Source File: mentions.py From fonduer with MIT License | 5 votes |
def __init__( self, n_min: int = 1, n_max: int = 5, split_tokens: Collection[str] = [] ) -> None: """Initialize Ngrams.""" MentionSpace.__init__(self) self.n_min = n_min self.n_max = n_max self.split_rgx = ( r"(" + r"|".join(map(re.escape, sorted(split_tokens, reverse=True))) + r")" if split_tokens and len(split_tokens) > 0 else None )
Example #24
Source File: compat.py From mapbox-vector-tile with MIT License | 5 votes |
def apply_map(fn, x): return list(map(fn, x))
Example #25
Source File: dataframes.py From eht-imaging with GNU General Public License v3.0 | 5 votes |
def make_camp_df(obs,ctype='logcamp',debias=False,band='unknown',polarization='unknown',mode='all',count='max',round_s=0.1,snrcut=0.): """generate DataFrame of closure amplitudes Args: obs: ObsData object round_s: accuracy of datetime object in seconds Returns: df: closure amplitude data in DataFrame format """ data = obs.c_amplitudes(mode=mode,count=count,debias=debias,ctype=ctype,snrcut=snrcut) sour=obs.source df = pd.DataFrame(data=data).copy() df['fmjd'] = df['time']/24. df['mjd'] = obs.mjd + df['fmjd'] df['quadrangle'] = list(map(lambda x: x[0]+'-'+x[1]+'-'+x[2]+'-'+x[3],zip(df['t1'],df['t2'],df['t3'],df['t4']))) df['datetime'] = Time(df['mjd'], format='mjd').datetime df['datetime'] =list(map(lambda x: round_time(x,round_s=round_s),df['datetime'])) df['jd'] = Time(df['mjd'], format='mjd').jd df['polarization'] = polarization df['band'] = band df['source'] = sour df['catype'] = ctype return df
Example #26
Source File: test_futurize.py From kgsgo-dataset-preprocessor with Mozilla Public License 2.0 | 5 votes |
def test_import_builtins(self): before = """ a = raw_input() b = open(a, b, c) c = filter(a, b) d = map(a, b) e = isinstance(a, str) f = bytes(a, encoding='utf-8') for g in xrange(10**10): pass h = reduce(lambda x, y: x+y, [1, 2, 3, 4, 5]) super(MyClass, self) """ after = """ from builtins import bytes from builtins import filter from builtins import input from builtins import map from builtins import range from functools import reduce a = input() b = open(a, b, c) c = list(filter(a, b)) d = list(map(a, b)) e = isinstance(a, str) f = bytes(a, encoding='utf-8') for g in range(10**10): pass h = reduce(lambda x, y: x+y, [1, 2, 3, 4, 5]) super(MyClass, self) """ self.convert_check(before, after, ignore_imports=False, run=False)
Example #27
Source File: pandas_py3k.py From kgsgo-dataset-preprocessor with Mozilla Public License 2.0 | 5 votes |
def lmap(*args, **kwargs): return list(map(*args, **kwargs))
Example #28
Source File: util.py From ektelo with Apache License 2.0 | 5 votes |
def prepare_for_json(item): """Operates on PRIMITIVES, dicts, numpy.array, and persistable objects. """ if type(item) in PRIMITIVES: return item elif 'marshal' in dir(item): return item.marshal() elif contains_superclass(type(item), 'Inspectable'): return prepare_for_json(item.inspect()) elif type(item) == np.ndarray: return {'ndarray': item.tolist(), 'shape': item.shape} elif type(item) == list or type(item) == tuple: replacement = [] for x in item: replacement.append(prepare_for_json(x)) return replacement elif type(item) == dict: replacement = {} for k, v in item.items(): k = str(k) replacement[k] = prepare_for_json(v) return replacement elif type(item) == OrderedDict: return {'ordered_dict': prepare_for_json(list(map(tuple, item.items())))} else: # attempt to coerce numpy scalars try: return float(item) except: pass raise TypeError('%s not supported by prepare_for_json' % type(item))
Example #29
Source File: _compat.py From pipenv with MIT License | 5 votes |
def __compat_repr__(self): # pragma: nocover def make_param(name): value = getattr(self, name) return '{name}={value!r}'.format(**locals()) params = ', '.join(map(make_param, self._fields)) return 'EntryPoint({params})'.format(**locals())
Example #30
Source File: utilities_general_v2.py From MachineLearningSamples-ImageClassificationUsingCntk with MIT License | 5 votes |
def listSort(list1D, reverseSort=False, comparisonFct=lambda x: x): indices = list(range(len(list1D))) tmp = sorted(zip(list1D,indices), key=comparisonFct, reverse=reverseSort) list1DSorted, sortOrder = list(map(list, list(zip(*tmp)))) return (list1DSorted, sortOrder) ################################################# # 2D list (e.g. tables) #################################################