code stringlengths 20 4.93k | docstring stringlengths 33 1.27k | source stringclasses 3
values |
|---|---|---|
def _sideral(date, longitude=0., model='mean', eop_correction=True, terms=106):
t = date.change_scale('UT1').julian_century
theta = 67310.54841 + (876600 * 3600 + 8640184.812866) * t + 0.093104 * t ** 2\
- 6.2e-6 * t ** 3
theta /= 240.
if model == 'apparent':
theta += ... | Get the sideral time at a defined date
Args:
date (Date):
longitude (float): Longitude of the observer (in degrees)
East positive/West negative.
model (str): 'mean' or 'apparent' for GMST and GAST respectively
Return:
float: Sideral time in degrees
GMST: Greenwich Mean Sideral Time
LST: Local Sideral Time (Mean)
GAST... | juraj-google-style |
def add_plugin(self, f):
if f.endswith('.py'):
plugin_name = os.path.splitext(os.path.basename(f))[0]
if plugin_name in sys.modules:
try:
handler = reload(sys.modules[plugin_name])
print'\t- %s %... | Adding and verifying plugin.
Args:
f: the filepath for the plugin. | juraj-google-style |
def get_domain_reports(self, domains):
api_name = 'virustotal-domain-reports'
(all_responses, domains) = self._bulk_cache_lookup(api_name, domains)
responses = self._request_reports("domain", domains, 'domain/report')
for domain, response in zip(domains, responses):
... | Retrieves the most recent VT info for a set of domains.
Args:
domains: list of string domains.
Returns:
A dict with the domain as key and the VT report as value. | juraj-google-style |
def add_minute(self, minute):
_moy = (self.moy + int(minute))
return self.__class__.from_moy(_moy) | Create a new DateTime after the minutes are added.
Args:
minute: An integer value for minutes. | codesearchnet |
def state_view_for_block(block_wrapper, state_view_factory):
state_root_hash = \
block_wrapper.state_root_hash \
if block_wrapper is not None else None
return state_view_factory.create_view(state_root_hash) | Returns the state view for an arbitrary block.
Args:
block_wrapper (BlockWrapper): The block for which a state
view is to be returned
state_view_factory (StateViewFactory): The state view factory
used to create the StateView object
Returns:
StateView object associated with the block | juraj-google-style |
def mkdir(self, path):
self.__validate_storage_path(path, projects_allowed=False)
parent_metadata = self.get_parent(path)
self.api_client.create_folder(path.split('/')[-1], parent_metadata['uuid']) | Create a folder in the storage service pointed by the given path.
Args:
path (str): The path of the folder to be created
Returns:
None
Raises:
StorageArgumentException: Invalid arguments
StorageForbiddenException: Server response code 403
StorageNotFoundException: Server response code 404
StorageException: other 400... | juraj-google-style |
def _execute(self, connection, query, fetch=True):
with connection.cursor() as cursor:
cursor.execute(query)
if fetch:
return cursor.fetchall()
else:
cursor.execute('COMMIT;') | Executes given query and returns result.
Args:
connection: connection to postgres database who stores mpr data.
query (str): sql query
fetch (boolean, optional): if True, fetch query result and return it. If False, do not fetch.
Returns:
iterable with query result or None if fetch is False. | codesearchnet |
def get_bucket_files(glob_pattern, base_dir, force=False, pattern_slice=slice(None)):
if (gcsfs is None):
raise RuntimeError("Missing 'gcsfs' dependency for GCS download.")
if (not os.path.isdir(base_dir)):
raise OSError('Directory does not exist: {}'.format(base_dir))
if isinstance(glob_pat... | Helper function to download files from Google Cloud Storage.
Args:
glob_pattern (str or list): Glob pattern string or series of patterns
used to search for on Google Cloud Storage. The pattern should
include the "gs://" protocol prefix. If a list of lists, then the
results of each sublist pattern are concatenated and ... | codesearchnet |
def OpenAndRead(relative_path='debugger-blacklist.yaml'):
try:
with open(os.path.join(sys.path[0], relative_path), 'r') as f:
return Read(f)
except IOError:
return None | Attempts to find the yaml configuration file, then read it.
Args:
relative_path: Optional relative path override.
Returns:
A Config object if the open and read were successful, None if the file
does not exist (which is not considered an error).
Raises:
Error (some subclass): As thrown by the called Read() function. | codesearchnet |
def _PromptUserForVSSCurrentVolume(self):
while True:
self._output_writer.Write('Volume Shadow Snapshots (VSS) were selected also process current\nvolume? [yes, no]\n')
process_current_volume = self._input_reader.Read()
process_current_volume = process_current_volume.strip()
process_... | Prompts the user if the current volume with VSS should be processed.
Returns:
bool: True if the current volume with VSS should be processed. | codesearchnet |
def look_source(self, sourcepath, library_paths=None):
if sourcepath not in self._CHILDREN_MAP:
with io.open(sourcepath, 'r', encoding='utf-8') as fp:
finded_paths = self.parse(fp.read())
children = self.resolve(sourcepath, finded_paths,
... | Open a SCSS file (sourcepath) and find all involved file through
imports.
This will fill internal buffers ``_CHILDREN_MAP`` and ``_PARENTS_MAP``.
Args:
sourcepath (str): Source file path to start searching for imports.
Keyword Arguments:
library_paths (list): List of directory paths for libraries to
resolve paths if... | juraj-google-style |
def get_cartesian(self):
def create_cartesian(positions, row):
xyz_frame = pd.DataFrame(columns=['atom', 'x', 'y', 'z'], index=self.index[:row], dtype='f8')
xyz_frame['atom'] = self.loc[(xyz_frame.index, 'atom')]
xyz_frame.loc[(:, ['x', 'y', 'z'])] = positions[:row]
from chemcoord.c... | Return the molecule in cartesian coordinates.
Raises an :class:`~exceptions.InvalidReference` exception,
if the reference of the i-th atom is undefined.
Args:
None
Returns:
Cartesian: Reindexed version of the zmatrix. | codesearchnet |
def getfileversion(self):
status, major_v, minor_v, release, info = _C.Hgetfileversion(self._id)
_checkErr('getfileversion', status, "cannot get file version")
return major_v, minor_v, release, info | Get file version info.
Args:
no argument
Returns:
4-element tuple with the following components:
-major version number (int)
-minor version number (int)
-complete library version number (int)
-additional information (string)
C library equivalent : Hgetlibversion | juraj-google-style |
def delete_fork_relation(self, **kwargs):
path = ('/projects/%s/fork' % self.get_id())
self.manager.gitlab.http_delete(path, **kwargs) | Delete a forked relation between existing projects.
Args:
**kwargs: Extra options to send to the server (e.g. sudo)
Raises:
GitlabAuthenticationError: If authentication is not correct
GitlabDeleteError: If the server failed to perform the request | codesearchnet |
def ami_lookup(region='us-east-1', name='tomcat8'):
if AMI_JSON_URL:
ami_dict = _get_ami_dict(AMI_JSON_URL)
ami_id = ami_dict[region][name]
elif GITLAB_TOKEN:
warn_user('Use AMI_JSON_URL feature instead.')
ami_contents = _get_ami_file(region=region)
ami_dict = json.loads(... | Look up AMI ID.
Use _name_ to find AMI ID. If no ami_base_url or gitlab_token is provided,
_name_ is returned as the ami id.
Args:
region (str): AWS Region to find AMI ID.
name (str): Simple AMI base name to lookup.
Returns:
str: AMI ID for _name_ in _region_. | codesearchnet |
def get_msd_plot(self, plt=None, mode='specie'):
from pymatgen.util.plotting import pretty_plot
plt = pretty_plot(12, 8, plt=plt)
if (np.max(self.dt) > 100000):
plot_dt = (self.dt / 1000)
unit = 'ps'
else:
plot_dt = self.dt
unit = 'fs'
if (mode == 'species'):
... | Get the plot of the smoothed msd vs time graph. Useful for
checking convergence. This can be written to an image file.
Args:
plt: A plot object. Defaults to None, which means one will be
generated.
mode (str): Determines type of msd plot. By "species", "sites",
or direction (default). If mode = "mscd", the smoothed ms... | codesearchnet |
def verify(self, obj):
if obj not in self.options:
raise ValidationError("Object is not in list of enumerated options",
reason='not in list of enumerated options', object=obj, options=self.options)
return obj | Verify that the object conforms to this verifier's schema.
Args:
obj (object): A python object to verify
Raises:
ValidationError: If there is a problem verifying the object, a
ValidationError is thrown with at least the reason key set indicating
the reason for the lack of validation. | juraj-google-style |
def times(*combined):
assert combined
if len(combined) == 1:
return combined[0]
first = combined[0]
rest_combined = times(*combined[1:])
combined_results = []
for a in first:
for b in rest_combined:
if set(a.keys()).intersection(set(b.keys())):
raise V... | Generate a product of N sets of combinations.
times(combine(a=[1,2]), combine(b=[3,4])) == combine(a=[1,2], b=[3,4])
Args:
*combined: N lists of dictionaries that specify combinations.
Returns:
a list of dictionaries for each combination.
Raises:
ValueError: if some of the inputs have overlapping keys. | github-repos |
def get_developer_package(path, format=None):
from rez.developer_package import DeveloperPackage
return DeveloperPackage.from_path(path, format=format) | Create a developer package.
Args:
path (str): Path to dir containing package definition file.
format (str): Package definition file format, detected if None.
Returns:
`DeveloperPackage`. | juraj-google-style |
def get_pending_enrollment_message(cls, pending_users, enrolled_in):
pending_emails = [pending_user.user_email for pending_user in pending_users]
return (
'warning',
_(
"The following learners do not have an account on "
"{platform_name}. ... | Create message for the users who were enrolled in a course or program.
Args:
users: An iterable of PendingEnterpriseCustomerUsers who were successfully linked with a pending enrollment
enrolled_in (str): A string identifier for the course or program the pending users were linked to
Returns:
tuple: A 2-tuple containin... | juraj-google-style |
def _group_value_by_device(per_replica_values):
destinations = per_replica_values[0]._devices
grouped = [[] for _ in range(len(destinations))]
for per_replica_value in per_replica_values:
for i, v in enumerate(per_replica_value.values):
assert per_replica_value._devices == destinations
... | Group values into sublists by their devices.
This grouping is needed to call the all-reduce library because it expects a
list of the following form:
[[(grad0_gpu0, v0_gpu0), (grad1_gpu0, v1_gpu0), (grad2_gpu0, v2_gpu0) ...],
[(grad0_gpu1, v0_gpu1), (grad1_gpu1, v1_gpu1), (grad2_gpu1, v2_gpu1) ...],
[(grad0_gpu2, v0_gp... | github-repos |
def LoadData(self, data, custom_properties=None):
self.__data = []
self.AppendData(data, custom_properties) | Loads new rows to the data table, clearing existing rows.
May also set the custom_properties for the added rows. The given custom
properties dictionary specifies the dictionary that will be used for *all*
given rows.
Args:
data: The rows that the table will contain.
custom_properties: A dictionary of string to string... | juraj-google-style |
def url_is(white_list):
def func(url):
prefixes = white_list.get('PREFIXES', ())
for prefix in prefixes:
if url.startswith(prefix):
return True
constants = white_list.get('CONSTANTS', ())
for exact_url in constants:
if (url == exact_url):
... | Function generator.
Args:
white_list (dict): dict with PREFIXES and CONSTANTS keys (list values).
Returns:
func: a function to check if a URL is... | codesearchnet |
def _cached_by_domain(api_name):
def wrapped(func):
def decorated(self, domains):
if (not self._cache):
return func(self, domains)
all_responses = self._cache.bulk_lookup(api_name, domains)
domains = list((set(domains) - set(all_responses)))
... | A caching wrapper for functions that take a list of domains as
parameters.
Raises:
ResponseError - if the response received from the endpoint is
not valid. | codesearchnet |
def process_new_issues(self, volumes, existing_issues):
new_issues = {}
for (issue_id, volume) in volumes.items():
state = EBSIssueState.DETECTED.value
if (issue_id in existing_issues):
issue = existing_issues[issue_id]
data = {'state': state, 'notes': issue.notes, 'last_... | Takes a dict of existing volumes missing tags and a dict of existing issues, and finds any new or updated
issues.
Args:
volumes (:obj:`dict` of `str`: `EBSVolume`): Dict of current volumes with issues
existing_issues (:obj:`dict` of `str`: `EBSVolumeAuditIssue`): Current list of issues
Returns:
:obj:`dict` of `str`: ... | codesearchnet |
def convert_tokens_into_matrix(self, token_list):
return np.array(self.vectorize(token_list)).astype(np.float32) | Create matrix of sentences.
Args:
token_list: The list of tokens.
Returns:
2-D `np.ndarray` of sentences.
Each row means one hot vectors of one sentence. | juraj-google-style |
def flatten_(structure):
if isinstance(structure, dict):
if structure:
structure = zip(*sorted(structure.items(), key=lambda x: x[0]))[1]
else:
structure = ()
if isinstance(structure, (tuple, list)):
result = []
for element in structure:
result += flatten_(element)
re... | Combine all leaves of a nested structure into a tuple.
The nested structure can consist of any combination of tuples, lists, and
dicts. Dictionary keys will be discarded but values will ordered by the
sorting of the keys.
Args:
structure: Nested structure.
Returns:
Flat tuple. | juraj-google-style |
def validate_read(self, address):
if not any(address.startswith(ns) for ns in self._read_list):
raise AuthorizationException(address=address) | Raises an exception if the address is not allowed to be read in
this context, based on txn inputs.
Args:
address (str): An address to be validated.
Returns:
None
Raises:
AuthorizationException | juraj-google-style |
def process_answer(self, user, item, asked, answered, time, answer, response_time, guess, **kwargs):
pass | This method is used during the answer streaming and is called after the
predictive model for each answer.
Args:
user (int):
identifier of ther user answering the question
asked (int):
identifier of the asked item
answered (int):
identifier of the answered item or None if the user answered
"I don't know"
response_time ... | codesearchnet |
def print_serial_number_info(self, serial_number, print_to_screen=True):
r = self.select_serial_number_row(serial_number)
if r.empty:
warnings.warn("missing serial number")
return
txt1 = 80 * "="
txt1 += "\n"
txt1 += f" serial number {serial_nu... | Print information about the run.
Args:
serial_number: serial number.
print_to_screen: runs the print statement if True,
returns txt if not.
Returns:
txt if print_to_screen is False, else None. | juraj-google-style |
def concat_pairs(tensor_tuple0: Tuple[torch.Tensor], tensor_tuple1: Tuple[torch.Tensor]) -> Tuple[torch.Tensor]:
return tuple([torch.cat([tensor0, tensor1]) for tensor0, tensor1 in zip(tensor_tuple0, tensor_tuple1)]) | Concatenate two tuples of tensors pairwise
Args:
tensor_tuple0 (`Tuple[torch.Tensor]`):
Tuple of tensors.
tensor_tuple1 (`Tuple[torch.Tensor]`):
Tuple of tensors.
Returns:
(`Tuple[torch.Tensor]`): Tuple of concatenated tensors. | github-repos |
def __init__(self, inputs=None,
outputs=None,
assettype=AssetType.GoverningToken,
assetname='',
amount=Fixed8(0),
precision=0,
owner=None,
admin=None):
super(RegisterTransaction, self)... | Create an instance.
Args:
inputs (list):
outputs (list):
assettype (neo.Core.AssetType):
assetname (str):
amount (Fixed8):
precision (int): number of decimals the asset has.
owner (EllipticCurve.ECPoint):
admin (UInt160): | juraj-google-style |
def trigger(self, target: str, trigger: str, parameters: Dict[(str, Any)]={}):
pass | Calls the specified Trigger of another Area with the optionally given parameters.
Args:
target: The name of the target Area.
trigger: The name of the Trigger.
parameters: The parameters of the function call. | codesearchnet |
def RegisterSourceType(cls, source_type_class):
if (source_type_class.TYPE_INDICATOR in cls._source_type_classes):
raise KeyError('Source type already set for type: {0:s}.'.format(source_type_class.TYPE_INDICATOR))
cls._source_type_classes[source_type_class.TYPE_INDICATOR] = source_type_class | Registers a source type.
Source types are identified based on their type indicator.
Args:
source_type_class (type): source type.
Raises:
KeyError: if source types is already set for the corresponding
type indicator. | codesearchnet |
def create_additional_charge(self, *, subscription_id, description, plan_value, plan_tax, plan_tax_return_base, currency):
payload = {'description': description, 'additionalValues': [{'name': 'ITEM_VALUE', 'value': plan_value, 'currency': currency}, {'name': 'ITEM_TAX', 'value': plan_tax, 'currency': currency}, {'n... | Adds extra charges to the respective invoice for the current period.
Args:
subscription_id: Identification of the subscription
description:
plan_value:
plan_tax:
plan_tax_return_base:
currency:
Returns: | codesearchnet |
def create_list(self, **kwargs):
path = self._get_path('create_list')
kwargs.update({'session_id': self.session_id})
payload = {'name': kwargs.pop('name', None), 'description': kwargs.pop('description', None)}
if ('language' in kwargs):
payload['language'] = kwargs['language']
response = sel... | Create a new list.
A valid session id is required.
Args:
name: Name of the list.
description: Description of the list.
language: (optional) ISO 639-1 code.
Returns:
A dict respresentation of the JSON returned from the API. | codesearchnet |
def rotation(self):
rotation = self._libinput.libinput_event_tablet_tool_get_rotation(self._handle)
changed = self._libinput.libinput_event_tablet_tool_rotation_has_changed(self._handle)
return (rotation, changed) | The current Z rotation of the tool in degrees, clockwise
from the tool's logical neutral position and whether it has changed
in this event.
For tools of type :attr:`~libinput.constant.TabletToolType.MOUSE`
and :attr:`~libinput.constant.TabletToolType.LENS` the logical
neutral position is pointing to the current logica... | codesearchnet |
def memcached_client(servers=config.memcached_uri, debug=config.debug_memcache):
key = None
try:
(client, key) = scoped_instance_manager.acquire(servers, debug=debug)
(yield client)
finally:
if key:
scoped_instance_manager.release(key) | Get a shared memcached instance.
This function shares the same memcached instance across nested invocations.
This is done so that memcached connections can be kept to a minimum, but at
the same time unnecessary extra reconnections are avoided. Typically an
initial scope (using 'with' construct) is made around parts of... | codesearchnet |
def get_initial_state_args(value_and_gradients_function, initial_position, grad_tolerance, control_inputs=None):
if control_inputs:
with tf.control_dependencies(control_inputs):
(f0, df0) = value_and_gradients_function(initial_position)
else:
(f0, df0) = value_and_gradients_function(... | Returns a dictionary to populate the initial state of the search procedure.
Performs an initial convergence check and the first evaluation of the
objective function.
Args:
value_and_gradients_function: A Python callable that accepts a tensor and
returns a tuple of two tensors: the objective function value and its
der... | codesearchnet |
def label_count(self, label_list_ids=None):
count = collections.defaultdict(int)
for label_list in self.label_lists.values():
if ((label_list_ids is None) or (label_list.idx in label_list_ids)):
for (label_value, label_count) in label_list.label_count().items():
count[label_v... | Return a dictionary containing the number of times,
every label-value in this utterance is occurring.
Args:
label_list_ids (list): If not None, only labels from label-lists
with an id contained in this list
are considered.
Returns:
dict: A dictionary containing the number of occurrences
with the label-value as key. | codesearchnet |
def show(self, view: View, request: Request):
return view.render('welcome', {'app': request.app().make('Application')}) | Show the welcome page.
Arguments:
view {masonite.view.View} -- The Masonite view class.
Application {config.application} -- The application config module.
Returns:
masonite.view.View -- The Masonite view class. | codesearchnet |
def build_inputs_with_special_tokens(self, token_ids_0: List[int], token_ids_1: Optional[List[int]]=None) -> List[int]:
if token_ids_1 is None:
return self.prefix_tokens + token_ids_0 + self.suffix_tokens
return self.prefix_tokens + token_ids_0 + token_ids_1 + self.suffix_tokens | Build model inputs from a sequence or a pair of sequence for sequence classification tasks by concatenating and
adding special tokens. An PLBART sequence has the following format, where `X` represents the sequence:
- `input_ids` (for encoder) `X [eos, src_lang_code]`
- `decoder_input_ids`: (for decoder) `X [eos, tgt_l... | github-repos |
def dynamic_import(modname, import_tuples, developing=True, ignore_froms=[], dump=False, ignore_startswith=[], ignore_endswith=[], ignore_list=[], check_not_imported=True, return_initstr=False, verbose=False):
if verbose:
print(('[UTIL_IMPORT] Running Dynamic Imports for modname=%r ' % modname))
try:
... | MAIN ENTRY POINT
Dynamically import listed util libraries and their attributes.
Create reload_subs function.
Using __import__ like this is typically not considered good style However,
it is better than import * and this will generate the good file text that
can be used when the module is 'frozen"
Returns:
str: init_... | codesearchnet |
def GetLaunchedFlows(self, flow_type='outstanding'):
result = None
all_clients = set(self.ListAllClients())
finished_clients = set(self.ListFinishedClients())
outstanding_clients = (all_clients - finished_clients)
if (flow_type == 'all'):
result = all_clients
elif (flow_type == 'finished... | Returns the session IDs of all the flows we launched.
Args:
flow_type: The type of flows to fetch. Can be "all", "outstanding" or
"finished".
Returns:
A list of flow URNs. | codesearchnet |
def check_models_are_auto_configured(module: types.ModuleType, all_auto_models: List[str]) -> List[str]:
defined_models = get_models(module)
failures = []
for model_name, _ in defined_models:
if model_name not in all_auto_models and (not ignore_unautoclassed(model_name)):
failures.append... | Check models defined in module are each in an auto class.
Args:
module (`types.ModuleType`):
The module in which we get the models.
all_auto_models (`List[str]`):
The list of all models in an auto class (as obtained with `get_all_auto_configured_models()`).
Returns:
`List[str]`: The list of error messages correspondi... | github-repos |
def overlap(self, feature, stranded: bool=False):
feature_strand = feature.strand
strand = self.strand
if (stranded and ((strand == '.') or ((strand == '+') and (feature_strand in ['-', '.'])) or ((strand == '-') and (feature_strand in ['+', '.'])))):
return False
iv_1 = set(range(feature.start,... | Determine if a feature's position overlaps with the entry
Args:
feature (class): GFF3Entry object
stranded (bool): allow features to overlap on different strands
if True [default: False]
Returns:
bool: True if features overlap, else False | codesearchnet |
def _add_mgmt_to_domains(self, conf, mgmts):
for dom_name, dom_spec in conf['domains'].iteritems():
domain_mgmt = [
nic['net'] for nic in dom_spec['nics'] if nic['net'] in mgmts
].pop()
dom_spec['mgmt_net'] = domain_mgmt | Add management network key('mgmt_net') to each domain. Note this
assumes ``conf`` was validated.
Args:
conf(dict): spec
mgmts(list): list of management networks names | juraj-google-style |
def prepare(self, variables):
initializedsteps = []
if variables is None:
variables = dict()
for step, params, _resources, _files in self.steps:
new_params = _complete_parameters(params, variables)
initializedsteps.append(step(new_params))
ret... | Initialize all steps in this recipe using their parameters.
Args:
variables (dict): A dictionary of global variable definitions
that may be used to replace or augment the parameters given
to each step.
Returns:
list of RecipeActionObject like instances: The list of instantiated
steps that can be used to execute this ... | juraj-google-style |
def _get_symmetry(self):
d = spglib.get_symmetry(self._cell, symprec=self._symprec, angle_tolerance=self._angle_tol)
trans = []
for t in d['translations']:
trans.append([float(Fraction.from_float(c).limit_denominator(1000)) for c in t])
trans = np.array(trans)
trans[(np.abs(trans) == 1)] = 0... | Get the symmetry operations associated with the structure.
Returns:
Symmetry operations as a tuple of two equal length sequences.
(rotations, translations). "rotations" is the numpy integer array
of the rotation matrices for scaled positions
"translations" gives the numpy float64 array of the translation
vectors in sc... | codesearchnet |
def encode(self, input_ids: jnp.ndarray, attention_mask: Optional[jnp.ndarray]=None, position_ids: Optional[jnp.ndarray]=None, output_attentions: Optional[bool]=None, output_hidden_states: Optional[bool]=None, return_dict: Optional[bool]=None, train: bool=False, params: Optional[dict]=None, dropout_rng: PRNGKey=None):
... | Returns:
Example:
```python
>>> from transformers import AutoTokenizer, FlaxPegasusForConditionalGeneration
>>> model = FlaxPegasusForConditionalGeneration.from_pretrained("google/pegasus-large")
>>> tokenizer = AutoTokenizer.from_pretrained("google/pegasus-large")
>>> text = "My friends are cool but they eat too m... | github-repos |
def for_input_type(self, input_type):
return self | Returns a specialized implementation of self, if it exists.
Otherwise, returns self.
Args:
input_type: the type of input elements. | github-repos |
def _add_def_paths(self, prop_dict):
for prop_key, prop_value in prop_dict.iteritems():
if prop_key == '$ref' and not 'prop_value'.startswith('
prop_dict[prop_key] = '
elif isinstance(prop_value, dict):
self._add_def_paths(prop_value) | Recursive method to add relative paths for any $ref objects.
Args:
prop_dict: The property dict to alter.
Side Effects:
Alters prop_dict in-place. | juraj-google-style |
def get_collection(self, id_or_uri, filter=''):
if filter:
filter = self.__make_query_filter(filter)
filter = "?" + filter[1:]
uri = "{uri}{filter}".format(uri=self.build_uri(id_or_uri), filter=filter)
logger.debug('Get resource collection (uri = %s)' % uri)
... | Retrieves a collection of resources.
Use this function when the 'start' and 'count' parameters are not allowed in the GET call.
Otherwise, use get_all instead.
Optional filtering criteria may be specified.
Args:
id_or_uri: Can be either the resource ID or the resource URI.
filter (list or str): General filter/query ... | juraj-google-style |
def _validate(self, value):
_LOGGER.info('validate: Got type %s', type(value))
if ((value is not None) and (not isinstance(value, client.Flow))):
raise TypeError('Property {0} must be convertible to a flow instance; received: {1}.'.format(self._name, value)) | Validates a value as a proper Flow object.
Args:
value: A value to be set on the property.
Raises:
TypeError if the value is not an instance of Flow. | codesearchnet |
def Delete(self, request, global_params=None):
config = self.GetMethodConfig('Delete')
return self._RunMethod(config, request, global_params=global_params) | Delete an association between a GCP project and a GitHub Enterprise server.
Args:
request: (CloudbuildProjectsGithubEnterpriseConfigsDeleteRequest) input message
global_params: (StandardQueryParameters, default: None) global arguments
Returns:
(Operation) The response message. | github-repos |
def ParseFileObject(self, parser_mediator, file_object):
try:
self._ParseFileHeader(file_object)
except errors.ParseError as exception:
raise errors.ParseError('Unable to parse index file header with error: {0!s}'.format(exception))
file_object.seek(112, os.SEEK_CUR)
self._ParseIndexTabl... | Parses a file-like object.
Args:
parser_mediator (ParserMediator): a parser mediator.
file_object (dfvfs.FileIO): a file-like object to parse.
Raises:
ParseError: when the file cannot be parsed. | codesearchnet |
def create_project(self, collab_id):
return self._authenticated_request.to_endpoint('project/').with_json_body(self._prep_params(locals())).return_body().post() | Create a new project.
Args:
collab_id (int): The id of the collab the project should be created in.
Returns:
A dictionary of details of the created project::
{
u'collab_id': 12998,
u'created_by': u'303447',
u'created_on': u'2017-03-21T14:06:32.293902Z',
u'description': u'',
u'entity_type': u'project',
u'modified_by'... | codesearchnet |
def _map_query_path_to_location_info(query_metadata_table):
query_path_to_location_info = {}
for (location, location_info) in query_metadata_table.registered_locations:
if (not isinstance(location, Location)):
continue
if (location.query_path in query_path_to_location_info):
... | Create a map from each query path to a LocationInfo at that path.
Args:
query_metadata_table: QueryMetadataTable, object containing all metadata collected during
query processing, including location metadata (e.g. which locations
are folded or optional).
Returns:
Dict[Tuple[str], LocationInfo], dictionary mapping que... | codesearchnet |
def __init__(self, filename, sample_filename, probability_threshold=0.9):
self.samples = pd.read_csv(sample_filename, sep=" ", skiprows=2,
names=["fid", "iid", "missing", "father",
"mother", "sex", "plink_geno"],
... | IMPUTE2 file reader.
Args:
filename (str): The name of the IMPUTE2 file.
sample_filename (str): The name of the SAMPLE file.
probability_threshold (float): The probability threshold.
Note
====
If the sample IDs are not unique, the index is changed to be the
sample family ID and individual ID (i.e. fid_iid). | juraj-google-style |
def __parse_tostr(self, text, **kwargs):
n = self.options.get('nbest', 1)
if (self._KW_BOUNDARY in kwargs):
patt = kwargs.get(self._KW_BOUNDARY, '.')
tokens = list(self.__split_pattern(text, patt))
text = ''.join([t[0] for t in tokens])
btext = self.__str2bytes(text)
self... | Builds and returns the MeCab function for parsing Unicode text.
Args:
fn_name: MeCab function name that determines the function
behavior, either 'mecab_sparse_tostr' or
'mecab_nbest_sparse_tostr'.
Returns:
A function definition, tailored to parsing Unicode text and
returning the result as a string suitable for displa... | codesearchnet |
def set_agent(self, short_name, client_id):
if (short_name not in self.services):
raise ArgumentError('Unknown service name', short_name=short_name)
self.agents[short_name] = client_id | Register a client id that handlers commands for a service.
Args:
short_name (str): The name of the service to set an agent
for.
client_id (str): A globally unique id for the client that
should receive commands for this service. | codesearchnet |
def new_panel(store, institute_id, panel_name, display_name, csv_lines):
institute_obj = store.institute(institute_id)
if (institute_obj is None):
flash('{}: institute not found'.format(institute_id))
return None
panel_obj = store.gene_panel(panel_name)
if panel_obj:
flash('panel... | Create a new gene panel.
Args:
store(scout.adapter.MongoAdapter)
institute_id(str)
panel_name(str)
display_name(str)
csv_lines(iterable(str)): Stream with genes
Returns:
panel_id: the ID of the new panel document created or None | codesearchnet |
def __init__(self, args=None, varargs=None, varkw=None, defaults=None, kwonlyargs=None, kwonlydefaults=None, annotations=None):
self.args = args or []
self.varargs = varargs
self.varkw = varkw
self.defaults = defaults or ()
self.kwonlyargs = kwonlyargs or []
self.kwonlydefaults = kwonlydefaults ... | Constructs a FullArgSpec with each provided attribute, or the default.
Args:
args: A list of the argument names accepted by the function.
varargs: The name of the *varargs argument or None if there isn't one.
varkw: The name of the **kwargs argument or None if there isn't one.
defaults: A tuple of the defaults for the... | github-repos |
def clock(self, interval, basis):
cache_name = self._classify_clock(interval, basis)
cache_data = self.clock_cache.get(cache_name)
if cache_data is None:
parent_stream, trigger = self.parent.clock(interval, basis)
if trigger.use_count is False:
... | Return a NodeInput tuple for triggering an event every interval.
We request each distinct type of clock at most once and combine it with our
latch stream each time it is requested.
Args:
interval (int): The interval (in seconds) at which this input should
trigger. | juraj-google-style |
def floor(cls, x: 'TensorFluent') -> 'TensorFluent':
return cls._unary_op(x, tf.floor, tf.float32) | Returns a TensorFluent for the floor function.
Args:
x: The input fluent.
Returns:
A TensorFluent wrapping the floor function. | codesearchnet |
def _get_grand_potential(self, composition):
if self.use_hull_energy:
grand_potential = self.pd_non_grand.get_hull_energy(composition)
else:
grand_potential = InterfacialReactivity._get_entry_energy(
self.pd_non_grand, composition)
grand_potential... | Computes the grand potential Phi at a given composition and
chemical potential(s).
Args:
composition (Composition): Composition object.
Returns:
Grand potential at a given composition at chemical potential(s). | juraj-google-style |
def generate(arglist, git_tag_override=None):
spec, head_symlink, _, dest_file = arglist
data = json.load(open(spec))
git_version = None
if not data['git']:
git_version = b'unknown'
else:
old_branch = data['branch']
new_branch = parse_branch_ref(head_symlink)
if new_b... | Generate version_info.cc as given `destination_file`.
Args:
arglist: should be a sequence that contains
spec, head_symlink, ref_symlink, destination_file.
`destination_file` is the filename where version_info.cc will be written
`spec` is a filename where the file contains a JSON dictionary
'git' bool that is true if... | github-repos |
def is_location(v) -> (bool, str):
def convert2float(value):
try:
float_num = float(value)
return float_num
except ValueError:
return False
if (not isinstance(v, str)):
return (False, v)
split_lst = v.split(':')
if (len(split_lst) != 5):
... | Boolean function for checking if v is a location format
Args:
v:
Returns: bool | codesearchnet |
def save_link(self, path_info):
assert path_info["scheme"] == "local"
path = path_info["path"]
if not os.path.exists(path):
return
mtime, _ = get_mtime_and_size(path)
inode = get_inode(path)
relpath = os.path.relpath(path, self.root_dir)
cm... | Adds the specified path to the list of links created by dvc. This
list is later used on `dvc checkout` to cleanup old links.
Args:
path_info (dict): path info to add to the list of links. | juraj-google-style |
def __init__(self, label, names=(), path=None):
self.label = label
self.names = names
self.path = path
for name in names:
setattr(self, name, self.__class__(name, path="{0}.{1}".format(path, label) if path else label)) | Create a new enumeration. The parent enum creates an instance for each item.
Args:
label (str): enum name
names (list): item labels
path (list): qualified parent name, for :func:`repr` output | juraj-google-style |
def output(self, filename):
if filename == '':
filename = 'contracts.dot'
if not filename.endswith('.dot'):
filename += ".dot"
info = 'Inheritance Graph: ' + filename
self.info(info)
with open(filename, 'w', encoding='utf8') as f:
f.wr... | Output the graph in filename
Args:
filename(string) | juraj-google-style |
def show(config, section, opt):
if section not in config.keys():
raise ConfigError("section '{}' doesn't exist".format(section))
if opt not in config[section].keys():
raise ConfigError(
"option '{}.{}' doesn't exist".format(section, opt)
)
... | Prints option value from the config.
Args:
config (configobj.ConfigObj): config to work on.
section (str): section name.
opt (str): option name. | juraj-google-style |
def _generate_parser(name, path, required=False, notfoundmsg=None):
output = ('def %s(dom):\n' % _get_parser_name(name))
dom = True
parser_table = {'find': (lambda path: _find_template(path.params, path.index, required, notfoundmsg)), 'wfind': (lambda path: _wfind_template(dom, path.params, path.index, requ... | Generate parser named `name` for given `path`.
Args:
name (str): Basename for the parsing function (see
:func:`_get_parser_name` for details).
path (obj): :class:`.PathCall` or :class:`.Chained` instance.
required (bool, default False): Use :func:`_required_idiom` to returned
data.
notfoundmsg (str, default None): Mes... | codesearchnet |
def plot_iso(axis, step, var):
(xmesh, ymesh, fld) = get_meshes_fld(step, var)
if conf.field.shift:
fld = np.roll(fld, conf.field.shift, axis=0)
axis.contour(xmesh, ymesh, fld, linewidths=1) | Plot isocontours of scalar field.
Args:
axis (:class:`matplotlib.axes.Axes`): the axis handler of an
existing matplotlib figure where the isocontours should
be plotted.
step (:class:`~stagpy.stagyydata._Step`): a step of a StagyyData
instance.
var (str): the scalar field name. | codesearchnet |
def predict(self, text):
pred = self.predict_proba(text)
tags = self._get_tags(pred)
return tags | Predict using the model.
Args:
text: string, the input text.
Returns:
tags: list, shape = (num_words,)
Returns predicted values. | juraj-google-style |
def quat2mat(quaternion):
q = np.array(quaternion, dtype=np.float32, copy=True)[[3, 0, 1, 2]]
n = np.dot(q, q)
if n < EPS:
return np.identity(3)
q *= math.sqrt(2.0 / n)
q = np.outer(q, q)
return np.array(
[
[1.0 - q[2, 2] - q[3, 3], q[1, 2] - q[3, 0], q[1, 3] + q... | Converts given quaternion (x, y, z, w) to matrix.
Args:
quaternion: vec4 float angles
Returns:
3x3 rotation matrix | juraj-google-style |
def AddEnumDescriptor(self, enum_desc):
if not isinstance(enum_desc, descriptor.EnumDescriptor):
raise TypeError('Expected instance of descriptor.EnumDescriptor.')
self._enum_descriptors[enum_desc.full_name] = enum_desc
self.AddFileDescriptor(enum_desc.file) | Adds an EnumDescriptor to the pool.
This method also registers the FileDescriptor associated with the message.
Args:
enum_desc: An EnumDescriptor. | juraj-google-style |
def multi_flags_validator(flag_names, message='Flag validation failed', flag_values=FLAGS):
def decorate(function):
register_multi_flags_validator(flag_names, function, message=message, flag_values=flag_values)
return function
return decorate | A function decorator for defining a multi-flag validator.
Registers the decorated function as a validator for flag_names, e.g.
@gflags.multi_flags_validator(['foo', 'bar'])
def _CheckFooBar(flags_dict):
...
See register_multi_flags_validator() for the specification of checker
function.
Args:
flag_names: [str], a li... | codesearchnet |
def BalanceFor(self, assetId):
for (key, fixed8) in self.Balances.items():
if (key == assetId):
return fixed8
return Fixed8(0) | Get the balance for a given asset id.
Args:
assetId (UInt256):
Returns:
Fixed8: balance value. | codesearchnet |
def _init_from_bool(self, z, x):
if (z is None):
raise QiskitError('z vector must not be None.')
if (x is None):
raise QiskitError('x vector must not be None.')
if (len(z) != len(x)):
raise QiskitError('length of z and x vectors must be the same. (z: {} vs x: {})'.format(len(z), len(... | Construct pauli from boolean array.
Args:
z (numpy.ndarray): boolean, z vector
x (numpy.ndarray): boolean, x vector
Returns:
Pauli: self
Raises:
QiskitError: if z or x are None or the length of z and x are different. | codesearchnet |
def remove_child(self, child):
if child in self.children.values() and hasattr(child, 'identifier'):
for k in self.children.keys():
if hasattr(self.children[k], 'identifier'):
if self.children[k].identifier == child.identifier:
if k... | Removes a child instance from the Tag's children.
Args:
child (Tag): The child to be removed. | juraj-google-style |
def pop_event(self, event_name, timeout=DEFAULT_TIMEOUT):
if (not self.started):
raise IllegalStateError('Dispatcher needs to be started before popping.')
e_queue = self.get_event_q(event_name)
if (not e_queue):
raise TypeError('Failed to get an event queue for {}'.format(event_name))
tr... | Pop an event from its queue.
Return and remove the oldest entry of an event.
Block until an event of specified name is available or
times out if timeout is set.
Args:
event_name: Name of the event to be popped.
timeout: Number of seconds to wait when event is not present.
Never times out if None.
Returns:
The oldest... | codesearchnet |
def _CheckMacOSPaths(self, filename, artifact_definition, source, paths):
result = True
paths_with_private = []
paths_with_symbolic_link_to_private = []
for path in paths:
path_lower = path.lower()
path_segments = path_lower.split(source.separator)
if (not path_segments):
... | Checks if the paths are valid MacOS paths.
Args:
filename (str): name of the artifacts definition file.
artifact_definition (ArtifactDefinition): artifact definition.
source (SourceType): source definition.
paths (list[str]): paths to validate.
Returns:
bool: True if the MacOS paths is valid. | codesearchnet |
def mark_deprecated(replaced_by):
def decorator(fn):
@wraps(fn)
def wrapper(*args, **kw):
from peltak.core import shell
if shell.is_tty:
warnings.warn("This command is has been deprecated. Please use "
"{new} inst... | Mark command as deprecated.
Args:
replaced_by (str):
The command that deprecated this command and should be used instead. | juraj-google-style |
def index(self, connection, partition, columns):
import hashlib
query_tmpl =
if not isinstance(columns,(list,tuple)):
columns = [columns]
col_list = ','.join('"{}"'.format(col) for col in columns)
col_hash = hashlib.md5(col_list).hexdigest()
tr... | Create an index on the columns.
Args:
connection (apsw.Connection): connection to sqlite database who stores mpr table or view.
partition (orm.Partition):
columns (list of str): | juraj-google-style |
def watermark_image(image, wtrmrk_path, corner=2):
padding = 2
wtrmrk_img = Image.open(wtrmrk_path)
if ((wtrmrk_img.width > (image.width - (padding * 2))) or (wtrmrk_img.height > (image.height - (padding * 2)))):
res = (int((image.width / 8.0)), int((image.height / 8.0)))
resize_in_place(wtr... | Adds a watermark image to an instance of a PIL Image.
If the provided watermark image (wtrmrk_path) is
larger than the provided base image (image), then
the watermark image will be automatically resized to
roughly 1/8 the size of the base image.
Args:
image: An instance of a PIL Image. This is the base image.
wtrmrk_... | codesearchnet |
def send_msg(self, address, args=[]):
if (not address.startswith('/')):
address = '/{}'.format(address)
msg = osc_message_builder.OscMessageBuilder(address=address)
for arg in args:
msg.add_arg(arg)
self.conn.send(msg.build())
return | Send multiple args into a single message to a given address.
Args:
address (str): OSC Address.
args (list): Arguments to be parsed in VVVV. | codesearchnet |
def identity_kernel_initializer(shape, dtype=tf.float32, partition_info=None):
if (len(shape) != 4):
raise ValueError('Convolution kernels must be rank 4.')
(filter_height, filter_width, in_channels, out_channels) = shape
if (filter_width != filter_height):
raise ValueError('Identity initial... | An initializer for constructing identity convolution kernels.
Constructs a convolution kernel such that applying it is the same as an
identity operation on the input. Formally, the kernel has entry [i, j, in,
out] = 1 if in equals out and i and j are the middle of the kernel and 0
otherwise.
Args:
shape: List of inte... | codesearchnet |
def on_graph_def(self, graph_def, device_name, wall_time):
if self._dump_dir:
if self._grpc_path:
self._write_graph_def(graph_def, device_name, wall_time)
else:
self._cached_graph_defs.append(graph_def)
self._cached_graph_def_device_names.append(device_name)
... | Implementation of the tensor value-carrying Event proto callback.
Args:
graph_def: A GraphDef object.
device_name: Name of the device on which the graph was created.
wall_time: An epoch timestamp (in microseconds) for the graph. | github-repos |
class TFDebertaStableDropout(keras.layers.Layer):
def __init__(self, drop_prob, **kwargs):
super().__init__(**kwargs)
self.drop_prob = drop_prob
@tf.custom_gradient
def xdropout(self, inputs):
mask = tf.cast(1 - tf.compat.v1.distributions.Bernoulli(probs=1.0 - self.drop_pr... | Optimized dropout module for stabilizing the training
Args:
drop_prob (float): the dropout probabilities | github-repos |
def set_calibration(self, enabled, imus):
if len(imus) == 0:
imus = list(range(MAX_IMUS))
for i in imus:
if i < 0 or i >= MAX_IMUS:
logger.warn('Invalid IMU index {} in set_calibration'.format(i))
continue
self.imus[i]._use_ca... | Set calibration state for attached IMUs.
Args:
enabled (bool): True to apply calibration to IMU data (if available).
False to output uncalibrated data.
imus (list): indicates which IMUs the calibration state should be set on.
Empty list or [0, 1, 2, 3, 4] will apply to all IMUs, [0, 1] only to
first 2 IMUs, etc. | juraj-google-style |
def to_dataframe(self, start_row=0, max_rows=None, use_cache=True, dialect=None, billing_tier=None):
return self.results(use_cache=use_cache, dialect=dialect, billing_tier=billing_tier).to_dataframe(start_row=start_row, max_rows=max_rows) | Exports the query results to a Pandas dataframe.
Args:
start_row: the row of the table at which to start the export (default 0).
max_rows: an upper limit on the number of rows to export (default None).
use_cache: whether to use cached results or not (default True).
dialect : {'legacy', 'standard'}, default 'legacy'
'l... | codesearchnet |
def processes(self, processes):
if self._processes > 1:
self._pool.close()
self._pool.join()
self._pool = multiprocessing.Pool(processes)
else:
self._pool = None
self._logger.log('debug', 'Number of processes set to {}'.format(
... | Set the number of concurrent processes the ABC will utilize for
fitness function evaluation; if <= 1, single process is used
Args:
processes (int): number of concurrent processes | juraj-google-style |
def zeros_like(array, dtype=None, keepmeta=True):
if keepmeta:
return xr.zeros_like(array, dtype)
else:
return dc.zeros(array.shape, dtype) | Create an array of zeros with the same shape and type as the input array.
Args:
array (xarray.DataArray): The shape and data-type of it define
these same attributes of the output array.
dtype (data-type, optional): If specified, this function overrides
the data-type of the output array.
keepmeta (bool, optional): Whet... | codesearchnet |
def on_put(self, req, resp, handler=None, **kwargs):
self.handle((handler or self.update), req, resp, **kwargs)
resp.status = falcon.HTTP_ACCEPTED | Respond on PUT HTTP request assuming resource update flow.
This request handler assumes that PUT requests are associated with
resource update/modification. Thus default flow for such requests is:
* Modify existing resource instance and prepare its representation by
calling its update method handler.
* Set response st... | codesearchnet |
def parent(self):
family = self.repository.get_parent_package_family(self.resource)
return (PackageFamily(family) if family else None) | Get the parent package family.
Returns:
`PackageFamily`. | codesearchnet |
def ndtri(p, name='ndtri'):
with ops.name_scope(name, values=[p]):
p = ops.convert_to_tensor(p, name='p')
if p.dtype.as_numpy_dtype not in [np.float32, np.float64]:
raise TypeError('p.dtype=%s is not handled, see docstring for supported types.' % p.dtype)
return _ndtri(p) | The inverse of the CDF of the Normal distribution function.
Returns x such that the area under the pdf from minus infinity to x is equal
to p.
A piece-wise rational approximation is done for the function.
This is a port of the implementation in netlib.
Args:
p: `Tensor` of type `float32`, `float64`.
name: Python str... | github-repos |
def pre(fqdn, parent, stackdepth, *argl, **argd):
global _atdepth_call, _cstack_call
pcres = _pre_call(_atdepth_call, parent, fqdn, stackdepth+1,
*argl, **argd)
entry, _atdepth_call, reduced, bound, ekey = pcres
_cstack_call.append(fqdn)
return (entry, bound, eke... | Adds logging for a call to the specified function that is being handled
by an external module.
Args:
fqdn (str): fully-qualified domain name of the function being logged.
parent: *object* that the function belongs to.
stackdepth (int): maximum stack depth before entries are ignored.
argl (list): positional arguments p... | juraj-google-style |
def contains(self, value, equality_comparer=operator.eq):
if self.closed():
raise ValueError("Attempt to call contains() on a "
"closed Queryable.")
if not is_callable(equality_comparer):
raise TypeError("contains() parameter equality_compar... | Determines whether the sequence contains a particular value.
Execution is immediate. Depending on the type of the sequence, all or
none of the sequence may be consumed by this operation.
Note: This method uses immediate execution.
Args:
value: The value to test for membership of the sequence
Returns:
True if value ... | juraj-google-style |
def configs_for_reader(reader=None, ppp_config_dir=None):
search_paths = ((ppp_config_dir,) if ppp_config_dir else tuple())
if (reader is not None):
if (not isinstance(reader, (list, tuple))):
reader = [reader]
new_readers = []
for reader_name in reader:
if (reade... | Generator of reader configuration files for one or more readers
Args:
reader (Optional[str]): Yield configs only for this reader
ppp_config_dir (Optional[str]): Additional configuration directory
to search for reader configuration files.
Returns: Generator of lists of configuration files | codesearchnet |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.