content stringlengths 39 14.9k | sha1 stringlengths 40 40 | id int64 0 710k |
|---|---|---|
def read_blacklisted_ranges(fn, num_alignments):
"""Read list of blacklisted ranges.
There must be 3 columns in the file:
1 - an identifier for an alignment that the guide should be
covering (0-based, with maxmimum value < num_alignments)
2 - the start position (inclusive) of a rang... | 2c67a0e60c225d1664313608529e5ff56444a87d | 72,332 |
import csv
def parse_csv_data(csv_filename) -> list: # Function to parse csv data into a list.
"""extracts CSV data and formats it as a list.
:param csv_filename: the name of the CSV file you wish to parse.
:return: the lines of the CSV as a list of lists.
"""
file_lines = [] # initialises list... | ce7c72c0cdbb18a379541e0b2d7e0fb3cc209e55 | 72,335 |
def checkOut(out,filename):
"""
Check for errors in uhbdaa and uhbdpr.out.
"""
lines = out.split("\n")
# Check for fatal errors
hash = [l[1:6] for l in lines]
try:
err_index = hash.index("FATAL")
err = ["%s\n" % (80*"-")]
err.append("Fatal Error in %s:\n" %... | f2b849d1dd72832fc6e807e85a684ca267061d94 | 72,337 |
def get_formatted_month_year(month, year):
"""
Returns month/year formatted like MM/YYYY.
e.g.: 09/2015
:param year: Year
:param month: Month
:return: Formatted month/year (e.g. 09/2015), ``str``
"""
return "{0:=02}/{1}".format(month,
year) | b2c484044d63661b68a1a3619e73c1f303575ba3 | 72,338 |
def _getCcFlags(build):
"""A wrapper for BuildType.CcFlags that copes with ValueError being raised.
This happens with the GccOptNative build type, since the compile flags are machine-specific.
"""
try:
return build.CcFlags()
except ValueError:
return "[machine specific optimisat... | 38191b8be52b77a22b274d0fb8f89bc744eb236e | 72,339 |
def format_index(index):
"""Convert Index to fixture format.
"""
return {
"fields": {
"name": index.name,
"table_id": index.table_id,
"workspace_id": str(index.workspace_id),
"created_at": str(index.created_at),
"updated_at": str(index.upda... | 94d1aeb1a48af39039314a6cd3623c580cb01532 | 72,340 |
def writeADESHeader(
observatory_code,
submitter,
telescope_design,
telescope_aperture,
telescope_detector,
observers,
measurers,
observatory_name=None,
submitter_institution=None,
telescope_name=None,
telescope_fratio=None,
... | 88c2685aa0dbf7de0fbf6af7f354092ea71b37dc | 72,343 |
import csv
def _parse_wmic_csv_output(text):
"""
Parse the output of Windows "wmic logicaldisk list full /format:csv" command.
"""
# parse out the comma-separated values of each non-empty row
rows = [row for row in csv.reader(text.split("\n")) if row]
# use the first row as the header row
... | 458cd60a21305ff8144440839d395cedd62d6f36 | 72,345 |
def is_iterable(f):
""" Returns True if an object can be iterated over by using iter(obj)
"""
try:
iter(f)
return True
except TypeError:
return False | d5d2eb93a82a9d42fdbdf3a5bac17646dd1339e5 | 72,348 |
def _check_conversion(key, valid_dict):
"""Check for existence of key in dict, return value or raise error"""
if key not in valid_dict and key not in valid_dict.values():
# Only show users the nice string values
keys = [v for v in valid_dict.keys() if isinstance(v, str)]
raise ValueError... | 9f9054265b53efc9ee5d6aaf7aeb56e476d18dd8 | 72,351 |
def comment_text(results):
""" get comment text """
text = results['text']
return text | 66663f27ef4a6992502791aa8cf6d34381380ab1 | 72,352 |
def token(args, premise):
"""Return token."""
return args[0] | 20d8efe0e2107fed4826bbaec61079bc7fa917af | 72,355 |
import math
def fix_float_single_double_conversion(value: float) -> float:
"""Fix precision for single-precision floats and return what was probably
meant as a float.
In ESPHome we work with single-precision floats internally for performance.
But python uses double-precision floats, and when protobuf... | 0964a25a0a8205d5b448388779351e90e3967505 | 72,360 |
def get_fi_repeated_prime(p, k=1):
"""
Return Euler totient for prime power p^k
:param p: prime number
:param k: power
:return: fi(p^k)
"""
return pow(p, k - 1) * (p - 1) | 142c6adf1ef0fbab3d74b3138cd63b19bf60ff62 | 72,361 |
def greatest_common_divisor(value1: int, value2: int):
"""Calcula o maior divisor comum de dois valores"""
value1 = abs(value1)
value2 = abs(value2)
if value1 < value2:
value1, value2 = value2, value1
remainder = value1 % value2
if remainder == 0:
return value2
r... | 8a9eb15c5e719dc124cc7c21bce6870d64d675e0 | 72,362 |
from typing import Tuple
def get_rgb_from_hex(hex_str: str) -> Tuple[int, int, int]:
"""Get the rgb values from a hex string."""
# Adopted from
# https://stackoverflow.com/questions/29643352/converting-hex-to-rgb-value-in-python
hx = hex_str.lstrip("#")
return int(hx[0:2], 16), int(hx[2:4], 16), i... | 4c46249d23852f2e1dcb7a683d72677d447fd349 | 72,364 |
def convert_to_face_coords(face_bbox, leye_bbox, reye_bbox):
""" Convert the left and right eye bounding boxes to be referenced relative to
the face crop instead of the raw image.
Args:
face_bbox: The face bounding box.
leye_bbox: The raw left eye bounding box.
reye_bbox: The raw right eye bounding bo... | 356a958fc4c5d0f96f8f34781796288570812b24 | 72,366 |
def convert_nonelike_to_none(input_item):
"""Converts None-like values ("none", "NULL", None, etc) to the uniform string "None".
Note, the output is NOT the python None, but a string.
Parameters
----------
input_item : string or int
Item to be converted to None (e.g. "none", "NULL" or the ... | 5f57dd07d15c7b753f5a36d2106a4bc5d82994d8 | 72,373 |
def _sort_run_times(x, show_time=True):
"""Sort runs based on acquisition times"""
ordered_runs = sorted(x, key=lambda x: x[2])
if show_time:
return dict([(i[0], i[1]) for i in ordered_runs])
else:
return [i[0] for i in ordered_runs] | b3c78e1b978b668cdd0062dcc974789ddc5613c7 | 72,376 |
def sanitize_filename(filename):
"""Sanitize a filename, removing dangerous characters that could be used to
escape the uploads directory. Everything except [A-Z a-z 0-9 - _ .] are
stripped, along with the pattern '..' which in *nix systems represents going
up a directory in the filepath.
"""
... | 469fd6bbeb245fe1eac8c837000c4c72df4dc430 | 72,380 |
def get_shell_cmd(cmd_object):
"""
Convert a plumbum cmd to a shell expression
"""
return ' '.join(cmd_object.formulate(10)) | a32011931de12a546f38bb39bc2dbc73e3202d50 | 72,382 |
def get_fast_weights(updates, initialization):
"""Compute task-specific weights
Takes initialization parameters and task-specific weight updates
and creates the corresponding, new (fast) weights.
Parameters
----------
updates : torch.Tensor
Updates proposed for parameters. Sha... | 08ec9441332050282da3dee5653c1e10442a1fa0 | 72,383 |
import shutil
def dependency_check(dependency: str) -> bool:
"""
Checks if a given program is present in the user's $PATH
:param dependency: String of program name
:return: True if program is in $PATH, False if not
"""
check = shutil.which(dependency)
if check is not None:
return T... | 0b43ca17df80519e553b08bb746254ce2b8b4903 | 72,384 |
def avg(ts):
"""Calculates the average of the timeseries.
Args:
ts: A timeseries list of [time, value].
Returns:
Average of the timeseries.
"""
return sum([float(v[1]) for v in ts]) / len(ts) | b853d70841bf064a4f01f846469d76f9110739d4 | 72,386 |
def client_superuser(client, admin):
"""Provides a client with a logged in superuser. """
client.force_login(admin)
return client | 2433b52f5e9dbaedf73195d77e9015be158a262e | 72,387 |
import csv
def read_path2port_map(filename):
"""
Reads csv file containing two columns: column1 is path name,
column2 is port number
:param filename:
:return: dictionary with port as key and path as value
"""
res = {}
with open(filename, 'r') as csvfile:
reader = csv.reader(c... | 39a317c21d66c544bd50576493cb1e50dbc5b6bf | 72,391 |
def parse_player(player):
"""Parse an input string for the first player
Args:
player (string): String to be parsed (eg, X)
Returns:
(string/None): The player if valid or None
"""
if player.lower() == "x":
return "X"
elif player.lower() == "o":
return "O"
else:... | a752b992d9edbc3ae65e17951635e6b52387f51f | 72,396 |
import re
def check_operator_spacing_around(code, operator):
"""Check for correct spacing around the given operator in the line.
There should be exactly one space on either side of the given operator.
Notice that operators `*` and `&` don't quite follow this rule, since we're
okay with `Foo* foo` or ... | 8ac388446e039d0cca34163448d50c42b01452dd | 72,397 |
def check_keys(model, pretrained_state_dict):
"""Validate that the pre-trained model has all the parameters needed by the model"""
ckpt_keys = set(pretrained_state_dict.keys())
model_keys = set(model.state_dict().keys())
used_pretrained_keys = model_keys & ckpt_keys
unused_pretrained_keys = ckpt_key... | 07c008b25577e8763316d3ffe5350e6122674284 | 72,399 |
def standardize(X, mean_ctr=True, with_std=True, axis=-1, copy=True):
"""
Standardization of data
Parameters
----------
X : ndarray
Data array
mean_ctr : bool
Mean-center data
with_std : bool
Normalize by the standard deviation of the data
axis : int
... | a56960ad0343beef2e1eebdee975018a40b23354 | 72,406 |
import torch
from typing import Union
from typing import Callable
import warnings
def do_activation(input_data: torch.Tensor, activation: Union[str, Callable] = "softmax") -> torch.Tensor:
"""
This function is used to do activation for inputs.
Args:
input_data: the input that to be activated, in ... | dfdcf3af2aed6adcfddfb007a29a26865c1d2dc6 | 72,411 |
def processCEF(assemeblyModelSubstring):
"""This function parses the substrings of the assembly model string and provides back information on the modularity and planarity."""
assemeblyModelSubstring = assemeblyModelSubstring[1:]
nummod = assemeblyModelSubstring.split('X')
num = int(nummod[0])
mod = ... | 775495132f1fd431139cf7a25127d3381afba55d | 72,418 |
def prev(space, w_arr):
""" Rewind the internal array pointer """
length = w_arr.arraylen()
current_idx = min(w_arr.current_idx, length) - 1
if current_idx < 0:
return space.w_False
w_arr.current_idx = current_idx
return w_arr._current(space) | 89186391e6ce0a8985f051b6c010e51aaf239c7a | 72,419 |
def get_default_chunksize(length, num_splits):
"""Creates the most equal chunksize possible based on length and number of splits.
Args:
length: The integer length to split (number of rows/columns).
num_splits: The integer number of splits.
Returns:
An integer chunksize.
"""
... | 28b13c6140a5685aea75dd7eaaefbd5a7b63b072 | 72,422 |
def get_flow_info(http_flow):
"""
Get the TCP, IP and Meta information of the flow.
:param http_flow: http flow object
:return: tcp (src,dst ports), ip (src, dst addresses)
"""
return {
"TcpSrcPort": http_flow["TCP"].srcport,
"TcpDstPort": http_flow["TCP"].dstport,
"IpSr... | 71d3f5f6655a91a0b135c18f1369415cd29531f4 | 72,425 |
def to_dict(_object, **extra_keys):
"""
A utility to convert an object with attributes to a dictionary with the
optional feature of slapping extra_keys. Because extra_keys can be
optionally set, it is assumed that any keys that clash will get
overwritten.
Private methods (anything that starts w... | 5a3204273046f36766f4974dcff725c3f8f27873 | 72,426 |
def get_rna_types_from(xrefs, name):
"""
Determine the rna_types as annotated by some database.
Parameters
----------
xrefs : iterable
The list of xrefs to fitler to extract the rna types from.
name : str
The name of the database to use.
Returns
-------
rna_types : ... | 23872b14e8b7555eeda7b807ee2831c00c71665b | 72,428 |
import requests
def get_http_status_code(url: str) -> int:
"""This gets the http status code of a web resource.
Parameters
----------
url : string
The url which the http status code will try and obtain.
Return
------
status_code : int
The status code.
"""
web_requ... | 91765c364076ac32cb717e3285c654ef938af5fb | 72,429 |
def filter_company(job):
"""Filter out company name."""
company_container = job.find('div', attrs={'class': '-name'})
company_name = company_container.get_text().strip()
return company_name | fc6f8215fdb378d6be59be786e2bf92e1e6292d0 | 72,430 |
def float_from_sat(amount: int) -> float:
"""Return the float monetary value equivalent of a satoshi amount."""
return float(amount / 1e8) | d0335d0d71695c8038510605707386c92f0631cb | 72,437 |
def prepare_dataframe(kraken_translate_report_fp,
taxonomic_rank,
taxa_levels,
taxa_levels_idx):
"""Return sets for sample IDs and taxonomy strings.
Parameters
----------
kraken_translate_report_fp: str
filepath to output of "kra... | 6a2e5bad8e15608c83cd2e176425a4e3d69a7d07 | 72,444 |
def compute_in_degrees(digraph):
"""
Makes a directed graph digraph (represented as a dictionary)
and computes the in-degrees for the nodes in the graph
"""
nodes = digraph.keys()
counts = {x:0 for x in nodes}
for key in digraph.keys():
values = digraph[key]
for value in valu... | c07fbaed0b95c78ad9cffbd64719ec160368a65f | 72,446 |
import time
def time_to_epoch(t):
"""
A simple utility to turn a datetime object into a timestamp
:param t: datetime object
:return: integer
"""
return int(time.mktime(t.timetuple())) | 20dd193c564fa99861de252f8a3d0fdbd2782359 | 72,450 |
def truncate_directory(directory: str) -> str:
"""Simple truncation of a given directory path as string."""
if len(directory) > 50:
split_directory = directory.split('/')
prefix_truncated = '/'.join(directory.split('/')[len(split_directory)-5:])
return '.../' + prefix_truncated
else... | a9d4c1958096be181b67983711907b0d15cfa2c7 | 72,451 |
import math
def binary_entropy( p ):
"""Entropy of bernoulli trial"""
return - p * math.log( p ) - ( 1 - p ) * math.log( 1 - p ) | 184ad982248e11983cfb4576a03f5db48b48d61b | 72,452 |
def _process_simple(doc, tag, tag_value):
"""
Generate node for simple types (int, str)
@param doc: xml doc
@param tag: tag
@param tag_value: tag value
@return: node
"""
node = doc.createElement(tag)
node.appendChild(doc.createTextNode(str(tag_value)))
return node | 9c44586c86f975da310a9034354eb9ca1d136d2c | 72,453 |
def smart_selection(labs, to_select, how='any', val=1):
""" Simplify selection of a single or multiple groups
in a pandas dataframe.
Args:
labs (panda dataframe): one-hot-encoded classes membership dataframe
with samples as rows and classes as columns.
to_s... | 49534e60d4e7c90b0763377c03b21a0340f27c03 | 72,456 |
import math
def get_Rost_ID_threshold(L, n=0):
"""
This function returns the Rost sequence identity threshold for a
given alignment of length "L".
@input:
L {int} alignment length
parameter {int} N parameter in the curve (if > 0 more strict)
@return: {Decimal}
"""
return... | e9d5bc41ea40acef751aadac30951a16884c6ed3 | 72,458 |
def truncate_roi(orig_roi, src_image_size):
"""
Returns truncated ROI for source and destination images. Crops ROI so that
image edges are handled correctly.
"""
# Set x position of ROI
if orig_roi[0] < 0:
src_x = 0
dst_x = -orig_roi[0]
w = orig_roi[2] + orig_roi[0]
e... | ce5699a8771585ebffa7470287143e89771c5b25 | 72,459 |
import re
def count_string_characters(string):
"""Count number of characters as displayed in string.
"" -> 0 characters
"abc" -> 3 characters
"aaa\"aaa" -> 7 characters
"\x27" -> 1 character
"""
string = string[1:-1].replace(r'\\', '_').replace(r'\"', '"')
regex = r'\\x[0-9a-f]{2}'
... | 9484a5c9bf3a7a503d09006d76f83922323ac216 | 72,460 |
def parse_courses(courses):
"""
Parse information of all courses that are retrieved from Moodle.
:param courses: Statements for all courses.
:type courses: list(dict(str, int))
:return: A dictionary containing the names and ids of all courses.
:rtype: list(dict(str, int))
"""
courses = ... | 3bad5f4633a4e5cfbdac7fb599fc8bbced72da12 | 72,462 |
def _get_shape_str(shape):
"""Convert image shape to string for filename description
"""
return '{}_{}'.format(*shape[:2]) | b290f415bc5c92c000e5955232f197bbc5cd91e8 | 72,464 |
from io import StringIO
def print_snapshots(ec2, region):
"""
Print a list of snapshots
:param ec2: The boto3 ec2 client
:param region: The region to search in
:return: The nicely formatted list of snapshots to print
"""
snapshots = ec2.describe_snapshots(OwnerIds=['self'])
snapshot_li... | e7d5167e5df20c3e6d41ccf791f22f6edf77799d | 72,469 |
def is_prime(n):
"""
Return True if n is prime, false otherwise.
>>> is_prime(1)
False
>>> is_prime(2)
True
>>> is_prime(19)
True
"""
if n == 1:
return False
i = n - 1
while i > 1:
if n % i == 0 or n == 1:
return False
i -= 1
retu... | baf0d24cae6858b1d7c42b750a4849ba866eb4c6 | 72,471 |
def longestCommonPrefix(*sequences):
"""
Returns longest common prefix occuring in given sequences
Reference: http://boredzo.org/blog/archives/2007-01-06/longest-common-prefix-in-python-2
>>> longestCommonPrefix('foobar', 'fobar')
'fo'
"""
if len(sequences) == 1:
return sequences[0... | a7363e7bb42ce99084419eb6e227a5a051856155 | 72,472 |
def get_full_date(date):
""" Returns a string like 'November 27, 2009' """
return date.strftime("%B %d, %Y") | 823c7802a68d575a6ab39f4cbe352a9fb0fe0514 | 72,474 |
def eliminate_prefix(v, u):
"""
Removes prefix b from the given input word v
If v = uw (u=prefix, w=suffix),
w = u-1 v
Parameters:
-----------------------------------
v: str
A (sub)word
u: str
The prefix to remove
Returns:
-----------------------------------
... | c17d69672e205267a1917b35ad30117300073522 | 72,485 |
def get_hypercube_interpolation_fn(coefficients):
"""Returns function which does hypercube interpolation.
This is only for 2^d lattice aka hypercube.
Args:
coefficients: coefficients of hypercube ordered according to index of
corresponding vertex.
Returns:
Function which takes d-dimension point... | 7db89e0c896ee03065adcc61cee235f10ddf7882 | 72,486 |
def bookValue(firm, date, pdatabase, printWarnings=True, bookUnit=1000000):
"""
Firm's book value as of latest quarterly earnings report preceding date
Relies on naming of pdatabase (compustat) and chronological data for each firm
Returns -1 if no data available
Returns FLOAT
"""
bookQuery =... | 395e43bc920fd5dbe78c2d9be738192cc750570a | 72,490 |
def float_range(x, low, high, strong=True):
""" Check if x is between low and high values.
It works for int and float ranges."""
if strong:
result = low <= x <= high
else:
result = low < x < high
return result | 4dcf957a74f3ddf07ca2768a611d5f8aaf5099a4 | 72,492 |
import torch
def resolvent(A, B, C, z):
"""
A: (... N N)
B: (... N)
C: (... N)
z: (... L)
returns: (... L) represents C (z - A)^{-1} B
"""
if A.is_complex() or B.is_complex() or C.is_complex() or z.is_complex():
dtype = torch.cfloat
else:
dtype = torch.float
N =... | b7e92af5c803042e0c2625f2b03aeed335091058 | 72,493 |
def find_in_list_by_name(some_list: list, name: str):
"""
Helper created to find ModelField by required name
:param some_list: list of objects with name field
:param name: name of object to be found
:raises ValueError: not found
:return: object with required name
"""
for item in some_li... | b1f6450f180121ad9bcaf568eacd03990dc46972 | 72,496 |
def cmp(a, b):
""" Equivalent of python 2 cmp function for python 3 """
return (a > b) - (a < b) | ce93052a446d0296ae53bbeed81463f31a23f0d0 | 72,497 |
def str2bool(txt):
"""
Convert a string to a boolean
:param txt: string object
:return: boolean
"""
if txt.lower() in ['1', 'true', 'yes', 'y']:
return True
elif txt.lower() in ['0', 'false', 'no', 'n']:
return False
else:
raise ValueError("Can't convert \"{}\" t... | dfa06d1908b56f58c423a3b9ed6e1748d37e81e1 | 72,498 |
def isChildDir(parent:str, cand:str) -> bool:
""" Returns true if parent is an ancestor of cand. """
if cand.startswith(parent) and len(cand) > len(parent):
return True
return False | 7468d4981ef8d539efd94ee5c6629d5cd95e5b69 | 72,502 |
def add_arg(p,*args,**kwds):
"""Add an argument or option to a parser
Given an arbitrary parser instance, adds a new
option or argument using the appropriate method
call and passing the supplied arguments and
keywords.
For example, if the parser is an instance of
argparse.ArgumentParser, t... | 0ae10e68e18676045c06d7fc5324af4206f4c7b5 | 72,506 |
def x_point_mid(df_agg):
"""Set the x_point to be mid-way between x_left and x_right"""
res = df_agg.assign(
x_point=lambda df: (df['x_left'] + df['x_right']) / 2.
)
return(res) | 9410c1806b71c3097063c7cc628a69cf4e63aa08 | 72,507 |
def inner_fidget(*args, **kwargs):
"""
define a ValidWidget class as an idiomatic inner widget
:param args: arguments forwarded to the template
:param kwargs: arguments forwarded to the template
"""
def ret(cls):
cls.__is_inner__ = cls.template(*args, **kwargs)
return cls
... | a2d0be0afb1f62d5f8243fcc5c7427c8477c0ddd | 72,508 |
def get_chunk_handlabels(handlabels_list):
""" Get all of the Hand-labels from all of the 'labels' tiers from the handlabels_list
Parameters
----------
handlabels_list : list
List of all Dictionaries containing all of the handlabels for each chunk for one day
shape: [chunk_num] -> {'lab... | c2c5845e7813baf27b37ed0cd7ae4c856414b370 | 72,514 |
def read_embedding_set(args):
"""
Reads a nodelist with vertices to be embedded.
"""
vertices = set()
with open(args.embed_subset, 'r') as f:
for line in f:
vertex = int(line.strip())
vertices.add(vertex)
return list(vertices) | 06401cd3581ccfc1f406ac9c7833381c85865497 | 72,515 |
def entity_char_to_token(entity, sentence):
"""Takes Stanza entity and sentence objects and returns the start and end tokens for the entity.
The misc value in a stanza sentence object contains a string with additional
information, separated by a pipe character. This string contains the
start_char and end_char ... | 9f41843c660614e3af4bc67b25042a399029dfda | 72,519 |
def sort_key(item):
"""Case-insensitive sorting."""
return item['name'].lower() | ccde3887d7eaa7d4cd1c1a44fa547943e505062f | 72,521 |
def smooth_color_func(niter, func):
"""Version of :func:`smooth_color` that accepts a function.
Can be used to pre-calculate a color list outside of a loop.
Parameters
----------
niter : int
number of iterations
func : callable
Examples
--------
>>> from pwtools import mpl... | 87bc0d17e01820ee6b9c5dbf6454128053b9c3e1 | 72,524 |
def lazy_reverse_binmap(f, xs):
"""
Same as lazy_binmap, except the parameters are flipped for the binary function
"""
return (f(y, x) for x, y in zip(xs, xs[1:])) | 1a2a982aa9aa69729ec31b57096b1c6fd34c4199 | 72,528 |
def get_syntax(command, fn, command_prefix):
"""
Read back the syntax argument provided in a command's wrapper. Return it
in a printable format.
:param command: Command being called.
:param fn: Function which the command is wrapped around.
:param command_prefix: Prefix used for commands in chat... | 2780b883bc067805744baa9163ba3ad7786490c3 | 72,534 |
def nucleotides(data, start, end):
"""
:param data: list of string of length 50 nucleotides
:param start: coordinate 0 index
:param end: coordinate 0 index
:return: sequence of nucleotide at chr:start-end
"""
def nucleotide(index): return data[(index // 50) + 1][index % 50].upper()
sequ... | 9c2037d07dcb92433380565c37d064137925fa05 | 72,541 |
def parse_tlpdb_to_dict(tlpdb_path):
"""Reads given tlpdb database and creates dict with packages, their dependencies and files
"""
with open(tlpdb_path, "r") as f:
packages = f.read().split("\n\n")
pkg_dict = {}
for pkg in packages:
if not pkg == "":
pkg_lines = pkg.sp... | c3fb4905a71f98d48dae11e71a7380ec4feeb69d | 72,542 |
def floor_pow2(n):
"""
Find the nearest power of 2 that's <= n
"""
k = 0
n >>= 1
while n:
k += 1
n >>= 1
return k | cf3769cab22ecf80c915b72cc0854f149c9e4407 | 72,543 |
def get_channel_names(stream):
"""
extract channel name from xdf stream
:param stream: dictionnary
xdf stream to parse
:return: list
list of channels names
"""
try:
return [
channel_info["label"][0]
for channel_info in stream["info"]["desc"][0... | da8038cc6f676616518f64e83c4f8889473b046e | 72,546 |
import sqlite3
def connect_to_db(local=True):
"""
initialize connection to local sqlite3
"""
con = None
if local:
# Create a SQL connection to our SQLite database
con = sqlite3.connect("./db/tableTennisData.db")
return con | 8ac48777680e7ff63df856bb61e2db8d3cef6b61 | 72,548 |
def pl2_to_pl(src_dict, scale=1000.):
"""Convert integral flux of PL2 to prefactor of PL"""
index = src_dict['spectral_pars']['Index']['value']
emin = src_dict['spectral_pars']['LowerLimit']['value']
emax = src_dict['spectral_pars']['UpperLimit']['value']
f = src_dict['spectral_pars']['Integral']['v... | 7cc1a57ac8763e08968ea32a93c867311c242785 | 72,551 |
def _compare_cat_hist(b1, b2, h1, h2):
"""
Compare two categorical histograms and return a overlap score based on RMSE
b1 bin edges of hist 1
b2 bin edges of hist 2
h1 histogram values of hist 1
h2 histogram values of hist 2
Return rmse-based overlap score
"""
cbe = list(set(b1) | s... | 7d819a06f2bb9c6b24f001bbcda88824e896a763 | 72,553 |
def convert_8_8_to_float(val_1, val_2):
"""8.8 to float converter"""
return val_1 + (val_2 / 256) | 7e4fee85e497baa207dcf7b532e2c3a1e7d29367 | 72,565 |
import math
def _conv_out_size(input_size, filter_size, stride,
padding="VALID"):
"""
Computes the output size for a given input size after
applying a 1D convolution with stride.
Args:
input_size : integer input size.
filter_size : size of 1D filter.
stride ... | 63bd6c226514bb5c0437fb04174f7ff80cb33757 | 72,566 |
def error_message(e, message=None, cause=None):
"""
Formats exception message + cause
:param e:
:param message:
:param cause:
:return: formatted message, includes cause if any is set
"""
if message is None and cause is None:
return None
elif message is None:
return '%... | 8017f426f8d6b94bbed729e91b48aad8f36e9fad | 72,569 |
def can_candidate_access(application, email):
"""
Can candidate access Application
Match on the authorized email field on Application model. Do not match on
the candidate email field on the Questionnaire model.
Parameters
----------
application : Application
Application that is pot... | 9448dc65cd314d803f0c27933b04e1f4903c8fa6 | 72,570 |
def extension(path : str) -> str:
"""Return the extension of the given path"""
idx = path.rfind('.')
if idx == -1:
return ''
if idx == 0:
return ''
return path[idx+1:] | aacf2b8976094de60c67861ce497f35dcd25adee | 72,571 |
import re
def _clean_sent(sent):
"""
This preprocessing function takes in a sentence object, grabs just the
actual sentence, and runs three regex substitutions to clean up the
sentence for querying.
"""
s = re.sub(r'\s([\.,!?\)\]])', r'\1', sent.get_sentence().lower())
s = re.sub(r'([\(\[]... | 95adc7b79a1663e8e00490077d65a1945ce36737 | 72,572 |
def gene_name_pull(feature):
"""Attempt to grab gene name, if gene name not found, grab locus_tag instead."""
try:
if len(feature.qualifiers['gene']) != 1:
print(feature.qualifiers['gene'])
assert False
return feature.qualifiers['gene'][0]
except KeyError:
if ... | d88d829f02a29fa17a9a94e6ccda6e9091521210 | 72,574 |
from typing import List
def _unique(collection: List[str]) -> bool:
"""
Determine if all elements of a collection are unique.
:param collection: The collection
:type collection: Iterable
:return: `True` if all elements are unique, `False` otherwise
:rtype: bool
"""
return len(set(col... | fe727e13852ea9baf7696a3eda7e5f2ab57d4b5d | 72,575 |
def check_keyword(line, keyword):
"""
Check if the line starts with the keyword
Replaces - for _ for backwards compatibility.
"""
new_line = line.replace("-", "_")
return new_line.startswith(keyword) | 2e9f1902db76527e2ecb3e7c6ce43e37ac889e04 | 72,578 |
def char_tokenizer(string):
"""
Splits a string into individual character symbols.
Args:
string (string): The string to be split into characters.
Returns:
list: The characters of the string.
"""
return list(string) | 2694f670bf862321e42768d63970f04b76782f07 | 72,580 |
def bisect(a, x, lo=0, hi=None, cmp=lambda e1, e2: e1 < e2):
"""
a simplified and generalized version of python's bisect package: https://docs.python.org/3.6/library/bisect.html
return the index where to insert item x in a list a
a must be sorted (in ascending order)
the return value i is such that... | 8fcf5c82f136b93c956069c17fbe338300ddc176 | 72,582 |
import math
def pick(n, k):
"""
Return the number of ways to select k objects from n objects with order
:param n: int
:param k: int
:return: int
>>> pick(1, 0)
1
>>> pick(1, 2)
0
>>> pick(5, 2)
20
"""
return math.factorial(n) // math.factorial(n - k) if n >= k else ... | a0a07a2b8a0194dba994ff19849e381696620728 | 72,588 |
def getDP(directionPointer: int) -> str:
"""
Finds the correct direction pointer string
:param directionPointer: Input direction pointer
:return: direction pointer string
"""
if directionPointer == 0:
return 'r'
if directionPointer == 1:
return 'd'
if directionPointer == ... | 05d02afdb7c20dfc796abb42563d983a2d45316f | 72,594 |
def spark_points_flat(lst, key):
"""
:param lst: list of dictionary
:param key: key value want to flat
:return: string flat with ','
"""
return ','.join(str(dic[key]) for dic in lst) | bdb00610c6a4c0213e6acc2c2f9d02c0e0c3f666 | 72,596 |
import ast
def checker(file_data: str, path: bool = True) -> bool:
"""Given a python file path/content, check whether the given file is syntactically correct or not
Args:
file_data: A path object or file content
path: True if file path is passed instead of its content
Return:
Tru... | bfe2edf400b3d34327292112be5f6a94a2b61d0c | 72,597 |
import inspect
def __get_caller_name(caller_frame):
"""Gets the name of the caller (fully qualified, if possible).
:param caller_frame: A caller's frame.
:type caller_frame: :class:`frame`
:returns: The name of the caller (:class:`str`).
"""
caller_name = caller_frame.f_code.co_name
if ... | 75998e451ded756afcd10a3bfa4a69df662ed82d | 72,598 |
def is_inside(aabb, point):
""" tests if a point is inside an aabb
aabb: (x,y,w,h)
point: (x,y)
"""
x,y,w,h = aabb
u,v = point
return u >= x and u < x+w and \
v >= y and v < y+h | 307996f7089fca486d078f6f3f6e3d2e998d312b | 72,601 |
import re
def get_cupy_release_for(chainer_version):
"""Returns CuPy version required for the given Chainer version."""
m = re.search(r'^v(\d)\.(.+)$', chainer_version)
if m is None:
raise ValueError(chainer_version)
chainer_major = int(m.group(1))
chainer_rest = m.group(2)
if chaine... | 0a3840c884f831d52d47c675a79ce29bddceb109 | 72,602 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.