content stringlengths 35 416k | sha1 stringlengths 40 40 | id int64 0 710k |
|---|---|---|
def get_invalid_value_message(value_name: str, value: str, line_no: int, uid: str, expected_vals: "list[str]") -> str:
"""
Returns the formatted message template for invalid value while parsing students data!
"""
msg = f"Invalid {value_name} <span class=\"font-weight-bold\">{value}</span>\
o... | cb7dc84b566bb117fe53ce5956919978558ccbbf | 3,513 |
def compute_score_for_coagulation(platelets_count: int) -> int:
"""
Computes score based on platelets count (unit is number per microliter).
"""
if platelets_count < 20_000:
return 4
if platelets_count < 50_000:
return 3
if platelets_count < 100_000:
return 2
if plate... | dc6e9935555fbb0e34868ce58a8ad8bc77be8b0c | 3,514 |
def check_horizontal_visibility(board: list):
"""
Check row-wise visibility (left-right and vice versa)
Return True if all horizontal hints are satisfiable,
i.e., for line 412453* , hint is 4, and 1245 are the four buildings
that could be observed from the hint looking to the right.
>>> che... | b84ff29fde689069ba5e92b10d54c8f0528aa321 | 3,515 |
def verify(params, vk, m, sig):
""" verify a signature on a clear message """
(G, o, g1, hs, g2, e) = params
(g2, X, Y) = vk
sig1 , sig2 = sig
return not sig1.isinf() and e(sig1, X + m * Y) == e(sig2, g2) | 7413d9172d383c3602cbc2b8348c4ace61c40302 | 3,516 |
import os
def prepend_items():
"""
Return a function than prepend any item from "paths" list with "prefix"
"""
def prepend_func(prefix, paths):
return [os.path.join(prefix, item) for item in paths]
return prepend_func | b7c4fd8e1c53c82ba7dd1e826feb084e6543691b | 3,517 |
import itertools
def average_distance(points, distance_func):
"""
Given a set of points and their pairwise distances, it calculates the average distances
between a pair of points, averaged over all C(num_points, 2) pairs.
"""
for p0, p1 in itertools.combinations(points, 2): # assert symmetry... | 236735da94e902dd7fbe062de8abb9a02208156f | 3,520 |
import glob
import os
import random
def get_filenames(feature_folder, glob_pattern, sample_size=None):
"""
Finds the all the files in the given feature folder which matches the glob pattern.
:param feature_folder: The folder to search for files.
:param glob_pattern: The glob pattern to use for finding... | 19b97b9e981b8fe0b978d5af2240dc22c02d7e93 | 3,522 |
def create_message(username, message):
""" Creates a standard message from a given user with the message
Replaces newline with html break """
message = message.replace('\n', '<br/>')
return '{{"service":1, "data":{{"message":"{mes}", "username":"{user}"}} }}'.format(mes=message, user=username) | d12807789d5e30d1a4a39c0368ebe4cf8fbde99e | 3,523 |
def obtener_atletas_pais(atletas: list, pais_interes: str) -> list:
"""
Función que genera una lista con la información de los atletas del país dado,
sin importar el año en que participaron los atletas.
Parámetros:
atletas: list de diccionarios con la información de cada atleta.
pais_in... | 4b03364a76af4e7818f977731b259fdfee6817ee | 3,525 |
def oddify(n):
"""Ensure number is odd by incrementing if even
"""
return n if n % 2 else n + 1 | dee98063cb904cf462792d15129bd90a4b50bd28 | 3,527 |
def concatenation(clean_list):
"""
Concatenation example.
Takes the processed list for your emails and concatenates any elements that are currently separate that you may
wish to have as one element, such as dates.
E.g. ['19', 'Feb', '2018'] becomes ['19 Feb 2018]
Works best if the lists are simi... | 59b727f21e663f2836f6fe939f4979e9f7484f62 | 3,528 |
import sys
import hashlib
def calc_md5_sign(secret, parameters):
"""
根据app_secret和参数串计算md5 sign,参数支持dict(建议)和str
:param secret: str
:param parameters:
:return:
"""
if hasattr(parameters, "items"):
keys = list(parameters.keys())
keys.sort()
parameters_str = "%s%s%s"... | f13cd469a86942c011f3d419a4a2cf89c79cf2df | 3,529 |
import torch
def model_predict(model, test_loader, device):
"""
Predict data in dataloader using model
"""
# Set model to eval mode
model.eval()
# Predict without computing gradients
with torch.no_grad():
y_preds = []
y_true = []
for inputs, labels in test_loader:
... | 0b43a28046c1de85711f7db1b3e64dfd95f11905 | 3,530 |
def get_gifti_labels(gifti):
"""Returns labels from gifti object (*.label.gii)
Args:
gifti (gifti image):
Nibabel Gifti image
Returns:
labels (list):
labels from gifti object
"""
# labels = img.labeltable.get_labels_as_dict().values()
label_dict = gifti... | 3a4915ed50132a022e29cfed4e90905d05209484 | 3,532 |
from typing import Set
import os
def _get_mtimes(arg: str) -> Set[float]:
"""
Get the modification times of any converted notebooks.
Parameters
----------
arg
Notebook to run 3rd party tool on.
Returns
-------
Set
Modification times of any converted notebooks.
"""... | c19e7ba43f6fb1d776f10e39f9fa46d05c947c72 | 3,534 |
def eh_menor_que_essa_quantidade_de_caracters(palavra: str, quantidade: int) -> bool:
"""
Função para verificar se a string é menor que a quantidade de caracters informados
@param palavra: A palavra a ser verificada
@param quantidade: A quantidade de caracters que deseja verificar
@return: Retorna T... | 827469606b0b93b78b63686465decbbbc63b9673 | 3,535 |
def check_diamond(structure):
"""
Utility function to check if the structure is fcc, bcc, hcp or diamond
Args:
structure (pyiron_atomistics.structure.atoms.Atoms): Atomistic Structure object to check
Returns:
bool: true if diamond else false
"""
cna_dict = structure.analyse.pys... | ae082d6921757163cce3ddccbca15bf70621a092 | 3,536 |
def radix_sort(arr):
"""Sort list of numberes with radix sort."""
if len(arr) > 1:
buckets = [[] for x in range(10)]
lst = arr
output = []
t = 0
m = len(str(max(arr)))
while m > t:
for num in lst:
if len(str(num)) >= t + 1:
... | 517ab99483ac1c6cd18df11dc1dccb4c502cac39 | 3,537 |
def _rfc822_escape(header):
"""Return a version of the string escaped for inclusion in an
RFC-822 header, by ensuring there are 8 spaces space after each newline.
"""
lines = header.split('\n')
header = ('\n' + 8 * ' ').join(lines)
return header | 1a3cd02b057742db00ed741c40947cf4e19d1a86 | 3,540 |
import random
def generate_numbers():
"""
Function to generate 3 random digits to be guessed.
Generate 3 random in a list in order to be compare to the user's digits.
Return:
str_digits (Array): List with 3 random digits converted to String
"""
# List comprehension to generate num... | 8efd0f579a3a0b3dc5021cd762f9ad2f5774f6be | 3,544 |
def summate2(phasevec):
"""Calculate values b'(j^vec) for combining 2 phase vectors.
Parameter:
phasevec: tuple of two phasevectors
Example:
On input (([b_1(0),b_1(1),...,b_1(L-1)], L), ([b_2(0),b_2(1),...,b_2(L'-1)], L'))
give output [b_1(0)+b_2(0), b_1(0)+b_2(1),..., b_1(1)+b_2(0),...,b_1(L-... | 5150c2ee29a31438bf16104eaadeb85a01f54502 | 3,545 |
import torch
def tensor_to_longs(tensor: torch.Tensor) -> list:
"""converts an array of numerical values to a tensor of longs"""
assert tensor.dtype == torch.long
return tensor.detach().cpu().numpy() | ba1788be8e353936cfc3d604d940b78a96990fd4 | 3,546 |
def requiredOneInGroup(col_name, group, dm, df, *args):
"""
If col_name is present in df, the group validation is satisfied.
If not, it still may be satisfied, but not by THIS col_name.
If col_name is missing, return col_name, else return None.
Later, we will validate to see if there is at least one... | de46a4ef2f3e45381644db41d617d8c4c0845877 | 3,547 |
def persist(session, obj, return_id=True):
"""
Use the session to store obj in database, then remove obj from session,
so that on a subsequent load from the database we get a clean instance.
"""
session.add(obj)
session.flush()
obj_id = obj.id if return_id else None # save this before obj i... | a308931f418616417d10d3115b0f370352778533 | 3,548 |
def non_repeating(value, counts, q):
"""Finds the first non-repeating string in a stream.
Args:
value (str): Latest string received in the string
counts (dict): Dictionary of strings containing the counts to determine if string is repeated
q (Queue): Container for all strings in stream ... | fc5ec025cffa0d7230d814d3677ae640cd652349 | 3,551 |
import torch
def energy_target(flattened_bbox_targets, pos_bbox_targets,
pos_indices, r, max_energy):
"""Calculate energy targets based on deep watershed paper.
Args:
flattened_bbox_targets (torch.Tensor): The flattened bbox targets.
pos_bbox_targets (torch.Tensor): Bounding... | 84bed4cc1a8bf11be778b7e79524707a49482b39 | 3,552 |
def enforce_excel_cell_string_limit(long_string, limit):
"""
Trims a long string. This function aims to address a limitation of CSV
files, where very long strings which exceed the char cell limit of Excel
cause weird artifacts to happen when saving to CSV.
"""
trimmed_string = ''
... | 9b8bcf4590dc73425c304c8d778ae51d3e3f0bf3 | 3,554 |
import requests
def is_at_NWRC(url):
"""
Checks that were on the NWRC network
"""
try:
r = requests.get(url)
code = r.status_code
except Exception as e:
code = 404
return code==200 | b909a9087940eb70b569ea6c686ff394e84a6ed9 | 3,555 |
import torch
def lmo(x,radius):
"""Returns v with norm(v, self.p) <= r minimizing v*x"""
shape = x.shape
if len(shape) == 4:
v = torch.zeros_like(x)
for first_dim in range(shape[0]):
for second_dim in range(shape[1]):
inner_x = x[first_dim][second_dim]
... | 24bda333cdd64df9a0b4fa603211036bbdad7200 | 3,556 |
def feature_norm_ldc(df):
"""
Process the features to obtain the standard metrics in LDC mode.
"""
df['HNAP'] = df['HNAC']/df['ICC_abs']*100
df['TCC'] = (df['ICC_abs']+df['DCC_abs'])/df['VOL']
df['ICC'] = df['ICC_abs']/df['VOL']
df['DCC'] = df['DCC_abs']/df['VOL']
return df | 60e3ef31c0be07179854de3191c2c75f4ec2cb4d | 3,557 |
import uuid
def get_tablespace_data(tablespace_path, db_owner):
"""This function returns the tablespace data"""
data = {
"name": "test_%s" % str(uuid.uuid4())[1:8],
"seclabels": [],
"spcacl": [
{
"grantee": db_owner,
"grantor": db_owner,
... | 3272e9b941d6bfb426ed754eed7f956c4c0933f4 | 3,559 |
def join_chunks(chunks):
"""empty all chunks out of their sub-lists to be split apart again by split_chunks(). this is because chunks now
looks like this [[t,t,t],[t,t],[f,f,f,][t]]"""
return [item for sublist in chunks for item in sublist] | a5daf41ba3fa6e7dafc4f05b29cc5aeaa397d5a5 | 3,560 |
def urls_equal(url1, url2):
"""
Compare two URLObjects, without regard to the order of their query strings.
"""
return (
url1.without_query() == url2.without_query()
and url1.query_dict == url2.query_dict
) | f2cbcf111cd5d02fa053fbd373d24b2dab047dfc | 3,561 |
def bytes_to_ints(bs):
"""
Convert a list of bytes to a list of integers.
>>> bytes_to_ints([1, 0, 2, 1])
[256, 513]
>>> bytes_to_ints([1, 0, 1])
Traceback (most recent call last):
...
ValueError: Odd number of bytes.
>>> bytes_to_ints([])
[]
"""
if len(bs) % 2 != 0:... | e8ac9ec973ff58973703e3e109da5b45d3f9d802 | 3,562 |
def _bgp_predict_wrapper(model, *args, **kwargs):
"""
Just to ensure that the outgoing shapes are right (i.e. 2D).
"""
mean, cov = model.predict_y(*args, **kwargs)
if len(mean.shape) == 1:
mean = mean[:, None]
if len(cov.shape) == 1:
cov = cov[:, None]
return mean, cov | 23bb62927e767057df94ef8b95b57874fc078d7f | 3,563 |
import re
def snake_to_camel(action_str):
"""
for all actions and all objects unsnake case and camel case.
re-add numbers
"""
if action_str == "toggle object on":
return "ToggleObjectOn"
elif action_str == "toggle object off":
return "ToggleObjectOff"
def camel(match):
... | c71745c02fc712e2b463e7bcb022bfca41c2efd4 | 3,564 |
def rename_columns(df):
"""This function renames certain columns of the DataFrame
:param df: DataFrame
:type df: pandas DataFrame
:return: DataFrame
:rtype: pandas DataFrame
"""
renamed_cols = {"Man1": "Manufacturer (PE)",
"Pro1": "Model (PE)",
"Man2"... | 9c22747d7c6da20cab1593388db5575a38aa313f | 3,565 |
import requests
import json
def get_github_emoji(): # pragma: no cover
"""Get Github's usable emoji."""
try:
resp = requests.get(
'https://api.github.com/emojis',
timeout=30
)
except Exception:
return None
return json.loads(resp.text) | 533a56e2e59b039cbc45ab5acb7ab4e8487e4ad9 | 3,566 |
def from_binary(bin_data: str, delimiter: str = " ") -> bytes:
"""Converts binary string into bytes object"""
if delimiter == "":
data = [bin_data[i:i+8] for i in range(0, len(bin_data), 8)]
else:
data = bin_data.split(delimiter)
data = [int(byte, 2) for byte in data]
return bytes(da... | f16706da2d5b9ae5984a35a13ebd02ae94581153 | 3,567 |
def one_on_f_weight(f, normalize=True):
""" Literally 1/f weight. Useful for fitting linspace data in logspace.
Parameters
----------
f: array
Frequency
normalize: boolean, optional
Normalized the weight to [0, 1].
Defaults to True.
Returns
-------
weight: array... | 54301aa7480e6f3520cbfcccfa463a2a02d34b9c | 3,568 |
import numpy
def fft_in_range(audiomatrix, startindex, endindex, channel):
"""
Do an FFT in the specified range of indices
The audiomatrix should have the first index as its time domain and
second index as the channel number. The startindex and endinex
select the time range to use, and the cha... | 30ce104795d0809f054439ba32f47d33528ecbff | 3,569 |
def get_at_content(sequence):
"""Return content of AT in sequence, as float between 0 and 1, inclusive. """
sequence = sequence.upper()
a_content = sequence.count('A')
t_content = sequence.count('T')
return round((a_content+t_content)/len(sequence), 2) | 6316d29cdb9d7129f225f2f79a50485fb6919e32 | 3,570 |
def replace(data, match, repl):
"""Replace values for all key in match on repl value.
Recursively apply a function to values in a dict or list until the input
data is neither a dict nor a list.
"""
if isinstance(data, dict):
return {
key: repl if key in match else replace(value,... | 1b3dc8ac7521ec199cf74ebc8f4d8777827ab9fc | 3,572 |
import time
def get_current_date() ->str:
"""Forms a string to represent the current date using the time module"""
if len(str(time.gmtime()[2])) == 1:
current_date = str(time.gmtime()[0]) + '-' + str(time.gmtime()[1]) + '-0' + str(time.gmtime()[2])
else:
current_date = str(time.gmtime()[0]... | 480d44fc0153407960eacb875474fc02cb17c6c3 | 3,573 |
import re
def valid_text(val, rule):
"""Return True if regex fully matches non-empty string of value."""
if callable(rule):
match = rule(val)
else:
match = re.findall(rule, val)
return (False if not match or not val else
True if match is True else
match[0] == va... | aa6f6ac3a3210d34b44eba1f2e8e8cff851ff038 | 3,577 |
def body_open():
"""open the main logic"""
return " @coroutine\n def __query(__connection):" | d8792f2b3237f024f20a12c6b7d371af1dbdb21e | 3,578 |
import os
import pickle
def load_tweet_users_posted_rumours():
"""
load user history (whether a user posted any rumour in the past)
:return: dict {timestamp at which the user posted a rumour: user_id}
"""
with open(os.path.join(os.path.dirname(os.path.dirname(__file__)), 'tweet_users_poste... | 626fc152aae0b38aa4531dafb4d917100bad37c8 | 3,579 |
def check_column(board):
"""
list -> bool
This function checks if every column has different numbers and returns
True is yes, and False if not.
>>> check_column(["**** ****", "***1 ****", "** 3****", \
"* 4 1****", " 9 5 ", " 6 83 *", "3 1 **", " 8 2***", " 2 ****"])
False
>>> ... | b903d1b589cd2981cc374ff47f985151d341e7ec | 3,580 |
def capacitorCorrection(m_cap):
"""Apply a correction to the measured capacitance value
to get a value closer to the real value.
One reason this may differ is measurement varies based on frequency.
The measurements are performed at 30Hz but capacitance values
are normally quoted for 1kH... | 1942c177d534bc5533bb636e10f0107c1230c81d | 3,581 |
from datetime import datetime
def read_raw(omega):
"""Read the raw temperature, humidity and dewpoint values from an OMEGA iServer.
Parameters
----------
omega : :class:`msl.equipment.record_types.EquipmentRecord`
The Equipment Record of an OMEGA iServer.
Returns
-------
:class:`... | 105e07d26774288319459ebdc485d75c3a909212 | 3,582 |
from datetime import datetime, timedelta
def determine_dates_to_query_on_matomo(dates_in_database):
"""
Determines which dates need to be queried on Matomo to update the dataset.
"""
# determines which dates are missing from the database and could be queried on Matomo
# NOTE: start date was set ... | 40db63fb7ff339d5c306df37cf0f4b1765b91f90 | 3,583 |
def k8s_stats_response():
"""
Returns K8s /stats/summary endpoint output from microk8s on Jetson Nano.
"""
with open("tests/resources/k8s_response.json", "r") as response_file:
response = response_file.read()
return response | 68413108eeea6bdd80a782b962f3a5c97e1a4b73 | 3,584 |
def logical_array(ar):
"""Convert ndarray (int, float, bool) to array of 1 and 0's"""
out = ar.copy()
out[out!=0] = 1
return out | 74d96d519929ed7f5ddfd92b0fbcef4741a38359 | 3,586 |
def _get_chinese_week(localtime):
"""获取星期和提醒"""
chinese_week = ["一", "二", "三", "四", "五", "六", "日"]
tm_w_day = localtime.tm_wday
extra_msg = "<green>当前正是周末啦~</green>" if tm_w_day in [5, 6] else "Other"
if extra_msg == "Other":
go_week = 4 - tm_w_day
extra_msg = f"<yellow>还有 {go_week} ... | 0a66bcf741c0d2e3cc9a238b5cb879c89333cc6b | 3,588 |
def m_college_type(seq):
"""
获取学校的类型信息
当学校的类型是985,211工程院校时:
:param seq:【“985,211工程院校”,“本科”】
:return:“985工程院校”
当学校的类型是211工程院校时:
:param seq:【“211工程院校”,“硕士”】
:return:“211工程院校”
当学校的类型是普通本科或者专科时:
如果获取的某人的学历信息是博士、硕士和本科时
输出的学校类型为普通本科
:param seq:【“****”,“... | bf72f60c51a67dd3e18a7dd1957bc2beb4f933fd | 3,589 |
import json
def user_config(filename):
"""user-provided configuration file"""
try:
with open(filename) as file:
return json.loads(file.read(None))
except FileNotFoundError as fnf:
raise RuntimeError(f"File '{filename}' could not be found") from fnf
except json.JSONDecodeErr... | a6aa05d76b4aaa12c02ff97e4ab5ba4ba1245324 | 3,590 |
def room_from_loc(env, loc):
"""
Get the room coordinates for a given location
"""
if loc == 'north':
return (1, 0)
if loc == 'south':
return (1, 2)
if loc == 'west':
return (0, 1)
if loc == 'east':
return (2, 1)
if loc == 'left':
return (1, 0)
... | 75192c47fd8d4b56332b35ec7c3b355927e50ca2 | 3,591 |
def shifted(x):
"""Shift x values to the range [-0.5, 0.5)"""
return -0.5 + (x + 0.5) % 1 | c40585748120af5d0acd85e4fed49f0575a92a3d | 3,592 |
def run_node(node):
"""Python multiprocessing works strangely in windows. The pool function needed to be
defined globally
Args:
node (Node): Node to be called
Returns:
rslts: Node's call output
"""
return node.run_with_loaded_inputs() | a0f52020db20b4b67e83599bc0fb6c86ec2f9514 | 3,593 |
def get_base_required_fields():
""" Get required fields for base asset from UI.
Fields required for update only: 'id', 'uid', ['lastModifiedTimestamp', 'location', 'events', 'calibration']
Present in input, not required for output:
'coordinates', 'hasDeploymentEvent', 'augmented', 'deployment_number... | 273c539d0c0b0da249e2bb171107aa775ce52ddf | 3,594 |
import os
import sys
def find_package(dir):
"""
Given a directory, finds the equivalent package name. If it
is directly in sys.path, returns ''.
"""
dir = os.path.abspath(dir)
orig_dir = dir
path = map(os.path.abspath, sys.path)
packages = []
last_dir = None
while 1:
i... | 0bc904165620daa2f408a3f1c526bfe4a34def97 | 3,596 |
def Window(node, size=-1, full_only=False):
"""Lazy wrapper to collect a window of values. If a node is executed 3 times,
returning 1, 2, 3, then the window node will collect those values in a list.
Arguments:
node (node): input node
size (int): size of windows to use
full_only (boo... | 1f85b576455f3b379e41a7247ff486281bf21f8f | 3,597 |
def add_colon(in_str):
"""Add colon after every 4th character."""
return ':'.join([in_str[i:i+4] for i in range(0, len(in_str), 4)]) | fa4258aa9d684a087d2a81ae09a2702d6e58e3e1 | 3,598 |
def get_alt_pos_info(rec):
"""Returns info about the second-most-common nucleotide at a position.
This nucleotide will usually differ from the reference nucleotide, but it
may be the reference (i.e. at positions where the reference disagrees with
the alignment's "consensus").
This breaks ties arbi... | 3abe3fcbbf0ddbccb44025f2e476f77dc3e8abf9 | 3,599 |
import threading
def handle_readable(client):
"""
Return True: The client is re-registered to the selector object.
Return False: The server disconnects the client.
"""
data = client.recv(1028)
if data == b'':
return False
client.sendall(b'SERVER: ' + data)
print(threading.acti... | 9a77bb893a5da4e76df5593feb6ecf49022e6ef3 | 3,601 |
import numpy
def create_objective(dist, abscissas):
"""Create objective function."""
abscissas_ = numpy.array(abscissas[1:-1])
def obj(absisa):
"""Local objective function."""
out = -numpy.sqrt(dist.pdf(absisa))
out *= numpy.prod(numpy.abs(abscissas_ - absisa))
return out
... | c63eeadffd067c2a94470ddbf03fb009265fbbbc | 3,602 |
def _is_segment_in_block_range(segment, blocks):
"""Return whether the segment is in the range of one of the blocks."""
for block in blocks:
if block.start <= segment.start and segment.end <= block.end:
return True
return False | e7509f18f0a72cf90fb1aa643c77c2e13154f0d0 | 3,603 |
def generate_episode(sim, policy, horizon=200):
"""
Generate an episode from a policy acting on an simulation.
Returns: sequence of state, action, reward.
"""
obs = sim.reset()
policy.reset() # Reset the policy too so that it knows its the beginning of the episode.
states, actions, rewards ... | 73a0bbb2703c047d3305e93dd2a340c83db12277 | 3,605 |
import torch
def disparity_to_idepth(K, T_right_in_left, left_disparity):
"""Function athat transforms general (non-rectified) disparities to inverse
depths.
"""
assert(len(T_right_in_left.shape) == 3)
# assert(T_right_in_left.shape[0] == self.batch_size)
assert(T_right_in_left.shape[1] == 4)
... | 454bda2fd9ec4e4ef5615dbdb054c2f3b454f31a | 3,607 |
import math
def foo(X):
"""The function to evaluate"""
ret = []
for x in X:
r = 2*math.sqrt(sum([n*n for n in x]));
if r == 0:
ret.append(0)
else:
ret.append(math.sin(r) / r);
return ret | 7b241cf45757cdf9a5a28ee56c59ee41099ccb1e | 3,608 |
def pre_process(image):
"""
Invert pixel intensity of 'images' (to compensate the conversion into image with imwrite).
"""
return 1 - image * 255 | 7e7227930567c31874d966ce18aeeffa9b73e646 | 3,613 |
import os
def is_source_path(path):
"""Check if path is source code path.
Parameters
----------
path : str
A possible path
Returns
-------
valid : bool
Whether path is a possible source path
"""
if os.path.exists(path):
return True
if path.find("\n") !... | f932049eb70275ad8e394ec21af8bbf9ef2c3880 | 3,614 |
def value_or_dash(value):
"""Converts the given value to a unicode dash if the value does
not exist and does not equal 0."""
if not value and value != 0:
return u'\u2013'.encode('utf-8')
return value | 8cadbfd8dcfad9dfeb4112cb8537f0e0d5de49ba | 3,615 |
import pkg_resources
def get_resource(name):
"""Convenience method for retrieving a package resource."""
return pkg_resources.resource_stream(__name__, name) | 63aada8f6e99956b770bd9ea7f737d90432c3f90 | 3,617 |
def error_message() -> str:
"""Error message for invalid input"""
return 'Invalid input. Use !help for a list of commands.' | 2ffea48dd495d464264bc657ca62cfe6043a1084 | 3,618 |
from typing import Counter
def palindrome_permutation(string):
"""
All palindromes follow the same rule, they have at most one letter whose
count is odd, this letter being the "pivot" of the palindrome. The letters
with an even count can always be permuted to match each other across the
pivot.
... | a1e5721d73e9773d802b423747277dd43ee5983f | 3,620 |
def symmetrise_AP(AP):
"""
No checks on this since this is a deep-inside-module helper routine.
AP must be a batch of matrices (n, 1, N, N).
"""
return AP + AP.transpose(2, 3) | 4a993f42e576656ec5f450c95af969722f10a58d | 3,621 |
def get_argument(value, arg):
"""Get argument by variable"""
return value.get(arg, None) | 0abd48a3a241ab1076c3ca19241df5b7b4346224 | 3,622 |
def get_target_proportions_of_current_trial(individuals, target):
"""Get the proportion waiting times within the target for a given trial of
a threshold
Parameters
----------
individuals : object
A ciw object that contains all individuals records
Returns
-------
int
all... | 95f3781677f3ca7bb620488778b52502783c6eb9 | 3,623 |
def how_many(aDict):
"""
aDict: A dictionary, where all the values are lists.
returns: int, how many values are in the dictionary.
"""
return sum(len(value) for value in aDict.values()) | ed1729b55411f29626dfe61c6853bc19813ceedc | 3,624 |
def crop_keypoint_by_coords(keypoint, crop_coords, crop_height, crop_width, rows, cols):
"""Crop a keypoint using the provided coordinates of bottom-left and top-right corners in pixels and the
required height and width of the crop.
"""
x, y, a, s = keypoint
x1, y1, x2, y2 = crop_coords
cropped_... | 5a2365a611275fea4d0f5d031127426c88c43905 | 3,625 |
def string_between(string, start, end):
"""
Returns a new string between the start and end range.
Args:
string (str): the string to split.
start (str): string to start the split at.
end (str): string to stop the split at.
Returns:
new string between start and end.
"... | fc6f2a3def4112140539c90abe6304f5daa8c1f4 | 3,626 |
def standardize_str(string):
"""Returns a standardized form of the string-like argument.
This will convert from a `unicode` object to a `str` object.
"""
return str(string) | ea007582363cd1eeee34d4b342a39581fd876c3a | 3,627 |
def infinitegenerator(generatorfunction):
"""Decorator that makes a generator replay indefinitely
An "infinite" parameter is added to the generator, that if set to True
makes the generator loop indifenitely.
"""
def infgenerator(*args, **kwargs):
if "infinite" in kwargs:
... | 6915a16dd765195e0344b5ebd255c1aca7737699 | 3,628 |
import os
def get_files(directory):
"""Gets full path of all files within directory, including subdirectories
Returns a list of paths"""
file_paths = []
for root, dirs, files in os.walk(directory):
for f in files:
filepath = os.path.join(root, f)
file_paths.append(file... | f0ad1ef92c5e00ef637c0b874acefa3344e64395 | 3,631 |
def load_labels(label_path):
"""
Load labels for VOC2012, Label must be maded txt files and like my label.txt
Label path can be change when run training code , use --label_path
label : { label naem : label color}
index : [ [label color], [label color]]
"""
with open(label_path, "r") as f:
... | 9c0388eb533293912b95ca020cbf3c9e9cb331d3 | 3,633 |
import argparse
def parse_args():
"""Parses command line arguments."""
parser = argparse.ArgumentParser(description='Install cert on device.')
parser.add_argument(
'-n', '--cert-name', default='dummycert', help='certificate name')
parser.add_argument(
'--overwrite', default=False, action='store_tr... | 94070336606f7ed68dfb479bcdd6ee79629c6888 | 3,635 |
import click
def num_physical_shards_option(f):
"""
Function to parse/validate the --num-physical-shards CLI option to dirbs-db repartition.
:param f: obj
:return: options obj
"""
def callback(ctx, param, value):
if value is not None:
if value < 1 or value > 100:
... | f53eb8003533da0f8562456517110ad92beeea01 | 3,637 |
def row_to_columns(row):
"""Takes a row as a string and returns it as a list of columns."""
return [column for column in row.split() if column.strip() != ''] | 837477f2e9c160b93c339a9753e0598ac56c819e | 3,639 |
def test_shift_to_other_frame(hlwm, direction, frameindex, clients_per_frame):
"""
in a frame grid with 3 columns, where the middle column has 3 rows, we put
the focused window in the middle, and then invoke 'shift' with the given
'direction'. Then, it is checked that the window stays focused but now
... | afeb04d178bd729fccae01118bc59e8e7b0c09dc | 3,642 |
def is_circular(linked_list):
"""
Determine whether the Linked List is circular or not
Args:
linked_list(obj): Linked List to be checked
Returns:
bool: Return True if the linked list is circular, return False otherwise
The way we'll do this is by having two pointers, called "runne... | 5a641df602f983de78c9c74b825847412aa54c21 | 3,645 |
def precisionatk_implementation(y_true, y_pred, k):
"""Fujnction to calculate precision at k for a given sample
Arguments:
y_true {list} -- list of actual classes for the given sample
y_pred {list} -- list of predicted classes for the given sample
k {[int]} -- top k predictions we are i... | 945caa95b32681939569ca675475e2527dbdee78 | 3,647 |
def AskNumber(text="unknown task"):
"""
Asks the user to interactively input a number (float or int) at any point in the script, and returns the input number.
| __option__ | __description__
| --- | ---
| *text | an optional string to identify for what purpose the chosen number will be used.
"""
def ValidateN... | 41949d0a2e2d87b5cdb26d2db9bff9a64fbeeb1d | 3,648 |
def get_unique_output_values(signals):
"""
Based on segment length, determine how many of the possible four
uniquely identifiable digits are in the set of signals.
"""
unique_digit_count = 0
for signal in signals:
for digit in signal["output"]:
if len(digit) in (2, 3, 4, 7):... | 84098d4d294bfdd1b983ea70d51da1453b17245a | 3,649 |
import itertools
def split_and_pad(s, sep, nsplit, pad=None):
""" Splits string s on sep, up to nsplit times.
Returns the results of the split, pottentially padded with
additional items, up to a total of nsplit items.
"""
l = s.split(sep, nsplit)
return itertools.chain(l, itertools.rep... | 6c439301df7109d9b01a06a87bd7d6adafb8ee1e | 3,650 |
def transpose_report(report):
"""Transposes the report. Columns into rows"""
return list(map(list, zip(*report))) | bc59f9106496b0b830fdc9ac0266f3b774a8f759 | 3,651 |
def _shape_from_resolution(resolution):
"""
Calculate the shape of the global Earth relief grid given a resolution.
Parameters
----------
resolution : str
Same as the input for load_earth_relief
Returns
-------
shape : (nlat, nlon)
The calculated shape.
Examples
... | c726d599696cee2259bc450606e63480b0991451 | 3,652 |
def get_fuel_from(mass: int) -> int:
"""Gets fuel from mass.
Args:
mass (int): mass for the fuel
Returns:
int: fuel necessary for the mass
"""
return mass // 3 - 2 | 37390c8cb9ba7e84c7b5c14841528d6c38f1589e | 3,653 |
import json
import sys
def read_config():
"""
Reads the configuration info into the cfg dictionary.
:return: A dictionary with the SSH-IPS configuration variables.
"""
CONFIG_FILE = '/etc/ssh-ips/config.json'
try:
with open(CONFIG_FILE, "r") as f:
cfg = json.load(f)
except ValueError as e:
print(str(e))... | 325e2e63fdf47c892ab432930de3e835faf1831d | 3,654 |
def minimaldescriptives(inlist):
"""this function takes a clean list of data and returns the N, sum, mean
and sum of squares. """
N = 0
sum = 0.0
SS = 0.0
for i in range(len(inlist)):
N = N + 1
sum = sum + inlist[i]
SS = SS + (inlist[i] ** 2)
mean = sum / float(N)
... | ca1d821ef64b93218bdb22268bfdde737f2d731c | 3,655 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.