code
stringlengths
20
4.93k
docstring
stringlengths
33
1.27k
source
stringclasses
3 values
def __init__(self, name=None, eid=None): if None not in (name, eid): raise TypeError("Provide only a `name` or an `eid`.") self._eid = eid or _get_enum(name) self._comments = EnumComments(self._eid)
Get an existing enum. Only provide one of `name` and `eid`. Args: name: Name of the enum eid: Enum ID
juraj-google-style
def tables_insert(self, table_name, schema=None, query=None, friendly_name=None, description=None): url = (Api._ENDPOINT + (Api._TABLES_PATH % (table_name.project_id, table_name.dataset_id, '', ''))) data = {'kind': 'bigquery if schema: data['schema'] = {'fields': schema} if query: data[...
Issues a request to create a table or view in the specified dataset with the specified id. A schema must be provided to create a Table, or a query must be provided to create a View. Args: table_name: the name of the table as a tuple of components. schema: the schema, if this is a Table creation. query: the query, if t...
codesearchnet
def offTagDel(self, name, func): if ('*' in name): self.ontagdelglobs.rem(name, func) return cblist = self.ontagdels.get(name) if (cblist is None): return try: cblist.remove(func) except ValueError: pass
Unregister a callback for tag deletion. Args: name (str): The name of the tag or tag glob. func (function): The callback func(node, tagname, tagval).
codesearchnet
def __init__(self, line: Optional[Text] = None): self.line = line or self.default_separator super(Separator, self).__init__(self.line, None, "-")
Create a separator in a list. Args: line: Text to be displayed in the list, by default uses `---`.
juraj-google-style
def netmiko_file_transfer(task: Task, source_file: str, dest_file: str, **kwargs: Any) -> Result: net_connect = task.host.get_connection('netmiko', task.nornir.config) kwargs.setdefault('direction', 'put') scp_result = file_transfer(net_connect, source_file=source_file, dest_file=dest_file, **kwargs) if...
Execute Netmiko file_transfer method Arguments: source_file: Source file. dest_file: Destination file. kwargs: Additional arguments to pass to file_transfer Returns: Result object with the following attributes set: * result (``bool``): file exists and MD5 is valid * changed (``bool``): the destination file was change...
codesearchnet
def _ExtractJQuery(self, jquery_raw): data_part = '' if not jquery_raw: return {} if '[' in jquery_raw: _, _, first_part = jquery_raw.partition('[') data_part, _, _ = first_part.partition(']') elif jquery_raw.startswith(' _, _, first_part = jquery_raw.partition('{') d...
Extracts values from a JQuery string. Args: jquery_raw (str): JQuery string. Returns: dict[str, str]: extracted values.
juraj-google-style
def build_tab_completion_table(alias_table): alias_commands = [t[1] for t in filter_aliases(alias_table)] tab_completion_table = defaultdict(list) for alias_command in alias_commands: for reserved_command in azext_alias.cached_reserved_commands: if reserved_command == a...
Build a dictionary where the keys are all the alias commands (without positional argument placeholders) and the values are all the parent commands of the keys. After that, write the table into a file. The purpose of the dictionary is to validate the alias tab completion state. For example: { "group": ["", "ad"], "dns"...
juraj-google-style
def iter(self, max_value: int) -> Iterator[int]: return chain.from_iterable( (self._get_range(elem, max_value) for elem in self.sequences))
Iterates through the sequence numbers contained in the set, bounded by the given maximum value (in place of any ``*``). Args: max_value: The maximum value of the set.
juraj-google-style
def isClientCert(self, name): crtpath = self._getPathJoin('users', '%s.p12' % name) return os.path.isfile(crtpath)
Checks if a user client certificate (PKCS12) exists. Args: name (str): The name of the user keypair. Examples: Check if the client certificate "myuser" exists: exists = cdir.isClientCert('myuser') Returns: bool: True if the certificate is present, False otherwise.
juraj-google-style
def Send(self, command_id, data=b'', size=0): if data: if not isinstance(data, bytes): data = data.encode('utf8') size = len(data) if not self._CanAddToSendBuffer(len(data)): self._Flush() buf = struct.pack(b'<2I', self.id_to_wire[com...
Send/buffer FileSync packets. Packets are buffered and only flushed when this connection is read from. All messages have a response from the device, so this will always get flushed. Args: command_id: Command to send. data: Optional data to send, must set data or size. size: Optionally override size from len(data).
juraj-google-style
def filename(self, fname, timestep=None, suffix='', force_legacy=False): if timestep is not None: fname += '{:05d}'.format(timestep) fname += suffix if not force_legacy and self.hdf5: fpath = self.hdf5 / fname else: fpath = self.par['ioin']['o...
Return name of StagYY output file. Args: fname (str): name stem. timestep (int): snapshot number, set to None if this is not relevant. suffix (str): optional suffix of file name. force_legacy (bool): force returning the legacy output path. Returns: :class:`pathlib.Path`: the path of the output file constructed with th...
juraj-google-style
def resolves_for(self, node): self.node = node self.actual_styles = node.style(*self.expected_styles.keys()) return all( toregex(value).search(self.actual_styles[style]) for style, value in iter(self.expected_styles.items()))
Resolves this query relative to the given node. Args: node (node.Base): The node to be evaluated. Returns: int: The number of matches found.
juraj-google-style
def DeletePendingNotification(self, timestamp): shown_notifications = self.Get(self.Schema.SHOWN_NOTIFICATIONS) if not shown_notifications: shown_notifications = self.Schema.SHOWN_NOTIFICATIONS() pending = self.Get(self.Schema.PENDING_NOTIFICATIONS) if not pending: return ...
Deletes the pending notification with the given timestamp. Args: timestamp: The timestamp of the notification. Assumed to be unique. Raises: UniqueKeyError: Raised if multiple notifications have the timestamp.
juraj-google-style
def remove_volume(self, name, force=False): params = {} if force: if utils.version_lt(self._version, '1.25'): raise errors.InvalidVersion('force removal was introduced in API 1.25') params = {'force': force} url = self._url('/volumes/{0}', name, params=params) resp = self._de...
Remove a volume. Similar to the ``docker volume rm`` command. Args: name (str): The volume's name force (bool): Force removal of volumes that were already removed out of band by the volume driver plugin. Raises: :py:class:`docker.errors.APIError` If volume failed to remove.
codesearchnet
def avg_grads(tower_grads): average_grads = [] for grad_and_vars in zip(*tower_grads): grads = [] for g, _ in grad_and_vars: expanded_g = tf.expand_dims(g, 0) grads.append(expanded_g) grad = tf.concat(0, grads) grad = tf.reduce_mean(grad, 0) ...
Calculate the average gradient for each shared variable across all towers. Note that this function provides a synchronization point across all towers. Args: tower_grads: List of lists of (gradient, variable) tuples. The outer list is over individual gradients. The inner list is over the gradient calculation for each ...
juraj-google-style
def broadcast_dynamic_shape(shape_x, shape_y): if not isinstance(shape_x, RaggedTensorDynamicShape): raise TypeError('shape_x must be a RaggedTensorDynamicShape') if not isinstance(shape_y, RaggedTensorDynamicShape): raise TypeError('shape_y must be a RaggedTensorDynamicShape') if shape_x.ra...
Returns the shape formed by broadcasting two shapes to be compatible. Args: shape_x: A `RaggedTensorDynamicShape` shape_y: A `RaggedTensorDynamicShape` Returns: A `RaggedTensorDynamicShape`. Raises: ValueError: If `shape_x` and `shape_y` are not broadcast-compatible.
github-repos
def remove_chain(self, name): if name in self.chains: delattr(self.chains, name) else: raise ValueError("Chain with this name not found")
Remove chain from current shelve file Args: name: chain name
juraj-google-style
def add_completions( replace_list: list, belstr: str, replace_span: Span, completion_text: str ) -> List[Mapping[str, Any]]: completions = [] for r in replace_list: if len(belstr) > 0: belstr_end = len(belstr) - 1 else: bel...
Create completions to return given replacement list Args: replace_list: list of completion replacement values belstr: BEL String replace_span: start, stop of belstr to replace completion_text: text to use for completion - used for creating highlight Returns: [{ "replacement": replacement, "cursor_loc": cursor_loc, "hi...
juraj-google-style
def to_b58check(self, testnet=False): version = (self.TESTNET_VERSION if testnet else self.MAINNET_VERSION) return base58.b58encode_check((bytes([version]) + bytes(self)))
Generates a Base58Check encoding of this private key. Returns: str: A Base58Check encoded string representing the key.
codesearchnet
def get_package_hashes(filename): log.debug('Getting package hashes') filename = os.path.abspath(filename) with open(filename, 'rb') as f: data = f.read() _hash = hashlib.sha256(data).hexdigest() log.debug('Hash for file %s: %s', filename, _hash) return _hash
Provides hash of given filename. Args: filename (str): Name of file to hash Returns: (str): sha256 hash
juraj-google-style
def core_name(self): buf_size = self.MAX_BUF_SIZE buf = (ctypes.c_char * buf_size)() self._dll.JLINKARM_Core2CoreName(self.core_cpu(), buf, buf_size) return ctypes.string_at(buf).decode()
Returns the name of the target ARM core. Args: self (JLink): the ``JLink`` instance Returns: The target core's name.
juraj-google-style
def bind_sockets(address, port): ss = netutil.bind_sockets(port=(port or 0), address=address) assert len(ss) ports = {s.getsockname()[1] for s in ss} assert (len(ports) == 1), 'Multiple ports assigned??' actual_port = ports.pop() if port: assert (actual_port == port) return (ss, actu...
Bind a socket to a port on an address. Args: address (str) : An address to bind a port on, e.g. ``"localhost"`` port (int) : A port number to bind. Pass 0 to have the OS automatically choose a free port. This function returns a 2-tuple with the new socket as the first element, and the port that was bound as the sec...
codesearchnet
def add_key_value(self, key, value): key = self._metadata_map.get(key, key) if (key in ['dateAdded', 'eventDate', 'firstSeen', 'publishDate']): self._group_data[key] = self._utils.format_datetime(value, date_format='%Y-%m-%dT%H:%M:%SZ') elif (key == 'file_content'): pass else: se...
Add custom field to Group object. .. note:: The key must be the exact name required by the batch schema. Example:: document = tcex.batch.group('Document', 'My Document') document.add_key_value('fileName', 'something.pdf') Args: key (str): The field key to add to the JSON batch data. value (str): The field value to ...
codesearchnet
def copy_docstring(source_class): def decorator(method): 'Decorator implementation.\n\n Args:\n method (Callable): The method to copy the docstring to.\n\n Returns:\n Callable: the same method passed in with an updated docstring.\n\n Raises:\n ValueErro...
Decorator that copies a method's docstring from another class. Args: source_class (type): The class that has the documented method. Returns: Callable: A decorator that will copy the docstring of the same named method in the source class to the decorated method.
codesearchnet
def permut2expr(self, P): if (len(P) > (1 << self.nbits)): raise ValueError(('P must not contain more than %d elements' % (1 << self.nbits))) X = self.var('X') ret = super(MBA, self).permut2expr(P, X.vec) return (self.from_vec(ret), X)
Convert a substitution table into an arybo application Args: P: list of integers. The list must not contain more than 2**nbits elements. Returns: A tuple containing an :class:`MBAVariable` object with the result and the symbolic input variable used in this object. A typical use case is to feed these into vectorial_de...
codesearchnet
def object_table(self, object_id=None): self._check_connected() if object_id is not None: return self._object_table(object_id) else: object_keys = self._keys(ray.gcs_utils.TablePrefix_OBJECT_string + ...
Fetch and parse the object table info for one or more object IDs. Args: object_id: An object ID to fetch information about. If this is None, then the entire object table is fetched. Returns: Information from the object table.
juraj-google-style
def depth_october_average_ground_temperature(self, value=None): if value is not None: try: value = float(value) except ValueError: raise ValueError( 'value {} need to be of type float ' 'for field `depth_oct...
Corresponds to IDD Field `depth_october_average_ground_temperature` Args: value (float): value for IDD Field `depth_october_average_ground_temperature` Unit: C if `value` is None it will not be checked against the specification and is assumed to be a missing value Raises: ValueError: if `value` is not a valid value
juraj-google-style
def addFileHandler(self,filename='', dr='',lvl=1): fname = self.name if filename != '': fname = filename if '.' not in fname: fname+='.log' fh = logging.FileHandler(os.path.join(dr,fname)) fh.setLevel(lvl) frmtString = '%(asctime)s - %(nam...
This function will add a file handler to a log with the provided level. Args: lvl (int): The severity level of messages printed to the file with the file handler, default = 1.
juraj-google-style
def model_spec(ops, matrix): return api.ModelSpec(matrix=np.array(matrix), ops=[INPUT] + ops + [OUTPUT])
NASBench model spec that is parameterized by ops and their connections. Args: ops: a list of allowed ops except the INPUT and OUTPUT layer. matrix: the adjacency matrix for the connectivity of each layers, which should be an upper triangle matrix. Returns: A NASBench spec.
github-repos
def normalize(self, image, mean, std, rescale=False): self._ensure_format_supported(image) if isinstance(image, PIL.Image.Image): image = self.to_numpy_array(image, rescale=True) elif rescale: if isinstance(image, np.ndarray): image = self.rescale(image.astype(np.float32), 1 / 25...
Normalizes `image` with `mean` and `std`. Note that this will trigger a conversion of `image` to a NumPy array if it's a PIL Image. Args: image (`PIL.Image.Image` or `np.ndarray` or `torch.Tensor`): The image to normalize. mean (`List[float]` or `np.ndarray` or `torch.Tensor`): The mean (per channel) to use for normal...
github-repos
def cancelPnL(self, account, modelCode: str = ''): key = (account, modelCode) reqId = self.wrapper.pnlKey2ReqId.pop(key, None) if reqId: self.client.cancelPnL(reqId) self.wrapper.pnls.pop(reqId, None) else: self._logger.error( ...
Cancel PnL subscription. Args: account: Cancel for this account. modelCode: If specified, cancel for this account model.
juraj-google-style
def ParseOptions(cls, options, output_module): if not isinstance(output_module, timesketch_out.TimesketchOutputModule): raise errors.BadConfigObject( 'Output module is not an instance of TimesketchOutputModule') document_type = cls._ParseStringOption( options, 'document_type', defa...
Parses and validates options. Args: options (argparse.Namespace): parser options. output_module (TimesketchOutputModule): output module to configure. Raises: BadConfigObject: when the output module object is of the wrong type. BadConfigOption: when a configuration parameter fails validation.
juraj-google-style
def load_wav_file(filename): with tf.compat.v1.Session(graph=tf.Graph()) as sess: wav_filename_placeholder = tf.compat.v1.placeholder(tf.string, []) wav_loader = io_ops.read_file(wav_filename_placeholder) wav_decoder = tf.audio.decode_wav(wav_loader, desired_channels=1) return sess.r...
Loads an audio file and returns a float PCM-encoded array of samples. Args: filename: Path to the .wav file to load. Returns: Numpy array holding the sample data as floats between -1.0 and 1.0.
github-repos
def loss(logits, labels, batch_size=None): if (not batch_size): batch_size = FLAGS.batch_size sparse_labels = tf.reshape(labels, [batch_size, 1]) indices = tf.reshape(tf.range(batch_size), [batch_size, 1]) concated = tf.concat(axis=1, values=[indices, sparse_labels]) num_classes = logits[0]....
Adds all losses for the model. Note the final loss is not returned. Instead, the list of losses are collected by slim.losses. The losses are accumulated in tower_loss() and summed to calculate the total loss. Args: logits: List of logits from inference(). Each entry is a 2-D float Tensor. labels: Labels from distorte...
codesearchnet
def get_query_info(sql, con, partition_column): engine = create_engine(con) if is_table(engine, sql): table_metadata = get_table_metadata(engine, sql) query = build_query_from_table(sql) cols = get_table_columns(table_metadata) else: check_query(sql) query = sql....
Return a columns name list and the query string Args: sql: SQL query or table name con: database connection or url string partition_column: column used to share the data between the workers Returns: Columns name list and query string
juraj-google-style
def every_match(self, callback, **kwargs): if (len(kwargs) == 0): raise ArgumentError('You must specify at least one message field to wait on') spec = MessageSpec(**kwargs) responder = self._add_waiter(spec, callback) return (spec, responder)
Invoke callback every time a matching message is received. The callback will be invoked directly inside process_message so that you can guarantee that it has been called by the time process_message has returned. The callback can be removed by a call to remove_waiter(), passing the handle object returned by this call ...
codesearchnet
def forward(self, hidden_states: torch.Tensor, position_embeddings: Optional[torch.Tensor]=None, reference_points=None, spatial_shapes=None, spatial_shapes_list=None, level_start_index=None, encoder_hidden_states: Optional[torch.Tensor]=None, encoder_attention_mask: Optional[torch.Tensor]=None, output_attentions: Optio...
Args: hidden_states (`torch.FloatTensor`): Input to the layer of shape `(seq_len, batch, embed_dim)`. position_embeddings (`torch.FloatTensor`, *optional*): Position embeddings that are added to the queries and keys in the self-attention layer. reference_points (`torch.FloatTensor`, *optional*): Reference points. spati...
github-repos
def attach(self, engine, start=Events.STARTED, pause=Events.COMPLETED, resume=None, step=None): engine.add_event_handler(start, self.reset) engine.add_event_handler(pause, self.pause) if (resume is not None): engine.add_event_handler(resume, self.resume) if (step is not None): engine.add...
Register callbacks to control the timer. Args: engine (Engine): Engine that this timer will be attached to. start (Events): Event which should start (reset) the timer. pause (Events): Event which should pause the timer. resume (Events, optional): Event which should resume the timer. step (Events, optional): Event whic...
codesearchnet
def parse_iso8601_str(string): datetime_obj = datetime.datetime.strptime(string, '%Y-%m-%dT%H:%M:%SZ') return int(calendar.timegm(datetime_obj.utctimetuple()))
Parse a fixed ISO8601 datetime string. .. Note:: This function only parses dates in the format ``%Y-%m-%dT%H:%M:%SZ``. You must use a library like ``dateutils`` to properly parse dates and times. Returns: float: A UNIX timestamp.
codesearchnet
def _any_overlap_or_contiguous(self, test_overlap: bool) -> bool: for i in range(len(self.intervals)): for j in range((i + 1), len(self.intervals)): first = self.intervals[i] second = self.intervals[j] if test_overlap: test = first.overlaps(second) ...
Do any of the intervals overlap? Args: test_overlap: if ``True``, test for overlapping intervals; if ``False``, test for contiguous intervals.
codesearchnet
def _bigbird_block_rand_mask(self, from_seq_length, to_seq_length, from_block_size, to_block_size, num_rand_blocks, last_idx=-1): if from_seq_length raise ValueError('Error the number of blocks needs to be same!') rand_attn = np.zeros((from_seq_length if not self.training: return rand_attn...
Create adjacency list of random attention. Args: from_seq_length: int. length of from sequence. to_seq_length: int. length of to sequence. from_block_size: int. size of block in from sequence. to_block_size: int. size of block in to sequence. num_rand_blocks: int. Number of random chunks per row. last_idx: if -1 then ...
github-repos
def _verify_docker_image_size(self, image_name): shell_call(['docker', 'pull', image_name]) try: image_size = subprocess.check_output( ['docker', 'inspect', '--format={{.Size}}', image_name]).strip() image_size = int(image_size) except (ValueError, subprocess.CalledProcessError) a...
Verifies size of Docker image. Args: image_name: name of the Docker image. Returns: True if image size is within the limits, False otherwise.
juraj-google-style
def make_layer_stack(layers=gin.REQUIRED, num_layers=6): return LayerStack([cls() for cls in layers] * num_layers)
Configurable layer stack. Args: layers: a list of subclasses of TransformerLayer num_layers: an integer Returns: a LayerStack
juraj-google-style
def GetPresetsInformation(cls): parser_presets_information = [] for preset_definition in ParsersManager.GetPresets(): preset_information_tuple = (preset_definition.name, ', '.join(preset_definition.parsers)) parser_presets_information.append(preset_information_tuple) return parser_presets_in...
Retrieves the presets information. Returns: list[tuple]: containing: str: preset name str: comma separated parser names that are defined by the preset
codesearchnet
class UnivNetModelOutput(ModelOutput): waveforms: Optional[torch.FloatTensor] = None waveform_lengths: Optional[torch.FloatTensor] = None
Output class for the [`UnivNetModel`], which includes the generated audio waveforms and the original unpadded lengths of those waveforms (so that the padding can be removed by [`UnivNetModel.batch_decode`]). Args: waveforms (`torch.FloatTensor` of shape `(batch_size, sequence_length)`): Batched 1D (mono-channel) outpu...
github-repos
def EnsureGdbPosition(self, pid, tid, frame_depth): position = [pid, tid, frame_depth] if not pid: return if not self.IsAttached(): try: self.Attach(position) except gdb.error as exc: raise PositionUnavailableException(exc.message) if gdb.selected_inferior().pid !=...
Make sure our position matches the request. Args: pid: The process ID of the target process tid: The python thread ident of the target thread frame_depth: The 'depth' of the requested frame in the frame stack Raises: PositionUnavailableException: If the requested process, thread or frame can't be found or accessed.
juraj-google-style
def _kernel(kernel_spec): if isinstance(kernel_spec, tf.compat.integral_types): return [kernel_spec, kernel_spec] elif (len(kernel_spec) == 1): return [kernel_spec[0], kernel_spec[0]] else: assert (len(kernel_spec) == 2) return kernel_spec
Expands the kernel spec into a length 2 list. Args: kernel_spec: An integer or a length 1 or 2 sequence that is expanded to a list. Returns: A length 2 list.
codesearchnet
def connect_to(self, vertex, weight=1): for edge in self.edges_out: if vertex == edge.vertex_in: return edge return Edge(self, vertex, weight)
Connect this vertex to another one. Args: vertex (Vertex): vertex to connect to. weight (int): weight of the edge. Returns: Edge: the newly created edge.
juraj-google-style
def from_storage(source, source_format='csv', csv_options=None, ignore_unknown_values=False, max_bad_records=0, compressed=False, schema=None): result = FederatedTable() if (source_format == 'csv'): result._bq_source_format = 'CSV' if (csv_options is None): csv_options = _csv_options...
Create an external table for a GCS object. Args: source: the URL of the source objects(s). Can include a wildcard '*' at the end of the item name. Can be a single source or a list. source_format: the format of the data, 'csv' or 'json'; default 'csv'. csv_options: For CSV files, the options such as quote character and...
codesearchnet
def padded_urlsafe_b64decode(value): b64string = to_bytes(value) padded = b64string + b'=' * (-len(b64string) % 4) return base64.urlsafe_b64decode(padded)
Decodes base64 strings lacking padding characters. Google infrastructure tends to omit the base64 padding characters. Args: value (Union[str, bytes]): The encoded value. Returns: bytes: The decoded value
juraj-google-style
def _write_cache(step, event_file_suffix=None, **kwargs): file_suffix = _TT_EVENT_FILE_SUFFIX if event_file_suffix is not None: file_suffix = string_ops.string_join([file_suffix, event_file_suffix], separator='.') summary_write_ops = [] summary_writer = summary.create_file_writer_v2(self._parame...
Writes the given caches as tensor summary. Args: step: Step tensor with dimension [num_cores]. event_file_suffix: Event filename suffix tensor. **kwargs: The dictionary of tensors that needs to be written as summaries. Key and value pairs within kwargs correspond to the tag name, and tensor content that will be writte...
github-repos
def consult_filters(self, url_info: URLInfo, url_record: URLRecord, is_redirect: bool=False) -> Tuple[(bool, str, dict)]: if (not self._url_filter): return (True, 'nofilters', None) test_info = self._url_filter.test_info(url_info, url_record) verdict = test_info['verdict'] if verdict: re...
Consult the URL filter. Args: url_record: The URL record. is_redirect: Whether the request is a redirect and it is desired that it spans hosts. Returns tuple: 1. bool: The verdict 2. str: A short reason string: nofilters, filters, redirect 3. dict: The result from :func:`DemuxURLFilter.test_info`
codesearchnet
def path_to_text(self, path): rsrcmgr = PDFResourceManager() retstr = StringIO() codec = 'utf-8' laparams = LAParams() device = TextConverter(rsrcmgr, retstr, codec=codec, laparams=laparams) fp = open(path, 'rb') interpreter = PDFPageInterpreter(rsrcmgr, ...
Transform local PDF file to string. Args: path: path to PDF file. Returns: string.
juraj-google-style
def paragraphs(self, index = None): if index is None: return self.select(Paragraph,None,True,default_ignore_structure) else: if index < 0: index = self.count(Paragraph,None,True,default_ignore_structure) + index for i,e in enumerate(self.selec...
Returns a generator of Paragraph elements found (recursively) under this element. Arguments: index (int or None): If set to an integer, will retrieve and return the n'th element (starting at 0) instead of returning the generator of all
juraj-google-style
def _callEventWaitAndGet(self, callback_id, event_name, timeout): timeout_ms = int(timeout * 1000) return self._event_client.eventWaitAndGet(callback_id, event_name, timeout_ms)
Calls snippet lib's eventWaitAndGet. Override this method to use this class with various snippet lib implementations. Args: callback_id: The callback identifier. event_name: The callback name. timeout: The number of seconds to wait for the event. Returns: The event dictionary.
github-repos
def format(self, record): if record.levelno >= logging.ERROR: color = colorama.Fore.RED elif record.levelno >= logging.WARNING: color = colorama.Fore.YELLOW elif record.levelno >= logging.INFO: color = colorama.Fore.RESET else: ...
Format the log record with timestamps and level based colors. Args: record: The log record to format. Returns: The formatted log record.
juraj-google-style
def ParseFileObject(self, parser_mediator, file_object): data = file_object.read(self._HEADER_READ_SIZE) if (not data.startswith(b'<?xml')): raise errors.UnableToParseFile('Not an Android usage history file [not XML]') (_, _, data) = data.partition(b'\n') if (not data.startswith(b'<usage-history...
Parses an Android usage-history file-like object. Args: parser_mediator (ParserMediator): mediates interactions between parsers and other components, such as storage and dfvfs. file_object (dfvfs.FileIO): file-like object. Raises: UnableToParseFile: when the file cannot be parsed.
codesearchnet
def get_qubit_los(self, user_lo_config): try: _q_los = self.default_qubit_los.copy() except KeyError: raise PulseError('Qubit default frequencies not exist.') for (channel, lo_freq) in user_lo_config.qubit_lo_dict().items(): _q_los[channel.index] = lo_freq if (_q_los == self.defa...
Embed default qubit LO frequencies from backend and format them to list object. If configured lo frequency is the same as default, this method returns `None`. Args: user_lo_config (LoConfig): A dictionary of LOs to format. Returns: list: A list of qubit LOs. Raises: PulseError: when LO frequencies are missing.
codesearchnet
def set_category(self, category): pcategory = self.find("general/category") pcategory.clear() name = ElementTree.SubElement(pcategory, "name") if isinstance(category, Category): id_ = ElementTree.SubElement(pcategory, "id") id_.text = category.id ...
Set the policy's category. Args: category: A category object.
juraj-google-style
def roll_to_business_day(self, date_tensor, roll_convention): pass
Rolls the given dates to business dates according to given convention. Args: date_tensor: DateTensor of dates to roll from. roll_convention: BusinessDayConvention. Determines how to roll a date that falls on a holiday. Returns: The resulting DateTensor.
github-repos
def incomplete_size(self, name=None): if name is None: name = '%s_BarrierIncompleteSize' % self._name return gen_data_flow_ops.barrier_incomplete_size(self._barrier_ref, name=name)
Compute the number of incomplete elements in the given barrier. Args: name: A name for the operation (optional). Returns: A single-element tensor containing the number of incomplete elements in the given barrier.
github-repos
def least_squares_effective_mass( cartesian_k_points, eigenvalues ): if not points_are_in_a_straight_line( cartesian_k_points ): raise ValueError( 'k-points are not collinear' ) dk = cartesian_k_points - cartesian_k_points[0] mod_dk = np.linalg.norm( dk, axis = 1 ) delta_e = eigenvalues - e...
Calculate the effective mass using a least squares quadratic fit. Args: cartesian_k_points (np.array): Cartesian reciprocal coordinates for the k-points eigenvalues (np.array): Energy eigenvalues at each k-point to be used in the fit. Returns: (float): The fitted effective mass Notes: If the k-points do not s...
juraj-google-style
def buckingham_input(self, structure, keywords, library=None, uc=True, valence_dict=None): gin = self.keyword_line(*keywords) gin += self.structure_lines(structure, symm_flg=not uc) if not library: gin += self.buckingham_potential(structure, valence_...
Gets a GULP input for an oxide structure and buckingham potential from library. Args: structure: pymatgen.core.structure.Structure keywords: GULP first line keywords. library (Default=None): File containing the species and potential. uc (Default=True): Unit Cell Flag. valence_dict: {El: valence}
juraj-google-style
def __init__(self, baseplate, token, actor_urn, *args, **kwargs): self.baseplate = baseplate self.rest_baseurl = 'https: self.token = token self.headers = {"Authorization": "Bot {}".format(token), "User-Agent": "Legobot", "Content...
Initialize DiscoBot Args: baseplate (Legobot.Lego): The parent Pykka actor. Typically passed in from Legobot.Connectors.Discord.Discord token (string): Discord bot token actor_urn (string): URN of Pykka actor launching DiscoBot *args: Variable length argument list. **kwargs: Arbitrary keyword arguments.
juraj-google-style
def get_threads(self, page=1): url = self._url.page_url(page) return self._request_threads(url)
Returns all threads on a certain page. Gets a list of Thread objects for every thread on the given page. If a thread is already in our cache, the cached version is returned and thread.want_update is set to True on the specific thread object. Pages on 4chan are indexed from 1 onwards. Args: page (int): Page to reques...
codesearchnet
def weights_multi_problem(labels, taskid=-1): taskid = check_nonnegative(taskid) past_taskid = tf.cumsum(to_float(tf.equal(labels, taskid)), axis=1) past_taskid *= to_float(tf.not_equal(labels, taskid)) non_taskid = to_float(labels) return to_float(tf.not_equal(past_taskid * non_taskid, 0))
Assign weight 1.0 to only the "targets" portion of the labels. Weight 1.0 is assigned to all labels past the taskid. Args: labels: A Tensor of int32s. taskid: an int32 representing the task id for a problem. Returns: A Tensor of floats. Raises: ValueError: The Task ID must be valid.
juraj-google-style
def _patch_expand_path(self, settings, name, value): if os.path.isabs(value): return os.path.normpath(value) value = os.path.expanduser(value) if ((not os.path.isabs(value)) and self.projectdir): value = os.path.join(self.projectdir, value) return os.path.normpath(value)
Patch a path to expand home directory and make absolute path. Args: settings (dict): Current settings. name (str): Setting name. value (str): Path to patch. Returns: str: Patched path to an absolute path.
codesearchnet
def from_yang(self, text: str) -> ScalarValue: res = self.parse_value(text) if (res is None): raise InvalidArgument(text) return res
Parse value specified in a YANG module. Args: text: String representation of the value. Raises: InvalidArgument: If the receiver type cannot parse the text.
codesearchnet
def print_solution(model, solver): model_proto = model.Proto() response_proto = solver.ResponseProto() variables_in_objective_map = {} maximization = False if model_proto.HasField('objective'): objective = model_proto.objective for i in range(len(objective.vars)): variabl...
Prints the solution associated with solver. If solver has already had Solve() called on it, prints the solution. This includes each variable and its assignment, along with the objective function and its optimal value. If solver has not had Solve() called on it, or there is no feasible solution, this will probably cras...
codesearchnet
def check_status(self, **kwargs): for work in self: work.check_status() if kwargs.pop('show', False): self.show_status(**kwargs)
Check the status of the works in self. Args: show: True to show the status of the flow. kwargs: keyword arguments passed to show_status
codesearchnet
def RegisterRecordType(cls, record_class): record_type = record_class.MatchType() if (record_type not in UpdateRecord.KNOWN_CLASSES): UpdateRecord.KNOWN_CLASSES[record_type] = [] UpdateRecord.KNOWN_CLASSES[record_type].append(record_class)
Register a known record type in KNOWN_CLASSES. Args: record_class (UpdateRecord): An update record subclass.
codesearchnet
def run_from_cli(self, args): if args['--dump-config']: self._config.print_config() else: (stdout, stderr) = self.lint(args['<path>']) self.print_results(stdout, stderr)
Read arguments, run and print results. Args: args (dict): Arguments parsed by docopt.
codesearchnet
def ParsePartitionsTable( self, parser_mediator, database=None, table=None, **unused_kwargs): if database is None: raise ValueError('Missing database value.') if table is None: raise ValueError('Missing table value.') for esedb_record in table.records: if parser_mediator.abort...
Parses the Partitions table. Args: parser_mediator (ParserMediator): mediates interactions between parsers and other components, such as storage and dfvfs. database (Optional[pyesedb.file]): ESE database. table (Optional[pyesedb.table]): table. Raises: ValueError: if the database or table value is missing.
juraj-google-style
def get_db_row(db, start, size): type_ = snap7.snap7types.wordlen_to_ctypes[snap7.snap7types.S7WLByte] data = client.db_read(db, start, type_, size) return data
Here you see and example of readying out a part of a DB Args: db (int): The db to use start (int): The index of where to start in db data size (int): The size of the db data to read
juraj-google-style
def mkdirs(path): filesystem = FileSystems.get_filesystem(path) return filesystem.mkdirs(path)
Recursively create directories for the provided path. Args: path: string path of the directory structure that should be created Raises: IOError: if leaf directory already exists.
github-repos
def node_run(input_file, coords_only, bc_settings, bc_grid_weights): log = logging.getLogger('pyspark') log.setLevel(logging.INFO) if (len(log.handlers) == 0): log.addHandler(logging.StreamHandler(sys.stdout)) precision = bc_settings.value['precision'] imager = oskar.Imager(precision) fo...
Main function to process visibility data on Spark cluster nodes. Args: input_file (str): RDD element containing filename to process. coords_only (boolean): If true, read only baseline coordinates to define the weights grid. bc_settings (pyspark.broadcast.Broadcast): Spark broadcast variable containing pipeline setting...
codesearchnet
def configure_stream(level='WARNING'): root_logger = logging.getLogger() root_logger.setLevel(level) template = '[%(asctime)s] %(name)-25s %(levelname)-8s %(message)s' formatter = logging.Formatter(template) console = logging.StreamHandler() console.setLevel(level) console.setFormatter(forma...
Configure root logger using a standard stream handler. Args: level (string, optional): lowest level to log to the console Returns: logging.RootLogger: root logger instance with attached handler
codesearchnet
def eval_image(image, height, width, scope=None): with tf.name_scope(values=[image, height, width], name=scope, default_name='eval_image'): image = tf.image.central_crop(image, central_fraction=0.875) image = tf.expand_dims(image, 0) image = tf.image.resize_bilinear...
Prepare one image for evaluation. Args: image: 3-D float Tensor height: integer width: integer scope: Optional scope for name_scope. Returns: 3-D float Tensor of prepared image.
juraj-google-style
def serialize_cert_to_pem(cert_obj): return cert_obj.public_bytes(encoding=cryptography.hazmat.primitives.serialization.Encoding.PEM)
Serialize certificate to PEM. The certificate can be also be a Certificate Signing Request (CSR). Args: cert_obj: cryptography.Certificate Returns: bytes: PEM encoded certificate
codesearchnet
def get_summary_dict(self, include_msd_t=False, include_mscd_t=False): d = { "D": self.diffusivity, "D_sigma": self.diffusivity_std_dev, "D_charge": self.chg_diffusivity, "D_charge_sigma": self.chg_diffusivity_std_dev, "S": self.conductivity, ...
Provides a summary of diffusion information. Args: include_msd_t (bool): Whether to include mean square displace and time data with the data. include_msd_t (bool): Whether to include mean square charge displace and time data with the data. Returns: (dict) of diffusion and conductivity data.
juraj-google-style
def _get_summary_signatures(self): signatures = self._flag_value_as_list(FLAG_NAME_SUMMARY_SIGNATURES) supported_signatures = self._supported_signatures() tt_signatures = [] for signature in signatures: signature_with_prefix = '%s_%s' % (_TT_PREFIX, signature) if signature in supported_s...
Verifies and returns the summary signatures. Returns: A dictionary of the signature identifiers {signature: index} that will be computed when trace_mode is summary.
github-repos
def SplitKeyPath(key_path, path_separator=definitions.KEY_PATH_SEPARATOR): return list(filter(None, key_path.split(path_separator)))
Splits the key path into path segments. Args: key_path (str): key path. path_separator (Optional[str]): path separator. Returns: list[str]: key path segments without the root path segment, which is an empty string.
juraj-google-style
def get_cache_key(**kwargs): key = '__'.join(['{}:{}'.format(item, value) for (item, value) in iteritems(kwargs)]) return hashlib.md5(key.encode('utf-8')).hexdigest()
Get MD5 encoded cache key for given arguments. Here is the format of key before MD5 encryption. key1:value1__key2:value2 ... Example: >>> get_cache_key(site_domain="example.com", resource="enterprise") # Here is key format for above call # "site_domain:example.com__resource:enterprise" a54349175618ff1659dee0978e3149c...
codesearchnet
def _dispatch_command(self, command): if command in self.CLI_EXIT_COMMANDS: return debugger_cli_common.EXPLICIT_USER_EXIT try: prefix, args, output_file_path = self._parse_command(command) except SyntaxError as e: print(str(e)) return if self._command_handler_registry.is_...
Dispatch user command. Args: command: (str) Command to dispatch. Returns: An exit token object. None value means that the UI loop should not exit. A non-None value means the UI loop should exit.
github-repos
def get_proposed_feature(project): change_collector = ChangeCollector(project) collected_changes = change_collector.collect_changes() try: new_feature_info = one_or_raise(collected_changes.new_feature_info) importer, _, _ = new_feature_info except ValueError: raise BalletErr...
Get the proposed feature The path of the proposed feature is determined by diffing the project against a comparison branch, such as master. The feature is then imported from that path and returned. Args: project (ballet.project.Project): project info Raises: ballet.exc.BalletError: more than one feature collected
juraj-google-style
def __init__(self, *dic): super().__init__() self.value = [ArraySingle()] self.l = self.value[0].value
init Args: *dic (dict): dictionary with format {'Day': 12, 'Hour': 34} Avaliable keys are Month, Day, Weekday, Hour, Minute. *Note the uppercase.* You can use gen(), genMix() to generate complex config dictionary.
juraj-google-style
def line_iter(xo: int, yo: int, xd: int, yd: int) -> Iterator[Tuple[int, int]]: data = ffi.new("TCOD_bresenham_data_t *") lib.TCOD_line_init_mt(xo, yo, xd, yd, data) x = ffi.new("int *") y = ffi.new("int *") yield xo, yo while not lib.TCOD_line_step_mt(x, y, data): yield (x[0], y[0]...
returns an Iterable This Iterable does not include the origin point. Args: xo (int): X starting point. yo (int): Y starting point. xd (int): X destination point. yd (int): Y destination point. Returns: Iterable[Tuple[int,int]]: An Iterable of (x,y) points.
juraj-google-style
def fingerprint(self): return gen_dataset_ops.dataset_fingerprint(self._variant_tensor)
Computes the fingerprint of this `Dataset`. If two datasets have the same fingerprint, it is guaranteed that they would produce identical elements as long as the content of the upstream input files does not change and they produce data deterministically. However, two datasets producing identical values does not alway...
github-repos
def parse_frequencies(variant, transcripts): frequencies = {} thousand_genomes_keys = ['1000GAF'] thousand_genomes_max_keys = ['1000G_MAX_AF'] exac_keys = ['EXACAF'] exac_max_keys = ['ExAC_MAX_AF', 'EXAC_MAX_AF'] gnomad_keys = ['GNOMADAF', 'GNOMAD_AF'] gnomad_max_keys = ['GNOMADAF_POPMAX', '...
Add the frequencies to a variant Frequencies are parsed either directly from keys in info fieds or from the transcripts is they are annotated there. Args: variant(cyvcf2.Variant): A parsed vcf variant transcripts(iterable(dict)): Parsed transcripts Returns: frequencies(dict): A dictionary with the relevant frequenci...
codesearchnet
def list_groups(self, filtr=None): return self.service.list_groups( filtr, self.url_prefix, self.auth, self.session, self.session_send_opts)
Get the groups the logged in user is a member of. Optionally filter by 'member' or 'maintainer'. Args: filtr (optional[string|None]): ['member'|'maintainer'] or defaults to None. Returns: (list[string]): List of group names. Raises: requests.HTTPError on failure.
juraj-google-style
def get_sv_variants(self, chromosome=None, end_chromosome=None, sv_type=None, pos=None, end=None): query = {} if chromosome: query['chrom'] = chromosome if end_chromosome: query['end_chrom'] = end_chromosome if sv_type: query['sv_type'] = sv_type if pos: if (not ('$an...
Return all structural variants in the database Args: chromosome (str) end_chromosome (str) sv_type (str) pos (int): Left position of SV end (int): Right position of SV Returns: variants (Iterable(Variant))
codesearchnet
def is_ready(self, node_id, metadata_priority=True): if (not self._can_send_request(node_id)): return False if metadata_priority: if self._metadata_refresh_in_progress: return False if (self.cluster.ttl() == 0): return False return True
Check whether a node is ready to send more requests. In addition to connection-level checks, this method also is used to block additional requests from being sent during a metadata refresh. Arguments: node_id (int): id of the node to check metadata_priority (bool): Mark node as not-ready if a metadata refresh is requ...
codesearchnet
def evpn_instance_rd_auto(self, **kwargs): config = ET.Element('config') rbridge_id = ET.SubElement(config, 'rbridge-id', xmlns='urn:brocade.com:mgmt:brocade-rbridge') rbridge_id_key = ET.SubElement(rbridge_id, 'rbridge-id') rbridge_id_key.text = kwargs.pop('rbridge_id') evpn_instance = ET.SubElemen...
Add RD auto under EVPN instance. Args: rbridge_id: Rbrdige id . instance_name: EVPN instance name. Returns: True if command completes successfully or False if not. Raises: None Examples: >>> import pynos.device >>> switches = ['10.24.39.211', '10.24.39.203'] >>> auth = ('admin', 'password') >>> for switch in switche...
codesearchnet
def patch_apply(self, patches, text): if not patches: return (text, []) patches = self.patch_deepCopy(patches) nullPadding = self.patch_addPadding(patches) text = nullPadding + text + nullPadding self.patch_splitMax(patches) delta = 0 results = [] f...
Merge a set of patches onto the text. Return a patched text, as well as a list of true/false values indicating which patches were applied. Args: patches: Array of Patch objects. text: Old text. Returns: Two element Array, containing the new text and an array of boolean values.
juraj-google-style
def sample_from_likelihood(self, n_timesteps=10): self.latent_state_sequences = lmap((lambda A: ltake(n_timesteps, iterate((lambda s: pd.Series((A @ s.values), index=s.index)), self.s0))), self.transition_matrix_collection) self.observed_state_sequences = [[self.sample_observed_state(s) for s in latent_state_se...
Sample a collection of observed state sequences from the likelihood model given a collection of transition matrices. Args: n_timesteps: The number of timesteps for the sequences.
codesearchnet
def merge_level_and_latent_dist(level_dist, latent_dist, merge_std='prev_level'): (level_mean, level_std) = (level_dist.loc, level_dist.scale) (latent_mean, latent_std) = (latent_dist.loc, latent_dist.scale) new_mean = (level_mean + latent_mean) if (merge_std == 'normal'): z_shape = common_layer...
Merge level_dist and latent_dist. new_dist ~ N(level_dist.mean + latent_dis.mean, std) where std is determined according to merge_std. Args: level_dist: instance of tfp.distributions.Normal latent_dist: instance of tfp.distributions.Normal merge_std: can be "prev_level", "prev_step" or "normal". Returns: merged_dist:...
codesearchnet
def if_true(self, predicate: Callable[..., bool]): return Conditional(predicate, self, None)
Conditionally applies current operation when predicate returns True. Args: predicate: The predicate that takes the outputs from the previous operation as input, with optional keyword arguments `global_state` and `step`. Returns True if current operation needs to be enabled. Otherwise no operation will be performed. R...
github-repos
def start_logging(self, region, name): ct = self.session.client('cloudtrail', region_name=region) ct.start_logging(Name=name) auditlog(event='cloudtrail.start_logging', actor=self.ns, data={'account': self.account.account_name, 'region': region}) self.log.info('Enabled logging for {} ({})'.format(name, ...
Turn on logging for a CloudTrail Trail Args: region (`str`): Name of the AWS region name (`str`): Name of the CloudTrail Trail Returns: `None`
codesearchnet
def get_min_muO2(self, min_voltage=None, max_voltage=None): data = [] for pair in self._select_in_voltage_range(min_voltage, max_voltage): if (pair.muO2_discharge is not None): data.extend([d['chempot'] for d in pair.muO2_discharge]) if (pair.muO2_charge is not None): dat...
Minimum critical oxygen chemical potential along path. Args: min_voltage: The minimum allowable voltage for a given step max_voltage: The maximum allowable voltage allowable for a given step Returns: Minimum critical oxygen chemical of all compounds along the insertion path (a subset of the path can be chosen by the ...
codesearchnet
def applies_to(self, transition, from_state=None): if '*' in self.names: return True elif self.kind in (HOOK_BEFORE, HOOK_AFTER, HOOK_CHECK): return self._match_transition(transition) elif self.kind == HOOK_ON_ENTER: return self._match_state(transitio...
Whether this hook applies to the given transition/state. Args: transition (Transition): the transition to check from_state (State or None): the state to check. If absent, the check is 'might this hook apply to the related transition, given a valid source state'.
juraj-google-style