content stringlengths 39 14.9k | sha1 stringlengths 40 40 | id int64 0 710k |
|---|---|---|
import copy
def match_files(input_files, results_files):
"""Takes in results from parse_input_files and parse_docuscope_results and sets the 'present' values
in the results dictionary to True for all the input files present in it. Does nothing if an input file
isn't in the docuscope results"""
job = c... | 35fb1797ee5dc73cf01f878f893507d4cbcbde9b | 75,058 |
def date_message(n_clicks, freq, start_date, end_date):
"""
Function that returns a message when the user enters a date range.
Args:
n_clicks: Number of clicks registered by the submit button.
freq: Radio option for selecting the requests per day, hour, minute.
start_date: Start da... | 93d1c413fb2c34cf35e3c6fb9a94d2cb19ef857a | 75,059 |
def get_vacant_binding_index(num_agents, bindings, lowest_binding_index,
force_scheduling=False):
"""Return a vacant binding_index to use and whether or not it exists.
This method can be used with DHCP and L3 agent schedulers. It will return
the lowest vacant index for one of t... | a3842da804ffb2f53d3089e5c4696fcec911aaa6 | 75,063 |
import re
def remove_comments(text):
"""Remove C-style /*comments*/ from a string."""
p = r'/\*[^*]*\*+([^/*][^*]*\*+)*/|("(\\.|[^"\\])*"|\'(\\.|[^\'\\])*\'|.[^/"\'\\]*)'
return ''.join(m.group(2) for m in re.finditer(p, text, re.M | re.S) if m.group(2)) | 638b646545ec3b85c9c2b7b799e56a951e68bd4b | 75,064 |
from typing import Optional
def is_limit_reached(num_messages: int, limit: Optional[int]) -> bool:
"""Determine whether the number of messages has reached a limit.
Args:
num_messages: The number of messages to check.
limit: Limit on the number of messages.
Returns:
`True` if the ... | 03c31cfe9bca1ac829b9d12243c454ef778d78bd | 75,065 |
def compress_feature_metadata(tip_metadata, int_metadata):
"""Converts tip/internal node metadata DataFrames to dicts to save space.
This is a pretty early optimization -- ideally we would use 2-D lists as
our final metadata structure, similar to the table / sample metadata
compression. This should be ... | dd78a7791bc61fd260325e778dc302d96484c16d | 75,066 |
import math
def gg2gc(gg):
"""transforms coordinates from geographic (lat, lon, h) to geocentric"""
factor = math.pi/180 # conversion factor from degrees to radians
r_earth = 6378.135 # earth radius (km) and flatness factor
g = 1.00673944 # earth flatness factor
lat = gg[0]*factor
lon = ... | 3fc4267aa2198e636e7d952945f77689102c6c45 | 75,070 |
def bound(low, value, high):
"""
If value is between low and high, return value.
If value is below low, return low.
If value is above high, return high.
If low is below high, raise an exception.
"""
assert low <= high
return max(low, min(value, high)) | eecdd663a7fc2712183f341677d7c918ede00fea | 75,071 |
def char_to_string(ll):
"""Convert 2-D list of chars to 1-D list of strings."""
# https://stackoverflow.com/questions/23618218/numpy-bytes-to-plain-string
# bytes_string.decode('UTF-8')
# We might be able to do this a bit more shorthand as we did in Python2.x
# i.e return [''.join(x).strip() for x... | 09d31eee4217ae04fc85485163c5b2528b340874 | 75,072 |
def sum_valid_rooms(valid_rooms):
"""
Get the sum of all the sector IDs in valid rooms.
Args:
valid_rooms (list): List containting tuples of valid rooms.
Returns:
int
"""
# Valid Room:
# (room_name, sector_id, checksum)
return sum([i[1] for i in valid_rooms]) | 6e4fd9220a1fcc5f5fcf96b0c5ce71b49ccb833c | 75,073 |
def _reward_scaler(reward: int) -> float:
"""
Scale a reward for a model
:param reward: The reward to be scaled
:return: The scaled reward
"""
if reward == 1:
return 1.0
if reward == 0:
return 0.0
return -1.0 | ca341cb182ceba34a87c76378328003b4bff71d4 | 75,087 |
import json
def readjson(sFile):
"""
Purpose:
Read the JSON from a file
Inputs:
sFile string, filename to read from
Return value:
aJS list of JSON/dictionary elements
"""
aJS= []
with open(sFile) as f:
for line in f:
try:
... | 9882c9797783bbe387b8c95753e08d68ab009472 | 75,088 |
import string
import random
def random_letter(only_capital=True):
"""Randomly select a letter from the alphabet"""
if only_capital:
letters = string.ascii_uppercase
else:
letters = string.ascii_letters
return random.choice(letters) | 703f54239e0937d046c676eec798725a778027f2 | 75,090 |
def sgn(val):
"""Sign function. Returns -1 if val negative, 0 if zero, and 1 if
positive.
"""
try:
return val._sgn_()
except AttributeError:
if val == 0:
return 0
if val > 0:
return 1
else:
return -1 | aaaa88e4620ce87b931bf156a5d30087c59b956f | 75,096 |
def bottom_up_longest_common_subsequence(text_1, text_2):
"""
Parameters
----------
text_1 : str
first string
text_2 : str
second string
Returns
-------
int
length of the longest common subsequence
>>> bottom_up_longest_common_subsequence("abcde", "ace")
... | ddbc090a0231ef51810ccf749dc7a030bf6017a0 | 75,100 |
import re
def get_display_name(class_name):
"""
Converts class names to a title case style.
For example, 'CelebrityApprovalReport' would become 'Celebrity Approval
Report'.
"""
# Thanks to Django's code for a portion of this regex
display = re.sub('(((?<=[a-z])[A-Z])|([A-Z](?![A-Z]|$)))',... | a2963e14a4a57a6a679220a0117242a68544942c | 75,101 |
def _cryptography_encrypt(cipher_factory, plaintext, key, iv):
"""Use a cryptography cipher factory to encrypt data.
:param cipher_factory: Factory callable that builds a cryptography Cipher
instance based on the key and IV
:type cipher_factory: callable
:param bytes plaintext: Plaintext data t... | d4ded5a2ab52a8b0116d90d11d846546a65fe23f | 75,102 |
def to_dict(meta):
"""
Convert a coords, meta, attrs or masks object to a python dict.
"""
return {name: var for name, var in meta.items()} | 23d2a77a28930a8460d461a0115a534e89a115c0 | 75,104 |
def split_chunks(lst: list, size: int = 100) -> "list[list]":
"""Splits ids into list of list according to api limit
`lst`: The list of ids
`size`: Max length of inner list"""
return [lst[i: i + size] for i in range(0, len(lst), size)] | 081e53ba6d764ea88a4bc3020a6d3b0c55adc2c8 | 75,108 |
def cite(fmt='bibtex'):
"""
Return the citation string of the slab module.
Arguments:
fmt (str): if bibtex, return the bibtex citation string, otherwise return the text reference
"""
if fmt == 'bibtex':
return """@article{Schönwiesner2021, doi = {10.21105/joss.03284}, url = {https:/... | 334e3a708401bec3cf681f24aed5ef79cc03bc92 | 75,109 |
def group_lines(lines):
"""Split a list of lines using empty lines as separators."""
groups = []
group = []
for line in lines:
if line.strip() == "":
groups.append(group[:])
group = []
continue
group.append(line)
if group:
groups.append(g... | 2237e063de3608486b4e1ef11ec8af250465977b | 75,113 |
def _spark_calc_values_chunk(points):
"""
Compute some basic information about the chunk points values
The returned information are :
* count : the number of points in chunk
* max : the maximum value in chunk
* min : the minimum value in chunk
* sum : the sum of the values in chunk
* sq... | 04dd208038bf1df0172b821943337533f9759291 | 75,114 |
import yaml
def _load_yaml(config_path, logger=None):
"""Load config yaml file
Args:
config_path (str): the path of config yaml.
logger (logging.Logger): the logger object to store logs.
Returns:
dict: config, a dictionary of configs.
"""
try:
with open(config_pat... | 10be02369d28ad3854ab91584376baedf1b2ee94 | 75,115 |
def get_country_key(my_lang):
"""
Country keys
:param my_lang: my_lang language name as String
:return: country_key
"""
if my_lang == "Finnish":
country_key = "fi-FI,en-US"
elif my_lang == "English":
country_key = "en-US,fi-FI"
elif my_lang == "French":
country_k... | 6548e442764b60291a804808761017fa02b3c569 | 75,121 |
def get_paths_for_object(paths, object):
"""
returns a list of paths starting with the given object
"""
paths_for_object = []
for path in paths:
if path.startswith('/' + object + '/'):
paths_for_object.append(path)
return paths_for_object | 04a0c7381cdafe11c4d48d1097409b926e7d5306 | 75,122 |
def print_msg_closure(msg: str):
"""
Closure function that returns a function that prints a message.
:param str msg: Message to attach to print function.
"""
def printer():
print(msg)
return printer | 4f142de4f7d2102269328641e443ae408171fe4e | 75,123 |
def make_response(request, code, data=None):
"""Make response based on passed request, status code and data."""
return {
'action': request.get('action'),
'time': request.get('time'),
'data': data,
'code': code,
} | f321341766011a19dc219021b577715d8312c67a | 75,125 |
def get_sample(name, gender):
""" Get the features of an input sample.
The method takes a training sample as input and computes the following 4 features from every name:
- Ends with A
- Frequency of A
- Ends with E
- Second from last character is N
Args
name: name of a person
gender: The label corresp... | f75be1f4b186ef7be21b0d3061eccb1f2d65a8a8 | 75,129 |
import logging
def getLowerTabs(bookYaml):
"""Gets the lower tabs from a parsed book.yaml dictionary.
Args:
bookYaml: the parsed book.yaml file
Returns:
An array of objects with the lower tabs
"""
result = []
try:
for tab in bookYaml['upper_tabs']:
if 'lower_tabs' in tab and 'other... | 139d9830a488f2822612c4eb09f0b0c5f20bc566 | 75,142 |
def tabular_tex(
body_df,
footer_df,
notes_tex,
render_options,
custom_index_names,
custom_model_names,
left_decimals,
sig_digits,
show_footer,
):
"""Return estimation table in LaTeX format as string.
Args:
body_df (pandas.DataFrame): the processed dataframe with par... | 5858b6334f33cf68bbd737a15117fec6e16c1c76 | 75,143 |
def get_id2label(labels):
"""
Get id2label mapping based on labels
Args:
labels: list of labels.
Return:
id2label map
"""
return {str(k): v for k, v in enumerate(labels)} | 664ed43c17bed4af72d4a2b7c3f61e3e33e0e66b | 75,145 |
from typing import List
def reduce(grouped_data: List[str]) -> List[str]:
"""
Reduces the grouped data to a single list with no whitespace
"""
return ["".join(set(entry.replace(" ", ""))) for entry in grouped_data] | b15f3cad105b15aded0c48897b41c6de9c5d1017 | 75,146 |
def is_protected(file_name, regex_list):
"""
Given a list of compiled regexes, verify if a filename matches and thus,
is "protected" from being deleted
"""
for regex in regex_list:
if regex.search(file_name):
return True
# Fall through to false
return False | 351f09fa5ee4ee7e38012d33a2fc9b275c8fc29c | 75,147 |
import socket
def ip6_to_bytes(ip):
"""Convert IPv6 string to :py:class:`bytes`
:param ip: IPv6 in dot-decimal notation
:type ip: str
:rtype: bytes
"""
return socket.inet_pton(socket.AF_INET6, ip) | 24ccd6f60707813e515d6f2d6565b75f74950d46 | 75,149 |
def get_chain(struct, chain_id='A'):
"""Returns a specific chain from a Bio.PDB.Structure.Structure."""
return struct.child_list[0].child_dict[chain_id] | 9c20309bd5e5d768e2465e13ca4cfa6207141578 | 75,152 |
import json
import requests
def find_most_recent_tag_dockerhub(name, url):
"""Find most recent tag of an image from Docker Hub
Arguments:
name {str} -- Name of the image
url {str} -- API URL of the Docker Hub image repository
Returns:
new_tag {str} -- Most recent image tag from D... | 4b03dd1d20b252a36ad5b01f44bb9cacce041155 | 75,156 |
def scorefunction(tree, dataset):
"""
This function checks every row in dataset, calculating the output from the function
and comparing it to the real result. It adds up all the diffences, giving lower
values for better programs.
Return value 0 indicates that the program got every result correct
... | e5a6e392760952a5e00a26c2913f7802ab6d1336 | 75,160 |
def is_conf_setter(f):
"""
Decorator for functions that set :py:data:`~lrms.common.Config` attributes.
"""
f.is_conf_setter = True
return f | 019cfb3a4a392fa7906e62a05c8fc40b99dd78e6 | 75,164 |
def flatten(nl):
"""Flattens a nested list/tuple/set, returns list"""
if isinstance(nl, (tuple, set)):
nl = list(nl)
# noinspection PySimplifyBooleanCheck
if nl == []: # don't change this
return nl
if isinstance(nl[0], (list, tuple, set)):
return flatten(list(nl)[0]) + fla... | 1f383815cf55b0e3ff59465e6e8e2248e074dca7 | 75,165 |
def _get_azure_file_url(cli_ctx, account_name, azure_file_share):
"""Returns Azure File URL for the given account
:param str account_name: account name
:param str azure_file_share: name of the share
:return str: Azure File URL to be used in mount volumes
"""
return 'https://{0}.file.{1}/{2}'.fo... | 40098eb8d4eb9d584c0b3ef0390c98b6537ec12b | 75,166 |
def deleteTagValue(fluiddb, objectId, path):
"""
Deletes a tag from an object.
"""
return fluiddb.objects[objectId][path].delete() | f966d038314b6966a451a3277e298ce2908a5962 | 75,167 |
def map_freqs(s):
"""
s é uma string não-vazia de caracteres
Retorna um dicionário que mapeia cada caractere em s que
é um dígito (0-9) ao número de vezes que ele ocorre em s.
"""
d = {}
for char in s:
if char.isdigit():
if char not in d:
d[char] = 1
... | 08150866dcb45e758cab9c0761061e14eba3fc76 | 75,171 |
def on_site(domain: str) -> str:
"""
Restrict search to a specific domain.
Can be repeated to restrict search on multiple sites.
:param domain: Domain name
:return: String in the format google understands
"""
return "site:{}".format(domain) | 43f81b2acf1426fcd303f3b7723bc95a59c9474e | 75,175 |
def rotate(string, n):
"""Rotate characters in a string.
Expects string and n (int) for number of characters to move.
"""
pref: str = ''
suf: str = ''
for pos in range(len(string)):
if n < 0:
if (len(string) + n) <= pos:
pref += string[pos]
els... | f1f1d0d14106996648dcc88239dde5e2520506e8 | 75,176 |
from typing import Optional
import requests
import json
def authenticate_username(
token: str,
github_api: str = 'https://api.github.com/graphql') -> Optional[str]:
"""Check that the token correspond to a valid GitHub username.
Using `GitHub GraphQL API v4 <https://developer.github.com/v4/>`... | b8ba4b3fb2e42c27b474d364f37c6c7086450401 | 75,177 |
import json
def get_json(s):
"""
Parse JSON from string.
"""
try:
return json.loads(s)
except ValueError:
return None | f09b4913f5373831eb157a07f615ba2068d5a19a | 75,178 |
from functools import reduce
def pipe(*funcs):
"""Performs left-to-right function composition. The leftmost function may have
any arity; the remaining functions must be unary.
In some libraries this function is named sequence.
Note: The result of pipe is not automatically curried"""
return lambda ... | 0f9884dac25a1d60ac54925d314c2c38f8a0c18a | 75,179 |
def xy(v0x=2.0, v0y=5.0, t=0.6):
"""Computes horizontal and vertical positions at time t"""
g = 9.81 # acceleration of gravity
return v0x*t, v0y*t - 0.5*g*t**2 | 87abba7e5414bb0966c1e423a04f5216126013b8 | 75,181 |
def has_regular_python_ext(file_name):
"""Does name end with .py?"""
return file_name.endswith(".py")
# Note that the standard library on MacOS X 10.6 is shipped only as .pyc files, so we need to
# have them processed by the generator in order to have any code insight for the standard library. | 01c3d02e3f9e2c1158f2fc3d5df7749a43f42f3a | 75,183 |
import csv
def find_unique(annotations: str) -> dict:
"""
find_unique will loop through the annotations csv, and generate a dictionary which contains
the unique images, and all associated rows. This is neccesary as the csv sometimes contains
multiple entries for an image, specifically when an image ha... | 387871929bc7244af5cc1f5c1bba60eb92cf0dbe | 75,184 |
def build_path(pattern, keys):
"""Replace placeholders in `pattern` to build path to be scraped.
`pattern` will be a string like "measure/%(measure)s/ccg/%(entity_code)s/".
"""
substitutions = {
"practice_code": "L83100",
"ccg_code": "15N",
"stp_code": "E54000037",
"reg... | 64e72a758ba4cb9c7f850cbc44e031e2bf2d9125 | 75,189 |
def is_prime(n):
"""Returns if the given number is a prime number or not
>>> is_prime(10)
False
>>> is_prime(7)
True
"""
"""BEGIN PROBLEM 1.4"""
if n in [2, 3]: # shortcut for if n equals 2 or 3
return True
if n % 2 == 0 or n < 2: # skip even numbers, since they are not prim... | b0f54c17621dd02e1494cb90685cd2cde5651961 | 75,192 |
def iou(box1, box2):
"""Intersection over Union value."""
# Intersection rectangle
intersect_x1 = max(box1[0], box2[0])
intersect_y1 = max(box1[1], box2[1])
intersect_x2 = min(box1[2], box2[2])
intersect_y2 = min(box1[3], box2[3])
# Area of intersection rectangle
if intersect_x1 >= inte... | 0783079dfa3c4134d7e6e2083f35b327a2b891f6 | 75,197 |
def passthru_loader(data, metadata):
"""A loader that leaves the data unchanged."""
return data | cfaf9c38fb59d39c187ed3578a33ecd3600b4d98 | 75,203 |
def formatContexts(contexts, declaration=True):
"""Given a list of context type names, generate a list of declarations
for them as formal parameters (if 'declaration' is true), or
as arguments to a function (if 'declaration' is false).
"""
if declaration:
s = "".join(", const {0}_t *{0... | 089a4b44f45bd3e218eaeaa40279d8a83a954af1 | 75,205 |
def get_url(usr):
""" Returns Anime List URL """
return 'https://myanimelist.net/animelist/{}'.format(usr) | 6225893a6f4006c12bbcbf48e650c42a999ad687 | 75,212 |
import io
import csv
def radio_id_csv() -> io.StringIO:
"""
Generates a placeholder RadioIDList.csv
"""
header = ["No.", "Radio ID", "Name"]
sio = io.StringIO()
writer = csv.writer(sio, dialect="d878uvii")
writer.writerow(header)
placeholder_radio_id = ("1", "268000", "CT0ZZZ")
... | 05aceba61149238e0734618eaf3ae8f59adbf8ab | 75,229 |
import pathlib
def load_fixture(name):
"""Load a fixture."""
return (pathlib.Path(__file__).parent / "fixtures" / name).read_text() | 41065de1fa3c3f0b5803ecd804db01fec6c354fb | 75,232 |
import pkg_resources
def find_and_insert_user_refstate(entry_point_plugin_name='espei.reference_states', namespace=globals()):
"""Discover user reference states entered as a setuptools entry_point
Parameters
----------
entry_point_plugin_name : str
Name of the key in the setuptools.setup entry_points d... | 408d5ea4574e5e55ad4157d9ff833cf4fec6394b | 75,243 |
def addr(idx: int) -> str:
"""
Return an IP address for a given node index
"""
return '10.0.0.%d' % idx | 2ff0d2f0a81dc1eb1a6d5690cdfecef1e5cb78d0 | 75,244 |
def pythagorus(num1, num2=0):
"""
### Description:
Calculates the root-sum-of-square of two numbers
### Args:
`num1`: The first number
`num2`: The second number, default `0`
### Returns:
The result of the **pythagorus** formula
$$dist = \\sqrt {... | 9258d876cbce37aa4c7f5e489871b2238c12d497 | 75,246 |
def hz2khz(frequency_in_hz):
"""Convert from Hz to kHz
Args:
frequency_in_hz: A float containing the frequency value in Hz
that is to be converted.
Return:
The frequency in kHz.
"""
return frequency_in_hz / 1000 | 178de0b7562e5155f65757dadbbf954ff64ac278 | 75,249 |
def filter_threshold(tf1_scores, tf2_scores, pref_scores, tf1_threshold, tf2_threshold):
"""
Filters scores in a preferences bed file by the following rules
- if tf1_score < tf1_threshold and tf2_score < tf2_threshold, None
- if pref_score > 0.0 and tf1_score > tf1_threshold, include
- if pref_score... | 900a8b5c1c41e638303f0f96b89dc4e32de84512 | 75,253 |
def get_short_url(short_id):
"""Returns a short_url for a given short_id."""
base_url = 'http://buscatextual.cnpq.br/buscatextual/'\
'visualizacv.do?id='
return base_url + str(short_id) | 38c49e43de52775ee411f5f9c8526ee9326d045a | 75,256 |
def dim_transform_inv(dims, mean=None, std=None):
""" Unnormalizes (usually regression results) to get predicted dims.
The mean and std are the mean and std as applied in the generator. They are unnormalized in this function and then applied to the dims.
Args
dims : np.array of shape (B, N, 3*... | 76a9590f619bbe767fa8324d0f945c37f081147d | 75,262 |
def diff(x):
"""Takes a list and returns a list of differences"""
diff_x = []
for a1 in x:
for b1 in x:
diff_x.append(a1 - b1)
return diff_x | da0055a1a3b272a3c1355820ca4d9fbd5d814f0e | 75,264 |
import re
def replace_table_name_with_query(table_name: str, table_query: str, original_query: str):
"""
Replaces the table_name with the table_query in the original_query.
"""
regular_expression = r" ?`?rj-smtr.*{}`? ?".format(table_name)
find_counts = len(re.findall(regular_expression, original_... | 31ee8b69499a3626fe5062451ae4d3466090d7ce | 75,267 |
def filter_output_fields(configs):
"""Remove fields that are not required by CloudWatch agent config file."""
desired_keys = ["log_stream_name", "file_path", "timestamp_format", "log_group_name"]
return [{desired_key: config[desired_key] for desired_key in desired_keys} for config in configs] | 0ac5f68799f4170becf88049f4608da02bda6a56 | 75,269 |
async def remove_level_role(bot, guild_id, level):
"""Remove a level role"""
level_role = await bot.level_db.fetch_one(
"SELECT * FROM leveling_roles WHERE guild_id=:guild_id AND level=:level",
{"guild_id": guild_id, "level": level},
)
if not level_role:
return f"No level role f... | 129495ffd5a0be426747395f74f6a19293592aa1 | 75,273 |
def append(data, value):
"""Append value to list
:param data: Data to append to, in list form
:param value: Value to append
:returns: List
"""
data.append(value)
return data | db9a9030dca80aecd10fb7e6fb2e6673a73298ae | 75,274 |
def apply_if_callable(maybe_callable, obj, **kwargs):
"""
Evaluate possibly callable input using obj and kwargs if it is callable,
otherwise return as it is.
Parameters
----------
maybe_callable : possibly a callable
obj : NDFrame
**kwargs
"""
if callable(maybe_callable):
... | 08bf973e22c34235fccfbb1d8728b23a0d8efbc9 | 75,276 |
def clarke_error_zone_detailed(act, pred):
"""
This function outputs the Clarke Error Grid region (encoded as integer)
for a combination of actual and predicted value
Based on 'Evaluating clinical accuracy of systems for self-monitoring of blood glucose':
https://care.diabetesjournals.org/content/1... | 83ddd6d5df4515c274cc4fa919a8716d6d08d4e6 | 75,278 |
def summary(task):
"""Given an ImportTask, produce a short string identifying the
object.
"""
if task.is_album:
return u'Album {1} by artist: {0}'.format(
task.cur_artist or 'Unknown', task.cur_album or 'Unknown'
)
else:
return u'Track {1} by artist: {0}'.format(
... | 601e988cc45686284e26ab849519e4cf608edfa4 | 75,282 |
import requests
def auth(
username=None, password=None, apikey=None, refresh_token=None, iam_endpoint=None
):
"""
Makes a authentication request to the IAM API to retrieve an IAM token and
IAM Refresh token.
:param username: Username
:param password: Password
:param apikey: IBMCloud/Bluem... | 35147496500f80860a0066fed4a4b3a811fa2763 | 75,285 |
def vec3_to_list(vec):
"""
Converts an indexable structure with len >= 3 to a list containing the first three elements.
:type vec: iterable
:rtype: list
"""
return [vec[0], vec[1], vec[2]] | a0834c6e25b6a7517ab8fc2af30b78c4bb155ae3 | 75,286 |
def makeRecordClass(db,record_class,field_names):
"""Generate a subclass of record_class, specifying a Base instance
and a list of field names and types"""
class _Record(record_class):
pass
setattr(_Record,'db',db)
setattr(_Record,'fields',list(field_names))
setattr(_Record,'types',[ ... | b03d1d44632633025b4a64dec37c36d88114b647 | 75,288 |
def dis_to_nearest_gene(region, genes, distance_cutoff=10000):
"""Compute the distance of a specified region to the nearest gene TSS.
Parameters
----------
region : GenomicRegion
GenomicRegion object.
genes : list
List of genes on that chromosome.
distance_cutoff : int
... | 41f6d9ab2a0c730698d6abf8455a9bc6791d84cd | 75,295 |
from pathlib import Path
def get_version() -> str:
"""
Get the version of a2j.
:return: Version of a2j.
:rtype: str
"""
# OPEN VERSION FILE
with open(Path.cwd() / "VERSION", "r") as file:
# READ VERSION FROM FILE
version = file.read().strip()
# CLOSE FILE
... | c8e508e6230a205221844cb8c1e891e6f7c51bf5 | 75,296 |
from typing import List
def find_substr_in_list(
substr: str, strs: List[str], start_pos: int = 0, exact: bool = False
) -> int:
"""Find a specific substring within the given list of strings,
starting from a given position."""
for i, s in enumerate(strs):
if i < start_pos:
continue... | 7f6348b3c39523171839bf2c62f6be2d66db0b40 | 75,301 |
def split_factory2(delimiter: str = ',', cast_to: type = list):
"""
Separates a text by a specific delimiter into separate sub-lists.
Returns a FUNCTION that can then process the text accordingly.
It DOES NOT ignore whitespaces.
*-------------------------------------------------------------*
E... | 3e5683a751ecde8768d6b8b0ecb3ad37c0effe60 | 75,304 |
def get_rc(re):
"""
Return the reverse complement of a DNA/RNA RE.
"""
return re.translate(str.maketrans('ACGTURYKMBVDHSWN', 'TGCAAYRMKVBHDSWN'))[::-1] | 2889d242ad8d3218a66ec52e7f22f00bc2aeff77 | 75,316 |
def is_weekend(d_or_dt):
"""Check if a datetime is weekend.
"""
return d_or_dt.isoweekday() in [6, 7] | e495543b5c4f25fedcbfb785445a27699e94d6a9 | 75,317 |
def _flat(commands):
"""Flatten commands while preserving order"""
commands = [cmd for cmd in commands if cmd is not None]
flattened = []
for command in commands:
if isinstance(command, str):
flattened.append(command)
elif isinstance(command, list):
flattened.exte... | bb53b112a89ae60ad5afee075df3a2baf39c7ad7 | 75,318 |
def get_dict_val(dictionary: dict, key_list: list = []):
"""
Return `dictionary` value at the end of the key path provided
in `key_list`.
Indicate what value to return based on the key_list provided.
For example, from left to right, each string in the key_list
indicates another nested level fur... | 4bcff4d35e81a34ff23f47e5311de5b4985743af | 75,319 |
def det_to_sci(image, detid):
"""Detector to science orientation
Reorient image from detector coordinates to 'sci' coordinate system.
This places +V3 up and +V2 to the LEFT. Detector pixel (0,0) is assumed
to be in the bottom left. Simply performs axes flips.
Parameters
----------
... | 32f36c76cffc01e1edcd086722eff949489b756e | 75,322 |
def num_labeled_samples(y, y_pred):
"""
Get the number of labeled samples for a given set of model predictions
Arguments:
- y: label array
- y_pred: array of label predictions for which ground truth is known
Returns:
- num_labeled_samples: number of labeled samples for a given... | 4944042bdb45f698a1ae30b28ea6707c34685af7 | 75,324 |
def clean_list(data_list: list) -> list:
"""Returns a list with any none values removed
Args:
data_list (list): The list to be cleaned
Returns (list): The list cleaned of None values.
"""
return list(filter(None, data_list)) | ec329fcaf25ef8f84479519ac7b79c0f51e8e625 | 75,326 |
def _bool_argument(s: str):
"""
Parse an argument that should be a bool
"""
if isinstance(s, bool):
return s
# Copying FastAPI booleans:
# https://fastapi.tiangolo.com/tutorial/query-params
return s.strip().lower() in ("1", "true", "on", "yes") | 5012ca6cde89c6c662e96fca2d4eefb23f5fd5e3 | 75,327 |
import importlib
def import_string(import_name: str):
"""
Import an object based on the import string.
Separate module name from the object name with ":". For example,
"linuguee_api.downloaders:HTTPXDownloader"
"""
if ":" not in import_name:
raise RuntimeError(
f'{import_n... | af3d9014acb99c359bf5c313075a163096f1bd2e | 75,328 |
import json
def SendRequestToServer(url, http_client, post_data=None):
"""Sends GET/POST request to arbitrary url and returns response content.
Args:
url (str): The url to send the request to.
http_client (HttpClient): The httpclient object with which to make the
server calls.
post_data (dict):... | 0b8aa1dc734a5d4a27f26e145749f1dcb4c38b8d | 75,329 |
def span(data, **kwargs):
"""
Compute the difference of largest and smallest data point.
"""
return max(data) - min(data) | 885cb57cc337c3ed19137da601d43a0ce0f0b750 | 75,330 |
def avgFriendDegree(v, G):
""" Calculate the average degree of the neighbors of a node"""
degSum = 0
for u in G.neighbors(v):
degSum += G.degree(u)
return degSum / G.degree(v) | 436466406f6ee61c452f410112881af51c93ceed | 75,336 |
def cwt_synthesis(wavelet_matrix, mean = 0):
"""Synthesizing a signal given a wavelet dataset
Parameters
----------
wavelet_matrix: ndarray
The wavelet data matrix.
mean: float
The mean to translate the signal.
Returns
-------
arraylike
The generated signal
""... | 62ecc30a190dd5be0b03406ef839ceb3f09ba647 | 75,344 |
def stripiter(target: list):
"""Striping all of texts in list."""
out = []
for txt in target:
out.append(
str(txt)
.rstrip()
.lstrip()
)
return out | 440ce39a3027e3bebff7fec12b10761742dbc075 | 75,345 |
import re
def get_pattern(delimiter, s):
"""
Get the pattern info between delimiters from the string
"""
regex = "%s(.*?)%s" % (delimiter, delimiter)
return re.findall(regex, s) | 9233549de43a9c7d8d19240d0eaf7076fc9ce5a8 | 75,349 |
import torch
def dbbox2roi(dbbox_list):
"""
Convert a list of dbboxes to droi format.
:param dbbox_list: (list[Tensor]): a list of dbboxes corresponding to a batch of images
:return: Tensor: shape (n, 6) [batch_ind, x_ctr, y_ctr, w, h, angle]
"""
drois_list = []
for img_id, dbboxes in enum... | d4dbe984d814ec5b68ec4269d03bd8c907c83ba3 | 75,350 |
def find_n_kickers(cards, used, n):
"""
Finds the top n kickers that are not already used.
Args:
cards(list(str)): A list of card strings sorted by ordinal value.
used(set(str)): A set of strings that have been used.
n(int): The number of cards to find.
Returns:
list(st... | ec58bba8f791ff3f87ecbda336edefc999007892 | 75,351 |
def get_git_repo_name_from_url(url: str) -> str:
"""
Get the git repository name from the url
:param url: The git repository url (either https or ssh)
:return: The repository name
"""
git_repo_name = url.split("/")[-1]
return git_repo_name.split(".git")[0] | b85b6473c814f88ce62d5bd0beb7fa6ff92a4a2c | 75,353 |
def _consume_single_get(response_iterator):
"""Consume a gRPC stream that should contain a single response.
The stream will correspond to a ``BatchGetDocuments`` request made
for a single document.
Args:
response_iterator (~google.cloud.exceptions.GrpcRendezvous): A
streaming itera... | 34e7d1226ac09423c29c9e22972c2ec4e8b34635 | 75,361 |
def index_date_formatter(base, date):
"""
Returns a time based index representation for the given base, date
:param str base: the index's base name
:param datetime.datetime date:the date to format the index for
:rtype: str
:return: the index representation for the given date
"""
return '... | 44d966e4c2170665e666dfe8934e681bc0cbc05a | 75,362 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.