content stringlengths 35 416k | sha1 stringlengths 40 40 | id int64 0 710k |
|---|---|---|
import hmac
import hashlib
def _hmac_sha256(key, msg):
"""
Generates a sha256 digest using the given key and message.
:param str key: starting key for the hash
:param str msg: message to be hashed
:returns: sha256 digest of msg as bytes, hashed using the given key
"""
return hmac.new(key, msg, hashli... | 0e85b6b26364fc06b8eb083e37e64803f33a9834 | 43,946 |
from typing import Dict
from typing import List
def convert_spin_to_list(spins: Dict) -> List:
"""Convert the Spin dictionary from the ssoCard into a list.
Add the spin index as parameter to the Spin entries.
Parameters
----------
spin : dict
The dictionary located at parameters.physical.... | 0d06523abe118305bbef13d681cb1d811628edda | 43,947 |
import os
def get_file_class(path: str) -> str:
"""
Return the type of the file as a human readable string.
"""
if os.path.islink(path):
return "Link"
elif os.path.isfile(path):
return "File"
elif os.path.isdir(path):
return "Directory"
return "Unknown" | 412ad938fb84d71e600ea397e8bffbfe12dc9e01 | 43,948 |
import re
def get_protein_sequence(entry):
"""Gets the sequence from the entry. This method
assumes that the sequence is ALWAYS at the end of
the entry.
"""
sequence_section = re.split('SQ [ ]+', entry)[1]
newline_split_sequence = sequence_section.split('\n')[1:]
return ''.join(newline_spl... | 4196ff9bee380d171dd406eb1088d5879ac588cb | 43,949 |
from typing import Dict
from typing import Any
def shim_store_v0(v0: Dict[str, Any], master_address: str) -> Dict[str, Any]:
"""
v1 schema is just a bit more nesting to support multiple masters.
"""
v1 = {"version": 1, "masters": {master_address: v0}}
return v1 | c4fa2b97b31981aaadc0e8999aae62b9e1843645 | 43,950 |
def _get_scripts_resource(pe):
"""Return the PYTHONSCRIPT resource entry."""
res = None
for entry in pe.DIRECTORY_ENTRY_RESOURCE.entries:
if entry.name and entry.name.string == b"PYTHONSCRIPT":
res = entry.directory.entries[0].directory.entries[0]
break
return res | 3bef22589a2793b09d89c4f4552f12f1583c9274 | 43,952 |
import logging
def viosupgrade_query(module):
"""
Query to get the status of the upgrade for each target
runs: viosupgrade -q { [-n hostname | -f filename] }
The caller must ensure either the filename or the target list is set.
args:
module the Ansible module
module.param used:
... | 4f3711642963ae5c426c0dd1e42e3386b9585d03 | 43,953 |
def messages_get(body, connection):
"""A stored join function that gets all the currently registered commands,
their relevant metadata, the name of the client they are associated with
and the message, if any. This is returned to the requestor in a JSON
format for further processing."""
cur = connect... | 4c01b2d7901e6de8ffb9fbd7fc70e531674db162 | 43,954 |
import os
def get_filename_root(directoryPath):
""" guess the prefix of texture filenames """
# guess the filename root by figuring out the full filename for 'albedo'
albedo_path = next(f for f in os.listdir(directoryPath) if "albedo" in f.lower())
if albedo_path == None:
print('Could not find... | 783b79db6790bcd37a41d92dd618341fc59bcc5a | 43,955 |
from typing import List
from typing import Any
from typing import Tuple
def pad(x: List[List[Any]],
pad: int) -> Tuple[List[List[int]], List[List[bool]]]:
"""Pad 2d list x based on max length. Also generate a mask to access valid
values in the padded list.
Args:
x (List[List[A... | 014ab67b5ff3337f700cf8c39991f91a8ff23dd2 | 43,959 |
def get_last_slackblocks_message_text(messages) -> str:
"""
Utility methods for retrieving the text content of the most recent message.
Assumes that message was constructed using a single SlackBlocks SectionBlock with
at least one attachment.
:raises KeyError: likely because the last messages was no... | 63755b319445ca9b030c4a244da990f39a4b33bf | 43,960 |
import uuid
def gen_uid():
"""
Generate CM UID
"""
return {'return':0,
'uid':uuid.uuid4().hex[:16]} | 3a5364262801b94bd998cec7601cf60657784e7c | 43,962 |
from typing import Dict
def config_get_policy(config: Dict[str, str]):
"""Return the effective SELinux policy
Checks if SELinux is enabled and if so returns the
policy; otherwise `None` is returned.
"""
enabled = config.get('SELINUX', 'disabled')
if enabled not in ['enforcing', 'permissive']:... | 36310d1cb67bd6288c5db4c0f240a24c11f09b81 | 43,963 |
def areDisplayOutputsCloned(outputs):
"""returns True whether more than one display output points at the same
framebuffer address
:outputs: array
:returns: boolean
"""
for index,output in enumerate(outputs):
if index > 0:
if output['x'] != outputs[index-1]['x'] or output['y... | e576e99d057e8ec3d622c5d7b09b553cc0e08021 | 43,965 |
def _gr_call_ ( graph , x , spline = None , opts = '' ) :
""" Use graph as function
>>> graph = ...
>>> y = graph ( 0.2 )
"""
## if not spline : spline = ROOT.MakeNullPointer(ROOT.TSpline)
return graph.Eval ( float( x ) , spline , opts ) | 51ab14baf25a772823b7b4d06d9cfa45e9ce8305 | 43,968 |
def ebitda(gross_profit, sg_a):
"""
Computes EBITDA(earnings before interest, tax, depreciation and amortizatin).
Parameters
----------
gross_profit : int or float
Gross profit for the period
sg_a : int or float
Selling, general and administrative cost
Returns
-------
... | 4de26c7535d6c76e2945af2f59e5aee8ab47afe9 | 43,969 |
def verctor_add(a, b):
"""
two vector add
a: list
b: list
return: list
"""
return [a[i]+b[i] for i in range(len(a))] | 86291f0b510454ea759d58e926390b778324587e | 43,970 |
def king(r, rc, rt, sigma_0, alpha=2):
"""
See http://iopscience.iop.org/1538-3881/139/6/2097/fulltext/
Parameters
----------
r: float
radius
rc: float
core radius
rt: float
truncation radius
sigma_0: float
central density
"""
def z(x):
r... | d5df62bfb6e2973d394fe65c77b24160eccfc125 | 43,971 |
from pathlib import Path
import glob
import re
def increment_path(path, exist_ok=False):
""" Automatically increment path, i.e. runs/exp --> runs/exp0, runs/exp1 etc.
Args:
path (str or pathlib.Path): f"{model_dir}/{args.name}".
exist_ok (bool): whether increment path (increment if False).
... | eaffc47b83ae969242b5e7af1389658a25873f1c | 43,972 |
def calculate_production_time(form_data, blueprint):
""" Returns the production time for the given blueprint. """
"""
The following data is taken into account while calculation:
1. Players industry skill level
2. Players hardwirings
3. Installation slot production time modifier
4. Blueprin... | 1538895f7f374ea4c404dc6ea696dde9f476b47b | 43,973 |
def mk_rule_key(rule):
""" Convert a rule tuple to a hyphen-separated string.
"""
return '{}-{}-{}-{}'.format(rule.source_institution,
rule.destination_institution,
rule.subject_area,
rule.group_number) | ca7ffddd023eaf10f6a50532e954c03ced182d29 | 43,976 |
import json
def getSuffixes():
""" get the suffixes from tibetan-spellchecker """
suffixesData = json.load(open('tibetan-spellchecker/syllables/suffixes.json'))
print(suffixesData)
return suffixesData | ff0f5a6c968865eed54bd486b0feb473506794e8 | 43,977 |
import re
def __replace_all_envs_in_str(content, env):
"""
Docker does not allow to replace volume names or service names, so we do it by hand
"""
all_params = re.findall(r'\$\{[^\}]*?\}', content)
for param in all_params:
name = param
name = name.replace("${", "")
name = n... | fb5fc1f87a2b665450a9dd684a68efa51d9c4898 | 43,979 |
def is_mt_str(my_str) -> bool:
"""Check to see if the given input is an empty string
Function that checks the given parameter my_str to see if it is an empty
string. Uses the innate identity __eq__ to check.
:param my_str: String to check if it is empty
:type my_str: str
:return: Boolean indic... | 68c044537edd522c78565b8fbc4b0a1d1986f4aa | 43,980 |
import pickle
def get_original_config(dirname: str) -> dict:
"""
Get original model config used with hydra
Args:
dirname (str): model directory
Returns:
dict: config dict
"""
config = pickle.load(open(f"{dirname}/tb/config.pkl", "rb"))
return config | 0dc54883bd508e8e95905a6ba67e7ec7cdb66d82 | 43,981 |
import six
def to_bytestring(data):
"""
Convert data to a (utf-8 encoded) byte-string if it isn't a byte-string
already.
"""
if not isinstance(data, six.binary_type):
data = six.text_type(data).encode('utf-8')
return data | a516417979a2cca0ae71a39cb8b504c2395ad2c4 | 43,982 |
import numpy
def get_savings(quantities, net_costs, target_ppu):
"""
For a given target price-per-unit calculate how much would be saved by each
practice if they had achieved that price-per-unit
"""
target_costs = quantities * target_ppu
savings = net_costs - target_costs
# Replace any neg... | 3ecd1be8bb7b6e2b4e677bf884930b5b7c43df9e | 43,983 |
def get_verbose_field_name(instance, field_name):
"""
Returns verbose_name for a field.
Usage:
{% get_verbose_field_name test_instance "name" %}
Thanks to pankaj28843,
https://stackoverflow.com/questions/14496978/fields-verbose-name-in-templates#14498938
"""
return instance._meta.ge... | 4bbeec943f84cc7f94343895e4a256941be922b6 | 43,985 |
from typing import Any
from typing import Union
def remove_duplicates_in_list_of_dict(o: dict[Any, Union[Any, list]]) -> dict:
"""
Remove duplicates in values of `o` of type `list`.
"""
return {
k: (list(dict.fromkeys(v)) if isinstance(v, list) else v) for k, v in o.items()
} | 5e97aa99b7494bf6270a04985db3c74727015601 | 43,989 |
import argparse
def cliparse():
"""sets up and parses the cli arguments"""
parser = argparse.ArgumentParser(description="Setup stalker database in "
"rethinkdb for stalkerd")
parser.add_argument("--host", help="hostname to connect to rethinkdb on",
... | 857612a223de1903db9658f04e37d444dd40e803 | 43,991 |
def point_to_node(gfa_, node_id):
"""Check if the given node_id point to a node in the gfa graph.
"""
return gfa_.nodes(identifier = node_id) != None | 16053e89556ce0e097f1dc62c02d5e313faf89eb | 43,993 |
import copy
def filter_dict(target_dict, keys_to_filter):
"""Filters key(s) from top level of a dict
Args:
target_dict (dict): the dictionary to filter
keys_to_filter (list, tuple, str): set of keys to filter
Returns:
A filtered copy of target_dict
"""
assert isinstance(tar... | 70a6577c30de54c8d826aae8ba7e76b3b07412f2 | 43,994 |
def greater_than_or_equal_to(x, y) -> bool:
"""x (actual), y (requirement)"""
return x >= y | 3a31bbf96129ed77d4d4fcbea42ee716a72b945e | 43,995 |
def create_pinhole_camera(height, width):
"""
Creates a pinhole camera according to height and width, assuming the principal point is in the center of the image
"""
cx = (width - 1) / 2
cy = (height - 1) / 2
f = max(cx, cy)
return f, cx, cy | 6dc23f777b97bcce3cc4b32c36f473fe0c507d0f | 43,996 |
from typing import List
import pathlib
def get_folder_paths(data_dir_path: str, species: List[str]) -> List[pathlib.Path]:
""" Get folder paths that match the species """
data_dir = pathlib.Path(data_dir_path)
if "all" in species:
return sorted(list(data_dir.glob(f"*/")))
folder_paths = []
... | 188bbe23ffc00eca304b4f3faf4a85a62dec7f0b | 43,998 |
def table(fn):
"""Generate a 12-bit lookup table."""
ret = []
for n in range(0, 2**12):
pre = "\n\t" if n % 8 == 0 else " "
pre = "\t" if n == 0 else pre
ret.append("{}0x{:04X}U,".format(pre, fn(n)))
return "".join(ret) | 2fd822150317373947fdf101cc3b034eb5e65ca9 | 43,999 |
from typing import List
def _replace_pw_references(alias_cmd: str, pw_args: List[str]) -> str:
"""Replace all occurrences of pw@ with the path to the pw script (argv[0]) plus all pw options"""
replacement = " ".join(pw_args) + " "
return alias_cmd.replace("pw@", replacement) | 9442bbc61389e3d0e6303668463cbf29aad52a1b | 44,000 |
def single_state_time_spent(state_dict, state):
"""
Given a ticket's state dictionary, returns how much time it spent
in the given `state`.
Assumes state_dict has the key `state` present.
"""
# Measurement 2: Average Time Spent in Scrum Team Backlog
# For the PRs that need to be reviewed by... | 94534ffd8958fe9c9d7ae3ec6a317108faad766d | 44,001 |
from typing import Union
def clamp(value: Union[float, int], lower: Union[float, int], upper: Union[float, int]) -> Union[float, int]:
"""
Clamp a number
Same as min(max((value, lower), higher)
Args:
value (Union[float, int]): Value to clamp
lower (Union[float, int]): min value
... | 48b4e6c81219385b0c9d608459bea02370b63880 | 44,002 |
def _scale8_video_LEAVING_R1_DIRTY(i, scale):
"""Internal Use Only"""
nonzeroscale = 0
if scale != 0:
nonzeroscale = 1
if i != 0:
i = ((i * scale) >> 8) + nonzeroscale
return i | e9425d2e92e5a754b35c54b95068a7aef7de33b1 | 44,004 |
import pathlib
def read_file(file_name='README.md', encoding='utf-8'):
"""
读取本地文件
:param file_name: 文件名
:param encoding: 文件编码,默认utf-8
:return:
"""
return pathlib.Path(file_name).open('r', encoding=encoding).read() | cd137b3bf44bf2a1116d7e879941ea9a7779ee8f | 44,006 |
def create(name, playbook, cluster_id, server_ids, hints, client):
"""Create new playbook configuration."""
cluster_id = str(cluster_id)
server_ids = [str(item) for item in server_ids]
return client.create_playbook_configuration(
name, cluster_id, playbook, server_ids, hints
) | a5ec5e359bd602038463b188b911ae8e31bfb752 | 44,007 |
import json
def file_open_json(file):
"""Reads json file from the location input
:param file: path of the json file
:type file: String
:return: contents of json
:rtype: dictionary(dict)
:raise Exception: Throws exception if unable to load file
"""
try:
with open(file) as f:
... | 99cfc9413880698260a7802b8917adfe4111b1e3 | 44,009 |
def decorate_class(patcher):
"""Generic way to decorate all methods in a class. Accepts the decorator function as it's argument. Note that I am
using the callable function, which wasn't included in python 3.0 and 3.1."""
def decorate(cls):
for name, attr in cls.__dict__.items():
if calla... | 6b2f7961abf1bd4325ad539038e767050b0dd7ff | 44,010 |
def read_block(fi):
"""Read and returns one block of non-empty lines from an input stream (stripped lines are returned in a list)"""
block = []
for line in fi:
line = line.strip()
if not line and len(block):
break
block.append(line)
return block | ac5852e74bac7ffc084300d7a0b2ee8e3f51ccb6 | 44,011 |
def __compare_table_headers(table_1, table_2):
"""
Step 2_2: Comparing table header (first row) values on each table
"""
col_num = len(table_1.rows[0].cells)
for i in range(0,col_num-1):
if table_1.rows[0].cells[i] != table_2.rows[0].cells[i]:
return False
return True | a1ed0906c76c350b46daf081efd269414fbcbbc2 | 44,013 |
def details_route(method, uri, is_list=False):
"""A decorator for Endpoint classes to define a custom URI.
Extends the endpoint's details route. For example, suppose the following
method was defined on an endpoint with the base uri as `foo`:
::
@details_route('GET', 'bar')
def bar_cal... | 5aacde4d3a62fdf1e4a162b9cb79dd11e9db34f4 | 44,014 |
from typing import List
def delete_duplicates(A: List[int]) -> List[int]:
"""
Time Complexity: O(n)
:param A: List[int]
:return: List[int]
"""
result = []
for i in A:
if not result:
result.append(i)
else:
if i != result[-1] and i not in result:
... | a3a3f1e1d4cf5e53aea909803cd50710e9661d59 | 44,016 |
import os
def readMarkers(map):
"""
Read markers from local file
"""
mapfile='plugins/mapmark/mapdata/markers/%s.dat' % map
if os.path.isfile(mapfile):
fd=open(mapfile,'r')
line=fd.readline()
markerlist=[]
while line:
line=fd.readline().strip()
... | c4850d36cab7f88a0bb3e77f9af6c07291d6d414 | 44,017 |
import subprocess
def get_kernel_version():
""" Return a str containing the kernel version.
"""
proc = subprocess.Popen(["cat /proc/version"],
stdout=subprocess.PIPE, shell=True)
(output, error) = proc.communicate()
version = output.decode("utf-8").split()[2]
return... | f0ec5ddce13fdf3eeb13df26c5f0352e24200b3e | 44,018 |
import torch
def is_supported_instance(module):
"""Internal auxiliary function"""
if isinstance(module, (torch.nn.Conv2d, torch.nn.ReLU, torch.nn.PReLU, torch.nn.ELU, \
torch.nn.LeakyReLU, torch.nn.ReLU6, torch.nn.Linear, torch.nn.MaxPool2d, \
torch.nn.Avg... | 8e9ac71a6466bc9e5f7ccdef8fd8c6b893a4148f | 44,019 |
import sympy
def handle_gcd_lcm(f, args):
"""
Return the result of gcd() or lcm(), as UnevaluatedExpr
f: str - name of function ("gcd" or "lcm")
args: List[Expr] - list of function arguments
"""
args = tuple(map(sympy.nsimplify, args))
# gcd() and lcm() don't support evaluate=False
... | 34ecae7681e1ba7f18ab00969703fec6a14e864a | 44,020 |
def check_geojson_is_polygon(geojson):
"""Checking geojson is polygon"""
types = ["Polygon", "MultiPolygon"]
for feature in geojson['features']:
if feature['geometry'] and feature['geometry']['type'] not in types:
return False
return True | cd0c20ef9fb9c723c23ad2b6a5fadfc29ceaa05c | 44,021 |
def extract_from(bibtex_db):
"""Get indentifer(s) from bibtex data
Returns a list of adsabs queries
"""
result = []
for i in bibtex_db.entries:
if "ID" in i:
if len(i["ID"]) == 19:
result.append(f'identifier:{i["ID"]}')
elif "doi" in i:
resu... | ea9f2b1cb0e29c5e5bddfb902d17853f93e6b4b9 | 44,022 |
import os
def HQfilterReads(path, Q ):
""" passes the commands of NanoFilt for generating a fastq file only with better quality reads
Requires the entery of full path of fastq reads file and the minimum quality to filter (Q)
Also """
Output_file = path.split(".")[0] + "_HQonly.fastq.gz"
commands = "gunzip ... | fcdea1c840004d5e7a6e5cd6499f5611cac4233d | 44,023 |
import argparse
import sys
def parse_arguments():
"""Parse arguments passed to script"""
parser = argparse.ArgumentParser(description=
"Check the set of jobs on the scheduler queue and \
\npresent the data in a clean, readable format. \
\n**Requires either '... | fd3962902c878b63833ff8cba6a07c9b6cc353f2 | 44,024 |
def get_sent_id(corpus_id,
doc_id,
naf_sent_id,
fill_width=8):
"""
:param corpus_id:
:param doc_id:
:param naf_sent_id:
:return:
"""
nltk_sent_id = ''
for id_ in [corpus_id, doc_id, naf_sent_id]:
id_filled = str(id_).zfill(fill_wi... | b6cdf2ec39fc88ad5abf1a713280a7edc47eb043 | 44,025 |
def get_author_name_and_id(soup):
"""
Get author name and id.
Examples
--------
>>> a_tag = '<a class="topic__author-link" href="/author_id">author_name</a>'
>>> soup = make_soup(a_tag)
>>> get_author_name_and_id(soup)
('author_name', 'author_id')
"""
author = soup.select('a.to... | d7ecb9c56337d38541dc9cfd63a4976ab8e5acda | 44,026 |
def function_namespace(f):
"""
Attempts to returns unique namespace for function
"""
if hasattr(f, 'im_func'):
return '%s.%s.%s' % (f.__module__, f.im_class.__name__, f.__name__)
else:
return '%s.%s' % (f.__module__, f.__name__) | 5951d2108fab56303791e6f3bcf08a43d0adc8ad | 44,027 |
def levenshtein(word_1, word_2):
"""
arg :
listRef --> list of string(word)
listComp --> list of string(word)
return :
integer
Description :
return the distance between 2 list of string
"""
char_list_1 = [l for l in word_... | 6409f08d34564f7fbbef6c06c39f4576b716eb09 | 44,028 |
def getBackend(x):
"""
This function determines the the backend of a given variable
"""
if 'numpy' in str(x.__class__):
return 'numpy'
elif 'arrayfire' in str(x.__class__):
return 'arrayfire'
elif 'torch' in str(x.__class__):
return 'torch'
elif str(x.__class__) in [
... | b7736b930b4af204b2e0d6ee62aca2af70907a6c | 44,029 |
def paginator(context, adjacent_pages=3):
"""
To be used in conjunction with the object_list generic view.
Adds pagination context variables for use in displaying first, adjacent and
last page links in addition to those created by the object_list generic
view.
"""
page = context['page_obj']
... | e26758417f194f8f69899b7b29c2036874c95108 | 44,030 |
import re
def _find_sgRNA(guide_sequence, target_sequence, strand):
"""
Find start, stop position of a sgRNA in a target sequence.
Parameters:
-----------
guide_sequence
target_sequence
Returns:
--------
start, stop
"""
guide_span = re.search(guide_sequence, target_seq... | 3b478908145a307262b7303bfc21320591b374db | 44,031 |
import struct
def getheader(filename, gtype):
"""Read header data from Gadget data file 'filename' with Gadget file
type 'gtype'. Returns a dictionary with loaded values and filename."""
DESC = '=I4sII' # struct formatting string
HEAD = '=I6I6dddii6iiiddddii6ii60xI' ... | daca7603362e8804736b4fae0ed95e772a183129 | 44,032 |
def gradient_add(grad_1, grad_2, param, verbose=0):
"""
Sum two gradients
:param grad_1: (TensorFlow Tensor) The first gradient
:param grad_2: (TensorFlow Tensor) The second gradient
:param param: (TensorFlow parameters) The trainable parameters
:param verbose: (int) verbosity level
:return... | e9e620c06edaf124830b0aec78604d653565860c | 44,033 |
def ROC_curve_compute(ROC, compute_area=False):
"""Compute the ROC curve and its area from the given ROC object.
Parameters
----------
ROC : dict
A ROC curve object created with ROC_curve_init.
compute_area : bool
If True, compute the area under the ROC curve (between 0.5 and 1).
R... | 555aab3e5798a5ef59c994d6f918074cbb34cce7 | 44,034 |
def _normalize_item(item, shape):
"""
>>> def print_item(item):
... print('[' + ', '.join([(f'{i.start if i.start is not None else ""}:{i.stop if i.stop is not None else ""}' if isinstance(i, slice) else str(i)) for i in item]) + ']')
>>> print_item((0, slice(None), slice(1), slice(5, 10)))
[0, ... | ddbf34783268ddc4bca59cb3af397ee0a6c1e083 | 44,035 |
import os
import subprocess
import sys
def check_rDNA_copy_number(ref, output, logger):
"""ensure reference has multiple rDNAs
Using barrnap to check that there are multiple rDNA copies
in the reference genome
"""
os.makedirs(os.path.join(output, "barrnap_reference"), exist_ok=True)
barroutput... | 44b7089fafbb30d82013e689c40699b004c9e8d5 | 44,036 |
def _remove_model_weights(model: dict, to_delete=None) -> dict:
"""
Removes certain weights of a given model. The weights to remove are given by the to_delete argument.
If there is also a bias term, that is deleted as well.
Args:
model: Loaded detectron2 model
to_delete (list): Names of ... | 70f88910db2fae52893869fc7acda8161b5df61e | 44,037 |
def overlaps(df, idx):
"""
Check if the note at the given index in the given dataframe overlaps any
other notes in the dataframe.
Parameters
----------
df : pd.DataFrame
The DataFrame to check for overlaps.
idx : int
The index of the note within df that might overlap.
... | 382c21c7b2232b40ce7c563d677afa8a70f5bfcc | 44,038 |
from typing import List
from typing import Tuple
def remove_pads(y_true: List[str], y_pred: List[str]) -> Tuple[List[str], List[str]]:
"""
Takes as input two lists of strings corresponding to the predicted and actual tags
and returns the same lists except that any <pad> tags in y_true are removed and the ... | fb660e2aa31c04be1ea77a57ac39b681786389f3 | 44,039 |
def chop(x, y, ymax=None, ymin=None, xmin=None, xmax=None):
"""Chops x, y."""
if xmax:
y = y[x < xmax]
x = x[x < xmax]
if xmin:
y = y[x > xmin]
x = x[x > xmin]
if ymax:
x = x[y < ymax]
y = y[y < ymax]
if ymin:
x = x[y > ymin]
y = y[... | ce3e2b212e4a132b242135485eeaf6b89978220f | 44,040 |
def splinter_headless():
"""Run Chrome in headless mode, for faster tests."""
return True | 3cf2ea16be08ef0405d250462506341c481b2693 | 44,041 |
from typing import OrderedDict
def provide_trigger_dict():
"""Provide a dictionnary mapping str names to byte values."""
trigger_dict = OrderedDict()
# At the beginning and end of the experiment ... take these triggers to
# crop the meaningful EEG data. Make sure to include some time BEFORE and
#... | ea8ba1c5de5071b2cdb7764effb667a619ef3f01 | 44,042 |
import requests
def request_url(url, headers):
"""fetch html page via request package"""
r = requests.get(url, headers = headers)
if r.status_code == 200:
return r.content
return False | 8344a52f3482bf465db172a4158a9e34bf3e346a | 44,043 |
def corr(result, result2, result3):
"""
Computes the correlation between the three regression methods by taking squared differences from averages in each category and then averaging those results.
Interpret this as a smaller # meaning a better score / agreement.
Parameters
----------
result:... | 9b7c00af5e5b03483b1e18565f5b590f7a51d745 | 44,044 |
from typing import Union
import builtins
import importlib
def _load_exception_class(import_specifier: str) -> Union[Exception, None]:
"""Load an exception class to be used for filtering Sentry events.
This function takes a string representation of an exception class to be filtered out
of sending to Sentr... | a1add93a1f637caad974593536e00063eca14f34 | 44,045 |
def has_missing_keys(minimum_keys, actual_keys, name):
"""Returns an error if expected keys are not present.
Do not warn about unexpected keys.
"""
actual_keys = frozenset(actual_keys)
missing = minimum_keys - actual_keys
if missing:
msg_missing = (' missing: %s' % sorted(missing)) if missing else ''
... | 22b6fda9cb5e2b8b5a3e1227caf4f2e0679d4ab4 | 44,046 |
def split_id(url_id):
"""
Data for the response is encoded in the ID URL
"""
parts = url_id.split("/")
data = {}
for i in range(1,len(parts)-1,2):
data[parts[i]] = parts[i + 1]
return data | 27579d7a0f8181ec5e141c7159490781bd130fa7 | 44,047 |
def yaml_time_serializer(dumper, data):
"""
This function is required to serialize datetime.time as string objects
when working with YAML as output format.
"""
return dumper.represent_scalar('tag:yaml.org,2002:str', str(data)) | b6c6a5d44a57391ca440704537cb3c449900d0cb | 44,049 |
def year_range(y_start, y_end):
"""Format a year range."""
year = y_start or ''
if y_end:
year += '–' + y_end
return year | ddd911e61d86e11f8f79de24a99620319ad605bd | 44,050 |
def same_keys(a, b):
"""Determine if the dicts a and b have the same keys in them"""
for ak in a.keys():
if ak not in b:
return False
for bk in b.keys():
if bk not in a:
return False
return True | 841a6d715fdfcefb9a2557e01b7ccb586fd62c06 | 44,053 |
def insert_fixed_parameters(parameters_dict, fixed_parameters):
"""Insert the fixed parameters into the parameters_dict."""
if fixed_parameters is not None:
for key, value in fixed_parameters.items():
parameters_dict[key] = value
return parameters_dict | 6c46f6bc7be1a6832dfeeb0007bd448bebfb7e1e | 44,054 |
def line(tam=43):
"""
Returns the number of the argument size. Remembering that the size is in pixels.
"""
return '-' * tam | d0b5179e370349226a21a4eb6139a9e587550f08 | 44,056 |
from pathlib import Path
def pyyaml_path_constructor(loader, node):
"""Helper method to load Path tag in PyYAML."""
value = loader.construct_scalar(node)
return Path(value) | e8740a9abe3e0d8b5ab27095eb8a89cb2b6f1af1 | 44,057 |
def filter_state(hdf_file_content, link_id, state='State0'):
"""Get the time series of a state for a link
Parameters
----------
hdf_file_content : np.array
data in the h5 file as a numpy array
link_id : int
link_id to be filtered
state : str , ex. State0(default), Stat... | 3ca64fcd455edfa0c5915fb1caba985370ce7dcc | 44,058 |
def _get_metric_prefix(power: int, default: str = "") -> str:
"""Return the metric prefix for the power.
Args:
power (int): The power whose metric prefix will be returned.
default (str): The default value to return if an exact match is
not found.
Returns:
str: The metri... | b35f5ff3691eafe87274a685d41f9c57161df1fb | 44,060 |
def get_average_att_network(networks, select='accuracy'):
"""Get the average accuracy for a group of networks.
Args:
networks (list): List of networks
Returns:
float: The average accuracy of a population of networks.
"""
total = 0
for network in networks:
if select == 'ac... | 78d14f731b3b10179abb5d85ff1150c4e784c94d | 44,061 |
def parse_size(size):
"""
Converts a size specified as '800x600-fit' to a list like [800, 600]
and a string 'fit'. The strings in the error messages are really for the
developer so they don't need to be translated.
"""
first_split = size.split('-')
if len(first_split) != 2:
raise Att... | 7a3ee86a48e320df70dec8f2a8fcb72bbaf377fe | 44,062 |
def split_writable_text(encoder, text, encoding):
"""Splits off as many characters from the begnning of text as
are writable with "encoding". Returns a 2-tuple (writable, rest).
"""
if not encoding:
return None, text
for idx, char in enumerate(text):
if encoder.can_encode(encoding, ... | c959aedca9085947043d676c8cd8420105e7af97 | 44,063 |
def rxn_chg_mult(rxn_muls, rxn_chgs):
""" evaluate the ts multiplicity from the multiplicities
of the reactants and products
"""
nrcts, nprds = len(rxn_muls[0]), len(rxn_muls[1])
# Set the multiplicities
rct_spin_sum, prd_spin_sum = 0, 0
rct_muls, prd_muls = [], []
if nrcts == 1 and... | c0beefb52e06f47fe117d02b889795a57f0d4f32 | 44,064 |
def get_all_lib_paths(project):
"""."""
all_lib_paths = []
# if project.is_arduino_project():
# core_src_path = selected.get_build_core_src_path(arduino_info)
# variant_path = selected.get_build_variant_path(arduino_info)
# all_lib_paths.append(core_src_path)
# all_lib_paths.... | 93483c05e94e8173aec30671eac781bad2e37594 | 44,065 |
from typing import OrderedDict
def backwards_state_dict(state_dict):
"""
Modify the state dict of older models for backwards compatibility
Parameters
----------
state_dict : dict
Model state dict with pretrained weights
Returns
-------
state_dict : dict
Updated model ... | ed52ca5897c25eed9a1d36b8aca6a14fb9f6a48e | 44,066 |
def are_attributes_valid(attributes):
""" Determine if attributes provided are dict or not.
Args:
attributes: User attributes which need to be validated.
Returns:
Boolean depending upon whether attributes are in valid format or not.
"""
return type(attributes) is dict | 7f9adebbbe64716333ee0114ffe1f63d2100e6c8 | 44,067 |
def chi_squared(text, standard, key_length):
"""
Finds the Chi-Squared value of the text
based on the standard distribution of letters
@param text is the text you are analyzing
@standard is the dictionary of letter : frequency
@key_length is the length of the key
@returns a Chi-Squared valu... | 20c83cfe136592a15ade9f5d55eb8becb9e559b4 | 44,069 |
import shutil
def desk_per_Win(path):
"""
path: the disk that you want to check, example: path = 'C:'
return: the percentage of the free space on that disk
"""
# Get the disk usage statistics
# about the given path
stat = shutil.disk_usage(path)
# Print disk usage statistics
... | ac6a8b76b46fbf6a9ceeb9f48b01543857a35f59 | 44,070 |
def find_first_non_none(positions):
"""Given a list of positions, find the index and value of first non-none element.
This method is specifically designed for pysam, which has a weird way of returning
the reference positions. If they are mismatched/softmasked it returns None
when fetched using get_refe... | ee020b29a50149d0cee1321a42095d770612d680 | 44,071 |
def visit_url(context, path):
"""Recursively visits the JSON response from a URL, driven by metadata
to follow links and process data."""
root = dict(context) # Makes a copy.
root["run"] = {}
root["run"]["data"] = root["retrieve_funcs"]["retrieve_data"](context, path)
root["run"]["meta"] = ro... | fd9b75dc379a2552efdf9d1fb8a46d957e42a94f | 44,072 |
def remove_bad_chars(input_string, bad_chars):
"""
:param input_string: string from which the bad characters are to be removed
:param bad_chars: list of bad characters
:return: string after removing bad characters
"""
translation_map = dict((c, ' ') for c in bad_chars)
return input_string.tr... | 3c7f530bd9c784367f984c9bbcaa686cd177bdd8 | 44,073 |
def normalize_to_str(value):
"""
unicode convert to string
"""
if hasattr(value, "encode") and isinstance(value, str):
return value.encode("utf-8")
return value | 0ae98c5610d19a8e1cb2e2de1066960539a2fb9f | 44,074 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.