content stringlengths 39 9.28k | sha1 stringlengths 40 40 | id int64 8 710k |
|---|---|---|
def time_to_text(time):
"""Get a representative text of a time (in s)."""
if time < 0.001:
return str(round(time * 1000000)) + " µs"
elif time < 1:
return str(round(time * 1000)) + " ms"
elif time < 60:
return str(round(time, 1)) + " s"
else:
return str(round(tim... | f87934f66c82c834f18d94189c67c22f6b8ef45f | 85,051 |
def get_results_value(results):
""" Gets the value in the last column of the first row of the ga results
:param results: dict: results from the ga analytics query
:return: int: the value from the results
"""
if results.get('rows', []):
return results.get('rows')[0][-1]
return None | 94089925dafdb1e77b927950fb83e2b90c1349c8 | 382,098 |
def s3_download(s3_bucket, file_key, output_path):
"""Download a file from S3."""
print(f"downloading [{file_key}] from [{s3_bucket.name}] to [{output_path.resolve().as_posix()}]")
s3_bucket.download_file(file_key, output_path.resolve().as_posix())
return output_path | 8a966b6f0230ffe037d054d798e05ff462036dbd | 63,139 |
def centerOfGravity( array ):
"""
Vypočítá ze zadaých bodů jejich těžiště.
Parametry:
----------
array: list
Pole s body.
Vrací:
-----
list
Pole s X- a Y-ovou souřadnicí těžiště.
"""
sum_X = 0
sum_Y = 0
# Sečte X-ové a Y-ové souřadnice ... | a5ef7714b0ea97258530ba3d2d6d0483ca82623a | 686,714 |
def rplog_convert(df, pwave_sonic, shear_sonic):
"""
Convert usec/ft (DT/DTS) to velocity (VP/VS)
Create Impedance logs from velocity and density logs (IP/IS)
Create VP/VS ratio log
"""
try:
df['VP'] = 304800 / df[pwave_sonic]
df["IP"] = df.VP * df.RHOB
df['VS'] = 304800 ... | 4c2cc1aa79dfc19d9427b9bd35ad594e09b973ee | 112,229 |
def RgbFromHex(color_hex):
"""Returns a RGB color from a color hex.
Args:
color_hex: A string encoding a single color. Example: '8f7358'.
Returns:
A RGB color i.e. a 3-int tuple. Example: (143, 115, 88).
"""
return tuple(int(color_hex[i:i + 2], 16) for i in (0, 2, 4)) | b6c385a334b45aae145008a35f372ee1b565020f | 267,330 |
def ema(df, price, ema, n):
"""
Exponential Moving Average (EMA) is a Weighted Moving Average (WMA) that
gives more weighting to recent price data than Simple Moving Average (SMA)
does.
The EMA formula is based on the previous day EMA value. Since we have to
start our calculation somewhere, the... | f8ef73e3c4b20d65b860fbfdc40e4a954b8d6730 | 254,214 |
def get_sizes_purities(clusters):
"""Return two lists containing the sizes and purities of `clusters`."""
sizes = []
purities = []
for cluster in clusters:
sizes.append(cluster["size"])
purities.append(cluster["purity"])
return sizes, purities | 91075470d54ef285c49be470eee26b321266e66c | 603,595 |
def collect_driver_info(driver):
"""Build the dictionary that describes this driver."""
info = {'name': driver.class_name,
'version': driver.version,
'fqn': driver.class_fqn,
'description': driver.desc,
'ci_wiki_name': driver.ci_wiki_name}
return info | 41e94ac324d9bfc2248d90e670378cf5e39e3e1d | 74,325 |
import cmath as c
def amp_ph_to_comp(a,ph):
""" Takes the amplitude and phase of the waveform and
computes the compose them together"""
t =[]
for i in range(len(a)):
t.append(a[i]*c.exp(ph[i]*1j))
return t | cd1b6a3135af89acc1785b49ba8a8888b8034618 | 228,604 |
def area(gdf):
"""Returns area of GeoDataFrame geometries in square kilometers."""
return gdf.to_crs(epsg=3035).area.div(1e6) | dfcd35c363699fe27052e2a4c8b3c3d24580513d | 609,188 |
def pronoun_instance_dist(novel, words):
"""
Takes in a novel and list of gender pronouns, returns a list of distances between each
instance of a pronoun in that novel
>>> from gender_novels import novel
>>> summary = "James was his convicted of adultery. "
>>> summary += "wh... | 6bd4cf1b3b968c395b230f1a23d4d07325029659 | 569,678 |
def bvw(sw, phi):
"""
Calculates Bulk Volume Water
Parameters
----------
sw : float
Water saturation (dec)
phi : float
Porosity (dec)
Returns
-------
float
Bulk volume water (dec)
"""
return sw * phi | 27b6e843e8a348488f7150080683d18421a062bf | 167,006 |
def get_default(arr, idx, default_value):
"""get arr[idx] or return default_value
"""
try:
return arr[idx]
except IndexError:
return default_value | 038b943da7fa1d36038444880264160da8e031f4 | 701,544 |
def _read_file(path):
"""Reads the whole file and returns its content.
Args:
path: The file path.
Returns:
The content of the file.
"""
f = open(path, 'r')
return f.read() | e765cd3d369c92190dd4bb78694b1daf79c74289 | 249,145 |
def jump_to_match(input_file, regex):
"""Jump to regex match in file.
@param input_file: File object
@param regex: Compiled regex object
@return: True if successful, False otherwise
"""
for line in input_file:
if regex.match(line):
return True
return False | 9ecae9a2218d3f334e2183cc1979d839113c995b | 635,465 |
def find_biomass_reaction(
model, biomass_string=["Biomass", "BIOMASS", "biomass"]
):
"""
Identifies the biomass reaction(s) in a metabolic model.
Parameters
----------
model : cobra.Model
Metabolic model.
biomass_string : str or list
String denoting at least a part of the n... | bbc9232462fb3850be1208e324ab147aa14be086 | 101,557 |
def isNumber(n):
"""
checks if n is an integer
:param n: value to be check
:return: true if n is a number, false in other case
"""
try:
int(n)
return True
except ValueError:
return False | c6aab9655eca55d20c002e2139b8a33a3a2eef57 | 194,691 |
from typing import Optional
def get_number_str(x: Optional[int]) -> str:
"""Get string from number or empty string if number is `None`."""
if x is None:
return ''
return str(x) | f0e7e05ab3db5f190853ac6cdb731ba6bbf64065 | 145,919 |
import six
def is_string(value):
"""Return a boolean value indicating whether the value is a string or not.
This method is compatible with both Python 2.7 and Python 3.x.
NOTE:
1. We can't use isinstance(string_value, str) because strings in Python 2.7 can have "unicode" type.
2. We can't use isi... | 809e4d43390219f08cf81e9389b38e045aae0e0c | 642,132 |
def create_attn_masks(input_ids):
"""
Create attention masks to tell model whether attention should be applied to
the input id tokens. Do not want to perform attention on padding tokens.
"""
# Create attention masks
attention_masks = []
# Create a mask of 1s for each token followed by 0s fo... | 6b55578b9c79410e81a6d2bf7e341bdfd51f2edf | 386,613 |
def lower(review):
"""Lowercase a review
Arguments:
- review: the review of the SemEvalReview class
Returns:
The review with lowercased text
"""
review.text = review.text.lower()
return review | 0f76d959b8258022244ee27c129a7762a9d72af3 | 136,022 |
def get_allowed_tokens(config):
"""Return a list of allowed auth tokens from the application config"""
return [token for token in (config.get('AUTH_TOKENS') or '').split(':') if token] | e046e369ef949501deaf91f6629a768af9416c75 | 83,336 |
def _get_reference_bodyreference(referencebody_element):
"""Parse ReferenceInput BodyReference element
"""
return referencebody_element.attrib.get(
'{http://www.w3.org/1999/xlink}href', '') | c0baeec99e3d9d4a54f17a721d00202e214defcc | 60,038 |
def get_parent_id(org_client, account_id):
"""
Query deployed AWS organanization for 'account_id. Return the 'Id' of
the parent OrganizationalUnit or 'None'.
"""
parents = org_client.list_parents(ChildId=account_id)['Parents']
try:
len(parents) == 1
return parents[0]['Id']
ex... | 69b42af5989f4672fdbce2c15da5b7290a1465c1 | 573,482 |
def compact(objects):
"""
Filter out any falsey objects in a sequence.
"""
return tuple(filter(bool, objects or [])) | 60af7d26e786113d9af7a29f1e6a46ee2191453d | 653,954 |
def velocity_exceeded(Rover, max_vel=2.0):
"""
Check if velocity is under max_vel.
Keyword arguments:
max_vel -- maximum velocity in meters/second
"""
return Rover.vel < max_vel | 944a8c1c19c3c080f8fc79364b40555a8ee792e1 | 604,202 |
from typing import OrderedDict
def _Net_blobs(self):
"""
An OrderedDict (bottom to top, i.e., input to output) of network
blobs indexed by name
"""
return OrderedDict([(bl.name, bl) for bl in self._blobs]) | 6c68e91a10fb9eda6c0be9ef03ffdd08823131d8 | 690,620 |
def is_test(t):
"""Returns True if the target is comprised of tests."""
return t.has_label('tests') | 55215c93a773c0c28e6455c39aa60ba133742960 | 487,642 |
from typing import Any
def get_client_region(client: Any) -> str:
"""Get the region from a boto3 client.
Args:
client: The client to get the region from.
Returns:
AWS region string.
"""
return client._client_config.region_name | 1b6d0810d7376bd5ef8ea59d7ae700c39a89e610 | 643,799 |
def parse_scaling(scaling_args):
"""Translate a list of scaling requests to a dict prefix:count."""
scaling_args = scaling_args or []
result = {}
for item in scaling_args:
key, values = item.split('=')
values = values.split(',')
value = int(values[0])
blacklist = frozense... | 61d25373093ace840bca120e01a71b6d4309c7f2 | 198,745 |
def local_patch(x, bbox):
"""Crop local patch according to bbox.
Args:
x: input
bbox: (top, left, height, width)
"""
return x[:, :, bbox[0]:bbox[0] + bbox[2], bbox[1]:bbox[1] + bbox[3]] | 017ae96fd8d05e789fd048842da0d16fcbd5634d | 569,593 |
def PrepareSets(args, tokenizer, train_set, dev_set, test_set, first_label=False):
"""
Function that prepares the datasets for usage.
Inputs:
args - Namespace object from the argument parser
tokenizer - BERT tokenizer instance
train_set - Unprepared training set
dev_set - Unp... | fea720f386c4a7819317bd53f35b4268aee43d6e | 343,304 |
def file_to_dict_array(input_file, separator="\t"):
"""
Turns a column based file into an array of dicts, where the keys are the column names
So result[3]["first"] gets the value from the column with the name "first" and the fourth row
"""
result = []
with open(input_file, 'rU') as i:
he... | 70998bbc31274c15d83d47aeb0df09c5cb590ed3 | 272,239 |
def _mock_check_state(_):
"""Mocked check_state method."""
return True | 1db16fd64d93147d1b1eb849e6afb4463b0f6ff3 | 661,191 |
def has22(list_one:list)->bool:
"""Returns True if the list contains a 2 next to a
2. Otherwise, the function returns False .
>>>has22([1,2,2,3])
True
>>>has22([1,2,3,4])
False
"""
if ', 2, 2' in str(list_one):
return True
elif list_one[0] == 2 and list_on... | be5554cc17b760977505120fb965aa7f9014aa6b | 621,252 |
import torch
def make_ent2idx(entities, max_ent_id):
"""Given a tensor with entity IDs, return a tensor indexed with
an entity ID, containing the position of the entity.
Empty positions are filled with -1.
Example:
> make_ent2idx(torch.tensor([4, 5, 0]))
tensor([ 2, -1, -1, -1, 0, 1])
"... | 627b6366cff49ab22d6e9bab76fcb030e233a92f | 306,618 |
def get_channel_youtube_url(channel_code):
""" Get the Youtube Channel URL given its code
Example:
UC6gsueJf0YTIF3inlGKWLPg
must return:
https://www.youtube.com/channel/UC6gsueJf0YTIF3inlGKWLPg
"""
return "https://www.youtube.com/channel/{:s}".format(channel_code) | 3b94e53de783204e718fc4a938c4ec34224d357e | 599,534 |
def first_index_not_below(arr, t):
"""Return first index of array >= t, or len(arr) if no such found"""
for i, x in enumerate(arr):
if x >= t:
return i
return len(arr) | dc41ea6c2dfa0a4243c180d04553bc1d8d3a83d8 | 185,171 |
from pathlib import Path
def _gen_outdir(outdir):
"""
Coerces `outdir` to `pathlib.Path` and creates it, if it doesn't exist
Parameters
----------
outdir : str
Path to desired output directory
Returns
-------
outdir : pathlib.Path
Path to desired output directory
... | d250e68a347efbb57dd8b69b73680477c81ede54 | 550,783 |
def TOTAL_DEGREE_FREEDOM(N_DOFSNODE, N_NODES):
"""
This function determines the quantity and ID values of the structure's global degrees of freedom.
Input:
N_DOFSNODE | Number of degress of freedom per node | Integer
N_NODES | Number of nodes | Integer
Outpu... | b6b374c0d9a18d4efb7077f6758cd78236bbfeeb | 277,114 |
def _join_words(words, delimiter=",", conjunction="and"):
"""Join words together for nice printout.
>>> _join_words(["first", "second", "third"])
'first, second, and third'
>>> _join_words(["first", "second"])
'first and second'
>>> _join_words(["first"])
'first'
"""
if len(words) =... | 4ad92cb027b3edf1442c122719d74d0b74d67cfe | 310,483 |
def fix_name(inp, names_used):
"""Append a number if an autoSql field name is duplicated.
"""
name = inp
i = 2
while name in names_used:
name = "%s%s" % (inp, i)
i += 1
names_used.append(name)
return name | 4021512b7ff815769bdf6b30b9852c4dfd5a17ab | 602,843 |
from typing import Tuple
def default_hyperparameter_denormalizer(n_factors_norm: float,
reg_weight_norm: float
) -> Tuple[int, float]:
"""Takes hyperparameter values normalized from default interval to (0; 1] interval,
and returns... | e5788cc3e1c8033ea6acccd3f17d273d14f244b0 | 466,506 |
from typing import List
from typing import Union
from pathlib import Path
def cli_args(tmpdir) -> List[Union[Path, str]]:
"""
Fixture simulating a set of CLI arguments.
Returns:
List of args.
"""
in_folder = Path("requirements.in")
assert in_folder.exists()
out_folder = Path(tmpd... | bbfdc585289dbbdb5cd532b2791bf695cb2f5a91 | 75,892 |
import torch
def test_model(model, dset_loader):
"""
Tests a model on a given data set and returns the accuracy of the model
on the set.
"""
model.train(False)
running_corrects = 0
for inputs, labels in dset_loader:
# wrap them in Variable
# inputs, labels = Variable(inpu... | c5b4a5673e2424bb1274b3988e064cde35385f58 | 164,056 |
def get_hpsearch_call(cmd_args, num_seeds, grid_config, hpsearch_dir=None):
"""Generate the command line for the hpsearch.
Args:
cmd_args: The command line arguments.
num_seeds (int): Number of searches.
grid_config (str): Location of search grid.
hpsearch_dir (str, optional): W... | 97525fc5e3e22c5367176996f5b76a9e5482c2fd | 433,357 |
def sign_split(M):
"""Given a matrix M, return two matrices. The first contains the
positive entries of M; the second contains the negative entries of M,
multiplied by -1.
"""
M_plus = M*(M>0).astype(int)
M_minus = -M*(M<0).astype(int)
return M_plus, M_minus | af573a2c68a6156cd92b5f3076c0fa6fb3c3c95e | 633,946 |
import csv
def read_known_craft(csv_file: str) -> list:
"""Reads the FILTER_CSV file into a `list`"""
all_rows = []
with open(csv_file) as csv_fd:
reader = csv.DictReader(csv_fd)
for row in reader:
all_rows.append(row)
return all_rows | 6afa0566f7a3e00b55e4e588dff52b3be5e196fb | 475,250 |
import re
def is_generate_var(var):
"""
Determine whether one variable is generated var
Args:
var: the variable which model used
Returns:
True if variable is generated var
"""
if re.match("_generated_var_[0-9]+", var) or \
re.match("sequence_pool_[0-9]+.tmp_[0-9]+", va... | 844c25a89b850a667df230856a9fb402a824fb28 | 455,289 |
from typing import Iterable
def comma_join(items: Iterable[str]) -> str:
"""
Joins an iterable of strings with commas.
"""
return ", ".join(items) | 4ba674593dc0a8afcf766186b496a625ab70d6d0 | 542,987 |
def _unchanged(v1, v2):
"""Check if anything except 'LastSeen' is different between two alerts."""
return ({k: v for k, v in v1.items() if k != 'LastSeen'} ==
{k: v for k, v in v2.items() if k != 'LastSeen'}) | 3fdc0c04532331e6db1e638256ab9fcbc11e45e1 | 366,530 |
def get_topic_name(prefix, table, operation):
"""Create a topic name.
The topic name needs to be synced between the agents.
The agent will send a fanout message to all of the listening agents
so that the agents in turn can perform their updates accordingly.
:param prefix: Common prefix for the age... | 277a2b3d193f39630be0fb8722521aa0d3e6c9da | 570,532 |
def stage_title(stage):
"""Helper function for setting the title bar of a stage"""
stage_txt = ("Name", "Vocation", "Character Design and Details",
"Stats and Skills", "All Done: Thank You!")
stage_cmd = ("{w@add/name <character name>{n", "{w@add/vocation <character's vocation>{n",
... | badd7ad6a59c52a0bbc4f186aca7fd4c653a0910 | 679,143 |
def obfuscate_email_address(address):
"""Replace anything looking like an e-mail address (``'@something'``)
with a trailing ellipsis (``'@…'``)
"""
if address:
at = address.find('@')
if at != -1:
return address[:at] + u'@\u2026' + \
('>' if address[-1] == '... | 4ee71b37a05112d8f68187db57850889cb3191f9 | 535,086 |
def convertToCPM(dose, period):
"""
Converts from milliSieverts/hr to CPM
Parameters:
dose (double): The dosage
period (double): The time period over which the dosage
is administered
Returns the measurement in CPM
"""
conversionFactor = 350000 / 1.0
return conversionFactor * dose / period | 1ec1f1b49c2596496b0b3dc6fe857fdea1e776c0 | 624,694 |
def process_benchmark_df(df_input):
"""Take in the featurized the benchmark dataframe and clean it up"""
# select the relevant columns
df_output = df_input[["formula", "avg_mx_dists", "avg_mm_dists", "iv", "iv_p1",
"v_m", "v_x", "est_hubbard_u", "est_charge_trans"]]
# rename th... | 1ef6e95adbcfd4185d1597f29e3e218ee8a8eae3 | 128,324 |
def occurrences(string, sub):
""" string count with overlapping occurrences """
count = start = 0
while True:
start = string.find(sub, start) + 1
if start > 0:
count+=1
else:
return count | f586df3f5ffbc3f039a72caf20f6c2c54952f224 | 165,727 |
def y(x: float, slope: float, initial_offset: float = 0) -> float:
"""Same function as above, but this time with type annotations!"""
return slope * x + initial_offset | 223f981813e7b7a24d40132aefbc7a546594ccf5 | 513,318 |
import collections
def merge(queries, qp, qc, qrels):
""" Merge queries, qrels, <query, passage> pairs, <query, chunk> pairs into a single dict. """
data = collections.OrderedDict()
for qid in qc:
passage_ids = list()
labels = list()
for passage_id in qp[qid]:
doc_id =... | 24665c962d588c24ab94d48593c52d129a7bab80 | 118,881 |
def filter_short_trajectories(df, threshold):
"""
Filter trajectories that are shorter in timesteps than the threshold
:param df: pandas df with columns=['x', 'y', 'frame', 'trackId', 'sceneId', 'metaId']
:param threshold: int - number of timesteps as threshold, only trajectories over threshold are kept... | d660eb522d85c1cc3eb3723d03faef0dc604df82 | 212,568 |
import json
def list_of_dicts_to_jsonl(list_input):
"""
takes a list of dict objects and turns it into a jsonl doc
"""
jsonl_contents = ""
for each_entry in list_input:
if len(jsonl_contents) == 0:
jsonl_contents = json.dumps(each_entry)
else:
jsonl_content... | 4da5583adec02c58e753475fba9e61dd773afcde | 243,160 |
def NPVCost(d):
"""
Parameters
----------
d : dict
Output of PED/statusQ functions with all saved variables and results
of optimization.
Returns
-------
dic : dict
dictonary with all relevant cost component of optimized solution.
"""
dic = {}
dic["... | f436752277196d3f2e42f10c35b220b71ca4440c | 396,637 |
import pkg_resources
def list_main(argv_unused): # pylint: disable=unused-argument
"""
list
List the FILENAMEs that edx_lint can provide.
"""
print("edx_lint knows about these files:")
for filename in pkg_resources.resource_listdir("edx_lint", "files"):
print(filename)
return... | 4f0ac77a03d882676c5b35e1726840d0aaeaf789 | 510,949 |
def df_rename_col(data, col, rename_to, destructive=False):
"""Rename a single column
data : pandas DataFrame
Pandas dataframe with the column to be renamed.
col : str
Column to be renamed
rename_to : str
New name for the column to be renamed
destructive : bool
If ... | da424f4c7202aa397153a3293f8f24a672c783d9 | 656,263 |
def ReadBBoxPredictFile(file_path):
"""
Args:
file path : str
File format:
image_name:<image_name.jpg>
(percentage) (abs)
<class_name>,<confidence>,<x1>,<y1>,<x2>,<y2>
...
end
example:
image_name:a.jpg
... | 086865ca68bd3387f090ffd5cdedac659cd10bbf | 37,333 |
def check_bit_set(value: int, bit: int):
"""
Simple function to determine if a particular bit is set
eg (12 - binary 1100) then positions 3 and 4 are set
:param value: Number to be tested
:param bit: Position to check; >0 (right to left)
:return: Bool: True if bit is set
"""
if va... | ce78135b1d74cc3da31010765bcc3c32dcb680ab | 230,206 |
def compute_optalpha(norm_r, norm_Fty, epsilon, comp_alpha=True):
"""
Compute optimal alpha for WRI
Parameters
----------
norm_r: Float
Norm of residual
norm_Fty: Float
Norm of adjoint wavefield squared
epsilon: Float
Noise level
comp_alpha: Bool
Whether ... | 7206d14d41df1f9d9c5e9989f4b9fc36b9b8ae31 | 647,409 |
def z_periodicity(periodicity_value):
"""
The periodicity of a bond along the z axis.
"""
return periodicity_value | 49cd0c249bde4dfea56410e0b051d2a4c65585bb | 135,490 |
def highlight_max(s):
"""
highlight the maximum in a Pandas dataframe Series yellow.
"""
is_max = s == s.max()
return ["background-color: yellow" if v else "" for v in is_max] | af0efb38f83511c8368fb174dd400a4d93a9d148 | 93,394 |
from typing import Iterable
from typing import Tuple
from typing import List
def paired_tuple_list_to_two_lists( inlist: Iterable[ Tuple ] ) -> Tuple[ List, List ]:
"""
Splits a list of the form [ ( value1_1, value1_2 ), ( value 2_1, value2_2 ), ... ]
and returns two lists containing values split by indic... | d0a4267e65a24951c447ba66bae74dcabe5320ef | 484,719 |
def find_prefix_entry(message, dictionary):
"""
Find the longest entry in dictionary which is a prefix of the given message
"""
for entry in dictionary[::-1]:
if message.startswith(entry[0]):
return dictionary.index(entry)
return -1 | 93b92c46adfb0bcf0086c8626ba6d5cab088abc2 | 197,072 |
def str2bytes(data):
"""
Converts string to bytes.
>>> str2bytes("Pwning")
b'Pwning'
"""
return bytes(data, encoding="utf-8") | 0e9ef347c245cdf4965e0b594b450ebeebc52a41 | 673,951 |
def P_otc6486(H, D, gamma, c):
""" Returns the uplift resistance of cohesive materials.
OTC6486 - Equation (7)
"""
return gamma * H * D + 2 * H * c | 2644f6df3744717be7f7614207469fbf5e26551a | 244,725 |
def get_invalid_keys(validation_warnings):
"""Get the invalid keys from a validation warnings list.
Args:
validation_warnings (list): A list of two-tuples where the first
item is an iterable of string args keys affected and the second
item is a string error message.
Returns... | 0eb0db053e505f696471e7166051d9b2e025d439 | 661,963 |
def closest_multiple(N, base : int = 16):
"""
Return the closest multiple of 'base' to 'N'
"""
return base * round( N / base ) | 8343e6e43fdf18418e52a07d9f003ae641cf848e | 560,366 |
def parse_join_code(join_code):
"""
takes the join code and makes sure it's at least 6 digits long
Args:
join_code (int): the number of join codes sent out so far
Returns:
string: the actual join code
"""
if join_code < 10:
return f"00000{join_code}"
elif join_code ... | a83ddcd31ecbe701ede66118691b5a0cba9fae19 | 74,617 |
def find_largest_hotspot(centroid_list: list) -> int:
"""
Description: Find the size of the cluster with the most data points
:param centroid_list: list of centroid for each final cluster.
each centroid in form of [longitude, latitude, # location]
:return: an integer which is the length of the ... | 6841f19e13af38520ab77b063c282f5a42c839ae | 527,415 |
def parse_variable_assignments(assignments):
"""
Parses a list of key=value strings and returns a corresponding dictionary.
Values are tried to be interpreted as float or int, otherwise left as str.
"""
variables = {}
for assignment in assignments or ():
key, value = assignment.replace('... | de3c10dc1c868423d69a8815b85deced278e1cf4 | 489,015 |
def dotted_name(cls):
"""Return the dotted name of a class."""
return "{0.__module__}.{0.__name__}".format(cls) | 7f0c8eab3769e4b200a9fd0ed5b2df22aad6e2a6 | 363,472 |
def is_equation(text):
"""test if a piece of text is a latex equation, by how it is wrapped"""
text = text.strip()
if any(
[
text.startswith("\\begin{{{0}}}".format(env))
and text.endswith("\\end{{{0}}}".format(env))
for env in [
"equation",
... | 6cfc441dd460833d28b22fd4a6bfdc355d312e73 | 551,716 |
def get_value(x):
"""
Extract value from <v,u> data.
"""
return x.value | d89f25e23b5b28cb3d36a1299b1f1fab01be9896 | 593,378 |
def parse_bool(value, additional_true=None, additional_false=None):
"""Parses a value to a boolean value.
If `value` is a string try to interpret it as a bool:
* ['1', 't', 'y', 'true', 'yes', 'on'] ==> True
* ['0', 'f', 'n', 'false', 'no', 'off'] ==> False
Otherwise raise TypeError.
A... | ca22044cf5ac0a35a0e42fe16a54c7c96dd8cc17 | 551,153 |
def is_numeric(s):
"""
Return True is the string ``s`` is a numeric string.
Parameters
----------
s : str
A string.
Returns
-------
res : bool
If True, ``s`` is a numeric string and can be converted to an int or a
float. Otherwise False will be returned.
""... | 4a2a9e99dab8c1bdd29e62cf9ddf35b9d8c949fc | 496,097 |
import logging
import codecs
def read_text_from_file(file_name, insert=''):
"""
Method that read message from text file, and optionally add some
dynamically generated info.
:param file_name: Name of file to read
:param insert:
:return: message
"""
if not isinstance(file_name, str):
... | 5eceae07d196c191d74c975abeee0128597d8c91 | 296,685 |
def subND(v1, v2):
"""Subtracts two nD vectors together, itemwise"""
return [vv1 - vv2 for vv1, vv2 in zip(v1, v2)] | 566b1916ea1b068e062d8e14665a039c1209bfc1 | 237,008 |
def is_in_constraints(trajectory, constraints, costs_by_time):
"""
Check wether or not the trajectory is complying with each
constraint.
Inputs:
- trajectory: pandas DataFrame
Trajectory to be checked
- constraints: list
Constraints the trajectory must comp... | 7d1b03c890a296ae6bf94bb4b90f5bfb1281b852 | 183,538 |
def invert_tree_recursive(root):
"""
Invert binary tree
:param root: root node
:type root: TreeNode
:return: root node of inverted tree
:rtype: TreeNode
"""
# basic case
if root is None:
return None
root.left, root.right = invert_tree_recursive(root.right), invert_tree_... | 4a655fa39b4c0d1de661b1ae948043c6ea6ca6c3 | 518,701 |
def parse_access_variable(v):
"""
Parses the accessibility arguments from a variable anme.
Should be structued as <variable_name>_<dir>_within<travel_time>_mode.
For example: `sb_jobs_sector92_to_within20_OpAuto`:
- variable: sb_jobs_sector92
- direction: travel towards the zone
... | 83ac0d8bfda29a18f6785a5bea5dfa7a4fdb004e | 657,765 |
def get_value(self):
"""get value as numpy array
:return: numpy array, or None if value is empty"""
self.__apply_lazy_initializer()
return self._get_npyarr() | 69a3d6c04870695da2e3948cac338833d8209c51 | 76,954 |
def average(number1, number2, number3):
"""
Calculating the average of three given numbers
Parameters:
number1|2|3 (float): three given numbers
Returns:
number (float): Returning the statistical average of these three numbers
"""
return (number1 + number2 + number3) / 3.0 | 04102ee8646b6e5d2cfa9265771c4f4bdbe45d45 | 30,570 |
def trivial(target):
"""
Return True if target is irreducible, False if reducible
or None if undecidable.
This trivial function checks the followings:
(1) if the constant term is zero, the polynomial is reducible.
(2) if not (1) and the degree is <= 1, the polynomial is irreducible.
"""
... | 5b43e8f19796a1a4075fddef3cf4a52254dedf85 | 68,393 |
import six
import base64
def _Base64EncodeLdap(username, passwd):
"""Base64 Encode Ldap username and password."""
enc = lambda s: six.ensure_text(base64.b64encode(six.ensure_binary(s)))
return enc(username), enc(passwd) | 06ac8a27a9e3e0e0efa045e82cb12a235eaf90de | 244,852 |
def make_move(state, coord, currentplayer):
"""Update the current board using a coordinate pair and the current
player."""
row, col = coord
state[row, col] = currentplayer
return state | 435d4d3e439e622f9441ac8ce7bb0a7222b54397 | 200,731 |
def quotestr(v):
"""Quote a string value to be output."""
if not v:
v = '""'
elif " " in v or "\t" in v or '"' in v or "=" in v:
v = '"%s"' % v.replace(r'"', r"\"")
return v | 9051d54c8716e78c0e684855bba32c2e7531588b | 488,400 |
def user_from_face_id(face_id: str) -> str:
"""Returns the name from a face ID."""
return face_id.split("_")[0].capitalize() | c49cc881b33699775338a0a772276702874029f3 | 69,470 |
def get_commands_file(filename):
"""
This takes a sql script file and breaks it down to commands to be executed separately
returns list(string) of individual commands
"""
with open(filename, "r") as sql_file:
# Split file in list
ret = sql_file.read().split(';')
# drop last e... | efd475bc5b79b5a1410c2f6b29e5ebf0c42aeda0 | 79,705 |
def get_bruised_limbs(life):
"""Returns list of bruised limbs."""
_bruised = []
for limb in life['body']:
if life['body'][limb]['bruised']:
_bruised.append(limb)
return _bruised | 8218fd689f531bc00b75469aa1be57cc63527c6d | 453,700 |
def convert_to_list_with_index(items: list) -> list:
"""
Prepare simple list to inquirer list.
Convert to dicts list, with 2 keys: index and value from original list
Args:
items (list): Original items list which needs to convert
Return:
list: List of dicts with index key and item
... | a8678056e96207caecbca88f25e62c0ca6eb1807 | 143,341 |
def z_score(input_data, axis = None):
""" compute the z score for a given input matrix and axis """
input_mean = input_data.mean(axis = axis, keepdims = True)
input_std = input_data.std(axis = axis, keepdims = True)
return (input_data - input_mean) / input_std | 9dc1807970e753f662499a6d389d0d2c5a62aab2 | 407,311 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.