code stringlengths 20 4.93k | docstring stringlengths 33 1.27k | source stringclasses 3
values |
|---|---|---|
def stop_loss(self, accountID, **kwargs):
return self.create(accountID, order=StopLossOrderRequest(**kwargs)) | Shortcut to create a Stop Loss Order in an Account
Args:
accountID : The ID of the Account
kwargs : The arguments to create a StopLossOrderRequest
Returns:
v20.response.Response containing the results from submitting
the request | codesearchnet |
def _await_flow(self, client, flow_id):
print('{0:s}: Waiting to finish'.format(flow_id))
while True:
try:
status = client.Flow(flow_id).Get().data
except grr_errors.UnknownError:
msg = 'Unable to stat flow {0:s} for host {1:s}'.format(flow_id, client.data.os_info.fqdn.lo... | Awaits flow completion.
Args:
client: GRR Client object in which to await the flow.
flow_id: string containing ID of flow to await.
Raises:
DFTimewolfError: if flow error encountered. | codesearchnet |
def blit(
self,
dest: tcod.console.Console,
fill_fore: bool = True,
fill_back: bool = True,
) -> None:
if not dest:
dest = tcod.console.Console._from_cdata(ffi.NULL)
if dest.width != self.width or dest.height != self.height:
raise Valu... | Use libtcod's "fill" functions to write the buffer to a console.
Args:
dest (Console): Console object to modify.
fill_fore (bool):
If True, fill the foreground color and characters.
fill_back (bool):
If True, fill the background color. | juraj-google-style |
def normalize_placeholders(arg, inject_quotes=False):
number_placeholders = re.findall('{{\\s*\\d+\\s*}}', arg)
for number_placeholder in number_placeholders:
number = re.search('\\d+', number_placeholder).group()
arg = arg.replace(number_placeholder, (('{{_' + number) + '}}'))
return (arg.r... | Normalize placeholders' names so that the template can be ingested into Jinja template engine.
- Jinja does not accept numbers as placeholder names, so add a "_"
before the numbers to make them valid placeholder names.
- Surround placeholders expressions with "" so we can preserve spaces inside the positional arguments... | codesearchnet |
def _get_course_content(course_id, course_url, sailthru_client, site_code, config):
cache_key = '{}:{}'.format(site_code, course_url)
response = cache.get(cache_key)
if (not response):
try:
sailthru_response = sailthru_client.api_get('content', {'id': course_url})
if (not sai... | Get course information using the Sailthru content api or from cache.
If there is an error, just return with an empty response.
Arguments:
course_id (str): course key of the course
course_url (str): LMS url for course info page.
sailthru_client (object): SailthruClient
site_code (str): site code
config (dict): config ... | codesearchnet |
def find_or_build(cls, **kwargs):
keys = (kwargs.pop('keys') if ('keys' in kwargs) else [])
return (cls.first(**subdict(kwargs, keys)) or cls.build(**kwargs)) | Checks if an instance already exists in db with these kwargs else
returns a new, saved instance of the service's model class.
Args:
**kwargs: instance parameters | codesearchnet |
def fit(self, X=None, y=None, **kwargs):
context = {'X': X, 'y': y}
context.update(kwargs)
last_block_name = list(self.blocks.keys())[(- 1)]
for (block_name, block) in self.blocks.items():
LOGGER.debug('Fitting block %s', block_name)
try:
fit_args = self._get_block_args(block... | Fit the blocks of this pipeline.
Sequentially call the `fit` and the `produce` methods of each block,
capturing the outputs each `produce` method before calling the `fit`
method of the next one.
During the whole process a context dictionary is built, where both the
passed arguments and the captured outputs of the `pr... | codesearchnet |
def combine_first_two_dimensions(x):
ret = tf.reshape(x, tf.concat([[(- 1)], common_layers.shape_list(x)[2:]], 0))
old_shape = x.get_shape().dims
(a, b) = old_shape[:2]
new_shape = ([((a * b) if (a and b) else None)] + old_shape[2:])
ret.set_shape(new_shape)
return ret | Reshape x so that the first two dimension become one.
Args:
x: a Tensor with shape [a, b, ...]
Returns:
a Tensor with shape [ab, ...] | codesearchnet |
def __init__(self, resolver_context, file_data):
super(FakeFile, self).__init__(resolver_context)
self._current_offset = 0
self._file_data = file_data
self._size = 0 | Initializes a file-like object.
Args:
resolver_context (Context): resolver context.
file_data (bytes): fake file data. | juraj-google-style |
def flush(self, hard=False):
if (not self.servers):
return
if hard:
self.client.flush_all()
self.reset_stats()
else:
from uuid import uuid4
tag = uuid4().hex
if self.debug:
tag = ('flushed' + tag)
self.current = tag | Drop existing entries from the cache.
Args:
hard (bool): If True, all current entries are flushed from the
server(s), which affects all users. If False, only the local
process is affected. | codesearchnet |
def sas_logical_interconnect_groups(self):
if (not self.__sas_logical_interconnect_groups):
self.__sas_logical_interconnect_groups = SasLogicalInterconnectGroups(self.__connection)
return self.__sas_logical_interconnect_groups | Gets the SasLogicalInterconnectGroups API client.
Returns:
SasLogicalInterconnectGroups: | codesearchnet |
def get_decomp_and_e_above_hull(self, entry, allow_negative=False):
if (entry in self.stable_entries):
return ({entry: 1}, 0)
comp = entry.composition
(facet, simplex) = self._get_facet_and_simplex(comp)
decomp_amts = simplex.bary_coords(self.pd_coords(comp))
decomp = {self.qhull_entries[f]:... | Provides the decomposition and energy above convex hull for an entry.
Due to caching, can be much faster if entries with the same composition
are processed together.
Args:
entry: A PDEntry like object
allow_negative: Whether to allow negative e_above_hulls. Used to
calculate equilibrium reaction energies. Defaults to ... | codesearchnet |
def attention_lm_prepare_decoder(targets, hparams):
if hparams.prepend_mode == "prepend_inputs_full_attention":
decoder_self_attention_bias = (
common_attention.attention_bias_prepend_inputs_full_attention(
common_attention.embedding_to_padding(targets)))
else:
decoder_self_attention_... | Prepare one shard of the model for the decoder.
Args:
targets: a Tensor.
hparams: run hyperparameters
Returns:
decoder_input: a Tensor, bottom of decoder stack
decoder_self_attention_bias: a Tensor, containing large negative values
to implement masked attention and possibly biases for diagonal alignments | juraj-google-style |
def is_native_xmon_op(op: ops.Operation) -> bool:
return (isinstance(op, ops.GateOperation) and
is_native_xmon_gate(op.gate)) | Check if the gate corresponding to an operation is a native xmon gate.
Args:
op: Input operation.
Returns:
True if the operation is native to the xmon, false otherwise. | juraj-google-style |
def get_saved_issue_data(self, issue, namespace='open'):
if isinstance(issue, int):
issue_number = str(issue)
elif isinstance(issue, basestring):
issue_number = issue
else:
issue_number = issue.number
issue_data_key = self._issue_data_key(na... | Returns issue data from local data.
Args:
issue:
`int`. Github issue number.
namespace:
`str`. Namespace for storing this issue. | juraj-google-style |
def handle_command(command):
try:
cmds = command.split(None, 1)
cmd = cmds[0]
if cmd == 'new':
add_task(get_arg(cmds))
elif cmd == 'done':
mark_done(int(get_arg(cmds)))
elif cmd == 'list':
for task in format_tasks(list_tasks()):
print task
elif cmd == 'delete':
... | Accepts a string command and performs an action.
Args:
command: the command to run as a string. | juraj-google-style |
def list(self, **kwargs):
resp = self.client.api.volumes(**kwargs)
if not resp.get('Volumes'):
return []
return [self.prepare_model(obj) for obj in resp['Volumes']] | List volumes. Similar to the ``docker volume ls`` command.
Args:
filters (dict): Server-side list filtering options.
Returns:
(list of :py:class:`Volume`): The volumes.
Raises:
:py:class:`docker.errors.APIError`
If the server returns an error. | juraj-google-style |
def dp020(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 `dp020`'.format(value))
self._dp020 = value | Corresponds to IDD Field `dp020`
Dew-point temperature corresponding to 2.0% annual cumulative frequency of occurrence
Args:
value (float): value for IDD Field `dp020`
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... | codesearchnet |
def _execute(self, command, data=None, unpack=True):
if not data:
data = {}
data.setdefault('element_id', self.element_id)
return self._driver._execute(command, data, unpack) | Private method to execute command with data.
Args:
command(Command): The defined command.
data(dict): The uri variable and body.
Returns:
The unwrapped value field in the json response. | juraj-google-style |
def __init__(self, tensor_callable, dtype, device):
super().__init__(tensor_callable, None, None, dtype, device) | Initializes a `Callable` object.
Args:
tensor_callable: A callable that takes no arguments and returns a Tensor.
dtype: Dtype of the tensor returned by the callable.
device: Device of the tensor returned by the callable. | github-repos |
def get_dropout(x, rate=0.0, init=True):
if init or rate == 0:
return x
return tf.layers.dropout(x, rate=rate, training=True) | Dropout x with dropout_rate = rate.
Apply zero dropout during init or prediction time.
Args:
x: 4-D Tensor, shape=(NHWC).
rate: Dropout rate.
init: Initialization.
Returns:
x: activations after dropout. | juraj-google-style |
def _reset_non_empty(self, indices):
observ = tf.py_func(
self._batch_env.reset, [indices], self.observ_dtype, name="reset")
observ.set_shape(indices.get_shape().concatenate(self.observ_shape))
with tf.control_dependencies([
tf.scatter_update(self._observ, indices, observ)]):
retu... | Reset the batch of environments.
Args:
indices: The batch indices of the environments to reset; defaults to all.
Returns:
Batch tensor of the new observations. | juraj-google-style |
def ConcatWith(x, tensor, dim):
if type(tensor) != list:
tensor = [tensor]
return tf.concat([x] + tensor, dim) | A wrapper around ``tf.concat`` to cooperate with :class:`LinearWrap`.
Args:
x (tf.Tensor): input
tensor (list[tf.Tensor]): a tensor or list of tensors to concatenate with x.
x will be at the beginning
dim (int): the dimension along which to concatenate
Returns:
tf.Tensor: ``tf.concat([x] + tensor, dim)`` | juraj-google-style |
def _copy_stream_position(position):
if isinstance(position, types.StreamPosition):
output = types.StreamPosition()
output.CopyFrom(position)
return output
return types.StreamPosition(**position) | Copy a StreamPosition.
Args:
position (Union[ \
dict, \
~google.cloud.bigquery_storage_v1beta1.types.StreamPosition \
]):
StreamPostion (or dictionary in StreamPosition format) to copy.
Returns:
~google.cloud.bigquery_storage_v1beta1.types.StreamPosition:
A copy of the input StreamPostion. | juraj-google-style |
def Get(self, key):
if key not in self._hash:
raise KeyError(key)
node = self._hash[key]
self._age.Unlink(node)
self._age.AppendNode(node)
return node.data | Fetch the object from cache.
Objects may be flushed from cache at any time. Callers must always
handle the possibility of KeyError raised here.
Args:
key: The key used to access the object.
Returns:
Cached object.
Raises:
KeyError: If the object is not present in the cache. | juraj-google-style |
def add_model_tags(self, tags: Union[List[str], str]) -> None:
if isinstance(tags, str):
tags = [tags]
if self.model_tags is None:
self.model_tags = []
for tag in tags:
if tag not in self.model_tags:
self.model_tags.append(tag) | Add custom tags into the model that gets pushed to the Hugging Face Hub. Will
not overwrite existing tags in the model.
Args:
tags (`Union[List[str], str]`):
The desired tags to inject in the model
Examples:
```python
from transformers import AutoModel
model = AutoModel.from_pretrained("google-bert/bert-base-cased"... | github-repos |
def verify_binary(flag_name, process_args=None):
if (process_args is None):
process_args = []
path = getattr(FLAGS, flag_name)
if (not path):
logging.error(('Flag %r not set' % flag_name))
sys.exit(1)
with open(os.devnull, 'w') as dev_null:
try:
subprocess.che... | Exits the program if the binary from the given flag doesn't run.
Args:
flag_name: Name of the flag that should be the path to the binary.
process_args: Args to pass to the binary to do nothing but verify
that it's working correctly (something like "--version") is good.
Optional. Defaults to no args.
Raises:
SystemExi... | codesearchnet |
def consult_robots_txt(self, request: HTTPRequest) -> bool:
if not self._robots_txt_checker:
return True
result = yield from self._robots_txt_checker.can_fetch(request)
return result | Consult by fetching robots.txt as needed.
Args:
request: The request to be made
to get the file.
Returns:
True if can fetch
Coroutine | juraj-google-style |
def cache_penalty_model(penalty_model, database=None):
if not _is_index_labelled(penalty_model.graph):
mapping, __ = _graph_canonicalization(penalty_model.graph)
penalty_model = penalty_model.relabel_variables(mapping, inplace=False)
if database is None:
conn = cach... | Caching function for penaltymodel_cache.
Args:
penalty_model (:class:`penaltymodel.PenaltyModel`): Penalty model to
be cached.
database (str, optional): The path to the desired sqlite database
file. If None, will use the default. | juraj-google-style |
def original_args(self):
return self._original_args | A `SessionRunArgs` object holding the original arguments of `run()`.
If user called `MonitoredSession.run(fetches=a, feed_dict=b)`, then this
field is equal to SessionRunArgs(a, b).
Returns:
A `SessionRunArgs` object | github-repos |
def Webhook(self, request, global_params=None):
config = self.GetMethodConfig('Webhook')
return self._RunMethod(config, request, global_params=global_params) | ReceiveWebhook is called when the API receives a GitHub webhook.
Args:
request: (CloudbuildWebhookRequest) input message
global_params: (StandardQueryParameters, default: None) global arguments
Returns:
(Empty) The response message. | github-repos |
def _command_template(self, switches, objectInput=None):
command = ["java", "-jar", self.file_jar, "-eUTF-8"]
if self.memory_allocation:
command.append("-Xmx{}".format(self.memory_allocation))
command.extend(switches)
if not objectInput:
objectInput = su... | Template for Tika app commands
Args:
switches (list): list of switches to Tika app Jar
objectInput (object): file object/standard input to analyze
Return:
Standard output data (unicode Python 2, str Python 3) | juraj-google-style |
def get_categorical_features_to_sampling(examples, top_k):
observed_features = collections.defaultdict(list)
for example in examples:
for feature_name in get_categorical_feature_names(example):
original_feature = parse_original_feature_from_example(example, feature_name)
observed... | Returns categorical features and a sampling of their most-common values.
The results of this slow function are used by the visualization repeatedly,
so the results are cached.
Args:
examples: Examples to read to get feature samples.
top_k: Max number of samples to return per feature.
Returns:
A dict of feature_name ... | codesearchnet |
def _indent(lines, prefix=' '):
indented = []
for line in lines.split('\n'):
indented.append((prefix + line))
return '\n'.join(indented) | Indent some text.
Note that this is present as ``textwrap.indent``, but not in Python 2.
Args:
lines (str): The newline delimited string to be indented.
prefix (Optional[str]): The prefix to indent each line with. Default
to two spaces.
Returns:
str: The newly indented content. | codesearchnet |
def on_created(self, event):
self._logger.debug('Detected create event on watched path: %s', event.src_path)
self._process_event(event) | Function called everytime a new file is created.
Args:
event: Event to process. | codesearchnet |
def generate_csr(self, csr_data, bay_number=None):
uri = "{}/https/certificaterequest".format(self.data['uri'])
if bay_number:
uri += "?bayNumber=%d" % (bay_number)
headers = {'Content-Type': 'application/json'}
return self._helper.do_post(uri, csr_data, -1, heade... | Creates a Certificate Signing Request (CSR) for an enclosure.
Args:
csr_data: Dictionary with csr details.
bay_number: OA from which the CSR should be generated.
Returns:
Enclosure. | juraj-google-style |
def valid_identifiers(self):
funcs = (list(utils.find_all(self.contexts[(- 1)])) + list(self.builtins))
return funcs | Get a list of all valid identifiers for the current context.
Returns:
list(str): A list of all of the valid identifiers for this context | codesearchnet |
def set_display_name(self, display_name):
self.displayname = display_name
return self.api.set_display_name(self.user_id, display_name) | Set this users display name.
Args:
display_name (str): Display Name | codesearchnet |
def get_by_hostname(self, hostname):
resources = self._client.get_all()
resources_filtered = [x for x in resources if x['hostname'] == hostname]
if resources_filtered:
return resources_filtered[0]
else:
return None | Retrieve a storage system by its hostname.
Works only in API500 onwards.
Args:
hostname: Storage system hostname.
Returns:
dict | juraj-google-style |
def fillup_layer(names):
longest = max([len(name) for name in names])
inputs_wires = []
for name in names:
inputs_wires.append(InputWire(name.rjust(longest)))
return inputs_wires | Creates a layer with InputWire elements.
Args:
names (list): List of names for the wires.
Returns:
list: The new layer | juraj-google-style |
def get_samples_live_last(self, sensor_id):
url = 'https:
headers = self.__gen_headers()
headers['Content-Type'] = 'application/json'
params = {'sensorId': sensor_id}
url = self.__append_url_params(url, params)
r = requests.get(url, headers=headers)
return r.json() | Get the last sample recorded by the sensor.
Args:
sensor_id (string): hexadecimal id of the sensor to query, e.g.
``0x0013A20040B65FAD``
Returns:
list: dictionary objects containing sample data | codesearchnet |
def list_sku_versions(access_token, subscription_id, location, publisher, offer, sku):
endpoint = ''.join([get_rm_endpoint(), '/subscriptions/', subscription_id, '/providers/Microsoft.Compute/', 'locations/', location, '/publishers/', publisher, '/artifacttypes/vmimage/offers/', offer, '/skus/', sku, '/versions?api... | List available versions for a given publisher's sku.
Args:
access_token (str): A valid Azure authentication token.
subscription_id (str): Azure subscription id.
location (str): Azure data center location. E.g. westus.
publisher (str): VM image publisher. E.g. MicrosoftWindowsServer.
offer (str): VM image offer. E.g. W... | codesearchnet |
def reset_subscription_since(self, account_id, datetime_str):
data = {
'account_id': account_id,
'datetime': datetime_str,
}
return self._perform_post_request(self.reset_subscription_since_endpoint, data, self.token_header) | Handler for `--reset-subscription-since` command.
Args:
account_id(int): id of the account to reset.
datetime_str(str): string representing the datetime used in the
next poll to retrieve data since.
Returns:
(str) json encoded response.
NOTES:
We don't care about validation here, we demand the responsibility to
the ... | juraj-google-style |
def disconnect(self):
result = False
logger.debug('SK8.disconnect({})'.format(self.conn_handle))
if (self.conn_handle >= 0):
logger.debug('Calling dongle disconnect')
result = self.dongle._disconnect(self.conn_handle)
self.conn_handle = (- 1)
self.packets = 0
return resul... | Disconnect the dongle from this SK8.
Simply closes the active BLE connection to the device represented by the current instance.
Returns:
bool. True if connection was closed, False if not (e.g. if already closed). | codesearchnet |
def filter_devices(ads, func):
results = []
for ad in ads:
if func(ad):
results.append(ad)
return results | Finds the AndroidDevice instances from a list that match certain
conditions.
Args:
ads: A list of AndroidDevice instances.
func: A function that takes an AndroidDevice object and returns True
if the device satisfies the filter condition.
Returns:
A list of AndroidDevice instances that satisfy the filter condition. | github-repos |
def _QueryHash(self, digest):
if (not self._url):
self._url = '{0:s}:
request_data = {self.lookup_hash: digest}
try:
json_response = self.MakeRequestAndDecodeJSON(self._url, 'POST', data=request_data)
except errors.ConnectionError as exception:
json_response = None
logger... | Queries the Viper Server for a specfic hash.
Args:
digest (str): hash to look up.
Returns:
dict[str, object]: JSON response or None on error. | codesearchnet |
def is_unused(input, model_file=None, model_proto=None, name=None):
return _gen_sentencepiece_processor_op.sentencepiece_get_piece_type(
input, model_file=model_file, model_proto=model_proto, name=name,
piece_type=2) | Returns true if input id is unused piece.
Args:
input: An arbitrary tensor of int32.
model_file: The sentencepiece model file path.
model_proto: The sentencepiece model serialized proto.
Either `model_file` or `model_proto` must be set.
name: The name argument that is passed to the op function.
Returns:
A tensor of bo... | juraj-google-style |
def _validate_isvalid_uncertainty(self, isvalid_uncertainty, field, value):
self._validate_isvalid_quantity(True, field, value)
if ((len(value) > 1) and (value[1]['uncertainty-type'] != 'relative')):
if (value[1].get('uncertainty') is not None):
self._validate_isvalid_quantity(True, field, [... | Checks for valid given value and appropriate units with uncertainty.
Args:
isvalid_uncertainty (`bool`): flag from schema indicating uncertainty to be checked
field (`str`): property associated with the quantity in question.
value (`list`): list with the string of the value of the quantity and a dictionary of
the unce... | codesearchnet |
def map(self, internalize: Callable[([TExternalQubit], TInternalQubit)], externalize: Callable[([TInternalQubit], TExternalQubit)]) -> 'QubitOrder':
def func(qubits):
unwrapped_qubits = [internalize(q) for q in qubits]
unwrapped_result = self.order_for(unwrapped_qubits)
return tuple((extern... | Transforms the Basis so that it applies to wrapped qubits.
Args:
externalize: Converts an internal qubit understood by the underlying
basis into an external qubit understood by the caller.
internalize: Converts an external qubit understood by the caller
into an internal qubit understood by the underlying basis.
Retur... | codesearchnet |
def call(self, input_features: TFModelInputType | None=None, decoder_input_ids: np.ndarray | tf.Tensor | None=None, decoder_attention_mask: np.ndarray | tf.Tensor | None=None, decoder_position_ids: np.ndarray | tf.Tensor | None=None, head_mask: np.ndarray | tf.Tensor | None=None, decoder_head_mask: np.ndarray | tf.Tens... | Returns:
Example:
```python
>>> import tensorflow as tf
>>> from transformers import TFWhisperModel, AutoFeatureExtractor
>>> from datasets import load_dataset
>>> model = TFWhisperModel.from_pretrained("openai/whisper-base")
>>> feature_extractor = AutoFeatureExtractor.from_pretrained("openai/whisper-base")
>>> ds ... | github-repos |
def write_block(self, block_, body):
self.write('for ; πF.State() >= 0; πF.PopCheckpoint() {')
with self.indent_block():
self.write('switch πF.State() {')
self.write('case 0:')
for checkpoint in block_.checkpoints:
self.write_tmpl('case $state: goto Label$state', state=checkpoint)... | Outputs the boilerplate necessary for code blocks like functions.
Args:
block_: The Block object representing the code block.
body: String containing Go code making up the body of the code block. | juraj-google-style |
def ParseFileObject(self, parser_mediator, file_object):
filename = parser_mediator.GetFilename()
if not filename.startswith('$I'):
raise errors.UnableToParseFile('Filename must start with $I.')
file_header_map = self._GetDataTypeMap('recycle_bin_metadata_file_header')
try:
... | Parses a Windows Recycle.Bin metadata ($I) 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. | juraj-google-style |
def flush(self, force: bool=False) -> bool | Any:
return self._messages.flush(force=force) | Flushes the underlying log message queue.
Args:
* force: If True, force queue to flush
Returns:
* True, if flushed with no errors
* False, if not flushed
* Error value from logger, if flushed with errors | github-repos |
def get_symbol(self, symbol):
self._ensure_symbols_loaded()
if (type(symbol) is int):
return self._symbols_by_index[symbol]
else:
return self._symbols_by_name[symbol] | Get a specific symbol by index or name.
Args:
symbol(int or str): The index or name of the symbol to return.
Returns:
ELF.Symbol: The symbol.
Raises:
KeyError: The requested symbol does not exist. | codesearchnet |
def ParseFileObject(self, parser_mediator, file_object):
try:
file_header = self._ReadFileHeader(file_object)
except (ValueError, errors.ParseError):
raise errors.UnableToParseFile('Unable to parse file header.')
tables = self._ReadTablesArray(file_object, file_header.tables_array_offset)
... | Parses a MacOS keychain file-like object.
Args:
parser_mediator (ParserMediator): mediates interactions between parsers
and other components, such as storage and dfvfs.
file_object (dfvfs.FileIO): a file-like object.
Raises:
UnableToParseFile: when the file cannot be parsed. | juraj-google-style |
def get_request_fields(self):
if hasattr(self, '_request_fields'):
return self._request_fields
include_fields = self.get_request_feature(self.INCLUDE)
exclude_fields = self.get_request_feature(self.EXCLUDE)
request_fields = {}
for (fields, include) in ((include_fields, True), (exclude_fields... | Parses the INCLUDE and EXCLUDE features.
Extracts the dynamic field features from the request parameters
into a field map that can be passed to a serializer.
Returns:
A nested dict mapping serializer keys to
True (include) or False (exclude). | codesearchnet |
def get_resource_from_handle(self, resource_handle):
repo_type = resource_handle.get("repository_type")
location = resource_handle.get("location")
if not (repo_type and location):
raise ValueError("PackageRepositoryManager requires "
"resource_ha... | Get a resource.
Args:
resource_handle (`ResourceHandle`): Handle of the resource.
Returns:
`PackageRepositoryResource` instance. | juraj-google-style |
def branch_lengths(self, terminal=True, internal=True):
if not isinstance(terminal, bool):
raise TypeError("terminal must be a bool")
if not isinstance(internal, bool):
raise TypeError("internal must be a bool")
for node in self.traverse_preorder():
i... | Generator over the lengths of the selected branches of this ``Tree``. Edges with length ``None`` will be output as 0-length
Args:
``terminal`` (``bool``): ``True`` to include terminal branches, otherwise ``False``
``internal`` (``bool``): ``True`` to include internal branches, otherwise ``False`` | juraj-google-style |
def from_string(cls, string):
lines = string.split('\n')
timestep = int(lines[1])
natoms = int(lines[3])
box_arr = np.loadtxt(StringIO('\n'.join(lines[5:8])))
bounds = box_arr[(:, :2)]
tilt = None
if ('xy xz yz' in lines[4]):
tilt = box_arr[(:, 2)]
x = (0, tilt[0], tilt[1], (... | Constructor from string parsing.
Args:
string (str): Input string. | codesearchnet |
def get_default_query_from_module(module):
if isinstance(module, types.ModuleType):
return module.__dict__.get(_SQL_MODULE_LAST, None)
return None | Given a %%sql module return the default (last) query for the module.
Args:
module: the %%sql module.
Returns:
The default query associated with this module. | juraj-google-style |
def PrintExtractionStatusHeader(self, processing_status):
self._output_writer.Write('Source path\t\t: {0:s}\n'.format(self._source_path))
self._output_writer.Write('Source type\t\t: {0:s}\n'.format(self._source_type))
if self._artifact_filters:
artifacts_string = ', '.join(self._artifact_filters)
... | Prints the extraction status header.
Args:
processing_status (ProcessingStatus): processing status. | codesearchnet |
def UpdateUser(self, user, ssh_keys):
if (not bool(USER_REGEX.match(user))):
self.logger.warning('Invalid user account name %s.', user)
return False
if (not self._GetUser(user)):
if (not (self._AddUser(user) and self._UpdateUserGroups(user, self.groups))):
return False
if... | Update a Linux user with authorized SSH keys.
Args:
user: string, the name of the Linux user account.
ssh_keys: list, the SSH key strings associated with the user.
Returns:
bool, True if the user account updated successfully. | codesearchnet |
def apply(self, func, workers=1, job_size=10000):
if workers == 1:
for lines in self.iter_chunks(job_size):
yield func(lines)
else:
with ProcessPoolExecutor(max_workers=workers) as executor:
for result in executor.map(func, self.iter_chunks(job_size)):
yield result | Apply `func` to lines of text in parallel or sequential.
Args:
func : a function that takes a list of lines. | juraj-google-style |
def CleanUpTest(cls, func):
def new_method(self, *args, **kwargs):
mox_obj = getattr(self, 'mox', None)
cleanup_mox = False
if mox_obj and isinstance(mox_obj, Mox):
cleanup_mox = True
try:
func(self, *args, **kwargs)
finally:
if cleanup_mox:
mox_o... | Adds Mox cleanup code to any MoxTestBase method.
Always unsets stubs after a test. Will verify all mocks for tests that
otherwise pass.
Args:
cls: MoxTestBase or subclass; the class whose test method we are altering.
func: method; the method of the MoxTestBase test class we wish to alter.
Returns:
The modified metho... | juraj-google-style |
def goto_step(self, inst: InstanceNode) -> InstanceNode:
return inst.look_up(**self.parse_keys(inst.schema_node)) | Return member instance of `inst` addressed by the receiver.
Args:
inst: Current instance. | juraj-google-style |
def get_appliance(self, appliance_id):
url = "https:
headers = self.__gen_headers()
headers["Content-Type"] = "application/json"
r = requests.get(url, headers=headers)
return r.json() | Get the information for a specified appliance
Args:
appliance_id (string): identifiying string of appliance
Returns:
list: dictionary object containing information about the specified appliance | juraj-google-style |
def Write2000256List(self, arr):
for item in arr:
ba = bytearray(binascii.unhexlify(item))
ba.reverse()
self.WriteBytes(ba) | Write an array of 64 byte items to the stream.
Args:
arr (list): a list of 2000 items of 64 bytes in size. | juraj-google-style |
def __init__(self, sdat):
self.sdat = sdat
self._last = UNDETERMINED
self._data = {None: _step.EmptyStep()} | Initialization of instances:
Args:
sdat (:class:`StagyyData`): the StagyyData instance owning the
:class:`_Steps` instance.
Attributes:
sdat (:class:`StagyyData`): the StagyyData instance owning the
:class:`_Steps` instance. | juraj-google-style |
def do_block(args):
rest_client = RestClient(args.url, args.user)
if args.subcommand == 'list':
block_generator = rest_client.list_blocks()
blocks = []
left = args.count
for block in block_generator:
blocks.append(block)
left -= 1
if left... | Runs the block list or block show command, printing output to the
console
Args:
args: The parsed arguments sent to the command at runtime | juraj-google-style |
def scan(initial_state, scan_func):
def _apply_fn(dataset):
return dataset.scan(initial_state=initial_state, scan_func=scan_func)
return _apply_fn | A transformation that scans a function across an input dataset.
This transformation is a stateful relative of `tf.data.Dataset.map`.
In addition to mapping `scan_func` across the elements of the input dataset,
`scan()` accumulates one or more state tensors, whose initial values are
`initial_state`.
Args:
initial_stat... | github-repos |
def save(hdf5_filename, array):
hdf5_filename = os.path.expanduser(hdf5_filename)
try:
h = h5py.File(hdf5_filename, 'w')
h.create_dataset('CUTOUT', data=array)
h.close()
except Exception as e:
raise ValueError('Could not save HDF5 file {0}.'.format(hdf5_filename))
return ... | Export a numpy array to a HDF5 file.
Arguments:
hdf5_filename (str): A filename to which to save the HDF5 data
array (numpy.ndarray): The numpy array to save to HDF5
Returns:
String. The expanded filename that now holds the HDF5 data | codesearchnet |
def recv_result_from_workers(self):
info = MPI.Status()
result = self.comm.recv(source=MPI.ANY_SOURCE, tag=RESULT_TAG, status=info)
logger.debug('Received result from workers: {}'.format(result))
return result | Receives a results from the MPI worker pool and send it out via 0mq
Returns:
--------
result: task result from the workers | codesearchnet |
def _get_dequantized_hist_mids_after_quantize(self, quant_min: float, quant_max: float) -> np.ndarray:
maxbound = 2 ** self._num_bits - 1
minbound = 0
scale = (quant_max - quant_min) / maxbound
zero_point = -quant_min / scale
if abs(zero_point) > 9000000000.0:
zero_point = 9000000000.0
i... | Quantizes and dequantizes hist_mids using quant_min and quant_max.
Quantization converts the range of numbers from [quant_min, quant_max] to
[0, 2^num_bits - 1]. Values less than quant_min are converted to 0, and
values greater than quant_max are converted to 2^num_bits - 1.
The histogram represents the distribution ... | github-repos |
def _protobuf_value_to_string(value):
value_in_json = json_format.MessageToJson(value)
if value.HasField("string_value"):
return value_in_json[1:-1]
return value_in_json | Returns a string representation of given google.protobuf.Value message.
Args:
value: google.protobuf.Value message. Assumed to be of type 'number',
'string' or 'bool'. | juraj-google-style |
def fetch(self, webfonts):
sorted_keys = sorted(webfonts.keys())
for webfont_name in sorted_keys:
self.get(webfont_name, webfonts[webfont_name]) | Store every defined webfonts.
Webfont are stored with sort on their name.
Args:
webfonts (dict): Dictionnary of webfont settings from
``settings.ICOMOON_WEBFONTS``. | codesearchnet |
def py_to_weld_type(self, obj):
if isinstance(obj, np.ndarray):
dtype = str(obj.dtype)
if dtype == 'int16':
base = WeldInt16()
elif dtype == 'int32':
base = WeldInt()
elif dtype == 'int64':
base = WeldLong()... | Summary
Args:
obj (TYPE): Description
Returns:
TYPE: Description
Raises:
Exception: Description | juraj-google-style |
def _filter_and_bucket_subtokens(subtoken_counts, min_count):
subtoken_buckets = []
for subtoken, count in six.iteritems(subtoken_counts):
if count < min_count:
continue
while len(subtoken_buckets) <= len(subtoken):
subtoken_buckets.append(set())
subtoken_buckets[len(subtoken)].add(s... | Return a bucketed list of subtokens that are filtered by count.
Args:
subtoken_counts: defaultdict mapping subtokens to their counts
min_count: int count used to filter subtokens
Returns:
List of subtoken sets, where subtokens in set i have the same length=i. | juraj-google-style |
def _bisect(self, begin, end, listener):
step = ((end.date - begin.date) / 2)
while (abs(step) >= self._eps_bisect):
date = (begin.date + step)
if (self.SPEAKER_MODE == 'global'):
orb = self.propagate(date)
else:
orb = begin.propagate(date)
if ((listener(b... | This method search for the zero-crossing of the watched parameter
Args:
begin (Orbit):
end (Orbit)
listener (Listener)
Return
Return | codesearchnet |
def _ParseStorageMediaOptions(self, options):
self._ParseStorageMediaImageOptions(options)
self._ParseVSSProcessingOptions(options)
self._ParseCredentialOptions(options)
self._ParseSourcePathOption(options) | Parses the storage media options.
Args:
options (argparse.Namespace): command line arguments.
Raises:
BadConfigOption: if the options are invalid. | codesearchnet |
def __init__(self, dataset_vid=None, vid=None, score=None):
assert vid is not None, 'vid can not be None.'
assert dataset_vid is not None, 'dataset_vid can not be None.'
assert score is not None, 'score can not be None.'
self.dataset_vid = dataset_vid
self.vid = vid
... | Initalizes partition search result fields.
Args:
dataset_vid (str): vid of the partition's dataset.
vid (str): partition vid.
score (int): score of the search result. | juraj-google-style |
def from_pure(cls, z):
return cls(cls._key, {z: 1.0}, {z: 1.0}, pyxray.element_symbol(z)) | Creates a pure composition.
Args:
z (int): atomic number | juraj-google-style |
def _client_receive(self):
try:
response = self._client.readline()
if self.verbose_logging:
self.log.debug('Snippet received: %s', response)
elif _MAX_RPC_RESP_LOGGING_LENGTH >= len(response):
self.log.debug('Snippet received: %s', response)
else:
... | Receives the server's response of an Rpc message.
Returns:
Raw byte string of the response.
Raises:
Error: a socket error occurred during the read. | github-repos |
def _sort_records_map(records):
ctx = context.get()
l = len(records)
key_records = ([None] * l)
logging.debug('Parsing')
for i in range(l):
proto = kv_pb.KeyValue()
proto.ParseFromString(records[i])
key_records[i] = (proto.key(), records[i])
logging.debug('Sorting')
k... | Map function sorting records.
Converts records to KeyValue protos, sorts them by key and writes them
into new GCS file. Creates _OutputFile entity to record resulting
file name.
Args:
records: list of records which are serialized KeyValue protos. | codesearchnet |
def handle_erroneous_response(self, response: requests.Response) -> NoReturn:
logger.debug('handling erroneous response: %s', response)
try:
err = BugZooException.from_dict(response.json())
except Exception:
err = UnexpectedResponse(response)
raise err | Attempts to decode an erroneous response into an exception, and to
subsequently throw that exception.
Raises:
BugZooException: the exception described by the error response.
UnexpectedResponse: if the response cannot be decoded to an
exception. | codesearchnet |
def _Open(self, path_spec, mode='rb'):
if not path_spec.HasParent():
raise errors.PathSpecError(
'Unsupported path specification without parent.')
resolver.Resolver.key_chain.ExtractCredentialsFromPathSpec(path_spec)
bde_volume = pybde.volume()
file_object = resolver.Resolver.Open... | Opens the file system defined by path specification.
Args:
path_spec (PathSpec): path specification.
mode (Optional[str]): file access mode. The default is 'rb'
read-only binary.
Raises:
AccessError: if the access to open the file was denied.
IOError: if the file system could not be opened.
PathSpecError: if the path... | juraj-google-style |
def split(self, path):
path = path.strip()
if not path.startswith(BlobStorageFileSystem.AZURE_FILE_SYSTEM_PREFIX):
raise ValueError('Path %r must be Azure Blob Storage path.' % path)
prefix_len = len(BlobStorageFileSystem.AZURE_FILE_SYSTEM_PREFIX)
last_sep = path[prefix_len:].rfind('/')
if l... | Splits the given path into two parts.
Splits the path into a pair (head, tail) such that tail contains the last
component of the path and head contains everything up to that.
For file-systems other than the local file-system, head should include the
prefix.
Args:
path: path as a string
Returns:
a pair of path compon... | github-repos |
def forward(self, hidden_states: torch.Tensor, attention_mask: Optional[torch.Tensor]=None, position_ids: Optional[torch.LongTensor]=None, past_key_value: Optional[Tuple[torch.Tensor]]=None, output_attentions: Optional[bool]=False, use_cache: Optional[bool]=False, cache_position: Optional[torch.LongTensor]=None, **kwar... | Args:
hidden_states (`torch.FloatTensor`): input to the layer of shape `(batch, seq_len, embed_dim)`
attention_mask (`torch.FloatTensor`, *optional*): attention mask of size
`(batch, 1, tgt_len, src_len)` where padding elements are indicated by very large negative values.
output_attentions (`bool`, *optional*):
Whether... | github-repos |
def select_with_condition(self, condition, key=None):
condition = Condition.as_condition(condition)
new_confs = []
for conf in self:
obj = conf if key is None else AttrDict(conf[key])
add_it = condition(obj=obj)
if add_it: n... | Remove all the configurations that do not satisfy the given condition.
Args:
condition: dict or :class:`Condition` object with operators expressed with a Mongodb-like syntax
key: Selects the sub-dictionary on which condition is applied, e.g. key="vars"
if we have to filter the configurations depending on the values in... | juraj-google-style |
def _apply_func_to_list_of_partitions(self, func, partitions, **kwargs):
preprocessed_func = self.preprocess_func(func)
return [obj.apply(preprocessed_func, **kwargs) for obj in partitions] | Applies a function to a list of remote partitions.
Note: The main use for this is to preprocess the func.
Args:
func: The func to apply
partitions: The list of partitions
Returns:
A list of BaseFramePartition objects. | juraj-google-style |
def make_nested_list_of_images(images: Union[list[ImageInput], ImageInput]) -> ImageInput:
if isinstance(images, (list, tuple)) and all((isinstance(images_i, (list, tuple)) for images_i in images)) and all((is_valid_list_of_images(images_i) for images_i in images)):
return images
if isinstance(images, (... | Ensure that the output is a nested list of images.
Args:
images (`Union[List[ImageInput], ImageInput]`):
The input image.
Returns:
list: A list of list of images or a list of 4d array of images. | github-repos |
def json_to_pybel(data, infer_bonds=False):
obmol = ob.OBMol()
obmol.BeginModify()
for atom in data['atoms']:
obatom = obmol.NewAtom()
obatom.SetAtomicNum(table.GetAtomicNum(str(atom['element'])))
obatom.SetVector(*atom['location'])
if 'label' in atom:
pd = o... | Converts python data structure to pybel.Molecule.
This will infer bond data if not specified.
Args:
data: The loaded json data of a molecule, as a Python object
infer_bonds (Optional): If no bonds specified in input, infer them
Returns:
An instance of `pybel.Molecule` | juraj-google-style |
def cast_if_floating_dtype_and_mismatch(targets, outputs):
if tensor_util.is_tf_type(targets):
return cast_single_tensor(targets, dtype=outputs[0].dtype)
new_targets = []
for target, out in zip(targets, outputs):
if isinstance(target, np.ndarray):
target = tensor_conversion.conve... | Returns target data tensors using correct datatype.
Checks that each target and output pair are the same datatype. If not, casts
the target to the output's datatype.
Args:
targets: tensor or list of targets.
outputs: tensor or list of outputs.
Returns:
Targets in appropriate datatype. | github-repos |
def transform(self, X):
sklearn.base.check_is_fitted(self)
X = _validate_data(self, X, reset=False)
return self.model_.predict(X) | Transform the data.
Args:
X: array-like, shape=(n_samples, n_features)
The input samples.
Returns:
X_transformed: array-like, shape=(n_samples, n_features)
The transformed data. | github-repos |
def key_for_entity_group(cls, key):
return model.Key(cls.KIND_NAME, cls.ID, parent=key.root()) | Return the key for the entity group containing key.
Args:
key: a key for an entity group whose __entity_group__ key you want.
Returns:
The __entity_group__ key for the entity group containing key. | juraj-google-style |
def apply_on_inputs(self, named_inputs: Dict[str, EventSetNode]) -> Dict[str, EventSetNode]:
g = deepcopy(self)
assert g.named_inputs is not None
assert g.named_outputs is not None
for name, new_node in named_inputs.items():
if name not in g.named_inputs:
raise ValueError(f"Input nod... | Applies the operators in this graph to new inputs.
Note that the objects in the modified graph are very inconsistent, but
that's okay since we won't use it anymore. When running it or save it
the graph will be re-inferred.
Args:
named_inputs: The new inputs to the graph.
Returns:
The graph's named outputs. | github-repos |
def _convert_to_seeder_format(dataset):
data = {}
seed = {}
_add_if_set(data, "name", dataset.get("title"))
_add_if_set(data, "issn", dataset.get("issn"))
_add_if_set(data, "annotation", dataset.get("annotation"))
rules = dataset.get("rules", {})
if rules:
_add_if_set(data, "f... | WA KAT dataset has different structure from Seeder. This is convertor
which converts WA-KAT -> Seeder data format.
Args:
dataset (dict): WA-KAT dataset sent from frontend.
Returns:
dict: Dict with converted data. | juraj-google-style |
def delete(self, invoice_id, **kwargs):
url = '{}/{}'.format(self.base_url, invoice_id)
return self.delete_url(url, {}, **kwargs) | Delete an invoice
You can delete an invoice which is in the draft state.
Args:
invoice_id : Id for delete the invoice
Returns:
The response is always be an empty array like this - [] | codesearchnet |
def authenticate_identify(self, api_token, override=True):
if (self.context.has_auth_params('Gem-Identify') and not override):
raise OverrideError('Gem-Identify')
if (not api_token or
not self.context.authorize('Gem-Identify', api_token=api_token)):
raise Au... | Set credentials for Identify authentication.
Args:
api_token (str): Token issued to your Application through the Gem
Developer Console.
override (boolean): Replace existing Application credentials. | juraj-google-style |
def format_checksum(checksum_pyxb):
return '{}/{}'.format(checksum_pyxb.algorithm.upper().replace('-', ''), checksum_pyxb.value().lower()) | Create string representation of a PyXB Checksum object.
Args:
PyXB Checksum object
Returns:
str : Combined hexadecimal value and algorithm name. | codesearchnet |
def resize(self, image: np.ndarray, size: Dict[str, int], resample: PILImageResampling.BICUBIC, data_format: Optional[Union[str, ChannelDimension]]=None, input_data_format: Optional[Union[str, ChannelDimension]]=None, **kwargs) -> np.ndarray:
size = get_size_dict(size, default_to_square=True)
if 'height' not in... | Resize an image to a certain size.
Args:
image (`np.ndarray`):
Image to resize.
size (`Dict[str, int]`):
The size to resize the image to. Must contain height and width keys.
resample (`PILImageResampling`, *optional*, defaults to `PILImageResampling.BICUBIC`):
The resampling filter to use when resizing the input.
data... | github-repos |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.