本文整理匯總了Python中builtins.map方法的典型用法代碼示例。如果您正苦於以下問題:Python builtins.map方法的具體用法?Python builtins.map怎麽用?Python builtins.map使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類builtins
的用法示例。
在下文中一共展示了builtins.map方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: is_instance_factory
# 需要導入模塊: import builtins [as 別名]
# 或者: from builtins import map [as 別名]
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
示例2: get_ast
# 需要導入模塊: import builtins [as 別名]
# 或者: from builtins import map [as 別名]
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,
}
示例3: anything_beetween
# 需要導入模塊: import builtins [as 別名]
# 或者: from builtins import map [as 別名]
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)
示例4: _update_column_metadata
# 需要導入模塊: import builtins [as 別名]
# 或者: from builtins import map [as 別名]
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")
示例5: info_namespace_statistics
# 需要導入模塊: import builtins [as 別名]
# 或者: from builtins import map [as 別名]
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
示例6: filter_file_list
# 需要導入模塊: import builtins [as 別名]
# 或者: from builtins import map [as 別名]
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
示例7: is_binary_file
# 需要導入模塊: import builtins [as 別名]
# 或者: from builtins import map [as 別名]
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
示例8: _assert_valid_axes_map
# 需要導入模塊: import builtins [as 別名]
# 或者: from builtins import map [as 別名]
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)
示例9: protobuf_scalar_to_python
# 需要導入模塊: import builtins [as 別名]
# 或者: from builtins import map [as 別名]
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)
示例10: protobuf_attr_to_python
# 需要導入模塊: import builtins [as 別名]
# 或者: from builtins import map [as 別名]
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))
示例11: make_cphase_df
# 需要導入模塊: import builtins [as 別名]
# 或者: from builtins import map [as 別名]
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
示例12: make_bsp_df
# 需要導入模塊: import builtins [as 別名]
# 或者: from builtins import map [as 別名]
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
示例13: match_multiple_frames
# 需要導入模塊: import builtins [as 別名]
# 或者: from builtins import map [as 別名]
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
示例14: standardize
# 需要導入模塊: import builtins [as 別名]
# 或者: from builtins import map [as 別名]
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
示例15: get_broadcast_funcs
# 需要導入模塊: import builtins [as 別名]
# 或者: from builtins import map [as 別名]
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)