content stringlengths 39 14.9k | sha1 stringlengths 40 40 | id int64 0 710k |
|---|---|---|
def enrich(alert, rules):
"""Determine if an alert meets an enrichment rule
:param alert: The alert to test
:param rules: An array of enrichment rules to test against
:returns: Alert - The enriched Alert object
"""
for enrichment in rules:
updates = enrichment(alert)
if not upda... | 97bf2d387e4c6e1ab38628860415bdf83c4634b9 | 704,175 |
def re(rm,rf,beta):
"""Returns cost of equity using CAPM formula."""
return rf + beta*(rm-rf) | 5f91fd21ba1833dcb816ac767c8e1a15e2a30a5a | 704,176 |
import socket
def check_tcp_port(host, port, timeout=3):
"""
Try connecting to a given TCP port.
:param host: Host to connect to
:param port: TCP port to connect to
:param timeout: Connection timeout, in seconds
:return: True if the port is open, False otherwise.
"""
s = socket.socke... | 5e49ebab2c219e9772174d830dffcb958033befd | 704,177 |
def get_sid_trid_combination_score(site_id, tr_ids_list, idfilt2best_trids_dic):
"""
Get site ID - transcript ID combination score, based on selected
transcripts for each of the 10 different filter settings.
10 transcript quality filter settings:
EIR
EXB
TSC
ISRN
ISR
ISRFC
S... | 9cc2d9a0f2fab4e4bf3030ef360b582caeaab45f | 704,179 |
def ergsperSecondtoLsun(ergss):
"""
Converts ergs per second to solar luminosity in L_sun.
:param ergss: ergs per second
:type ergss: float or ndarray
:return: luminosity in L_sun
:rtype: float or ndarray
"""
return ergss / 3.839e33 | 806b590c713bc9177db66993aff2f6feaa32d736 | 704,181 |
from typing import Any
def produces_record(obj: Any) -> bool:
"""Check if `obj` is annotated to generate records."""
if hasattr(obj, 'get_data_specs'):
return True
else:
return False | b65ffe3d599963f8f5ee4d1581179ab7567aa074 | 704,182 |
import json
def readJson(fname):
""" Read json file and load it line-by-line into data
"""
data = []
line_num = 0
with open(fname, encoding="utf-8") as f:
for line in f:
line_num += 1
try:
data.append(json.loads(line))
except:
... | 0a4a78ce7e36fbc444b27ca6eec3ad5ba582b7cd | 704,183 |
def binary_search(arr, val):
"""
Summary of binary_search function: searches an input array for a value and
returns the index to matching element in array or -1 if not found.
Parameters:
array (array): An array of values
val (integer): An integer value
Returns:
index (integer): Re... | 3d5a44b5edce3820d1e669e549f9395d9052d433 | 704,184 |
import torch
def compute_jacobian(x, y, structured_tensor=False,
retain_graph=False):
"""Compute the Jacobian matrix of output with respect to input.
If input and/or output have more than one dimension, the Jacobian of the
flattened output with respect to the flattened input is retur... | bd5fd8e3e2b8171680bf059d10fadfe1c39d8899 | 704,186 |
def make_rows(cngrs_prsn):
"""Output a list of dicitonaries for each JSON object representing a
congressperson.
Each individaul dictionary will contain information about the congressperson
as well as info about their term.
"""
name = cngrs_prsn["name"]["first"] + " " + cngrs_prsn["name"]["last"]
birthd... | a80c55c3db1261a339ec08814c0f532efd35e45a | 704,191 |
def get_list_of_results(results):
"""Modify the outputs so that they are returned in a list format where it is
sometimes easier to be used by other functions.
Parameters
----------
results : list
A list of named tuples for each iteration
Returns
-------
list, list, list
... | b5903e3b99aeb37ce90190e86a7cd6e2408ad35b | 704,193 |
def return_last(responses):
"""Return last item of a list."""
return responses[-1] | f4aedfe0b10adcdb859ac1d0f5809ca666abac80 | 704,199 |
def get_boundary_cell_count(plate_dims, exclude_outer=1):
"""Get number of wells in outer or inner edges
Parameters
----------
plate_dims : array
dimensions of plate
Returns
-------
boundary_cell_count : int
number of wells in the edges
"""
boundary_cell_count =... | 8e5056af647f893854bab3de3e6e5038c0d703e1 | 704,201 |
def compute_border_indices(log2_T, J, i0, i1):
"""
Computes border indices at all scales which correspond to the original
signal boundaries after padding.
At the finest resolution,
original_signal = padded_signal[..., i0:i1].
This function finds the integers i0, i1 for all temporal subsamplings... | 09d29c4de2c808a1947d513580817bda16a6bfe7 | 704,202 |
def isbuffer(obj) -> bool:
"""
Test whether `obj` is an object that supports the buffer API, like a bytes
or bytearray object.
"""
try:
with memoryview(obj):
return True
except TypeError:
return False | bede4ffeb154e765c7c2f4dea3bfa77281b313f2 | 704,203 |
def aggregate(loss, weights=None, mode='mean'):
"""Aggregates an element- or item-wise loss to a scalar loss.
Parameters
----------
loss : Theano tensor
The loss expression to aggregate.
weights : Theano tensor, optional
The weights for each element or item, must be broadcastable to... | 6d888d1854cfa78e13fcd5eba412e224164386d7 | 704,209 |
def is_workinprogress(change):
"""Return True if the patchset is WIP
:param dict change: De-serialized dict of a gerrit change
:return: True if one of the votes on the review sets it to WIP.
"""
# This indicates WIP for older Gerrit versions
if change['status'] != 'NEW':
return True
... | ac2f5ba1ab8d5fd432ef7b13c5b033e0c3710fd4 | 704,214 |
import pickle
def pickle_load(namefile: str):
"""Load Python variable, given name of file.
:param namefile: A string of file to load.
:return output: A loaded variable.
"""
with open(namefile, 'rb') as load_file:
output = pickle.load(load_file)
return output | 425e53b8daf69bf832abc45a4270cc01f383c50e | 704,216 |
def negate(condition):
"""
Returns a CPP conditional that is the opposite of the conditional passed in.
"""
if condition.startswith('!'):
return condition[1:]
return "!" + condition | 5f31ed3ee2f16a53674f830402fdec890af25032 | 704,218 |
def points(start, end):
"""
Bresenham's Line Drawing Algorithm in 2D
"""
l = []
x0, y0 = start
x1, y1 = end
dx = abs(x1 - x0)
dy = abs(y1 - y0)
if x0 < x1:
sx = 1
else:
sx = -1
if y0 < y1:
sy = 1
else:
sy = -1
err = dx - dy
whil... | ffa8be5eb09e2b454242e4095883bfee239e5319 | 704,222 |
def ab_from_mv(m, v):
"""
estimate beta parameters (a,b) from given mean and variance;
return (a,b).
Note, for uniform distribution on [0,1], (m,v)=(0.5,1/12)
"""
phi = m*(1-m)/v - 1 # z = 2 for uniform distribution
return (phi*m, phi*(1-m)) | 0326c165e44c1ab9df091e0344f12b9fab8c0e19 | 704,223 |
import csv
def csvReadCallback(inputFile, **kw):
"""Read callback for CSV data"""
inputFile.readline() # skip header
reader = csv.reader(inputFile, lineterminator='\n', **kw)
return [row for row in reader] | e36c92e5792e905da22438a58c8ce810c2a22e2a | 704,230 |
def _LJ_rminepsilon_to_ab(coeffs):
"""
Convert rmin/epsilon representation to AB representation of the LJ
potential
"""
A = coeffs['epsilon'] * coeffs['Rmin']**12.0
B = 2 * coeffs['epsilon'] * coeffs['Rmin']**6.0
return {"A": A, "B": B} | 0963c0e8b949d35842660a499ce80a388485773f | 704,233 |
def CycleTarget_to_c(self):
"""Syntax for a target of a cycle."""
return f"cycle_{self.targetID}: continue;" | 12cc7a57e5a24a62aba43ac99879d5a5d364ee29 | 704,240 |
def get_pipeline_lines(input_pipeline):
"""Returns a list with the lines in the .cppipe file"""
with open(input_pipeline) as f:
lines = f.readlines()
return lines | 403e7531b1cadfe25f519d2b176b97ac344cde6b | 704,243 |
def get_interface_type(interface):
"""Gets the type of interface
"""
if interface.upper().startswith("ET"):
return "ethernet"
elif interface.upper().startswith("VL"):
return "svi"
elif interface.upper().startswith("LO"):
return "loopback"
elif interface.upper().startswith... | f770a3ef1c43574d22630a5c4fff2f25d4975279 | 704,246 |
def rgb2gray(image):
"""Convert 3-channel RGB image into grayscale"""
if image.ndim == 3:
return (0.299 * image[:, :, 0] + 0.587 * image[:, :, 1] +
0.114 * image[:, :, 2])
elif image.ndim == 4:
return (0.299 * image[:, :, :, 0] + 0.587 * image[:, :, :, 1] +
0.... | f87ed301dfd9c13ebfbabf99ad4b56c959a91e46 | 704,247 |
def move_ship_waypoint(instructions: list) -> list:
"""Move the ship using the waypoint movement rules
:param instructions: List of movement instructions
:return: Final position of the ship
"""
waypoint = [10, 1]
ship = [0, 0]
for instruction in instructions:
cmd, val = instruction
... | 7202392e4826d522287455d94f7b06c0e2f931ee | 704,251 |
import itertools
def get_hyperparams_combinations(hyperparams):
"""Get list of hyperparmeter (dict) combinations."""
# transforms tuning hyperparams to a list of dict params for each option
return [
{k:v for k,v in zip(hyperparams.keys(), hypms)}
for hypms
in itertools.product(*[... | e5f52a8eddb8a2a476e0daa47f63161d440263f2 | 704,252 |
def p_to_stars(p, thres=(0.1, 0.05, 0.01)):
"""Return stars for significance values."""
stars = []
for t in thres:
if p < t:
stars.append("*")
return "".join(stars) | d88c2fd6c1b4e2d75a9cb664dfc10fab308bc6ee | 704,255 |
def factorial_r(number):
"""
Calculates the factorial of a number, using a recursive process.
:param number: The number.
:return: n!
"""
# Check to make sure the argument is valid.
if number < 0:
raise ValueError
# This is the recursive part of the function.
if number == 0... | e5c28edac93b965f438bd61c5bb1c0a935c96700 | 704,257 |
from typing import Any
def create_result_scalar(name: str, item_type: str, value: Any) -> dict:
"""
Create a scalar result for posting to EMPAIA App API.
:param name: Name of the result
:param item_type: Type of result
:param value: Value of the result
"""
result = {"name": name, "type": ... | 3fb16c540cc8c76cfc42e4a906e4be280346b802 | 704,264 |
import sympy
def replace_heaviside(formula):
"""Set Heaviside(0) = 0
Differentiating sympy Min and Max is giving Heaviside:
Heaviside(x) = 0 if x < 0 and 1 if x > 0, but
Heaviside(0) needs to be defined by user.
We set Heaviside(0) to 0 because in general there is no sensitivity. This
done ... | d1aff5e4a2dd68ba53ced487b665e485dab4b54d | 704,265 |
def untempering(p):
"""
see https://occasionallycogent.com/inverting_the_mersenne_temper/index.html
>>> mt = MersenneTwister(0)
>>> mt.tempering(42)
168040107
>>> untempering(168040107)
42
"""
e = p ^ (p >> 18)
e ^= (e << 15) & 0xEFC6_0000
e ^= (e << 7) & 0x0000_1680
e ^... | 4118b55fd24008f9e96a74db937f6b41375484c3 | 704,271 |
def multiplicar(a, b):
"""
MULTIPLICAR realiza la multiplicacion de dos numeros
Parameters
----------
a : float
Valor numerico `a`.
b : float
Segundo valor numerico `b`.
Returns
-------
float
Retorna la suma de `a` + `b`
"""
return a*b | 2d1a56924e02f05dcf20d3e070b17e4e602aecf6 | 704,272 |
def can_comment(request, entry):
"""Check if current user is allowed to comment on that entry."""
return entry.allow_comments and \
(entry.allow_anonymous_comments or
request.user.is_authenticated()) | 04bcd019af083cff0367e236e720f4f7b00f7a65 | 704,274 |
def data_scaling(Y):
"""Scaling of the data to have pourcent of baseline change columnwise
Parameters
----------
Y: array of shape(n_time_points, n_voxels)
the input data
Returns
-------
Y: array of shape(n_time_points, n_voxels),
the data after mean-scaling, de-meaning a... | 94b550386b8411a96b9ccd3f5e93098560c327e1 | 704,278 |
import json
def load_json(path: str):
"""Load json file from given path and return data"""
with open(path) as f:
data = json.load(f)
return data | d165d087c78a0ba88d318a6dbe8b2ac8f9a8c4b5 | 704,279 |
def _get_int_val(val, parser):
"""Get a possibly `None` single element list as an `int` by using
the given parser on the element of the list.
"""
if val is None:
return 0
return parser.parse(val[0]) | d2e029657b3424027e83ee8e1e2be76e3abf8fda | 704,280 |
def get_n_p(A_A, n_p_in='指定しない'):
"""付録 C 仮想居住人数
Args:
A_A(float): 床面積
n_p_in(str): 居住人数の入力(「1人」「2人」「3人」「4人以上」「指定しない」)
Returns:
float: 仮想居住人数
"""
if n_p_in is not None and n_p_in != '指定しない':
return {
'1人': 1.0,
'2人': 2.0,
'3人': 3.0,
'4人以上':... | db257abdb76ee35f16b07e5baccec82211737971 | 704,282 |
def make_mmvt_boundary_definitions(cv, milestone):
"""
Take a Collective_variable object and a particular milestone and
return an OpenMM Force() object that the plugin can use to monitor
crossings.
Parameters
----------
cv : Collective_variable()
A Collective_variable object whi... | 45baaaa70ea24cb564c529cd885597415561a25d | 704,283 |
def parseConfigFile(configFilePath):
"""
:param configFilePath:
:return: a hash map of the parameters defined in the given file.
Each entry is organized as <parameter name, parameter value>
"""
# parse valid lines
lines = []
with open(configFilePath) as f:
for line in f:
... | aee6a1da052f4c2ef907bf41b2cfaa4b93612a5e | 704,286 |
def has_annotations(doc):
""" Check if document has any mutation mention saved. """
for part in doc.values():
if len(part['annotations']) > 0:
return True
return False | 6b57893bc35af45950ec2eeb5008b663028d48bf | 704,287 |
import hashlib
def calc_checksum(filename):
"""
Calculates a checksum of the contents of the given file.
:param filename:
:return:
"""
try:
f = open(filename, "rb")
contents = f.read()
m = hashlib.md5()
m.update(contents)
checksum = m.hexdigest()
... | 080e3686279ae126951cd1b66efdb9a0d2448011 | 704,295 |
import time
def get_elapsed_time(start_time) -> str:
""" Gets nicely formatted timespan from start_time to now """
end = time.time()
hours, rem = divmod(end-start_time, 3600)
minutes, seconds = divmod(rem, 60)
return "{:0>2}:{:0>2}:{:05.2f}".format(int(hours), int(minutes), seconds) | d75a1873254e1b1cc9ffc714e65d3a9ed95e5803 | 704,297 |
def clean_string_columns(df):
"""Clean string columns in a dataframe."""
try:
df.email = df.email.str.lower()
df.website = df.website.str.lower()
except AttributeError:
pass
str_columns = ["name", "trade_name", "city", "county"]
for column in str_columns:
try:
... | eb9aaa474fe517b346eaa8cd93e669b3fcc3459d | 704,302 |
def split_exon(exon, cds):
"""Takes an exon and a CDS, and returns a map of regions for each
feature (UTR5/3, CDS) that may be inferred from the arguments.
Note that the CDS is simply returned as is, to simplify
downstream handling of these features."""
results = [cds]
if exon["start"] < cds["s... | e2bb12a688bbe3e5c79039c2a9cce4e5aa9e9a1b | 704,307 |
def state_dict_to_cpu(state_dict):
"""Make a copy of the state dict onto the cpu."""
# .state_dict() references tensors, so we detach and copy to cpu
return {key: par.detach().cpu() for key, par in state_dict.items()} | 2d1fcc07ab8eac192a846cbcdb8d7363ffd8e9e8 | 704,308 |
import unicodedata
def normalize_str(text):
"""
Normalizes unicode input text (for example remove national characters)
:param text: text to normalize
:type text: unicode
"""
# unicodedata NFKD doesn't convert properly polish ł
trans_dict = {
u'ł': u'l',
u'Ł': u'L'
}
... | 40c8f77cdbf08b12a3867cd4a9d9bb91b323b50b | 704,309 |
def public_dict(obj):
"""Same as obj.__dict__, but without private fields."""
return {k: v for k, v in obj.__dict__.items() if not k.startswith('_')} | 2edee1a17d0dad6ab4268f80eb565406656a77b4 | 704,317 |
def wilight_to_opp_position(value):
"""Convert wilight position 1..255 to opp.format 0..100."""
return min(100, round((value * 100) / 255)) | 4f6e4298a77c29ff0375d0ce5e5fd23e77e30622 | 704,319 |
def get_task_link(task_id, task_df):
"""Get the link from the PYBOSSA task."""
try:
task = task_df.loc[int(task_id)]
except KeyError:
return None
return task['info']['link'] | d90e994d2f0a4718bbedf8fd5fd534f6d5d32549 | 704,320 |
from typing import List
from typing import Tuple
def partwise_function(function: str, parts: List[Tuple[str, str]], add_zero_otherwise: bool = True) -> str:
"""
Returns a string representing the definition a part-wise mathematical function.
**Parameters**
- `function`: str
The name of the f... | b2954a9c947add4cf4b4740ac62f4ca16d3e1d70 | 704,321 |
def read_restrictions_file(file):
"""
<Purpose>
Reads in the contents of a restrictions file.
<Arguments>
file: name/path of the file to open
<Returns>
A list, where each element is a line in the file
"""
# Get the file object, read mode with universal newlines
fileo = open(file,"rU"... | df7207ea3bab49af47fcfbdaa9cc51f54692bb85 | 704,322 |
def get_file_content(file: str) -> str:
"""
Get file content.
"""
try:
with open(file, 'r') as f:
content = f.read()
return content
except IOError as e:
print(e)
print('Exiting...')
exit(1) | c10407d73ba2cd2d84eb99c0f131d3895ede460d | 704,327 |
def resource_name_for_resource_type(resource_type, row):
"""Return the resource name for the resource type.
Each returned row contains all possible changed fields. This function
returns the resource name of the changed field based on the
resource type. The changed field's parent is also populated but is not us... | 500bc32be1765f1e516f4f7cd386b24c3c4f373f | 704,329 |
import re
def to_yw7(text):
"""Convert html tags to yWriter 6/7 raw markup.
Return a yw6/7 markup string.
"""
# Clean up polluted HTML code.
text = re.sub('</*font.*?>', '', text)
text = re.sub('</*span.*?>', '', text)
text = re.sub('</*FONT.*?>', '', text)
text = re.sub('</*SPAN.*?... | 59b9b961f7a94d23e2829b9d940f63c32207600b | 704,330 |
import time
def wait_for_job(res, ping_time=0.5):
"""
Blocks execution and waits for an async Forest Job to complete.
:param JobResult res: The JobResult object to wait for.
:param ping_time: The interval (in seconds) at which to ping the server.
:return: The completed JobResult
"""
while... | 1a7202f58affa97b0001b246fb7cd187d6a59f44 | 704,335 |
def numeric_type(param):
"""
Checks parameter type
True for float; int or null data; false otherwise
:param param: input param to check
"""
if ((type(param) == float or type(param) == int or param == None)):
return True
return False | a5f67a30b3128c1214d8825abbc6ae5170680d80 | 704,336 |
def get_page_generator(s,max_items=0):
"""Get the generator that returns the Page objects
that we're interested in, from Site s.
"""
page_generator = s.allpages()
if(max_items>0):
page_generator.set_maximum_items(max_items)
return page_generator | d53a890523c999df878fecc71ef1dbd8d17c188c | 704,338 |
def segment_text_to_sentences(text_file, sentence_splitter):
""" Segment text into sentences. Text is provided by BRAT in .txt
file.
Args:
text_file (str): the full path to the BRAT .txt file.
sentence_splitter (spacy LM): SpaCy EN language model.
Returns:
... | d74857a4931d162b9573b1b086a8720563b4fd41 | 704,340 |
def param_to_string(metric) -> str:
"""Convert a list / tuple of parameters returned from IE to a string"""
if isinstance(metric, (list, tuple)):
return ', '.join([str(x) for x in metric])
else:
return str(metric) | 54476f88936336728ba73425bb57860e17fb7561 | 704,342 |
def fitness_func_large(vector):
""" returns a very large number for fitness"""
return 9999999999999999999 | 08e6f43c5f891fe7138dfc7b1d0809ba048bf070 | 704,345 |
def remove_prefix(s, pre):
"""
Remove prefix from the beginning of the string
Parameters:
----------
s : str
pre : str
Returns:
-------
s : str
string with "pre" removed from the beginning (if present)
"""
if pre and s.startswith(pre):
return s[len(pre):]
... | 6bae14cddd38fcfabfb0fadb9f4dbeaea81ff4ac | 704,346 |
def remove_empty(df):
"""
Drop all rows and columns that are completely null.
Implementation is shamelessly copied from `StackOverflow`_.
.. _StackOverflow: https://stackoverflow.com/questions/38884538/python-pandas-find-all-rows-where-all-values-are-nan # noqa: E501
Functional usage example:
... | c2ea9fc13bfa57bc357a83c607bfe9ce9348fb2e | 704,348 |
from typing import Optional
def calculate_serving_size_weight(
weight: Optional[float], number_of_servings: Optional[float]
) -> Optional[float]:
"""
Given a weight (representing the total weight of the
component included in a recipe) and a number of servings
(how many servings of the component ar... | b22732a60f1f6000277861a615c78e785b4757bb | 704,349 |
def format_key(key):
"""
Format the key provided for consistency.
"""
if key:
return key if key[-1] == "/" else key + "/"
return "/" | 8b5e41bb76c524ec8c45a22ad0dae84c84ed530b | 704,350 |
from typing import Dict
def _define_problem_with_groups(problem: Dict) -> Dict:
"""
Checks if the user defined the 'groups' key in the problem dictionary.
If not, makes the 'groups' key equal to the variables names. In other
words, the number of groups will be equal to the number of variables, which
... | ab29954f3349509a9153219d040feb8fa3125ec7 | 704,351 |
def gaspari_cohn_mid(z,c):
"""
Gaspari-Cohn correlation function for middle distances (between c and 2*c)
Arguments:
- z: Points to be evaluated
- c: Cutoff value
"""
return 1./12*(z/c)**5 - 0.5*(z/c)**4 + 5./8*(z/c)**3 \
+ 5./3*(z/c)**2 - 5*z/c - 2./3*c/z + 4 | 0852e84c1ce10856d69420fcc585054488591e73 | 704,352 |
import math
def DrawTextBar(value, max_value, max_width=53):
"""Return a simple ASCII bar graph, making sure it fits within max_width.
Args:
value: integer or float representing the value of this bar.
max_value: integer or float representing the largest bar.
max_width: How many characters this graph ... | 7f4b267527317cbceddadc9f7a0307f8ec430bb4 | 704,355 |
def _FindBinmanNode(dtb):
"""Find the 'binman' node in the device tree
Args:
dtb: Fdt object to scan
Returns:
Node object of /binman node, or None if not found
"""
for node in dtb.GetRoot().subnodes:
if node.name == 'binman':
return node
return None | bf924d173a1adf81c1705ad1ea1fae490567a317 | 704,356 |
def _host_is_same(host1: str, host2: str) -> bool:
"""Check if host1 and host2 are the same."""
return host1.split(":")[0] == host2.split(":")[0] | 0bd9393786801d0f69d4982fc9f8edce378e9656 | 704,359 |
import math
def round_half_up(n: float, decimals: float = 0) -> float:
"""This function rounds to the nearest integer number (e.g 2.4 becomes 2.0 and 2.6 becomes 3);
in case of tie, it rounds up (e.g. 1.5 becomes 2.0 and not 1.0)
Args:
n (float): number to round
decimals (int): number of ... | e0aab5cba456b4ffe6fab11a21b97fe4e17b045a | 704,362 |
from typing import Set
def _possible_edges(n1: Set, n2: Set, directed: bool, self_loops: bool = False):
"""Compute the number of possible edges between two sets."""
a = n1.intersection(n2)
e = (len(n1) - len(a)) * (len(n2) - len(a))
if directed:
e *= 2
if self_loops:
e += len(n1) +... | 4cf21d9521c3d071d7d1376bd917f2ec39435108 | 704,363 |
def default_category_orders() -> dict:
"""Returns the default dictionary of category orders"""
day_order = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]
weekend_order = ["Weekday", "Weekend"]
season_order = ["Spring", "Summer", "Autumn", "Winter"]
month_order = [
"January",
"Febr... | 4110287bc30445f27c7c3d0c38cb662d769a5217 | 704,365 |
import re
def is_guid(techfin_tenant):
"""Validate guid arg
Args:
tenant (str): techfin tenant id
Returns:
bool: true if is valid guid value
"""
c = re.compile('[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}', re.I)
res = c.match(techfin_tenant)
r... | 7242f0da279375ab5873670ffef1fd4aa8749546 | 704,366 |
def __standard_cand_fun(candidates):
"""
Convert candidates from the forms accepted by :py:fun:`recommend` into
a standard form, a function that takes a user and returns a candidate
list.
"""
if isinstance(candidates, dict):
return candidates.get
elif candidates is None:
retu... | ad206802bfbcd0ec8f4601ebc043f8d468709c75 | 704,368 |
def dBrickId(brickId):
"""Return box id if valid, raise an exception in other case"""
if brickId >= 0 and brickId <= 15:
return brickId
else:
raise ValueError(
'{} is not a valid Brick Id, Brick Id must be between 0-15'.format(
brickId)) | 10e0f27f179dcd54c5cc4967ea960b77a4c5a924 | 704,370 |
import hashlib
def hash(text, digest_alg = 'md5'):
"""
Generates hash with the given text using the specified
digest hashing algorithm
"""
if not isinstance(digest_alg,str):
h = digest_alg(text)
else:
h = hashlib.new(digest_alg)
h.update(text)
return h.hexdigest() | 386268086a55b8e622c00b407cabd3207bb94ffb | 704,371 |
def merge_params(params, config):
"""Merge CLI params with configuration file params. Configuration params
will overwrite the CLI params.
"""
return {**params, **config} | a1dc002a900968e6cf7c5ba401519759e6ef485e | 704,372 |
def tasks(tmpdir):
"""
Set up a project with some tasks that we can test displaying
"""
task_l = [
"",
" ^ this is the first task (released)",
" and it has a second line",
" > this is the second task (committed)",
" . this is the third task (changed, not yet com... | 64104bde2aab55021cf0d49fbb1d47670d0e4e0d | 704,376 |
def singer_map(pop, rate):
"""
Define the equation for the singer map.
Arguments
---------
pop: float
current population value at time t
rate: float
growth rate parameter values
Returns
-------
float
scalar result of singer map at time t+1
"""
return... | 84aba1d96304b67fba1b4a0e7a909e23121a3d6b | 704,378 |
import json
def format_rpc_response(data, exception=None):
"""
Formats a response from a RPC Manager.
It provides the data and/or a serialized exception so it can be
re-created by the caller.
:param Any data: A JSON Serializable object.
:param Exception exception: An Exception object
:ret... | c900e2512fd486c91789ab4312883061553a2fb1 | 704,379 |
import logging
def select_best_haplotype_match(all_matches):
"""Returns the best HaplotypeMatch among all_matches.
The best matching HaplotypeMatch is the one with the lowest match_metrics
score.
Args:
all_matches: iterable[HaplotypeMatch]. An iterable of HaplotypeMatch objects
we want to select t... | 0e40fef830055e5cd297b0f00672d8b0caedc62e | 704,380 |
def get_tokens_list_from_column_list(column_name_list: list,
delimiter: str = '!!') -> list:
"""Function that returns list of tokens present in the list of column names.
Args:
column_name_list: The list of column name strings.
delimiter: delimiter seperating tok... | 66e2c3c280188d2cc3e8df35e0112095f3244918 | 704,381 |
def load_variable_config(project_config):
"""Extract the variable configuration out of the project configuration.
Args:
project_config (dict-like): Project configuration.
Returns:
dict: Variable dictionary with name: [levels] (single level will have a list containing None.)
"""
# ... | 37caccfa5f9c3a724e61233610c3e4a3e9938695 | 704,385 |
import torch
def cross_op_torch(r):
"""
Return the cross operator as a matrix
i.e. for input vector r \in \R^3
output rX s.t. rX.dot(v) = np.cross(r, v)
where rX \in \R^{3 X 3}
"""
if len(r.shape) > 1:
rX = torch.zeros(r.shape[0], 3, 3).to(r)
rX[..., 0, 1] = -r[..., 2]
rX[..., 0, 2] = ... | 04f926f00f6ed58bee3feae80ef573f5a8822d20 | 704,386 |
from typing import Callable
from typing import Optional
from typing import Union
from typing import Tuple
from typing import Iterable
def solve_nr(
f: Callable[[float], float],
df: Callable[[float], float],
estimate: float,
eps: Optional[float]=1.0e-6,
max_num_iter=100,
throw_if_failed_converge=True,
re... | c6ab8b6bb27f8b9be9c31fe7cbd58300637d9fef | 704,394 |
import calendar
import pytz
def epoch(dt):
"""
Returns the epoch timestamp of a timezone-aware datetime object.
"""
return calendar.timegm(dt.astimezone(pytz.utc).timetuple()) | 027ea75bf75b6bb6b4da14b2bed1afc363a9121a | 704,397 |
def set_produce_compilation_cache(enabled: bool) -> dict:
"""Forces compilation cache to be generated for every subresource script.
Parameters
----------
enabled: bool
**Experimental**
"""
return {"method": "Page.setProduceCompilationCache", "params": {"enabled": enabled}} | 3d2dd7fa6c8d04713ace26c666d9b00407a5a586 | 704,398 |
def clean_column(df, column):
"""
Function to return clean column text. Pass each cell to a cleaner
and return the cleaned text for that specific column
:params:
--------
:df dataframe(): containing the column
:column str(): in which column the text is located
:returns:
---... | 095a854c452f87b9a960eabb81ace5c18814f266 | 704,404 |
def file_readlines(fn):
"""Open file with name `fn`, return open(fn).readlines()."""
fd = open(fn, 'r')
lst = fd.readlines()
fd.close()
return lst | 2594e6763b566f4e83844f2f4457bcc8ea3663a5 | 704,407 |
def __num_elems(shape):
"""Returns the number of elements in the given shape
Args:
shape: TensorShape
Return:
tot_elems: int
"""
tot_elems = 1
for s in shape:
tot_elems *= int(s)
return tot_elems | fd4f72394b22c98e6bedb545d7d11b8bfae11add | 704,411 |
def players_player_id_get(player_id): # noqa: E501
"""Retrieve a single player's record
Returns a player record # noqa: E501
:param player_id: ID of player to return
:type player_id: str
:rtype: Player
"""
return 'do some magic!' | d9c2c92dbba3d139b2b5188e8722a0add7668393 | 704,417 |
def build_info_str(username: str, name_len: int, remaining_chip: int, action: str,
chip: int, is_waiting: bool, countdown: int) -> str:
"""Build a string to explain action of a user
Args:
username (str): user name
name_len (int): characters to show the name
remaining_... | 1ecbb6c33d54a55500d51ce09cf9740ac28def96 | 704,419 |
def get_similarity_score(dict1, dict2, dissimilarity = False):
"""
The keys of dict1 and dict2 are all lowercase,
you will NOT need to worry about case sensitivity.
Args:
dict1: frequency dictionary of words or n-grams for one text
dict2: frequency dictionary of words or n-grams for ano... | 31e8602d6ef098a58a8eaf497badebf2e19288eb | 704,421 |
def predict_fn(input_data, model):
"""Predict using input and model"""
return model(input_data) | 00f7bf0bd71f70833f8f77b16ffa62559747e915 | 704,422 |
def get_unnormalized_text(words):
""" Returns the (unnormalized) text composed from the given words."""
return "".join([x.unnormalized_with_whitespaces for x in words]) | 162854d917ee4d49c3b2b824abc07697ac4f05ba | 704,423 |
import json
def get_ability_icons(champion, input_path):
"""
This function takes a champion and input path strings as input and returns a
dictionary of png file paths with keys corresponding to the following
abilities: Passive, Q, W, E, and R
"""
global ability_icon_paths
ability_icon_pa... | e33c01bedcd8bf20959978df2bc2b33b934e2181 | 704,425 |
def _l1_regularization(l1, model):
"""Computes the L1 regularization for the given model
Args:
l1 (float): L1 parameter
model (:obj:`torch.nn.Module`): Model to use
Returns:
float: L1 loss (i.e. l1 * l1_norm(params))
"""
l1_loss = sum(param.norm(1) for param in model.parame... | 32826672a7de00f8a0412e2496e6ebfea213b502 | 704,427 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.