content stringlengths 35 416k | sha1 stringlengths 40 40 | id int64 0 710k |
|---|---|---|
def joblib_cache(ds,
dirname,
version,
numpy_keys=None,
mmap_mode=None,
eager=True):
"""
chunks data together, converting values in `keys` into numpy arrays,
(for more efficient storage) then dechunks them afterwards
d... | b41ddc35d53dd82d5614e4c4aea0db26c25b1e42 | 29,716 |
def find_in_reference_list(reference_list, source_name):
"""Check if it is already in reference list"""
for reference in reference_list:
if reference['sname'] == source_name:
return True
return False | 09769d77724ba58d41b54ef0b182e110f606161e | 29,717 |
import numpy
def _subset_xy_grid_for_interp(
field_matrix, grid_point_x_coords_metres, grid_point_y_coords_metres,
query_x_coords_metres, query_y_coords_metres):
"""Subsets x-y grid before interpolation.
Interpolation will be done from the x-y grid to the query points.
M = number of rows... | 112261e863a8afda6c5baa7cc63b7a9e36b64fe8 | 29,719 |
import numpy
def npmedian(x):
"""Numpy Library Median"""
return numpy.median(x) | 4aa37d3c149cb4fa326aa963ef9813547975b00f | 29,720 |
def canonicalize(data):
"""Restructure to preferred TCZYX or CZYX form..."""
data = data.transpose(*[d for d in map(data.axes.find, 'TCIZYX') if d >= 0])
projection = []
if 'T' in data.axes and data.shape[0] == 1:
projection.append(0) # remove trivial T dimension
if 'C' not in data.axes:
... | d61b4e87be5e78ba96e0d15536674ed58dff32b4 | 29,721 |
def upper(input_string: str) -> str:
"""Convert the complete string to uppercase."""
return input_string.upper() | 9acbac80cf1de15a1b21f4413d75e91e171c6c3f | 29,722 |
import traceback
def tryExcept(myFunction):
""" A decorator the surrounds the inner function with a try/except
EXAMPLE USE
@tryExcept
def fragileFunction():
pass
"""
def wrapper(*args, **kwargs):
try:
return myFunction(*args, **kwargs)
except Exception as error:
traceback.print_exception(type(e... | 9cd6275f785886dfbc840541c765d6a274bb9143 | 29,723 |
def auth_set(hashed_sks, auth_set_indices, height, hashfun):
"""Return the authentication set defined by the given indices.
Keyword arguments:
hashed_sks -- the hased secret key components which form the
leaves of the tree
auth_set_indices -- A list of tuples (h, i) defini... | 0f4565d4aa399ab534a962b6f3ec89fb3325cdb5 | 29,725 |
def _var_names(self):
""" Covers more activations than act_names """
predictor = self
predictor.retain(True)
x = self.xp.random.randn(16,3,32,32).astype('f')
#t = self.xp.random.randint(0,1, size=(16,))
#loss = self(x, t)
loss = self(x)
names = [name for name,_ in predictor.namedvars()]
... | eed797a5865bd3625156ea8c0474c5ccf0f40f0b | 29,726 |
import subprocess
def git(*args, err_ok=False, stderr_to_stdout=False):
"""Runs a git command, returning the output."""
stderr = subprocess.DEVNULL if err_ok else None
stderr = subprocess.STDOUT if stderr_to_stdout else stderr
try:
return (
subprocess.check_output(["git"] + list(ar... | b905f1a6cd5d081785fbb897a89a59e4d544a47f | 29,727 |
def read_credentials(filepath='.yelp/credentials'):
"""Read credential file and return dictionary of important information"""
with open(filepath, 'r') as f:
contents = f.readlines()
credentials = {}
key_items = ['client_id', 'api_key']
for line in contents:
for item in key_items:
... | 998ab1a770fb2c819757869772214fad89c7e13a | 29,728 |
def get_ns(tag):
"""
Extract namespace.
This function is opposite to get_local_name, in that
it returns the first part of the tag: the namespace.
Parameters
----------
tag : str
Tag to process.
"""
p_open = tag.find('{')
p_close = tag.find('}... | d10d1e8d2a0a89d5aadd9fd4bf509a0e6e49d49e | 29,729 |
import ast
def convert_types_in_dict(xml_dict):
"""
Evaluates all dictionary entries into Python literal structure, as dictionary read from XML file is always string.
If value can not be converted it passed as it is.
:param xml_dict: Dict - Dictionary of XML entries
:return: Dict - Dictionary with... | 88e0030c2e1612802fd13c46c4ba6d7a1a2f8885 | 29,730 |
import os
def get_access_token(sandbox=False):
"""get upload key, strip white space."""
if sandbox:
return open(os.path.join(os.environ["HOME"], ".sandbox_id"), "r").read().strip()
else:
return open(os.path.join(os.environ["HOME"], ".zenodo_id"), "r").read().strip() | 7c8a61823120058674cf183d213f45810b89ca2c | 29,731 |
import os
def dir_from_path(path):
"""If path is file address. Strip file name and retrieve dir directory"""
if not os.path.isdir(path):
path = os.path.dirname(path)
return path | 05fa4d99d623d11f532d181ff0bad2ea1a05db4e | 29,732 |
def nvmf_set_max_subsystems(client,
max_subsystems=None):
"""Set NVMe-oF target options.
Args:
max_subsystems: Maximum number of NVMe-oF subsystems (e.g. 1024)
Returns:
True or False
"""
params = {}
params['max_subsystems'] = max_subsystems
retu... | 5c41028b040f055c2ba2fea8dec05e1744f46310 | 29,734 |
def get_parameters(parameters):
"""
Gives confidence and support, also if not given in parameters
"""
confidence = parameters.get("min_confidence", 0.75)
support = parameters.get("min_support", 2)
return confidence, support | e619fca63833651b1625a45ae2cfda806d227cd1 | 29,735 |
import os
def format_stacktrace(stack):
"""Print a stack trace that is easier to read.
* Reduce paths to basename component
* Truncates the part of the stack after the check failure
"""
lines = []
for _, f in enumerate(stack):
fname = os.path.basename(f[0])
line = "\t%s:%d\t%s... | 3868ae40e81fc9867c11132f97630ae4c058851b | 29,736 |
import math
def ZScore_GeneGo(n, N, n1, n2):
"""Each subnetwork is associated with a Z-score which ranks the subnetworks according to saturation with the objects from the initial gene list. The Z-score ranks the subnetworks of the analyze network algorithm with regard to their saturation with genes from the exper... | 92c8a46ffad5a3e218c45826423fa3ee31e4fee5 | 29,737 |
import functools
def to_pagination():
"""Decorator to convert the result query into a pagination object.
:return: Decorated function
:rtype: fun
"""
def decorator_add_sorting(func):
@functools.wraps(func)
def decorator(*args, **kwargs):
"""Converts the query into a pag... | 112021416a82735ef9af7f149cd959f2d3fbe004 | 29,740 |
from time import perf_counter
from time import time
def timer():
"""Multiplying is done o return millis and keep backwards compatibility.
"""
try:
return int(round(perf_counter() * 1000))
except ImportError:
return int(round(time() * 1000)) | 7420b19387147cc2d1ba20ccbb0dbe97160dd6f2 | 29,743 |
def returns(k, df):
"""
Computes the log returns over a k-day period
Arguments:
k -- window size
df -- yahoo finance dataframe
Returns:
Log returns over a day period
"""
return ((df.open / df.adj_close.shift(k)) - 1) * 100 | 1190ec7bd6b366049caebde7ec180343d6f96a9d | 29,744 |
def read_acl_file(filename):
"""Read contents of given acl file.
Args:
filename: name of file to be read for acl information
Returns:
list: list containing ACL entries
"""
f = open(filename, 'r')
content = f.readlines()
f.close()
# Parse
acl = []
for entry in ... | 9fb3e08bc35db72f90ee586f26de2fca04e4a66b | 29,745 |
def is_status_complete(status: str) -> bool:
"""
Check if stack status is running and complete.
"""
return status in ("CREATE_COMPLETE", "UPDATE_COMPLETE") | d134f9ad2c8f106f74aef226abebfeedec381f9f | 29,746 |
import os
def get_version():
"""get the package version from __init__.py
modified from this source: https://packaging.python.org/guides/single-sourcing-package-version/
"""
package_dir = os.path.abspath(os.path.dirname(__file__))
with open(os.path.join(package_dir, "astropaint", "__init__.py"), "r... | 9aa5fe0ab9498aea035b36b6d1c6a1d579e38145 | 29,748 |
import math
def create_tsp_data(rt):
"""Stores the distance matrix for the stops on the route"""
data = {}
data['time_matrix'] = []
row = []
for i in range(len(rt.stop)):
for j in range(len(rt.stop)):
if rt.stop[i].key != rt.stop[j].key:
row.append(int(math.floo... | 0af2a3f3bfe9298992ec7467a93cdeafb711720f | 29,749 |
import random
def next_household_ages(household_list):
"""
:param: complete list of households
:return: randomly select a type of household from a distribution suitable to City,
and return the list of the ages of the people in that household
"""
return random.choice(household_list) | 935ecbda9e0e725bf144b9026041602e0a659658 | 29,750 |
import argparse
def create_arg_parser():
"""Creates argument parser
Returns:
argparse.ArgumentParser: Parser to fetch arguments from terminal
"""
parser = argparse.ArgumentParser(description="Welcome to Homeless Network Server! (run to start server)", prog="HomelessNet")
parser.add_argument('--init', des... | f612c49cff194c0ee79072cc80ca92bb9acd1ee7 | 29,751 |
def multiply(value, arg):
"""
Multiplies the arg and the value
:param value:
:param arg:
:return:
"""
if value:
value = "%s" % value
if type(value) is str and len(value) > 0:
return float(value.replace(",", ".")) * float(arg)
return None | 66b9785dd7f142e1831793662749e74cceb9c93d | 29,752 |
import math
def mapping_options(target_line_angle, step_angle):
"""takes the target line slope angle, and the given rule step angle, and returns the two lines
that intersect at the target line at the step angle"""
# first get base step angle slopes
base = [math.tan(math.radians(step_angle)), math... | 38a97e3616df8046e47c70f2896290ffbc61c072 | 29,753 |
import torch
def create_loss_mask(inp):
"""mask for the loss function"""
mask = torch.all(inp == 0, dim=-1).float()
return mask[:, 1:] | d46f41c5e0e0afa380474b4f6af66eba7a3fec3b | 29,754 |
def root_generator(folder, build, variant="common"):
"""
Generate roots for the SHAxxx hash lookup URLs.
:param folder: Dictionary of variant: loader name pairs.
:type folder: dict(str: str)
:param build: Build to check, 3 letters + 3 numbers.
:type build: str
:param variant: Autoloader v... | 394d824ce1c87eb3ea32d2ce1b0bb3ad72ef648d | 29,755 |
import argparse
def parse_arguments(args_to_parse):
""" Parse CLI arguments """
descr = 'Train a baseline model'
parser = argparse.ArgumentParser(description=descr)
general = parser.add_argument_group('General settings')
general.add_argument('name', type=str, help="The name of the experimental di... | 24dc112cdb8b4ae46a8838c91f30b98355fea47f | 29,759 |
def countDigits(n):
"""Count the number of digits in a given number "n". """
num = len(str(abs(n)))
return num | b8ecf5117f45a425b1bb0ced8b01f209cfdaca20 | 29,763 |
def safe_issubclass(cls, classinfo):
"""As the builtin issubclass, but returns False instead of a TypeError if the first argument is not a class."""
try:
return issubclass(cls, classinfo)
except TypeError: # cls is not actually a class
return False | 4e4218b51824d68a58f7aeca360845bbb12ba40a | 29,764 |
def calculate_aggregates_day_wise(docs_df):
""" Takes a Pandas data frame with index=published_date, cols: num_occurrences and
arxiv_identifier as input, calculates the no. of unique and total occurrences by
grouping by published_date and cacluating the count and sum on the column
num_occurrences. The a... | adf67c53c6366d524bc68ae298472cbff8352091 | 29,765 |
def get_news_url(tweet):
"""
searchs and returns the link in the tweet
Args:
tweet: tweet as tweepy object
Returns:
url if exists
"""
print("Searching for URL in the tweet..")
try:
return tweet.entities.get('urls')[0].get('expanded_url')
except:
print("Url... | b18f6011ca7eae7d114c65ac593d7af03df8390c | 29,768 |
from typing import Optional
def doc_to_doc_string(doc: Optional[str], indent_level: int = 0) -> str:
"""Generate a documentation string from a schema salad doc field."""
lead = " " + " " * indent_level + "* "
if doc:
doc_str = "\n".join([f"{lead}{line}" for line in doc.split("\n")])
else:
... | efd0237f5d39660459e8b736e74ec24bc665ef77 | 29,770 |
def safe_div(x, y):
""" This function divides two numbers and avoids division by zero
:param x: x-value
:param y: y-value
:return: result
"""
if y < 1.e-5:
y = 1.e-5
if x < 1.e-5:
x = 1.e-5
return x / y | 1ce30f2f9f5616d8ff8b4c7f29aad3bcbd51201d | 29,771 |
def get_evinfo(act_ptrn):
"""
[概要]
アクション実行パターン別にテストで使用するイベント情報を返却
[引数]
act_ptrn : 1=OPERATION_ID, 2=SERVER_LIST, 3=MENU_ID
"""
event_info = '{"EVENT_INFO":["mas-pj-dev","httpd"]}'
if act_ptrn == 3:
event_info = '{"EVENT_INFO":["mas-pj-dev","httpd","date"]}'
elif act_ptr... | 8f3cec9d5a085f203f3cde317c7d148686c94f9f | 29,774 |
def roi_corners(roi):
"""
roi_corners = [top_left, top_right, bottom_left, bottom_right]
"""
return [
roi[0],
[roi[1][0], roi[0][1]],
[roi[0][0], roi[1][1]],
roi[1]
] | 9eaef99257411f3e4bb06c21647ee116305e715a | 29,775 |
def unzip(zipped):
"""
Unzip a zipped list
:param list-of-tuple zipped: list of tuples to be disaggregated
:returns: list of tuples
Example
_______
>>> unzip([(1, 2, 3), (4, 5, 6), (7, 8, 9)])
[(1, 4, 7), (2, 5, 8), (3, 6, 9)]
"""
return list(zip(*zipped)) | 0ac5d80574eaeb5e84417dbfed9e617cde60d101 | 29,777 |
def getCollectionKeys(collection):
"""Get a set of keys from a collection"""
keys_list = []
collection_list = collection.find().limit(300) #otherwise pulls all records just to get schema which is bit wasteful. Yea, may miss some field names, but it's good compromise
for document in collection_list:
... | edc02521e87ec40a4731887cb05d0df6afbd2b49 | 29,778 |
def can_manage_content(user, content):
"""
Returns True if user is staff or instructor(owner).
"""
if user.is_authenticated():
owner = user == content.course.owner
if user.is_staff or owner:
return True
return False | bb4d2209155b5df1458f3194737d25a4a9b1a7c3 | 29,779 |
from typing import List
from typing import Tuple
def extract_node_waypt(way_field: List[Tuple[str, str]]) -> int:
"""
Given a list with a reference node such as [('ref', '0')], extract out the lane ID.
Args:
way_field: key and node id pair to extract
Returns:
node_id: unique ID for a n... | 564a738d0fdecb5230b9bb757764f4463dee85e0 | 29,780 |
import functools
import traceback
import sys
def suppress_broken_pipe_msg(f):
"""
When using the CLI as part of a script pipeline, we want to gracefully handle the next command closing the pipe
early (eg head). This is a workaround for the fact that python prints an error message to the console even
... | 752c4b8fc878e2ae2cb735f0e259d703653c7531 | 29,781 |
from typing import List
def create_subdict(data: List):
""" Return data in List form as dictionary,
Start, to which model parameters is appended.
Parameters
-----------
data: List
Data (potentially pca component output in 2d form).
Return
-------
Dict:
D... | 6850588d1b1eeae69265aa1a63377ee2fa759b80 | 29,782 |
def get_suggestion_string(sugg):
"""Return the suggestion list as a string."""
sugg = list(sugg)
return ". Did you mean " + ", ".join(sugg) + "?" if sugg else "" | 7eb93d747818b66f5996241c993fbbe2ab638dd7 | 29,783 |
def str_to_class(s):
"""Alternate helper function to map string class names to module classes."""
lst = s.split(".")
klass = lst[-1]
mod_list = lst[:-1]
module = ".".join(mod_list)
try:
mod = __import__(module)
if hasattr(mod, klass):
return getattr(mod, klass)
... | 7ffd66b1a9032980fdc09fbec86fd914b84d52c7 | 29,785 |
def with_(context, *args):
""":yaql:with
Returns new context object where args are stored with 1-based indexes.
:signature: with([args])
:arg [args]: values to be stored under appropriate numbers $1, $2, ...
:argType [args]: chain of any values
:returnType: context object
.. code::
... | a85dea242ee315e5c238084cc9a563317ddfe976 | 29,786 |
def removeDoubleVertexesAlternative(V):
"""
alternativte removing of doublefaces. Hopefully more memory efficient
"""
X = range(len(V))
# Vs = [v for (v, x) in VIsorted]
# Is = [x for (v, x) in VIsorted]
Vs = []
Is = [0]*len(V)
prevv = None
i = 0
for [v, x] in sorted(zip(V, ... | d9722e481b38bae0703f5f63982e39d5c2364bd0 | 29,787 |
def get_key(text):
"""return keyword: first word of text,
isolating keywords followed by '(' and ':' """
t = text.replace('(', ' (').replace(':', ' :').strip()
return t.split(' ', 1)[0].strip() | e27e76b97e6b9247f24bd62c074787f6d140f688 | 29,788 |
def solution_two(numbers: list[int]) -> list[int]:
"""
timeComplexity: BigO(2n)
spaceComplexity: BigO(n)
"""
total = 1
for n in numbers:
total *= n
result = []
for n in numbers:
result.append(total // n)
return result | ceba8dddf112299b9856b2099fa6f679db28f225 | 29,789 |
from typing import Union
from typing import List
def read_file(file_path: str, split: bool = False) -> Union[str, List[str]]:
"""
Reads a text file.
>>> from snakypy import helpers
>>> file = '/tmp/my_file.txt'
>>> helpers.files.create_file('My content file', file, force=True)
True
>>> he... | af2429f9d696a693b89c0fa33200e453906ee0c8 | 29,791 |
def max_sublist(a_list):
""" Kadane's Algorithm
>>> max_sublist([-2, 1, -3, 4, -1, 2, 1, -5, 4])
(6, 3, 6)
>>> max_sublist([0, -1, 2,- 3, 5, 9, -5, 10])
(19, 4, 7)
:param a_list: The list to get the maximum sub-list for.
:return: The sum from the sublist, the start index, and the end index.... | e535a182e0a0118395dfd6f6e130a42d3c4b051f | 29,795 |
import random
def generate_social_security_number():
"""Randomly generate a social security number.
For example: '234 78 9012'
Update to reflect state, date of birth info
consider: http://www.pnas.org/content/106/27/10975.full.pdf
"""
number1 = random.randint(1,999)
assert number1 > 0
... | 4bdef47477dae586683ad7a2487ca09852baf57b | 29,796 |
def get_fold(dict_actors_per_fold, actor_id):
"""
Get the fold that the actor belongs to.
:param dict_actors_per_fold[dict] Map with the fold number as key (ranging from 1 to 5) and the list of actors in that test fold as the value of the dict.
:param actor_id:[int] Id of the actor. W... | 0b5543ed37cd4fc8bed84a7f269fca04a5d71d01 | 29,797 |
def getModel(tsinput):
"""
This is the wrapper function for all turbulence models implemented
in the runInput package.
Parameters
----------
tsinput : :class:`tscfg <.base.tscfg>`
A TurbSim input object.
Returns
-------
specModel : A subclass of :class:`.sp... | c745ca7127b92f47aa13e2965b37f7d57dd6d588 | 29,798 |
def filter_cov_id(pid, cov, *df):
"""Filters the passed dataframe, returning only rows that meet
passed percentage identity and coverage criteria.
"""
return tuple([d[(d.percentage_identity > pid) & (d.query_coverage > cov) &
(d.subject_coverage > cov)] for d in df]) | 7373d1c3d54e219cbcc1c307fd9808d924fc3ae2 | 29,800 |
def intToBinaryString(integer : int) -> str:
"""Convert an integer to a string representing a big endian binary number
Parameters
----------
integer : int
A positive integer
Returns
-------
str
A string representing a big endian binary number
"""
rtn = ""
while ... | 5f0d3aba71c7fffaa14725fef0576b72ae17b461 | 29,803 |
def dista10(n):
"""
seja um inteiro n
retorna True se a diferença absoluta entre n e 100 ou n e 200
for menor ou igual a 10
dista10(93) -> True
dista10(90) -> True
dista10(89) -> False
"""
if abs(n - 100) <= 10 or abs(n - 200) <= 10:
return True
return False | f575451e55a511c436fe3c70c915c3cddc98ddd9 | 29,804 |
def filter_capabilities_by_languages(bears, languages):
"""
Filters the bears capabilities by languages.
:param bears: Dictionary with sections as keys and list of bears as
values.
:param languages: Languages that bears are being filtered on.
:return: New ... | 3f5661f6d72579b0fcd8ce5b6e055f0fefce3dcc | 29,806 |
import os
def get_config_folders():
"""Read folder config from environment"""
folders = []
for env_key, env_val in os.environ.items():
if env_key.startswith('FOLDER_'):
folder_id = env_key.split('_', 1)[1]
folder_name = env_val
folder_extension = os.getenv(f'EXT... | d18952397fabcad11eac26c9ba28ee3de9ffbd31 | 29,807 |
import os
def filename_maker(name: str, path: str, start_date, end_date) -> str:
"""
Create the name of the main files
Returns:
String with the path to save the file.
"""
return os.path.join(path, name + start_date.replace('-','') + '_' + end_date.replace('-','')) | 996683de49edb626f5d2974da3af26030ca6eb46 | 29,809 |
def convert_aa_code(three_letter, convert):
"""
Assumes a string that contains a three letter aminoacid code and
returns the corresponding one letter code.
"""
aa_code = {
'CYS': 'C',
'ASP': 'D',
'SER': 'S',
'GLN': 'Q',
'LYS': 'K',
'ILE': ... | 84cf3b1b383f3c6559dee6d212c0e2265c2f97a0 | 29,811 |
def expanding_mean(new_value, old_value, time):
"""
Args:
new_value: this time step's value
old_value: aggregate from last time step
time: current time, zero-indexed
Returns:
mean from t = 0 : time
"""
time_1plus = time + 1
return (1. / time_1plus) * new_value + (... | 9f701473a9904e48ec042983a8bedc2e27a464ba | 29,813 |
def _gradient_normalization(grad, non_zero, centralize_gradients=True, normalize_gradients=True):
"""
substract the mean from the gradient and divide it by its standard deviation
`non_zero` is a function that takes an input and insures that it will not be zero or negative
"""
can_centralize = centra... | 82a73e90759ec00e49e4dde1797377362819683d | 29,815 |
from typing import Callable
from typing import Iterable
def sort_by_reversed(key: Callable):
"""Return a new list containing all items from the iterable in descending order, sorted by a key.
>>> sort_by_reversed(lambda x: x % 10)([2231, 47, 19, 100])
[19, 47, 2231, 100]
"""
def sort_by_reversed(s... | 711df771751590a6315deefb075d9a436743cacb | 29,816 |
from multiprocessing import Process, Queue
import traceback
import functools
def pl_multi_process_test(func):
"""Wrapper for running multi-processing tests."""
@functools.wraps(func)
def wrapper(*args, **kwargs):
queue = Queue()
def inner_f(queue, **kwargs):
try:
... | 4b75d5734ae1f2ee57111e2bec9b5fef40c12bad | 29,817 |
import itertools
def is_sorted(iterable, *, key=None, reverse=False, strict=False):
"""Returns true if iterable is sorted
Parameters
----------
iterable : iterable
The iterable to check for sorted-ness.
key : x -> y, optional
Apply mapping function key to iterable prior to checkin... | 682d0026193a3189bcee7e693f8ed28d5c18d10b | 29,819 |
from typing import Dict
from typing import Tuple
def _has_all_valid_descriptors(peak_descriptors: Dict[str, float],
filters: Dict[str, Tuple[float, float]]) -> bool:
"""
Check that the descriptors of a peak are in a valid range.
aux function of get_peak_descriptors.
Pa... | c797949c6faa5f401abfaf020c64b55e2e41c544 | 29,820 |
import torch
def dist2(feat_a, feat_b):
"""
Args:
feat_a: the feature of image_a
feat_b: a list of features, on a list of images
Return:
dist: a list, which means a list of distances between feat_a and each one in feat_b
"""
dist=[]
feat_a = torch.FloatTensor(feat_a)
for i in range(len(feat_... | c26ef4f337f0d4248f61f03cbf962b0187a4f7c6 | 29,821 |
import argparse
def validate_color_temperature(s: str) -> int:
"""Validate color temperature argument."""
try:
value = int(s)
except ValueError:
raise argparse.ArgumentTypeError(f"{s} is not an integer")
if value < 2900 or value > 7000:
raise argparse.ArgumentTypeError(
... | 2f462e7faa32bba34e4b26017e844edd61644904 | 29,824 |
import re
def rlist_to_int(string):
"""Takes an rlist string as input, and outputs a corresponding integer"""
rlist = 0
string = re.sub(r"r|R", "", string)
for m in re.finditer(r"[^,]+", string):
args = m.group().split("-")
if len(args) == 1: lo,hi = args*2
else: lo,hi = args
... | 782f01cdaee0e2c51ff6dfcd281c5d83e1a3e98b | 29,825 |
def interpolate_template(template, context):
"""Interpolate context into a template.
(i.e. replace things in strings without % replacement).
Args:
template (str) : String to fill with context
context (dict) : Dictionary of variables
Returns:
str : Populated template
"""
... | 6c9151075c9fa836b340ee163452de47eec8fe2c | 29,826 |
def accepts(source):
""" Test if source matches a Twitter handle """
# If the source equals the plugin name, assume a yes
if source["type"] == "twitter":
return True
# Default to not recognizing the source
return False | 03ce273a924736ac68d73b2f68a4dada9b412c8a | 29,827 |
def get_qualifiers(qualifiers):
"""
get qualifiers, if exist and returns a dict of "qualifier_name: data" - pairs
"""
qualifiers_dict = dict()
if qualifiers is not None:
qualifiers = qualifiers if isinstance(qualifiers, list) else [qualifiers]
for qualifier in qualifiers:
... | d0f354d709c11ea40b212e2baaaef5762a3ad5c2 | 29,828 |
def make_enum_pair(ele, till, delimiter=", "):
"""
Create list of pair of strings with consecutive numbering as follows:
make_enumerated_pair('P%d p%d', 3) -> 'P1 p1, P2 p2, P3 p3'
"""
return delimiter.join(ele % (i + 1, i + 1) for i in range(till)) | 66b9410f307027ef151dd81edb7b29998ef65628 | 29,829 |
def convert_dtw_struc_dist(distances, start_layer=1):
"""
Convert
:param distances: dict of dict
:param start_layer:
:return:
"""
for vertices, layers in distances.items():
keys_layers = sorted(layers.keys())
start_layer = min(len(keys_layers), start_layer)
for layer ... | 8c62ab92e565509625bbef293bcc4d05870e1754 | 29,830 |
def average(keyword, values):
"""
calculate average of all values at values[+].keyword and return
:param keyword: the key of the value you care about
:param values: [{key: value},...] array of dicts, values assumed numeric
:return: single averaged value
"""
average = 0.0
for val in value... | aed36e90a485e4f433de7330f920167dd0e558d5 | 29,831 |
import os
def _file_size_is_valid(sequence_file, minimum_file_size):
"""
Performs a os.path.getsize operation on the sequence file(s) on the sequence_file object
if any files are less than the file minimum, return false, else return true
:param sequence_file: SequenceFile object
:param minimum_fi... | edb2d7ed33aedc7cef18d63a2b468e6982aa7897 | 29,833 |
def can_collapse(row):
"""
returns true if the given row
can be collapsed to the left
can also be a column
"""
for a,b in zip(row[1:], row):
if a==0:
continue
if b==0 or a==b:
return True
return False | 50a26acd3ea27049fd2be3d60860a1f10bf999ed | 29,835 |
def transition_required(*transitions):
"""
Permission factory that requires that current user has access to at least one of the transitions and at the same time has ``required`` permission (or factory).
If the required permission is not set, it is considered as true. If it is callable,
it is called at ... | 96e273057360c1c03ea78a6f1618b7900abbb128 | 29,836 |
def get_count(inputStr):
"""
Return the number (count) of vowels in the given string.
We will consider a, e, i, o, and u as vowels for this Kata.
The input string will only consist of lower case letters and/or spaces.
:param inputStr: input string value.
:return: the number (count) of vowels in ... | f4700b0c93175b4b3553f16e27384a3ee3481c60 | 29,838 |
import random
def random_bit_value():
"""Returns random bit"""
return random.randint(0, 1) | 3627c3ef2246f7913ce14f5ebf31b7b56ebff461 | 29,840 |
def fractional_basal_area_by_species(data):
"""For group of trees, calculate the fraction total basal area represented by each species"""
# cast to str so can store sparsely :)
fractional_ba = (
(
data.groupby(data["SPCD"].astype(str)).unadj_basal_area.sum()
/ data.unadj_basa... | ea8e8dc4ee75c6756eb48acd18e0e22d8198d6f2 | 29,841 |
def subDict(somedict, somekeys, default=None):
"""
Returns subset of a dictionary with keys from somekeys
"""
return dict([ (k, somedict.get(k, default)) for k in somekeys ]) | 17b95ee28986ca2c2f02e3405fc71c76a14fbbc9 | 29,842 |
def qset_cmb_box(cmb_box, string, data=False):
"""
Set combobox to the index corresponding to `string` in a text field (data = False)
or in a data field (data=True). When `string` is not found in the combobox entries,
select the first entry. Signals are blocked during the update of the combobox.
... | f2a53bca106fe160d04142ebf0fdfb2de966a98d | 29,843 |
def parse_f90idx(tokens, t, prior_t):
"""Parse Fortran vector indices into a tuple of Python indices."""
idx_end = (',', ')')
v_name = prior_t
v_indices = []
i_start = i_end = i_stride = None
# Start index
t = next(tokens)
try:
i_start = int(t)
t = next(tokens)
exc... | a3b9f6b3c492e4c31a3c7d3d66c3779ea76d7449 | 29,846 |
from typing import Iterator
import itertools
def decimal(start: int = 1) -> Iterator[int]:
"""
Increments from `start`.
e.g. 1, 2, 3, .. 9, 10, 11, etc.
Args:
start: The first value to start with.
"""
return itertools.count(start) | 5c0a4b75b45c391597091e83c4b3991ba64d6626 | 29,847 |
def lunar_add(n, m):
"""lunar addition"""
sn, sm = str(n), str(m)
l = max(len(sn), len(sm))
return int("".join(max(i, j) for i, j in zip(sn.rjust(l, "0"), sm.rjust(l, "0")))) | eb6c62c4a72176615b398e9b4c04535ec9fa3d2e | 29,848 |
def get_rendered(font, text, color, cache):
"""Simple font renderer that caches render."""
if text in cache:
image = cache[text]
else:
image = font.render(text, 0, color)
cache[text] = image
return image | 13557f705882da5865812a0be86cf8b46b95e202 | 29,849 |
def adv_word_probs_for_rev(rev, td):
"""
Return adversarial word probabilities for the reviewer
"""
# Get topics for the reviewer
rev_top_list = td.rev_top[rev.name()]
wds_prob = {}
for t_id, t_prob in rev_top_list[:3]:
# Get words contributing to each topic
t_wds = td.top_wd... | 24baf7bcdb5655881f56c9abb6c889884c926347 | 29,850 |
import math
def angle_to(tup1,tup2):
"""The angle to tup2 from tup1, measured against 'straight up' clockwise, in radians.
Tuples are given in a coordinate system with (0,0) top left, (1,0) is one step right, (0,1) is one step down,
and (1,1) is down right.
>>> angle_to((1,1),(1,0))/math.pi
0.0
... | edece575727f69d716ffd217807b4b794a6b7a1c | 29,851 |
def OkErrMiss(o):
"""
compute Ok, errors, missed from the ResultStructure object
return a triple (ok, err, miss)
"""
ok = o.truePos
err = o.resTotal - ok
miss = o.gtTotal - ok
return ok, err, miss | 11f3958272d1fdbb34621c5d0ad7700193b9a2f9 | 29,852 |
def solution(A):
"""
DINAKAR
Idea is xor of two same numbers produces 0
x = 3 (011) and y = 3 (011) is 000
at the end single numbers left in xor variable.
:return:
"""
xor = 0
for item in A:
xor ^= item
return xor | 2f59e3ffdfc9c429b96d1273850c633d90b77f1e | 29,853 |
import re
def filter_partheading(line):
"""
Removes 'part 4 / The New World'
:param line:
:return:
"""
line = line.strip()
m = re.search("part \d+ \/", line)
if m:
return None
return line | fa0e51c60eb19870ef186112b3bcbcd181bc71f0 | 29,855 |
import logging
def featurize_data(model, array):
"""
Given a model and an array, perform error checking and return the prediction
of the full feature array.
Parameters:
----------
model : keras.models.Model
The featurizer model performing predictions
array : np.ndarra... | 1b8796ace6f3a72a288b6621f01e62c90a06a769 | 29,856 |
def init_params():
"""Set up the simulation parameters."""
p = {}
p['endYear'] = 2040
p['statsCollectFrom'] = 1990
p['numberPolicyParameters'] = 4
p['numberScenarios'] = 9
p['implementPoliciesFromYear'] = 2020
p['discountingFactor'] = 0.03
return p | 322731e35a31b5d44351ca743aff14a353f08301 | 29,857 |
def get_vector(model, line):
"""
获得文章的向量
:param final: list
:return: final: list
"""
vec = model.infer_vector(line)
return vec | 740791cd8773beeed4ebbee066dfbe6830694685 | 29,858 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.