content stringlengths 35 416k | sha1 stringlengths 40 40 | id int64 0 710k |
|---|---|---|
from datetime import datetime
def get_date(data):
""" Parses a date
"""
# Match patterns like "2019-04-22"
parsed_date = None
try:
parsed_date = datetime.strptime(data, "%Y-%m-%d")
except ValueError:
pass
return parsed_date | a4eea694076c70f1ee672524ad529b0804f4d65d | 42,461 |
import time
def calc_time(func, *args, **kwargs):
"""Calculate execution time of specified function."""
start_time = time.time()
func(*args, **kwargs)
finish_time = time.time()
return finish_time - start_time | 104b378b66009a9b49ebf8804c27f33a01b33287 | 42,463 |
def _nus_uuid(short: int) -> str:
"""Get a 128-bit UUID from a ``short`` UUID.
Args:
short: The 16-bit UUID.
Returns:
The 128-bit UUID as a string.
"""
return f"6e40{short:04x}-b5a3-f393-e0a9-e50e24dcca9e" | 207163a7339808b65c0f3d1b0fcdfde87057eb57 | 42,464 |
import functools
def force_run(iterable):
"""
Run every function in the provided list - left to right - regardless of
whether any exceptions are thrown. Useful for unwinding.
>>> a, b = 0, 0
>>> a == 0 and b == 0
True
>>> def x():
... global a
... a = 1
>>> def y():
... | 6d4c86132e4a9d769ea9a82c67e5c58eb95aaed3 | 42,465 |
def form_model_meta_model_name(form):
"""
:param form
:return: form model name
Usage: {% form_model_meta_model_name form %}
"""
return form.Meta.model._meta.model_name[1:] | e7d932c16c6ee1cdd018b7f384ddba1c0ad28c5a | 42,466 |
def whole_requirement(func):
"""A decorator for whole requirement functions. A whole requirement
function should accept a *data* object and return values appropriate
for instantiating a :exc:`ValidationError` (either an iterable of
differences or a 2-tuple containing an iterable of differences and
a... | 4e6957767e68d8ad445816a9040f99f006ced1bf | 42,467 |
def address_in_db(cursor, address):
"""Returns true if address is in database, false otherwise."""
cursor.execute('SELECT address FROM farmers WHERE address=?',
(str(address),))
data = cursor.fetchone()
if data is None:
return False
return True | 1e93eaf2874fdf9fca8c4db73b981e41a00c5538 | 42,468 |
def convert_units(cube, units):
"""
Convert the units of a cube to new ones.
This converts units of a cube.
Arguments
---------
cube: iris.cube.Cube
input cube
units: str
new units in udunits form
Returns
-------
iris.cube.Cube
converte... | a0562d75d96b97caaab125b9999856030c41975c | 42,469 |
def lemmatize_all_pos_pair(keyword_score_pair, lemmatizer):
"""
lemmatize each word in text and return a list of lemmatized tokens
:param keyword_score_pair: list of tuple, [(keyword, score), ...], where keyword is a string and score is a float
:param lemmatizer: nltk WordNetLemmatizer
:return: dic... | 854b8c4ba6b29fa1db92d65429ddead2f9b83aa5 | 42,470 |
from pathlib import Path
def get_real_path_to_torchmeta_miniimagenet(dummy_datapath: Path) -> Path:
"""
Since torchmeta expects the path to where the folder miniimagenet/ is (i.e. the folder with the data set)
this function get the path to miniimagenet given the dummy path e.g.
~/data/miniimagenet... | b218902fcbdb8eb277b999d116c79689d64e1e09 | 42,471 |
import yaml
def gen_yaml_decoder(cls):
"""Generate a custom YAML decoder with non-default mapping class
Args:
cls: Class used for mapping
"""
def struct_constructor(loader, node):
"""Custom constructor for Struct"""
return cls(loader.construct_pairs(node))
# pylint: disab... | d1218af849ddf8f1402057735bb40de7d954f181 | 42,473 |
def all_equal(arg1, arg2):
"""
Shortcut function to compute element-wise equality between two iterables
Parameters
----------
arg1 : iterable
Any iterable sequence
arg2 : iterable
Any iterable sequence that has the same length as arg1
Returns
-------
bool
Tr... | 1920e0e28c7ca632438c3adde2c22f5b21f7e54e | 42,474 |
def extract_general_rxn_info(br_data):
"""
Extract all activating molecules for the PR of this RS.
It is possible that there is no information, or multiple entries.
"""
nprop = 'RT'
output_nprop = []
list_of_nprop = br_data[nprop]
for i, entry in enumerate(list_of_nprop):
value ... | df06d4a61f83282cf904ca69b38cd0e5a8b6ac98 | 42,476 |
def get_adjacent_face ( surface, edge_data, idx ):
""" get_adjacent_face ( surface, edge_data, idx )
Get the number (index) of the face that includes the edge that is the reverse
direction of the passed (hashed) edge
@param surface - working surface structure (dictionary)
@param edge_data - pre ge... | 5d417afb1668b1eeb82ebbc9c2cd612e6559889a | 42,477 |
def get_cluster_idx(_cluster):
"""
returns cluster idx for sorting
"""
return _cluster.cluster_idx | b58c5fd2fe51231cb900428f068868b0ed0218b1 | 42,479 |
def bool_mapper(attribute):
"""
Maps ``yes``, ``1`` and ``on`` to ``True`` and ``no``, ``0``
and ``off`` to ``False``.
"""
def _fn(values):
if values["bool"].lower() in ("yes", "1", "on", "true"):
return {attribute: True}
elif values["bool"].lower() in ("no", "0", "off",... | 549260ae13c65b452b91551865f37626dda5a423 | 42,481 |
import os
def get_cybershake_list(cybershake_root):
"""Gets the cybershake list, specifying the faults and number of realisation"""
return os.path.join(cybershake_root, "list.txt") | 4b02f49e1d5d3535ba228b9404132f14adc64009 | 42,484 |
def ask_for_even_more_input():
"""
asks for even more input needed for the simulation
Returns:
detection_probability (float): probability an infected human will get quarantined
"""
while True:
try:
detection_probability = float(input(
"Probability of dete... | e50c9de0d729298ee04206710c912d475eb14d3d | 42,485 |
def pkcs7pad(ciphertext, blocksize, value=b'\x04'):
"""
ciphertext: bytes string, blocksize: int, value: bytes char
Return ciphertext padded with value until it reach blocksize length.
"""
length = len(ciphertext)
pad = blocksize - (length % blocksize)
return b''.join((ciphertext, value * pa... | 1715cd2e5a7ffb4cfb535db28f0d8dca5db4adae | 42,486 |
def get_indeed_url(position, location):
"""
Gives the indeed url of a search query with a job position and location given as parameters
Parameters : Job Position
Job Location
Return : Appropriate Indeed URL
"""
pattern = 'https://fr.indeed.com/jobs?q={}&l={}'
url = patter... | 7b31bf4ca2a89ed25d43add9028c23b505419da2 | 42,487 |
def fix_list(x):
"""
Turn a string of a list into a Python list.
"""
if len(x) > 0:
y = eval(x)
if len(y) > 0:
return y
return None | 15bf9733b145a29a89c95985b41457b79fc984cc | 42,489 |
def mean(array):
"""
get mean of list, returns None if length is less than 1
"""
if not array:
return None
return float(sum(array))/float(len(array)) | 2417125c93ceb9a46b108817c7cc7961c841bc14 | 42,490 |
import os
def is_network_namespace_exists(name):
"""
Checks that a namespace exist or not
Parameter
---------
name : namespace name as str
Returns
-------
True if exists False otherwise
"""
return os.path.exists('/var/run/netns/%s' % name) | 14fc0fb1ad373b5bfd637f5fdb41d14d1e59daa2 | 42,491 |
import math
def sigmoid(z):
"""激活函数(Sigmoid):f(z) = Sigmoid(z)
:param z: 神经元的输入
:return: 神经元的输出
"""
return 1.0 / (1.0 + math.exp(-z)) | 996cbbbddd7f38596054b794375695fcf923c813 | 42,492 |
import os
import secrets
from pathlib import Path
def mktempfn(fn):
"""Return a path object temporary filename in the same directory as `fn`.
For very long input file names, the resulting file name my exceed the
maximum length allowed by the OS. This is considered to be unlikely here,
where only name... | 05b973522af9ca9723d3433119ca07b000eb2a61 | 42,493 |
def copynode2(nod,dup):
"""
copies only essential elements of nod into dup (faster)
"""
x=nod.value
dup.value=x if type(x)!=list else x[:]
dup.lastchange=nod.lastchange
dup.nature=nod.nature[:]
dup.isdelayed=nod.isdelayed
dup.occur=nod.occur[:]
dup.pointe... | 87cf9763288b3a030c49a3c004f6546d82a0a4ca | 42,494 |
from typing import List
def subsequence(search: List, seq: List) -> bool:
"""Determine if seq is a subsequence of search, starting at index 0.
"""
return len(search) >= len(seq) and all(x == y for (x, y) in zip(search, seq)) | f7d93fba1c5af1972442d9f4306c6b0986ba8858 | 42,495 |
import torch
def _align_and_update_loaded_state_dicts(model_state_dict, loaded_state_dict):
"""
Strategy: suppose that the models that we will create will have
prefixes appended to each of its keys, for example due to an extra
level of nesting that the original pre-trained weights from ImageNet
wo... | 6f2a40f13b9789218aaff015e442ef17be311f83 | 42,500 |
def rangelist(numbers):
""" Convert a list of integers to a range string in the form
'1,2-5,7'.
"""
numbers = numbers[:]
numbers.sort()
numbers.append(999999)
pattern = ','
for i in range(len(numbers)-1):
if pattern[-1] == ',':
pattern = pattern + str(numbers[i])
... | e4ab99de85e67ac17ca2f3a0450c988b540cc8e6 | 42,501 |
def estimate_bias_randomized_response_bool(prior, p):
"""estimates the bias of randomized response
when the probability of returning the true answer is `p`,
and the likelihood that each answer is given is held in `priors`.
For example, say you have a prior that your survey question will be answered "y... | e5d1690c0c4cb9888d304794925fdd84287adeff | 42,503 |
import os
def env_get_var_value(var_name):
"""Returns value for variable in os.environ
Function throws AssertionError if variable is defined.
Unit-test based python tests require certain input params
to be set in environment, otherwise they can't be run
"""
assert var_name in os.environ.keys(... | 100271f66cdf8d0a3d0701d45d203ac9d02ae116 | 42,504 |
import sys
def get_os():
"""Get OS name.
.. note::
darwin: Mac.
linux: Linux.
Win32: Windows.
Returns:
str: OS name.
Examples:
>>> get_os() #doctest: +ELLIPSIS
'...'
"""
return sys.platform | b6bc09a4ad03201f8dce5a6e9e7fa72d9f49b145 | 42,506 |
import math
def euclidean_distance(point1, point2):
"""Return the euclidean distance between two points."""
return math.sqrt((point2.x - point1.x)**2 + (point2.y - point1.y)**2 + (point2.z - point1.z)**2) | 5ab2d751e24313b3ebe969b7c897164ffac425f9 | 42,507 |
def select_subscription(subs_code, subscriptions):
"""
Return the uwnetid.subscription object with the subs_code.
"""
if subs_code and subscriptions:
for subs in subscriptions:
if (subs.subscription_code == subs_code):
return subs
return None | 95490620b6841e7bf718023b6484096ff112d27b | 42,508 |
def get_object_to_write(result):
"""
Returns the constructed object containing the search results data, for later analysis.
Args:
result: The output from running the query
Returns:
object_to_write: the constructed object containing desired search result data
"""
... | 9b3bba46d8eadd8f3df4c21e622aa8b821bf1781 | 42,509 |
import torch
def cam_project(points, K):
"""
:param points: torch.Tensor of shape [b, n, 3]
:param K: torch.Tensor intrinsics matrix of shape [b, 3, 3]
:return: torch.Tensor points projected to 2d using K, shape: [b, n, 2]
"""
b = points.shape[0]
n = points.shape[1]
points_K = torch.m... | 3fc4af68e156f4bc46fbe106d54f7e577a457cf6 | 42,510 |
import re
def check_string(text, search=re.compile(r'[^A-Za-z0-9-_]').search):
"""Test that a string doesnt contain unwanted characters.
:param text: Text that you want to verify is compliant.
:type text: str
:param search: Regex to use to check the string. Defaults to allowing
[^a-z0-9-_].
... | 59348de4e86bc762cc8a7aef2243e1d2b2ce9f85 | 42,511 |
def get_bool_param(param):
"""Return bool param value."""
if isinstance(param, bool): return param
return True if param.strip().lower() == 'true' else False | ce43ae34e8676d1b9412738adc6647f9af1713c6 | 42,514 |
import sys
def is_venv():
"""Check to see if we are currently in a virtual environment
Returns:
[type] -- [description]
"""
return hasattr(sys, "real_prefix") or (
hasattr(sys, "base_prefix") and sys.base_prefix != sys.prefix
) | c746d2510ee0dd0764f586a692d5c389b815eb61 | 42,517 |
def stdist2(stddev, x):
"""
I don't remember. Related to Cumulative distribution function...
"""
if stddev == 0.0:
return 0.0 # to avoid division by zero
ea = abs(x / stddev / pow(2, 0.5))
if ea < 0.5:
return 0.38
elif ea < 1.5:
return 0.24
elif ea < 2.5:
... | 91870cd43238cdabf31a10be7ecdb54e01d6befa | 42,519 |
def _get_band_order(root):
"""Returns B0, B1, B2, B3 in some order"""
ee = root.findall('.//Band_Display_Order/*')
return [e.text for e in ee] | ff6837824a66cb3d8ef537df6eed575e1d8231f5 | 42,521 |
import re
def year_from_babyfile_string(babyfile_string):
"""
return year as a string
"""
print('year_from_babyfile_string')
match = re.search(r'Popularity in \w\w\w\w', babyfile_string)
if match:
print('found {}', match.group())
year_int = match.group()[-4:]
year = str... | f3d8729a2e7d3909acffffd6fdce48a81c9395d5 | 42,522 |
def modify_idx(*args, idx, dim):
"""
Make an index that slices a specified dimension while keeping the slices
for other dimensions the same.
Parameters
----------
*args : tuple of int or None
constructor arguments for the slice object at target axis
idx : tuple of slice
tup... | 09d0553b6281d1c7e5103b14dfde78003f92a554 | 42,523 |
import argparse
def parse_args():
"""
Returns parsed arguments from command line input.
"""
# Opens up an argument parser.
parser = argparse.ArgumentParser(description="Determines type of capture.")
parser.add_argument("--type", action="store", default="frame",
type=s... | 31592b48d24106b678dabaa2289edb4a3ab67430 | 42,524 |
def is_wanted_header(header):
"""Return True if the given HTTP header key is wanted.
"""
key, value = header
return key.lower() not in ('x-content-type-warning', 'x-powered-by') | 5b3dddbbfc7279d9d750f88eba2c07b9c87a0e29 | 42,525 |
from pathlib import Path
def _get_all_migrations_from_folder(migration_folder):
"""Simply checks folder for files which ends with up.sql
:param migration_folder: Path to migration folder
:type migration_folder: string
:returns: Path object globbed for a string *.up.sql
:rtype: pathlib.Path
""... | 983c736cd2cf1ec2587ec67f33018c3368740c70 | 42,526 |
def matrix2vec(m, axis='x'):
"""Calculate axis vector from rotation matrix
Parameters
----------
m : numpy.ndarray
rotation matrix
axis : str, optional
axis x, y, z, by default 'x'
Returns
-------
vec : numpy.ndarray
Raises
------
ValueError
axis sh... | 9c6cda577f35158a8756e866a1db9a4d5f851ab4 | 42,527 |
def split_text_by_maxlen(text, maxlen=512):
"""
长句切分为短句,每个短句maxlen个字
:param text: str
:param maxlen: int, 最大长度
:return: list, (sentence, idx)
"""
result = []
for i in range(0, len(text), maxlen):
result.append((text[i:i + maxlen], i))
return result | 6ed3bb269d7c7628e5743f824aaa5a85057ecc1e | 42,528 |
def time_in_range(start, end, x_time):
""" See if a time falls within range """
if start <= end:
return start <= x_time <= end
return end <= x_time <= start | 7250d9fb58360b5923e3a29fbf268f3ced979890 | 42,529 |
import shlex
def split_cli_command_and_shell_commands(command_text):
"""Split the command text into cli commands and pipes
e.g.::
cat ID | grep text
``cat ID`` is a CLI command, which will be matched against the CLI grammar tree
``grep text`` is treated as a SHELL command
Returns a tup... | d7219805e8064ce681eb24487e5bbc8ff2236af4 | 42,531 |
def make_category_query(category):
"""Creates a search query for the target audio category"""
# mediatype:(audio) subject:"radio"
return f"mediatype:(audio) subject:{category}" | f30b563bde7323483a7be670d2b41c475622ba20 | 42,532 |
import os
def get_framework_template(framework_name: str) -> str:
"""Reads the framework's template.
Args:
framework_name: String represents the name of the framework.
Returns:
The framework's template.
"""
return open(os.path.join('./src/frameworks', framework_name, 'template.p... | 96da8f7fda1ad1bee3ed90967ee75a1f00b151e2 | 42,533 |
import os
import re
def get_future_s3_filename(filename, bucket_objects):
"""
Allows us to get the filename to use when we upload the object in S3
e.g if filename='temp.txt' does not exist in bucket_objects, we return temp.txt;
if temp.txt exists but temp-(\d?).txt does not, we return temp-1.txt;
... | 52b25f091e28ccac4d3c06011672336aa8c5b2c2 | 42,535 |
def new_position(floor_df, participant_df, mappings_df):
"""
Create position.
"""
# print("Info : my_lib/position/new_position().")
"""
floor_df
--------
ID,X,Y,BLOCK
27,0,0,C
26,1,0,C
25,2,0,C
"""
# print("Info : floor.csv : {}".format(floor_map_csv_file))
... | edf8737f10d6c7c574861800d12b4b84026f2146 | 42,536 |
import os
def getFileNameWithoutExtension(fileName: str) -> str:
"""
获取文件名,不带扩展名
"""
return os.path.splitext(os.path.basename(fileName))[0] | a775395fee8affd5126f7adc03fe66ea4b380107 | 42,537 |
def _exclusions(table_name, ignore_columns):
"""Generate a list of columns to exclude from serialisation for a given table name
Parameters
----------
table_name : str
The name of a data table within the app
ignore_columns : list, tuple, dict or str
A list or tuple of column names t... | 5590783c98e3e24317705751965ee48499611064 | 42,539 |
def plugins_string(secrets):
"""Provide a plugins_string property to the template if it exists"""
return secrets.relation.plugins_string | b2137fb7e8be7911c48a4d95cb48d280df3a0dc0 | 42,540 |
def get_multiple_model_method(model):
"""
It returns the name of the Multiple Model Chain element of the model.
Parameters
----------
model :
A Scikit-learn model instance
Returns
-------
The multiple model method for a mining model.
"""
if model.__class__.__n... | a87525ab9eedfb46443319f771b2275756b7188e | 42,542 |
import pathlib
import os
def realpath(path: pathlib.Path) -> pathlib.Path:
"""Return the canonical path of the specified filename."""
return pathlib.Path(os.path.realpath(path)) | ebe94ecabab3693e5590de94d5a9d5d05bd1b041 | 42,543 |
from datetime import datetime
def parse_date_string(date_string):
"""
Converts the date strings created by the API (e.g. '2012-04-06T19:11:33.032') and
returns an equivalent datetime instance.
"""
return datetime.strptime(date_string, "%Y-%m-%dT%H:%M:%S.%f") | eefa2ba1cec70c2a96c2deb1ece85802360e47f1 | 42,544 |
def create_pi_dict(file_path):
"""Reads Octamers file and creates a dictionary of P and I values for each octamer.
:param file_path (string): Path of the file containing P and I values for all octamers
:return: A dictionary containing a list of PI values for each octamer
"""
pi_dict = dict()
w... | 798790a9b8ef5fddbea18ee759a4af7069b656a6 | 42,545 |
def make_plotting_func(function, ratios):
"""Return a lambda function ready for plotting in ternary."""
return lambda inputs: function(ratios)/100 | 223acf81f6e5f810dc4b746c56b904c0b1dc8564 | 42,546 |
def _find_files(metadata):
"""
.. versionadded:: 3001
Looks for all the files in the Azure Blob container cache metadata.
:param metadata: The metadata for the container files.
"""
ret = {}
for container, data in metadata.items():
if container not in ret:
ret[containe... | 2c410afa58131466ec83675d98a23770680575be | 42,547 |
def normalize_title(title):
"""Normalize titles.
"""
return title.strip().title() | 86a06fa50033e565d34b4c8b93bc67ad048fdb72 | 42,548 |
def make_filter_params(db447x, n_downsample: int = 1, n_0: int = 4096, n_poles: int = 1, f_cutoff: int = 10000,
n_avg: int = 1, factor: int = 1):
"""
Function to turn filter parameters into a dictionary that is later read by the parse_filter function
:param db447x: dataframe of ni447x... | ef59ee3c427387947702532f3827e779b3f2cb91 | 42,549 |
def handle_dot(next, token):
"""
/./
"""
def select(result):
return result
return select | 3a8575f515c3336c751cabf13d543ceb2f0ce229 | 42,553 |
def state_in_addrlist(state, l):
"""
Determine whether the instruction addresses of a state are in a list
provided by ...
"""
if not l:
# empty list
return False
for addr in state.block().instruction_addrs:
if addr in l:
return True
return False | d5d52e036c931061e3e6a1298524b9b1e821847e | 42,554 |
def convert_mongo_document_to_api_dict(obj):
"""Converts a mongo document object to the api dict that can be used for json conversion"""
dict_ = obj.to_mongo()
dict_.update({'id': str(dict_['_id'])})
result = dict_.copy() # cannot change a dict while iterating
for k, _ in dict_.iteritems():
... | ec1015b508adead06fc29aff90cdb5a494b0754b | 42,556 |
def last(path):
"""Returns a last "part" of a path.
Examples:
last('abc/def/ghi') => 'ghi'
last('abc') => 'abc'
last('') => ''
"""
if '/' not in path:
return path
return path.split('/')[-1] | af0071fa80ed67c2e427daf9f4202782aeb71997 | 42,559 |
def select_covid(conn, chatId):
"""
"""
cur = conn.cursor()
sql = f"""
SELECT Body
FROM MessageInfo
WHERE ChatID = {chatId} AND Body like "%covid19-live-analytics%" AND Timestamp > 0
"""
cur.execute(sql)
rows = cur.fetchall()
return rows | 0c358b3d6d4ab673742d5b244981a94feaeed604 | 42,560 |
def _get_configs(mod):
"""Gets module variables and creates dictionary"""
if "__all__" in mod.__dict__: # noqa
configs = mod.__dict__["__all__"]
else:
configs = [x for x, v in mod.__dict__.items() if not x.startswith("__") and not callable(v)]
configs = {k: getattr(mod, k) for k in con... | 0aaeab86d4aa16d581254f273d816b983506fa07 | 42,561 |
def _aligned_i(i, olen, alignment):
"""
A function that checks if a given foreign word is aligned
to any 'english' word in a given 'english' sentence
"""
# print "i:%s" % (i)
# print "olen:%s" % (olen)
# print "len(alignment):%s" % (len(alignment))
for o in range(olen):
if (i, o)... | 86bb647db43cca2df0f102dc725bac040dc142de | 42,562 |
import pathlib
import zipfile
def source_input_directory(user_filepath):
"""Examine program arguments to determine the location of an archive.
Extract as needed.
"""
if user_filepath is None:
return "export"
path = pathlib.Path(user_filepath)
if not path.exists():
raise Runtim... | 730319b194cebff9ed15e1ffc90e0991f5531f04 | 42,563 |
def n_target_classes():
"""
Number of target classes (that have >= 1 prototype assigned to them).
"""
return 10 | 3a56a980358488b86524e0d522ceef32ac3c4b66 | 42,564 |
def fuzzy_sort_coarse(image, pano_threshold):
""" A very fuzzy sort by aspect ratio - portrait then square then landscape then pano"""
if image.width > image.height*pano_threshold:
return 2
elif image.width > image.height:
return 1
elif image.width < image.height:
return -1
e... | 87249a3fa900131b80e0a7cd86d2b51691eee166 | 42,565 |
def print_para(opt):
"""
Prints parameters of a model
:param opt:
:return:
"""
st = []
for p_name, p in opt.named_parameters():
st.append("({}) {}: {}".format('grad' if p.requires_grad else ' ',
p_name, p.size()))
return '\n'.join(st) | ce4d70015494451f5cf34056350d1334cdbcbfca | 42,566 |
def prettify_error(s):
"""Adds a blank and replaces regular spaces by non-breaking in the first 90 characters
This function adds a big blank space and forces the first words to be a big block of
unbreakable words. This enforces a newline in the DSS display and makes the error prettier.
"""
retu... | 5424d45c735b860918685b6190c445603cf7d0d9 | 42,567 |
def increase(_):
"""Return offset adjust 1."""
return 1 | cf83fd360f07980b1a21d63eff6f405dd5a0ee1c | 42,568 |
import re
def onlyalphanum(value):
"""
Filtre `value` pour ne garder que les caractères alphanumériques.
Parameters
----------
value : str
La chaîne à filtrer
Returns
-------
str
La chaîne obtenue après filtrage
"""
return re.sub(r'[^A-Za-z0-9]+', '', value) | ade9b61fbda291a31d00ca2d8cb4975b197a3101 | 42,569 |
def eval_acc(test_fn, all_examples):
"""
Evaluate accuracy on `all_examples`.
"""
acc = 0
n_examples = 0
for x1, mask1, x2, mask2, l, y in all_examples:
acc += test_fn(x1, mask1, x2, mask2, l, y)
n_examples += len(x1)
return acc * 100.0 / n_examples | 62b7413fd39d30b35e144349a82e80a60adfca9e | 42,570 |
import os
def get_path_or_create(path):
"""
returns the path and the flag, if it has been just created
"""
path = os.path.abspath(os.path.expanduser(path))
if not os.path.exists(path):
os.makedirs(path)
return path, True
return path, False | d5a479e7ba2a98b60adf703f27dbc33340bc3b7e | 42,572 |
def create_worker(queue, worker_class):
"""
Creates a non-stop worker to gather tweets
Arguments:
----------
queue: queue.Queue
A queue to gather tasks from
worker_class: class or function returning an object
The returned object must respond to `work(status, query)`
Retur... | 269569e4c6016169f59d84862630c588c2a93c17 | 42,574 |
def verify_files(dir, addon):
"""Verify if the files in the path can be compressed in a gma"""
verified, disallowed = addon.verify_files()
if verified:
print("No illegal files were found.")
else:
print("Illegal files were found:")
for f in disallowed: print('\t' + f)
print("Please remove these files or add... | 2f39850ae02d2d6b7d5dbae6990037113d7b9aa4 | 42,575 |
def layer_info(layer, x, y, crs, params, identity):
"""Query layer and return info result as dict:
{
'features': [
{
'id': <feature ID>, # optional
'attributes': [
{
'name': '<attribute ... | 0ba311d8022de7dbc6a7bd8b505dbac67905fc64 | 42,576 |
def _is_yearbook_transaction(transaction_detail):
"""Returns True iff the paypal `transaction_detail` object contains an `item_name` of Yearbook.
"""
cart_info = transaction_detail.get('cart_info')
if cart_info:
item_details = cart_info.get('item_details')
if item_details and len(item_de... | 0540efb4d5d2fedc97ac5fe14ea29577d0adb358 | 42,577 |
def get_string_after_n_space(text, n):
"""
Method to return string after the nth space
Input --> 'test1 test2 test3', 1
Output --> test2 test3
Input --> 'test1 test2 test3, 2
Output --> test3
:param text
:param n:
:return: string after nth space
"""
return text.split(' ', n... | 99abae9dc2f24d1b26999d6e401b7fc56ec584ad | 42,579 |
def hovertext_eth_type(eth_type):
"""
Passed an eth_type (decimal, not enumerated) and
return it wrapped in extra text to convey context
"""
return "Ethernet Type: " + str(eth_type) + " (decimal)" | b99e79cb1adca0aab7daba5f59e3f4c8fda1dc68 | 42,581 |
def loadMushroomDataSet(path):
"""
return the dataset (list) of mushroom from path file
:param path: path of mushroom dataset
:return: mushroom dataset
"""
mushroomDataset = None
try :
mushroomDataset = [line.split() for line in open(path).readlines()]
except Exception as e:
... | 48119645cb8dc67f68f0fe56eb41040fe5e414b1 | 42,583 |
import os
import configparser
def read_config(section, key=None):
"""Read configure file.
Read configure file to get configure information.
:param: section: the section of ini file
:param: key in section of ini file
:return: configure information
"""
root_path = os.path.abspath(os.path.d... | 40b256321578a8174345d60aed79bfbfc46542ff | 42,584 |
def formatSearchQueryForCostco(query):
"""
The formatSearchQueryForCostco function formats the search string into a string that
can be sent as a url paramenter.
"""
queryStrings = query.split(' ')
formattedQuery = ""
for str in queryStrings:
formattedQuery += str
formattedQue... | 30818a20c304192fcba70e9161772744799e4b5b | 42,585 |
def get_bits(register, index, length=1):
"""
Get selected bit(s) from register while masking out the rest.
Returns as boolean if length==1
:param register: Register value
:type register: int
:param index: Start index (from right)
:type index: int
:param length: Number of bits (default 1... | a407074b60cb7598341ab335137f595cc9e811e4 | 42,587 |
def get_last_chunk(buffer, info):
"""A sampler function to extract only the last chunk of the memory.
"""
i_trans = info["num_records"]
# Get the last chunk, reshaped (mix the first two dimensions)
chunk = {}
for key in buffer:
chunk[key] = buffer[key][:,i_trans-info["num_steps"]-1:i_tr... | 987f1695191c7c9826e867c8c88aff6aa46f72c0 | 42,589 |
def _fix_url(url: str) -> str:
""" Add 'https://' to the start of a URL if necessary """
corrected_url = url if url.startswith("http") else "https://" + url
return corrected_url | ad26693c9cf2958e31155f6666e5bffad9c13628 | 42,590 |
import calendar
def first_day(year, month, bday=True):
"""
Return first day of month. Default to business days
"""
weekday, days_in_month = calendar.monthrange(year, month)
if not bday:
return 1
if weekday <= 4:
return 1
else:
return 7-weekday+1 | f68ba78fdfed08c2bd25165932a857a51de353c4 | 42,591 |
def wiki_title(name):
"""Like title(), except it never lowercases a letter."""
return ''.join(min(x,y) for x,y in zip(name, name.title())) | 073e2466bc21c8bd838561a5a798357386fec1f8 | 42,592 |
def extract_preference(prefer):
"""Extracts the parameters from a Prefer header's value
>>> extract_preferences('return=representation;include="http://www.w3.org/ns/ldp#PreferMinimalContainer http://www.w3.org/ns/oa#PreferContainedIRIs"')
{"return": "representation", "include": ["http://www.w3.org/ns/ldp#Pr... | 21e226ca89e76cb5b508f6ac60d24c4caa4d051b | 42,594 |
def put_in_bucket(d, l, value):
"""
If this helper function is called on every gene in our analysis, it will group all
genes with the same z-score into the same list. Each of those lists of same-z-score
genes is stored in l.
Args:
d: Dict, in the context of this file,... | 475a6edf846bc56f9b5ecc15a6c742f1a6ed377c | 42,595 |
def existed(fileobj):
"""
Returns a boolean indicating whether a file opened by openReadWrite existed
in the filesystem before it was opened.
"""
return 'r' in getattr(fileobj, "mode", '') | 620e7271c9d6abc7851f0ded16413b02e73b82b6 | 42,596 |
def extractDEPDataFromSoup( soup ):
"""
Takes in data structure from BeautifulSoup and parses for DEP Boiler Data.
We assume that the soup has been prescreened to ensure that data exist.
"""
tables = soup.find_all( "table" )
#get premise address, boro name, BIN, block #, and lot #
#This p... | 321b5b8dc00a4ac9773ba73ac171845f51ff4917 | 42,597 |
def choose_attribute(data, attributes, class_attr, fitness, method):
"""
Cycles through all the attributes and returns the attribute with the
highest information gain (or lowest entropy).
"""
best = (-1e999999, None)
for attr in attributes:
if attr == class_attr:
continue
... | b99a9fe29accc199314ac9f9852f911b9e28eeb5 | 42,598 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.