content stringlengths 39 14.9k | sha1 stringlengths 40 40 | id int64 0 710k |
|---|---|---|
def S_id(v):
"""Fingerprints a potential value to a string identifier."""
return 'S{:07d}'.format(int(round(-v * 1e5))) | c25e13843d2c7654acaad9ab30a2401f448e76f9 | 93,333 |
import hmac
import hashlib
def calculate_answer(nonce, password_hash):
"""
Calculate Answer on Server
-> Answer = HMAC(nonce, password_hash, sha256)
:param nonce:
:param password:
:return: answer
"""
answer = hmac.new(key=password_hash.encode(), msg=nonce.encode(), digestmod=hashlib... | b056360c1d6bb18258d728f488f451af73360fc6 | 93,335 |
def get_nodes_from_xpath(xpath, nodes):
"""If the selector is longer than 0 chars, then return the children
of nodes that match xpath. Otherwise, return all the nodes.
:param str xpath: The xpath to match.
:param etree nodes: LXML etree object of nodes to search.
:return list: The matched nodes, as... | 027db6fcd97299cf594043d30f8ce24000175d69 | 93,338 |
def gtk_menu_get_item_by_label(menu, label):
"""
Retrieve a menu item from a menu by it's label. If more than one items share
the same label, only the first is returned.
:param menu: The menu to search for the item in.
:type menu: :py:class:`Gtk.Menu`
:param str label: The label to search for in *menu*.
:return... | 753767656c0ca35a48fbb6a255bebc03616cdf60 | 93,339 |
import re
def extract_id(url):
"""Extract the tournament id of the tournament from its name or URL."""
match = re.search(r'(\w+)?\.?challonge.com/([^/]+)', url)
if match is None or match.group(2) is None:
raise ValueError(f'Invalid Challonge URL: {url}')
subdomain, tourney = match.groups()
... | c16f28fc114b5439800713e02a06243cbd3b67d8 | 93,340 |
def degrees_to_angle(value):
"""1 degree = 60000 angles"""
return int(round(value * 60000)) | 762da68859b790a679363737ea98c859f9bd1bd6 | 93,344 |
def read_list(file_path: str):
"""Reads in a \n separated file of things into a list.
Args:
file_path: Path to file.
Returns: List
"""
with open(file_path, 'r') as fh:
return [s.strip() for s in fh.readlines()] | eeacd59d6aca9a7736a52668a56c00aaa2fcb1d2 | 93,346 |
def mouv(m_):
"""
Converts SINGLE movement from human comprehensive to boolean and str
Parameters
----------
m_ : str
The movement <F B L R U D> [' 2]
Returns
-------
f : str
The face to move <F B L R U D>
cw : boolean
True = rotates clockwise
r180 : boolean
True = rotates twice
"""
# Creating ret... | 4978cb5b1641e773674d2dab7a63797a1818be40 | 93,348 |
def seconds_to_minutes(seconds):
"""
Convert seconds to minutes and seconds.
Parameters:
-----------
seconds : float
Returns:
--------
(float, float)
Minutes and seconds left as a tuple.
"""
minutes = seconds // 60
seconds = seconds % 60
return minutes, seconds | 98d6b6508ebdb7383b268ee381fc455e5864ace7 | 93,351 |
import torch
def abs(input, *args, **kwargs):
"""
Computes the absolute value of each element in ``input``.
Examples::
>>> import torch
>>> import treetensor.torch as ttorch
>>> ttorch.abs(ttorch.tensor([12, 0, -3]))
tensor([12, 0, 3])
>>> ttorch.abs(ttorch.ten... | 6a8be70c27951af7af6d5d99ccd6af0817fffd59 | 93,354 |
from pathlib import Path
def check_file_exist(file_path: Path) -> bool:
""" checks if the file behind the path exists """
return Path(file_path).is_file() | ca132fd51cf5a4f53d0efde27daede02b3ce95fa | 93,357 |
def _le_to_uint(val):
"""Returns the unsigned integer represented by the given byte array in little-endian format.
Args:
val: Byte array in little-endian format that represents an unsigned integer.
Returns:
The unsigned integer represented by the byte array ``val``.
"""
return int.from... | 63672a183492d823c02a547d500b8d426dc2b5b1 | 93,358 |
def xor(s1, s2):
"""
Exclusive-Or of two byte arrays
Args:
s1 (bytes): first set of bytes
s2 (bytes): second set of bytes
Returns:
(bytes) s1 ^ s2
Raises:
ValueError if s1 and s2 lengths don't match
"""
if len(s1) != len(s2):
raise ValueError('Input n... | dd07456e4db3af60c06df09ddb88a5a9db587ef6 | 93,360 |
def replace(arr, mask, val):
"""Replace values in mask with val; returns a copy of the array.
Parameters
----------
arr: ndarray
array of values to replace
mask: ndarray
boolean mask of values to replace
val: float
value replacing the elements on the mask
Returns
... | 60d0fd7d540abe6c44cea8964e8acd2770e0b722 | 93,363 |
def standard_deviation(x):
"""
calculates the standard deviation. Does not correct for bias
inputs
------
x: list of all floats/integers
returns:
float - standard deviation
"""
for elem in x:
if isinstance(elem, int) != True and isinstance(elem, float) != True:
... | 364ff843eb1b915e23c7cea66e4bb7e6f5a85467 | 93,364 |
def _unescape_specification(specification):
# type: (str) -> str
"""
Unescapes the interface string: replaces '%2F' by slashes '/'
:param specification: Specification name
:return: The unescaped name
"""
return specification.replace("%2F", "/") | fee7492fedde134af72d3259a016b752f70f1053 | 93,365 |
import re
def get_params(line):
"""
Gets the parameters from a line.
@ In, line, string, The line to parse
@ Out, (name,params), (string,string or list), The name of the parameter
and either a single parameter or a list of parameters.
"""
start_match = re.search("\[\./([a-zA-Z_]+)\]",line)
i... | c022cb28e9d77b1021fefaa4cc24f293e4b8bba2 | 93,367 |
def open_text_file(file_path, mode, encoding):
"""Open text file with encoding."""
try: # Python 3.5+
fhandle = open(file_path, mode + 't', encoding=encoding)
except TypeError: # pragma: no cover
# Python 2
fhandle = open(file_path, mode + 'b') # pylint: disable=unspecified-encodi... | 0ca433917fd5bf66a23fa331f48ddb57a3792342 | 93,369 |
def _fileOpen(fileModel, file):
"""
Open a file using the local file path if possible, since that will be more
efficient than opening it through some assetstores.
:param fileModel: the Girder file model instance.
:param file: file document.
:return: A file-like object containing the bytes of th... | d33704d8ff5c179017efac617e21b0b83346ddf4 | 93,374 |
import hashlib
def GetChecksumsFromFile(filename, hash_fns=None):
"""Computes MD5 and/or other checksums of a file.
Args:
filename: Name of the file.
hash_fns: Mapping of hash functions.
Default is {'md5': hashlib.md5}
Returns:
Mapping of hash names to hexdigest strings.
{ <hashn... | bc74a9e708ae14ca0c15594d7623bd20d95b0fd0 | 93,380 |
def responsePeaks(peaks, sensor, energyScale):
""" Augment the peak list based on the sensor response
Args:
peaks: List of found peaks.
sensor: Sensor model used for responding the peaks.
energyScale: Energy scale.
Returns:
List of responsed peaks.
"""
for i in ran... | f1ca639f03f2e318f842f5191ce42e040d83aac3 | 93,381 |
def lzip(*args):
"""
zip function that returns a list.
"""
return list(zip(*args)) | b69558ce0c87fe932774a38e096185135dc00f1a | 93,383 |
from typing import Tuple
def options_help_message(options: Tuple[str, ...], message: str) -> str:
"""Help message for groups option
:param Tuple[str, ...] options: List of options
:param str message: Help message
:return: Formatted options help message
"""
if options == [''] or options is No... | e5b5ae8e97f2a65974a6418eef6051d09bf92285 | 93,385 |
import time
def get_season(date):
"""
Get Season based on from_date
:param date: date
:return: season -> ex: 2016 for 2016-2017 season
"""
year = date[:4]
date = time.strptime(date, "%Y-%m-%d")
if date > time.strptime('-'.join([year, '01-01']), "%Y-%m-%d"):
if date < time.st... | b0152c389ebec7e576662632e02ce98b29b58e5b | 93,386 |
def highlight_max(s):
"""
highlight the maximum in a Pandas dataframe Series yellow.
"""
is_max = s == s.max()
return ["background-color: yellow" if v else "" for v in is_max] | af0efb38f83511c8368fb174dd400a4d93a9d148 | 93,394 |
def get_column_names(max_element_size, num_extra_columns):
"""Generate a list of column names used for Pandas to parse the data
Args:
max_element_size(int, required):
the maximum element size in the mesh elements (e.g. if the mesh only contains E3T elements then
the max_element_... | 2a3e730f00b1c88018552a13dc484efbb442c06a | 93,395 |
def build_atom_aliases(body_atoms):
""" Name each atom in the body with "aliases" and return the alias list
Args:
body_atoms:
the list of atoms of the rule body
Return:
body_atom_alias_list:
the list of aliases of the body atoms
"""
bo... | 793fa593b4f739a532a03b79ac721e2109d573e1 | 93,397 |
def get_exclude_seg_ids(exclude_grp, all_segs):
"""
get the segments to exclude
:param exclude_grp: [dict] dictionary representing the exclude group from
the exclude yml file
:param all_segs: [array] all of the segments. this is needed if we are doing
a reverse exclusion
:return: [list like]... | 2a311acd516ee35151660395b5d64cce95252e84 | 93,405 |
import re
def alias_tpl(data):
"""Generates Mantle alias
Output:
@"postTime": @"post_time",
"""
name = data['original_name']
candidates = re.findall(r'(_\w)', name)
if not candidates:
new_name = data['name']
else:
new_name = re.sub(r'_(\w)', lambda x: x.group(1).upp... | 13e42ecffb27018e87acfd1919bb812603c50f4c | 93,416 |
def resize_quota_delta(context, new_flavor, old_flavor, sense, compare):
"""Calculate any quota adjustment required at a particular point
in the resize cycle.
:param context: the request context
:param new_flavor: the target instance type
:param old_flavor: the original instance type
:param sen... | 25d65a5e60ab6665674dfb47ca2c573861432fc1 | 93,419 |
import random
def generate_key(word_list: list, words: int):
"""
(method) generate_key
---------------------
Generates a key.
---
Parameters
```
word_list : list
The word list.
words : int
The number of words to include in the key.
```
"""
return " ".j... | ba918cd9dfb4ee73442283371c30c1cd7debfa0f | 93,420 |
import yaml
def load_yaml_config(filename):
"""Read the YAML configuration file into a dictionary.
Arguments:
filename {string} -- The location of the YAML configuration file.]
Returns:
Dictionary -- The contents of the configuration file. An empty
dictionary is returned on error.
"""
wit... | e0d8c6c32919cf5c226bdf09eccea78bfa911b14 | 93,422 |
from typing import Optional
import re
def parse_host(link: str) -> Optional[str]:
"""
Parse the host name in a given link
Args:
link: Link to a website
Returns:
str: the host name
"""
pattern = re.compile("^http[s]?://([a-z0-9]*\.[a-z]*)[/]?[a-zA-z0-9]*?$")
matches = patte... | c3cea8e01565fb8540b6f2ae54d87bbf6fa16f01 | 93,426 |
import re
def normalize(string, force_underscore=False):
"""Replaces invalid characters with an underscore character
string.normalize will add an "_" character in front of the returned string
if the input starts with an intiger
Args:
string(str): A string to normalize
force_underscor... | 582d0101da2af83c37ffec48bbd51e06503b8586 | 93,428 |
def first_sample_of_frame(frame,
frame_shift_in_samples,
window_size_in_samples):
"""
Returns the sample-index of the first sample of the frame with index
'frame'. Caution: this may be negative; we treat out-of-range samples
as zero.
Analogous to ... | 8d7063a8491e294debd6ba8cdfdf090f7bb08942 | 93,430 |
def is_analytics_type(odk_type):
"""Test if an odk type is suitable for tracking in analytics.
Args:
odk_type (str): The type to test
Returns:
Return true if and only if odk_type is good for analytics
"""
bad_types = (
"type",
"calculate",
"hidden",
... | df2a6f8e46575f01c32b0af600ed3a5af07197d1 | 93,431 |
def alc_calc_scans_n(inpt_mos_data_dict, inpt_selected_samples):
"""Get the total number of scans that will be run (i.e., represented in
both the Notebook data dict and in list[selected samples]). For ALC/
mosaic datasets/Notebooks.
Parameters
----------
inpt_mos_data_dict : dict
... | e35d47d2688c881851cc979e2d8336b8a4ccd685 | 93,435 |
import math
def ComputeDistAtom(dAtom1, dAtom2):
"""Compute the distance between two atoms.
Input: dAtom1, dAtom2 which are dico corresponding to atom 1 and atom 2 respectively.
For instance dAtom = dPDB[resnumber][atom].
Output: distance (float)
"""
coord1 = [dAtom1["x"], dAtom1["y"],... | 067338daab5ffc1c1c7f496f73fef1796d4b5884 | 93,436 |
def interpolation_linear(x, x1, x2, y1, y2):
"""
Linear interpolation
returns (y2 - y1) / (x2 - x1) * (x - x1) + y1
"""
m = (y2 - y1) / (x2 - x1)
t = (x - x1)
return m * t + y1 | c73fcf8f928ade078a18d0e171eaf94fb27db9a0 | 93,438 |
def getNeumes(seq, counter):
""" Given a list of MEI note elements, return a string of the names of the neumes seperated by underscores.
"""
neumes = str(seq[0].parent.parent.getAttribute('name').value)
for k in range(1, counter):
if seq[k].parent.parent.id != seq[k-1].parent.parent.id:
... | f511511c89c4afba556d9ff8b38c8cfa3de1401f | 93,443 |
def fetch_parameter(kwargs, param):
"""Fetch a parameter from a keyword-argument dict
Specifically for use in enforcing "stricter" typing for functions or methods that
use **kwargs to allow for different sets of arguments.
"""
try:
return kwargs.pop(param)
except KeyError:
raise... | 575f1b68119fc2fd91b4180eb95ca0fb4ddc51bf | 93,453 |
import _struct
def from_native_int8( raw_bytes, offset ):
""" Reads a native 8-bit signed integer from an array of bytes. """
return _struct.unpack_from( "=b", raw_bytes, offset )[ 0 ], offset + 1 | 01e30fc8f9ebac92f61e8715a1388660ff56ba64 | 93,455 |
def get_datastore_state(target, device):
"""Apply datastore rules according to device and desired datastore.
- If no target is passed in and device has candidate, choose candidate.
- If candidate is chosen, allow commit.
- If candidate is chosen and writable-running exists, allow lock on running
... | e4956d5283f525c9b282dec1784622d5f30a4816 | 93,457 |
def filter_df(summary_df, country_list, feat_list, year_range):
"""
Helper func to filter summary_df to countries, columns (feat_list), and list of years.
Keep "country", "happiness_score", "year" for downstream tasks
"""
year_list = list(range(min(year_range), max(year_range) + 1))
if country_... | 8535a5e8374423a7983a4c3d970dedcf9af5d1d3 | 93,461 |
def balanced_parentheses(string: str) -> bool:
"""
Check if parentheses in a string are balanced, ignoring any non-parenthesis
characters. E.g. true for "(x())yz", false for ")(" or "(".
"""
bal = 0
for c in string:
if c == "(":
bal += 1
elif c == ")":
if ... | fcb2ff7379d1c63cc7922d4c139ff0513261cc8c | 93,463 |
import importlib
def import_class(modname, classname):
"""function equivalent to from [mod] import [class]"""
mod = importlib.import_module(modname)
return getattr(mod, classname) | b6443dc68172ebdcf7a99d81574f366b4166135f | 93,464 |
def hpa_to_mmhg(hpa):
"""
Convert hectopascal to millimeter of mercury [0 °C]
"""
return int(hpa / 1.3332239) | 094958d800583024364375206de518cf976b8a87 | 93,465 |
import struct
def encode_time(t):
"""
Converts date to specific codification of time used in ZKTeco
get/set time procedures.
:param t: Datetime object, with the date.
:return: Bytearray, with the time stored in little endian format.
"""
return bytearray(struct.pack('<I',
... | b6e6d88b1324e015e08649d5cdd4951585012756 | 93,468 |
import typing
def id_class_name(value: typing.Any) -> str:
"""Provide class name for test identifier."""
return str(value.__class__.__name__) | 9d7fae15e07dd994f865baf67d753b43031efd31 | 93,471 |
from typing import List
def get_lines(ls, params) -> List[str]:
"""Get all text lines in the current document."""
text_doc = ls.workspace.get_document(params.text_document.uri)
source = text_doc.source
return source.splitlines() | d0c48f4d2e7fd56fa00b23cd4409d70bdc9dd163 | 93,472 |
from typing import Union
from typing import Iterable
from typing import Set
import pkg_resources
def _safe_parse_requirements(
requirements: Union[str, Iterable[str]]
) -> Set[pkg_resources.Requirement]:
"""Safely parse a requirement or set of requirements. This effectively replaces
pkg_resources.parse_re... | 4366d6b88ceb3d2c7779c502afc08304015c928d | 93,473 |
def count(iterable):
"""Simply returns the number of entries (left) in the given iterable."""
return sum(1 for _ in iterable) | 418f2e1c954fd9230fd822a1a5d8ec605b6e228d | 93,478 |
def db_list_tables(con):
"""Return all table names"""
cursor = con.cursor()
cursor.execute("select name from sqlite_master where type='table';")
return [x[0] for x in cursor.fetchall()] | 4f83b111e6eb6d820d51bda9ee3fe2aeafc3ebee | 93,480 |
def next_perm(v):
"""
Generates next permutation with a given amount of set bits,
given the previous lexicographical value.
Taken from http://graphics.stanford.edu/~seander/bithacks.html
"""
t = (v | ( v - 1)) + 1
w = t | ((((t & -t) / (v & -v)) >> 1) - 1)
return w | 7b4098980a3c211153586a3b7e7127486b7f3ea0 | 93,488 |
import torch
def quad_kl_div(pi, gamma, ref):
"""Compute the quadratic entropy (KL^otimes(pi otimes gamma | ref))
with full plans
Parameters
----------
pi: first input, torch.Tensor of size [Batch, size_X, size_Y]
gamma: second input torch.Tensor of size [Batch, size_X, size_Y]
ref: Ref... | 2dc303ee217ee034c12c631cf90a3432bcd37827 | 93,490 |
def rgb_intensity(rgb):
"""Convert an RGB color to its intensity"""
return rgb[0] * 0.299 + rgb[1] * 0.587 + rgb[2] * 0.114 | 65bd42cece4a66d0e9fa6419b67db887b1130ab3 | 93,491 |
def chunked(data, chunksize):
"""
Returns a list of chunks containing at most ``chunksize`` elements of data.
"""
if chunksize < 1:
raise ValueError("Chunksize must be at least 1!")
if int(chunksize) != chunksize:
raise ValueError("Chunksize needs to be an integer")
res = []
... | 4037be6d94b26d46a54ece9d733e7e9a325bd8fe | 93,496 |
def get_employee_vacation_days(employee, month):
"""Calls the vacation days for the given employee and month."""
return month.get_employee_vacation_days(employee) | ddf611cfee3f1a89b32d153220ebbf93d16b64e6 | 93,506 |
def dias_para_segundos(dias, horas, minutos, segundos):
""" Recebe uma data em dias com horas, minutos e segundos, e retorna
a data em segundos"""
dias_para_segundos = dias*86400
horas_para_segundos = horas*3600
minutos_para_segundos = minutos*60
segundos_para_segundos = segundos*1
soma = di... | ab3bd996343e37863e9b064dab86100ed47b14de | 93,510 |
def labels_to_string(labels):
"""
Concatenates a list of labels to a single string to match the labelselector pattern
"""
return (
",".join(["%s=%s" % (str(k), str(v)) for k, v in labels.items()])
if labels
else "*"
) | 3607e7a84b912d7a9d8085fea36d17f884f393af | 93,514 |
from datetime import datetime
import click
import json
def write_json_file(file_name: str, results: list) -> str:
"""Write data to json file"""
now = datetime.now()
timestamp = f"_{now.month}-{now.day}-{now.year}_{now.hour}-{now.minute}.json"
file_path = file_name + timestamp
click.secho(f"[*] ... | 4cb127c0b9bb916ab5f32c859fd03cc0570eb561 | 93,519 |
def get_evaluation_args(eval_py: str, train_logdir_local: str,
dataset_dir_local: str, eval_logdir: str, tfdl_config):
"""Generate the array of arguments needed to run the eval script.
Args:
eval_py: The URI of the eval script.
train_logdir_local: The directory in-whic... | 3f1f1da5e343d7a423990a1a19a317ed6f808686 | 93,521 |
def df_to_string_list(df):
"""
Convert the input df into a list of strings, suitable for using as popups in a map.
This is a utility function.
"""
# print "Converting df with size %s to string list" % df.shape[0]
array_list = df.to_dict(orient='records')
return [str(line) for line in array_l... | 2e6d125755001847364b9ee332ddc3a0e71d9d0a | 93,522 |
def _short_repr(value):
"""
Return a shortened ``repr`` output of value for use in ``__repr__`` methods.
"""
if isinstance(value, str):
chars = len(value)
threshold = 30
if chars > threshold:
return "{0!r}...+{1}".format(value[:threshold], chars-threshold)
return... | 22e827fe9415b7d5000c3b5337cae9e6f1d15635 | 93,524 |
def list_same_len(*lists):
"""
confirm all lists have the same length
"""
n = len(lists[0])
return all(len(x) == n for x in lists) | 808d93118890625a954acb630762870ad137a307 | 93,531 |
def _nominal_metric(v1, v2, **_kwargs):
"""Metric for nominal data."""
return v1 != v2 | a10d80868ecac0023edf0afbd5d23ebca7b2e63b | 93,538 |
def survivor(probabilities, t):
"""Survivor function S"""
s = 1 - probabilities[0]
for x in range(1, t + 1):
s = s - probabilities[x]
return s | af5ccc4173c595f8dce347f7a9afeaf2b56b1a34 | 93,540 |
def get_work_directory(config):
"""Return the aiida work directory to use."""
if config.getoption("lammps_workdir") is not None:
return config.getoption("lammps_workdir")
return None | 4ec26399efb1cabe31f1ff6ceccaa36013abf480 | 93,544 |
def generate_bond_indices(natoms):
"""
Finds the array of bond indices of an interatomic distance matrix, in row wise order:
[[0,1], [0,2], [1,2], [0,3], [1,3], [2,3], ..., [0, natoms], [1, natoms], ...,[natoms-1, natoms]]
Parameters
----------
natoms: int
The number of atoms
R... | 6acf86aeefe33122c95f88db8a960012aa4198b4 | 93,545 |
def normalize_file_name(fn):
"""
Normalize a file name string by replacing '\' with '/'. This is useful for writing
file names to control files.
:param fn: file name
:returns: normalized file name
.. versionadded:: 9.2
"""
return fn.replace('\\', '/') | 71537295fda78fd8110e5cad187ffae4fb40b3da | 93,546 |
def row_to_edge(row):
"""
Given an election result row or poll data row, returns the Democratic edge
in that state.
"""
return float(row["Dem"]) - float(row["Rep"]) | fab57ddd3d0207ef558bfc5f2ad6e3fbddd11b24 | 93,548 |
import unicodedata
def strip_string(string):
"""Cleans a string based on a whitelist of printable unicode categories
You can find a full list of categories here:
http://www.fileformat.info/info/unicode/category/index.htm
"""
letters = ("LC", "Ll", "Lm", "Lo", "Lt", "Lu")
numbers = ("Nd", "Nl", "No")... | d6aa5f61be5a468d3fc9cf52e44e5325f2663167 | 93,550 |
import re
def has_repeat_char_with_one_between(chars):
"""
It contains at least one letter which repeats with exactly one letter
between them, like xyx, abcdefeghi (efe), or even aaa.
"""
if re.search(r'(\w)[^\1]\1', chars):
return True
return False | f0f37bcc7d4ab5b102e1f9f0ccfd3057a29a8f25 | 93,553 |
import re
def _validate_pattern(pattern):
"""Check that regex pattern conforms to type and format requirements."""
if not isinstance(pattern, str):
raise TypeError("Pattern must be a string.")
if pattern.count("(#") != 1:
raise ValueError("Pattern must contain exactly one anchor group.")... | 9222423d7fe9f723c33ce76aa1a88b39235b78de | 93,556 |
import re
def normalize_response_key(key: str) -> str:
"""
Convert camel case `ParamA` to snake case `param_a`
"""
split = re.findall(r'[A-Z](?:[a-z]+|[A-Z]*(?=[A-Z]|$))', key)
if split:
return '_'.join([val.lower() for val in split])
return key.lower() | b9df00dc7c39aca339c4d547d88bf102b4e765f1 | 93,557 |
from typing import Tuple
from typing import List
from typing import Dict
import csv
def parse_csv(csvfile: str) -> Tuple[List[str], List[str], List[str]]:
"""Open and parse csv.
Args:
csvfile: path to csvfile
Returns:
a tuple of lists for images, labels, and notes
"""
with open(c... | 228edaffe9e1096866ef71a6f9b010b073ad2306 | 93,559 |
from typing import Any
import torch
def default_label_extractor(x: Any) -> torch.Tensor:
"""Default callable for getting label from batch data."""
out: torch.Tensor = x["label"] if isinstance(x, dict) else x[1]
return out | 5c65cf61651e01f15a93b650deb76965a2577d11 | 93,560 |
def escape_quotes(string):
"""Make the string accepatble to command line by esacping any quotes
>>> escape_quotes('word"here') == r'word\\"here'
True
"""
return string.replace('"', r'\"').replace("'", r"\'") | 1b6d6a4cdfd5fd2f6b5a69301b1b4829ec643e73 | 93,561 |
def normalizeRhythms(rhy):
"""Return normalized rhythms
Parameters: rhy: -1xn array- Rhythms energy
Returns: rhy_n: -1xn array- Normalized Rhythms"""
rhy_n = (rhy - min(rhy))/max(rhy)*100
return(rhy_n) | da4580792cfacf1cbd50178064c6178cefa30071 | 93,563 |
import re
def remove_urls(text):
"""
Removes twitter short URLS from a string and returns the result.
URLs are matched by the substring 'https://t.co'. If the string
contains no matching URLs, the returned string is identical to
the input string.
"""
text = re.sub(r"https://t.co\S+", "", t... | 84229e78c864eae03d26101469852c62d9a0fe89 | 93,565 |
from typing import List
from typing import Tuple
from typing import Dict
from typing import Counter
def create_cardinality_dict_for_doc_sentences(
list_of_tuples: List[Tuple[str]],
) -> Dict[Tuple[str], int]:
"""Creates a dictionary with the elements of the input list of tuples
as keys and their cardinali... | 8f7f9ea35727e66e6f38dc44378bef588fb4a93b | 93,566 |
def extract_data(raw_data, data_list, price_dataset, region):
"""
Extract data on data_list from raw_data.
Return data will be a dictionary, including three key-value pairs:
(1) 'workdays'
a DataController, the workdays data of the trading region.
(2) 'price'
a Dataset, the price da... | 77fe452e23d2d0b7f0d228ef4a5311c194a89ae8 | 93,568 |
import math
def get_half(n: int) -> int:
"""Gets the half point of an integer
Parameters
----------
n : int
The number to divide in half.
Returns
-------
:rtype: int
"""
return math.ceil(n / 2) | af1e6d0b9712431c2d909747ff919f4e49dd443a | 93,569 |
import calendar
def days_in_month(date):
"""Number of days in the month `date` belongs to."""
return calendar.monthrange(date.year, date.month)[1] | 49aa1366b6be5ef2ec4df8a3bf81d358e2d8817e | 93,570 |
def f(X):
"""Given a scalar X, return some value (a real number)."""
Y = (X - 1.5)**2 + 0.5
print("X = {}, Y = {}".format(X, Y)) # for tracing
return Y | e76e90433f1528a2028df52113dc59835946d582 | 93,573 |
def get_start_button_payload(poll, action):
"""Compile the /start action payload for a certain action."""
# Compress the uuid a little and remove the 4 hypens
uuid = str(poll.uuid).replace("-", "")
return f"{uuid}-{action.value}" | 9e6e9548afa4411d1db3e93153f145c87f7748e7 | 93,574 |
def date_format(date_str):
"""Formats date to yyyy-mm-dd. Returns date as string"""
# The day in row data is not supplied
day = '01'
split_date = date_str.split('/')
# When month is not supplied
if len(split_date) < 2:
month, year = '01', split_date[0]
else:
month, year = sp... | 7ea8b8dffd9d7e1aa126b95367daf10634635ec9 | 93,579 |
def commit_veto(request, response): # unused request arg pylint: disable=W0613
"""
Strict commit veto to use with the transaction manager.
Unlike the default commit veto supplied with the transaction manager,
this will veto all commits for HTTP status codes other than 2xx unless
a commit is explici... | 4b53d855ea0a4a91498c62e89dbbff6f2ed16efd | 93,580 |
from typing import Any
from typing import List
from typing import Dict
def remove_dict_from_list(
value: Any, target_list: List[Dict[str, Any]], key_name: str
) -> List[Dict[str, Any]]:
"""Remove a dict in list.
:param value: value to search for and remove
:type value: Any
:param target_list: lis... | e9f580869fc1b6a275c0bde1f50a1fbded361316 | 93,583 |
from typing import Any
import json
def format_data(data: Any, indent: int = 4) -> str:
"""Format the data dictionary returned by any class of
the cmc-py modules.
Args:
data (Any): Data to be formatted.
indent (int, optional): Indentation of the data. Defaults to 4.
Returns:
s... | b8dd0d79fb0892405152ee9bc5fca934a8743f5d | 93,586 |
def calc_sc_carter(slr, ecc, x):
"""
Compute carter constant for the SC case (a = 0).
Parameters:
slr (float): semi-latus rectum [6, inf)
ecc (float): eccentricity [0, 1)
x (float): inclination value given by cos(theta_inc) (0, 1]
negative x -> retrograde
... | 0b1213c83494f806b67b60321bbd90e02d007c83 | 93,594 |
def asbool(s):
"""
Convert a string to its boolean value
"""
if s.lower() == 'true':
return True
elif s.lower() == 'false':
return False
elif s.isdigit():
return bool(int(s))
else:
raise ValueError('must be integer or boolean: %r' % s) | 1460377e516c16f076702ba3d55d4b1579f3fe22 | 93,596 |
def sqr(x):
"""Return the conjugate of x multiplied by x."""
return x.conjugate() * x | a3c5447145a0f7cb761f52c14998e16e739223a1 | 93,597 |
def tokenizer(sentence):
"""Split header text to tokens, add newline symbols"""
return " \n ".join(sentence.split("\n")).split(" ") | b64e29f0fcfa1c8cb21a101af57ac78337916d68 | 93,599 |
def fieldSorter(fieldname, forcedOrder=None):
"""Sort a field
A generic sorter which allows to define a field for sorting.
If forcedOrder is not None it will be used as the sort order.
"""
def handleSort(order):
if forcedOrder is not None:
order = forcedOrder
return {fi... | bccca4d32165b92d059e40dd8e68f87d0e3fd808 | 93,601 |
def get_specific_mouse_files(mouse_ids, files):
"""Return sub-list of `files` that contain an id in `mouse_ids`.
"""
return [s for s in files if any(xs in s for xs in mouse_ids)] | 5bc41df971e2c464d6cb632f661623b5ff4a9047 | 93,602 |
def _field_access_description(target, provider, field):
"""Returns a string denoting field access to a provider on a target.
This function is used to generate a pretty string that can be used in
assertion failure messages, of the form
`<//package:target>[ProviderInfo].some.field.path`.
Args:
... | 3e6fb2eae77a237d30f32a131da66632cc791cb3 | 93,604 |
import json
def parse_posted_message(m):
"""
From.
{"event":"posted","data":{"channel_display_name":"","channel_name":"xxx","channel_type":"D","mentions":"[\"to56ryq76frapk54a1sx1sqppr\"]","post":"{\"id\":\"xxx\",\"create_at\":xxx,\"update_at\":xxx,\"edit_at\":0,\"delete_at\":0,\"is_pinned\":false,\"user_... | deae2f7c23519466af11e87c1df37604f3932991 | 93,606 |
def topology_3_bonds_apart(covalent_bond_dict):
"""
Map atom connectivity EXACTLY 3 bonds apart.
See Amber20 manual Figure 14.1.
Parameters
----------
covalent_bond_dict : dict
Per residue covalent connectivity.
Returns
-------
dict
Per residue 3 bonds apart connec... | 3dacd28bd2a0510d5c9b6ed30bbbf88aa12a5e95 | 93,607 |
def create_pids2idxs(data_source):
"""Creates a mapping between pids and indexes of images for that pid.
Returns:
2D List with pids => idx
"""
pid2imgs = {}
for idx, (img, target, _) in enumerate(data_source.imgs):
if target not in pid2imgs:
pid2imgs[target] = [idx]
... | 3bad529a87dfaf62e8ebcd9373c413fc0bdc8ca3 | 93,608 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.