content stringlengths 39 9.28k | sha1 stringlengths 40 40 | id int64 8 710k |
|---|---|---|
import asyncio
async def subprocess_output(cmd, **kwargs):
"""
Run cmd until completion & return stdout, stderr
Convenience method to start and run a process
"""
proc = await asyncio.create_subprocess_exec(
*cmd,
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PI... | b75097dd39c82d43f8d14c575d678341ec289e51 | 90,968 |
import gzip
import json
def load_reference_file(path):
"""
Load a list of merged otus documents from a file associated with a Virtool reference file.
:param path: the path to the otus.json.gz file
:type path: str
:return: the otus data to import
:rtype: dict
"""
with open(path, "rb"... | dd4fb19e232ad375893668f9b081cedb6b571c0a | 307,739 |
def parseBands(band, allBands, error):
"""Parses a string that specifies bands.
Bands are horizontal rectangles defined with respect to lines.
They correspond with regions of interest where we try to find specific
marks, such as commas and accents.
Parameters
----------
band: string or Non... | f502ddc4107d2440e914166866168c700fd5a6e2 | 646,901 |
def itemize(*items):
"""Restructured text formatted itemized list
>>> print itemize('alpha', 'beta')
* alpha
* beta
"""
return '\n'.join(['* ' + item for item in items]) | 41339defc4e665a54dcf3a072c9ab95ab619ecc4 | 286,406 |
def cube(x):
"""The cube of a number
Calculates and returns the cube of any floating-point number;
note that, as currently written, the function also works for
arrays of floats, ints, arrays of ints, and more generally,
any number or array of numbers.
Parameters
----------
x: float
Number to cube
Returns
---... | 13ffb5afb827cf8e0dc3addce1afe6d74f93e17f | 543,604 |
import collections
def collapseExpansions(expansions, numDims):
"""Scans through the given list of expansions (each assumed to pertain
to a single 3D image), and combines any which cover the same
image area, and cover adjacent volumes.
:args expansions: A list of expansion slices - see :func:`calcExp... | 073923a29d065ee21e26ef234135b4d358ecd288 | 696,730 |
def add_to_set(value, values):
"""
Add non-empty value to set of values
"""
if value:
values.add(value)
return values | 97d999fb829556e0659e416537945fcec62fe059 | 491,696 |
import torch
def sample_model_N_times(dVel0, dVel, v0, dv_l_const, v_max, n_layers, dz, dx, ny, nz, N):
"""Sample N earth models according to the generative model defined in Roeth and Tarantola 1994
Arguments:
dVel0 {torch.distribution} -- Pytorch Distribution for the random velocity contribution... | 9337f6f38194c91f52b88c8da13f87ab9ead9716 | 267,981 |
def my_add(argument1, argument2):
"""
adds two input arguments.
Parameters
----------
argument1 : int, float, str
input argument 1
argument2 : int, float, str
input arguement 2
Returns
-------
results : int, float or str
the two added input argum... | 52c595ac6259f4fa59bb434317c5b89a1bdec428 | 137,503 |
def validate_sequence(sequence, sequence_type):
"""
This method is used to evalute the string passed to the Sequence constructor
I used this https://blast.ncbi.nlm.nih.gov/Blast.cgi?CMD=Web&PAGE_TYPE=BlastDocs&DOC_TYPE=BlastHelp as reference
for which bases and aminoacids representation are va... | 5ac5edecd8209f9d2fa48bc348e45e67c225c615 | 450,197 |
def object_list_check_unique_attribute(object_list,attr_name):
"""
check if all the objects in the list have the same attribute value.
"""
unique = True
attr0 = object_list[0].__getattribute__(attr_name)
for obj in object_list[1:]:
if obj.__getattribute__(attr_name) == attr0:
... | 8f8e8f8d9163b9fc9d2aba08f1a5670b6c55fad2 | 176,716 |
from typing import Counter
def bag_of_ngrams(msg, n):
"""
Extract a bag of word ngrams from a message, with fixed n
:param msg: input string
:param n: size of ngram
:return: bag of features, as a Counter
"""
if n == 0:
raise ValueError('n must be a positive integer')
words = ms... | 8b7867df2de8ce7026adcbbc865665759057e617 | 292,275 |
def norn(x):
""" return the next or None of an iterator """
try:
return next(x)
except StopIteration:
return None | cb6cd9ff9de36e83fdb41458ccf39e3d566b7fc6 | 543,209 |
def get_optimal_value(capacity, items):
"""
get_optimal_value function implements an algorithm for the fractional knapsack problem
:param capacity: Number represents the total capacity of the bag
:param items: list of list that contains values and weights of each item, where items[𝑖] = [value(𝑖), weig... | 6501672bec4c0860a0b47c36bd074dffb3a2826a | 74,263 |
def mulrowcol(row, col, K):
"""
Multiplies two lists representing row and column element-wise.
Gotcha: Here the column is represented as a list contrary to the norm
where it is represented as a list of one element lists. The reason is
that the theoretically correct approach is too expensive. This p... | 448aec2928b314cabe707f19f69bfd687b8fe31c | 635,331 |
def pairwise_analogy_func(wrap, a1, b1, a2, b2, weight_direct, weight_transpose):
"""
Rate the quality of the analogy a1 : b1 :: a2 : b2.
"""
va1 = wrap.get_vector(a1)
vb1 = wrap.get_vector(b1)
va2 = wrap.get_vector(a2)
vb2 = wrap.get_vector(b2)
value = (
weight_direct * (vb2 - ... | 6f96c26fb4c17d0006ab6888225dcc1f4bdc4391 | 67,833 |
def valid_cards_syntax(cards_str):
""" Confirm that only numeric values separated by periods was given as input """
cards = cards_str.split('.')
for c in cards:
if not c.isnumeric():
return 'Cards must contain only digits 0-9 separated by periods'
return None | 8e3811505075269d2b1a37751c14017e107ce69b | 41,597 |
def find_last_break(times, last_time, break_time):
"""Return the last index in times after which there is a gap >= break_time.
If the last entry in times is further than signal_separation from last_time,
that last index in times is returned.
Returns -1 if no break exists anywhere in times.
"""
i... | 01d883bc0c67022a32397f87703acf109f95bd55 | 671,665 |
def create_qualification(conn, name: str, keywords: str, description: str, auto_granted: bool = True,
auto_granted_value: int = 100) -> str:
"""
Creates a new qualification for a task.
@returns the qualification type id.
"""
response = conn.create_qualification_type(
... | 69f07f96ad948c2f8d5b557f49a33f9f4c056889 | 142,498 |
def _boundaries_overflow(index: int, radius: int, length: int) -> bool:
"""Checks boundaries defined by the index of the center and the radius are
inside the sequence of given length.
Returns True if boundaries are already outside the sequence,
False otherwise.
"""
return ((index + radius) >= l... | 45123b2668fb77d48ce638f77e734582bd5ac6d6 | 196,920 |
def zone_target_temperature(zone):
"""
Get target temperature for this zone
"""
return zone["targettemperature"] | 380235b8fdbb9e50239862d3243857edb2d3258a | 292,559 |
def breguet_propellant_winged_powered(R_cruise, v_cruise, lift_drag, I_sp_ab):
"""Recovery propellant factor P for winged vehicle with air-breathing propulsion.
See Breguet range equation http://web.mit.edu/16.unified/www/FALL/thermodynamics/notes/node98.html
Arguments:
R_cruise (scalar): cruise r... | ab5e4cf2159bcd612a6c4cb5a1f062cb4c3910db | 132,609 |
def spaces(num: int):
"""Utility function to easily indent strings."""
return " " * num | 7a346bde1344bdf66ac5084c4f018c33f0707c90 | 547,793 |
def read_predictions_from_file(filename):
"""
Reader for the gold file and the template output file.
Return values are four arrays with article ids, labels
(or ? in the case of a template file), begin of a fragment,
end of a fragment.
"""
articles_id, span_starts, span_ends, gold_labels ... | 1b7663d11fa341d72a3f2f8733f3625b1d096324 | 612,376 |
import itertools
def nflatten(iterable, n=1):
"""
Flattens an iterable n times.
Args:
iterable: The list to flatten.
n: The number of times the list should be flattened.
Returns:
A generator yielding the flattened list.
Note:
Will also flatten strings.
"""
... | 0f0b73ecdf34c997c9b2a237c074e55fe458981c | 397,146 |
from datetime import datetime
def estimate_time_shift_from_server_to_user(hh, mm):
"""
If it's negative means usually server is west of user
:param hh: hours
:param mm: minutes
:return: minutes of shift (rounded to 30)
"""
now = datetime.now()
my_hh, my_mm = now.hour, now.minute
d... | 2c7e9b98ca6053127ec98d676c6841639afde99a | 320,606 |
def discount(rewards, impatience):
"""Sum the rewards, where far off rewards are devalued by impatience.
For example, if rewards were [1, 1, 1, 1] and impatience was 0.5,
returns: sum([1, 0.5, 0.25, 0.125])
Args:
rewards (list): list of rewards to accumulate
impatience (float): factor ... | bffd30a9133b2cb4b6a596fc060e01d7f0333efd | 93,813 |
from typing import List
def mean(nums: List) -> float:
"""
Find mean of a list of numbers.
Wiki: https://en.wikipedia.org/wiki/Mean
>>> mean([3, 6, 9, 12, 15, 18, 21])
12.0
>>> mean([5, 10, 15, 20, 25, 30, 35])
20.0
>>> mean([1, 2, 3, 4, 5, 6, 7, 8])
4.5
>>> mean([])
Trace... | 3c802b4967f646b6338e52b4ce12977274054c15 | 708,627 |
def calc_iou(box_a, box_b):
"""
Calculate the Intersection Over Union of two boxes
Each box specified by upper left corner and lower right corner:
(x1, y1, x2, y2), where 1 denotes upper left corner, 2 denotes lower right corner
Returns IOU value
"""
# Calculate intersection, i.e. area of overlap between the 2 ... | c330af6b6b213c5086fa8df079228ee214407455 | 642,234 |
def jaccard(s1, s2):
"""
Calculate the Jaccard *distance* between two sets (the length of the intersection / the length of the union). If
either or both sets are empty the distance is 1.
Note that this returns a distance -- 0 means things are similar, 1 means things are different
:param s1: Set on... | 989a5a4e26f20e501ec79c1fa6bad93c5941bf1b | 209,469 |
def handle_sketch_name(msg):
"""Process an internal sketch name message."""
if not msg.gateway.is_sensor(msg.node_id):
return None
msg.gateway.sensors[msg.node_id].sketch_name = msg.payload
msg.gateway.alert(msg)
return None | 2faae0aca4255a6439ea40efef5d2ae8a4fd4522 | 417,228 |
from datetime import datetime
def _get_last_commits(repo, n):
"""
Returns list [time, commit_message] of last n commits to repo.
"""
log = []
log_ref = repo.head.reference.log()
for x in range(1, n+1):
if len(log_ref) < x:
break
log_entry = log_ref[-x]
if lo... | 4c0d1a6c509a5a0faf6d660a1e8bd52fc8a77372 | 358,248 |
def pad_packed_images(packed_images, pad_value=0., snap_size_to=None):
"""Assemble a padded tensor for a `PackedSequence` of images with different spatial sizes
This method allows any standard convnet to operate on a `PackedSequence` of images as a batch
Parameters
----------
packed_images : Packe... | dc382533060baf2ff70dcc460e8f2ad5223f0a47 | 236,277 |
def uproot_to_numpy(uproot_hist):
"""
Convert an `uproot` histogram to a `numpy` histogram.
Args:
uproot_hist (hist): An uproot histogram
Returns:
Tuple of NumPy arrays: The converted `numpy` histogram
"""
# return values, edges
return uproot_hist.to_numpy() | cdc87136f4acf5ee399c6ce6091e055ff1a81511 | 302,508 |
import random
def pick_from_distribution(input_map):
"""
Generates an item from a distribution map
:param input_map: The dictionary of items to their probabilities
:return: An item from the dictionary
"""
rand = random.random()
total = 0.0
for item, prob in input_map.iteritems():
... | 2ba62477bdc02c6f541d5f05100dee646d9b2f76 | 632,402 |
def urldecode(url):
"""Decode %7B/%7D to {}."""
return url.replace('%7B', '{').replace('%7D', '}') | 91e2f969e59bc68004e1696434b5b0329012342f | 26,473 |
def choose_first_not_none(*args):
""" Choose first non None alternative in args.
:param args: alternative list
:return: the first non None alternative.
"""
for a in args:
if a is not None:
return a
return None | fe3efba85251161cd0a6ecb50583cc443cd04dc0 | 1,103 |
def makeIntervals(evts):
"""From evts=[a,b,c], create a list of intervals: [(0,a), (b,c)]
From evts=[a,b,c,d], create a list of intervals: [(0,a), (b,c), (d,1)].
Assumes all values in evts are in (0,1)"""
if evts == []: return [(0.0, 1.0)]
evts.sort()
left = 0.0
intervals = []
for e in evts:
if left >= 0.0:
... | 093299058904966682e9df91d96c6cc7adc430f2 | 651,952 |
def generate_grid_coordinates(feature_length):
"""
A list is created with each element corrosponding to a coordinate of a
feature_length x feature_length grid. The list is then broken up into roughly
equal chunks so each chunk can be sent to a different core.
Parameters
----------
feature... | 43fe20bd2f046e660b541a5fd7ff5a67b18595f5 | 599,618 |
def make_nbr_dic(nbr_list):
"""
Make a dictionary that maps each atom to the indices
of its neighbors.
Args:
nbr_list (torch.LongTensor): nbr list for a geometry
Returns:
nbr_dic (dict): dictionary described above
"""
nbr_dic = {}
for nbr in nbr_list:
nbr_0 = nbr... | 44aab0b700ec797bfdfaa8cbd30869794cbd9133 | 249,520 |
def get_last_usable_skill(skill_dict):
"""Returns the last usable skill contained by the input dictionary.
Args:
skill_dict: an ordered dictionary with scox.value.Skill objects as
values.
Returns: the last usable skill in skill_dict.
"""
usable = []
for s in skill_dict.keys():
... | 575973188601810720bda3787f3ed0d2dcd4e923 | 455,921 |
import ast
def filter_block(node_list):
"""
Remove no-op code (``pass``), or any code after
an unconditional jump (``return``, ``break``, ``continue``, ``raise``).
"""
if len(node_list) == 1:
return node_list
new_list = []
for node in node_list:
if type(node) == ast.Pass:
... | b88d3e4966e162d3e23e56e622ff47c63165b7e6 | 45,551 |
def humanbytes(B):
"""Return the given bytes as a human friendly KB, MB, GB, or TB string"""
B = float(B)
KB = float(1024)
MB = float(KB ** 2) # 1,048,576
GB = float(KB ** 3) # 1,073,741,824
TB = float(KB ** 4) # 1,099,511,627,776
if B < KB:
return '{0} {1}'.format(B,'Bytes' if 0 == B > 1 el... | ac23fcb827f38e4f2e23ca5572e73a46f6d2f632 | 441,684 |
def obj_to_dict(obj):
"""
Converts an :py:obj:`object` to a :py:obj:`dict` by taking the object's
properties and variables and their values and putting them into a dict.
Private and dunder (``__``) properties are ignored.
The use case for this is to enable passing of an object's data across
the... | 0c7a8d758357dcd7f33b0351004fe29354d0134e | 22,881 |
def default_range(start, stop):
"""[start, start + 1, ..., stop -1]"""
return range(start, stop) | 98a882164b916090f60fd8168b85b4aca3b031e8 | 250,782 |
def null(shape):
"""Return the shape as-is."""
return shape | 956c209a33312c235748a2b4a433955404e5f641 | 288,303 |
def bxor(inp, key):
"""
Preforms the bitwise xor on an array of bytes.
"""
return bytes([inp[i] ^ key[i % len(key)] for i in range(len(inp))]) | e12078b24d52aa785afbd118ed48157bedc7926b | 529,238 |
from typing import Any
def binary_search(L: list, v: Any) -> int:
"""Return the index of the first occurrence of value in L, or return
-1 if value is not in L.
>>> binary_search([1, 3, 4, 4, 5, 7, 9, 10], 1)
0
>>> binary_search([1, 3, 4, 4, 5, 7, 9, 10], 4)
2
>>> binary_search([1, 3, 4, 4,... | f844dc94aa3beab375beb051bb8a7a90baeb85fe | 92,613 |
import logging
import requests
def request_playlist_html(playlist_url, headers):
"""Send a request to a YouTube playlist webpage.
Parameters
----------
playlist_url : str
URL to the playlist webpage.
headers : Dict[str, str]
HTTP request headers.
Returns
-------
str
... | c6471d8330ea1988a0ad04d2f91d9a4ae8aefd07 | 372,871 |
def check_std(df, num_cols, threshold = 0.01):
""" Return column names, whose standard deviation is less than the threshold"""
stds = dict(df.std())
cols = [k for k, v in stds.items() if v < threshold]
return cols | fc5a554da7ea37ff5248ceeba2637e3c13ee7e94 | 488,965 |
def inherits_from(obj, parent):
"""
Takes an object and tries to determine if it inherits at *any*
distance from parent.
Args:
obj (any): Object to analyze. This may be either an instance
or a class.
parent (any): Can be either instance, class or python path to class.
R... | 9d7e0665b4e4fe2a3f7c136436a2502c8b72527c | 706,396 |
def last_posted_user_name(ticket):
"""
Get the username of the last post created
:param ticket: The requested ticket to get last post for
:return: username of last post
"""
last_post = ticket.posts.all().order_by('created_at').last()
return last_post.user.username | 904f35f8923422f35c970a5efc452394a7deb12b | 671,879 |
import functools
def fluent(func):
"""Decorator for class methods which forces return of self.
"""
@functools.wraps(func)
def wrapper(self, *args, **kwargs):
func(self, *args, **kwargs)
return self
return wrapper | 15d702971d877f4a04609adf94019c9696827bb3 | 265,238 |
def _surf70(phi1, phi2, phi3, phi4):
"""Compute area of a south fire trapeze
Parameters
----------
phi1 : float
Level-set at south west point
phi2 : float
Level-set at south east point
phi3 : float
Level-set at north east point
phi4 : float
Level-set at north... | c4f166bccd0a290b37469f3f616bd568f90f1259 | 667,575 |
def make_text_from_orth(example_dict: dict) -> str:
"""
Reconstructs the text based on ORTH and SPACY from an Example turned to dict
"""
text = ""
for orth, spacy in zip(
example_dict["token_annotation"]["ORTH"],
example_dict["token_annotation"]["SPACY"],
):
text += orth
... | 73cd17f1cf9a0fcd9d7f29d731f8b737822afd82 | 529,871 |
def class_text_to_int(cls_name, label_map):
"""
Get index of class name
:param cls_name: name of class
:param label_map: label map
:return: index of class if found
"""
if cls_name in label_map:
return label_map[cls_name]
raise ValueError('Invalid class') | ee5b15982369609173098d8ceaedc2bebe1425ec | 461,439 |
def get_filename_in_second_line(cpp_txt):
"""
From the second line of cpp_txt, get the filename
Expected input argument:
// ```
// Begin file_name.cpp
// ...
Expected output argument in this case:
file_name.cpp
"""
result = ""
for line in cpp_txt.splitlines():
if ... | b0e3e3efe7af0af667b20c74c1334c3d61f74ebf | 578,152 |
from pathlib import Path
def read_image_scipy2(input_filename: Path) -> np.array: # type: ignore
"""
Read an image file with scipy and return a numpy array.
:param input_filename: Source image file path.
:return: numpy array of shape (H, W), (H, W, 3).
"""
numpy_array = imageio.imread(input_... | 54d3aa7d8a3043e5a79e2668be1e971b543669d9 | 10,780 |
def _iget(key, lookup_dict):
"""
Case-insensitive search for `key` within keys of `lookup_dict`.
"""
for k, v in lookup_dict.items():
if k.lower() == key.lower():
return v
return None | f53e1723a015e5ac0a1244ee0821d56f4a26c5d8 | 576,508 |
from typing import Tuple
from typing import Sequence
import math
def _conv2d_output_size(
input_dimensions: Tuple[int, int],
output_channels: Sequence[int],
kernel_sizes: Sequence[int],
stride_sizes: Sequence[int],
) -> int:
"""Calculates the output size of convolutional layers based on square ker... | f22b6f8c4e8f8467960915f7a91a47f779ac67b9 | 453,365 |
def bmul(vec, mat, axis=0):
"""Expand vector for batchwise matrix multiplication.
Parameters
----------
vec : 2dtensor
vector for multiplication
mat : 3dtensor
matrix for multiplication
axis : int, optional
batch axis, by default 0
Returns
-------
3dtensor
... | 78fc47c98bd10792efeeea8df073e52921e4c9ac | 95,527 |
import struct
def enc_float(val):
"""Encode a single float"""
return struct.pack("!f", val) | f4d6d3fff683c3b64dcebc97c48b4ab8e3815f91 | 50,417 |
from typing import Union
from typing import Callable
from typing import Any
from typing import Optional
from typing import Tuple
from typing import Dict
def format_callback_to_string(
callback: Union[str, Callable[..., Any]],
args: Optional[Tuple[Any, ...]] = None,
kwargs: Optional[Dict[str, Any]] = None,... | 2e07074dac0d7035f63bd192369cf2aa0ce8b410 | 437,883 |
import re
def get_major_version(from_go_version: str) -> str:
"""
Extracts the "major" version part of a full Go release version. ("major" to
the Go project is the part of the version that most people think of as the
major and minor versions - refer to examples).
>>> get_major_version("1.23.45-6rc7")
'1.23'
>... | 6f879cc4141f6de0a8902ae88996d65296aa6634 | 452,605 |
def doize(*, tock=0.0, **opts):
"""
Returns decorator that makes decorated generator function Doist compatible.
Imbues decorated generator function with attributes used by Doist.enter() or
DoDoer.enter().
Only one instance of decorated function with shared attributes is allowed.
Usage:
@doi... | bbdbfb47a56826b815585cdd1d3b515dc3ad8f03 | 451,097 |
import re
def subs_text(text, lst):
"""Same as replaceChars but uses a list instead of a dictionary.
Args:
text: The text that will be substitute
lst: A list that contains regexes for denoising text
Returns:
text: New text without garbages
"""
for n in range(... | 2ccb16198fdfad5a7bb6d89c28e2511b7218de83 | 290,510 |
def compute_amnesty_flags(app_config, curr_date):
"""Helper function to determine whether the date falls within amnesty eval or amnesty period."""
in_amnesty_eval_period = True if app_config.amnesty_config.amnesty_enabled and \
curr_date <= app_config.amnesty_config.evaluation_period_end_date else False... | da35675436c4aa0fd648354cb848b526282d112b | 398,350 |
def _shape(ys):
""" Get the shape of a non-numpy python array. This assumes the first index of every dimension is
indicative of the shape of the whole matrix.
Examples:
>>> _shape([1, 2, 3])
[3]
>>> _shape([[1, 2, 3], [4, 5]])
[2, 3]
"""
if hasattr(ys, '__len__'):
... | 66264e78f61198bc2eff27aa54d2f1caed8e0b58 | 281,482 |
def notIn(i, subset):
"""Returns True if i-th bit in the subset is not set."""
return (1 << i) & subset == 0 | 04f3fce32260123d8da947fca5159cc83852ed07 | 168,679 |
def mappings_intersect(a, b):
"""
True if `a` and `b` share a mapping.
Mapping is a list of ((key, value), (mapping1, mapping2,...)).
>>> mappings_intersect([(('waterway', 'riverbank'), ('mapping_waterareas',))],
... [(('waterway', 'riverbank'), ('mapping_waterareas',))])
True
>>> mappings_... | a8a5ebda37325d8dc8a074f26be922ed41f28505 | 399,462 |
def chunks(l, n):
"""
returns list of list of length n.
E.g. chunks([1, 2, 3, 4, 5], 2) returns [[1, 2], [3, 4], [5]]
"""
return [l[i:i+n] for i in range(0, len(l), n)] | 24e71aca504e1fe5c25c95026e4ac8ca8cb047df | 150,871 |
def find_index_from_freq(freq, frequency_step):
"""
Gives the index corresponding to a specific frequency (eg to find a frequency
from a fourier transform list). Requires the frequency step of the list
Arguments:
freq - frequency being looked for
frequency_step - the step between consecutive indexes
"""
ind... | b909914f649b9bdc9b70571e1c148e8216213bbd | 444,223 |
def merge_group_answers_with_count(file_content):
"""
Merges the group answers together and count the number of people in each group
:param [str] file_content: Content from the input file
:return: For each group, a long string of all the answers and the number of people
:rtype: [(str, int)]
"""
... | 691a58dffe5e7f6f5f8ba79ce521c0ce23f29e86 | 489,082 |
def validate_encryptionoption(encryption_option):
"""
Validate EncryptionOption for EncryptionConfiguration
Property: EncryptionConfiguration.EncryptionOption
"""
VALID_ENCRYPTIONCONFIGURATION_ENCRYPTIONOPTION = [
"CSE_KMS",
"SSE_KMS",
"SSE_S3",
]
if encryption_opti... | 2e6c7df84fa8434c6692fc58c95bbb9ecd46d05d | 496,928 |
import re
from typing import Literal
def extract_text(
pattern: re.Pattern[str] | str,
source_text: str,
) -> str | Literal[False]:
"""Match the given pattern and extract the matched text as a string."""
match = re.search(pattern, source_text)
if not match:
return False
match_text = ma... | a6f762cfd26dd1231db4b6e88247e2566d186212 | 208 |
def rot_word(word):
"""Takes a 4-byte word and performs cyclic permutation.
Aka one-byte left circular shift.
[b0, b1, b2, b3] -> [b1, b2, b3, b0]
"""
return word[[1, 2, 3, 0]] | f89b3499009d29c7e3e9745e30f643b941c77f00 | 96,265 |
def positive_sum3(a: int, b: int, c: int=0):
"""Normal exposed function
Parameters
----------
a: int
b: int
c: int, default 0
All parameters are positive values.
If negative, an exception is raised.
Returns
----------
int
"""
if a<0 or b<0 or c<0:
ra... | 008baaa83ef666181e83f56f167a3b4fa6ddd4e7 | 418,205 |
from pathlib import Path
def requirements_path() -> Path:
""" Return the absolute Path to 'tests/requirements' """
return Path(__file__).parent / Path('requirements') | d20bf1c50fe0881238435641f782a3975a82c1f7 | 366,614 |
from functools import reduce
from operator import mul
import torch
def flat_softmax(inp):
"""Compute the softmax with all but the first two tensor dimensions combined."""
orig_size = inp.size()
flat = inp.view(-1, reduce(mul, orig_size[2:]))
flat = torch.nn.functional.softmax(flat, -1)
return fla... | e3cbe2603daba7f044b49e28fb3505fb17f95fa6 | 474,805 |
import requests
import json
def get_metadata(metadata_url: str) -> dict:
"""Gets metadata from a jsonld published by AAFC
Args:
metadata_url (str): url to get metadata from.
Returns:
dict: AAFC Land Use Metadata.
"""
if metadata_url.endswith(".jsonld"):
if metadata_url.star... | 486cca39ea054ab36b9011591cd069a0835c608e | 250,142 |
def qbytearray_to_str(qba):
"""Convert QByteArray object to str in a way compatible with Python 2/3"""
return str(bytes(qba.toHex().data()).decode()) | 7b1a016d3b7469cfad287a646c3f2e0aa61c2552 | 88,235 |
def _floatFormat(value):
"""Format the floating number to make sure it gets the decimal point."""
valueStr = "%.16G" % value
if "." not in valueStr and "E" not in valueStr:
valueStr += ".0"
return valueStr | 5c322d41909e76860d5aa1ddfe8fcebcec0da711 | 443,942 |
def fix_thread_string(tstr):
"""
Takes a string with numbers separated by period and possibly with /
at end, and outputs a string with 3 digit numbers separated by periods.
"""
remove_slash = lambda s: s[:-1] if s[-1] == '/' else s
three_digits = lambda s: "%03d" % int(s)
return '.'.join( ma... | fb0c4dd83a1446114835eb8758501b07e7392d4d | 214,569 |
def lemmatizer_fun(lemmatizer, token, token_tag=None):
"""lemmatize token with tag of token in sentence
if token has not tag lemmatized With no tag method
Arguments:
lemmatizer {obj} -- instance of WordNetLemmatizer
token {str} -- token
Keyword Arguments:
token_tag {str} -- tag... | a64597b3a5e3e76b31bb3c3e8f5cf6d34f892e12 | 587,642 |
def convert_boolean(value: bool) -> str:
"""Convert from python bool to postgresql BOOLEAN"""
if value is True:
return 'TRUE'
elif value is False:
return 'FALSE'
else:
return 'NULL' | 102c9b4ce2db0d74f3d0838f09810b14737772fe | 528,648 |
from typing import AbstractSet
def add_to_set(set_: AbstractSet[str] | None, new: str) -> set[str]:
"""Add an entry to a set (or create it if doesn't exist).
Args:
set_: The (optional) set to add an element to.
new: The string to add to the set.
"""
return set(set_).union([new]) if se... | ec1f6e3ca51bc11ff0996a1aab00e84e2c23228e | 690,677 |
def get_last_logline(logfile: str) -> str:
"""Get last line of logfile
Args:
logfile: path to logfile
Returns:
last line of logfile
"""
line = ""
with open(logfile) as file_handle:
for line in file_handle:
pass
return line | 92a97d380b3f6bad1a337da79350f57fc46ab556 | 350,449 |
def which(repository_ctx, cmd, default = None):
"""
A wrapper around repository_ctx.which() to provide a fallback value. Doesn't %-escape the value!
Args:
repository_ctx: The repository context.
cmd: name of the executable to resolve.
default: Value to be returned when such executable cou... | 369b00e3131831664cdd1c07e0bbbf66d28795a8 | 269,824 |
import pickle
import glob
def cluster_files_reader(files_pattern,
trainer_count,
trainer_id,
loader=pickle.load):
"""
Create a reader that yield element from the given files, select
a file set according trainer count and trainer_id... | abeeb739df94b21d0b94de485ba6cf01c6dae8e9 | 190,694 |
def get_backbone_atoms(structure):
"""
Return the backbone atoms of the specified structure.
Parameters
----------
structure : Bio.PDB.Structure
The structure.
Returns
-------
list of Bio.PDB.Atom
The backbone atoms.
"""
atoms = []
for model in structure:
... | 791c120b88329c81afb1578964e1e3b501abc47c | 485,641 |
import re
def count_aspects(mask: list):
"""Counts the number of keywords (runs) in a given aspect mask
Example:
- input: [1,1,0,0,1,0]
- output: 2
Arguments:
- mask: list of booleans (returned by function create_aspectmask)
Return:
Positive integer
"""
mask_str = "".join([str(... | ad1ebfc54bcc2dc6440e431bc2454dc64e2d69c4 | 333,680 |
from pathlib import Path
from typing import List
import re
def get_amici_base_sources(
base_dir: Path,
with_hdf5: bool = True
) -> List[str]:
"""Get list of source files for the amici base library
Expects that we are inside $AMICI_ROOT/python/sdist
Arguments:
base_dir: AMICI base... | 62f0f10dbffff57864a75725f79749636f70a68a | 320,420 |
def _reset_time_for_date(date):
"""
Set time on a datetime to 00:00:00
"""
return date.replace(hour=0, minute=0, second=0, microsecond=0) | 2333115d6aa427d3e0cf4a77668981234abbbd27 | 423,273 |
def reorder_columns(df, order):
"""Reorders dataframe columns, sorting any extra columns alphabetically."""
extra_cols = set(df.columns) - set(order)
return df[list(order) + sorted(extra_cols)] | 41e117de52a909925197738df066da2e278bb915 | 403,314 |
def parse_qualifiers(gb_feature):
"""Parse the GBFeature_quals block of the GBFeature entry and create a
dictionary of qualifiers using the GBQualifier_name as a key.
Args:
gb_feature: Reference to GBFeature block from Entrez XML
Kargs:
None
Raises:
None
"""
qualif... | c76332a86a71b30d354800478eb7f2b4702a7efd | 451,569 |
import threading
def makeThreadSafe(function, lock=None):
""" Call with a function you want to make thread safe
Call without lock to make the function thread safe using one lock per
function. Call with existing lock object if you want to make several
functions use same lock, e.g. all functions that c... | dde480d751b867e442fcef4263d6d5e5b9da1f37 | 72,102 |
def read_lines_from_text_file(file_path):
"""Read lines from a text file."""
with open(file_path) as f:
lines = [line.strip() for line in f.readlines()]
return lines | 95a1592a20d4e83a62def2f8aa8f20633e1024a6 | 23,223 |
def preprocess_user_data(user_id, ratings_df):
"""
Build a Surprise test set with book ids of the books
that have not been rated by a given user.
"""
rated_books = set(ratings_df.loc[ratings_df['user_id'] == user_id, 'book_id'])
all_books = set(ratings_df['book_id'])
books_unknown_rating =... | 868f4ebf43a3e1bade5d996c9409e9b77b834ada | 242,933 |
def categorical_error(pred, label):
"""
Compute categorical error given score vectors and labels as
numpy.ndarray.
"""
pred_label = pred.argmax(1)
return (pred_label != label.flat).mean() | 577df5b9dd7835334084eb65d9789118e6951e7d | 497,941 |
def title_to_snake_case(text):
"""Converts "Column Title" to column_title
"""
return text.lower().replace(' ', '_').replace('-', '_') | 72893c308cd772cc972f76199ee0e32ce5f7c92b | 100,759 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.