content stringlengths 39 14.9k | sha1 stringlengths 40 40 | id int64 0 710k |
|---|---|---|
def p_list_formatter(primer_list):
"""
Reformat the primer list (remove unnecessary characters from biopython2 output).
Args:
primer_list (list): list from list_from_gen output
Returns:
primer_dimers (list): list with unnecessary chars removed.
"""
reformat_p_list = []
primer... | 0b1585221a13c3560d511127af782875fcd71732 | 9,466 |
def _repr_rule(iptc_rule, ipv6=False):
""" Return a string representation of an iptc_rule """
s = ''
if ipv6==False and iptc_rule.src != '0.0.0.0/0.0.0.0':
s += 'src {} '.format(iptc_rule.src)
elif ipv6==True and iptc_rule.src != '::/0':
s += 'src {} '.format(iptc_rule.src)
if ipv6==... | e01c3b27ec6ee831a7d88fc87e69e707639ef0b6 | 9,470 |
def add_padding_0_bits(bits_string: str, required_length: int) -> tuple:
"""
Adds 0 to bits string.
Returns tuple - (bits string with padding, number of added 0s)
"""
extra_0_bits_count = 0
while len(bits_string) < required_length:
bits_string += '0'
extra_0_bits_count += 1
r... | fd3eee071821d087b710c33a0beef72431836505 | 9,471 |
def IsInstance(type_):
"""Returns a function which can be used to check whether or not a value is of the given type."""
def Do(item):
return isinstance(item, type_)
return Do | 06f916e8658761a03619834692d78a44d145b514 | 9,472 |
def seq_type(seq):
"""
Determines whether a sequence consists of 'N's only
(i.e., represents a gap)
"""
return 'gap' if set(seq.upper()) == {'N'} else 'bases' | 5555e5cd0ccdbf8f5e7b475c5c983ab54a17fb07 | 9,475 |
def get_ar(bbox):
"""
:param bbox: top left, right down
:return: aspect ratio
"""
[x1, y1, x2, y2] = bbox
return (y2 - y1) / (x2 - x1) | d79eb51eafec917b1754558a9a87307734fd8ac4 | 9,482 |
def validate_image_pull_credentials(image_pull_credentials):
"""
Validate ImagePullCredentialsType for Project
Property: Environment.ImagePullCredentialsType
"""
VALID_IMAGE_PULL_CREDENTIALS = ("CODEBUILD", "SERVICE_ROLE")
if image_pull_credentials not in VALID_IMAGE_PULL_CREDENTIALS:
... | f4953fefbca3ca5906ca58497152b25a07247c9a | 9,485 |
def num_bits(i):
"""Returns the number of bits in an unsigned integer."""
n = 0
while i:
n += 1
i &= i - 1
return n | 3eb664bd642717556af0b2c09314000d70209b44 | 9,486 |
def get_index_of_feature(feature_list, item):
"""
Gets the index of the feature in the provided feature list
:rtype : int
:param feature_list: List of features to search from
:param item: The feature to search
:return: The index where the feature was founded, -1 otherwise
"""
# getting... | 2f2d79d4caf953b60ecf841a23d86e8b4a00b937 | 9,491 |
import math
def sol_rad_from_t(et_radiation, cs_radiation, temperature_min, temperature_max, coastal):
"""
Estimate incoming solar (or shortwave) radiation, *Rs*, (radiation hitting
a horizontal plane after scattering by the atmosphere) from min and max
temperature together with an empirical adjustmen... | 6952aa6509897494551839e412d5a15e51b5e30c | 9,495 |
def moving_avg(v, N):
"""
simple moving average.
Parameters
----------
v : list
data ta to average
N : integer
number of samples per average.
Returns
-------
m_avg : list
averaged data.
"""
s, m_avg = [0], []
for i, x in enumerate(v, 1):
... | 2e71eefb91ac694eaf06c2167e38ef497671145e | 9,496 |
from typing import Union
import re
def get_brackets(title: str) -> Union[str, None]:
"""
Return the substring of the first instance of bracketed text.
"""
regex_brackets = re.search(r"\[(.*?)\]", title)
if regex_brackets is None:
return None
else:
return regex_brackets.group() | f1d985cf79ae881e8aca168c065d40e640a9c1ff | 9,500 |
def _dof(mean_tau, sd_tau2):
"""
Returns the degrees of freedom for the chi-2 distribution from the mean and
variance of the uncertainty model, as reported in equation 5.5 of Al Atik
(2015)
"""
return (2.0 * mean_tau ** 4.) / (sd_tau2 ** 2.) | 9a4a395c9aea7b965a477550c7f254bf744cadc5 | 9,501 |
from typing import List
import json
def compare_apache_profiles(baseline_file, test_file, threshold=0.5) -> List:
"""
Compare baseline Apache access log profile against test profile.
:param baseline_file: file containing baseline profile
:param test_file: file containing test profile
:param thresh... | 0b94ad318fcb61be559767cbdba51def1b6db61f | 9,505 |
def uuid_mole_index(moles, mole_uuid):
"""Return the index of the first mole with the specified uuid."""
for i, mole in enumerate(moles):
if mole["uuid"] == mole_uuid:
return i
return None | 851877da59f6a6dd8c06b9bb2d462f6239d512e7 | 9,507 |
def find_average_record(sen_set, voting_dict):
"""
Input: a set of last names, a voting dictionary
Output: a vector containing the average components of the voting records
of the senators in the input set
Example:
>>> voting_dict = {'Klein': [-1,0,1], 'Fox-Epstein': [-1,-1,-1], 'Rav... | ef0c0aeb5a75c0335de57ae6cca1c013fe59b8b0 | 9,514 |
def get_commit_link(repo_name: str, commit_sha: str) -> str:
"""
Build a commit URL for manual browser access using full repository name and commit SHA1
:param repo_name: full repository name (i.e. `{username}/{repoanme}`)
:param commit_sha: 40 byte SHA1 for a commit
:return: A commit URL
"""
... | a1cf8d30f3e5c5ce3c5fefc719cca7c1c4d92331 | 9,524 |
def msi_file_finder(pth):
"""
Return True if pth represents a msi file file.
"""
return bool(pth.fname.endswith('.msi.txt')) | 35c0d0dac72d44cbdd6f87b280a70917d264db0c | 9,526 |
def get_accuracy(y_true, y_predicted):
"""Compute the accuracy for given predicted class labels.
Parameters
----------
y_true: numpy array
The true class labels of shape=(number_points,).
y_predicted: numpy array
The predicted class labels of shape=(number_points,).
Returns
... | c88a6b51021c9e01133852fa84c6f434043391a5 | 9,532 |
def get_connections(network):
"""
Function creates a dictionary with agent id's as a key and adjacent nodes as a value.
:param network: object of graph
:type network: networkx.classes.graph.Graph
"""
return {agent_id: list(adj_agents.keys()) for (agent_id, adj_agents) in network.adjacency()} | fa614b599c577de5c2554818366159e918c1335b | 9,533 |
def meta_name(file_name):
"""Generate the name of the meta file"""
return "{}.json".format(file_name) | fc168d19c145c4f93fb8d92e3c0daa109aad31b6 | 9,534 |
def concat_body_paragraphs(body_candidates):
"""
Concatenate paragraphs constituting the question body.
:param body_candidates:
:return:
"""
return ' '.join(' '.join(body_candidates).split()) | a0faaa0ae0be0cda007c2af1f6e47f3b745862b3 | 9,536 |
import re
def matchNumbersOnly(value):
"""Match strings with numbers and '.' only."""
if re.match('^[0-9.]+$', value):
return True
return False | 04d782431b79e78f93269c662c747d1f7348c9ec | 9,538 |
def get_sample_mean(values: list) -> float:
"""
Calculates the sample mean (overline x) of the elements in a list
:param values: list of values
:return: sample mean
"""
sample_mean = sum(values) / len(values)
return sample_mean | 182befe514f406340f0b1f37e892ad1add1f0ed2 | 9,543 |
def polyfill_integers(generator, low, high=None, size=None, dtype="int32",
endpoint=False):
"""Sample integers from a generator in different numpy versions.
Parameters
----------
generator : numpy.random.Generator or numpy.random.RandomState
The generator to sample from. I... | b4061e8ec7cb9927bbe4fcce1c847aecdc10052b | 9,544 |
import difflib
import pprint
def pprint_diff(first, second, first_name='first', second_name='second'):
"""Compare the pprint representation of two objects and yield diff lines."""
return difflib.unified_diff(
pprint.pformat(first).splitlines(),
pprint.pformat(second).splitlines(),
fromfile=first... | 5c88916b47cfa970d6ab15caa650540d2dab3c3b | 9,548 |
def ascii(value):
"""Return the string of value
:param mixed value: The value to return
:rtype: str
"""
return '{0}'.format(value) | 11cf1af6567c53a5583d8bdcb6da2431f6b79ba9 | 9,551 |
def find_closest_date(date, list_of_dates):
"""
This is a helper function that works on Python datetimes. It returns the closest date value,
and the timedelta from the provided date.
"""
match = min(list_of_dates, key = lambda x: abs(x - date))
delta = match - date
return match, delta | 57f9ecbf764539fcea495057ba4b908df700b8db | 9,552 |
from collections import Counter
def solve_part_one(id_list: list) -> int:
"""
Calculates the checksum for a list of IDs
:param id_list: Python list containing a list of ID strings
:return: Checksum as defined by the problem
"""
twos, threes = 0, 0
for id in id_list:
id_counter = C... | a4fe4d7b8205492e132175199121f3ed5a58b7b9 | 9,554 |
def is_prerelease(version_str):
"""
Checks if the given version_str represents a prerelease version.
"""
return any([c.isalpha() for c in version_str]) | c6454bb350b2c4e55dbc271f23253aa2e3472802 | 9,556 |
import re
def class_name_to_resource_name(class_name: str) -> str:
"""Converts a camel case class name to a resource name with spaces.
>>> class_name_to_resource_name('FooBarObject')
'Foo Bar Object'
:param class_name: The name to convert.
:returns: The resource name.
"""
s = re.sub('(.)... | b0ac6692c441b0f4cfca4a9b680dc612552795f4 | 9,557 |
def datetime_to_date(dt, org):
"""
Convert a datetime to a date using the given org's timezone
"""
return dt.astimezone(org.timezone).date() | 92565cf65b0c485e6f8649a9a47619f516d0fd35 | 9,558 |
import requests
def current_server_id() -> str:
"""Helper to get the current server id"""
rsp = requests.get("http://localhost:10000/api/servers")
if rsp.status_code != 200:
raise ValueError("Failed to fetch current server id")
return rsp.json()['current_server'] | 8ec4efcc0eeea0b5b62ce5446aece5abdf6fbd66 | 9,560 |
def get_class_name(obj):
"""
Returns the name of the class of the given object
:param obj: the object whose class is to be determined
:return: the name of the class as a string
"""
return obj.__class__.__name__ | 93be3acf545376dc1df43684da75a59e967d2b2f | 9,565 |
def dataset(client):
"""Create a dataset."""
with client.with_dataset(name='dataset') as dataset:
dataset.authors = {
'name': 'me',
'email': 'me@example.com',
}
return dataset | 4f77cd30c58ad74e48280be193f4dd30b0fb5584 | 9,567 |
import grp
def is_existing_group(group_name):
"""Asserts the group exists on the host.
Returns:
bool, True if group exists on the box, False otherwise
"""
try:
grp.getgrnam(group_name)
return True
except KeyError:
return False | 8831281684107d9f4c4511cb4cf3493494269650 | 9,570 |
def median(lst):
"""
Get the median value of a list
Arguments:
lst (list) -- list of ints or floats
Returns:
(int or float) -- median value in the list
"""
n = len(lst)
if n < 1:
return None
if n % 2 == 1:
return sorted(lst)[n//2]
else:
... | b6b7eefdf63490e35e74063995cabd38f4c12089 | 9,573 |
import weakref
def weakref_props(*properties):
"""A class decorator to assign properties that hold weakrefs to objects.
This decorator will not overwrite existing attributes and methods.
Parameters
----------
properties : list of str
A list of property attributes to assign to weakrefs.
... | 4ae42fc4e2dccbb7193a377e122f96c4f7d5112d | 9,575 |
from pathlib import Path
def lglob(self: Path, pattern="*"):
"""Like Path.glob, but returns a list rather than a generator"""
return list(self.glob(pattern)) | eba1b9d6300a1e1aca5c47bedd6ac456430e4d89 | 9,576 |
from typing import Sequence
def parse_attrs(attrs):
"""Parse an attrs sequence/dict to have tuples as keys/items."""
if isinstance(attrs, Sequence):
ret = [item.split(".") for item in attrs]
else:
ret = dict()
for key, value in attrs.items():
ret[tuple(key.split("."))] = value
return ret | 15779e14fbdb9783d91732aa3420ccb18ee6c620 | 9,580 |
def scanD(d, ck, minSupport):
"""
计算候选数据集CK在数据集D中的支持度,
并返回支持度大于最小支持度 minSupport 的数据
Args:
D 数据集
Ck 候选项集列表
minSupport 最小支持度
Returns:
retList 支持度大于 minSupport 的集合
supportData 候选项集支持度数据
"""
# ssCnt 临时存放选数据集 Ck 的频率. 例如: a->10, b->5, c->8
ssCnt = {... | a37fccca461774777bf082ca1b1e2bf3528cc220 | 9,582 |
import codecs
def _readfile(fname, strip="\n"):
"""Shortcut for reading a text file."""
with codecs.open(fname, 'r', 'UTF8') as fp:
content = fp.read()
return content.strip(strip) if strip else content | 5708a91ed7ceb8743bf0e6a40962c80e74996368 | 9,583 |
def eval_request_bool(val, default=False):
"""
Evaluates the boolean value of a request parameter.
:param val: the value to check
:param default: bool to return by default
:return: Boolean
"""
assert isinstance(default, bool)
if val is not None:
val = val.lower()
if val... | 99909909846f3194abc8c83ad84411c3ccd1245c | 9,586 |
def get_category_index_from_categories(categories, category):
"""
Gets the index of a category from the categories dictionary. If the category
doesn't exist, it creates a new entry for that category name and returns
the new index number.
"""
if category not in categories:
categories[cat... | 94ce8e2926c1de55383d5fd11e531d9c81792f9c | 9,589 |
def intervalLength(aa, wrapAt=360.):
"""Returns the length of an interval."""
if wrapAt is None:
return (aa[1] - aa[0])
else:
return (aa[1] - aa[0]) % wrapAt | dbceac2d1606d1bedf7c12b4114c17b70db78a86 | 9,591 |
import json
def read_json(file_path: str) -> dict:
"""Reads json file from the given path.
Args:
file_path (str): Location of the file
Returns:
dict: Json content formatted as python dictionary in most cases
"""
with open(file_path, "r") as f:
return json.load(f) | 251c0ad8597ca2819727f95e7e52aa062444cba2 | 9,595 |
def get_weather_units(units):
"""returns a str representation of units of measurement that corresponds to given system of units.
if units is 'metric' return °C
if units is 'kelvin' return K
by default if units is 'imperial' return °F
Parameters
----------
:param str units: the system of un... | 6a12cb96e98f6ccf95927a79a5e9ffaa0a31d4ab | 9,598 |
from typing import Callable
from typing import Iterable
from typing import Dict
from typing import Any
def groupby_many_reduce(key: Callable, reducer: Callable, seq: Iterable):
"""Group a collection by a key function, when the value is given by a reducer function.
Parameters:
key (Callable): Key function... | 7d08325206bfb78cfe421244af6d91b4cd3ceb56 | 9,600 |
def store(src, rel, dst):
"""
Returns an SQL statement to store an edge into
the SQL backing store.
:param src: The source node.
:param rel: The relation.
:param dst: The destination node.
"""
smt = 'INSERT INTO %s (src, dst) VALUES (?, ?)'
return smt % rel, (src, dst) | 1fcb76ff722fbf0a43c125a4ff42405b12d54ec6 | 9,603 |
def get_output_metadata(packer, sample_dim_name):
"""
Retrieve xarray metadata for a packer's values, assuming arrays are [sample(, z)].
"""
metadata = []
for name in packer.pack_names:
n_features = packer.feature_counts[name]
if n_features == 1:
dims = [sample_dim_name]
... | 7a16ed6878d58be45a3cd63b0a5bec515ab6475e | 9,613 |
def get_sample_interval(info, chan_info):
"""
Get sample interval for one channel
"""
if info['system_id'] in [1, 2, 3, 4, 5]: # Before version 5
sample_interval = (chan_info['divide'] * info['us_per_time'] *
info['time_per_adc']) * 1e-6
else:
sample_inter... | e1a397ad9221c30b70997f0cfb296305e0ca7355 | 9,625 |
def get_input_artifact_location(job):
"""
Returns the S3 location of the input artifact.
"""
input_artifact = job["data"]["inputArtifacts"][0]
input_location = input_artifact["location"]["s3Location"]
input_bucket = input_location["bucketName"]
input_key = input_location["objectKey"]
r... | 282881315313b88882f1df8019f60ae88f654cab | 9,626 |
import hashlib
def getImageHash(img):
""" Calculates md5 hash for a given Pillow image. """
md5hash = hashlib.md5(img.tobytes())
return md5hash.hexdigest() | d7bd7e1857f6849143f07063c045ae206985d4a3 | 9,634 |
import ssl
def create_ssl_context(verify=True, cafile=None, capath=None):
"""Set up the SSL context.
"""
# This is somewhat tricky to do it right and still keep it
# compatible across various Python versions.
try:
# The easiest and most secure way.
# Requires either Python 2.7.9 o... | fe8db07f3d0043224cb3ca739fa43a1e3e69fdae | 9,637 |
import csv
def LoadVNSIM(nsim_csv):
"""Returns dictionary with degraded file key and mean nsim value.
The CSV should have three values: reference path, degraded path, nsim value
Args:
nsim_csv: Path to CSV file with NSIM values, format described above.
Returns:
Dictionary with degraded file key and... | 919d1dcffab7e4a78e0ced2cbeee01126d586c27 | 9,641 |
def getCharOverlapCount(from1, to1, from2, to2):
"""Calculates the number of overlapping characters of the two given areas."""
#order such that from1 is always prior from2
if from1 > from2:
tmp = from1
from1 = from2
from2 = tmp
tmp = to1
to1 = to2
to2 = tmp
... | 66ea7cbc9408d41de002c96e40705d4dd45f9ad5 | 9,642 |
import re
def clean_python_name(s):
"""Method to convert string to Python 2 object name.
Inteded for use in dataframe column names such :
i) it complies to python 2.x object name standard:
(letter|'_')(letter|digit|'_')
ii) my preference to use lowercase and adhere
... | d77eaa81607aabf8cae62e2a9c36a51e8428aac4 | 9,646 |
def count_distinct_col(curs, table_name, col='y'):
"""Queries to find number of distinct values of col column in table in
database.
Args:
curs (sqlite3.Cursor): cursor to database
table_name (str): name of table to query
col (str): name of column to find number of distinct values fo... | c346b8463eeb4faec645917831f7bde8f42ed5e1 | 9,650 |
import struct
def encode_string(input_string):
"""Encode the string value in binary using utf-8
as well as its length (valuable info when decoding
later on). Length will be encoded as an unsigned
short (max 65535).
"""
input_string_encoded = input_string.encode("utf-8")
length = len(input... | ecb26ce97cbebfe79b694e96b6e16d50069858b4 | 9,656 |
def parse_vmin_vmax(container, field, vmin, vmax):
""" Parse and return vmin and vmax parameters. """
field_dict = container.fields[field]
if vmin is None:
if 'valid_min' in field_dict:
vmin = field_dict['valid_min']
else:
vmin = -6 # default value
if vmax is No... | a7c096e4648662a5efe59c38de016e586c718ffb | 9,658 |
def fib_mem(n, computed={0:0,1:1}):
"""find fibonacci number using memoization"""
if n not in computed:
computed[n] = fib_mem(n-1, computed) + fib_mem (n-2, computed)
return computed[n] | 5d25c22ccdc5ea41fbd0faf21a8b35ac535acaef | 9,661 |
def get_hash_tuple(a_dict, included_keys=None):
""" Helps in hashing a dictionary by flattening it to a flat list of its keys and values, and then converting it into a tuple (which is what the hash function expects). """
if included_keys is not None:
a_dict = {included_key:a_dict[included_key] for inclu... | b35feea54e6e4446ac1097487445027a07751910 | 9,662 |
def get_cfg_option(cfg, sec, opt, verbose=False):
"""
Retrieve value of a specific option of a configuration.
Parameters
----------
cfg : configparser.ConfigParser()
Configuration as retrieved by the function read_cfg_file().
sec : str
The section in which the option is located.... | 1f387c63d241f1364aa17caec76efe3b33f41b88 | 9,664 |
from typing import Callable
def check_callback(callback):
"""
Check if callback is a callable or a list of callables.
"""
if callback is not None:
if isinstance(callback, Callable):
return [callback]
elif (isinstance(callback, list) and
all([isinstance(c, Cal... | 1e0be3680c934a79777dbe99a47ecc406df19d2a | 9,671 |
def fasta_name_seq(s):
"""
Interprets a string as a FASTA record. Does not make any
assumptions about wrapping of the sequence string.
"""
DELIMITER = ">"
try:
lines = s.splitlines()
assert len(lines) > 1
assert lines[0][0] == DELIMITE... | e450455710a945df25ad2cf4cc3c7f9ad662e7d3 | 9,676 |
def get_commit_timestamps(commits):
"""Get all commit timestamps for the given ebuild.
Args:
commits (list[Commit]): The commits in question.
Returns:
list[int]: The uprev commit unix timestamps, in order.
"""
return [int(commit.timestamp) for commit in commits] | 72694219664d0d6cf83d793e9ccce2b0642ec89f | 9,678 |
def commonprefix(m):
"""Given a list of pathnames, returns the longest common leading component without trailing /"""
if not m:
return ""
m = [p.rstrip("/").split("/") for p in m]
s1 = min(m)
s2 = max(m)
s = s1
for i, (c1, c2) in enumerate(zip(s1, s2)):
if c1 != c2:
... | 4d0bb25fd1eb1dbcd4ee28f67b61574751b6e091 | 9,681 |
def edgecolor_by_source(G, node_colors):
""" Returns a list of colors to set as edge colors based on the source node for each edge.
Parameters
----------
G : graph.
A networkx graph.
node_colors : list
List of node colors.
Example
--------
>>> colormap = {'male':... | 961205e100cf208f5471c08afdd8b3c7328713c0 | 9,682 |
def build_tuple_for_feet_structure(quantity):
"""
Builds the tuple required to create a FeetAndInches object
:param quantity: string containing the feet, inches, and fractional inches
:return: tuple containing feet, inches, and calculated fractional inches
"""
feet = float(quantity[0])
inche... | 2a66e7bf859e120d224c097a628445342a987067 | 9,685 |
def _all(itr):
"""Similar to Python's all, but returns the first value that doesn't match."""
any_iterations = False
val = None
for val in itr:
any_iterations = True
if not val:
return val
return val if any_iterations else True | bb1145abaaaa1c6910371178ca5ebe68600bb287 | 9,686 |
def no_init(_data, weights):
"""
Return the entered weights.
Parameters
----------
_data: ndarray
Data to pick to initialize weights.
weights: ndarray
Previous weight values.
Returns
-------
weights: ndarray
New weight values
Notes
-----
Useful ... | f120b49ab26fa1051360b4e4ae85dd07025ae5cc | 9,687 |
import uuid
def is_valid_uuid(val):
"""
Check if a string is a valid uuid
:param val: uuid String
:return: Returns true if is a string is a valid uuid else False
"""
try:
uuid.UUID(str(val))
return True
except ValueError:
return False | d04f658d3ae2fa85377e110b0a6716bc34ee9df0 | 9,689 |
def convert_to_hexadecimal(bits, padding):
"""
Converts bits to a hexadecimal character with padding.
E.g.
Converts [False, False, False, True], 0 to "1".
Converts [True, False, False, False], 2 to "08"
Args:
bits: List of boolean values.
padding: Integer of number of ... | b8cd1647a24072278aca65f7734934acd93d8f12 | 9,690 |
import string
def _sanitize_title(title):
""" Remove all non alphanumeric characters from title and lowercase """
alphanumeric = string.ascii_lowercase + string.digits + ' '
title = title.lower()
title = "".join(filter(lambda x: x in alphanumeric, title))
return title | 6f0d1818140bc2a50b160f73b8b4590be8f31891 | 9,691 |
def IsBefore(version, major, minor, revision):
"""Decide if a given version is strictly before a given version.
@param version: (major, minor, revision) or None, with None being
before all versions
@type version: (int, int, int) or None
@param major: major version
@type major: int
@param minor: minor... | 3fe9f995b90d7406d0b0366b0bbe5a940f975893 | 9,692 |
def ts_grismc_sim(pixels):
"""
Simple analytic wavelength calibration for Simulated GRISMC data
"""
disp = 0.0010035 ## microns per pixel (toward positive X in raw detector pixels, used in pynrc)
undevWav = 4.0 ## undeviated wavelength
undevPx = 1638.33
wavelengths = (pixels - undevPx) ... | f3491fea1fa1e8833384711076e6187f0f6cb42b | 9,699 |
def get_profile_avatar_upload_to(instance, filename):
""" Returns a valid upload path for the avatar associated with a forum profile. """
return instance.get_avatar_upload_to(filename) | 840e7482b225c0a456dbc8cd967203aa542945f8 | 9,700 |
def parse_bool_token(token):
"""
Parses a string token to convert it to its equivalent boolean value ignoring
the case of the string token or leaves the token intact if it cannot.
:param token:
String to convert to ``True`` or ``False``.
:type token:
``str``
:return:
``T... | bd9de30ee85921ba72a46e83eb96a0af104f998d | 9,702 |
def predict_by_moving_avg_growth(stock, s, **_):
"""Returns predicted value of a stock
Predicts the next price of a stock by extrapolating the moving average and its growth.
Parameters
----------
stock : :obj:`stock`
Stock to be predicted.
s : int
Number of data points used to... | c8e02b9c55bd339ff6f1793b697ba46647331326 | 9,706 |
def select_data(df, countries_list, regions_list, ages_list, genders_list):
"""Extracts from the dataset the data corresponding to many criterias.
Parameters:
-----------
df : Pandas DataFrame
dataset
countries_list : list of str
countries to be selected
regions_list : ... | de6e24966f3060728657a4cc6685c8203bfa85e7 | 9,710 |
def percentage(value, precision=2):
"""Convert `float` to #.##% notation as `str`.
A value of 1 = `"100.00%"`; 0.5 = `"50.00%"`"""
return f"{value:.{precision}%}" | 7abd3fafa8fc6f8323ca448ff5022faa0f83aa60 | 9,717 |
import re
def findAlphanumeric(line):
"""Parse string to extract all non-numeric strings"""
return re.findall(r'^\w+', line) | 7ac210f35d347532ff9e68b4fd6f6f978b0c61ea | 9,718 |
def rep(data):
"""Checks if all labels are represented
in the dataset `data`."""
labels = [0, 1]
# Iteratively check if all labels are represented
for i in range(len(data) - 1):
row = data[i]
label = row["label"]
contains = label in labels
if contains and labels:
... | 803c561c48fec10c44154138e83e95405054dad5 | 9,720 |
import numbers
def torch_item(x):
"""
Like ``x.item()`` for a :class:`~torch.Tensor`, but also works with numbers.
"""
return x if isinstance(x, numbers.Number) else x.item() | dae9881c21a305b42e5c488723a88beb117bf90f | 9,724 |
def count(grid, c):
"""
Count the occurrences
of an object "c" in
the 2D list "grid".
"""
acc = 0
for row in grid:
for elem in row:
acc += c == elem
return acc | 6a497b5d052ce8e1d2619f2278010ecd41126a42 | 9,725 |
def config_retry_strategy(retry):
"""Generate retry strategy."""
if not isinstance(retry, int):
raise ValueError("Parameter retry should be a number")
return {"limit": retry, "retryPolicy": "Always"} | cb436261391e57e845ac5019c7906a56edc2db64 | 9,726 |
def interval(lower_, upper_):
"""Build an interval."""
if lower_ <= upper_:
return lower_, upper_
return None | 3dd1b0c04c9cad8e5f8a69e5c348f07a7542fe7b | 9,728 |
def fetch_links(html):
"""
Fetch all links on a given page and return their hrefs in a list
"""
elements = html.cssselect('a')
return [e.get('href') for e in elements if e.get('href') is not None] | f97f610e5baeb3e3b304c3093a5e27fc0b8de551 | 9,729 |
def echo_handler(ex, *args, **kwargs):
"""
Example error handler which echoes the exception and the arguments.
"""
argstring = ','.join(['%s' % arg for arg in args])
return '%s/%s/%s' % (ex.message, argstring, kwargs) | 29ca4f7663e9c3bf1893bf3f4ab84c8744827ec3 | 9,731 |
import json
def load_config(config_name):
"""
Loads a json config file and returns a config dictionary.
:param config_name: the path to the config json
"""
with open(config_name) as config_file:
config = json.load(config_file)
return config | 5920d21c67133d2d106863910fdd8db95efc94e6 | 9,733 |
def get_by_name(opname, operators):
"""Return operator class instance by name.
Parameters
----------
opname: str
Name of the sklearn class that belongs to a TPOT operator
operators: list
List of operator classes from operator library
Returns
-------
ret_op_class: class
... | 29692c00ae034c391582ab7dd40a1d728406e73f | 9,735 |
def get_sub_text_from_xml_node( xmlnode, _text=None ):
"""
Concatenates the content at and under the given ElementTree node, such as
text = get_sub_text_from_xml_node( xmlnode )
"""
if _text == None:
_text = []
if xmlnode.text:
_text.append( xmlnode.text )
for nd in xm... | 620200d5ba782f5696c720ba4da722204783bd17 | 9,737 |
def cmp_char(a, b):
"""Returns '<', '=', '>' depending on whether a < b, a = b, or a > b
Examples
--------
>>> from misc_utils import cmp_char
>>> cmp_char(1, 2)
'<'
>>> print('%d %s %d' % (1, cmp_char(1,2), 2))
1 < 2
Parameters
----------
a
Value to be compare... | 7e8183564f888df3cce65f2bbbeb659aec43928c | 9,744 |
def get_command_name(cmd, default=''):
"""Extracts command name."""
# Check if command object exists.
# Return the expected name property or replace with default.
if cmd:
return cmd.name
return default | f77a73d1ff24ec74b1c7cf10f89c45fab41fed20 | 9,746 |
import hashlib
def get_str_md5(content):
"""
Calculate the MD5 for the str file
:param content:
:return:
"""
m = hashlib.md5(content) # 创建md5对象
return m.hexdigest() | c0e864288d8d6af2fe31b5cb5afe54bfe83e2fb3 | 9,750 |
def make_test(row):
"""
Generate a test method
"""
def row_test(self):
actual = row.get("_actual")
if actual in ("P", "F"):
if actual == "P":
self.assertMeansTest("eligible", row)
else:
self.assertMeansTest("ineligible", row)
... | 083117f44687c56a7a33cfa74776baea6b40048c | 9,751 |
def _find_last_larger_than(target, val_array):
"""
Takes an array and finds the last value larger than the target value.
Returns the index of that value, returns -1 if none exists in array.
"""
ind = -1
for j in range(len(val_array), 0, -1):
if val_array[j - 1] > target:
ind ... | dbdba59ba35b502669082c8416159770843b7312 | 9,766 |
import struct
def readStruct(fb, structFormat, seek=False, cleanStrings=True):
"""
Return a structured value in an ABF file as a Python object.
If cleanStrings is enabled, ascii-safe strings are returned.
"""
if seek:
fb.seek(seek)
varSize = struct.calcsize(structFormat)
byteStri... | 1920c69f1881698a3898774be95e8f10a462d936 | 9,767 |
def abspath(newpath, curpath):
"""Return the absolute path to the given 'newpath'.
The current directory string must be given by 'curpath' as an absolute
path.
"""
assert newpath
assert curpath
assert curpath.startswith('/')
subdirs = newpath.split('/')
if not subdirs[0] or curpath... | 0b1416492891121f433ce3bfbf934601bfc96f06 | 9,770 |
def get_by_string(source_dict, search_string, default_if_not_found=None):
"""
Search a dictionary using keys provided by the search string.
The search string is made up of keywords separated by a '.'
Example: 'fee.fie.foe.fum'
:param source_dict: the dictionary to search
:param search_string: se... | 59386f5777805f2e7c5a7c7204c56d3d5792c190 | 9,772 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.