content stringlengths 39 14.9k | sha1 stringlengths 40 40 | id int64 0 710k |
|---|---|---|
def case_of(value: str) -> int:
"""Returns 1 for all uppercase, 0 for all lowercase, and -1 for
mixed case."""
if all(map(lambda x: x.isupper(), value)):
return 1
elif all(map(lambda x: x.islower(), value)):
return 0
return -1 | e0b56890ff73a9b59385e716be6ea3c41ab03bc6 | 36,151 |
def __filter_event_type__(trace_events, event_type):
"""
Looks for the events in the trace matching the event type
:param trace_events: Events found in the trace (filtered by family).
:param event_type: Event type to filter.
:return: Filtered trace
"""
filtered = []
for line in trace_ev... | 4a4b49272014ff2a2f552f3a4a381f859a886a5a | 36,152 |
from typing import Callable
def map(f: Callable, collection):
"""Transform each element of a collection.
Examples
--------
.. doctest::
>>> a = ['The', 'quick', 'brown', 'fox']
>>> hl.eval_expr(hl.map(lambda x: hl.len(x), a))
[3, 5, 5, 3]
Parameters
----------
f... | 677c8b5185e45126c85448020a6a914c0938f785 | 36,154 |
from functools import reduce
from operator import mul
def prod(iterable):
"""
Return the product of all numbers in an iterable.
"""
return reduce(mul, iterable) | d4ca281afd572aaae7da4bf13696ebc8d05be32f | 36,161 |
def get_project_from_manifest(manifest, pid):
"""
Returns the project entry from the manifest
:param manifest:
:param pid:
:return:
"""
if 'projects' not in manifest:
return None
for project in manifest['projects']:
if project['identifier'] == pid:
return proj... | 5f72faffeb14bc20568c2898ca3b9c65b2edb53f | 36,164 |
def all_properties(obj):
"""
Return a list of names of non-methods of 'obj'
"""
noncallables = []
for name in dir(obj):
if not hasattr(getattr(obj, name), '__call__'):
noncallables.append(name)
return noncallables | 58a86250e03e9cb4c9f6567eaf072173ff419e73 | 36,167 |
def power_level(serial: int, x: int, y: int) -> int:
"""Compute the power level of the fuel cell at x, y.
"""
rack_id = x + 10
p = rack_id * y + serial
p *= rack_id
p = (p // 100) % 10
return p - 5 | 316895b97f752867171ff4dd0463ea5395228b97 | 36,170 |
from pathlib import Path
def get_nprocs(modelpath):
"""Return the number of MPI processes specified in input.txt."""
return int(Path(modelpath, 'input.txt').read_text().split('\n')[21].split('#')[0]) | 82faad4d21e5a9acb7de123338e71b1123ad79cc | 36,172 |
import pathlib
def is_relative_to(path: pathlib.Path, base: pathlib.Path) -> bool:
"""Check whether `path` is contained inside `base`."""
try:
path.relative_to(base)
return True
except ValueError:
return False | 6a9bed0700d87d9c74ba8980f25f3de522fa5ca8 | 36,181 |
from functools import reduce
import operator
import collections
def strings_to_wordsets(strings, stop_words=None):
"""Build a dict of wordsets from a list of strings, with optional filter.
For each distinct word found in the list of strings, the wordset dict will
map that word to a set of the strings tha... | 407f604d6fe78e6aad10e972fcda63ebb42209f1 | 36,185 |
from typing import Union
import re
def _cast_valid_types(content: Union[str, int, bool]) -> Union[str, bool, int]:
"""
Cast an input that explicitly reads "true" or "false" (case-insensitive) as a boolean type and cast all strings
of only digits as an integer type. This function does nothing and returns t... | c06e3635c1f5d4ac6d33939db8d552d58803dda1 | 36,187 |
def more_like_this(_es, es_index, field, like_list, min_term_freq, max_query_terms):
"""Build and execute a more like this query on the like document
See https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-mlt-query.html
Returns
result (list): list of documents that match the ... | a48fcc6e44b9a25bafd7936122c5ecc91cfdb932 | 36,189 |
import re
def _getXMLText(fileobj):
"""Convenience function for reading the XML header data in a ShakeMap grid file.
:param fileobj:
File-like object representing an open ShakeMap grid file.
:returns:
All XML header text.
"""
tline = fileobj.readline()
datamatch = re.compile('grid_... | a44091de4543142a83a13b010de7f5a471a21df8 | 36,191 |
def map_l2dist_gaussianmech_renyiDP(sensitivity, scale, alpha):
"""map an L2 distance `sensitivity` through the gaussian mechanism with parameter `scale` to (alpha, epsilon)-RDP
Proposition 7 and Corollary 3: https://arxiv.org/pdf/1702.07476.pdf#subsection.6.3
:param sensitivity: maximum L2 distance pertur... | 98b5454fdc299b345a73ad1473ff56e249a29397 | 36,193 |
import json
def to_dict(data):
"""Convert json to dict data, if input is not json return None"""
if isinstance(data, dict):
return data
try:
value = json.loads(data)
if not isinstance(value, dict):
raise
return value
except:
return None | 9419173d027b998cebe949e7a43424834fd50d7c | 36,194 |
from typing import Mapping
from typing import Any
def _get_param_or_die(input_params: Mapping[str, Any], param: str) -> Any:
"""Returns value of param. Dies with user-formatted message if not defined.
Args:
input_params: Mapping from input parameter names to values.
param: Name of the param to get the va... | f06bfb5ae5393cf0e41a33db1c03797e940fcdef | 36,197 |
def fieldmap_minmax(fieldmap, variable):
"""Data limits for a given varible across all zones in a fieldmap"""
limits = None
for z in fieldmap.zones:
if limits is None:
limits = z.values(variable).minmax()
else:
low, high = z.values(variable).minmax()
limit... | 662da76d19fd73c8e93b0cbaf80a04d8f14f3135 | 36,200 |
def reverse(sentence):
""" split original sentence into a list, then append elements of the old list to the new list starting from last to first. then join the list back toghether. """
original = sentence.split()
reverse = []
count = len(original) - 1
while count >= 0:
reverse.append(orig... | 258bb97834a177a90dbfcf436d3228bb7f9a7237 | 36,202 |
from typing import Dict
import torch
def create_ner_conditional_masks(id2label: Dict[int, str]) -> torch.Tensor:
"""Create a NER-conditional mask matrix which implies the relations between
before-tag and after-tag.
According to the rule of BIO-naming system, it is impossible that `I-Dog` cannot be
ap... | 0cda8db465b039349eff1022a8cd2cc071f21295 | 36,203 |
def acquire_image_url(soup):
"""
Take a BeautifulSoup content of a book page.
Return the url of the image of the book.
"""
partial_url = soup.img['src'][5:]
image_url = f"http://books.toscrape.com{partial_url}"
return image_url | c2c14823f3fa1dbe30838dbab2513653d7c0fa3c | 36,204 |
def encode_varint_1(num):
""" Encode an integer to a varint presentation. See
https://developers.google.com/protocol-buffers/docs/encoding?csw=1#varints
on how those can be produced.
Arguments:
num (int): Value to encode
Returns:
bytearray: Encoded presentation of i... | 3a5883a352a85c3c472889b8b1e347ba41df0615 | 36,205 |
def to_degrees(dir, value):
"""
convert the GPS coordinates stored in the EXIF to degress in float format
:param value: tuples of DMS
:param dir: direction E/N/W/S
"""
d = float(value[0][0]) / float(value[0][1])
m = float(value[1][0]) / float(value[1][1])
s = float(value[2][0]) / float(... | 3cb60e15049bf3c538d8dc46fae92b123e4cafd5 | 36,210 |
import math
def distance(x1, y1, x2, y2):
"""Get euclidean distance between two points"""
return math.sqrt(math.pow(abs(x1-x2), 2) + math.pow(abs(y1-y2), 2)) | 722600df2cba61443a0663e4076c58f5522ea7b1 | 36,212 |
def unknown_pairs_present(model):
"""
Test if PDB file contains unknown type pairs
Parameters:
model (obj): model object
Returns:
(bool): True if PDB file contains unknown type pairs
"""
grm = model.get_restraints_manager()
sites_cart = model.get_sites_cart()
site_labels = model.get_xray_struc... | f826a41f2e62436b68a3ed9ab15d15b5a8335252 | 36,215 |
def _quote_tag_if_needed(tag: str) -> str:
"""Quotes tags just like timewarrior would quote them.
Args:
tag: The tag that should be quoted.
Returns:
The quoted tag.
"""
if tag[0] == '"' or tag[0] == "'":
return tag
special_chars = [" ", '"', "+", "-", "/", "(", ")", "<... | bfcb2064dae08c758d9c75eac3abe371854ea62b | 36,219 |
def largest_prime_factor(input_num):
"""
Function returns the largest prime factor of an input.
REQ: input_num >= 0 and whole
:param input_num: {int} is original input number
:return: {int} the largest prime factor of the input or {NoneType} if input_num < 2
"""
# if input is less than 2,... | 507c36186f29ba96ec842dce0b3c7c76cca89d9e | 36,222 |
def get_fastqs_for_read_index(lane_to_fastqs, read_index):
"""Get a list of fastq urls for the given read index
Args:
lane_to_fastqs (Dict[Dict[str, str]]): dict of dict mapping each lane to a dict of read index to fastq url
read_index (str): the read_index to filter by, e.g. "read1", "read2", ... | 2f81d5f4457bb635b47ddcf85c8d8acca0eccbb2 | 36,227 |
from pathlib import Path
import torch
def load_pretrained(vae, path, load_predictor):
"""Load a previously trained model, and optionally ignore weights/bias for predictor"""
load_path = Path(path)
state = torch.load(load_path)
if "epoch" in state.keys():
print(f"Loading model from epoch {state... | 20ea5b631b56078732da4c3631e614e53d37ac19 | 36,228 |
def determine_best_contact(contacts):
"""
gibt Kontakt mit höchster übertragener Datenmenge aus übergebener Menge zurück
:param contacts: list / set / ...
:return: Contact
"""
current_best_data = 0
best_contact = None
for contact in contacts:
current_data = contact.get_data()
... | 5ce0ccb4c6489ca545983adf78cead03311aae03 | 36,229 |
def find_key(d: dict, key: str, default: None):
""" Search for the first occurence of the given key deeply in the dict.
When not found is returned the default value """
if key in d:
return d[key]
for k, v in d.items():
if isinstance(v, dict):
item = find_key(v, key, default)... | 8f3741a99da6eb3d7989089e460cb7a5eaa4554a | 36,231 |
def polygon_trans(p):
"""
:param p: polygon list with dict("lat": v1, "lng": v2) as elements
:return: polygon list with (v_lat, v_lng) as elements
"""
new_p = []
for point in p:
new_p.append((point["lat"], point["lng"]))
return new_p | 86000bc8f94a79060ad0321808d13fbc7296be6b | 36,232 |
def _buffer_if_necessary(shape):
"""Fix the basins shapes which are invalid.
Following the advice given here:
https://github.com/Toblerity/Shapely/issues/344
"""
if not shape.is_valid:
shape = shape.buffer(0.0)
assert shape.is_valid
return shape | f7646b8a909f9790f16e672e8de5b479402a5b5d | 36,235 |
def get_stats(data):
"""
Returns some statistics about the given data, i.e. the number of unique entities, relations and
their sum.
Args:
data (list): List of relation triples as tuples.
Returns:
tuple: #entities, #relations, #entities + #relations.
"""
entities = set()
relations = set()
for triple in d... | 6496db5be15b330de84345d862a66a16c0ebc969 | 36,236 |
def format_pylint_disables(error_names, tag=True):
"""
Format a list of error_names into a 'pylint: disable=' line.
"""
tag_str = "lint-amnesty, " if tag else ""
if error_names:
return u" # {tag}pylint: disable={disabled}".format(
disabled=", ".join(sorted(error_names)),
... | de7355f51fc20ba174f5f8db852c9254c016fa75 | 36,237 |
def is_jar_library(target):
"""Returns True if the target is an external jar library."""
return target.has_label('jars') | 020d389e3bc71723a21d948f43debaa274b0de39 | 36,245 |
def myfuncMean( TheListOfvalues ):
"""
This function computes and returns:
1.- The mean of a list holding any set of values.
2.- A message regarding whether the mean is or not a whole number.
To call this function do:
thevalues = [1,2,3,4,5]
meanval, me... | 1276f97d42161b5a4b8ddb882660ce97fdaae030 | 36,247 |
from pathlib import Path
def get_expect_file(sql_file: Path) -> Path:
"""
Returns the csv file with the expected results for a sql file.
"""
if (
str(sql_file) == ""
or sql_file.stem == ""
or sql_file.suffix == ""
or sql_file.suffix.lower() not in (".sql")
):
... | a110787038fe149a7282beb8830f620fe41ac23a | 36,250 |
def binaryFilesEqual(fn1, fn2):
"""True if two files are bytewise identical."""
with open(fn1, "rb") as f1, open(fn2, "rb") as f2:
for byte1, byte2 in zip(f1, f2):
if byte1 != byte2:
return False
return True | e1d71d0a8ed51eb85d4e3deae11f46730bd51d51 | 36,252 |
def score_char_overlap(term1: str, term2: str) -> int:
"""Count the number of overlapping character tokens in two strings.
:param term1: a term string
:type term1: str
:param term2: a term string
:type term2: str
:return: the number of overlapping ngrams
:rtype: int
"""
num_char_mat... | 8bda41b2babffcc55b27831bced476b6d9a77eb5 | 36,253 |
def clean_command_type(text: str) -> str:
"""Remove parents from the command type"""
text = text.replace("Command.", "")
text = text.replace("CommandType.", "")
return text | ca6b1a8ee0a3ee87487c5901413ad141c6a97ff2 | 36,257 |
import tempfile
import getpass
def get_default_session_filename(username: str) -> str:
"""Returns default session filename for given username."""
dirname = tempfile.gettempdir() + "/" + ".instaloader-" + getpass.getuser()
filename = dirname + "/" + "session-" + username
return filename.lower() | 8f8e9415f5151088a55144e9c3e6f0a9608e1dba | 36,258 |
import re
def parse_points(points_str):
"""Parses the points specification for polyline and polygon
elements (SVG 1.1, 9.7.1).
"""
# Treat #-# as # -#
points_str = points_str.replace('-', ' -')
return [float(s) for s in re.split("[\x20\x09\x0D\x0A]+|[,]",
points_str) if s != ""] | b2b29ffcf9e240ea06ca75d55f2595416b75963d | 36,260 |
def find_text(node, path):
"""Find a node's text or None
"""
return getattr(node.find(path), 'text', None) | ddc951dcec720ab2ed73c4277d582e8ffa25ae2b | 36,270 |
def format_time(time):
"""
Format time based on strftime.
Args:
time: Expected time as datetime.datetime class
Returns:
Formatted time.
"""
return time.replace(second=0).strftime('%Y-%m-%d %H:%M:%S') | fe6abda2c787c5504ea8518c25fc2ddf0054b8f2 | 36,271 |
from typing import Iterable
from pathlib import Path
def list_images(img_dir) -> Iterable[str]:
"""List all image files in img_dir.
Returns an iterator that lists the files to process. Subclasses may want to override this to return specific
image types or filter the results. By default, will list all ima... | c7585c4fe737fb95af27a3fad578ebf3347e4f9c | 36,282 |
from pathlib import Path
def assemble_path(*args):
"""Join together all specified inputs into a directory path."""
if not args:
raise ValueError("You must specify at each one path parameter to assemble")
assembled_path = Path(args[0])
for index, path in enumerate(args[1:]):
assembled_p... | cfe2102683046fa655535bbf1ae6323960046780 | 36,286 |
from typing import OrderedDict
def list_drop_duplicates(li: list, keep: str = 'first') -> list:
"""
Drop duplicates from a (ordered) list
:param li: List to drop duplicates from
:param keep: Keep first or last occurrence of the unique items
"""
if keep == 'first':
return list(OrderedD... | b43b59a7d6ea266843266ee3eb8d5af5eaf7bb33 | 36,287 |
def is_api_disabled(config, api_name):
"""Check if api_name is disabled in the config.
Args:
config (dict): GCP API client configuration.
api_name (str): The name of the GCP api to check.
Returns:
bool: True if the API is disabled in the configuration, else False.
"""
retur... | cdce24c07cdf1190c1ea46613cbdccfaec649404 | 36,289 |
import glob
def get_file_paths(path_to_data: str = 'drive/MyDrive/Belgorodskaya/*.tif', feature_names: list = ['tmax', 'tmin', 'pr']):
"""
Filters out required features amongs terraclim dataset
Arguments:
path_to_data (str): path to directory that containts terraclim dataset
feature_names (list):... | 3e9e5d3a527cb7c7dafa800736cc274ea23e34e0 | 36,290 |
def deserialize_measurement(serialized):
"""Deserialize a `openff.evaluator.unit.Measurement` from a dictionary of the form
`{'value', 'error'}`.
Parameters
----------
serialized : dict of str and str
A dictionary representation of a `openff.evaluator.unit.Measurement`
which must ha... | 80b28ac9c641fb0399efc5d24eddfc381df68f27 | 36,293 |
def score(letter):
"""
Returns index of letter in alphabet e.g. A -> 1, B -> 2, ...
"""
string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
return(string.index(letter) + 1) | becba57c57c36204d2b106836233a91b90960712 | 36,294 |
import re
import unicodedata
def slugify(string):
"""
Slugify unicode string.
Example:
>>> slugify("Hélló Wörld")
"hello-world"
"""
if not string:
return ''
return re.sub(r'[-\s]+', '-', re.sub(r'[^\w\s-]', '', unicodedata.normalize('NFKD', string)).strip().lower()) | 8924c712d7b9527f3c0df2d2b3522a411a3dfd4a | 36,299 |
def computeSimilarityScores(inputs, fvecfunc, combfunc, clsfunc):
"""Computes similarity scores for all pairs in the given set of inputs.
Exhaustively goes through all pairs of inputs, and looks up feature vectors
using the given fvecfunc. Pairs of feature vectors are combined using the
combfunc. These ... | 383be99d20e2bea50b3b551f009daa0e5f54cb0a | 36,302 |
def get_device_id(device):
""" Get the device_id of a device """
return device.type[len('_arsdk-'):-len('._udp.local.')] | f53f38a06089d584382d5ab02d3e3dd3b250bb41 | 36,304 |
import re
def remove_default_namespace(src):
"""
Remove default xmlns from the given string.
:param str src: Source string
:returns: String with xmlns definitions removed.
"""
return re.sub(r' xmlns="[^"]+"', '', src) | 600a0d2331b32010d29c4ba9cb004cc3bdf80d05 | 36,310 |
def get_display_range(worksheet):
"""
Get the conditions displayed on a worksheet.
args:
worksheet (seeq.spy.workbooks._worksheet.AnalysisWorksheet): Worksheet
returns:
conditions (dict): Display range. {'Start':Timestamp, 'End':Timestamp}
"""
return worksheet.display_range | 160447f5adf495748042f1b2010921eb4da3c573 | 36,312 |
def _is_prefix(lhs, rhs):
""" return True if the first list is a prefix of the second """
rhs = list(rhs)
while rhs:
if lhs == rhs: return True
rhs.pop()
return False | 6b80093479f4f8f989386f51af98862593fc6867 | 36,315 |
def count_number_of_entries(row, feature, ref_counts):
"""Count the number entries for given building based on
building reference number.
row : pandas.Series
EPC dataset row.
feature: str
Feature by which to count building entries.
e.g. "BUILDING_REFERNCE_NUMBER" or "BUILDING_I... | 2658281beeb51cea8ca1bd3484a8ecd089763d55 | 36,319 |
def comment_parser(reddit_comment_object):
"""Parses a comment and returns selected parameters"""
post_timestamp = reddit_comment_object.created_utc
post_id = reddit_comment_object.id
score = reddit_comment_object.score
ups = reddit_comment_object.ups
downs = reddit_comment_object.downs
pos... | 2331c0b52201272a39d0b3befeb8a962f59c05a6 | 36,322 |
def ids2tokens(vocab, tokids):
"""
Convert list of numeric token ID arrays `tokids` to a character token array with the help of the vocabulary
array `vocab`.
Returns result as list of string token arrays.
.. seealso:: :func:`~tmtoolkit.preprocess.tokens2ids` which reverses this operation.
:par... | 70149c881d362bbe32fa39de6941891e0f8915db | 36,323 |
def get_block_size(num_antennas=1,
tchans_per_block=128,
num_bits=8,
num_pols=2,
num_branches=1024,
num_chans=64,
fftlength=1024,
int_factor=4):
"""
Calculate block size, given a ... | 25d667f84ddaaf25b0cb4bae48a0ab1f363bc63a | 36,329 |
def dimensionsKeepAspect(targetWidth, targetHeight, oldWidth, oldHeight):
"""
Gives resizing dimensions to keep an image within (targetWidth, targetHeight)
while preserving the original aspect ratio. Does not upsize iamges smaller
than the target dimensions.
"""
if (oldWidth < targetWidth) and (... | 9763638a9a4334dcc22f2d38f1e6b4a8fda1d1b6 | 36,330 |
def calculate_IonS(salt):
"""DOE handbook, Chapter 5, p. 13/22, eq. 7.2.4"""
return 19.924 * salt / (1000 - 1.005 * salt) | 7bb10b47580831b49c7f8f2b9af3fce31272eb43 | 36,342 |
def str_dict(input_dict):
"""
Convert all the values in a dictionary to str
:param input_dict:
:type input_dict: dict{any: any]
:return: dictionary including str values
:rtype dict[any: str]
"""
return {key: "{}".format(value) for key, value in input_dict.items()} | cc893ede066a50426990e4e578151d8ef97bfb55 | 36,346 |
from typing import Union
from pathlib import Path
from typing import Any
import pickle
def read_pkl(pkl: Union[str, Path]) -> Any:
"""
Read pickle file.
Parameters
----------
pkl : str or pathlib.Path
The path od pickle file.
Returns
-------
obj : Any
Restored object.
"""... | e98815a571e4812b654cf264f53e044f7b31ae8a | 36,347 |
def alignment_percentage(document_a, document_b, model):
"""
Returns the percentage of alignments of `document_a` and `document_b`
using the model provided.
- `document_a` and `document_b` are two lists of Sentences to align.
- `model` can be a YalignModel or a path to a yalign model.
"""
... | dbd11fbdf9649e6f2c3a20e8407a799a3faeb428 | 36,355 |
import re
def format_card(card_num):
"""
Formats card numbers to remove any spaces, unnecessary characters, etc
Input: Card number, integer or string
Output: Correctly formatted card number, string
"""
card_num = str(card_num)
# Regex to remove any nondigit characters
return re.sub(r"... | 0c967a499a71ff8934b7578a3f62a31874f22ca2 | 36,357 |
def _produce_scores(scores, exp):
"""Produces the scores dictionary.
Args:
scores: Is either the score dictionary, or a function that produces the
score dictionary based on an experiment.
exp: The experiment ojbect.
Returns:
The dictionary of scores.
"""
if i... | bd7d3e4883f294ba7daed987a555c8e5310160e7 | 36,362 |
def bessel_spoles(n, Ts=1):
""" Return the roots of the reverse Bessel polynomial normalized the given
settling time. The settling time is 1 second by default. Adapted from
Digital Control: A State-Space Approach, Table 6.3.
Args:
n: The order of the Bessel polynomial.
Ts (optional... | 4e2191c9c1201997e77da314316ef1ebc208f7d4 | 36,364 |
from typing import List
from typing import Tuple
def words_to_ngrams(words: List[str]) -> List[Tuple[str]]:
""" Convert a list of words to uni-grams
:param words: The list of words to convert
:return: A list of the same size, containing single-element tuples of uni-grams.
"""
return [(w,) for w i... | 3d4fa456bd9c8bbe034b9441521bdc62940f8cf9 | 36,366 |
def _copy_non_t_vars(data0, data1):
"""Copies non-t-indexed variables from data0 into data1, then
returns data1"""
non_t_vars = [v for v in data0.data_vars
if 't' not in data0[v].dims]
# Manually copy over variables not in `t`. If we don't do this,
# these vars get polluted with a ... | 81c0a21f61fd284fd572383acff2ac8744101777 | 36,371 |
from typing import Dict
from typing import Any
from typing import List
def filter_dict(mydict: Dict[str, Any], keys: List[str]) -> Dict[str, Any]:
"""Filter dictionary by desired keys.
Args:
mydict: disctionary with strings as keys.
keys: a list of key names to keep.
Returns:
the... | 339101fc16fc69110f3d470668eda455f430c062 | 36,377 |
import random
def gen_individual(toolbox, config, out_type='out'):
"""
Generates a random tree individual using the toolbox and arity and height configuration.
The ``ou_type`` parameter specifies the output type of the root of the tree.
:param toolbox: Toolbox which contains methods to create the ind... | 5fb0d051502cd9764e8bedc31dc2c717200f618f | 36,378 |
def top_n(n: int, tokens: list) -> list:
"""Return a list of top-n unique elements of the dataset
Arguments:
n {int} -- number of top unique elements to return
Returns:
list -- array of top-n elements within a dataset
"""
top_n_elements = tokens[:n]
return top_n_element... | 6d0e03b3d041edb460a874394af171cf589b2b1b | 36,380 |
from typing import List
from typing import Type
def validate_objects(elements: List, element_class: Type) -> bool:
"""
Check if all the elements are instance of the element_class.
Args:
elements: List of objects that should be instance of element_class.
element_class: class of the objects... | cd913ef4005d5360f8c2053ae30a72173e41d886 | 36,381 |
def check_day(n):
"""
Given an integer between 1 and 7 inclusive,
return either string 'work!' or string 'rest!'
depending on whether the day is a workday or not
"""
if n < 1 or n > 7:
return None
if n >= 6:
return "rest!"
return "work!" | f7329fb411a737c2fb9799a37a0bb52e28d4db83 | 36,382 |
def tolist(x):
"""convert x to a list"""
return x if isinstance(x, list) else [x] | eb987b9766d09d7a36f1e671e5cf266296c0604e | 36,383 |
def get_index_of_table_a_1(type):
"""表A.1における行番号を取得する
Args:
type(str): 主たる居室に設置する暖冷房設備機器等
Returns:
int: 表A.1における行番号
"""
key_table = {
'電気蓄熱暖房器': 0,
'温水暖房用パネルラジエーター': 1,
'温水暖房用床暖房': 2,
'温水暖房用ファンコンベクター': 3,
'ルームエアコンディショナー': 4,
'FF暖房機': 5,
... | 70f2087e08d05520bb1db7fb04fa2f66b8f5d445 | 36,385 |
def neg_network(network):
"""
Perform the operation
``-1 * network``
where ``network`` is an instance of ``Network``.
"""
return network * -1 | da1e59f09ca8c91efb6fdaa22bf03e58a6fb7e43 | 36,393 |
def cell_width(cell_name):
""" Set the width of the cells from the pdf report file."""
if cell_name == "No":
table_cell_width = 6
elif cell_name == "Phrase":
table_cell_width = 73
elif cell_name == "Question":
table_cell_width = 57
else:
table_cell_width = 25
retu... | fac9e9dc0f8ad3cac09ed3054a798e7d832cdcc6 | 36,396 |
def get_shape_from_dims(axis_0, axis_1=None):
"""
Constructs a chain shape tuple from an array-like axis_0 and an optional array-like axis_1
:param axis_0: Iterable of dimensions for the first leg on each site of the chain
:param axis_1: Optional iterable of dimensions for the second leg on each sit... | 3508654e6b94ab515bf1975755d95923775c4849 | 36,399 |
def add_node(nodes, parent, time):
"""Adds a node with specified parent and creation time. This functions assumes that
a node has been already allocated by "child" functions `add_node_classifier` and
`add_node_regressor`.
Parameters
----------
nodes : :obj:`Nodes`
The collection of node... | d204d618114b13ffcbfc038c91884f4a87e743c0 | 36,405 |
def scale(y, yerr):
"""
Standardization of a given dataset y
Parameters:
y = data; subtract mean, divide by std
yerr = errors; divide by std of x
Returns:
standardized y and yerr
"""
m, s = y.mean(), y.std()
return (y-m)/s, yerr/s | 5985fa930470d1535b4befde5878ce325f1dc86b | 36,414 |
def isoforest_label_adjust(pred_func):
"""Adjusts isolation forest predictions to be 1 for outliers, 0 for inliers.
By default the scikit-learn isolation forest returns -1 for outliers and 1
for inliers, so this method is used to wrap fit_predict or predict methods
and return 0 for inliers, 1 for outli... | 11ac61f691404525a357a32e725c30dd2675a85a | 36,415 |
def join_list(words: list, join_s: str):
"""
Take each strings in the list 'words' is joined in a single string spaced whit 'join_s'
:param words: string to be joined
:param join_s: spaced string
:return: joined string
"""
return join_s.join(words) | cf7641ec81d7284c0ec6f65085567a572310d193 | 36,416 |
def write_gwosc_string(config, ifos, outdir):
"""
Write command string to execute bajes_read_gwosc.py
given a config file
"""
read_string = 'bajes_read_gwosc.py --outdir {} '.format(outdir)
try:
read_string += '--event {} '.format(config['gw-data']['event'])
except Exce... | 2c42d4956764b4328a92792cb6b6087fbb2daf57 | 36,417 |
import gc
import time
def run_test(func, fobj):
"""Run func with argument fobj and measure execution time.
@param func: function for test
@param fobj: data for test
@return: execution time
"""
gc.disable()
try:
begin = time.time()
func(fobj)
end = time.... | c9851736cb5ad3886565fc3a06cb8ef2c2ee5478 | 36,420 |
def _CheckNoIn(input_api, output_api):
"""Checks that corpus tests don't contain .in files. Corpus tests should be
.pdf files, having both can cause race conditions on the bots, which run the
tests in parallel.
"""
results = []
for f in input_api.AffectedFiles(include_deletes=False):
if f.LocalPath().en... | 814b7b52c59c373a3d7ec010f99b85d602b8dd02 | 36,421 |
import asyncio
import functools
def schedule_coroutine(delay, coro_func, *args, **kwargs):
"""
Creates a coroutine out of the provided coroutine function coro_func and
the provided args and kwargs, then schedules the coroutine to be called
on the running event loop after delay seconds (delay can be fl... | 4df7fc85d20f15a5c1850f1d2d4b2645b22445cd | 36,422 |
def pop_node_record(records):
"""Pops (removes and returns) a node record from the stack of records.
Parameters
----------
records : Records
A records dataclass containing the stack of node records
Returns
-------
output : tuple
Outputs a tuple with eight elements containin... | 2cc535ab444c7cb86a544ec2f98de176fcc546db | 36,423 |
from typing import Sequence
import re
def _validate_against_blacklist(string: str, blacklist: Sequence[str]):
"""Validates a string against a regex blacklist."""
return not any(re.search(pattern, string, re.IGNORECASE) for pattern in blacklist) | 7c1e3ca9b9b295d3927d8b516f0562a2a04858af | 36,428 |
def cycles_per_trial(nwb):
"""Get the number of microscope cycles/trial.
That is, the number of times each point is imaged in each
trial. Currently looks at the first imaging timeseries in
the first trial, and assumes they're all the same.
"""
trial1 = nwb['/epochs/trial_0001']
for ts_name ... | dbe421716267669041ee654bb357426259ed2703 | 36,429 |
def format_name(f_name, l_name):
"""Take a first and last name and format it
to return the title case version of the name.
Args:
f_name ([string])
l_name ([string])
Returns:
f_name + l_name in title
"""
if f_name == "" or l_name == "":
return "You not enter a va... | 59c7a9b135d0001c7bc1a378bbcbfb68a4dfa36a | 36,431 |
import re
def parse_num(s):
"""Parse data size information into a float number.
Here are some examples of conversions:
199.2k means 203981 bytes
1GB means 1073741824 bytes
2.1 tb means 2199023255552 bytes
"""
g = re.match(r'([-+\d.e]+)\s*(\w*)', str(s))
if not g:
r... | 721cc52cdf543bcaf3ff77d8059a7bfe6cb6d892 | 36,433 |
def rstrip_line(line):
"""Removes trailing whitespace from a string (preserving any newline)"""
if line[-1] == '\n':
return line[:-1].rstrip() + '\n'
return line.rstrip() | adb3b707ddb450996b1677e68ad1861a76313cc6 | 36,438 |
import inspect
import typing
def get_type(type):
"""
Helper function which converts the given type to a torchScript acceptable format.
"""
if isinstance(type, str):
return type
elif inspect.getmodule(type) == typing:
# If the type is a type imported from typing
# like Tuple... | 116e169107460cd0807257eef303d4959323319b | 36,440 |
def pow_mod(a: int, b: int, p: int) -> int:
"""
Computes a^b mod p using repeated squaring.
param a: int
param b: int
param p: int
return: int a^b mod p
"""
result = 1
while b > 0:
if b & 1:
result = (result * a) % p
a = (a * a) % p
b >>= 1
ret... | e84085c1ed5e4c9c321f42a3a6275537736789bc | 36,451 |
import functools
def get_latex_name(func_in, **kwargs):
"""
Produce a latex formatted name for each function for use in labelling
results.
Parameters
----------
func_in: function
kwargs: dict, optional
Kwargs for function.
Returns
-------
latex_name: str
Latex... | 1eb376cd597e78a4d7e7c1c0144fc904ffa3ea60 | 36,452 |
import yaml
def create_blacklist(config_file):
"""
Generate a list of images which needs to be excluded from docker_image_list
:param config_file: application_configuration file where images are.
:return:
"""
with open(config_file, 'r') as f:
file = yaml.load(f, Loader=yaml.SafeLoader)... | 9d0b7ae78b83670f06390abb43d2b19d3f3342e0 | 36,456 |
def join_segments_raw(segments):
"""Make a string from the joined `raw` attributes of an iterable of segments."""
return "".join(s.raw for s in segments) | ba2f3d1157ee505daaec3919c4e70ad6e49e5db2 | 36,457 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.