content stringlengths 35 416k | sha1 stringlengths 40 40 | id int64 0 710k |
|---|---|---|
def has_no_duplicates(input_):
"""Check that a list contains no duplicates.
For example:
['aa', 'bb', 'cc'] is valid.
['aa', 'bb', 'aa'] is not valid. The word aa appears more than once.
"""
return len(input_) == len(set(input_)) | 6bc1b29b3509e4b17523408ea362591cace8d05d | 709,353 |
def _getBestSize(value):
"""
Give a size in bytes, convert it into a nice, human-readable value
with units.
"""
if value >= 1024.0**4:
value = value / 1024.0**4
unit = 'TB'
elif value >= 1024.0**3:
value = value / 1024.0**3
unit = 'GB'
elif value >= 1024... | 6c1859c50edcbd5715443fbf30775eeee83d6a0c | 709,354 |
def inVolts(mv):
""" Converts millivolts to volts... you know, to keep the API
consistent. """
return mv/1000.0 | 6c92195996be1aa2bd52aa0a95d247f7fdef5955 | 709,355 |
from typing import IO
import mimetypes
def guess_mime_type(file_object: IO) -> str:
"""Guess mime type from file extension."""
mime_type, _encoding = mimetypes.guess_type(file_object.name)
if not mime_type:
mime_type = "application/octet-stream"
return mime_type | 12e6e6667b08eaaa24b822c37d56055c1487a801 | 709,356 |
import os
def _resource_path_dev(relative_path):
"""
:return: Package relative path to resource
"""
base_path = os.path.dirname(os.path.abspath(__file__))
return os.path.join(base_path, relative_path) | 8cdf30f3fa62fb824dcdc70bf9d2627b74f66110 | 709,357 |
def replace_word_choice(sentence: str, old_word: str, new_word: str) -> str:
"""Replace a word in the string with another word.
:param sentence: str - a sentence to replace words in.
:param old_word: str - word to replace
:param new_word: str - replacement word
:return: str - input sentence with ne... | 27d0eae1aa12538c570fec3aa433d59c40556592 | 709,358 |
def append_slash(url):
"""Make sure we append a slash at the end of the URL otherwise we
have issues with urljoin Example:
>>> urlparse.urljoin('http://www.example.com/api/v3', 'user/1/')
'http://www.example.com/api/user/1/'
"""
if url and not url.endswith('/'):
url = '{0}/'.format(url)
... | 3d8f009f0f7a2b93e2c9ed3fee593bbcf0f25c4f | 709,359 |
def test_if_tech_defined(enduse_fueltypes_techs):
"""Test if a technology has been configured,
i.e. a fuel share has been assgined to one of the
fueltpyes in `fuel_shares`.
Arguments
---------
enduse_fueltypes_techs : dict
Configured technologies and fuel shares of an enduse
Return... | a727b375dc1bc7e76fe63090d8e278013fa2c6bb | 709,360 |
def classification_result(y, y_pred):
"""
:param y:
:param y_pred:
:return:
"""
assert len(y) == len(y_pred)
correct = []
wrong = []
for i in range(len(y)):
if y[i] == y_pred[i]:
correct.append(i)
else:
wrong.append(i)
return correct, wro... | bdab32eeded40691a721fe8e1463819605c5639c | 709,361 |
def map_class_to_id(classes):
"""
Get a 1-indexed id for each class given as an argument
Note that for MASATI, len(classes) == 1 when only considering boats
Args:
classes (list): A list of classes present in the dataset
Returns:
dict[str, int]
"""
class_ids = list(range(1, l... | 7c2b47249f61f446327c0a798c1a129c62fde6b3 | 709,362 |
import os
import subprocess
def check_qe_completed(folder,prefix,output_file,calc_type='pw'):
"""
Check if qe calculation has correctly completed.
- folder: where the calculation has been run.
- prefix: qe prefix
- output_file: name of output file
- calc_type: either 'pw' or 'ph' or 'gkk... | 778375406379996d86d0e033da8531566f8fa7dd | 709,363 |
import os
def _is_file_not_empty(file_path):
"""Return True when buildinfo file is not empty"""
# NOTE: we can assume, that when file exists, all
# content have been dowloaded to the directory.
return os.path.getsize(file_path) > 0 | 08ef68719eaf57adbb946412dc259ea3d42117d1 | 709,364 |
import os
def check_file_exists(filename):
"""Try to open the file `filename` and return True if it's valid """
return os.path.exists(filename) | 93edc12c8d87863b560637f0bff73f0545f38270 | 709,365 |
def get_output_detections_image_file_path(input_file_path, suffix="--detections"):
"""Get the appropriate output image path for a given image input.
Effectively appends "--detections" to the original image file and
places it within the same directory.
Parameters
-----------
input_file_path: s... | b8d060dff6800750c418c70c61bd4d8e0b7bb416 | 709,366 |
from typing import Callable
def partial(fn: Callable, *args, **kwargs) -> Callable:
"""Takes a function and fewer than normal arguments, and returns a function
That will consume the remaining arguments and call the function"""
def partial_fn(*rem_args, **rem_kwargs):
return fn(*args, *rem_args, *... | 80f0df16915593fa0c5212e7560626db78147da6 | 709,368 |
import re
def parse_lipid(name):
"""
parse_lipid
description:
parses a lipid name into lipid class and fatty acid composition, returning a
dictionary with the information. Handles total fatty acid composition, as well
as individual composition, examples:
PC(38:3) -->... | 31a26cf57edfd08c6025c07982b7d6805704088e | 709,369 |
import re
import os
def rootUrlJoin(base, extend):
"""
Adds a path element to the path within a ROOT url
"""
if base:
match = re.match("^root://([^/]+)/(.+)", base)
if match:
host = match.group(1)
path = match.group(2)
newpath = os.path.join(path, ex... | 613db9d8ae230bfba064e16cf4fe1712b061be91 | 709,370 |
def either(a, b):
"""
:param a: Uncertain value (might be None).
:param b: Default value.
:return: Either the uncertain value if it is not None or the default value.
"""
return b if a is None else a | 3fd2f99fa0851dae6d1b5f11b09182dbd29bb8c1 | 709,371 |
def get_app_label_and_model_name(path):
"""Gets app_label and model_name from the path given.
:param str path: Dotted path to the model (without ".model", as stored
in the Django `ContentType` model.
:return tuple: app_label, model_name
"""
parts = path.split('.')
return (''.join(parts[... | 998e8d81f59491a51f3ae463c76c8627ed63b435 | 709,372 |
import math
def vec_len(x):
""" Length of the 2D vector"""
length = math.sqrt(x[0]**2 + x[1]**2)
return length | a357d31df808720eb2c4dfc12f4d6194ef904f67 | 709,373 |
def part1_count_increases(measurements):
"""Count increases of a measure with the next."""
windows = zip(measurements[1:], measurements[:-1])
increases = filter(lambda w: w[0] > w[1], windows)
return len(list(increases)) | 59311b940ff7fe72cd6fe9cd4d0705918e796e69 | 709,374 |
def remove_empties(seq):
""" Remove items of length 0
>>> remove_empties([1, 2, ('empty', np.nan), 4, 5])
[1, 2, 4, 5]
>>> remove_empties([('empty', np.nan)])
[nan]
>>> remove_empties([])
[]
"""
if not seq:
return seq
seq2 = [x for x in seq
if not (isins... | 500cbbd942682bfde1b9c1babe9a2190413b07fd | 709,375 |
def read_code_blocks_from_md(md_path):
"""
Read ```python annotated code blocks from a markdown file.
Args:
md_path (str): Path to the markdown fle
Returns:
py_blocks ([str]): The blocks of python code.
"""
with open(md_path, "r") as f:
full_md = f.read()
md_py_sp... | ca920f74e9326cf5f3635fbb6ebe125b6d97a349 | 709,376 |
import math
def get_localization_scores(predicted_start: int, predicted_end: int, true_start: int, true_end: int):
"""
exp(-abs(t_pred_start-t_start)/(t_end-t_start))
exp(-abs(t_pred_end-t_end)/(t_end-t_start))
:param predicted_start:
:param predicted_end:
:param true_start:
:param true_en... | dfcef55e0594507b48aa83027c5b55a2a6530717 | 709,377 |
def json_compatible_key(key: str) -> str:
"""As defined in :pep:`566#json-compatible-metadata`"""
return key.lower().replace("-", "_") | b914ba17b3da5df84d72497048565a118fc4fb05 | 709,378 |
def _scale_func(k):
"""
Return a lambda function that scales its input by k
Parameters
----------
k : float
The scaling factor of the returned lambda function
Returns
-------
Lambda function
"""
return lambda y_values_input: k * y_values_input | 65fd06bfb1a278b106eecc4974bc9317b1dea67f | 709,379 |
import copy
def simplify_graph(G):
"""remove the scores, so the cycle_exits() function can work"""
graph = copy.deepcopy(G)
simplified = dict((k, graph[k][0]) for k in graph)
# add dummy edges,so the cycle_exists() function works
for source in simplified.keys():
for target in simplified[s... | fc9b052c83ce500d20842367b3b6f011268a5a7d | 709,380 |
def export_python_function(earth_model):
"""
Exports model as a pure python function, with no numpy/scipy/sklearn dependencies.
:param earth_model: Trained pyearth model
:return: A function that accepts an iterator over examples, and returns an iterator over transformed examples
"""
i = 0
ac... | 593d8cf9f1156359f2276f0481e02a2d00d8ffde | 709,381 |
def get_disable_migration_module():
""" get disable migration """
class DisableMigration:
def __contains__(self, item):
return True
def __getitem__(self, item):
return None
return DisableMigration() | d44a26c5e597f23dbc2434488baf54ebccc5010c | 709,382 |
def split_rows(sentences, column_names):
"""
Creates a list of sentence where each sentence is a list of lines
Each line is a dictionary of columns
:param sentences:
:param column_names:
:return:
"""
new_sentences = []
root_values = ['0', 'ROOT', 'ROOT', 'ROOT', 'ROOT', 'ROOT', '0', ... | 444733a9c169bedae8dc0045cd696cafed7085e2 | 709,383 |
from datetime import datetime
def _metadata(case_study):
"""Collect metadata in a dictionnary."""
return {
'creation_date': datetime.strftime(datetime.now(), '%c'),
'imagery': case_study.imagery,
'latitude': case_study.lat,
'longitude': case_study.lon,
'area_of_interest... | eb16892135326662029fe568922f2871f016090e | 709,384 |
import re
def fix_reference_name(name, blacklist=None):
"""Return a syntax-valid Python reference name from an arbitrary name"""
name = "".join(re.split(r'[^0-9a-zA-Z_]', name))
while name and not re.match(r'([a-zA-Z]+[0-9a-zA-Z_]*)$', name):
if not re.match(r'[a-zA-Z]', name[0]):
name... | 2f1a291fc7ac9816bc2620fceeeaf90a1bb3fd4a | 709,385 |
def get_3d_object_section(target_object):
"""Returns 3D section includes given object like stl.
"""
target_object = target_object.flatten()
x_min = min(target_object[0::3])
x_max = max(target_object[0::3])
y_min = min(target_object[1::3])
y_max = max(target_object[1::3])
z_min = min(tar... | e11d62ad06ada005d16803b2f440ac700e272599 | 709,386 |
import requests
import json
def _get_page_num_detail():
"""
东方财富网-数据中心-特色数据-机构调研-机构调研详细
http://data.eastmoney.com/jgdy/xx.html
:return: int 获取 机构调研详细 的总页数
"""
url = "http://data.eastmoney.com/DataCenter_V3/jgdy/xx.ashx"
params = {
"pagesize": "5000",
"page": "1",
"j... | 84c32485637cb481f1ebe6fe05609e5b545daece | 709,387 |
def _get_partition_info(freq_unit):
"""
根据平台单位获取tdw的单位和格式
:param freq_unit: 周期单位
:return: tdw周期单位, 格式
"""
if freq_unit == "m":
# 分钟任务
cycle_unit = "I"
partition_value = ""
elif freq_unit == "H":
# 小时任务
cycle_unit = "H"
partition_value = "YYYYMM... | 1f7df3364a21018daa8d3a61507ee59c467c8ffc | 709,388 |
import logging
def stream_logger():
""" sets up the logger for the Simpyl object to log to the output
"""
logger = logging.Logger('stream_handler')
handler = logging.StreamHandler()
handler.setFormatter(logging.Formatter('%(asctime)s %(message)s'))
logger.addHandler(handler)
return logger | 45f5af00a0006cc8155bb4a134cce531e51e646a | 709,390 |
def get_breakeven_prob(predicted, threshold = 0):
"""
This function calculated the probability of a stock being above a certain threshhold, which can be defined as a value (final stock price) or return rate (percentage change)
"""
predicted0 = predicted.iloc[0,0]
predicted = predicted.iloc[-1]
p... | a1cededbe7a0fbe7ffe19e9b873f55c8ce369590 | 709,391 |
import pathlib
def present_from(ref: pathlib.Path, obs: pathlib.Path) -> pathlib.Path:
"""Build a somehow least surprising difference folder from ref and obs."""
ref_code = ref.parts[-1]
if obs.is_file():
return pathlib.Path(*obs.parts[:-1], f'diff-of-{obs.parts[-1]}')
present = pathlib.Path(... | 59ae1eefaeacc9ddfac773c0c88974b98757d4a2 | 709,392 |
def comp_mass(self):
"""Compute the mass of the Frame
Parameters
----------
self : Frame
A Frame object
Returns
-------
Mfra: float
Mass of the Frame [kg]
"""
Vfra = self.comp_volume()
# Mass computation
return Vfra * self.mat_type.struct.rho | b78ef02f045c1f624b3277ec3e358921b3ea5c02 | 709,393 |
def _create_unicode(code: str) -> str:
"""
Добавление экранизирующего юникод кода перед кодом цвета
:param code: Код, приоритетно ascii escape color code
:return:
"""
return u'\u001b[{}m'.format(code) | 523973766d4f18daca8870e641ac77967b715532 | 709,394 |
def get_all(isamAppliance, check_mode=False, force=False, ignore_error=False):
"""
Retrieving the current runtime template files directory contents
"""
return isamAppliance.invoke_get("Retrieving the current runtime template files directory contents",
"/mga/template_f... | 9ff291b63471b57b110885c35939c8afe3d2f0d8 | 709,395 |
import os
def _fix_importname(mname):
"""
:param mname:
"""
mname = os.path.normpath(mname)
mname = mname.replace(".", "")
mname = mname.replace("-", "")
mname = mname.replace("_", "")
mname = mname.replace(os.path.sep, "")
mname = mname.replace(os.path.pathsep, "")
return mn... | 22f8ab56800a593502822a612c3f642e8cec22ea | 709,396 |
import os
import glob
def get_font_paths(fonts_dir):
"""
Load font path recursively from a folder
:param fonts_dir: folder contains ttf、otf or ttc format font
:return: path of all fonts
"""
print('Load fonts from %s' % os.path.abspath(fonts_dir))
fonts = glob.glob(fonts_dir + '/**/*', recu... | bf6368f90023fd59d64d358e6dac919627feb9ab | 709,398 |
def secondsToHMS(intervalInSeconds):
"""converts time in seconds to a string representing time in hours, minutes, and seconds
:param intervalInSeconds: a time measured in seconds
:returns: time in HH:MM:SS format
"""
interval = [0, 0, intervalInSeconds]
interval[0] = (inter... | b38d4b886eaabd1361c162b6b7f55e11493dfb60 | 709,399 |
def find_layer(model, type, order=0):
"""
Given a model, find the Nth layer of the specified type.
:param model: the model that will be searched
:param type: the lowercase type, as it is automatically saved by keras in the layer's name (e.g. conv2d, dense)
:param order: 0 by default (the first matc... | 6d4e08c181900774b9e5666a11df9767f68a10ca | 709,400 |
def _find_weektime(datetime, time_type='min'):
"""
Finds the minutes/seconds aways from midnight between Sunday and Monday.
Parameters
----------
datetime : datetime
The date and time that needs to be converted.
time_type : 'min' or 'sec'
States whether the time difference shoul... | 2ed28166d239dabdc9f8811812e472810b10c7d7 | 709,401 |
def field_as_table_row(field):
"""Prints a newforms field as a table row.
This function actually does very little, simply passing the supplied
form field instance in a simple context used by the _field_as_table_row.html
template (which is actually doing all of the work).
See soc/templates/soc/templatetags/_... | 74d120e2a46ae8465832d98ddf02848b5b2cc936 | 709,402 |
def get_samples(select_samples: list, avail_samples: list) -> list:
"""Get while checking the validity of the requested samples
:param select_samples: The selected samples
:param avail_samples: The list of all available samples based on the range
:return: The selected samples, verified
"""
# S... | e1c0c98697d2c504d315064cbdfbad379165d317 | 709,403 |
import collections
def _find_stop_area_mode(query_result, ref):
""" Finds the mode of references for each stop area.
The query results must have 3 columns: primary key, foreign key
reference and number of stop points within each area matching that
reference, in that order.
:param... | e4677638b272e67d2ae21ee97f71f1f1700fd072 | 709,404 |
def _255_to_tanh(x):
"""
range [0, 255] to range [-1, 1]
:param x:
:return:
"""
return (x - 127.5) / 127.5 | a60a67ee489093292fc58136a8f01387482fb162 | 709,405 |
import datetime
def Write(Variable, f):
"""Function to Convert None Strings to Strings and Format to write to file with ,"""
if isinstance(Variable, str) == False:
if isinstance(Variable, datetime.datetime) == True:
return f.write(f"{Variable.strftime('%Y-%m-%d')},")
else:
... | 9963c4117c7cc3f19d91331ed6c36e5733cffb56 | 709,406 |
def root():
"""Root endpoint that only checks if the server is running."""
return 'Server is running...' | ea9ecd1c736e9379795f361462ed54f464a4008b | 709,407 |
def clone_model(model, **new_values):
"""Clones the entity, adding or overriding constructor attributes.
The cloned entity will have exactly the same property values as the
original entity, except where overridden. By default, it will have no
parent entity or key name, unless supplied.
Args:
... | ed668632c8917ad685b86fb5c71146be7c9b3b96 | 709,408 |
def finnegans_wake_unicode_chars():
"""Data fixture that returns a string of all unicode characters in Finnegan's Wake."""
return '¤·àáãéìóôþŒŠŸˆ–—‘’‚“”‡…‹' | 78205c9181545544a61ef1eab6c2f51d212dac13 | 709,409 |
from typing import Any
def accept_data(x: Any) -> Any:
"""Accept any types of data and return it as convenient type.
Args:
x: Any type of data.
Returns:
Any: Accepted data.
"""
if isinstance(x, str):
return x
elif isinstance(x, list):
return x
elif i... | 9862995eafb7015fc446466e2dbb7774be39f54b | 709,410 |
def merge_dict_list(merged, x):
""" merge x into merged recursively.
x is either a dict or a list
"""
if type(x) is list:
return merged + x
for key in x.keys():
if key not in merged.keys():
merged[key] = x[key]
elif x[key] is not None:
merged[key... | 00685be39a0b1447c81ecd8de777ebab38aa9bfe | 709,411 |
def gomc_sim_completed_properly(job, control_filename_str):
"""General check to see if the gomc simulation was completed properly."""
job_run_properly_bool = False
output_log_file = "out_{}.dat".format(control_filename_str)
if job.isfile(output_log_file):
# with open(f"workspace/{job.id}/{output... | 20635ba94b5176298216ad5807e6428a5fb957c2 | 709,412 |
def changenonetoNone(s):
"""Convert str 'None' to Nonetype
"""
if s=='None':
return None
else:
return s | 9f6af1580d8b47d2a7852e433f7ba8bbd5c7044d | 709,413 |
def identify_word_classes(tokens, word_classes):
"""
Match word classes to the token list
:param list tokens: List of tokens
:param dict word_classes: Dictionary of word lists to find and tag with the
respective dictionary key
:return: Matched word classes
:rtype: list
"""
if w... | ca7aa602d19ac196321af19c42a60df415c7d115 | 709,414 |
def is_interested_source_code_file(afile):
"""
If a file is the source code file that we are interested.
"""
tokens = afile.split(".")
if len(tokens) > 1 and tokens[-1] in ("c", "cpp", "pl", "tmpl", "py", "s", "S"):
# we care about C/C++/perl/template/python/assembly source code files
... | 9bd77dc3b530262cc2bf8a32c0d050ea30077030 | 709,415 |
def recursively_extract(node, exfun, maxdepth=2):
"""
Transform a html ul/ol tree into a python list tree.
Converts a html node containing ordered and unordered lists and list items
into an object of lists with tree-like structure. Leaves are retrieved by
applying `exfun` function to the html nodes... | cc5732a786579172dda31958ad2bd468a4feef81 | 709,416 |
def get_body(m):
"""extract the plain text body. return the body"""
if m.is_multipart():
body = m.get_body(preferencelist=('plain',)).get_payload(decode=True)
else:
body = m.get_payload(decode=True)
if isinstance(body, bytes):
return body.decode()
else:
return body | 7980c1471a0a09c793cb8124066a97caac21ae0d | 709,417 |
def density(mass, volume):
"""
Calculate density.
"""
return mass / volume * 1 | 53b1f76ba66695a9cd72be9186bcc374ee11f53b | 709,418 |
import os
import warnings
def get_apikey() -> str:
"""
Read and return the value of the environment variable ``LS_API_KEY``.
:return: The string value of the environment variable or an empty string
if no such variable could be found.
"""
api_key = os.environ.get("LS_API_KEY")
if api_k... | b88a6c0ac8e11add97abd1d7415126f75f50696d | 709,419 |
def num_jewels(J: str, S: str) -> int:
"""
Time complexity: O(n + m)
Space complexity: O(n)
"""
jewels = set(J)
return sum(stone in jewels for stone in S) | f1a9632a791e3ef94699b566da61e27d9dc46b07 | 709,420 |
import os
def get_town_table(screenshot_dir):
"""Generate python code for town table
Its format is
table[town_name] = (nearby town1, nearby town2...nearby town5)
The length of tuple may be different depends on town.
Arguments:
screenshot_dir (str): Directory which have town_name dir... | b6e1c9591cc0531fe9a28b7ce5fec5e5cc231849 | 709,421 |
import glob
def _get_vmedia_device():
"""Finds the device filename of the virtual media device using sysfs.
:returns: a string containing the filename of the virtual media device
"""
sysfs_device_models = glob.glob("/sys/class/block/*/device/model")
vmedia_device_model = "virtual media"
for m... | e8f8e83b7bf0c73d10d8893a5b4b49670edba7ac | 709,423 |
def has_field_warning(meta, field_id):
"""Warn if dataset has existing field with same id."""
if meta.has_field(field_id):
print(
"WARN: Field '%s' is already present in dataset, not overwriting."
% field_id
)
print("WARN: Use '--replace' flag to overwrite existin... | 1cc5016f8ffcce698bcb53dcf6f307b760d7df55 | 709,424 |
def fc_layer(x):
"""Basic Fully Connected (FC) layer with an activation function."""
return x | f26865e13065187363746b8bfe7d95ac221bf236 | 709,425 |
def get_tagset(sentences, with_prefix):
""" Returns the set of entity types appearing in the list of sentences.
If with_prefix is True, it returns both the B- and I- versions for each
entity found. If False, it merges them (i.e., removes the prefix and only
returns the entity type).
"""
iobs =... | c0b00f7c5546bfc7fe10b2d4b35998b5dedeba21 | 709,426 |
def normpath(s: str) -> str:
"""Normalize path. Just for compatibility with normal python3."""
return s | 30c528b11f75f52275b753c789e2e3d5bf71641c | 709,428 |
def _proxies_dict(proxy):
"""Makes a proxy dict appropriate to pass to requests."""
if not proxy:
return None
return {'http': proxy, 'https': proxy} | ce51015dc652c494dc89bb11e21f18803ba34c85 | 709,429 |
def gen_run_entry_str(query_id, doc_id, rank, score, run_id):
"""A simple function to generate one run entry.
:param query_id: query id
:param doc_id: document id
:param rank: entry rank
:param score: entry score
:param run_id: run id
"""
return f'{query_id} Q0 {doc_id} {rank}... | 657c59fea34e4aed2159337360c973dc99b53082 | 709,430 |
def StretchContrast(pixlist, minmin=0, maxmax=0xff):
""" Stretch the current image row to the maximum dynamic range with
minmin mapped to black(0x00) and maxmax mapped to white(0xff) and
all other pixel values stretched accordingly."""
if minmin < 0: minmin = 0 # pixel minimum is 0
if maxm... | 5f511b4a8bd053d503618767fee06597f1688619 | 709,431 |
def get_database_uri(application):
""" Returns database URI. Prefer SQLALCHEMY_DATABASE_URI over components."""
if application.config.get('SQLALCHEMY_DATABASE_URI'):
return application.config['SQLALCHEMY_DATABASE_URI']
return '{driver}://{username}:{password}@{host}:{port}/{name}'\
.form... | 6b04a9518798aa3392cdf41667e5edf1fdaa5125 | 709,432 |
def is_variant(title) -> bool:
"""
Check if an issue is variant cover.
"""
return "variant" in title.lower() | 5e0bab3030c069d7726bbc8c9909f561ed139cb8 | 709,433 |
from typing import Tuple
def _lex_single_line_comment(header: str) -> Tuple[str, str]:
"""
>>> _lex_single_line_comment("a=10")
('', 'a=10')
>>> _lex_single_line_comment("//comment\\nb=20")
('', 'b=20')
"""
if header[:2] != "//":
return "", header
line_end_pos = header.find("\n... | 4d562557db11c7279042e439a56cc7864fa259ef | 709,434 |
def default_marker_size(fmt):
""" Find a default matplotlib marker size such that different marker types
look roughly the same size.
"""
temp = fmt.replace('.-', '')
if '.' in temp:
ms = 10
elif 'D' in temp:
ms = 7
elif set(temp).intersection('<>^vd'):
ms = 9
else... | feebe9bdda47a2e041636f15c9b9595e5cd6b2cc | 709,435 |
def vote_smart_candidate_rating_filter(rating):
"""
Filter down the complete dict from Vote Smart to just the fields we use locally
:param rating:
:return:
"""
rating_filtered = {
'ratingId': rating.ratingId,
'rating': rating.rating,
'timeSpan': rating.times... | f4fec92e46f58444abb8dab56f28acc7e670aab0 | 709,436 |
def get_syntax(view):
""" get_syntax(view : sublime.View) -> str
>>> get_syntax(view)
'newLISP'
>>> get_syntax(view)
'Lisp'
Retuns current file syntax/language
"""
syntax = view.settings().get('syntax')
syntax = syntax.split('/')[-1].replace('.tmLanguage', '')
return syntax | a5be75f51de105af63ce53df7c3b7094537d28f3 | 709,437 |
import argparse
def commandline(args):
"""
Settings for the commandline arguments.
Returns the parsed arguments.
"""
parser = argparse.ArgumentParser(description='Checks the timestamps for files in a directory.')
parser.add_argument("-p", "--path", required=True,
help... | f3c1726e0dfde2bce6cd3e62a2300abbace7900e | 709,438 |
from typing import List
from typing import Dict
def seq_hist(seq_lens: List[int]) -> Dict[int, int]:
"""Returns a dict of sequence_length/count key/val pairs.
For each entry in the list of sequence lengths, tabulates
the frequency of appearance in the list and returns the
data as a dict. Useful for histogra... | 5778b7566d1b64e8db0e2dce6bbf53e06cdb196d | 709,439 |
import os
def make_ms_url( syndicate_host, syndicate_port, no_tls, urlpath="" ):
"""
Make a URL to the MS.
Return the URL.
"""
scheme = "https://"
default_port = 80
if no_tls:
default_port = 443
scheme = "http://"
if syndicate_port != default_port:
return scheme + ... | 4aec60c48285a8e8f8d58b18ea29928e338fa1bc | 709,440 |
def get_right_list_elements(result):
"""Some of the results are empty - therefore, the try-except.
Others are lists with more than one element and only specific
elements are relevant.
Args:
result (dict of lists): result of the xpath elements.
Returns:
dict of strs
"""
for... | b81e80363f82dfe43878b3d8cb319f7129ebfc50 | 709,441 |
def is_repo_in_config(config, repo, rev, hook_id):
"""Get if a repository is defined in a pre-commit configuration.
Parameters
----------
config : dict
Pre-commit configuration dictionary.
repo : str
Repository to search.
rev : str
Repository tag revision.
hook_id : Ho... | 855315c50f4bfe53a4f9b7a5d392bb539e364617 | 709,442 |
def split_dataframe(df, size=10*1024*1024):
"""Splits huge dataframes(CSVs) into smaller segments of given size in bytes"""
# size of each row
row_size = df.memory_usage().sum() / len(df)
# maximum number of rows in each segment
row_limit = int(size // row_size)
# number of segments
seg... | 46f34d388e6f596bfcf803b4569eb3015344bafb | 709,443 |
def qx_to_npx(df):
""" Return df with qx converted to npx.
"""
df = 1 - df
out = df.cumprod().shift()
for i in df.index:
out.loc[i, i] = 1
return out | 683a26f57dfb7ae1762df84f74186f0b88cb4688 | 709,444 |
def calculate_line_number(text):
"""Calculate line numbers in the text"""
return len([line for line in text.split("\n") if line.strip() != ""]) | f35533945203ec2f47a89e7072ddd9b172f5554b | 709,446 |
def convert_sentences(sentences, tokenizer):
"""
Truncate each sentence to 512 bpes in order to fit on BERT and convert it to bpes.
:param tokenizer: The BERT tokenizer we used in order convert each sentence to ids.
:param sentences: The tokenized sentences of the summary we are processing.
:return:... | 48cde2cba0af288bff9f49cb2ffc66dd22cfd952 | 709,447 |
def verify_spec(spec_utid, proxy_utid):
"""
For a specific unit test id (utid) compares the spec with the proxy
"""
results=''
for key in spec_utid:
results += '%s: spec=%s, proxy=%s (%s) *** ' % (key,spec_utid[key],proxy_utid[key],(spec_utid.get(key)==proxy_utid.get(key)))
return results | b9854e23f0d88ed4f9abcc0c16236a2d543b9eb0 | 709,448 |
def lammps_created_gsd(job):
"""Check if the mdtraj has converted the production to a gsd trajectory for the job."""
return job.isfile("trajectory-npt.gsd") | a66c899a20e9602098150f46067d5505572232c2 | 709,449 |
def deslugify_province(prov):
"""
Province slug to name, i.e. dashes to spaces and title case.
KZN is a special case.
"""
if prov == 'kwazulu-natal':
return 'KwaZulu-Natal'
return prov.replace('-', ' ').title() | 8e88ea7325c3b911495780b4437bc02784fbad82 | 709,450 |
import re
def parse_vectors(vectors):
""" Basic cleanup of vector or vectors
Strip out V from V#s. Similar to parse tables, this by no means guarantees
a valid entry, just helps with some standard input formats
Parameters
----------
vectors : list of str or str
A string or list of st... | d2161e45bae51db21d7668ea6008ddb9ada16c4e | 709,451 |
def serialize_skycoord(o):
"""
Serializes an :obj:`astropy.coordinates.SkyCoord`, for JSONification.
Args:
o (:obj:`astropy.coordinates.SkyCoord`): :obj:`SkyCoord` to be serialized.
Returns:
A dictionary that can be passed to :obj:`json.dumps`.
"""
representation = o.representa... | 52830d9243cac36573c358f1579987eb43435892 | 709,452 |
def redis_sentinel(create_sentinel, sentinel, loop):
"""Returns Redis Sentinel client instance."""
redis_sentinel = loop.run_until_complete(
create_sentinel([sentinel.tcp_address], timeout=2, loop=loop))
assert loop.run_until_complete(redis_sentinel.ping()) == b'PONG'
return redis_sentinel | 3b779c9ef73e3bc5949afadbace34a9dcca1273a | 709,453 |
def _diff_tail(msg):
"""`msg` is an arbitrary length difference "path", which could
be coming from any part of the mapping hierarchy and ending in any kind of
selector tree. The last item is always the change message: add, replace,
delete <blah>. The next to last should always be a selector key of s... | 224a4ca5f73b1f147c27599b62f0540480e40a0d | 709,454 |
import torch
def choice(x, a):
"""Generate a random sample from an array of given size."""
if torch.is_tensor(x):
return x[torch.randint(len(x), (a,))]
return x | af21321bcd12fe5f1a5eb59b8f0db14096899b5d | 709,455 |
def process_repl_args(args):
""" Process PANDA replay-related arguments.
"""
assert False, 'Not implemented yet.'
cmd = []
cmd.extend(['-display', 'none'])
return cmd
# p_test "${panda_rr}-rr-snp" f "trace memory snapshot"
# p_test "${panda_rr}-rr-nondet.log" f "trace nondet log"
# -... | 660495454f3b04f76d9aa0447262cb3a8c06b543 | 709,456 |
import pickle
def load_pickle(filename: str):
"""
Load a file from disk.
Parameters
----------
filename: str
Name of the file that is loaded.
Returns
-------
"""
return pickle.load(open(filename, 'rb')) | cae6710ba18664f244c55525c14a6bda0bea314d | 709,458 |
import os
def find_pssm_missing_proteins(fasta_dict, pssm_dir):
"""find_pssm_missing_proteins function finds the missing pssm files of the proteins in fasta file.
Args:
fasta_dict (dict): This is a dict of fasta file. The keys of fasta_dict are protein ids and
values are protein sequences.
... | d3ab3011216329ba7dc9a6d7449d930ea3e536c7 | 709,459 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.