code stringlengths 20 4.93k | docstring stringlengths 33 1.27k | source stringclasses 3
values |
|---|---|---|
def write(self, output_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0):
local_buffer = utils.BytearrayStream()
if self._located_items:
self._located_items.write(local_buffer, kmip_version=kmip_version)
if self._unique_identifiers:
for unique_identifier in self._unique_identifiers:
... | Write the data encoding the Locate response payload to a buffer.
Args:
output_buffer (stream): A data buffer in which to encode object
data, supporting a write method.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be encoded. Optional,
defaults to KMIP 1.0. | codesearchnet |
def clean(self, force: bool=False):
assert (not self._closed)
with (yield from self._host_pools_lock):
for (key, pool) in tuple(self._host_pools.items()):
(yield from pool.clean(force=force))
if ((not self._host_pool_waiters[key]) and pool.empty()):
del self._host... | Clean all closed connections.
Args:
force: Clean connected and idle connections too.
Coroutine. | codesearchnet |
def orthologize(self, species_id: str) -> 'BEL':
if (not self.ast):
return self
if (not self.ast.collected_orthologs):
self = self.collect_orthologs([species_id])
self.ast.species = set()
self.ast = bel_utils.orthologize(self.ast, self, species_id)
return self | Orthologize BEL AST to given species_id
Will return original entity (ns:value) if no ortholog found.
Args:
species_id (str): species id to convert genes/rna/proteins into
Returns:
BEL: returns self | codesearchnet |
def tersoff_input(self, structure, periodic=False, uc=True, *keywords):
gin = self.keyword_line(*keywords)
gin += self.structure_lines(
structure, cell_flg=periodic, frac_flg=periodic,
anion_shell_flg=False, cation_shell_flg=False, symm_flg=not uc
)
... | Gets a GULP input with Tersoff potential for an oxide structure
Args:
structure: pymatgen.core.structure.Structure
periodic (Default=False): Flag denoting whether periodic
boundary conditions are used
library (Default=None): File containing the species and potential.
uc (Default=True): Unit Cell Flag.
keywords: GULP f... | juraj-google-style |
def get_dm_channel(self, userid):
dm_open = self.slack_client.api_call('im.open', user=userid)
return dm_open['channel']['id'] | Perform a lookup of users to resolve a userid to a DM channel
Args:
userid (string): Slack userid to lookup.
Returns:
string: DM channel ID of user | juraj-google-style |
def is_mobile(user_agent):
if user_agent:
b = reg_b.search(user_agent)
v = reg_v.search(user_agent[0:4])
return (b or v)
return False | Checks if the user browser from the given user agent is mobile.
Args:
user_agent: A given user agent.
Returns: True if the browser from the user agent is mobile. | codesearchnet |
def date_to_datetime(self, time_input, tz=None):
dt = None
try:
dt = parser.parse(time_input)
if tz is not None and tz != dt.tzname():
if dt.tzinfo is None:
dt = self._replace_timezone(dt)
dt =... | Convert ISO 8601 and other date strings to datetime.datetime type.
Args:
time_input (string): The time input string (see formats above).
tz (string): The time zone for the returned data.
Returns:
(datetime.datetime): Python datetime.datetime object. | juraj-google-style |
def add_api_key(key, value):
if ((key is None) or (key == '')):
logger.error('Key cannot be empty')
if ((value is None) or (value == '')):
logger.error('Value cannot be empty')
from .. import datatools
data = datatools.get_data()
if ('keys' not in data['discord']):
data['disc... | Adds a key to the bot's data
Args:
key: The name of the key to add
value: The value for the key | codesearchnet |
def dump(collection: BioCCollection, fp, pretty_print: bool = True):
fp.write(dumps(collection, pretty_print)) | Serialize ``collection`` as a BioC formatted stream to ``fp``.
Args:
collection: the BioC collection
fp: a ``.write()``-supporting file-like object
pretty_print: enables formatted XML | juraj-google-style |
def tile_and_concat(image, latent, concat_latent=True):
if not concat_latent:
return image
image_shape = common_layers.shape_list(image)
latent_shape = common_layers.shape_list(latent)
height, width = image_shape[1], image_shape[2]
latent_dims = latent_shape[1]
height_multiples = height
pad = heig... | Tile latent and concatenate to image across depth.
Args:
image: 4-D Tensor, (batch_size X height X width X channels)
latent: 2-D Tensor, (batch_size X latent_dims)
concat_latent: If set to False, the image is returned as is.
Returns:
concat_latent: 4-D Tensor, (batch_size X height X width X channels+1)
latent tiled a... | juraj-google-style |
def get_body(name):
body = Pck()[name]
body.propagate = (lambda date: get_orbit(name, date))
return body | Retrieve the Body structure of a JPL .bsp file object
Args:
name (str)
Return:
:py:class:`~beyond.constants.Body` | codesearchnet |
def __init__(self, string_or_filelike, parser_delegate):
if hasattr(string_or_filelike, 'readline'):
line_reader = string_or_filelike.readline
else:
if six.PY2:
string_or_filelike = unicode(string_or_filelike)
string_io = io.StringIO(string_or_filelike)
line_reader = strin... | Construct the parser.
Args:
string_or_filelike: Either the string to parse, or a file-like object
supporting the readline method.
parser_delegate: An instance of the ParserDelegate class, that will be
responsible for constructing appropriate objects for configurable
references and macros. | juraj-google-style |
def _slice_shape(self, start, stop):
if stop <= start:
return DynamicRaggedShape._from_inner_shape([])
elif start == 0:
if stop <= self.num_row_partitions:
if stop == 1:
return DynamicRaggedShape._from_inner_shape([self.row_partitions[0].nrows()])
new_row_... | Returns a shape self[start:stop].
If start == 0, then this truncates dimensions after stop.
If start != 0, then this will return a shape with num_row_partitions == 0.
See __getitem__.
Args:
start: the first dimension. 0 <= start <= rank
stop: the last dimension (exclusive). 0 <= stop <= rank | github-repos |
def scanJoiner(self, xEUI='*', strPSKd='threadjpaketest'):
print '%s call scanJoiner' % self.port
if not isinstance(xEUI, str):
eui64 = self.__convertLongToString(xEUI)
if len(eui64) < 16:
eui64 = eui64.zfill(16)
print eui64
... | scan Joiner
Args:
xEUI: Joiner's EUI-64
strPSKd: Joiner's PSKd for commissioning
Returns:
True: successful to add Joiner's steering data
False: fail to add Joiner's steering data | juraj-google-style |
def _export_files(self, bq: bigquery_tools.BigQueryWrapper, element: 'ReadFromBigQueryRequest', table_reference: TableReference):
job_labels = self._get_bq_metadata().add_additional_bq_job_labels(self.bigquery_job_labels)
export_job_name = bigquery_tools.generate_bq_job_name(self._job_name, self._source_uuid, b... | Runs a BigQuery export job.
Returns:
bigquery.TableSchema instance, a list of FileMetadata instances | github-repos |
def _make_env(resultdir=None):
env = {'config': {}, 'resultdir': '', 'config_file': '', 'nodes': {}, 'phase': '', 'user': '', 'cwd': os.getcwd()}
if resultdir:
env_path = os.path.join(resultdir, 'env')
if os.path.isfile(env_path):
with open(env_path, 'r') as f:
env.up... | Loads the env from `resultdir` if not `None` or makes a new one.
An Enos environment handles all specific variables of an
experiment. This function either generates a new environment or
loads a previous one. If the value of `resultdir` is `None`, then
this function makes a new environment and return it. If the value
i... | codesearchnet |
def strides(self) -> List[int]:
return _compute_mesh_strides(self.shape()) | Returns the strides tensor array for this mesh.
If the mesh shape is `[a, b, c, d]`, then the strides array can be computed
as `[b*c*d, c*d, d, 1]`. This array can be useful in computing local device
offsets given a device ID. Using the same example, the device coordinates of
the mesh can be computed as:
```
[(device... | github-repos |
def content(self, request, id):
gist = self.send(request, id).json()
def convert(data):
return base64.b64decode(data).decode('utf-8')
content = {}
for (name, data) in gist['files'].items():
content[name] = convert(data['content'])
return content | Returns the content of the gist
Arguments:
request: an initial request object
id: the gist identifier
Returns:
A dict containing the contents of each file in the gist | codesearchnet |
def _check_triple_quotes(self, quote_record):
(_, triple, row, col) = quote_record
if (triple != TRIPLE_QUOTE_OPTS.get(self.config.triple_quote)):
self._invalid_triple_quote(triple, row, col) | Check if the triple quote from tokenization is valid.
Args:
quote_record: a tuple containing the info about the string
from tokenization, giving the (token, quote, row number, column). | codesearchnet |
def Get(self, path, follow_symlink=True):
key = self._Key(path=path, follow_symlink=follow_symlink)
try:
return self._cache[key]
except KeyError:
value = Stat.FromPath(path, follow_symlink=follow_symlink)
self._cache[key] = value
if ((not follow_symlink) and (not value.IsSyml... | Stats given file or returns a cached result if available.
Args:
path: A path to the file to perform `stat` on.
follow_symlink: True if `stat` of a symlink should be returned instead of
a file that it points to. For non-symlinks this setting has no effect.
Returns:
`Stat` object corresponding to the given path. | codesearchnet |
def __setitem__(self,key,value):
self.rdb.hset(self.session_hash,key,value)
self.rdb.expire(self.session_hash,self.ttl) | Set an existing or new key, value association.
Args:
key (str): The dictionary key.
value (str): The dictionary value | juraj-google-style |
def get_day_end(config):
day_start_datetime = datetime.datetime.combine(datetime.date.today(), config['day_start'])
day_end_datetime = day_start_datetime - datetime.timedelta(seconds=1)
return day_end_datetime.time() | Get the day end time given the day start. This assumes full 24h day.
Args:
config (dict): Configdict. Needed to extract ``day_start``.
Note:
This is merely a convinience funtion so we do not have to deduct this from ``day_start``
by hand all the time. | juraj-google-style |
def push(self, value):
stream = DataStream.FromEncoded(value.stream)
if (stream.stream_type == DataStream.OutputType):
if (len(self.streaming_data) == self.streaming_length):
raise StorageFullError('Streaming buffer full')
self.streaming_data.append(value)
else:
if (len(s... | Store a new value for the given stream.
Args:
value (IOTileReading): The value to store. The stream
parameter must have the correct value | codesearchnet |
def cancel(self, queue):
try:
consumer = self._consumers[queue]
yield consumer.channel.basic_cancel(consumer_tag=consumer.tag)
except pika.exceptions.AMQPChannelError:
pass
except KeyError:
defer.returnValue(None)... | Cancel the consumer for a queue.
Args:
queue (str): The name of the queue the consumer is subscribed to.
Returns:
defer.Deferred: A Deferred that fires when the consumer
is canceled, or None if the consumer was already canceled. Wrap
the call in :func:`.defer.maybeDeferred` to always receive a Deferred. | juraj-google-style |
def __tf_tracing_type__(self, context: TracingContext) -> TraceType: | Returns the tracing type of this object.
The tracing type is used to build the signature of a tf.function
when traced, and to match arguments with existing signatures.
When a Function object is called, tf.function looks at the tracing type
of the call arguments. If an existing signature of matching type exists,
it wil... | github-repos |
def add_answer(self, vote, rationale):
self.raw_answers.append({VOTE_KEY: vote, RATIONALE_KEY: rationale}) | Add an answer
Args:
vote (int): the option that student voted for
rationale (str): the reason why the student vote for the option | codesearchnet |
def scale(self, scalar, ignored_variables=None, ignored_interactions=None, ignore_offset=False):
if (ignored_variables is None):
ignored_variables = set()
elif (not isinstance(ignored_variables, abc.Container)):
ignored_variables = set(ignored_variables)
if (ignored_interactions is None):
... | Multiply by the specified scalar all the biases and offset of a binary quadratic model.
Args:
scalar (number):
Value by which to scale the energy range of the binary quadratic model.
ignored_variables (iterable, optional):
Biases associated with these variables are not scaled.
ignored_interactions (iterable[tuple], ... | codesearchnet |
def _get_variation_id(value, capital=False):
value = int(value)
base_power = base_start = base_end = 0
while value >= base_end:
base_power += 1
base_start = base_end
base_end += pow(26, base_power)
base_index = value - base_start
... | Convert an integer value to a character. a-z then double aa-zz etc
Args:
value (int): integer index we're looking up
capital (bool): whether we convert to capitals or not
Returns (str): alphanumeric representation of the index | juraj-google-style |
def _infer(self, request):
label_vocab = inference_utils.get_label_vocab(
request.args.get('label_vocab_path'))
try:
if request.method != 'GET':
logger.error('%s requests are forbidden.', request.method)
return http_util.Respond(request, {'error': 'invalid non-GET request'},
... | Returns JSON for the `vz-line-chart`s for a feature.
Args:
request: A request that should contain 'inference_address', 'model_name',
'model_type, 'model_version', 'model_signature' and 'label_vocab_path'.
Returns:
A list of JSON objects, one for each chart. | juraj-google-style |
def remove_species(self, species):
new_sites = []
species = [get_el_sp(s) for s in species]
for site in self._sites:
new_sp_occu = {sp: amt for (sp, amt) in site.species.items() if (sp not in species)}
if (len(new_sp_occu) > 0):
new_sites.append(PeriodicSite(new_sp_occu, site.fra... | Remove all occurrences of several species from a structure.
Args:
species: Sequence of species to remove, e.g., ["Li", "Na"]. | codesearchnet |
def __init__(self, script_hash=None, key=None):
self.ScriptHash = script_hash
self.Key = key | Create an instance.
Args:
script_hash (UInt160):
key (bytes): | juraj-google-style |
def __pad_value(value, pad_len_multiple, pad_char):
assert pad_len_multiple > 0
assert len(pad_char) == 1
padding_length = (pad_len_multiple -
(len(value) % pad_len_multiple)) % pad_len_multiple
return value + pad_char * padding_length | Add padding characters to the value if needed.
Args:
value: The string value to be padded.
pad_len_multiple: Pad the result so its length is a multiple
of pad_len_multiple.
pad_char: The character to use for padding.
Returns:
The string value with padding characters added. | juraj-google-style |
def stop(self, consumer):
stopped_workflows = []
for request in [r for r in consumer.controller.state.active_requests]:
job = AsyncResult(request.id)
workflow_id = job.result['workflow_id']
if (workflow_id not in stopped_workflows):
client = Client(SignalConnection(**consumer... | This function is called when the worker received a request to terminate.
Upon the termination of the worker, the workflows for all running jobs are
stopped gracefully.
Args:
consumer (Consumer): Reference to the consumer object that handles messages
from the broker. | codesearchnet |
def get_soundcloud_data(url):
data = {}
request = requests.get(url)
title_tag = request.text.split('<title>')[1].split('</title')[0]
data['title'] = title_tag.split(' by ')[0].strip()
data['artist'] = title_tag.split(' by ')[1].split('|')[0].strip()
return data | Scrapes a SoundCloud page for a track's important information.
Returns:
dict: of audio data | codesearchnet |
def translate_ostat(ostat):
ostat_lower = ostat.strip().lower()
if (ostat_lower == 'monomer'):
return 1
elif (ostat_lower == 'homo-dimer'):
return 2
elif (ostat_lower == 'homo-trimer'):
return 3
elif (ostat_lower == 'homo-tetramer'):
return 4
elif (ostat_lower == ... | Translate the OSTAT field to an integer.
As of 2018-02-26, works on all E. coli models. Untested on other pre-made organism models.
Args:
ostat (str): Predicted oligomeric state of the PDB file
Returns:
int: Translated string to integer | codesearchnet |
def find_or_create_all(cls, list_of_kwargs, keys=[]):
(list_of_kwargs_wo_dupes, markers) = remove_and_mark_duplicate_dicts(list_of_kwargs, keys)
added_objs = cls.add_all([(cls.first(**subdict(kwargs, keys)) or cls.new(**kwargs)) for kwargs in list_of_kwargs_wo_dupes])
result_objs = []
iterator_of_added_... | Batch method for querying for a list of instances and
creating them if required
Args:
list_of_kwargs(list of dicts): A list of dicts where
each dict denotes the keyword args that you would pass
to the create method separately
keys (list, optional): A list of keys to use for the
initial finding step. Matching is done ... | codesearchnet |
def forward(self, hidden_states, output_router_logits):
forwarded_states, router_tuple = self.mlp(hidden_states)
forwarded_states += torch.tanh(self.soft_bypass_mlp(hidden_states))
output = hidden_states + self.norm(forwarded_states)
if output_router_logits and router_tuple is not None:
return (... | Args:
hidden_states (`torch.Tensor`) :
[num_groups, tokens_per_group, hidden_dim] inputs to send to experts.
output_router_logits (`bool`) :
output experts router output.
Returns:
torch.Tensor[num_groups, tokens_per_group, hidden_dim] | github-repos |
def _GetFormatErrorLocation(
self, yaml_definition, last_definition_object):
name = yaml_definition.get('name', None)
if name:
error_location = 'in: {0:s}'.format(name or '<NAMELESS>')
elif last_definition_object:
error_location = 'after: {0:s}'.format(last_definition_object.name)
... | Retrieves a format error location.
Args:
yaml_definition (dict[str, object]): current YAML definition.
last_definition_object (DataTypeDefinition): previous data type
definition.
Returns:
str: format error location. | juraj-google-style |
def ParseStatusRow(self, parser_mediator, query, row, **unused_kwargs):
query_hash = hash(query)
event_data = TwitterIOSStatusEventData()
event_data.favorite_count = self._GetRowValue(
query_hash, row, 'favoriteCount')
event_data.favorited = self._GetRowValue(query_hash, row, 'favorited')
... | Parses a contact row from the database.
Args:
parser_mediator (ParserMediator): mediates interactions between parsers
and other components, such as storage and dfvfs.
query (str): query that created the row.
row (sqlite3.Row): row resulting from query. | juraj-google-style |
def __init__(self, data_type_definition):
super(StreamMap, self).__init__(data_type_definition)
self._fold_byte_stream = None
self._map_byte_stream = None
if self._element_data_type_definition.IsComposite():
raise errors.FormatError('Unsupported composite element data type') | Initializes a stream data type map.
Args:
data_type_definition (DataTypeDefinition): data type definition.
Raises:
FormatError: if the data type map cannot be determined from the data
type definition. | juraj-google-style |
def reset(self, name=None):
if self._reader_ref.dtype == dtypes.resource:
return gen_io_ops.reader_reset_v2(self._reader_ref, name=name)
else:
return gen_io_ops.reader_reset(self._reader_ref, name=name) | Restore a reader to its initial clean state.
Args:
name: A name for the operation (optional).
Returns:
The created Operation. | github-repos |
def ParseOptions(cls, options, configuration_object):
if not isinstance(configuration_object, tools.CLITool):
raise errors.BadConfigObject(
'Configuration object is not an instance of CLITool')
preferred_year = cls._ParseNumericOption(options, 'preferred_year')
process_archives = geta... | Parses and validates options.
Args:
options (argparse.Namespace): parser options.
configuration_object (CLITool): object to be configured by the argument
helper.
Raises:
BadConfigObject: when the configuration object is of the wrong type. | juraj-google-style |
def _create_dom(data):
if (not isinstance(data, dhtmlparser.HTMLElement)):
data = dhtmlparser.parseString(utils.handle_encodnig(data))
dhtmlparser.makeDoubleLinked(data)
return data | Creates doublelinked DOM from `data`.
Args:
data (str/HTMLElement): Either string or HTML element.
Returns:
obj: HTMLElement containing double linked DOM. | codesearchnet |
async def _get_async(self, url, session):
data = None
async with session.get(url) as resp:
if (resp.status == 200):
data = (await resp.json())
return data | Asynchronous internal method used for GET requests
Args:
url (str): URL to fetch
session (obj): aiohttp client session for async loop
Returns:
data (obj): Individual URL request's response corountine | codesearchnet |
def saml_metadata(self, client_id):
return self.get(url='https: | Get SAML2.0 Metadata.
Args:
client_id (str): Client Id of the application to get the SAML metadata for. | codesearchnet |
def require_params(self, req):
params = {}
for name, param in self.params.items():
if name not in req.params and param.required:
missing = set(
p for p in self.params
if self.... | Require all defined parameters from request query string.
Raises ``falcon.errors.HTTPMissingParam`` exception if any of required
parameters is missing and ``falcon.errors.HTTPInvalidParam`` if any
of parameters could not be understood (wrong format).
Args:
req (falcon.Request): request object | juraj-google-style |
def fit(self, train_x, train_y):
if self.first_fitted:
self.incremental_fit(train_x, train_y)
else:
self.first_fit(train_x, train_y) | Fit the regressor with more data.
Args:
train_x: A list of NetworkDescriptor.
train_y: A list of metric values. | juraj-google-style |
def log_likelihood(self, y, _const=math.log((2.0 * math.pi)), quiet=False):
y = self._process_input(y)
resid = (y - self.mean.get_value(self._t))
try:
self._recompute()
except solver.LinAlgError:
if quiet:
return (- np.inf)
raise
if (len(y.shape) > 1):
rai... | Compute the marginalized likelihood of the GP model
The factorized matrix from the previous call to :func:`GP.compute` is
used so ``compute`` must be called first.
Args:
y (array[n]): The observations at coordinates ``x`` from
:func:`GP.compute`.
quiet (bool): If true, return ``-numpy.inf`` for non-positive
definite ... | codesearchnet |
def from_corpus(cls, corpus):
ds = Corpus()
tracks = copy.deepcopy(list(corpus.tracks.values()))
track_mapping = ds.import_tracks(tracks)
issuers = copy.deepcopy(list(corpus.issuers.values()))
issuer_mapping = ds.import_issuers(issuers)
... | Create a new modifiable corpus from any other CorpusView.
This for example can be used to create a independent modifiable corpus from a subview.
Args:
corpus (CorpusView): The corpus to create a copy from.
Returns:
Corpus: A new corpus with the same data as the given one. | juraj-google-style |
def __init__(self, faulty_file, msg):
self.file = faulty_file
self.msg = msg
super().__init__(faulty_file, msg) | Initialization of instances:
Args:
faulty_file (pathlike): path of the file where a parsing problem
was encountered.
msg (str): error message.
Attributes:
file (pathlike): path of the file where a parsing problem was
encountered.
msg (str): error message. | juraj-google-style |
def pi_to_number(self, page=1, item=1):
if page > 1:
return ((page - 1) * self.page_items) + item
else:
return 0 + item | Convert subpage & subitem to a integer
* if page == 1, then return 0, since the item count is the true # of items
* if page == 2, then return, page-1 * items_per_page, since we are
returning the # of items on a full page.
Args:
* None
Returns:
* Integer - Which represents the number of items up to the page. | juraj-google-style |
def __getitem__(self, column):
if isinstance(column, (list, tuple)):
ret = []
for col in column:
ret.append(self[col])
return ret
try:
return self._values[self._index[column]]
except (KeyError, TypeError, ValueError):
... | Support for [] notation.
Args:
column: Tuple of column names, or a (str) column name, or positional
column number, 0-indexed.
Returns:
A list or string with column value(s).
Raises:
IndexError: The given column(s) were not found. | juraj-google-style |
def classify_coincident(st_vals, coincident):
if (not coincident):
return None
if ((st_vals[(0, 0)] >= st_vals[(0, 1)]) or (st_vals[(1, 0)] >= st_vals[(1, 1)])):
return UNUSED_T
else:
return CLASSIFICATION_T.COINCIDENT | r"""Determine if coincident parameters are "unused".
.. note::
This is a helper for :func:`surface_intersections`.
In the case that ``coincident`` is :data:`True`, then we'll have two
sets of parameters :math:`(s_1, t_1)` and :math:`(s_2, t_2)`.
If one of :math:`s1 < s2` or :math:`t1 < t2` is not satisfied, the
coi... | codesearchnet |
def _InvokeGitkitApi(self, method, params=None, need_service_account=True):
body = (simplejson.dumps(params) if params else None)
req = urllib_request.Request((self.google_api_url + method))
req.add_header('Content-type', 'application/json')
if need_service_account:
if self.credentials:
... | Invokes Gitkit API, with optional access token for service account.
Args:
method: string, the api method name.
params: dict of optional parameters for the API.
need_service_account: false if service account is not needed.
Raises:
GitkitClientError: if the request is bad.
GitkitServerError: if Gitkit can not handle th... | codesearchnet |
def num_gpus():
return context().num_gpus() | Get the number of available GPU devices.
Returns:
The number of available GPU devices. | github-repos |
def putenv(key, value):
key = path2fsn(key)
value = path2fsn(value)
if (is_win and PY2):
try:
set_windows_env_var(key, value)
except WindowsError:
raise ValueError
else:
try:
os.putenv(key, value)
except OSError:
raise Value... | Like `os.putenv` but takes unicode under Windows + Python 2
Args:
key (pathlike): The env var to get
value (pathlike): The value to set
Raises:
ValueError | codesearchnet |
def _example_from_array_spec(self, prop_spec):
if isinstance(prop_spec['items'], list):
return [self.get_example_from_prop_spec(item_prop_spec) for item_prop_spec in prop_spec['items']]
elif ('type' in prop_spec['items'].keys()):
if (('format' in prop_spec['items'].keys()) and (prop_spec['items'... | Get an example from a property specification of an array.
Args:
prop_spec: property specification you want an example of.
Returns:
An example array. | codesearchnet |
def apply_transformation(self, structure):
if structure.is_ordered:
return structure
species = [dict(sp) for sp in structure.species_and_occu]
for sp in species:
for k, v in sp.items():
old_occ = sp[k]
new_occ = float(
... | Discretizes the site occupancies in the structure.
Args:
structure: disordered Structure to discretize occupancies
Returns:
A new disordered Structure with occupancies discretized | juraj-google-style |
def _make_dense_default(self, key, shape, dtype):
default_value = self.dense_defaults.get(key)
if shape.ndims is not None and shape.ndims > 0 and (shape.dims[0].value is None):
if default_value is None:
default_value = ops.convert_to_tensor('' if dtype == dtypes.string else 0, dtype=dtype)
... | Construct the default value tensor for a specified dense feature.
Args:
key: The key string identifying the dense feature.
shape: The dense feature's shape.
dtype: The dense feature's dtype.
Returns:
A Tensor. | github-repos |
def _enrichment_test_preprocessor(test_spec: dict, expected: List[str], env: TestEnvironment):
if (pipeline := test_spec.get('pipeline', None)):
for transform in pipeline.get('transforms', []):
if transform.get('type', '').startswith('Enrichment'):
transform['type'] = 'TestEnrich... | Preprocessor for tests that involve the Enrichment transform.
This preprocessor replaces the actual Enrichment transform with a mock
`TestEnrichment` transform. This allows the test to verify the pipeline's
correctness without requiring external services like BigTable or BigQuery.
Args:
test_spec: The dictionary repr... | github-repos |
def structure_path(self, path):
if (not path):
self.structure_dir = None
self.structure_file = None
else:
if (not op.exists(path)):
raise OSError('{}: file does not exist!'.format(path))
if (not op.dirname(path)):
self.structure_dir = '.'
else:
... | Provide pointers to the paths of the structure file
Args:
path: Path to structure file | codesearchnet |
def update(self, *args, **kwargs):
for next_dict in chain(args, (kwargs,)):
for (k, v) in next_dict.items():
self[k] = v | Equivalent to the python dict update method.
Update the dictionary with the key/value pairs from other, overwriting
existing keys.
Args:
other (dict): The source of key value pairs to add to headers
Keyword Args:
All keyword arguments are stored in header directly
Returns:
None | codesearchnet |
def add_node(self, node_id, name, labels):
node = self.graph_db.get_or_create_indexed_node('Node', 'node_id', node_id, {'node_id': node_id, 'name': name})
try:
node.add_labels(*labels)
except NotImplementedError:
pass | Add the node with name and labels.
Args:
node_id: Id for the node.
name: Name for the node.
labels: Label for the node.
Raises:
NotImplementedError: When adding labels is not supported. | codesearchnet |
def apply_grad_processors(opt, gradprocs):
assert isinstance(gradprocs, (list, tuple)), gradprocs
for gp in gradprocs:
assert isinstance(gp, GradientProcessor), gp
class _ApplyGradientProcessor(ProxyOptimizer):
def __init__(self, opt, gradprocs):
self._gradprocs = gradprocs[:]
... | Wrapper around optimizers to apply gradient processors.
Args:
opt (tf.train.Optimizer):
gradprocs (list[GradientProcessor]): gradient processors to add to the
optimizer.
Returns:
a :class:`tf.train.Optimizer` instance which runs the gradient
processors before updating the variables. | codesearchnet |
def __init__(self, model: PreTrainedModel):
super().__init__()
if model.generation_config is None:
raise AssertionError('The model must have a generation config to be exported with static caching. Please set `generation_config`.')
if not model.generation_config.use_cache:
raise AssertionErro... | Initializes the wrapper module with the pretrained model.
Args:
model (`PreTrainedModel`): The pretrained model to wrap. The model must have caching
enabled and use a 'static' caching implementation.
Raises:
AssertionError: If the pretrained model does not have caching enabled or if it does
not use a 'static' caching... | github-repos |
def RegisterImplementation(cache_name, map_name, cache):
global _cache_implementations
if cache_name not in _cache_implementations:
logging.info('Registering [%s] cache for [%s].', cache_name, map_name)
_cache_implementations[cache_name] = {}
_cache_implementations[cache_name][map_name] = ca... | Register a Cache implementation with the CacheFactory.
Child modules are expected to call this method in the file-level scope
so that the CacheFactory is aware of them.
Args:
cache_name: (string) The name of the NSS backend.
map_name: (string) The name of the map handled by this Cache.
cache: A class type that is a s... | github-repos |
def get_selector(self, name):
try:
return self.matcher.by_name[name]
except (AttributeError, KeyError):
if self.base is not None:
return self.base.get_selector(name)
else:
raise KeyError("No selector found for style '{}'".form... | Find a selector mapped to a style in this or a base style sheet.
Args:
name (str): a style name
Returns:
:class:`.Selector`: the selector mapped to the style `name`
Raises:
KeyError: if the style `name` was not found in this or a base
style sheet | juraj-google-style |
def op(name, data, bucket_count=None, display_name=None, description=None, collections=None):
import tensorflow.compat.v1 as tf
if (display_name is None):
display_name = name
summary_metadata = metadata.create_summary_metadata(display_name=display_name, description=description)
with tf.name_scop... | Create a legacy histogram summary op.
Arguments:
name: A unique name for the generated summary node.
data: A `Tensor` of any shape. Must be castable to `float64`.
bucket_count: Optional positive `int`. The output will have this
many buckets, except in two edge cases. If there is no data, then
there are no buckets. If ... | codesearchnet |
def setDocuments(self, documenting_pid, documented_pid):
self._check_initialized()
documenting_id = self.getObjectByPid(documenting_pid)
documented_id = self.getObjectByPid(documented_pid)
self.add((documenting_id, CITO.documents, documented_id)) | Add a CiTO, the Citation Typing Ontology, triple asserting that
``documenting_pid`` documents ``documented_pid``.
Adds assertion: ``documenting_pid cito:documents documented_pid``
Args:
documenting_pid: str
PID of a Science Object that documents ``documented_pid``.
documented_pid: str
PID of a Science Object that is... | juraj-google-style |
def print_stack_info(self):
try:
rest_api_id = None
deployment_found = False
response = self._cf_client.describe_stack_resources(
StackName=self._stack_name
)
print('\nThe following resources were created:')
rows ... | List resources from the given stack
Args:
None
Returns:
A dictionary filled resources or None if things went sideways | juraj-google-style |
def WriteOutput(self, output_file, feed_merger,
old_feed_path, new_feed_path, merged_feed_path):
if merged_feed_path is None:
html_merged_feed_path = ''
else:
html_merged_feed_path = '<p>Merged feed created: <code>%s</code></p>' % (
merged_feed_path)
html_header... | Write the HTML output to a file.
Args:
output_file: The file object that the HTML output will be written to.
feed_merger: The FeedMerger instance.
old_feed_path: The path to the old feed file as a string.
new_feed_path: The path to the new feed file as a string
merged_feed_path: The path to the merged feed file as a s... | juraj-google-style |
def conv1d(x, kernel, strides=1, padding='valid', data_format=None, dilation_rate=1):
if data_format is None:
data_format = image_data_format()
if data_format not in {'channels_first', 'channels_last'}:
raise ValueError('Unknown data_format: ' + str(data_format))
kernel_shape = kernel.shape.... | 1D convolution.
Args:
x: Tensor or variable.
kernel: kernel tensor.
strides: stride integer.
padding: string, `"same"`, `"causal"` or `"valid"`.
data_format: string, one of "channels_last", "channels_first".
dilation_rate: integer dilate rate.
Returns:
A tensor, result of 1D convolution.
Raises:
ValueError: if `data... | github-repos |
def _section_from_possible_title(possible_title):
for section in SECTION_TITLES:
if _matches_section(possible_title, section):
return section
return None | Returns a section matched by the possible title, or None if none match.
Args:
possible_title: A string that may be the title of a new section.
Returns:
A Section type if one matches, or None if no section type matches. | github-repos |
def randint(self, low: int, high: int) -> int:
return int(lib.TCOD_random_get_i(self.random_c, low, high)) | Return a random integer within the linear range: low <= n <= high.
Args:
low (int): The lower bound of the random range.
high (int): The upper bound of the random range.
Returns:
int: A random integer. | juraj-google-style |
def get_google_drive_folder_location():
gdrive_db_path = 'Library/Application Support/Google/Drive/sync_config.db'
yosemite_gdrive_db_path = 'Library/Application Support/Google/Drive/user_default/sync_config.db'
yosemite_gdrive_db = os.path.join(os.environ['HOME'], yosemite_gdrive_db_path)
if os.path.is... | Try to locate the Google Drive folder.
Returns:
(str) Full path to the current Google Drive folder | codesearchnet |
def set_cellpy_datadir(self, directory=None):
if directory is None:
self.logger.info("no directory name given")
return
if not os.path.isdir(directory):
self.logger.info("directory does not exist")
return
self.cellpy_datadir = directory | Set the directory containing .hdf5-files.
Used for setting directory for looking for hdf5-files.
A valid directory name is required.
Args:
directory (str): path to hdf5-directory
Example:
>>> d = CellpyData()
>>> directory = "MyData/HDF5"
>>> d.set_raw_datadir(directory) | juraj-google-style |
def DeregisterPlugin(cls, plugin_class):
name = getattr(plugin_class, 'ARTIFACT_DEFINITION_NAME', plugin_class.__name__)
name = name.lower()
if (name not in cls._plugins):
raise KeyError('Artifact plugin class not set for name: {0:s}.'.format(name))
del cls._plugins[name]
if (name in cls._fi... | Deregisters an preprocess plugin class.
Args:
plugin_class (type): preprocess plugin class.
Raises:
KeyError: if plugin class is not set for the corresponding name.
TypeError: if the source type of the plugin class is not supported. | codesearchnet |
def __init__(self, channel):
self.Lookup = channel.unary_unary(
"/google.datastore.v1.Datastore/Lookup",
request_serializer=google_dot_cloud_dot_datastore__v1_dot_proto_dot_datastore__pb2.LookupRequest.SerializeToString,
response_deserializer=google_dot_cloud_dot_dat... | Constructor.
Args:
channel: A grpc.Channel. | juraj-google-style |
def UpdateFrom(self, src):
if (not isinstance(src, PathInfo)):
raise TypeError(('expected `%s` but got `%s`' % (PathInfo, type(src))))
if (self.path_type != src.path_type):
raise ValueError(('src [%s] does not represent the same path type as self [%s]' % (src.path_type, self.path_type)))
if ... | Merge path info records.
Merges src into self.
Args:
src: An rdfvalues.objects.PathInfo record, will be merged into self.
Raises:
ValueError: If src does not represent the same path. | codesearchnet |
def __init__(self, callback):
super(RPCServer, self).__init__()
self._callback = callback | Initializes the RPC server object.
Args:
callback (function): callback to invoke on get status RPC request. | juraj-google-style |
def _process_book(link):
data = DOWNER.download(link)
dom = dhtmlparser.parseString(
utils.handle_encodnig(data)
)
dhtmlparser.makeDoubleLinked(dom)
price = None
try:
price = _strip_content(zapi.get_price(dom))
except UserWarning:
price = dom.find... | Download and parse available informations about book from the publishers
webpages.
Args:
link (str): URL of the book at the publishers webpages.
Returns:
obj: :class:`.Publication` instance with book details. | juraj-google-style |
def __init__(self, file_path_regex=None, log_format_regex=None, top_dir=None):
if file_path_regex is not None:
self.file_path_regex = file_path_regex
if log_format_regex is not None:
self.log_format_regex = log_format_regex
if top_dir is not None:
sel... | Init method.
Args:
file_path_regex (regex): the regex to find the log files.
log_format_regex (regex): the regex to parse the log files.
top_dir (str): the path to the root directory containing the logs. | juraj-google-style |
def fit(self, X):
if isinstance(X, (pd.Series, pd.DataFrame)):
self.name = X.name
self.constant_value = self._get_constant_value(X)
if self.constant_value is None:
self.mean = np.mean(X)
self.std = np.std(X)
else:
self._replace_... | Fit the model.
Arguments:
X: `np.ndarray` of shape (n, 1).
Returns:
None | juraj-google-style |
def RegisterMessage(self, message):
desc = message.DESCRIPTOR
self._symbols[desc.full_name] = message
if (desc.file.name not in self._symbols_by_file):
self._symbols_by_file[desc.file.name] = {}
self._symbols_by_file[desc.file.name][desc.full_name] = message
self.pool.AddDescriptor(desc)
... | Registers the given message type in the local database.
Args:
message: a message.Message, to be registered.
Returns:
The provided message. | codesearchnet |
def run_program(self, name, arguments=[], timeout=30, exclusive=False):
logger.debug('Running program ...')
if exclusive:
kill_longrunning(self.config)
prog = RunningProgram(self, name, arguments, timeout)
return prog.expect_end() | Runs a program in the working directory to completion.
Args:
name (str): The name of the program to be executed.
arguments (tuple): Command-line arguments for the program.
timeout (int): The timeout for execution.
exclusive (bool): Prevent parallel validation runs on the
test machines, e.g. when doing perf... | codesearchnet |
def util_granulate_time_series(time_series, scale):
n = len(time_series)
b = int(np.fix(n / scale))
temp = np.reshape(time_series[0:b*scale], (b, scale))
cts = np.mean(temp, axis = 1)
return cts | Extract coarse-grained time series
Args:
time_series: Time series
scale: Scale factor
Returns:
Vector of coarse-grained time series with given scale factor | juraj-google-style |
def __init__(self, optimizer, num_steps=10, unroll_loop=False, scope='multi-step', summary_labels=()):
assert isinstance(num_steps, int) and num_steps > 0
self.num_steps = num_steps
assert isinstance(unroll_loop, bool)
self.unroll_loop = unroll_loop
super(MultiStep, se... | Creates a new multi-step meta optimizer instance.
Args:
optimizer: The optimizer which is modified by this meta optimizer.
num_steps: Number of optimization steps to perform. | juraj-google-style |
def _apply_filters_to_first_location_occurrence(match_traversal, location_to_filters, already_filtered_locations):
new_match_traversal = []
newly_filtered_locations = set()
for match_step in match_traversal:
current_location = match_step.as_block.location
if (current_location in newly_filter... | Apply all filters for a specific location into its first occurrence in a given traversal.
For each location in the given match traversal,
construct a conjunction of all filters applied to that location,
and apply the resulting Filter to the first instance of the location.
Args:
match_traversal: list of MatchStep obje... | codesearchnet |
def movies_upcoming(self, **kwargs):
path = self._get_path('movies_upcoming')
response = self._GET(path, kwargs)
self._set_attrs_to_values(response)
return response | Gets the upcoming movies from the API.
Args:
page_limit (optional): number of movies to show per page, default=16
page (optional): results page number, default=1
country (optional): localized data for selected country, default="us"
Returns:
A dict respresentation of the JSON returned from the API. | juraj-google-style |
def format_usage(doc, width=None):
sections = doc.replace('\r', '').split('\n\n')
width = (width or get_terminal_size().columns or 80)
return '\n\n'.join((_wrap_section(s.strip(), width) for s in sections)) | Format the docstring for display to the user.
Args:
doc: The docstring to reformat for display.
Returns:
The docstring formatted to parse and display to the user. This includes
dedenting, rewrapping, and translating the docstring if necessary. | codesearchnet |
def stage_out(self, file, executor):
if ((file.scheme == 'http') or (file.scheme == 'https')):
raise Exception('HTTP/HTTPS file staging out is not supported')
elif (file.scheme == 'ftp'):
raise Exception('FTP file staging out is not supported')
elif (file.scheme == 'globus'):
globus_... | Transport the file from the local filesystem to the remote Globus endpoint.
This function returns a DataFuture.
Args:
- self
- file (File) - file to stage out
- executor (str) - Which executor the file is going to be staged out from.
If the executor argument is not specified for a file
with the 'globus' scheme, the f... | codesearchnet |
def normalize_url(base_url, rel_url):
if not rel_url:
return None
if not is_absolute_url(rel_url):
rel_url = rel_url.replace("../", "/")
if (not base_url.endswith("/")) and (not rel_url.startswith("/")):
return base_url + "/" + rel_url.replace("../", "/")
retu... | Normalize the `url` - from relative, create absolute URL.
Args:
base_url (str): Domain with ``protocol://`` string
rel_url (str): Relative or absolute url.
Returns:
str/None: Normalized URL or None if `url` is blank. | juraj-google-style |
def mobility(sdat, tstart=None, tend=None):
tseries = sdat.tseries_between(tstart, tend)
steps = sdat.steps[tseries.index[0]:tseries.index[-1]]
time = []
mob = []
for step in steps.filter(rprof=True):
time.append(step.timeinfo['t'])
mob.append(step.rprof.iloc[-1].loc['vrms'] / s... | Plates mobility.
Compute the ratio vsurf / vrms.
Args:
sdat (:class:`~stagpy.stagyydata.StagyyData`): a StagyyData instance.
tstart (float): time at which the computation should start. Use the
beginning of the time series data if set to None.
tend (float): time at which the computation should end. Use the
end of the ... | juraj-google-style |
def request(self, request):
url = '{}{}'.format(self._base_url, request.path)
timeout = self.poll_timeout
if (request.stream is True):
timeout = self.stream_timeout
try:
http_response = self._session.request(request.method, url, headers=self._headers, params=request.params, data=request.... | Perform an HTTP request through the context
Args:
request: A v20.request.Request object
Returns:
A v20.response.Response object | codesearchnet |
def _replace_args_with_defaults(self, _args=None, **kwargs):
if _args is None:
_args = six.iterkeys(kwargs)
my_defaults = self.defaults
for k in _args:
if k not in kwargs:
if k in my_defaults:
kwargs[k] = my_defaults[k]
elif k in _defaults:
kwargs[k] = _d... | Internal method to fill absent values in the kwargs with the defaults.
Args:
_args: A list of arguments to replace if a subset is required. Name
chosen to prevent conflicts with kwargs.
**kwargs: The arguments to replace with defaults.
Returns:
A map with the same fields as kwargs, but absent values are filled with
d... | juraj-google-style |
def parse_environment_file(filename, world_size=(60, 60)):
infile = open(filename)
lines = infile.readlines()
infile.close()
tasks = []
res_order = []
res_dict = {}
for line in lines:
if line.startswith("GRADIENT_RESOURCE"):
name, cells = parse_gradient(line,... | Extract information about spatial resources from an environment file.
Arguments:
filename - a string representing the path to the environment file.
world_size - a tuple representing the x and y coordinates of the world.
(default: 60x60)
Returns a list of lists of sets indicating the set of resources
available at each... | juraj-google-style |
def add(self, layers, above=None, below=None):
def add_named_layer(name, image):
image = self.get_image(image, output='vector')
if above is not None:
image[image < above] = 0.
if below is not None:
image[image > below] = 0.
... | Add one or more layers to the stack of masking layers.
Args:
layers: A string, NiBabel image, list, or dict. If anything other
than a dict is passed, assigns sequential layer names based on
the current position in stack; if a dict, uses key as the name
and value as the mask image. | juraj-google-style |
def options(self):
if context.executing_eagerly():
options = self._options_tensor_to_options(self._options())
options._set_mutable(False)
return options
warnings.warn('To make it possible to preserve tf.data options across serialization boundaries, their implementation has moved to be pa... | Returns the options for this dataset and its inputs.
Returns:
A `tf.data.Options` object representing the dataset options. | github-repos |
def create_html_from_fragment(tag):
try:
assert isinstance(tag, bs4.element.Tag)
except AssertionError:
raise TypeError
try:
assert tag.find_all('body') == []
except AssertionError:
raise ValueError
soup = BeautifulSoup('<html><head></head><body></body></html>'... | Creates full html tree from a fragment. Assumes that tag should be wrapped in a body and is currently not
Args:
tag: a bs4.element.Tag
Returns:"
bs4.element.Tag: A bs4 tag representing a full html document | juraj-google-style |
def claim(self, file_readers):
(prefix_to_readers, filter_files, unclaimed_set) = self._find_varscan_files(file_readers)
prefix_by_patients = self._split_prefix_by_patient(prefix_to_readers)
self._validate_vcf_readers(prefix_by_patients)
vcf_hc_pairs = self._pair_files(prefix_to_readers, filter_files)
... | Recognizes and claims VarScan VCFs form the set of all input VCFs.
Each defined caller has a chance to evaluate and claim all the incoming
files as something that it can process. Since VarScan can claim
high-confidence files as well, this process is significantly more
complex than for other callers.
Args:
file_reader... | codesearchnet |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.