content stringlengths 39 9.28k | sha1 stringlengths 40 40 | id int64 8 710k |
|---|---|---|
def topLeftToCenter(pointXY, screenXY, flipY=False):
"""
Takes a coordinate given in topLeft reference frame and transforms it
to center-based coordiantes. Switches from (0,0) as top left to
(0,0) as center
Parameters
----------
pointXY : tuple
The topLeft coordinate which is to be ... | eb3dd24fc4f26d74fa69c5988895da6fb4adca25 | 148,596 |
from bs4 import BeautifulSoup
def html(icon: str) -> BeautifulSoup:
"""Return the icon as HTML tag."""
return BeautifulSoup(icon, "html.parser") | 86d59392f7867f724f6308264759e884b9502869 | 310,857 |
def media(a, b, c):
"""Calcula a média ponderada de três notas"""
med = ((2 * a) + (3 * b) + (5 * c))/10
return print(f'MEDIA = {med:.1f}') | f40cafc8219b648a3cebeafa95f6a0cf319f47ae | 398,491 |
import string
import random
def filenameGenerator(size=12, chars=string.ascii_uppercase + string.digits + string.ascii_lowercase):
"""
Description: generate randon filename with .csv extension
Input: size (optional), chars (opional)
Return: filename
"""
return ''.join(r... | dba0eb435e76eb6f3c69d0a6612fe6945fdf7035 | 165,243 |
def merge_dict(a: dict, b: dict) -> dict:
"""
Merge 2 dictionaries.
If the parent and child shares a similar key and the value of that key is a dictionary, the key will be recursively
merged. Otherwise, the child value will override the parent value.
Parameters
----------
a dict:
P... | cc827b5d8cba295b7eeda0723a3ae2a664c296f9 | 658,415 |
def get_file_info_from_url(url: str, spec_dir: str):
"""
Using a url string we create a file name to store said url contents.
"""
# Parse a url to create a filename
spec_name = url.replace('https://raw.githubusercontent.com/', '')\
.replace('.yml', '')\
.replace... | 229de0038d0b0249a68a7e4c058f76f972296fac | 652,606 |
def _indent_for_list(text, prefix=' '):
"""Indent some text to make it work as a list entry.
Indent all lines except the first with the prefix.
"""
lines = text.splitlines()
return '\n'.join([lines[0]] + [
prefix + l
for l in lines[1:]
]) + '\n' | 98da37331f46f50e775bf4676d9d45c8274ffa03 | 666,596 |
def get_swap_array(orient):
"""Gives how to reorder and flip the axes to fit scanner space
[phase, readout, slice] -> [x,y,z]
Used with np.moveaxes
Args:
orient -- procpar parameter 'orient'
Returns:
arr -- sequence of new axes
flipaxis -- axis to flip
sliceaxi... | c3ec0373d6219626ac4e36ad0fb25dcfd09bf35d | 493,962 |
import re
def get_libc_version(path):
"""Get the libc version.
Args:
path (str): Path to the libc.
Returns:
str: Libc version. Like '2.29', '2.26' ...
"""
content = open(path).read()
pattern = "libc[- ]([0-9]+\.[0-9]+)"
result = re.findall(pattern, content)
if result:
... | fd6d505c9bfe287ec642999160888260064cd4a3 | 506,096 |
def make_year_column(economy_data):
"""
Make year column
:param economy_data: pandas economy data
:return: dataframe with year column
"""
years = list(economy_data.columns)
economy_data = economy_data.transpose()
economy_data['year'] = years
return economy_data | c1fc323221637341994ee19f48a89f12e28cb837 | 380,581 |
def convert_range_to_number_list(range_list):
"""
Returns list of numbers from descriptive range input list
E.g. ['12-14', '^13', '17'] is converted to [12, 14, 17]
Returns string with error message if unable to parse input
"""
# borrowed from jpalanis@redhat.com
num_list = []
exclude_nu... | 31faa5b80baecccea7975237fc9796d7ca784c84 | 66,575 |
def guess_type(cube_arr):
"""Predicts the class based on the highest probability
Args:
cube_arr (np.array): cube array data
"""
return cube_arr.argmax(axis=1) | be46493cac7d9232832f02c0c726874ec05e230f | 325,245 |
from io import StringIO
def _unpack(bytes):
"""Unpack C{bytes} into a digest, keyInfo, iv, and a payload.
@return: a 4-tuple of digest, keyInfo, iv, and payload.
"""
buffer = StringIO(bytes)
digest = buffer.read(20)
keyInfo = buffer.read(4)
iv = buffer.read(16)
payload = buffer.read()... | 10858aa79fc86d3c48e348e1be42e2145215b5b7 | 445,581 |
def collapse_complexes(data, conjugate_flag=False):
"""Given a list or other iterable that's a series of (real, imaginary)
pairs, returns a list of complex numbers. For instance, given this list --
[a, b, c, d, e, f]
this function returns --
[complex(a, b), complex(c, d), complex(e, f)]
T... | 12d089ebc6b1fb882e0ae32fc71740794b595f00 | 688,107 |
def all_but_last(seq):
""" Returns a new sequence containing all but the last element of the input sequence.
If the input sequence is empty, a new empty sequence of the same type should be returned.
Example:
>>> all_but_last("abcde")
"abcd"
"""
newSeq = seq * 0
for i in range(len(seq) -... | f88182e8efd2c56f4cc59a4be2fce2f8c06b3b91 | 158,568 |
def parity(byte):
"""
Return True if the number of bits that are set is even.
"""
return str(bin(byte)).count('1') % 2 == 0 | 670fa6344a0941104bb5feee480b7bd4426f08c8 | 192,171 |
def find_correct_weight(program_weights, program, correction):
"""Return new weight for node."""
return program_weights[program] + correction | 994c25efef10fa37971372f444a879e816708830 | 8,998 |
def _validate_ld_matrix(ld_mat):
"""
Takes an `LDMatrix` object and checks its contents for validity.
Specifically, we check that:
- The dimensions of the matrix and its associated attributes are matching.
- The LD boundaries are correct.
- The masking is working properly.
:param ld_mat: ... | 96b1883f369a8a5e920c8afd3c9ed5ce1c268e32 | 260,391 |
from typing import List
from typing import Tuple
def start_end_locations_from_locations(
locations: List[float],
) -> Tuple[List[float], List[float]]:
"""
Calculates the start and end times of each location
Ex) 5, 10, 15
start_times == 5, 10, 15
end_times == 10, 15, 15
Returns
... | ea6df1e9cbc216c2d06a5685c04936363a40c25f | 234,011 |
import re
def split_user(userid):
"""Return the user and domain parts from the given user id as a dict.
For example if userid is u'acct:seanh@hypothes.is' then return
{'username': u'seanh', 'domain': u'hypothes.is'}'
:raises ValueError: if the given userid isn't a valid userid
"""
match = r... | 9419ca7a4f20b7393752476e9889a0eb62f0fbd7 | 420,226 |
def add(vec_1, vec_2):
"""
This function performs vector addition. This is a good place
to play around with different collection types (list, tuple, set...),
:param vec_1: a subscriptable collection of length 3
:param vec_2: a subscriptable collection of length 3
:return vec_3: a subscriptable ... | 4a17a82422cef472decb37c376e8bf5259ade60a | 707,653 |
def is_sentence(sentence):
"""
Evaluates if the input is a sentence (more than one word)
"""
return len(sentence.split(' ')) > 1 | 1eed35f0d0655edf225999687a7a10de7e613505 | 138,356 |
def parsePoint(storedPt):
"""
Translates a string of the form "{1, 0}" into a float tuple (1.0, 0.0)
"""
return tuple(float(c) for c in storedPt.strip("{}").split(",")) | e9d7f88c866fe0f504119258488df90b9e56024f | 685,098 |
def get_ffmpeg_concact(file_names):
"""Returns the file names in a formatted string for the 'ffmpeg concat' command"""
lines = ["file '{}'".format(f) for f in file_names]
return '\n'.join(lines) | 6c13d27821f212c253c9a44d276b8e9cdc48657a | 595,789 |
def get_reverse_endian(bytes_array):
"""
Reverse endianness in arbitrary-length bytes array
"""
hex_str = bytes_array.hex()
hex_list = ["".join(i) for i in zip(hex_str[::2], hex_str[1::2])]
hex_list.reverse()
return bytes.fromhex("".join(hex_list)) | eb610455fd39b9973e4c764e61c066e2952f2665 | 286,824 |
def add_three(src: int) -> int:
"""3 を足して返す。
Args:
src (int): 元の値
Returns:
int: 3 を足した値
"""
return src + 3 | a7783e9e79df90ab9baa6d70457069205b59f4b4 | 320,329 |
def define_pagination_variables(limit, offset, homophonesGroupCollection):
""" Define previous URL, next URL, total number of pages and current page based
on the limit and offset. """
if offset - limit < 0:
prevURL = None
else:
prevURL = f'/p/?limit={limit}&offset={offset - limit}'
totalDocuments = homophone... | bfd370457b2c5dd6683be7198d608162720e6ee7 | 566,318 |
def find_parameter(env, param, role=""):
"""
Find a parameter in an environment map and return it.
If paramter is not found return 0.
Supports role parameters too. E.g. given the following
inside of env, with param=CephHciOsdCount and role="",
this function returns 3. But if role=ComputeHCI, th... | 507862516cb99e3e07354c027dc373d24de879ee | 608,428 |
def parse_input_args(input_str: str):
"""
Utility to parse input string arguments. Returns a dictionary
"""
output_dict = {}
if not input_str:
raise ValueError("Empty input string: {}".format(input_str))
key_pairs: list = input_str.split(",")
key_pairs = [x.strip() for x in key_pai... | bd49087607ca223b1bb4de4261a71242416ce616 | 390,109 |
import re
def extract_tarball_url(_tail):
"""
Extract the tarball URL for missing user code if possible from stdout tail.
:param _tail: tail of payload stdout (string).
:return: url (string).
"""
tarball_url = "(source unknown)"
if "https://" in _tail or "http://" in _tail:
patt... | 97d8d2e74a3b152bd1fe822b1501e01a8331c30c | 174,659 |
import re
def file_sort(my_list):
"""
Sort a list of files in a nice way.
eg item-10 will be after item-9
"""
def alphanum_key(key):
"""
Split the key into str/int parts
"""
return [int(s) if s.isdigit() else s for s in re.split("([0-9]+)", key)]
my_list.sort(... | 55e59aa0166769278f0911c3c784079557f7c162 | 352,779 |
def is_npy(s):
"""
Filter check for npy files
:param str s: file path
:returns: True if npy
:rtype: bool
"""
if s.find(".npy") == -1:
return False
else:
return True | 28263f183974b64762a69e3e41d57e92265175b5 | 570,903 |
def _get_db_table_for_model(model):
"""
Return table name in database server for passed model.
"""
return model._meta.db_table | 14607fd11ae308b371af45232467bbe13fe907ac | 646,617 |
def build_conflicting_scores_string(conflicting_scores):
"""Builds a printable string from a conflicting scores list"""
string_builder = ""
for i in conflicting_scores:
string_builder += f"\n\"{i[0].name}\" match score: {i[1]}"
return string_builder | 7677e3e412971ee4ba35208a58dbd5ae0f51961e | 548,653 |
def Notas(*valores, sit=False):
"""A função consiste de dois parâmetros:
-Valores: indica as notas do aluno, cuja quantidade é variada.
-Sit: indica se a situação deverá ou não ser mostrada (é falsa por padrão).
A função retorna um dicionário contendo a maior e a menor nota, bem como a média e, por fim, a s... | e018804eac02e3146c53ebcd4cfd9c0dc10fd8e3 | 522,340 |
def strip_port_from_host(host):
"""
Strips port number from host
"""
return host.split(':')[0] | 033b5e1725e85b9f6945bdc114c3ae4309ef78a8 | 111,188 |
def _block_prepend(string, val):
"""Prepend val to each line of string."""
return "\n".join(
map(lambda l: val+l, string.split("\n"))
) | 915086d46e06e3cdc3daeb51374f3ebf178ace37 | 236,877 |
def find_pport(sys_w, physloc):
"""Find an SR-IOV physical port based on its location code.
:param sys_w: pypowervm.wrappers.managed_system.System wrapper of the host.
:param physloc: Physical location code string (per SRIOV*PPort.loc_code) of
the SR-IOV physical port to find.
:retu... | 045d9e7e508f3111ac7da70710f7a2e5e38249de | 231,525 |
def drop_id_prefixes(item):
"""Rename keys ending in 'id', to just be 'id' for nested dicts.
"""
if isinstance(item, list):
return [drop_id_prefixes(i) for i in item]
if isinstance(item, dict):
return {
'id' if k.endswith('id') else k: drop_id_prefixes(v)
for k, v... | 6fc752fa49771a0fc6e7e28e889cf29941a95a10 | 47,696 |
def primitives_usages(request):
"""Fixture to return possible cases of promitives use cases."""
return request.param | a36f59d124a20f73d19ea63df85f919b9b5681f3 | 74,307 |
def block_properties(img_size, blk_size):
"""Calculates properties for sliding window processing
:param img_size: Size of input image
:param blk_size: Size of individual blocks
:return: Number of rows and cols of the resulting matrix
"""
map_rows = int(img_size[0] / blk_size)
map_cols = int... | 365159f1c1b6ecbf8118f6523976afd442b6c9b1 | 220,344 |
def almost_equal(a, b, rel_tol=1e-09, abs_tol=0.0):
"""A function for testing approximate equality of two numbers.
Same as math.isclose in Python v3.5 (and newer)
https://www.python.org/dev/peps/pep-0485
"""
return abs(a-b) <= max(rel_tol * max(abs(a), abs(b)), abs_tol) | d2f9091216c69421fdef9c6d26804a157e731289 | 522,947 |
import base64
import json
import time
import hmac
import hashlib
def extractAndValidateBody(
body: str,
key: str = "",
signature: str = "",
isBase64: bool = False,
with_validate: bool = True,
) -> dict:
"""
Basic parsing of the body, including optional validation of a HMAC, to a dict
... | 7e8d514c368c58fc0fd8a61fe065b4166666d31f | 530,412 |
import numbers
def _time2sec(time):
"""Convert string (e.g. 1d or 0.5h) to seconds"""
if not isinstance(time, numbers.Number):
time, unit = float(time[:-1]), time[-1]
assert unit in 'dh'
time *= 24 * 3600 if unit == 'd' else 3600
return time | 997b5d5fc2a6d6cc395deeadcffffb9a0bf53762 | 552,291 |
def GetKeyIdFromResourceName(name):
"""Gets the key id from a resource name. No validation is done."""
return name.split('/')[5] | 3f6d2a06adfebe684e8b1f637ebfc12417169b2a | 662,187 |
def learner_name(learner):
"""Return the value of `learner.name` if it exists, or the learner's type
name otherwise"""
return getattr(learner, "name", type(learner).__name__) | 1da28e9c918df8e3bdf994df3cf2b7bbd6146d76 | 661,879 |
import math
def elastic_easeinout(pos):
"""
Easing function for animations: Elastic Ease In & Out
"""
if pos < 0.5:
return 0.5 * math.sin(13 * math.pi * pos) * math.pow(2, 10 * ((2 * pos) - 1))
return 0.5 * (
math.sin(-13 * math.pi / 2 * ((2 * pos - 1) + 1)) * pow(2, -10 * (2 * pos... | a4f645de3fc46b9ef41ce6aa7645b2e7d3751b38 | 456,735 |
def print_same_line(s: str, fill_num_chars: int, done: bool = False) -> int:
"""A helper to repeatedly print to the same line.
Args:
s: The text to be printed.
fill_num_chars: This should be `0` on the first call to
print_same_line() for a series of prints to the same output line. The... | e9926b538473dbfba11fab0d121b58dd845e5d4c | 23,204 |
def rgb2hsv(rgb):
"""Converts RGB to HSV.
Note that H may be None when S is 0 (for grey colors).
"""
r, g, b = rgb
minimum = min(r, g, b)
maximum = max(r, g, b)
v = maximum
delta = maximum - minimum
if delta != 0:
s = delta / maximum
else:
# h is undefined
... | f3f95c7c8d8c3dc5fef54712c6d3683f7c99ca10 | 275,456 |
def check_puzzle_list(lst, n):
"""
Checks a puzzle one dimensional list and validates it.
lst : The list to be validated.
n : Puzzle type (n-puzzle).
Returns True of it's fine and False if it's not valid.
"""
# Check list's length
if len(lst) != n + 1:
return False
lst = ... | 3ee5f7459e48104d2798b9147fef48295f327fe4 | 562,081 |
def template_escape(text: str) -> str:
"""Returns the text escaped an ready for usage in a Jinja template
Escapes {{, {% and {#
Example
>>> template_escape("{% value }")
"{{'{%'}} value }"
Args:
text (str): The text to escape
Returns:
str: Escaped text
"""
escape... | df0d8bcdc23ca18824f70a99cc216aefc1a4d8c9 | 481,947 |
def _calc_ta(eff, n_gre, tr_gre, tr_seq, ti1, ti2, a1, a2):
"""Calculate TA for MP2RAGE sequence."""
return (2.0 * ti1 - n_gre * tr_gre) / 2.0 | 06f3891743cef4dcd7ac9ad6c87d9dae945484a8 | 379,593 |
def has_trailing_slash(p):
"""Checks if a path has a single trailing slash"""
if not p:
return False
return str(p)[-1] == '/' | a45620d801229d2f572557716057c39f35a20c17 | 194,249 |
def check_int(integer):
"""
Check if number is integer or not.
:param integer: Number as str
:return: Boolean
"""
if not isinstance(integer, str):
return False
if integer[0] in ('-', '+'):
return integer[1:].isdigit()
return integer.isdigit() | 2f020ca2b07bddcbbd72fc473a99258638e49191 | 552,189 |
import math
def safe_sqrt(val):
"""
Safely calculates the square root of a value. If the value is -1 (unknown),
then the result is -1 (unknown).
"""
return -1 if val == -1 else math.sqrt(val) | 77d1d61d81a29f226054685b2f92be1baf6bdcb6 | 594,018 |
def split_rule_matrioska(rule):
"""Split a rule for knowing which bag can contain another bag
"""
return rule.split(' bags contain ') | de06ec496f2bcf7bd8b57226be6bf11fdd11ebd1 | 408,128 |
def get_category(risk_attr):
"""
Assigns a category to a given risk attribute,
that is to a human at a given hour of a given day
Args:
risk_attr (dict): dictionnary representing a human's risk at a given time
Returns:
str: category for this person
"""
if risk_attr["test"]:... | 39abaccd032cdfdf294f0c1c3db662364cb52ff6 | 545,523 |
def limit_to_box(x, box):
"""select only the points within a given box."""
mf = x.copy()
for i, t in enumerate(box):
mf = mf[mf[:, i] >= t[0], :]
mf = mf[mf[:, i] <= t[1], :]
return mf | 46c5be7acaefdfffe5ead23102cba03dc856bac8 | 385,197 |
def crop_center(img, cropx, cropy, cropz):
"""
Take a center crop of the images.
If we are using a 2D model, then we'll just stack the
z dimension.
"""
x, y, z, c = img.shape
# Make sure starting index is >= 0
startx = max(x // 2 - (cropx // 2), 0)
starty = max(y // 2 - (cropy // 2... | 047144047667bafd02e5ef5691b3382391680e44 | 63,910 |
def parse_project_id(project_id):
"""Simple check for project id.
:param project_id: a numeric project id, int or string.
:return: a unified project id.
:rtype: :class:`str`
"""
try:
int(project_id)
except ValueError:
raise ValueError("Project id should be convertible to int... | 2f5b2d737596b4df21fd6887e69e59175542feb1 | 505,916 |
def get_institution(soup):
"""Return institution name (or None, if there is no institution name)."""
institution = soup.find('div', style="line-height: 30px; \
text-align: center; margin-bottom: 1ex").find('span').find('span').text
if not institution:
institution = None
return institution | 86381acfde88cb50627a866f3877db6a47ebf1c4 | 375,898 |
from typing import Tuple
def rgb_to_int(x: Tuple[int, int, int]) -> int:
"""Return an integer from RGB tuple."""
return int(x[0] << 16 | x[1] << 8 | x[2]) | eb9eeb8e7a4347a00837effa2c731ec62b496746 | 441,551 |
import torch
def complex_conj(x: torch.Tensor) -> torch.Tensor:
"""
Complex conjugate.
This applies the complex conjugate assuming that the input array has the
last dimension as the complex dimension.
Args:
x: A PyTorch tensor with the last dimension of size 2.
Returns:
A Py... | 5744be8a438cbb7848c352530d6d9c6371737ec7 | 563,008 |
import math
def exp_ce(x: float, a: float = 1) -> float:
""" Inverse of exp_utility """
return -math.log(1 - x) / a | 224164fae4d21c4dcba9d19238ab8bba74efd470 | 125,602 |
from typing import Tuple
def hex_to_rgb(hex_value: str) -> Tuple[int, int, int]:
"""
Converts a valid hexadecimal color string given by '#XXXXXX' to a tuple representing RGB values.
If the string representation does not match the above description, a ValueError is raised.
:param hex_value: String repr... | 2fbbfd2958c86a8e36d5e26f58ecf566873ce79b | 467,670 |
def make_array_header(byte_string: bytes, name: str) -> str:
"""Returns the header define for an array with the given name and size."""
byte_string = bytearray(byte_string)
return 'extern const uint8_t ' + name + '[{:d}];\n'.format(len(byte_string)) | 2b4ef7b5b90122a22d462e67b81e4cf56173108a | 255,185 |
def get_angle_unit_data(sum_df, **kwargs):
"""
Function: get angle unit information from measured target positions.
Input:
- sum_df: DataFrame. processed DataFrame that contains both bundle heel and target info and growth cone length and angle info.
- kwargs: additional parameters
- 'criteria': Dataframe with Bo... | 5ec2d1c3d0ed819d3322258f1eae347424fbb7d2 | 125,589 |
def is_requirements_empty(requirements_file_path):
"""
Tests to see if a pip requirements.txt file is empty.
:param requirements_file_path: the path to the requirements.txt file
:return: True if it is empty, False otherwise
"""
fp = open(requirements_file_path)
line_c... | b6b4820b4c771ec93ec86a466807c3d26fad315f | 184,450 |
def version_to_float(version):
"""
Convert version string to float.
"""
if version.endswith('b'):
return float(version[:-1])
return float(version) | 2dfa2003fdf7f6344ebccb00cc12c618eb863708 | 39,397 |
def as_iterable(iterable_or_scalar):
"""Utility for converting an object to an iterable.
Parameters
----------
iterable_or_scalar : anything
Returns
-------
l : iterable
If `obj` was None, return the empty tuple.
If `obj` was not iterable returns a 1-tuple containing `obj`.
Ot... | a0b19a89715e6c06c3f5dc9d66480c9c1f44ea42 | 616,064 |
def rename_key(key):
"""Rename state_dict key."""
# ResidualBlockWithStride: 'downsample' -> 'skip'
if ".downsample.bias" in key or ".downsample.weight" in key:
return key.replace("downsample", "skip")
return key | d7a5638fca107ea31d6910ce7730c4376fdeedd6 | 121,687 |
def get_picard_max_records_string(max_records: str) -> str:
"""Get the max records string for Picard.
Create the 'MAX_RECORDS_IN_RAM' parameter using `max_records`. If
`max_records` is empty, an empty string is returned.
"""
if max_records is None or max_records == "":
return ""
else:
... | f337511815b9f2d4381f868e1937393374932a3a | 585,231 |
import time
def utc_to_epoch(utc):
"""
Take UTC formatted date and return it in
millisecond accurate epoch time.
"""
timeformat = '%Y-%m-%d %H:%M:%S+00'
return int(time.mktime(time.strptime(utc, timeformat)) * 1000) | 7aac2c6e4b3429e1de129f3e96b64ae44a357bf1 | 399,810 |
def _non_blank_line_count(string):
"""
Parameters
----------
string : str or unicode
String (potentially multi-line) to search in.
Returns
-------
int
Number of non-blank lines in string.
"""
non_blank_counter = 0
for line in string.splitlines():
if li... | dfa6f43af95c898b1f4763573e8bf32ddf659520 | 708,450 |
def get_count_coprime_number_count(prime_1: int, prime_2: int) -> int:
"""
get_count_coprime_number_count returns the number of coprime numbers
between prime_1 and prime_2
Args:
prime_1 (int): prime number
prime_2 (int): prime number
Returns:
int: number of coprimes in the ... | 437797d12205d51500bfc22478fdb4d697eeaff7 | 152,247 |
def get_id(vmfObject, idPropName='id'):
""" Returns the ID of the given VMF object. """
return int(vmfObject[idPropName]) | ffed36fe64194c5d9aeb5f154639b9f321b33a7d | 635,215 |
def get_index(x, item):
""" return the index of the first occurence of item in x """
for idx, val in enumerate(x):
if val == item:
return idx
return -1 | fc584087cd9b54ea2e42080a796c578ddbae6676 | 475,356 |
def getFolder(filename: str) -> str:
"""
Returns the folder on which the given path is stored
Args:
filename: the path of the file
Returns:
the folder of the same given file
"""
filename = filename.replace("\\", "/")
try:
filename = filename[0:-filename[::-1].index(... | 3cbbeefa494ea3b4ec9454e2bf38bd32c76169b3 | 486,733 |
def modulus(angka1: float, angka2: float) -> float:
"""
hasil dari modulus antara angka1 dan angka2
>>> modulus(3.0, 2.0)
1.0
"""
return angka1 % angka2 | 13442aabaecff54ebd036f48d5c27af002584354 | 634,022 |
def merge_extras(extras1, extras2):
"""Merge two iterables of extra into a single sorted tuple. Case-sensitive"""
if not extras1:
return extras2
if not extras2:
return extras1
return tuple(sorted(set(extras1) | set(extras2))) | 0383e0e99c53844f952d919eaf3cb478b4dcd6d1 | 5,673 |
import random
import copy
def partition(n,m,minQuota,maxQuota):
"""
Function to partion a particular integer.
Parameters:
n (int) - the number we want to partition.
m (int) - the number of blocks we want.
minQuota (int) - the minimum size of a block.
maxQuota (int) - the m... | 73587a6c4544be9c282d94027c18299bcf29adfc | 630,107 |
def get_plot_title(l_table, adm_key, adm_value):
"""Determine plot title for a given area based on adm code and lookup table.
For ADM0 and ADM1 plots, uses names. For ADM2 plots, the ADM1 name is
included in addition to the ADM2 name.
Parameters
----------
l_table : pandas.DataFrame
Da... | d26a3366a09b741cac3443b75637d308fb7719e9 | 378,887 |
def add_match_to_profile(profile, match, ismap=True, nucl=None):
"""Merge current read-gene matches to master profile.
Parameters
----------
profile : dict
Master gene profile.
match : dict
Read-gene matches.
ismap : bool, optional
Whether matches are a read-to-gene(s) m... | 0431ec934881ccf2bb72f2367e6a1afcbcc38e5d | 685,880 |
def get_highest9(pair_list):
"""Gets the pairs with the highest 9 scores.
If there is a tie for the 9th highest score, will return all that
match it.
Assumes pair_list[0] has the lowest score and the score
is the first element of the pair.
"""
cutoff_score = pair_list[-9][0]
result = p... | 5b63975d8eeb8a1ba42e501a228be789125fa58a | 432,307 |
def _get_limb_section(asm_str):
"""decode the limb and the section (h or l) from limb (e.g "4l")"""
if len(asm_str.split()) > 1:
raise SyntaxError('Unexpected separator in limb reference')
if asm_str.lower().endswith('l'):
s = 0
elif asm_str.lower().endswith('h'):
s = 1
else:... | 332a2154ac851c5a92697cde0654dca164d17c79 | 559,444 |
import struct
def _unpack_single(t, data):
"""
Unpacks and returns the first piece of data from a struct
"""
try:
return struct.unpack(t, data)[0]
except:
print(data)
raise | 325051e53ac20768f3a16b116f4cc88d4dbb6e23 | 426,640 |
from typing import Union
def concat_keypath(*args: Union[str, int]) -> str:
"""Concatenate partial keypaths and keys into a concatenated single
keypath.
Args:
*args (Union[str, int]): The partial keypaths and keys to concatenate.
Returns:
str: the concatenated keypath.
"""
re... | ef9c2e0c8d1e6ed35071f4e6bdddc73f72161541 | 341,262 |
def get_attributes(parent, selector, attribute):
"""Get a list of attribute values for child elements of parent matching the given CSS selector"""
return [child.get(attribute) for child in parent.cssselect(selector)] | f4fecaf7aa16465a63e3e1dd062465b4cc810ad8 | 654,176 |
def default_version_splitter(instring):
"""Split the version string out of version output."""
return instring.split()[-1] | b9939fa5e0d01ce798b8184bc49a1a627f7034f0 | 599,822 |
def is_oppo_pass(event_list, team):
"""Returns whether an opponent passed the ball (likely a bad pass)"""
oppo_pass = False
for e in event_list[:1]:
if e.type_id == 1 and e.team != team and e.outcome == 0:
oppo_pass = True
return oppo_pass | 0e7d4e97a60f9e907f91caee2a7b1eeae6e52e96 | 261,876 |
def fixed_point_integer_part(fixed_point_val: int, precision: int) -> int:
"""
Extracts the integer part from the given fixed point value.
"""
if (precision >= 0):
return fixed_point_val >> precision
return fixed_point_val << precision | 5abf5c8dc9bbb0ba24099ff35fc0128c03fc791f | 621,324 |
import pickle
def load_pickle(filename, channel=-1, verbose=0):
"""
Load Joerg's pickle files.
Parameters
----------
filepath: string
The full path and name of the file to load.
channel: int
The data channel. If negative all channels are selected.
verbose: int
if >... | 59c1b4f19149078cc43e6f0b171fb7e2c77013f4 | 600,419 |
def select_one(src, rel, dst):
"""
Create an SQL query that selects one ID from a
relation table given a source and destination node.
:param src: The source node.
:param rel: The relation.
:param dst: The destination node.
"""
smt = 'SELECT src FROM %s WHERE src = ? AND dst = ? LIMIT 1'... | f8fba18226a265778b686934fdc235b9d40b732b | 273,449 |
import re
def _add_missing_tags(html_doc):
"""Fixes a issue in the orginal HTML, where the tag <Option> is not closed..
Changes from:
<Select Name=Linha class='ordenacaoSelect'>
<Option Value='510-87'>510 - AUXILIADORA
<Option Value='620-5'>520 - TRIANGULO/24 DE OUTUBRO
To:
<Se... | 54efd589e9ef1054bd9cfa9e1632b4383a6c86e3 | 220,151 |
def _build_arg_list(tokens):
"""Given a list of Tokens for a line, return an argument list. A
tag with no arguments which includes parentheses should be returned
as an empty tuple. A tag with no arguments which does not have
parentheses will be returned as None."""
try:
# Check for an openin... | 24ae3db836487f93ba5e69d0fd9336371b527567 | 480,348 |
import pathlib
def create_file(root_path, file_name):
"""Touch file of file_name at root_path.
This function touch new empty file which name file_name at root_path.
----------
Args:
root_path(str): project rootpath.
file_name(str): file name created under project root.
Returns:... | 929b4fece26875864be6916d07da7f895d49acb2 | 384,869 |
def f_to_c(fahrenheit):
"""Convert to Celsius."""
return (fahrenheit - 32.0) / 1.8 | 6cc214ed0c985b71758c5be8fbcf826debe9acf7 | 528,462 |
def count_y_clusters(y):
"""
Count BGCs regions in a list of protein domain BGC states. Done by counting all consecutive 1 as one region.
:param y: List of BGC states (0 = non-BGC, 1 = BGC), one state for each protein domain
:return: Count of BGCs in given list of protein domain BGC states.
"""
... | c37936f7d7a4ca8b56eddd29c1626675a9b209cf | 366,230 |
def _chname(x):
"""
Returns changed name. Removing the last *
"""
return x[:-1] if x[-1] == '*' else x | ae9c08eb259a5be868d2b707476067e623a8e533 | 188,848 |
def _timeitlike_time_format(time_seconds, precision=3):
"""Shamelessly adapted formatting from timeit.py
Parameters
----------
time_seconds : float
The time in seconds
precision : int
The precision of the output. All digits.
Returns
-------
str
A timeit-like for... | f81c00f1ff3c5c1f223785c24bcd181cee939a3a | 430,370 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.