content stringlengths 35 416k | sha1 stringlengths 40 40 | id int64 0 710k |
|---|---|---|
def tobin(data, width):
"""
"""
data_str = bin(data & (2**width-1))[2:].zfill(width)
return [int(x) for x in tuple(data_str)] | 1679bc6826cbfd226e99f33dbfd049a284c26a75 | 705,008 |
def open_file_externally(path: str) -> None:
"""open_file_externally(path: str) -> None
(internal)
Open the provided file in the default external app.
"""
return None | 8bb6f5c19ad89fbef59e2ecbec89d5e2b5d05783 | 705,010 |
def counter():
"""Creates a counter instance"""
x = [0]
def c():
x[0] += 1
return x[0]
return c | 0f78a34b53bc5cc8b125a939cd88f58b047607a0 | 705,011 |
import re
def Element(node, tag, mandatory=False):
"""Get the element text for the provided tag from the provided node"""
value = node.findtext(tag)
if value is None:
if mandatory:
raise SyntaxError("Element '{}.{}' is mandatory, but not present!".format(node.tag, tag))
return... | 2173f1ff50f8c685496d9b2708b19f1d6d808fb5 | 705,012 |
import base64
def fix_string_attr(tfjs_node):
"""
Older tfjs models store strings as lists of ints (representing byte values). This function finds and replaces
those strings, so protobuf can correctly decode the json.
"""
def fix(v):
if isinstance(v, list):
return base64.encode... | c137144fd9a42134451d2c49c93b20d562f1188b | 705,013 |
def maximumProduct(nums):
"""
:type nums: List[int]
:rtype: int
"""
nums = sorted(nums)
first_option=nums[0]*nums[1]*nums[-1]
second_option=nums[-3] * nums[-2] * nums[-1]
return first_option if first_option > second_option else second_option | 2ebbc11893499d18fcbf7630fc815b07abf329fd | 705,014 |
import os
def get_config_filepath():
"""Return the filepath of the configuration file."""
default_config_root = os.path.join(os.path.expanduser('~'), '.config')
config_root = os.getenv('XDG_CONFIG_HOME', default=default_config_root)
return os.path.join(config_root, 'zoia/config.yaml') | 53d78749adf56219ca08b3b4556901241608a57d | 705,015 |
def friction_fnc(normal_force,friction_coefficient):
"""Usage: Find force of friction using normal force and friction coefficent"""
return normal_force * friction_coefficient | 7c25e651d7ef8990eab049a5b356f5470496af8e | 705,016 |
def last_char(text: str, begin: int, end: int, chars: str) -> int:
"""Returns the index of the last non-whitespace character in string
`text` within the bounds [begin, end].
"""
while end > begin and text[end - 1] in chars:
end -= 1
return end | 5d59cd50fb99593d5261513327b9799fc175cd6c | 705,017 |
import time
def next_tide_state(tide_info, current_time):
"""Compute next tide state"""
# Get next tide time
next_tide = tide_info.give_next_tide_in_epoch(current_time)
if next_tide.get("error") == None:
tidetime = time.strftime("%H:%M", time.localtime(next_tide.get("tide_time")))
tide... | cc4f78cf41aa76d3788b69daaf64f4711d68714f | 705,019 |
def convert_idx(text, tokens):
"""
Calculates the coordinates of each start
end spans of each token.
:param text: The text to extract spans from.
:param tokens: The tokens of that text.
:return: A list of spans.
"""
current = 0
spans = []
for token in tokens:
current = ... | 6022dca6591ae4a9bea3902af09ff59fee7d5cd5 | 705,020 |
import os
def get_materials():
"""return _materials dictionary, creating it if needed"""
mat = {}
fname = 'materials.dat'
if os.path.exists(fname):
fh = open(fname, 'r')
lines = fh.readlines()
fh.close()
for line in lines:
line = line.strip()
if... | b89b230954d5690314069810b4595a49557e6620 | 705,021 |
import subprocess
import os
def decoratebiom(biom_file, outdir, metadata, core=""):
"""inserts rows and column data
"""
out_biom = '.'.join(biom_file.split('.')[0:-1]) + '.meta.biom'
cmd_sample = f"biom add-metadata -i {biom_file} -o {out_biom} -m {metadata} --output-as-json"
res_add = subprocess.... | 1c327110ba7b27d710dced5e3d59cfabf3f440fc | 705,022 |
def get_arg_name(node):
"""
Args:
node:
Returns:
"""
name = node.id
if name is None:
return node.arg
else:
return name | fecee0dfa53bbb4e1d520e13e5e2363e9035454b | 705,023 |
import ast
def parse_code_str(code_str) -> ast.AST:
"""Parses code string in a computation, which can be incomplete.
Once we found something that leads to error while parsing, we should handle it here.
"""
if code_str.endswith(":"):
code_str += "pass"
try:
return ast.parse(code_st... | ed0c2101dd38ca5e2fc390db3ba94b7fe13ff44d | 705,025 |
def fibonacci_list(n):
"""
用列表缓å˜ä¸é—´çš„计算结果
:param n: n>0
:return
"""
lst = [0, 1, 1]
while len(lst) < n + 1:
ln = len(lst)
lst.append(lst[ln - 1] + lst[ln - 2])
return lst[0] if n < 0 else lst[n] | 02890bd5877c49d5e4d7f053a64dd9cfdeaa7d7d | 705,026 |
def merge(line):
"""
Function that merges a single row or column in 2048.
"""
result = []
count = 0
newline = []
result2 = []
count2 = 0
for a in range(len(line)):
result.append(0)
for a in range(len(line)):
result2.append(0)
for num in line:
if n... | 5992c1bc48af124b069fd31419fec5b6edd5f3ab | 705,027 |
def _perc(a, b):
"""
Funzione di utility: fa il rapporto tra "a" e "b", ritornandone la percentuale a due cifre
"""
return 'N/A' if b == 0 else round(100.0 * a / b, 2) | aa0f4c0fa09dc77b422b3779d0e9e2484b0df348 | 705,028 |
def shift_left_bit_length(x: int) -> int:
""" Shift 1 left bit length of x
:param int x: value to get bit length
:returns: 1 shifted left bit length of x
"""
return 1 << (x - 1).bit_length() | 854e79309125c60c6e5975685078809fb4c016a4 | 705,029 |
import argparse
def cli():
"""Parse and return command line arguments."""
parser = argparse.ArgumentParser()
parser.add_argument(
'file',
nargs='?',
default='/home/sam/notes/2020-08-28_5.md',
help='reading list file for reading/writing markdown notes'
)
args = parse... | 80a6ee8ff618aa9cfaadfddab7daccff3fe7fa1e | 705,030 |
from typing import List
def get_function_contents_by_name(lines: List[str], name: str):
"""
Extracts a function from `lines` of segmented source code with the name `name`.
Args:
lines (`List[str]`):
Source code of a script seperated by line.
name (`str`):
The name ... | 60239b0063e83a71641d85194f72a9cc61221177 | 705,031 |
import ctypes
from ctypes.util import find_library
import errno
def create_linux_process_time():
"""
Uses :mod:`ctypes` to create a :func:`time.process_time`
on the :samp:`'Linux'` platform.
:rtype: :obj:`function`
:return: A :func:`time.process_time` equivalent.
"""
CLOCK_PROCESS_CPUTIM... | d1c479e059ad17c8377db0f6012a7e8ab55b1905 | 705,032 |
import json
def get_json(obj, indent=4):
"""
Get formatted JSON dump string
"""
return json.dumps(obj, sort_keys=True, indent=indent) | be1376fcb9e820cc5012f694ca830ba0c52b5fef | 705,033 |
def build_operation(id, path, args, command="set", table="block"):
"""
Data updates sent to the submitTransaction endpoint consist of a sequence of "operations". This is a helper
function that constructs one of these operations.
"""
if isinstance(path, str):
path = path.split(".")
retu... | 74656a7568a6d705c9c24c091660b93d16977512 | 705,034 |
def compute_min_refills(distance: int, tank: int, stops: list):
"""
Computes the minimum number of gas station pit stops.
>>> compute_min_refills(950, 400, [200, 375, 550, 750])
2
>>> compute_min_refills(10, 3, [1, 2, 5, 9])
-1
Example 3:
>>> compute_min_refills(200, 250, [100, 150])
... | 41dff6085f3b46b191c40c3dde9b68ee3ee41e3e | 705,036 |
def invert_dict(d):
"""Invert dict d[k]=v to be p[v]=[k1,k2,...kn]"""
p = {}
for k, v in d.items():
try:
p[v].append(k)
except KeyError:
p[v] = [k]
return p | 1438ad5879cccf89030cb96dc5ae6c024f8e417c | 705,037 |
def _upper(string):
"""Custom upper string function.
Examples:
foo_bar -> FooBar
"""
return string.title().replace("_", "") | 04ad1596657736847e909e0c4937afc407ea1f60 | 705,038 |
import re
def escape_sql_string(string: str) -> str:
"""
Escapes single quotes and backslashes with a backslash and wraps everything between single quotes.
"""
escaped_identifier = re.sub(r"(['\\])", r"\\\1", string)
return f"'{escaped_identifier}'" | 68f91b6a5c5bfcec6298f6b6f5c7dfb6b7a095f5 | 705,039 |
def _round_to_base(x, base=5):
"""Round to nearest multiple of `base`."""
return int(base * round(float(x) / base)) | beccfe2951b9fcc7aafef57fd966418df1ce2cc1 | 705,040 |
def performStats(dataArray):
"""
Statically calculate and assign summed values of occurances to each entry
"""
yearArray = [[0,0] for i in range(20)]
for entry in dataArray:
oSum = 0
nSum = 0
for k, v in entry.old.items():
# print(k,v)
oSum += v
... | 444c291504783c6cf353c9dad0b4a33c0c4fa172 | 705,041 |
from typing import Any
def ispointer(obj: Any) -> bool:
"""Check if a given obj is a pointer (is a remote object).
Args:
obj (Any): Object.
Returns:
bool: True (if pointer) or False (if not).
"""
if type(obj).__name__.endswith("Pointer") and hasattr(obj, "id_at_location"):
... | 34bdf58b8352a11d878043ee2611d0b7c2a0dae5 | 705,042 |
def context():
"""context: Overwritten by tests."""
return None | 1bd0bc8ca8c9829ffcb7b141b7cf64dfcd87df45 | 705,043 |
def svm_predict(model, samples):
"""Predicts the response based on the trained model"""
return model.predict(samples)[1].ravel() | a510a64e602bbe14a3aa192cacd11b996704d91e | 705,044 |
def __none_to_zero(string):
"""
Return '0' if the string is "none" or "null";
return the string itself otherwise.
@type string: C{string}
@param string: The string to test for values of "none" or "null".
@rtype: C{string}
@return: '0' if the string is "none" or "null", the string itself
... | 45da6720f4e8b6047e161dfe985421c8c7b37a38 | 705,045 |
import glob
import os
def include(d, e):
"""Generate a pair of (directory, file-list) for installation.
'd' -- A directory
'e' -- A glob pattern"""
return (d, [f for f in glob.glob('%s/%s'%(d, e)) if os.path.isfile(f)]) | b1afcf1698a2991001c480cc009bbe1858ce8120 | 705,046 |
def ubatch_to_csv(batch):
"""
Utility function to convert a batch of APIUser data to CSV.
"""
permkey = 'permissions_dict'
fields = [k for k in batch[0].keys() if k != permkey]
fields.extend(batch[0][permkey].keys())
return '{}\n{}'.format(','.join(fields), '\n'.join([
','.join([str(... | 9950cb8e1f79f2cc37580142a125717e7e534de1 | 705,047 |
def guid_to_num(guid):
"""
Convert a DHT guid to an integer.
Args:
guid: The guid to convert, as a string or unicode, in
hexadecimal.
Returns:
An integer corresponding to the DHT guid given.
"""
return int(guid.rstrip('L'), base=16) | 7da3e7a60b6ae3410baab62083714f47a3afc790 | 705,048 |
import itertools
def gather_slice_list_items(slices, key):
"""For a list of slices, get the flattened list of all of a certain key."""
return list(itertools.chain(*[s[key] for s in slices if key in s])) | 068b511aefa124f9881f0d8cdc4d115b15922066 | 705,049 |
def contributions(datafile):
""" text data file => list of string """
contribs = []
with open(datafile, 'r') as data:
for line in data.readlines():
line = line.strip()
line_data = line.split(" ")
info_string = " ".join(line_data[:-1])
contrib = {}
con... | 37c5743df822be2cefdbe0bad60db35491ea599d | 705,050 |
import random
def randomize_demand(demand):
"""Return a randomized demand when given a static demand"""
return random.uniform(0, 2.25) * demand | 01eed8f0008e71af117920782a2a42b566055a89 | 705,051 |
import argparse
def parse_args(args):
"""define arguments"""
parser = argparse.ArgumentParser(description="go_term_enrichment")
parser.add_argument(
"file_names",
type=str,
help="Name of folder and filenames for the promoters extracted",
)
parser.add_argument(
"go_d... | 9501ca0e9e603231751a2e7fe7a1dcf90f753be4 | 705,052 |
import subprocess
def clip(text):
"""
Attempts to copy the specified text to the clipboard, returning
a boolean indicating success.
"""
text_bytes = text.encode()
try:
pbcopy = subprocess.Popen("pbcopy", stdin=subprocess.PIPE, stdout=subprocess.PIPE)
pbcopy.communicate(text_bytes)
return(not pbcopy.... | 7096bc53dfc1d33af0536143ebb7d09c23e29e0f | 705,053 |
def get_item():
"""Returns a dict representing an item."""
return {
'name': 'Nikon D3100 14.2 MP',
'category': 'Cameras',
'subcategory': 'Nikon Cameras',
'extended_info': {}
} | 692c3d83ee1cc04026e71b7ad7357ebd9930f47f | 705,054 |
import torch
def abs_(input):
"""
In-place version of :func:`treetensor.torch.abs`.
Examples::
>>> import torch
>>> import treetensor.torch as ttorch
>>> t = ttorch.tensor([12, 0, -3])
>>> ttorch.abs_(t)
>>> t
tensor([12, 0, 3])
>>> t = ttorch.t... | 65b32c91cf00a72b94b950d0e65cca71390b8c24 | 705,055 |
import textwrap
def dedent(text):
"""Remove any common leading whitespace from every line in a given text."""
return textwrap.dedent(text) | 514f9f41feac1c19ff92d6c9258bf54d7d3d7bd8 | 705,056 |
def enumerate_square(i, n):
"""
Given i in the range(n^2-n) compute a bijective mapping
range(n^2-n) -> range(n)*range(n-1)
"""
row = int(i // (n-1))
col = int(i % (n-1))
if col >= row:
col += 1
return row, col | 93d3465c88a7bc9952161524fded4d7250131a65 | 705,057 |
import re
def get_playback_time(playback_duration):
""" Get the playback time(in seconds) from the string:
Eg: PT0H1M59.89S
"""
# Get all the numbers in the string
numbers = re.split('[PTHMS]', playback_duration)
# remove all the empty strings
numbers = [value for value in numbers if v... | 6a68c68ce465610b57626a725ac9c8889b527fdb | 705,058 |
def _binary_array_to_hex(arr):
"""
internal function to make a hex string out of a binary array
"""
h = 0
s = []
for i, v in enumerate(arr.flatten()):
if v:
h += 2**(i % 8)
if (i % 8) == 7:
s.append(hex(h)[2:].rjust(2, '0'))
h = 0
return "... | b705e4dc1dfc48f92f7c97dd7ba9d4dd4c4d0a98 | 705,059 |
def float_nsf(num, precision=17):
"""n-Significant Figures"""
return ('{0:.%ie}' % (precision - 1)).format(float(num)) | c2390b69364455adc6220e1e4aad81d7081bd5e4 | 705,060 |
def from_literal(tup):
"""Convert from simple literal form to the more uniform typestruct."""
def expand(vals):
return [from_literal(x) for x in vals]
def union(vals):
if not isinstance(vals, tuple):
vals = (vals,)
v = expand(vals)
return frozenset(v)
if not isinstance(tup, tuple):
... | a06d35e27512bfeae030494ca6cad7ebac5c7d2c | 705,061 |
def print_result(error, real_word):
"""" print_result"""
if error == 5:
print("You lost!")
print("Real word is:", real_word)
else:
print("You won!")
return 0 | 598814ac64ac767c102080a0a82541d3b888843c | 705,062 |
def mongo_convert(sch):
"""Converts a schema dictionary into a mongo-usable form."""
out = {}
for k in sch.keys():
if k == 'type':
out["bsonType"] = sch[k]
elif isinstance(sch[k], list):
out["minimum"] = sch[k][0]
out["maximum"] = sch[k][1]
elif is... | 0208ceda058042a9f44249a1b724c4b7883afec1 | 705,063 |
import math
def discounted_cumulative_gain(rank_list):
"""Calculate the discounted cumulative gain based on the input rank list and return a list."""
discounted_cg = []
discounted_cg.append(rank_list[0])
for i in range(1, len(rank_list)):
d = rank_list[i]/math.log2(i+1)
dcg = d + disco... | eaa5ad6185e2abb239097be5399dffd82d143fd3 | 705,064 |
import sys
import os
def ancienne_fonction_chemin_absolu(relative_path):
"""
Donne le chemin absolu d'un fichier.
PRE : -
POST : Retourne ''C:\\Users\\sacre\\PycharmProjects\\ProjetProgra\\' + 'relative_path'.
"""
base_path = getattr(sys, '_MEIPASS', os.path.dirname(os.path.ab... | a33db91a2bd72273acc14caea415181297c16318 | 705,065 |
def get_form_field_names(form_class):
"""Return the list of field names of a WTForm.
:param form_class: A `Form` subclass
"""
unbound_fields = form_class._unbound_fields
if unbound_fields:
return [f[0] for f in unbound_fields]
field_names = []
# the following logic has been taken fr... | 27c91a1e3c1b71f69d44747955d59cee525aa50e | 705,066 |
def format_dnb_company_investigation(data):
"""
Format DNB company investigation payload to something
DNBCompanyInvestigationSerlizer can parse.
"""
data['dnb_investigation_data'] = {
'telephone_number': data.pop('telephone_number', None),
}
return data | 9c27990bad98b36649b42c20796caabeaae1e21b | 705,067 |
def calculate_relative_enrichments(results, total_pathways_by_resource):
"""Calculate relative enrichment of pathways (enriched pathways/total pathways).
:param dict results: result enrichment
:param dict total_pathways_by_resource: resource to number of pathways
:rtype: dict
"""
return {
... | 7060e032f2a619929cfcf123cf0946d7965b86de | 705,069 |
def clean_name(name):
"""Clean a name string
"""
# flip if in last name, first name format
tokens = name.split(',')
if len(tokens) == 2:
first, last = tokens[1], tokens[0]
else:
first, last = name.split(' ')[:2]
# remove punctuation
first_clean = first.strip().capitaliz... | ef5fe3e53ba1134c45c30f4b6342a0641e85f114 | 705,070 |
def diff_align(dfs, groupers):
""" Align groupers to newly-diffed dataframes
For groupby aggregations we keep historical values of the grouper along
with historical values of the dataframes. The dataframes are kept in
historical sync with the ``diff_loc`` and ``diff_iloc`` functions above.
This fu... | 2a92476cd913404b737dc941d51083f64ef70978 | 705,071 |
def load_targets_file(input_file):
"""
Takes a string indicating a file name and reads the contents of the file.
Returns a list containing each line of the file.
Precondition: input_file should exist in the file system.
"""
with open(input_file, 'r') as f:
f = f.readlines()
out = [i.replace('\n','').replace('\... | 40d305e244264d6c3249bb9fb914cda3ebcda711 | 705,072 |
def pega_salada_sobremesa_suco(items):
""" Funcao auxiliar que popula os atributos salada, sobremesa e suco do cardapio da refeicao fornecida."""
alimentos = ["salada", "suco", "sobremesa"]
cardapio = {}
for alim in alimentos:
tag = alim.upper() + ":" # tag para procurar o cardapio dos alimento... | 4ccf2907a4e828d1357e16e827ad587e4a50a287 | 705,073 |
def show_hidden_word(secret_word, old_letters_guessed):
"""
:param secret_word:
:param old_letters_guessed:
:return: String of the hidden word except the letters already guessed
"""
new_string = ""
for letter in secret_word:
if letter in old_letters_guessed:
new_string = ... | 2b3618619dcde2875da9dc8600be334e7aaadaad | 705,074 |
def filter_packages(packages: list, key: str) -> list:
"""Filter out packages based on the given category."""
return [p for p in packages if p["category"] == key] | 46f11f5a8269eceb9665ae99bdddfef8c62295a2 | 705,075 |
import os
def create_splits(dataframe, split_path, n_splits = 10) :
"""
Should i reset index ?
"""
length = int(dataframe.shape[0] / int(n_splits))
for i in range(n_splits) :
frame = dataframe.iloc[i*length:(i+1)*length]
if i == n_splits-1 :
frame = dataframe.iloc[i*len... | fd6c8e31fe271a957028ff7471a1294a84ee62be | 705,078 |
import os
def get_data_filepath(filename):
"""Construct filepath for a file in the test/data directory
Args:
filename: name of file
Returns:
full path to file
"""
return os.path.join(os.path.dirname(__file__), 'data', filename) | d3d83cbf83d32b0252658f77b7bbb6fbdb99845f | 705,079 |
def _column_number_to_letters(number):
"""
Converts given column number into a column letters.
Right shifts the column index by 26 to find column letters in reverse
order. These numbers are 1-based, and can be converted to ASCII
ordinals by adding 64.
Parameters
----------
number : int... | c9a68bcd32c8f254af322bc61e447cfae61cb6d2 | 705,080 |
def _chunk_member_lag(chunk, repl_member_list, primary_optimedates, test_run_indices):
"""Helper function to compute secondary lag from values in a chunk
:param collection.OrderedDict chunk: FTDC JSON chunk
:param list[str] repl_member_list: list of all members in the replSet
:param str primary: which ... | 115ba53505d5bcbb9e0c1cdf0eab675fae73e568 | 705,081 |
def smallest_evenly_divisible(min_divisor, max_divisor, minimum_dividend=0):
"""Returns the smallest number that is evenly divisible (divisible
with no remainder) by all of the numbers from `min_divisor` to
`max_divisor`. If a `minimum_dividend` is provided, only dividends
greater than this number will ... | fa23d9a413a0909bfc05d7eb928aec8ade4cb06f | 705,082 |
def factorial(n):
"""
Returns the factorial of n
Parameters
----------
n : int
denotes the non-negative integer for which factorial value is needed
"""
if(n<0):
raise NotImplementedError(
"Enter a valid non-negative integer"
)
if(n==0 or n==... | fe0b7100e1292d1e96daf18545d9fdfb931f9f74 | 705,083 |
def Divide(a, b):
"""Returns the quotient, or NaN if the divisor is zero."""
if b == 0:
return float('nan')
return a / float(b) | 3ed0b07949bb802177e52bf8d04e9dfde92ab2de | 705,084 |
import os
def craft_item():
"""Get craft item from environ varriable"""
return os.environ.get('CRAFT_ITEM', None) | 2f6f940ad83023dc21f68c2212c98c0e13d8d0e4 | 705,085 |
import ntpath
def path_leaf(path):
"""
Extract the file name from a path.
If the file ends with a slash, the basename will be empty,
so the function to deal with it
Parameters
----------
path : str
Path of the file
Returns
-------
output : str
The name of the ... | 58930f081c2366b9084bb279d1b8b267e5f93c96 | 705,086 |
def focus_metric(data, merit_function='vollath_F4', **kwargs):
"""Compute the focus metric.
Computes a focus metric on the given data using a supplied merit function.
The merit function can be passed either as the name of the function (must be
defined in this module) or as a callable object. Additional... | c8f571e11202d39d8f331fca5fc93333aeb71e62 | 705,087 |
def get_canonical_import(import_set):
"""Obtain one single import from a set of possible sources of a symbol.
One symbol might come from multiple places as it is being imported and
reexported. To simplify API changes, we always use the same import for the
same module, and give preference to imports coming from... | ae53ca4d271ab543a7a13f1ce8240ce6eb328bbb | 705,088 |
import torch
from typing import Iterable
def _tensor_in(tensor: torch.Tensor, iterable: Iterable[torch.Tensor]):
"""Returns whether `tensor is element` for any element in `iterable` This function is necessary because `tensor in
iterable` does not work reliably for `Tensor`s.
See https://discuss.pytorch.o... | 84ac8a129440c9c8d7785029b04bd403514a3bb9 | 705,089 |
def is_development_mode(registry):
"""
Returns true, if mode is set to development in current ini file.
:param registry: request.registry
:return: Boolean
"""
if 'mode' in registry.settings:
return registry.settings['mode'].lower() == 'development'
return False | af1b11fa69231a455406247b593f8ff49855bc3f | 705,090 |
def float_fraction(trainpct):
""" Float bounded between 0.0 and 1.0 """
try:
f = float(trainpct)
except ValueError:
raise Exception("Fraction must be a float")
if f < 0.0 or f > 1.0:
raise Exception("Argument should be a fraction! Must be <= 1.0 and >= 0.0")
return f | 8eb28dcaa0ed9250f4aa68d668ad424b5b5eded5 | 705,091 |
def handle_internal(msg):
"""Process an internal message."""
internal = msg.gateway.const.Internal(msg.sub_type)
handler = internal.get_handler(msg.gateway.handlers)
if handler is None:
return None
return handler(msg) | 0f5cae49cf5d36a5e161f88902c46af931fd622a | 705,092 |
import codecs
import json
def _get_input_json(input_path):
"""
A really basic helper function to dump the JSON data. This is probably a
leftover from when I was iterating on different reduce() functions.
"""
# Read in the input file.
input_file = codecs.open(input_path, encoding="utf-8", mode=... | 5c91e77b2224435dbf17fcfc2351c574c173c6aa | 705,093 |
import math
def conv_float2negexp(val):
"""Returns the least restrictive negative exponent of the power 10
that would achieve the floating point convergence criterium *val*.
"""
return -1 * int(math.floor(math.log(val, 10))) | 562ccf7d34f8034a25cabfb471e7fc2ab9c0feb6 | 705,096 |
import random
def img_get_random_patch(img,w,h):
"""Get a random patch of a specific width and height from an image"""
# Note that for this function it is the user's responsibility to ensure
# the image size is big enough. We'll do an asertion to help but...
# Figure out the maximum starting point w... | 41ce199eb5ab8eb136f740eb2e1b495226510690 | 705,098 |
import os
def expand_path(filename: str) -> str:
"""
Expands variables (user and environment) in a file name.
:param filename: File name, possibly containing variables.
:return: File name with variables expanded.
"""
return os.path.expandvars(os.path.expanduser(filename)) | b6dae3491edbaa00a5f73959b2227ad2fe6f506e | 705,099 |
def prepare_wiki_content(content, indented=True):
"""
Set wiki page content
"""
if indented:
lines = content.split("\n")
content = " ".join(i + "\n" for i in lines)
return content | 14daea5cdb509b333c2aead6dcb453a82e73ce8d | 705,100 |
def default_browser():
"""
Return the name of the default Browser for this system.
"""
return 'firefox' | a5df3959983bcc11fb59b0aea44a0e6ed42cc579 | 705,101 |
def splinter_remote_url(request):
"""Remote webdriver url.
:return: URL of remote webdriver.
"""
return request.config.option.splinter_remote_url | 17bf9bf3ebd7296a2305fe9edeb7168fbca7db10 | 705,102 |
import re
def split_list_item_by_taking_words_in_parentheses(item):
"""This function goes through items in a list and creates a new item with only the words inside the parentheses."""
species_pop_name = item.split('(')[0].split(',')
if len(species_pop_name) > 1:
species_pop_name = species_pop_name... | 2d8543611007e799d089c77b79ae7263cba36a30 | 705,103 |
def pad(value, digits, to_right=False):
"""Only use for positive binary numbers given as strings.
Pads to the left by default, or to the right using to_right flag.
Inputs: value -- string of bits
digits -- number of bits in representation
to_right -- Boolean, direction of padding
... | 98476653ccafeba0a9d81b9193de0687dbf9d85c | 705,104 |
import tempfile
import os
def setup_directories(
create_report_directory=True,
create_publish_directory=False,
temporary_work_directory=None,
):
"""
Setup a temporary directory, a report directory under it (created if necessary),
and the publish directory (not created by default if necessary).... | c54db5354523653d87fc8baee0739b401fa5351b | 705,105 |
def check_band_below_faint_limits(bands, mags):
"""
Check if a star's magnitude for a certain band is below the the
faint limit for that band.
Parameters
----------
bands : str or list
Band(s) to check (e.g. ['SDSSgMag', 'SDSSiMag'].
mags : float or list
Magnitude(s) of the ... | 9e26fcef5bf79b4480e93a5fe9acd7416337cf09 | 705,106 |
def find_place_num(n, m):
"""
"""
if n==1 or m==1:
return 1
else:
return find_place_num(n-1, m) + find_place_num(n, m-1) | 632e06db2eb2e2eebdb1c5b34bea36124843a960 | 705,107 |
def add_license_creation_fields(license_mapping):
"""
Return an updated ``license_mapping`` of license data adding license status
fields needed for license creation.
"""
license_mapping.update(
is_active=False,
reviewed=False,
license_status="NotReviewed",
)
return li... | 3856c434a672150c09af4b5e4c7fd9fa55014d5c | 705,108 |
import sys
def InputChecking(str_inputFileName_genotype, str_inputFileName_phenotype):
"""
To check the numbers of sample are consistent in genotype and phenotype data.
Args:
str_inputFileName_genotype (str): File name of input genotype data
str_inputFileName_phenotype (str): File name o... | c1cf089a2018d2ab99f35e374f55626458698764 | 705,109 |
def lowercase(obj):
""" Make dictionary lowercase """
if isinstance(obj, dict):
return {k.lower(): lowercase(v) for k, v in obj.items()}
elif isinstance(obj, (list, set, tuple)):
t = type(obj)
return t(lowercase(o) for o in obj)
elif isinstance(obj, str):
return obj.lower... | 08b0addd87ef7ba5c016ebee50790e8d5e31042b | 705,110 |
import argparse
import os
def getOptions():
"""Function to pull arguments"""
parser = argparse.ArgumentParser(description="Removes samples from the design file" \
"belonging to the user-specified group(s).")
# Standar Input
standar = parser.add_argument_group(title=... | e86fda9acc65f90f968a3be2b2238370910b866b | 705,111 |
def dequote(s):
"""
from: http://stackoverflow.com/questions/3085382/python-how-can-i-strip-first-and-last-double-quotes
If a string has single or double quotes around it, remove them.
Make sure the pair of quotes match.
If a matching pair of quotes is not found, return the string unchanged.
"""... | 41c5e5fed901d70472dd6eef1ada7d53d395002c | 705,113 |
def url_form(url):
"""Takes the SLWA photo url and returns the photo url. Note this
function is heavily influenced by the format of the catalogue and could be
easily broken if the Library switches to a different url structure.
"""
if url[-4:] != '.png' and url[-4:] != '.jpg':
url = url + '... | 7469850ffb6877ca116a28251d204024e15bc407 | 705,114 |
import os
def _filepaths(directory, full_paths=True):
"""Get the filenames in the directory.
Args:
directory: Directory with the files
full_paths: Give full paths if True
Returns:
result: List of filenames
"""
# Initialize key variables
if bool(full_paths) is True:
... | 1a40cb2f3f940a911690f862fd8711d84d90fc94 | 705,115 |
def Rpivot(p, q, Mb):
"""
Given an augmented matrix Mb, Mb = M|b, this gives the output of the
pivot entry [i, j] in or below row p, and in or to the right of column q.
"""
# n is the number of columns of M, which is one less than that of Mb.
m = len(Mb)
n = len(Mb[0]) - 1
# Initialize ... | 155be98d8560bf42cea928e8b1da6e14e3e7762d | 705,117 |
def compute_down(expr):
""" Compute the expression on the entire inputs
inputs match up to leaves of the expression
"""
return expr | 71677a16093d82a28c1d153c9385b33c01b4dd24 | 705,118 |
from typing import Tuple
def requests_per_process(process_count: int, conf) -> Tuple[int, int]:
"""Divides how many requests each forked process will make."""
return (
int(conf.concurrency / process_count),
int(conf.requests / process_count),
) | 00af7a63471201c3fffcfb610f74a745ca326b68 | 705,120 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.