content stringlengths 39 14.9k | sha1 stringlengths 40 40 | id int64 0 710k |
|---|---|---|
def grant_url(focus_area, month):
"""Use the focus area and donation date information to get the original grant URL."""
fa = {
"community-development": 13,
"education-youth": 28,
"religion": 11,
}[focus_area]
month_param = month[2:]
return f"https://lillyendowment.org/for-cu... | 6ae83240afbec368038aba07b3f37d44ea0d1afe | 27,049 |
def parse_srg(srg_filename):
"""Reads a SeargeRG file and returns a dictionary of lists for packages, classes, methods and fields"""
srg_types = {'PK:': ['obf_name', 'deobf_name'],
'CL:': ['obf_name', 'deobf_name'],
'FD:': ['obf_name', 'deobf_name'],
'MD:': ['o... | ac33b56fc52831a80f1e38261b38c47407fd1bfb | 27,050 |
import random
def choose(bot, trigger):
""".choice option1|option2|option3 - Makes a difficult choice easy."""
if not trigger.group(2):
return bot.reply('I\'d choose an option, but you didn\'t give me any.')
choices = [trigger.group(2)]
for delim in '|\\/, ':
choices = trigger.group(2)... | ad4fd246e9db86d45a7a6cb06ef5b9813c0a0d5f | 27,051 |
from typing import List
def primes(max: int) -> List[int]:
"""
Return a list of all primes numbers up to max.
>>> primes(10)
[2, 3, 5, 7]
>>> primes(11)
[2, 3, 5, 7, 11]
>>> primes(25)
[2, 3, 5, 7, 11, 13, 17, 19, 23]
>>> primes(1_000_000)[-1]
999983
"""
max += 1
nu... | 1fbdda28414f9a846d2ea1dc945af619df6aeea7 | 27,055 |
def current_user(self):
"""Get current user"""
return self.handler.current_user | 790a3478390dbb5439380ef1a35b6bc67f89721a | 27,056 |
import torch
from typing import Tuple
def _split_crossval(xy: torch.Tensor, crossval_count: int, crossval_index: int) -> Tuple[torch.Tensor, torch.Tensor]:
"""
Generates a split of the given dataset along the first dimension for cross-validation.
:param xy: The data that should be split. The split will b... | 211146bdac3396da475b6c6b74d990031a537af7 | 27,061 |
from typing import Optional
from typing import Any
from typing import List
from typing import Iterable
def as_list(value: Optional[Any]) -> List[Any]:
"""Normalizes the value input as a list.
>>> as_list(None)
[]
>>> as_list("foo")
['foo']
>>> as_list(123)
[123]
>>> as_list(["foo", "b... | 54f13890437dfafd779583a3bbdc42ae769312f4 | 27,062 |
def unique_proportion(_metrics):
"""Computes the proportion of unique non-null values out of all non-null values"""
total_values = _metrics.get("table.row_count")
unique_values = _metrics.get("column.distinct_values.count")
null_count = _metrics.get("column_values.nonnull.unexpected_count")
# Ensur... | df44cc537623404d4de949ffc8bb5acf4fb62d48 | 27,077 |
import math
def signed_distance_point_to_line(a, b, c, p):
"""
Distance between a point p and a line defined by a, b and c.
a, b, c: the line $x + by + c = 0$
p: the point
"""
d1 = (a*p[0] + b*p[1] + c)
d2 = math.sqrt(math.pow(a, 2.) + math.pow(b, 2.))
#d = abs(d1)/d2
d = d1/d2
... | f06b67e62b940e259963b1a092650936dc8e9fb0 | 27,081 |
import yaml
def validate_spackyaml(filename):
"""
Ensure that a spack.yaml file has a spack or env directive
"""
try:
with open(filename, "r") as fd:
data = yaml.load(fd, Loader=yaml.FullLoader)
if "env" not in data and "spack" not in data:
return False
... | c9bdf6de87d9945d106c2312087441f84584daef | 27,082 |
def ResetStNum(N=0):
"""Reset the state numbering counter.
"""
global NXTSTATENUM
NXTSTATENUM = N
return NXTSTATENUM | 7b3c49221da9110c498bc0b1dc88d230e5d65018 | 27,083 |
import binascii
def bytes_str(val):
"""
Converts bytes into hex string.
Returns:
hex string
"""
assert isinstance(val, (bytes, bytearray))
return binascii.hexlify(val).decode('ascii') | dfe6d5192b639f656a56918f5ab570f8edd96dd7 | 27,084 |
def pull_key(key_fun):
"""Return a new dict with members of objs as values and values generated by key_fun as keys.
pull_key(key_fun)(objs)
:: Hashable K => (X -> K) -> Seq[X] -> {K : X}
Equivalent to the following in Python 3:
{key_fun(v):v for v in objs}
>>> from operator import itemgett... | 3b2288ec0eee6f164896d7b97a31aaec9cb52422 | 27,091 |
import re
def word_tokenizer(sentence):
"""
将一句话分成单词的列表, 会顺便承担清除标点符号的工作
Parameters
----------
sentence : string
Returns
--------
words : the list of word
"""
solve_sentence = re.sub(r'\W+|\s+', ' ', sentence)
words = solve_sentence.lower().strip(' ').split(' ')
return... | 835e78d4a4a35beb54e232a1d44a67332b3c267a | 27,093 |
def flatten(list_of_lists: list) -> list:
"""Given a list of lists, flatten all the items into one list.
>>> flatten([ [1, 2, 3], [4, 5, 6]])
[1, 2, 3, 4, 5, 6]
"""
return [val for sublist in list_of_lists for val in sublist] | 093d3bfbb90c043414fdfb18da79334e8910b150 | 27,095 |
def timeseries_train_test_split(df, test_size=0.2, gap=0, ascending=True):
"""Split DataFrame or matrices into random train and test subsets for timeseries
Parameters
----------
df : pd.DataFrame, shape (n_samples, n_features)
Training data, where n_samples is the number of samples an... | 8a11f2b0ca1c60dc7c9a92419a6f5a2ab8994815 | 27,097 |
def list_to_string(l):
"""
Converts a string list in to a string
@param l is the string list
@returns a concatentation of each element in the list
"""
res = ""
for elem in l:
res += elem
return res | ef30e847703f56453c79a2c51ba61497f26b4963 | 27,101 |
def is_aware(
time_point):
"""
Return whether ``time_point`` is aware of the timezone
"""
return time_point.tzinfo is not None and \
time_point.utcoffset() is not None | 9169af11d30bb1fca2b4dbc7708dfee7e44e858f | 27,104 |
import logging
from pathlib import Path
def get_filelist(paths: list[str], recursive: bool = False) -> list[str]:
"""Get a list of files (but not directories) from a path.
Args:
paths (list[str]): The path(s) to search for files.
recursive (bool, optional): Whether to recursively search the p... | 9b73c1d0845385279a90e860a7666aea2342912c | 27,109 |
import re
def size2integer(value):
"""Try to convert a string representing a size to an integer value
in bytes.
Supported formats:
* K|k for KB
* M|m for MB
* G|g for GB
:param value: the string to convert
:return: the corresponding integer value
"""
m = re.match("(\d+)\s*(\w... | f7771bd9fd8904d03a7ab75da5939e01d4a126d7 | 27,110 |
def find_domain_zone_matches(domains, zones):
"""
Finds matches between Amazon SES verified domains and Route 53 hosted zones.
Subdomain matches are taken when found, otherwise root domain matches are taken.
:param domains: The list of domains to match.
:param zones: The list of hosted zones to mat... | d6a0ed7bd974c411aeb4d4571a23565b7c21ca59 | 27,111 |
def format_seconds(s):
"""
Format a seconds value into a human-readable form
"""
years, s = divmod(s, 31556952)
min, s = divmod(s, 60)
h, min = divmod(min, 60)
d, h = divmod(h, 24)
return '%sy, %sd, %sh, %sm, %ss' % (years, d, h, min, s) | f004d9f2cef8b3b9eee967ebd9d4811cbc80ae6c | 27,113 |
def sanitize_string(input_string):
"""Removes unwanted characters from a string and returns the result
"""
return input_string.replace('"', '') | 596bd7bf4810ce9ef2b96c6d6fead947bd4e22ec | 27,116 |
def parse_distro_info_path(path):
"""Break distro_info path into repo + file"""
path = path.strip().rsplit("/", 1)
info_repo = path[0]
info_file = path[1]
remote = False
if info_repo.startswith("http"):
remote = True
return info_file, info_repo, remote | 44f221485e04b6e3203ac3863a10d06fcbbe1555 | 27,123 |
import math
def volatilization_rate(k, mass, dz, dt):
"""
Compute the transfer of the volatilization (kg/s)
source : (“CHEMMAP technical User’s manual 6.10,” 2014)
params
------
k : volatilization coefficient [m/s]
dz : vertical diffusivity [m²/s]
dt : length of a timestep [s]
mas... | 69ebb196ecb9a860adcb46b5775e90a85c2ca06c | 27,125 |
def _FlattenToScoresList(config_param_score_dict):
"""Extracts a list of scores from input data structure.
Args:
config_param_score_dict: of the form {'capture_name':
{'param_name' : score_value,.. } ..}
Returns: Plain list of all score value present in input data
structure
"""
result = []
... | 188e784f59711bbe46f89c4c8171c3a0551a0cf3 | 27,129 |
def filter_dataset(dataset, filter_indices):
"""
Filter a dataset consisting of a dictionary for the different variables by a vector of True/False indicating if
the data point (a row index) should be kept or not.
Returning a copy to leave the original dataset untouched.
"""
dataset_copy = datase... | 256878262c879f4b914693a7333236539f062bc6 | 27,131 |
from typing import Mapping
def check_dict_nested_attrs(item: Mapping, dict_data: Mapping) -> bool:
""" Checks the values from `dict_data` are contained in `item`
>>> d = {'a': 1, 'b': {'c': 2}}
>>> check_dict_nested_attrs(d, {'a': 1})
True
>>> check_dict_nested_attrs(d, {'b': {'c': 2}})
True
... | 08ed8dbc405e236b95e33e10e9c342e15b6363c9 | 27,132 |
import itertools
def is_almost_simplicial(G, n):
"""Determines whether a node n in G is almost simplicial.
Parameters
----------
G : NetworkX graph
The graph on which to check whether node n is almost simplicial.
n : node
A node in graph G.
Returns
-------
is_almost_s... | a1ffdb2b23e6f0d49cb6e65220523eb0553b1a74 | 27,135 |
import csv
def create_csv_table(table_path, rows_list):
"""Create csv file from list of lists.
Args:
table_path (str): file path to table.
rows_list (list): nested list of elements to write to table.
Returns:
table_path (str): filepath to table.
"""
with open(table_path, ... | f46f1295c408925adac0b2e97e63200036ffd50f | 27,141 |
def processReducedResult(key_value_tuple):
"""
input: (TW-100917-125717-1537514430, 4.03)
output: [TW, 100917, 125717, 1537514430, 4.03]
"""
values = key_value_tuple[0].split("-")
values.append(str(key_value_tuple[1]))
return values | 22ad7e6f5381ccf983ad159f190a7e1686ab2558 | 27,142 |
def _split_csv(string):
"""Split string into a list, excluding empty strings"""
if string is None:
return []
return [n.strip() for n in string.split(',') if n] | de6b21c340ec4c24462f3120f3486e974feafb9d | 27,151 |
import random
def selectNRandom(nodes, N):
"""
Selects n random nodes from a list of nodes and returns the list
"""
random.shuffle(nodes)
return nodes[:N] | 4d4a330136a8b56b4ee1943db318df13a3be3c3f | 27,152 |
def globify_time_descriptors(path):
"""Convert strftime time descriptors to a glob-compatible expression.
For example, convert,'%Y' to '[12][0-9][0-9][0-9]'. Then the
glob expression can be used to match path names containing
a four digit year.
"""
path = path.replace('%Y', '[12][0-9][0-9][0-9... | b28d47c903742def7bb9517102f7df3b989fb1ae | 27,157 |
def MakeTuple(object_):
"""
Returns the given object as a tuple, if it is not, creates one with it inside.
@param: Any object or tuple
The object to tupleIZE
"""
if isinstance(object_, tuple):
return object_
else:
return (object_,) | 119e17785bcf5c7b8dae48c422d12dc501c32d57 | 27,159 |
def reorder_exons(exon_ids):
"""
Reorder exons if they were out of order.
Parameters:
exon_ids (list of str): List of exons 'chrom_coord1_coord2_strand_exon'
Returns:
exons (list of str): List of same exon IDs ordered based on strand
and genomic location
"""
strand = exon_ids[0].split('_')[-2]
coords = ... | d3f52a24d4da1a05a1deceaf38927622c141a9ad | 27,161 |
def get_reaction_from_name(reactions, name):
"""Return reaction with name.
Args:
reactions (list(reactions)): the reactions.
name (str): name of the desired reaction.
Returns:
reaction: the corresponding reaction.
"""
matches = [r for r in reactions if r.name == name]
... | d27da8428d7a9f8e07ede7cf9e4574d2c012e480 | 27,166 |
def extract_sub_ids(file, naive=False, label_of_interest=0):
"""
Extracts sub_ids from dataset_x.txt files of the following format:
SubjectID,Network,Station,Latitude,Longitude,PercentageEarthquakes,PercentageTremor,
PercentageNoise,PercentageUnclearEvent
Args:
file (path): Path to file con... | a51daa18ec2c1799dc9e07e59008088290977bb3 | 27,168 |
def format_api_output(response):
"""Format retrieved json from API call"""
data = response["items"][0]
return {
"rep": data["reputation"],
"gold": data["badge_counts"]["gold"],
"silver": data["badge_counts"]["silver"],
"bronze": data["badge_counts"]["bronze"],
} | 1f914f8f16ac7c623ae554ac567399037752575b | 27,169 |
def relativize_paths(root, paths):
"""
Take a list of fully-qualified paths and remove the root,
thus making them relative to something.
"""
clean_paths = []
for path in paths:
clean_paths.append(path.replace("%s/" % root, ''))
return clean_paths | 12487e109b281fd886c37f4673e22ffad4d6fe21 | 27,183 |
def runner(app):
"""Using test app, create and return a CLI runner object."""
return app.test_cli_runner() | 67284844e1e2be40dd3dbbed58b04fdbf295a83c | 27,184 |
def _is_descendant(index, target):
"""
Return true if index is a parent of target.
"""
while target.isValid():
if target == index:
return True
target = target.parent()
return False | f97dd888fa9506a57bc81730f2e449b834aafa96 | 27,187 |
def pybtex_unescape(string: str) -> str:
"""
Reverts the escaping applied by Pybtex.
:param str: Input string with pybtex-escape characters.
:return: Output string where this has been reverted.
"""
return string.replace('\\_', '_').replace('\\textasciitilde ', '~') | 0c8312ac82c360282369a4e4a05ea9b5899550d8 | 27,194 |
def isPointInsideRect(x, y, rect):
"""
This function determines if the point x, y is within the rectangle rect.
Returns TRUE if it is and FALSE if it is not.
"""
if ((x > rect.left) and
(x < rect.right) and
(y > rect.top) and
(y < rect.bottom)):
return True
else:
... | 984855f6fa85912b323806ebba3b98c7c6aae441 | 27,195 |
import torch
def zero_loss(*args, **kwargs):
"""Dummy loss that always returns zero.
Parameters
----------
args : list
Can take any number of positional arguments (without using them).
kwargs : dict
Can take any number of keyword arguments (without using th... | 2c4821e6fb1e443258f7fc482f2630c16dedb3a2 | 27,197 |
def get_attribute_from_tag(tag, attribute):
"""Returns a xml attribute from a given tag"""
element = None
try:
element = tag.attrib[attribute]
except KeyError:
pass
# print("Error: attribute {} was not defined in this tag.".format(e))
return element | 914e04f2e6441ffb5f42d71de49bd99fe5e3092b | 27,207 |
def fib (n: int) -> int:
""" Returns the n'th Fibonacci number.
Note that this function uses zero style indexing, meaning that the first Fibonacci number has an index
of zero (n=0)."""
f_p, f_c= 0, 1
for i in range(n):
f_n = f_c + f_p
f_p = f_c
f_c = f_n
return f_c | 431c0ba58b2dfb25eca03c14890d7b6ecab88f0d | 27,213 |
def get_project_ids(config, modeling_application):
""" Get a list of the ids of models in the source database for a particular modeling application (e.g., XPP)
Args:
config (:obj:`dict`): configuration
modeling_application (:obj:`str`): modeling application (e.g., ``XPP``)
Returns:
... | c3ebe7f74a1eb27dbbcd316002ad91d2ebaa4bf6 | 27,216 |
def construct_filter_based_on_destination(reimbursable_destination_type: str):
"""
Construct Filter Based on Destination
:param reimbursable_destination_type: Reimbusable Destination Type
:return: Filter
"""
filters = {}
if reimbursable_destination_type == 'EXPENSE_CATEGORY':
filters... | 73116ce3e6398e98c1540380094e70cc1620867b | 27,221 |
import random
def natural(values, classes=5, maxsize=1000, samples=3):
"""
Jenks Optimal (Natural Breaks) algorithm implemented in Python.
The original Python code comes from here:
http://danieljlewis.org/2010/06/07/jenks-natural-breaks-algorithm-in-python/
and is based on a JAVA and Fortran code ... | 8ba4085847bb1dbb70433a0af1491c83dccc39d9 | 27,225 |
def calc_url_by_from_date(url, period1_sec, period2_sec):
"""This function takes the url and the start and ens periods and insert them in the relevant place in the url """
prefix = url.split('history?', 1)[0] + 'history?'
periods = 'period1=' + str(period1_sec) + '&period2=' + str(period2_sec)
suffix = ... | 404c7a7259c2edf1dbc565ea21b8158d33b8b1ba | 27,228 |
def containsNonAlphaNum(word_list):
"""
Does list of words contain any special characters?
Parameters:
word_list: list of words
Returns:
bool: whether any word in the list contains a special
character
"""
chars = ["-", "_", "."]
allow_chars = set(chars)
for word in word... | 7a87c706eaec5cd4ee10fa0ccc027a4850430eb3 | 27,230 |
def graph_codes(dataframe,code):
"""A function that takes the dataframe, NAICS code(string). Graphs both the original
and the LQ of the code using hvplot. Only necessary arguments are dataframe and code. """
return dataframe.hvplot(c= code, tiles='OSM', title= code, alpha=0.6) + dataframe.hvplot(c= 'LQ... | ad403862e136f83dd4e334cd0cdf47fa8cc5df4c | 27,231 |
def _get_user_id_from_session(session):
"""
Get user's identifier from the session. It could be their id or username
since both are unique.
"""
user_sess_id = session.session_token.get("sub")
if user_sess_id:
try:
user_sess_id = int(user_sess_id)
except ValueError:
... | 759249581ea54660968958ceed1dd29c5cf1c247 | 27,232 |
def str_fsize(sz):
"""
Formats file size as string (i.e., 1.2 Mb)
"""
if sz < 1024:
return '%.1f bytes' % sz
sz /= 1024.0
if sz < 1024:
return '%.1f KB' % sz
sz /= 1024.0
if sz < 1024:
return '%.1f MB' % sz
sz /= 1024.0
if sz < 1024:
return '%.1f G... | 6e42389ab96678d595c3c0bd11441e6fa5c96810 | 27,234 |
def get_position_of_one(min: float, max: float) -> float:
"""
Maps 1.0 value in range min-max to range 0-1
:param min: minimum
:param max: maximum
:return:
"""
mm = max - min
return (1.0 - min) / mm | 773810b54e8e84b108185468c6e1e9c416ee08ce | 27,235 |
def vector(a, b):
"""
Return the vector between a and b
"""
return b - a | 8d55f178bf67c7dfd48d1e8def8af798c6593203 | 27,239 |
def decode_integer_big_endian_4(frame, start):
""" Encode an integer in a byte array using big endian on 4 bytes.
Args:
frame: Source byte array
start: Read start index
Returns:
Decoded integer value
"""
return (frame[start] << 24) | (frame[start + 1] << 16) | (frame[start ... | 00b7809b3f759d57628f1f70af801f6f7f4ccb41 | 27,245 |
def adda(a, b, c=0, d=0, e=0):
"""Add number b to number a. Optionally also add
any of numbers c, d, e to the result.
"""
print(f"Function `adda` called with arguments a={a} b={b}", end="")
if c: print(f" c={c}", end="")
if d: print(f" d={d}", end="")
if e: print(f" e={e}", end="")
prin... | 50a1a923f2dd046114bf92caffe9ba770d062f43 | 27,249 |
def _looks_like_url(name):
"""
Function tries to determine if input argument
looks like URL and not like S3 bucket name.
:param name - input name
:return: True, if name looks like URL;
False otherwise.
"""
if name.endswith('.com'):
return True
if name.find(':') >= 0:... | d65eff615612fd087ec48a847347be6a5cefef91 | 27,251 |
import pickle
def load_from_file(fn):
"""
Wczytanie danych zapisanych wcześniej przez save_to_file.
:param fn: nazwa pliku.
:return: wczytane dane.
"""
return pickle.loads(open(fn, "rb").read()) | b25a8063b0e7d77bf2725b2657fc7e65473317bd | 27,253 |
def multi_replace(s, rep_dict):
"""
Replace multi strings
Parameter
---------
s: string
The string need to be replaced
rep_dict: dict
The replace patterns, {old: new}
Return
------
s: string
The replaced string
"""
for pattern ... | 01ce4d83b12d60252b01681adc89c12a2f8b3e91 | 27,257 |
def generate_gene(base, indexes) -> str:
"""
Takes a base string and indices of where the base string to be added to the cumulative string and returns
constructed gene
"""
gene = base
for i in indexes:
gene = gene[:i + 1] + gene + gene[i + 1:]
return gene | a5cdca4d70e111003defe8286733ccc36325a66d | 27,263 |
import math
def get_meansd(values):
"""Returns mean and standard deviation of the specified values."""
if not values:
return float('nan'), float('nan')
mean = sum(values) / len(values)
sd = math.sqrt(sum([(v - mean) ** 2 for v in values]) / len(values))
return mean, sd | 77f69a86a886f3ea7f814f91a02a362fee2e3588 | 27,265 |
def get_short_object_id(cid):
"""return shortened contribution ID (ObjectId) for `cid`.
>>> get_short_object_id('5a8638add4f144413451852a')
'451852a'
>>> get_short_object_id('5a8638add4f1400000000000')
'5a8638a'
"""
length = 7
cid_short = str(cid)[-length:]
if cid_short == '0'*lengt... | 8e39f877f3b8914401d898aa5423b4fa2360aacf | 27,272 |
def _make_scales(notes):
""" Utility function used by Sound class for building the note frequencies table """
res = dict()
for note, freq in notes:
freq = round(freq)
for n in note.split('/'):
res[n] = freq
return res | 21ebc91750f231fa3d25f10f59d55c921940db4b | 27,273 |
import torch
def interp(x: torch.Tensor, xp: torch.Tensor, fp: torch.Tensor) -> torch.Tensor:
"""Interpolate ``x`` tensor according to ``xp`` and ``fp`` as in ``np.interp``.
This implementation cannot reproduce numpy results identically, but reasonable.
Code referred to `here <https://github.com/pytorch/... | b18c373d8d1bfc8da736a0322d6abcc41af3cde0 | 27,279 |
def get_pr_labels(pull):
"""Gets PR labels as set"""
pr_lables = set()
for label in pull.labels:
pr_lables.add(label.name)
return pr_lables | be807aeddddfd642412ba9e1455085af1c67ca7d | 27,282 |
def all_image_ids(images):
"""Given images data, return a dict of all image IDs therein.
:param images: images data from Twistlock, decoded from json
:return: A dict whose keys are the IDs of the images, and values are
the tag for that image (if present)
"""
results = {}
for image in im... | 829614ea917521b6292754a6aa29be0486360a31 | 27,284 |
def addNodeMI(nm_dict, node, value):
"""
Add motif information to node dictionary.
Input:
nm_dict: (dictionary) the dictionary of node motif degree
node: (int) the id of node
value: (int) the change value of node
Output:
nm_dict: (dictionary) changed ... | 67fe86aefcf8c54feaa72e07a15f2be65b916fc1 | 27,286 |
def dict_without_keys(d, *omitkeys):
"""
Returns a copy of a dict without the specified keys
Args:
d (dict): A dict that to omit keys from
*omitkeys: Variable length list of keys to omit
Returns:
dict: A dict with omitted keys
"""
return {key: d[key] for key in d.keys()... | 75b04a1ef3f2848e390b065f2df12eedec8919ea | 27,290 |
def get_root_nodes(config_yaml):
"""
List the root nodes defined in the given taxonomy config.
Args:
config_yaml: configuration content
Returns: list of root nodes
"""
root_nodes = []
for root_node in config_yaml['Root_nodes']:
root_nodes.append(root_node['Node'])
retur... | 8f336e87ec0688ab15ca91c032f6921175ab021b | 27,292 |
def hard_dedupe(s):
"""Takes in a string, and returns a string where only the first occurrence of each letter is retained. So the string 'abccba' goes to 'abc'. The empty string returns the empty string."""
seen = set()
ans = ''
for char in s:
if char in seen:
continue
seen.a... | 58104d46d19c1de713fc86ff08ea36383dc5598e | 27,294 |
import re
def standardize_whitespace(string: str) -> str:
"""
Removes leading, trailing, and repeat whitespace from a given *string*.
"""
return re.sub(r"\s+", " ", string.strip()) | 499f361101d45eea82928dafef8b18a87d910841 | 27,297 |
def get_compatibility_list_from_parser(parser):
"""
Extract the docstring information (if any) about compatible versions
:param parser: a parser function
:return: list of versions
"""
docstring = parser.__doc__
if docstring is None:
return None
lines = docstring.split('\n')
... | 25f83a29f684739c9989ffa03119ca3f880514f3 | 27,309 |
def map_SWAS_var2GEOS_var(var, invert=False):
"""
Map variables names from SWAS to GEOS variable names
"""
d = {
# '1_3_butadiene':,
# '1_butene':,
# '2_3_methylpentane':,
# '224_tmp':,
'acetaldehyde': 'ALD2',
'acetone': 'ACET',
# 'a... | 89ee80ff698aa17c04b589c3068b5b584adea95b | 27,312 |
def is_valid_bdf_multiplier(multiplier):
"""check if the detect_multiplier is valid"""
if multiplier < 3 or multiplier > 50:
return False
return True | d6c9b96611f42d2004f00fd334d5ae8773aecb94 | 27,315 |
import re
def _can_skip_tests(file_names, triggers):
"""
Determines if tests are skippable based on if all files do not match list of regexes
:param file_names: list of changed files generated by _get_changed_files()
:param triggers: list of regexes matching file name that indicates tests should be run
:r... | de3f9c66332b8b6cc1c788233a6db0462fb38470 | 27,322 |
def format_puzzle(grid):
"""Formats the puzzle for printing."""
puzzle = ""
for line in grid:
puzzle += " ".join(line) + "\n"
return puzzle | 0b6017d0e9d8a2d29cfe83ef3c20c4cdf535d035 | 27,326 |
import random
def roll(add=0):
"""A quick function to roll a d20 and add the modifier"""
return random.randint(1, 20) + add | e8afe08b270ac2488ded0e6c9fa9574d406d9005 | 27,334 |
def yn_prompt(question: str, yes=None, no=None) -> bool:
"""Ask yes-no question.
Args:
question: Description of the prompt
yes: List of strings interpreted as yes
no: List of strings interpreted as no
Returns:
True if yes, False if no.
"""
if not yes:
yes = ... | 3338493b42b118d9aacadff70dab3738643b538a | 27,341 |
def hlstr(string, color="white"):
"""
Return HTML highlighting text with given color.
Args:
string (string): The string to render
color (string): HTML color for background of the string
"""
return f"<mark style=background-color:{color}>{string} </mark>" | 52e9d069d559feec2237d0847e667a1cb53326d8 | 27,343 |
def make_valid_did(lfn_dict):
"""
When managing information about a LFN (such as in `rucio upload` or
the RSE manager's upload), we add the `filename` attribute to record
the name of the file on the local disk in addition to the remainder
of the DID information.
This function will take that pyt... | 10e5777e5727e835683752aac197b43808d48fb4 | 27,353 |
def get_response(move) -> int:
"""
Utility function to enter the response to a move.
:param move: The move to which to respond.
:return: 1: hit, 2: hit and ship destroyed, 3: game over, you win, -1: miss
"""
print("Move made:", move)
return int(input('What response to return?')) | cb115447fe5cf244b7a0bee424edeedb45b5ea42 | 27,354 |
import gzip
def load_fasttext_class_probabilities(probability_file_path):
"""
Utility function that loads class probabilities from a previously performed prediction run.
:param probability_file_path: str, path to the output file with class probabilities for the test dataset
:return: list of float: pr... | 3ddff33c878b6ec013b2bfb8ff1e978f602a7d91 | 27,355 |
def get_package_names(pyproject):
"""
Get package names
:param dict pyproject: pyproject.toml body.
:return: Package names
:rtype: list
"""
package_names = []
for pkg in pyproject["package"]:
if pkg["category"] == "main":
package_names.append(pkg["name"])
return... | 9d12deab1613c4780a7b53d6f13233b72b51cf23 | 27,356 |
import random
def sim_detections(gt, tpr, fpr):
"""Simulates detection data for a set of ground truth cluster labels and an
annotator with a specified TPR and FPR.
Returns an array of with same length as input gt, where 1 indicates the
simulated annotator detected a cluster and 0 indicates an undetec... | ad8d0ac4423333c64ab1db8b838cba4ed7da4291 | 27,357 |
def update_csv_data_dict(csv_data, first_column, *other_columns):
"""
Update a csv dictionary for a given first column
:param csv_data: The csv data dictionary to add the row to.
:param first_column: The first column of the row to add.
:param *other_columns: The further columns of the row to add.
... | 34abbef2c026bc520a7f4048cd00b6710414294d | 27,361 |
import unittest
def run_student_tests(print_feedback=True, show_traces=True,
success_required=True):
"""Run a suite of student submitted tests.
Tests must be located in /autograder/source/student_tests/
Args:
print_feedback (bool): Print success or failure message
s... | e262b6d5e8c74ca9085aa943a5d58670314d781d | 27,362 |
import torch
def rotated_box_to_poly(rotated_boxes: torch.Tensor):
""" Transform rotated boxes to polygons
Args:
rotated_boxes (Tensor): (x, y, w, h, a) with shape (n, 5)
Return:
polys (Tensor): 4 corner points (x, y) of polygons with shape (n, 4, 2)
"""
cs = torch.cos(rotated_boxe... | 52f0aa5f225006162bbbd676d1319477802cb49e | 27,363 |
import torch
def maybe_cuda(what, use_cuda=True, **kw):
"""
Moves `what` to CUDA and returns it, if `use_cuda` and it's available.
Args:
what (object): any object to move to eventually gpu
use_cuda (bool): if we want to use gpu or cpu.
Returns
object: the s... | ad9f8aa37c4d32000690768d5c18f327ff3bc76c | 27,364 |
import logging
def get_logger(
log_level=logging.INFO,
msg_format="%(asctime)s - %(levelname)s - %(filename)s:%(funcName)s:%(lineno)s"
"- %(message)s",
cls_name=__name__,
):
"""
Instantiate a new logger.
Args:
log_level = One of the log reporting levels defined in the logging modu... | 154518079694a57f44ebe2c83a5e19ff8c4b2396 | 27,365 |
def load_RIRE_ground_truth(file_name):
"""
Load the point sets defining the ground truth transformations for the RIRE
training dataset.
Args:
file_name (str): RIRE ground truth file name. File format is specific to
the RIRE training data, with the actual data expectd to... | 9c7747b6fad1a10fb8cbb32162a3423e31fa40f3 | 27,368 |
def subdivide(x_1, x_2, n):
"""Performs the n-th cantor subdivision of the interval (x_1, x_2), a subset [0, 1]"""
if n == 0:
return []
new_x_1 = 2 * (x_1 / 3) + x_2 / 3
new_x_2 = x_1 / 3 + 2 * (x_2 / 3)
return (
subdivide(x_1, new_x_1, n - 1)
+ [new_x_1, new_x_2]
+ ... | ee2cc0ba214d363555224e4b70c10976c63d7dec | 27,369 |
def _get_ref(info: list) -> str:
"""Get the workspace reference from an info tuple"""
return f"{info[6]}/{info[0]}/{info[4]}" | fbd7bb479abc090b643fa1f1ecfcdd84dee18f62 | 27,373 |
import re
import inspect
def parse_pyvars(code: str, frame_nr: int = 2):
"""Looks through call stack and finds values of variables.
Parameters
----------
code : str
SuperCollider command to be parsed
frame_nr : int, optional
on which frame to start, by default 2 (grandparent frame... | 381d698d3905ee306f75ad888d07c1107e398251 | 27,374 |
def _get_lines(file_obj):
"""Return all the lines in file_obj."""
return [line.strip() for line in file_obj.readlines()] | 07b2bcab4ad9f4f48e5c633752c088791eee4c2d | 27,380 |
def discovery_topic_is_device_config(topic):
"""Return True if the discovery topic is device configuration."""
return topic.endswith("config") | ffb313d9a35312bf8dd6f9c5ad97a9b1dc9ab2fd | 27,387 |
def format_class_name(name):
"""
Formats a string to CapWords.
:param name: string to format
:type name: str
:return: string with the name in CapWords
:rtype: str
"""
fixed_name = name.title().replace("_", "")
return fixed_name | 064369048205aaf5afe872844ceff4605b6f1498 | 27,397 |
import time
def wait_on_job(job):
"""Block until the async job is done."""
while job.status() != 'done':
time.sleep(.05) # pragma: no cover
return job | e08190d6a8dee960e7e3f3490ed934203f0aa7ff | 27,405 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.