content stringlengths 35 416k | sha1 stringlengths 40 40 | id int64 0 710k |
|---|---|---|
import warnings
def get_ann_text(sel):
"""
Compute an annotating text for a `Selection` (passed **unpacked**).
This is a single-dispatch function; implementations for various artist
classes follow.
"""
warnings.warn(
f"Annotation support for {type(sel.artist).__name__} is missing")
... | 2f7b621a49c48aa4606c14b2d5669e64bc73fd15 | 693,951 |
def merge(left_array, right_array):
"""
1. Compare first element of both arrays and append the smaller element
2. Increment the index for the array whose element has been pushed to merged array
3. Follow steps 1 and 2 till either of two array is completely merged
4. Whichever array has remaining ele... | f4997c3e7a4d67b3dd8f2f0c86335b28e29d9450 | 693,952 |
def find_related_forms(self,form_name,form_dict,foreign_forms=None):
"""
Finds the form_name value in the form_dict. If it is found, the function
will call itself using form_dict[form_name]. The form_dict is a dictionary
with the keys being a form name and the value being the name of the form they
have a foreign ... | 3568dcb5383ddddc8b1e5eb0306654a972a425db | 693,953 |
def identity(func):
"""The identity decorator."""
# this method provides a
def inner(*args,**kwargs):
return func(*args,**kwargs)
inner.__name__ = func.__name__
inner.__doc__ = func.__doc__
return inner | 6ecd1af13adb9a0486c036b1867338374806c625 | 693,955 |
def get_dat_id(datnum, datname):
"""Returns unique dat_id within one experiment."""
name = f'Dat{datnum}'
if datname != 'base':
name += f'[{datname}]'
return name | 4505b1932e89c6e76073605011aa6260563daa84 | 693,956 |
import ctypes
def _IsStructType(t):
"""Tests if a type is a structure."""
return type(t) is type(ctypes.Structure) | 7815d9fc840d3fbd29625404b96fa60eb209dd85 | 693,957 |
def electric_consume(data, meta):
"""
Transfer function to change sign of electricity consumed, for cashflows
@ In, data, dict, partial requested activity
@ In, meta, dict, additional info
@ Out, data, dict, filled-in requested activity
@ Out, meta, dict, additional info (possibly modified, possib... | 32f6a95d29dbbe50bb573b0cfcaeab042d2fcd38 | 693,958 |
def asini_c(pb, mf):
"""
asini_c(pb, mf):
Return the orbital projected semi-major axis (lt-sec) given:
'pb' is the binary period in sec.
'mf' is the mass function of the orbit.
"""
return (mf * pb * pb / 8015123.37129)**(1.0 / 3.0) | 1dd86e3619f2334d6d11c14bc2a7b28c9edb9dcb | 693,961 |
async def root():
"""
Useful for health checks
:return: a simple static JSON object
"""
return {"status": "ok"} | c49c7b99ce096692f3fe5f97e198697fc61c4ccb | 693,962 |
import os
import subprocess
def rsync(original, new):
""" Uses subprocess.call to rsync from 'filename' to 'new'
If new is directory, copies original in.
If new is new file, copies original to that name.
"""
assert os.path.exists(original), 'Need original file!'
res = subprocess.call(["rsync"... | ab60136e6c622df88dca15c07d487f86fcde78c6 | 693,963 |
import re
def preprocess_dash(arg: str) -> str:
"""Replace any dashes with tildes, otherwise argparse will assume they're options"""
return re.sub(r"^-(?=([\w_\*]+/[\w_\*]+)|(\d+)$)", "~", arg) | c92b2dbc259f455567749c6be76969c6132ec519 | 693,966 |
def argkvpair(val):
"""Splitting key value pair"""
k, v = val.split("=", 1)
return k, v | 9da942bbc32b402217cebcbc1a39d637c15f835b | 693,967 |
import re
import logging
def edit_header(in_vcf):
"""
Create an edited header
return the header as well as contig information from vcf header
"""
header = []
ctgre = re.compile(r"##contig=<ID=(?P<name>.*),length=(?P<length>\d+)>$")
contigs = []
while True:
line = in_vcf.readlin... | c6cd687082c52c046b4d574fe2f54b81640c66fd | 693,968 |
from typing import Any
from typing import List
from typing import Dict
def check_is_list_of_dicts(x: Any) -> List[Dict[Any, Any]]:
"""Return `x` if it is `List[Dict[Any, Any]]`, raise `ValueError`."""
if not isinstance(x, list):
raise ValueError()
for element in x:
if not isinstance(elemen... | b9c0c09607543e52f29ab678a4a27198e2f8642e | 693,969 |
def php_str_repeat(_input, _multiplier):
"""
>>> php_str_repeat('*', 10)
'**********'
>>> php_str_repeat('xyz', 3)
'xyzxyzxyz'
>>> php_str_repeat('xyz', 0)
''
"""
return _input * _multiplier | f083f3041c324001caa4791e0fda61aaedb9aa50 | 693,970 |
import argparse
def positive_value(num):
"""
Checks whether num is positive number and returns it in float format.
Parameters
----------
num : str
Amount of money.
Returns
-------
float
Amount of money in float format.
"""
try:
value = float(num)
... | 1d682035a42eb8a33f4bf582de5a51639849455f | 693,971 |
def header_translate_inverse(header_name):
"""Translate parameter names back from headers."""
name_dict = {'XCENREF': 'xcen_ref',
'YCENREF': 'ycen_ref',
'ZENDIR': 'zenith_direction',
'ZENDIST': 'zenith_distance',
'FLUX': 'flux',
... | ffd333d190530a70aca014438cb3b49eab032e42 | 693,972 |
def handler(event, context):
"""
Execute pickled function in remote Lambda environment using all globals from source environment
"""
print('Passed event: {}'.format(event))
print('Passed context: {}'.format(context))
job = None
return {
'statusCode': 200,
'body': str(b'byt... | 3087be09fa3b7c0bda4487ebcffabd1fa4357b3c | 693,973 |
from typing import IO
import io
import subprocess
def decompress_raw_data_by_zcat(raw_data_fd: IO, add_bracket: bool = True):
"""Experimental: Decompresses raw data from file like object with zcat. Otherwise same as decompress_raw_data.
Args:
raw_data_fd: File descriptor object.
add_bracket: ... | ba7ce5208a6f8daf9f318b5ef174d3f52f00e50a | 693,974 |
import jinja2
def render_without_request(template_name, **template_vars):
"""
Usage is the same as flask.render_template:
render_without_request('my_template.html', var1='foo', var2='bar')
"""
env = jinja2.Environment(
loader=jinja2.PackageLoader('server','templates')
)
template =... | 37fd509f08c7b3f3f07926b130a5739001ecadd2 | 693,975 |
def tsne_kwargs(n_dims, initial_dims, perplexity=25.0, n_epochs=1000):
"""Argument options for t-SNE.
Args:
n_dims (int): Number of dimensions to reduce the data down to.
initial_dims (int): Initial number of dimensions of the input data.
perplexity (float): Related to number of nearest... | 4899997827237b383efb60eb6a2b2b230b879170 | 693,976 |
def get_dic(f, dataset="spectrum"):
"""
Get a dictionary from dataset in a HDF5 File
"""
# select the data set
dset = f[dataset]
dic = {}
# loop over the attributes
for key, value in dset.attrs.items():
if "_" in key:
# we have an axis key
axis, subkey ... | f6cb53e74e0cdde4b5c619ec3bb5471a53e229bc | 693,977 |
import os
def check_already_extracted(feature_dir):
"""Check to see if we created the -0001 frame of this file."""
return bool(os.path.exists(os.path.join(feature_dir ,'*.txt'))) | f7425651dc7125dd77e8ea0a0e5e56bbb83c3a08 | 693,978 |
def restriction(d, keys):
"""Return the dictionary that is the subdictionary of d over the specified
keys"""
return {key: d.get(key) for key in keys} | 9fdb2d2e5bea0d96380e592ffc6d7720b32ade30 | 693,979 |
import re
def is_valid_phone(phone_number: str):
"""Return if the phone_number is valid or not."""
if phone_number:
phone_number = phone_number.replace(' ', '').replace('(', '').replace(')', '')
return re.match(
r'[\+\d]?(\d{2,3}[-\.\s]??\d{2,3}[-\.\s]??\d{4}|\(\d{3}\)\s*\d{3}[-\.\... | d9837f9a53a59fdbf92f2c16325a6c4a7c61e1c6 | 693,980 |
def e_m(val):
"""energy multiplier"""
if val == 5: return 10
elif val >= 6: return 100
else: return None | dc24986ab270b22e1037c77091de58c4b15a4474 | 693,982 |
import torch
def get_qkv(inp_list):
"""The 1st element of the inp_list is about the template,
the 2nd (the last) element is about the search region"""
dict_x = inp_list[-1]
dict_c = {"feat": torch.cat([x["feat"] for x in inp_list], dim=0),
"mask": torch.cat([x["mask"] for x in inp_list],... | ae5cc39cbfc7fdc3a755e35ad0f3d44ae3c8ae5f | 693,983 |
def binary_to_int(value):
"""Convert binary number to an integer."""
return int(value, 2) | 792b9a01883dc460fb23d10f8415fa6656918c56 | 693,984 |
from pathlib import Path
import re
def read_input():
"""Read input file, return string, and drop unexpected characters."""
text = Path(__file__).with_name('input.txt').read_text()
return re.sub(r'[^<>^v]', '', text) | e02cb930464c6a4cf1973ed2cee123877a6a0b2b | 693,985 |
import subprocess
def is_elf(filepath):
"""Returns True if |filepath| is an ELF file."""
result = subprocess.run(['file', filepath],
stdout=subprocess.PIPE,
check=False)
return b'ELF' in result.stdout | e97f06cb785d99fc40cbc757db435a9cc396fd24 | 693,986 |
def box_overlap(box1, box2, resolution, padding=0):
"""Incoming format is y1, x1, y2, x2.
Padding is optional, but can improve post-processing.
"""
box1_ymin, box1_xmin, box1_ymax, box1_xmax = box1
box2_ymin, box2_xmin, box2_ymax, box2_xmax = box2
if box1_ymin == resolution[1]:
box1_ymin... | 2d191d89e486bdfbd1f0b91d5da002910ea38086 | 693,987 |
def mul_with_none(v1,v2):
""" Standard mul treating None with zero """
if v1 is None:
return None
elif v2 is None:
return None
else:
return v1 * v2 | 7065344b6b0efa29cbca14a7ddf85a3ade245fa1 | 693,988 |
def root_node(tree, level):
"""
:param tree: a tree node
:param level: level of the subtree (0 for the tree root)
:return: subtree root at level
"""
root = tree
while root.level > level:
root = root.parent
return root | ae41c019e6e2c395343aa64d32ac6a700e451a24 | 693,989 |
def get_patch_position(tile,patch):
"""
tile: tuple -> (tile x position, tile y position, tile size)
patch: tuple -> (patch x position, patch y position, patch size)
"""
tx,ty,ts = tile
px,py,ps = patch
return (px-tx,py-ty,ps) | 03c1cbf6c32a2ec8f8ea048297f03aaa836c26a7 | 693,992 |
def StringsContainSubstrings(strings, substrings):
"""Returns true if every substring is contained in at least one string.
Looks for any of the substrings in each string. Only requires each substring
be found once.
Args:
strings: List of strings to search for substrings in.
substrings: List of strings... | 52c4bf8b4b57a9ebb619c71276881668b6b2a1d8 | 693,993 |
def U234():
"""MF8/MT457 from JEFF-3.3 U-234. It was selected because it contains
both continuous and discrete spectra.
"""
text = """ 9.223400+4 2.320300+2 0 0 0 63541 8457 1
7.75370+12 9.467280+9 0 0 6 03541 8457 2
1.4143... | 446efcce73bfebe404f442d7657d2d3ae6674e80 | 693,994 |
def normalize_url(url):
"""If passed url doesn't include schema return it with default one - http."""
if not url.lower().startswith('http'):
return 'http://%s' % url
return url | b957056e8ca32f6294c85466b6e52c56bb1dba84 | 693,995 |
def search_matrix_lintcode(matrix, target):
"""
Search target in given 2D matrix
:param matrix: given matrix
:type matrix: list[list[int]]
:param target: target number
:type target: int
:return: number of occurrences
:rtype: int
"""
occur = 0
if len(matrix) != 0 or len(matri... | 74ef1f0e60db34768f45f7c56bf0b45339746bfb | 693,996 |
def singleGridIndexToGridIndex(i, nx, ny, nz):
"""
Convert a single into a grid index (3 indices):
:param i: (int) single grid index
:param nx, ny, nz: (int) number of grid cells in each direction
:return: ix, iy, iz:
(3-tuple) grid index in x-, y-, z-axis direct... | 12b3b69318437d66007fd5295ae209f8186f8b36 | 693,997 |
import inspect
def _get_not_annotated(func, annotations=None):
"""Return non-optional parameters that are not annotated."""
argspec = inspect.getfullargspec(func)
args = argspec.args
if argspec.defaults is not None:
args = args[:-len(argspec.defaults)]
if inspect.isclass(func) or inspect.i... | b16e9a2f1e7b71a1b9e4df303a01e67b7eea5482 | 693,998 |
def keysplit(strng):
"""Split an activity key joined into a single string using the magic sequence `⊡|⊡`"""
return tuple(strng.split("⊡|⊡")) | eb1b965843b602410010337f23ea8d0053f2f4b6 | 693,999 |
import re
def ensure_peak_format(ann, sep=[':', '-']):
"""
Ensure that the AnnData object have a consistent
peak format for later comparisons and operations.
"""
peaks = ann.var.index.tolist()
non_alphanum = "[^0-9a-zA-Z.]+"
regex = [re.findall(non_alphanum, p) for p in peaks]
if all... | 810b619a98baa4e0a05b8759ca8801b82903eb96 | 694,000 |
def flatten_list(list_):
"""
Turn list of lists into list of sublists' elements.
Args:
list_ (list): List to flatten.
Returns:
Flattened list.
"""
return [item for sublist in list_ for item in sublist] | d42e5ef6e2333cbce13e6c4294f8b6b2c8a8ca70 | 694,001 |
import re
def argo_gdac_float_meta(profile_index,float_wmoid):
""" Accessor for metadata on a specific Argo float from GDAC.
Returns dict 'this_float_meta' relevant to the given float's profiles, with following keys:
'num_profs': number of profiles (integer)
'prof_nums': array of profile numb... | bdcf6da4d02ef1961ac79a8af2790ad2f0418df7 | 694,002 |
def get_close_descriptions(get_close, initial_state, current_state):
"""
Get all 'close' descriptions from the current state (if any).
Parameters
----------
get_close: function
Function that gets the drawer or the door which is closed.
initial_state: nd.array
Initial state of the... | 54181292066c58968d00e4d8e3d98ec584338e18 | 694,003 |
def tmpfile(tmpdir):
"""A temporary file that can be read"""
file_path = tmpdir.join("test")
file_path.write("Temporary test file")
return file_path | 46feeb0c7ef4a3e9771376c977adefba4e64de08 | 694,004 |
def doc_to_text(doc):
"""
Convert document object to original text represention.
Assumes parser offsets map to original document offsets
:param doc:
:param sent_delim:
:return:
"""
text = u""
for i, sent in enumerate(doc.sentences):
# setup padding so that BRAT displays a mi... | 64595c77fbad868ce7aa89aa0cdecc9773cd6c44 | 694,005 |
def get_bumped_prerelease_version(version):
"""Return the pre-release version of the specified version.
:param version: version to get the pre-release version of
"""
prerelease_version = version.next_patch()
prerelease_version.prerelease = ('beta', )
return prerelease_version | db5966c687b77b268dcdcdbff79bbe90a9d17624 | 694,006 |
import torch
def l1_penalty(model, l1_coef):
"""Compute L1 penalty. For implementation details, see:
https://discuss.pytorch.org/t/simple-l2-regularization/139
"""
reg_loss = 0
for param in model.pcca.parameters_('y2'):
reg_loss += torch.norm(param, 1)
return l1_coef * reg_loss | 3a2ddc8bd1eeb64e9ba94ce009e2e621677242e2 | 694,007 |
def list_parameters_from_groups(parameter_groups, groups):
"""Return a list of all the parameters in a list of groups
"""
return [
p for group in groups
for p in parameter_groups[group].values()
] | 2ea08013616fd978a49f8d2d5fa2c233a17fabfc | 694,008 |
def color(marks, index):
"""Compute color for given mark index."""
steps_of_color = int(256 / len(marks) * 2) - 1
index_of_yellow_label = int(len(marks) / 2)
if index < index_of_yellow_label:
r = abs(0 - index) * steps_of_color
g = 255
return 'fill:rgb({} {} {});'.format(r, g, 0... | cd0b4e15fa98174c39e81bf94c80d4f7d37b2f6b | 694,009 |
def ec2config_delete(ec2config):
"""Implement here your function"""
return ec2config | 7476aa5f7c82353d29d49d07a8e23a9cfee1002d | 694,010 |
import string
def is_hexdigit(s):
"""Check if all characters are hexadecimal digits.
:param str s: the string
:return: ``True`` if all characters in the string are hexadecimal digits
and there is at least one character
:rtype: bool
.. versionadded:: 0.5.0
"""
return bool(s) ... | e556080419cefa9ec1668a0fc0a19010c49e261f | 694,011 |
def calc_bpe_charge_transfer_resistance(j_0_bpe, T):
"""
The area specific charge transfer resistance through the BPE
units: Ohm*m2
Notes:
"""
kb = 1.3806e-23 # (J/K) Boltzmann constant
e = -1.602e-19 # (C) charge of an electron
R_ct = kb * T / j_0_bpe / e
return R_ct | d90a8a45ea03e213ea46aeab1dfab98bf1e78f56 | 694,013 |
def unhex(s):
"""unhex(s) -> str
Hex-decodes a string.
Example:
>>> unhex("74657374")
'test'
"""
return s.decode('hex') | dcf2d6cd9c317b5eafd77e969272fcf753556403 | 694,014 |
import shlex
import subprocess
def run(cmd):
"""Runs the given command, returning the exit code (nonzero on failure)"""
print('\nRunning: ' + shlex.join(cmd) + '\n')
return subprocess.call(cmd) | d81c3eea046464b9d542b6d2f8ced1417d5dc075 | 694,015 |
import json
def get_features(geojson_file, nl=False):
"""
Get a list of features from something resembling geojson.
Note that if the `nl` option is True, this will return a generator
that yields a single feature from each line in the source file.
"""
if nl:
return (json.loads(line) fo... | 4c3b5bb6011968d3361b44b358a846b51d4fe404 | 694,016 |
def _find_test_plugins(paths_file):
"""
One plugin path per line in a file
Lines starting with a # are considered comments and ignored
:type paths_file: str
:return: List[str]
"""
with open(paths_file) as f:
path = f.read().strip()
lines = path.split('\n')
lines = [x.strip(... | 85b62e7ab41ea02f8d123379c7b0ed2b96c46566 | 694,019 |
def sort_population(population):
"""
Sorts the population based on fitness values
:param population: population to be sorted
:return: sorted population
"""
return sorted(population, key=lambda tup: float(tup[1]), reverse=True) | b368bcec27cb4162a464260895bfa463729b4df1 | 694,020 |
import hashlib
def block_compute_raw_hash(header):
"""
Compute the raw SHA256 double hash of a block header.
Arguments:
header (bytes): block header
Returns:
bytes: block hash
"""
return hashlib.sha256(hashlib.sha256(header).digest()).digest()[::-1] | 4d6a13316aeda0ec42ca1904ba91170ca0220aae | 694,021 |
import csv
def parseGeneColor(by_gene_color_file_name):
"""
Returns
gene2label
"""
gene_file = open(by_gene_color_file_name)
gene2label = {}
csv_reader = csv.DictReader(gene_file, delimiter="\t")
for row in csv_reader:
gene2label[row["gene"]] = row["label"]
return gene2l... | 80340d02bacfec4e273b87aea12e9c4122c0e784 | 694,022 |
import operator
def map_method(*args, **kwargs):
"""
Given a method name and a sequence of models, return a sequence of values
of applying the extra positional and keyword arguments in each method.
Attr:
attr:
Method name. Dotted python names are valid.
models:
... | aa2ab34f729c41376e30c9a9b8c6536e14ba8be4 | 694,023 |
def compare_version_part(a_part, b_part):
"""Compare two parts of a version number and return the difference (taking into account
versions like 7.0.0-M1)."""
try:
a_bits = a_part.split('-')
b_bits = b_part.split('-')
version_difference = int(a_bits[0]) - int(b_bits[0])
if ver... | 1bcd1a3c8c4b070e0b33abc0d9c15cbfd146a80a | 694,024 |
import torch
def _create_metafeature_tensor(metafeatures, seq, metafeature_spec):
"""Convert a metafeature vector into a tensor.
:returns Tensor: dim <string_length x 1 x metafeature_dim>, where
metafeature_dim is a continuous feature.
"""
m = []
for i, feature in enumerate(metafeatures):... | b61beaaabcc06bd5b2034cb10077fd4523c9e71d | 694,025 |
import os
def get_template(name, path):
"""Retrieves the path of the template.
Searches the path provided to find the name of the template. If the
template exists, return the name, otherwise Return False.
Parameters:
name (str): The name of the template.
Returns:
str: the path ... | 5afbc1de13d8a87d04f2e230c0bc00e8e8b84b9f | 694,026 |
def get_cell_genes(cur,cell):
"""
Return the genes expressed in cell
Parameters
----------
cur : MySQLdb cursor
cell : str
Name of cell
"""
sql = ("select genename from WB.association "
"join WB.cells on "
"WB.association.idcell = WB.cells.idcells "
... | 03550cc6a8645b49c86d280d17032b05102b88d3 | 694,027 |
import difflib
def diff(string1, string2):
"""
Returns an array where array[0] is the content of s2 that have been added
in regards to s1 and array[1] is the content of s2 that has been removed
from s1
"""
differ = difflib.Differ()
added = ""
removed = ""
for i in differ.compare(st... | 5192ec2001364715c2de73cab6a32733833bb309 | 694,028 |
def unflatten_dict(d, separator='.'):
"""Unflatten nested dictionary.
Transforms {'a.b.c': 5, 'a.d': 6} into {'a': {'b': {'c': 5}, 'd': 6}}
Args:
d (dict): nested dictionary to flatten.
separator (str): the separator to use between keys.
prefix (str): key prefix
Returns:
... | bc51bc813d9e9c0bf95956213e34349425cc8ffb | 694,029 |
import random
def RAND():
"""
Returns a random number between 0 inclusive and 1 exclusive.
"""
return random.random() | 1dc007502f8951187b28a10ad326ec98205737ce | 694,030 |
def add_values_to_config(defaults, values, source):
"""Given a defaults dictionary (structured like configurable_defaults above)
and a possibly nested config dict, combine the two and return a
new dict, structured like cfg_defaults. Every node will have at least
'type', 'source' and 'value' keys."""
... | 5be63bb25b6b626c473878428d63ae2b01e06648 | 694,031 |
import torch
def test(model, test_loader, device=torch.device("cpu")):
"""Checks the validation accuracy of the model.
Cuts off at 512 samples for simplicity.
"""
model.eval()
correct = 0
total = 0
with torch.no_grad():
for batch_idx, (data, target) in enumerate(test_loader):
... | 2df49a192c144a9300b5cd218b347a55f79da467 | 694,032 |
import os
import shutil
def remove_if_exist(path):
"""Delete a file or a directory recursively if it exists, else no exception is raised"""
if os.path.exists(path):
if os.path.isdir(path):
shutil.rmtree(path)
return True
elif os.path.isfile(path):
os.remove(... | b2ad0b5ced9a91b85d5b04df497c42e8677fa499 | 694,033 |
def plotmatrix(X):
"""
Creates a matrix of marginal plots.
On diagonal, are marginal plots of each variable. Off-diagonal plot (i,j)
shows the joint marginal density of x_i and x_j.
"""
return X.plotmatrix() | 12e3de82f8b4ecd4ed41da85d465ecfc8da06f00 | 694,034 |
def isGlideinHeldNTimes(jobInfo, factoryConfig=None, n=20):
"""This function looks at the glidein job's information and returns if the
CondorG job is held for more than N(defaults to 20) iterations
This is useful to remove Unrecoverable glidein (CondorG job) with forcex option.
Args:
jobInfo (... | e608ada46f1571b9e96531bc3cca3692f940846a | 694,035 |
def SliceCoordsConstant(minVal, maxVal, divisions):
"""
Generate one dimension of annulus slice coordinates based upon the supplied
geometry information, with constant node spacing
"""
return [minVal + (maxVal - minVal) * (float(i) / divisions) for i in range(divisions + 1)] | a69ad0eaafc17c2742407e278c9f6bd414471945 | 694,036 |
def get_z_from_orient(mat_orient):
"""To get the angle in degree from an orientation matrix"""
return mat_orient[1,2] | 97fd0e836a74b4d7e5265b89d886da7ba7c02890 | 694,037 |
import re
def prepare_whitelist(patterns):
"""Join and compile the re patterns.
Args:
patterns: regex patterns.
Return:
A compiled re object
"""
return re.compile('|'.join(patterns)) | 5c1eb91c2aa534af6b8ff5cc4165095a5eb577e7 | 694,038 |
def _GetVersionIndex(version_str):
"""Returns the version index from ycsb version string.
Args:
version_str: ycsb version string with format '0.<version index>.0'.
Returns:
(int) version index.
"""
return int(version_str.split('.')[1]) | 9c415a55a97adedb6bbc5576d7147d2164651d4e | 694,041 |
import re
def parse_ping_output(ping_output):
"""Parse ping output.
Returns a tuple with the number of packets sent and the percentage of
packet loss from a ping output."""
match = re.search(
'(\d*) packets transmitted, .* ([\d\.]*)\% packet loss',
ping_output)
return match.groups... | e3af78babdbd21dd6369f18de150a9d453fe7d21 | 694,042 |
def concat(liste):
"""
Concatenate lines_list to rebuild the treated file content
=============== ============ ==============================================================
**Parameters** **Type** **Description**
*liste* string list a string list representing the content of a .extension fil... | 72a937674c635b2044507221a32ef81dd5e01217 | 694,043 |
def get_fake_ap_data():
"""
Grabs the selected fake AP top-of-ticket data file.
"""
path = 'www/timemachine/US.txt'
with open(path, 'rb') as f:
return f.readlines() | 0b951d006523e98ba2e822af020aba897b03ff60 | 694,044 |
def is_transform(str_in):
"""Determines if str_in is the name of a transformation file
"""
return '.ima' in str_in \
or '.trm' in str_in | c7f65ac6c86776c640a0027c94b0cee5afdd8cfb | 694,045 |
def process_resize_value(resize_spec):
"""Helper method to process input resize spec.
Args:
resize_spec: Either None, a python scalar, or a sequence with length <=2.
Each value in the sequence should be a python integer.
Returns:
None if input size is not valid, or 2-tuple of (height, width), deri... | 2850b1f86a62cb35611bcb89a543bb35eb8226bf | 694,046 |
import requests
import json
def get_elements_from_elasticsearch(sysmlId, index="mms", elasticHost="localhost"):
"""
Method will return an array of elements based on the sysmlid provided. It will be the entire history of the element.
:param sysmlid: string
:param index: ElasticSearch Index
:param e... | 2df4484bfa7209ab356cc0e7b5f97f7c611cfb34 | 694,047 |
def Tokenize_Context(context, question, tokenizer):
""" Tokenize single sample.
Params:
context
question
tokenizer: tokenizer of Transformer-based model from huggingface
Return:
input_id
attention_mask
segment_id
"""
encoded_dict = tokenizer.encode_plu... | ed0a25e6b5c7ea3941d73bd4fd872d23ed8b96d5 | 694,048 |
def split_wrap(sql):
"""Split with \n, and strip the ' '. """
sql_list = sql.split('\n')
if sql_list[0] == '':
del sql_list[0]
if sql_list[-1] == '':
del sql_list[-1]
sql_list = list(map(lambda x: x.strip(), sql_list))
return sql_list | 7d8639b99219226b5a29da204a1c7fd8f71acc0e | 694,050 |
def fastpath_dup_rid_input(app):
"""
Access DB directly. Fetch > 1 measurements from fastpath that share the same
report_id and input
Returns (rid, input, count)
"""
sql = """
SELECT report_id, input,
from fastpath
group by report_id, input
HAVING count(*) > 1
LIMIT 1
"""... | a09e82cd84483c21722a197ab8f5becae2c1d5a6 | 694,051 |
def get_BM_data(filename):
"""Read the contents of the given file. Assumes the file
in a comma-separated format, with 6 elements in each entry:
0. Name (string), 1. Gender (string), 2. Age (int)
3. Division (int), 4. Country (string), 5. Overall time (float)
Returns: dict containing a list for e... | c3dce697ed850ed422a5d60fbd08310f04461a82 | 694,052 |
def get_xml_line(xml_list, index):
"""get xml specified line valid string data"""
ele = None
while xml_list and not ele:
if index >= 0 and index >= len(xml_list):
return None
if index < 0 and abs(index) > len(xml_list):
return None
ele = xml_list[index]
... | 9bc5de648c4213f30d0142dc595d0f38549d1564 | 694,053 |
def build_B_spline_higher_degree_basis_fns(
breaks, prev_degree_coefs, degree, x):
"""Build the higer order B spline basis coefficients
N_{i,p}(x) = ((x-u_i)/(u_{i+p}-u_i))N_{i,p-1}(x) \
+ ((u_{i+p+1}-x)/(u_{i+p+1}-u_{i+1}))N_{i+1,p-1}(x)
"""
assert degree > 0
coefs = []
f... | a8b732ce519a608ea277aa1c1165be8d674e141b | 694,054 |
import subprocess
def get_operation(migration):
"""Gets the current operation being executed by the migration"""
command = ['kubectl', 'get', 'migrations.anthos-migrate.cloud.google.com', '-n', 'v2k-system', migration, '-o',
'jsonpath={.status.currentOperation}']
output = subprocess.run(com... | 53a4f6fc2b5a3e802e8ac9fd69339095e623ac85 | 694,055 |
def circular_distance(a: int, b: int, C: int) -> int:
"""
Finds the shortest distance between two points along the perimeter of a circle.
arguments:
a: a point on a circle's circumference.
b: another point on the cicrle.
C: the total circumference of the circle.
return:
... | 1b1a54dca54edc18ef4c44a9e54f883410fb7c8f | 694,056 |
from pathlib import Path
def cache_dir(warn_scraper_dir):
"""Set scraper directory."""
return str(Path(warn_scraper_dir).joinpath("cache")) | 7c840f6529a6d1783afa2358d1b3d92d8693ed85 | 694,057 |
def get_proxy_list_size(proxy_list):
""" Return the current Queue size holding a list of proxy ip:ports """
return proxy_list.qsize() | 982240d8225f7c79327c661c91d6741311c1dd4e | 694,058 |
def find_toolchain(ctx):
"""Finds the first rust toolchain that is configured.
Args:
ctx (ctx): The ctx object for the current target.
Returns:
rust_toolchain: A Rust toolchain context.
"""
return ctx.toolchains["@io_bazel_rules_rust//rust:toolchain"] | 2c003b40529dec403c17cf02d7bf97f0e1d427fa | 694,059 |
def apply_function(funct, value, iterations):
"""
Example of a function that takes another function as an argument
"""
for index in range(iterations):
value = funct(value)
return value | 65836cb9b76adeb43c6e92bdc72c15d49ebf4b01 | 694,061 |
def dectodms(decdegs):
"""Convert Declination in decimal degrees format to hours, minutes,
seconds format.
Keyword arguments:
decdegs -- Dec. in degrees format
Return value:
dec -- list of 3 values, [degrees,minutes,seconds]
"""
sign = -1 if decdegs < 0 else 1
decdegs = abs(decde... | 4e41df37b9df3e375809c9c8c9f89ef420e0ac60 | 694,062 |
import re
def sub(pattern, repl, names, count=0, flags=0):
"""Replace characters that match regular expression."""
regex = re.compile(pattern, flags=flags)
return [regex.sub(repl, i, count=count) for i in names] | b85c9e6a350a5cbfbb9bde372def0a892517d9c1 | 694,063 |
def entrarNota(text):
""" funcion para añadir una nota """
while True:
try:
nota = float(input("{}(0-100): ".format(text)))
if 0<=nota<=100:
return nota
else:
print("la nota tiene que estar entre 0 y 100")
except:
pr... | ed628593e5a82be03873554a116f68f1299ac4d2 | 694,064 |
import os
def executable_name( f ):
"""Folder where the executable is"""
return os.path.basename( f ) | 27b7e9aee1dfd97a4c7dfaeb3cd18d0672822e69 | 694,065 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.