content stringlengths 39 9.28k | sha1 stringlengths 40 40 | id int64 8 710k |
|---|---|---|
def extract_status_code_from_topic(topic):
"""
Topics for responses from DPS are of the following format:
$dps/registrations/res/<statuscode>/?$<key1>=<value1>&<key2>=<value2>&<key3>=<value3>
Extract the status code part from the topic.
:param topic: The topic string
"""
POS_STATUS_CODE_IN_T... | a75dd25e4236b37a54ee764b9caf2863c1e13873 | 120,442 |
def generate_numbers(partitions):
"""Return a list of numbers ranging from [1, partitions]."""
return list(range(1, partitions + 1)) | 8c1ad09496c4cbddb53c8b93d162d78e3e41b60e | 25,417 |
def share_edge(label, uv1, uv2, h, w):
"""Determine if two uv share an edge."""
if uv1[0] == uv2[0]:
if uv1[0] == 0 or uv1[0] == w:
return True
elif uv1[1] == uv2[1]:
if uv1[1] == 0 or uv1[1] == h:
return True
else:
return False | ad999f355a8386903c12ca514edcf195b2baad30 | 421,411 |
def sort_matrix(df, sort_columns=True):
"""Sorts a DataFrame, first by its columns and then by its rows."""
if sort_columns:
freqs = (df.astype(float) > 0).sum(axis=0)
order = list(freqs.sort_values(ascending=False).index)
else:
order = list(df.columns)
df_sorted = df[order]
... | 8eb00ed0478ff99de256aaf9bf0370218357c2b3 | 292,239 |
import hashlib
def CreateIdentifier(str_id):
"""Return a 24 characters string that can be used as an identifier."""
return hashlib.sha1(str_id.encode("utf-8")).hexdigest()[:24].upper() | c4a950e7ba39d0ea22790db928d933d6b89f0d69 | 423,806 |
def get_patient_status(index, patients): # test
"""Retrieves most recent heart rate with associated status and time stamp
Args:
index (int): index of patient to be located in list
patients (dictionary): list of patients in database
Returns:
dictionary: if data available, contains ... | 999438c3e0661ff85cc69ecc5c7e8981ce92dde7 | 539,667 |
import itertools
def cross_named_parameters(*args):
"""Cross a list of lists of dicts suitable for @named_parameters.
Takes a list of lists, where each list is suitable as an input to
@named_parameters, and crosses them, forming a new name for each crossed test
case.
Args:
*args: A list of lists of di... | 51863e234e74ecc8398cbce9e755de868e4ec942 | 552,263 |
def loss_inversely_correlated(X, y):
"""
Return
-1 * (concept_direction * prediction)
where
prediction = X[0]
concept_direction = y
"""
prediction, *_ = X
concept_direction = y
return -1 * (concept_direction * prediction) | 9d7649c40d6cc3053b3ce721a468f8079a2be0c8 | 252,973 |
def get_fabric_design(fabric_design_uri, rest_obj):
"""
Get the fabric design name from the fabric design uri which is returned from GET request
:param fabric_design_uri: fabric design uri
:param rest_obj: session object
:return: dict
"""
fabric_design = {}
if fabric_design_uri:
... | 6f615548fd0e49419eef5f3f79d860e21ad3a344 | 491,663 |
def get_param_name_list(expressions):
"""Get parameter names from a given expressions list"""
return sorted(list({symbol.name for expression in expressions for symbol in expression.free_symbols if "x" not in symbol.name})) | 706a7077fe4971e72758d9757d9dfcbf4e34f28a | 197,440 |
import requests
from bs4 import BeautifulSoup
def get_page(url):
"""
Simple funtion that get the url with requests and return a bs4 object.
:param (str): The string of the url
:return: bs4 object
"""
try:
req = requests.get(url)
return BeautifulSoup(req.text, 'html.par... | 50224f5d660f501874d5951c586bf3ec1b40871c | 334,737 |
def _get_product_id(device_dict):
"""Converts 0x1234 to 1234."""
return device_dict['product_id'].split('x')[-1] | 8719d7022991a4fa53658330b01221a4e886e6a3 | 607,732 |
def get_number_versions(pypi_pkg):
"""Count number of versions released"""
version_list = list(pypi_pkg["pypi_data"]["releases"])
num_versions = len(version_list)
return num_versions | 9711506698d83ae9d4903ae924aac2bf075e3aec | 239,842 |
def org_id_from_org_name(org_name):
"""Extract the organization id (number) from the organization name.
Args:
org_name (str): The name of the organization, formatted as
"organizations/${ORGANIZATION_ID}".
Returns:
str: just the organization_id.
"""
return org_name[len('... | 0f9d324164a930f7eeebee8527cda14396049ba3 | 364,963 |
import builtins
def is_a_builtin(word) -> bool:
"""
Returns True if a word is a builtin python object
Args:
word: word to check
Returns: True if word is builtin python object
"""
return str(word) in dir(builtins) | 5dd2eed08273d8fc5a4bba1e67cc681f3a2488ca | 677,906 |
def split_into_equal_sublists(a_list, number_of_parts):
""" Splits a list into a list of sublists
Arguments
----------
a_list : list object
List wich will be split into Sublists
number_of_parts : int
Number of sublists which should be created
Returns
-------
seperat... | a98098aeff74f2e7be8bae9560a7aebd48b017f0 | 222,150 |
def valid_int(value):
"""Converts the value to an integer value or zero.
"""
try:
result = int(value)
except ValueError:
result = 0
return result | 2addb578b251832b40a11b02d0406b8a3875479f | 323,910 |
def get_remote_accounts(web3, total=6):
"""
Return 6 accounts
(admin, bidder, hoster, validator1, validator2, validator3,
validator4) = get_accounts()
"""
return [web3.eth.accounts[i] for i in range(0, total)] | 8cc381e79fa4ab43ae41b9784c5046f3d39014e1 | 521,726 |
def display_time(seconds, granularity=1):
""" Turns seconds into weeks, days, hours, minutes and seconds.
Granularity determines how many time units should be returned. EG:
# 2 time unites, week and day
1934815, 2 = '3 weeks, 1 day'
# 4 time units
1934815, 4 = '3 weeks, 1 day, 9 hours, 26 minute... | d4b94ffafcdbda99526ecc906ed8379d7fc5edab | 10,624 |
def twoSum(nums, target):
"""
Given an array of integers, return indices of the two numbers such that they add up to a specific target.
You may assume that each input would have exactly one solution, and you may not use the same element twice.
"""
h = {}
for i, v in enumerate(nums):
if v... | a1503f8e43fbdb51d2ed2693444f9ce33ae80914 | 134,311 |
import re
def get_number_in_string(line, pattern=r'\ done\ processing\ event\ \#(\d+)\,'):
"""
Extract a number from the given string.
E.g. file eventLoopHeartBeat.txt contains
done processing event #20166959, run #276689 22807 events read so far <<<===
This function will return 20166959 as ... | ffb323b664fe873dcf2cf75267a0ec3e3390cedf | 88,671 |
def binary_array_to_int(x, sep=''):
"""Turn 1D array `x` of 0s and 1s into integer."""
return int(sep.join(x.astype(str)), 2) | bfbf898b7b53869a86b6c441d1d2d7f63d6c287c | 239,298 |
def crop_border(img, border_x, border_y):
"""Crop the border of an image. Due to peripheral blurring.
Args:
img (np.ndarray): input image
border_x (int): number of pixels to crop on each side of x border
border_y (int): number of pixels to crop on each side of y border
Returns:
... | 9fb5aaa27e90f16b035d731ab99534a13dbcc899 | 300,973 |
def calculate_event_handler_snapshot_difference(client, snapshot_old, snapshot_new):
"""
Calculates the difference between two event handler snapshot returning the difference.
Parameters
----------
client : ``Client``
The respective client instance.
snapshot_old : `dict` of (`str`, ... | 7ff9f6afd548e3a49c797a259c5177316b427469 | 52,619 |
def _find_framework_name(package_name, options):
"""
:param package_name: the name of the package
:type package_name: str
:param options: the options object
:type options: dict
:returns: the name of framework if found; None otherwise
:rtype: str
"""
return options.get(package_name, ... | 3b345a5ccbed309ad7a706dce621a8fd405dd9e4 | 33,717 |
def model_str(instance, attr) -> str:
"""
The field to display for an object's __str__. If the field doesn't exist then an
alternative will be displayed.
:param instance: Instance object
:param attr: Field name to get data from if it exists
:return: str
"""
return ha... | 55934a0514083b75ea46d0690a1405343365f98f | 265,264 |
def pmtcorrection(x_humidity):
"""
Correction factor for low budget pm sensors data based on the research paper 'Developing a Relative Humidity Correction for Low-Cost Sensors Measuring
Ambient Particulate Matter' by Di Antonio et al.
k: the degree of hygroscopicity of a particle.
x_humidity: relati... | 6fd601f5e4d16024a9c12767f2f7ce2238812125 | 403,572 |
from typing import Mapping
from typing import Any
from typing import List
def get_by_keys(data: Mapping[str, Any],
keys: List[Any],
default_value=None,
optional: bool = False) -> Any:
"""Returns value with given key(s) in (possibly multi-level) dict.
The keys repre... | cb488798fcfb301f7a3b147a16f20fbb65ada623 | 373,533 |
def _make_alg_experience(experience, name):
"""Given an experience, extracts the ``rollout_info`` field for an
algorithm.
"""
if experience.rollout_info == ():
rollout_info = ()
else:
rollout_info = getattr(experience.rollout_info, name)
return experience._replace(
rollou... | 888a0ddf3772a42f4d11ec18b8268e42da9b68e1 | 535,770 |
def fairness_metrics_goal_threshold(metric):
"""Returns metric goal and threshold values.
Parameters
----------
metric: str
The name of the metric
Returns
-------
int:
goal value
float:
threshold (+ and -) of the metric
"""
metrics_goal_1 = [
'di... | 20d0b062ca865da85ff4a75078a3b379ac5c73f1 | 292,875 |
import re
def remove_number_of_hits_from_autocomplete(user_entry):
"""
removes number of hits from entry string that has been added by autocomplete
:param user_entry: user entry string with number of hits in parenthesis
:return: user_entry without number of hits
"""
user_entry = re.sub("\([0-9... | e6e356cce3048988a48b03ba7c26da07a03ee8bc | 97,474 |
def age_bracket(x):
"""
Converts ages from [15,65] into age brackets (1,5). If age
is out of that range, returns None
Integer -> String
"""
if 15 <= x < 25:
return '1'
elif 25 <= x < 35:
return '2'
elif 35 <= x < 45:
return '3'
elif 45 <= x < 55:
ret... | 95963b7f2b9a07ee090e6e4a6d049ebe9dc402e1 | 599,123 |
def keep_accessible_residues(naccess_rsa):
"""From the output of naccess we keep only accessible residues
which have a all_atoms_rel value > 30 (arbitrary threshold)
Args:
naccess_rsa: A dictionnary containing the output of naccess's calculations
Returns:
dict: Keys are the residue ids... | d837b6525fd54375ba05029879d57bec36f9cbb5 | 526,005 |
def bias(obs, mod):
"""
Bias = mean(obs) - mean(mod)
"""
return obs.mean(axis=0) - mod.mean(axis=0) | 72315d45513e9181d522ec007ad9d587464f7f79 | 117,002 |
def replace_string_in_list(str_list: list, original_str: str, target_str: str):
"""
Replace a string in a list by provided string.
Args:
str_list (list): A list contains the string to be replaced.
original_str (str): The string to be replaced.
target_str (str): The replacement of st... | 31649c8c7171518598f6b3fe4d5db1b46e5cd573 | 688,225 |
def is_bound(f):
"""Test whether ``f`` is a bound function.
"""
return getattr(f, '__self__', None) is not None | ddc524591d3f262c77373ef8eafbab5112197647 | 196,601 |
import random
def relative_uniform(mean, scale_factor):
"""Returns a value from a uniform distribution where the min and max
are scaled relative to the middle value given as the mean"""
return random.uniform(mean * (1 - scale_factor), mean * (1 + scale_factor)) | 949822c6566b81478c4fd3d8ef2a0775636f6b25 | 339,785 |
def _process_match(rule, syms):
"""Process a match to determine if it is correct, and to find the correct
substitution that will convert the term into the pattern.
Parameters
----------
rule : RewriteRule
syms : iterable
Iterable of subterms that match a corresponding variable.
Ret... | b81c450ddfa2294ef0f1b46597f336ad72be3187 | 398,516 |
def is_valid_triangle(triangle: list) -> bool:
""" Valid triangles have one length greater than the sum of the two shorter lengths.
Args:
triangle (list): side lengths of this triangle
Returns:
[bool]: Whether valid, according to the rules
"""
triangle = sorted(triangle)
return... | a18d8b88bd2a3624ad55e027821a14235dcce6db | 306,824 |
def clean_facet_name(name):
"""Clean facet name, without geo distance ":" suffix"""
return name.partition(':')[0] | 45bb44a54253085c6967b0e6fb706d14b6425afa | 469,066 |
def _fix_filename(filename):
"""Return a filename which we can use to identify the file.
The file paths printed by llvm-cov take the form:
/path/to/repo/out/dir/../../src/filename.cpp
And then they're truncated to 22 characters with leading ellipses:
...../../src/filename.cpp
This makes it real... | d4b005f591879aab44275d100e725f61b5d6a764 | 701,357 |
from pathlib import Path
from typing import Optional
from typing import Callable
from typing import Generator
def collect_paths(
input_base_path: Path,
glob_pattern: str,
path_filter: Optional[Callable[[Path], bool]] = None,
) -> Generator[Path, None, None]:
"""
Collect paths, and apply a filter
... | 349f992bb0ef23b769a0efcc7aab74e9a48f9eb8 | 391,786 |
def T_model_from_NW(NW):
"""Returns Z1, Z2, and Z3, computed from the [ABCD] parameters of
the NW (object of Network Class).
____ ____
o----------|_Z1_|----------|_Z2_|-------o
_|__
|_Z3_|
|
o--------------------------------------o"""
Z3 = 1/NW.C
Z1 = (NW.A-1)/NW.C
... | 9a78c5020810d492937c06377d70249efde1bfae | 264,113 |
def get_virtualenv_dir(version):
"""Get virtualenv directory for given version."""
return "version-{}".format(version) | 1b292b48f9c5ce72304019ecb83a1befe25eaf77 | 678,490 |
import json
def parse_json_string(json_string):
"""Parse json string to object, if it fails then return none
:param json_string: json in string format
:type json_string: str
:return: object or none
:rtype: dict/None
"""
json_object = None
if not isinstance(json_string, str):
... | 71552552022cc82c425780fe8713e17d91ebc8b7 | 629,501 |
def next_tick(cell_alive, number_of_neighbors):
"""Returns a cell's state in the next turn
Three conditions for the next state are layed out:
1. A cell is alive and has 2/3 neighbors, it stays alive
2. A cell is dead and has 3 neighbors, it is born
3. Neither of the above, it dies
"""
... | 8a6bd216934d19096b9d238bd5fdef52d8067d5c | 348,436 |
from typing import List
def parse_line(row: str) -> List[str]:
"""
Parse a given row in a list of elements
:param row: A string representation of a row
:return: A list of elements
"""
return [char for char in row] | e10c034a571c250bc570cec93a2f6571335c39e0 | 386,496 |
def check_parse_type(raw):
""" Checks the type for which the given value should be parsed. Currently
only detects strings and arrays."""
if raw.strip()[0] == '[':
return 'array'
else:
return 'string' | 8a4278e25be8cf49dcc66721a57792c29f0e99e4 | 556,945 |
import itertools
def four_body_sum(spins):
"""Calculate four body term in the periodic lattice
Input:
spins: spins configuration matrix.
Output:
sum of four body terms.
"""
size = len(spins)
Sum = 0
for i,j in itertools.product(range(size), repeat=2):
Sum += spins[i,j] * s... | 3e1408e1618db137489d29b0ee93b1ee7d88564f | 689,667 |
def splitFill(text, delim, count, fill=u""):
"""
Split text by delim into up to count pieces. If less
pieces than count+1 are available, additional pieces are added containing
fill.
"""
result = text.split(delim, count)
if len(result) < count + 1:
result += [fill] * (count + 1 - len(... | f314bad515508a3286ead7396135c172c8bf7767 | 237,960 |
def _adjusted_index(k: int, n: int) -> int:
"""Index `k` mod `n` (for wraparound)."""
return k % n | 9db5e5a66e8984fe912f1e916a634247aee7f5e4 | 338,815 |
def unshape_data(data):
"""
Return 1D version of data.
"""
return data.flatten() | a291df4b076cc26ccd12054ea10cb7e5a7ee5f25 | 175,078 |
def add_key(rec, idx):
"""Add a key value to the character records."""
rec["_key"] = rec["id"]
rec["influential"] = "false" if rec["influential"] == "False" else "true"
rec["original"] = "false" if rec["original"] == "False" else "true"
del rec["utc_offset"]
del rec["id"]
return rec | b69361dfab5fce7edf09b00805b4aae577ed08a1 | 156,613 |
def bit_to_str(bit):
"""
Converts a tuple (frame, bit, value) to its string representation.
"""
s = "!" if not bit[2] else ""
return "{}{}_{:02d}".format(s, bit[0], bit[1]) | 49bdab85689b545039eec5275c1bd59b78a3574f | 548,554 |
def getEmailParamFrom(request):
"""
Returns str or None.
Arguments:
request -- bottle.request
"""
result = request.query.email
if not result:
result = None
return result | 5ae07d6e0ae7dfa66b65b510cbe1e40c46f29c1b | 260,403 |
def findRdkitMolRadicalAtomIds(rdkitMol):
"""Returns a list of atom ids with radical sites."""
radicalAtomIds = []
for atom in rdkitMol.GetAtoms():
if atom.GetNumRadicalElectrons() > 0:
radicalAtomIds.append(atom.GetIdx())
return radicalAtomIds | 8a8494c4c1a4a2a8af99e92498e0fb73ce45701c | 661,231 |
import logging
def prepare_data(df):
"""It is used to separate the dependent and iindependent features
Args:
df (pd.DataFrame): It is a dataframe
Returns:
tuple: returning dependent and independent variable tuples
"""
logging.info("preparing the data by segregating the independen... | 58e848cbe8e7933f21daf788e08accc4073e5a80 | 172,370 |
def post_process_botok_segmented_data(segmented_text):
"""Remove unwanted space from segmented text
Args:
segmented_text (str): Botok segmented text
Returns:
str: clean segmented text
"""
clean_segmented_text = segmented_text.replace('\n ', '\n')
clean_segmented_text = clean_se... | d2c1be518ee5445b5b4c3b99a7d457d1319f91da | 409,816 |
def cost(num_of_cities, distance_matrix, tour):
"""
Given `distance_matrix` and `num_of_cities`, calculates cost of a tour
"""
cost = 0
for i in range(num_of_cities):
cost += distance_matrix[tour[i]][tour[(i+1) % num_of_cities]]
return cost | 30374d358e5b052d9cac05d2740ba3502211069b | 312,426 |
def getWords(text: str) -> list:
"""
Return words found in a text as list.
A word considering if contains at least single digit or letter.
"""
if not isinstance(text, str):
raise TypeError('Must be passed string, not {0}'.format(type(text)))
return list(
filter(
lamb... | bb76541819336d8cfe92725f0774d30622d7791e | 460,806 |
def image_mask_overlaps_cropobject(mask, cropobject,
use_cropobject_mask=False):
"""Determines whether the given image mask overlaps the given CropObject.
Can either take into account the cropobject's bounding box only, or can
also take into account the cropobject's mask,... | c4b022bf27a91aa075c93ff663a51ccf513e2e09 | 374,831 |
def format_bytes(size):
"""
Format a number of bytes as a string.
"""
names = ("B", "KB", "MB", "GB", "TB")
mag = 0
while size > 1024:
mag += 1
size = size / 1024.0
return "{} {}".format(round(size, 2), names[mag]) | 437c5f000b60198887d97b9a8672f8cc7c714249 | 380,699 |
import json
def json_load(path):
"""
Load information stored in json file.
"""
with open(path) as data_file: # open & read json
return json.load(data_file) | 7160612c81e071d50ad63c11f5aeb6d83d093782 | 243,743 |
def stop_words(lang='en'):
"""
Get common words that are often removed during preprocessing of text data,
i.e. "stop words". Currently only English stop words are provided.
Parameters
----------
lang : str, optional
The desired language. Default: 'en' (English).
Returns
-------... | af611e17227c8edf441edcb4eca8bd29faf030b2 | 309,604 |
def to_list(x):
"""Normalizes a list/tuple to a list.
If a tensor is passed, we return
a list of size 1 containing the tensor.
Arguments:
x: target object to be normalized.
Returns:
A list.
"""
if isinstance(x, (list, tuple)):
return list(x)
return [x] | 2eb3c8776f44cbdf2cf598e0cf893d846c36497b | 343,995 |
def f1_score (true_positive, positive, gt_positive):
"""Compute the F1-score
Args:
true_positive (Int): Number of true positives
positive (Int): Number of positively classified samples
gt_positive (Int): Number of effectively positive samples
Returns:
float: F1-score
""... | de4358d3c9ca6327033a253c3fd4a9f9d9321a1b | 308,553 |
def decompose_trans(trans):
"""
Decompose SE3 transformations into R and t, support torch.Tensor and np.ndarry.
Input
- trans: [4, 4] or [bs, 4, 4], SE3 transformation matrix
Output
- R: [3, 3] or [bs, 3, 3], rotation matrix
- t: [3, 1] or [bs, 3, 1], translation matrix
"""
... | 511c1b6d838bfcce18e399fee78f1d1aa30030a0 | 580,796 |
def format_file_size(size):
"""
Formats the file size as string.
@param size numeric value
@return string (something + unit)
"""
if size >= 2 ** 30:
size = size / 2 ** 30
return "%1.2f Gb" % size
elif size >= 2 ** 20:
size = size / 2 ** 20... | 31a00ceb1e757a7bcb1ba360c561e723c6875763 | 351,970 |
def limit(num, minimum=1, maximum=255):
"""Limits input 'num' between minimum and maximum values.
Default minimum value is 1 and maximum value is 255."""
return max(min(num, maximum), minimum) | fac54ad0bba741f14f97341a6331c025b5bd49fd | 633,199 |
def fibonacci(n):
"""
This is the original function, it will be used to compare execution times.
"""
if n <= 1:
return n
return fibonacci(n - 1) + fibonacci(n - 2) | 1ca15b9bfd259712b924f7f2f67f34183a701555 | 626,719 |
def missing_key_from_list_in_dict(test_list, test_dict):
"""
Takes a list and a dictionary and checks if all keys in the list are present
in the dictionary. Raises a KeyError with the missing key if found, returns
False otherwise.
"""
for key in test_list:
if key not in test_dict:
raise KeyError(key)
return... | 9dac476e428892ab64027d0963b57ed27e122a4e | 488,616 |
def no_check(param):
"""doesn't perform any check, always returns true"""
return True | 02bcc16249dd34fcfa9113ee90fb4bef3bc16fca | 102,495 |
def cleaning(document: str) -> str:
"""Clean a given document
Args:
document (str): A CPF or CNPJ with special chars
Returns:
str: the document without special chars
"""
return document.replace('-', '').replace('.', '').replace('/', '') | ed7bec7a5d7f1e48688ec8c7145c1a36d4f7acb5 | 531,248 |
import re
def validate_date(date: str) -> dict:
"""
Validate provided date data.
Desired format: YYYY or YYYY-MM (2021 or 2021-12).
"""
# regex patters
rp_year_month = re.compile('^(20[0-9]{2})-((0[1-9])|(1[0-2]))$')
rp_year = re.compile('^(20[0-9]{2})$')
# Match year-month object
... | 86ed53dc1a7a1b7e060fc1acf8762e3f447ff279 | 662,883 |
def get_p2p_scatter_over_mad(model):
"""Get ratio of variability of folded and unfolded models."""
return model['scatter_over_mad'] | c49c1cb91e455c4fe5902a23e3ccb924642fc56a | 383,475 |
def format_size(nb_bytes):
"""
Format a size expressed in bytes as a string
Parameters
----------
nb_bytes : int
the number of bytes
Return
------
formated : str
the given number of bytes fromated
Example
-------
>>> format_size(100)
'100.0 bytes'
>... | 0a3147d75571bc862749c41d0465ffe89b3c4ab4 | 681,504 |
def get_active_planet(ship_position, planets):
"""
ship_position = [q, r]
planets is a list of the planets in the game
returns [planet, #indexOfPlanet] if at a planet
returns [None, -1] otherwise
"""
for planet in planets:
if ship_position == planet.position_of_hexes[planet.current_p... | e8f4641e29226f94a648e964ddf2306d104d5f8a | 242,779 |
def lerp(value1, value2, fac):
"""
linear interpolation
"""
return value1 * (1-fac) + value2 * fac | 37d1ab5031815b60ae3f68e5c75d4557a2b78994 | 162,588 |
import re
def alphanum_key(s):
"""Order files in a 'human' expected fashion."""
key = re.split(r'(\d+)', s)
key[1::2] = list(map(int, key[1::2]))
return key | e1545b791aecf6fd215048620eb6c05a23df30d8 | 101,030 |
def get_video_results(preds, anomaly_frames, normal_frames):
"""Returns confusion matrix values for predictions of one video
Args:
preds (set): set of frame number predictions for a threshold
anomaly_frames (set) set of frames numbers that are anomalies
normal_frames (set) set of normal ... | 1814d1c3e46a6ee84c76d134b32a7c2778c70519 | 265,467 |
from typing import List
import re
def string_to_caps_words(in_string: str) -> List[str]:
"""
Convert string to list of words in caps
:param in_string: input string
:return: word list (all caps)
>>> string_to_caps_words("Svool, R'n z hgirmt!")
['SVOOL', ',', "R'N", 'Z', 'HGIRMT', '!']
"""
... | 79d15d4b89a43aa88007aa54e1465389f4759894 | 184,599 |
def indent_level( block ):
"""Number of characters of indent"""
block = block.replace( '\t',' '*8)
line = block.lstrip( ' ' )
return len(block) - len(line) | 04031f50b592619cfa63062909513420e15b4c4c | 385,567 |
import warnings
def _encode_link_field(value):
"""
Encode the field of a `RiakObject.links` entry as bytes if necessary.
"""
if isinstance(value, bytes):
warnings.warn(
"Passing `RiakObject.links` fields as bytes is deprecated "
"and may be removed in a future release. ... | c1c6cdd2f8f0531dc4de94d59b38ba4d7baa1cc6 | 220,790 |
from typing import List
from typing import Dict
def count(items: List, key_from: str, increment_fun=(lambda x: 1)):
"""
Aggregate objects from a list by the attribute `key_from`.
By default each item increments the counter by 1.
"""
counts: Dict[str, int] = {}
for item in items:
key = ... | 73099b827d0e9281475209ed3104aef622d9b4b2 | 443,497 |
def get_crop_shape(dataset_name):
"""Returns cropping shape corresponding to dataset_name."""
if 'MPISintel' in dataset_name:
return (384, 768)
elif 'KITTI' in dataset_name:
return (320, 896)
else:
raise ValueError('Unknown dataset name {}'.format(dataset_name)) | 18368554e9e4d8c6e3cc964df58b2abfe69d404b | 570,036 |
def binary_step(n: float) -> int:
"""
Binary Step (Unipolar Binary) Activation Function
"""
if n >= 0:
return 1
return 0 | edc86bd63182bf4f152a7746bae8860addc569cf | 610,991 |
def column_names(table_name: str, schema: str) -> str:
"""Return column names of the given table."""
return f"""
SELECT
column_name, data_type
FROM
information_schema.columns
WHERE
table_schema = '{schema}' AND
table_name = '{table_name}'
ORDER BY
ordinal... | 70e66a12e1baac2963f5369c8838cab5e711b467 | 80,495 |
def invalid_usb_device_protocol(request):
"""
Fixture that yields a invalid USB device protocol.
"""
return request.param | d6bbf3f3c321de2800b82bb32a03fe9b1f892de1 | 128,035 |
def read_label_map(description2label_txt):
"""Reads a label map text file into a dictionary (map)
"""
description2label = {}
f = open(description2label_txt, 'rb')
s = f.read().decode('ISO-8859-1')
lines = s.splitlines()
lines = lines[1:] # skip header
for line in lines:
line = ... | f7c32863f8213d476d2155d6b97acaca9f816900 | 277,656 |
def _convert_to_pillow_kwargs(arg):
"""
Converts a string to the correct keyword to use for tiff compression in pillow.
Parameters
----------
arg : str
The string keyword used in the PySimpleGUI window.
Return
------
arg_mapping[arg] : None or str
The keyword in pillow ... | c5b425489665a0b4bc7a211b590dc79a6fc2892d | 157,460 |
import fcntl
import errno
def xioctl(fd, req, arg):
"""
Wrapper around ioctl that polls it until it no longer returns EINTR
"""
while True:
try:
r = fcntl.ioctl(fd, req, arg)
except IOError as e:
if e.errno != errno.EINTR:
raise
print... | 42dd19410d17bc10d3e4a28610294a843140bc87 | 694,430 |
import itertools
def explode(*ds):
"""Returns a generator of the concatenated (key,value) pairs of the provided dictionaries"""
return itertools.chain(*map(lambda d: d.items(), ds)) | 136ab4aff1e1e6e82fc07a5f5941b66f2f67cf09 | 363,114 |
def replace(group):
"""
takes in a pandas group, and replaces the
null value with the mean of the none null
values of the same group
"""
mask = group.isnull()
group[mask] = group[~mask].mean()
return group | 97b0cab2ff247d689a58a6717a07b5716fcc2cd2 | 92,484 |
def in_range(value, ranges):
"""
checks if a float value `value` is in any of the given `ranges`, which are
assumed to be a list of tuples (or a single tuple) of start end end points
(floats).
Returns `True` or `False`.
"""
# is there anythin to check?
if not ranges or not len(ranges):
... | e0c823c0aabbdf5f106f70501bd8d41608447a85 | 348,513 |
def is_tuple(obj) -> bool:
"""Checks if the given object is a tuple."""
return isinstance(obj, tuple) | cf156273c006128d2f0c9fc0f8a3530007f4c5f1 | 310,638 |
def coerce_url(url, default_schema='http'):
"""
>>> coerce_url('https://blog.guyskk.com/feed.xml')
'https://blog.guyskk.com/feed.xml'
>>> coerce_url('blog.guyskk.com/feed.xml')
'http://blog.guyskk.com/feed.xml'
>>> coerce_url('feed://blog.guyskk.com/feed.xml')
'http://blog.guyskk.com/feed.xm... | 9c9b4da76ccdab01f65dd25c967830521813d9b9 | 130,266 |
def bytes_view(request):
"""
A simple test view that returns ASCII bytes.
"""
return b'<Response><Message>Hi!</Message></Response>' | 19bac61604ba81a0f87640670f2993a56aee4d3f | 692,855 |
import copy
def remove_redundant_data(sequence):
"""Returns a copy of the sequence with redundant data removed.
An event is considered redundant if it is a time signature, a key signature,
or a tempo that differs from the previous event of the same type only by time.
For example, a tempo mark of 120 qpm at 5... | 6ebf40f54c57cddbdc9a7d59e15d91fc10c50e38 | 336,449 |
from typing import OrderedDict
def get_query_columns(engine, query):
""" Extract columns names and python typos from query
Args:
engine: SQLAlchemy connection engine
query: SQL query
Returns:
dict with columns names and python types
"""
con = engine.connect()
result =... | 733b4a2786672eac30b09fc755bb39c42a17eb4a | 433,030 |
def clean_link(link):
"""
Many links will direct you to a specific subheading of the page, or
reference some particular component on the page. We don't want to
consider these "different" URLs, so parse this out.
In: string representiaton of a URL link.
Out: "cleaned" version of the link... | 434e014302e878503d870d66ffe7f4a925793934 | 353,342 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.