content stringlengths 39 14.9k | sha1 stringlengths 40 40 | id int64 0 710k |
|---|---|---|
def get_data_meta_path(either_file_path: str) -> tuple:
"""get either a meta o rr binary file path and return both as a tuple
Arguments:
either_file_path {str} -- path of a meta/binary file
Returns:
[type] -- (binary_path, meta_path)
"""
file_stripped = '.'.join(either_file_path.... | 0456186cd99d5899e2433ac9e44ba0424077bcc0 | 707,218 |
def get_local_info(hass):
"""Get HA's local location config."""
latitude = hass.config.latitude
longitude = hass.config.longitude
timezone = str(hass.config.time_zone)
elevation = hass.config.elevation
return latitude, longitude, timezone, elevation | 1fdefbad46c7cdb58abdc36f7d8799aa1e4af87c | 707,222 |
def get_word_combinations(word):
"""
'one-two-three'
=>
['one', 'two', 'three', 'onetwo', 'twothree', 'onetwothree']
"""
permutations = []
parts = [part for part in word.split(u'-') if part]
for count in range(1, len(parts) + 1):
for index in range(len(parts) - count + 1):
... | 5a4c042cc0f3dedb297e2513bf638eac4278e0a6 | 707,230 |
def dice_counts(dice):
"""Make a dictionary of how many of each value are in the dice """
return {x: dice.count(x) for x in range(1, 7)} | 427703283b5c0cb621e25f16a1c1f2436642fa9f | 707,233 |
from typing import List
def dict_to_kvp(dictionary: dict) -> List[tuple]:
"""
Converts a dictionary to a list of tuples where each tuple has the key and value
of each dictionary item
:param dictionary: Dictionary to convert
:return: List of Key-Value Pairs
"""
return [(k, v) for k, v in d... | 2b856ebb218884a4975d316bebe27546070f2083 | 707,236 |
import re
def _get_ip_from_response(response):
"""
Filter ipv4 addresses from string.
Parameters
----------
response: str
String with ipv4 addresses.
Returns
-------
list: list with ip4 addresses.
"""
ip = re.findall(r'\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)... | ac36a3b729b0ce4ba13a6db550a71276319cbd70 | 707,238 |
def read_csv_to_data(path: str, delimiter: str = ",", headers: list = []):
"""A zero-dependancy helper method to read a csv file
Given the path to a csv file, read data row-wise. This data may be later converted to a dict of lists if needed (column-wise).
Args:
path (str): Path to csv file
... | f60e163e770680efd1f8944becd79a0dd7ceaa08 | 707,240 |
def getInputShape(model):
"""
Gets the shape when there is a single input.
Return:
Numeric dimensions, omits dimensions that have no value. eg batch
size.
"""
s = []
for dim in model.input.shape:
if dim.value:
s.append(dim.value)
... | 628f61a995784b9be79816a5bbcde2f8204640be | 707,243 |
def kewley_agn_oi(log_oi_ha):
"""Seyfert/LINER classification line for log([OI]/Ha)."""
return 1.18 * log_oi_ha + 1.30 | 5e6b71742bec307ad609d855cced80ae08e5c35c | 707,244 |
def multiply_str(char, times):
"""
Return multiplied character in string
"""
return char * times | cc69f0e16cba1b8c256301567905e861c05291ea | 707,247 |
def calories_per_item(hundr, weight, number_cookies, output_type):
"""
>>> calories_per_item(430, 0.3, 20, 0)
'One item has 64.5 kcal.'
>>> calories_per_item(430, 0.3, 20, 1)
'One item has 64.5 Calories.'
>>> calories_per_item(1, 1000, 10, 1)
'One item has 1000.0 Calories.'
>>> calories_... | 9ca16eee8aa8a81424aeaa30f696fb5bec5e3956 | 707,248 |
def solar_true_longitude(solar_geometric_mean_longitude, solar_equation_of_center):
"""Returns the Solar True Longitude with Solar Geometric Mean Longitude,
solar_geometric_mean_longitude, and Solar Equation of Center,
solar_equation_of_center."""
solar_true_longitude = solar_geometric_mean_longitude +... | a335bb82002846eb2bc2106675c13e9f3ee28900 | 707,249 |
def findUsername(data):
"""Find a username in a Element
Args:
data (xml.etree.ElementTree.Element): XML from PMS as a Element
Returns:
username or None
"""
elem = data.find('User')
if elem is not None:
return elem.attrib.get('title')
return None | f7b6bb816b9eeeca7e865582935a157cdf276928 | 707,252 |
def is_valid_table_name(cur, table_name):
"""
Checks whether a name is for a table in the database.
Note: Copied from utils.database for use in testing, to avoid
a circular dependency between tests and implementation.
Args:
cur: sqlite3 database cursor object
table_name (str): name t... | f1efc66220baa215a73f374da19842ab38c619be | 707,261 |
import re
def sub_repeatedly(pattern, repl, term):
"""apply sub() repeatedly until no change"""
while True:
new_term = re.sub(pattern, repl, term)
if new_term == term:
return term
term = new_term | e57c648fb057f81e35e0fc2d2dc57edd0b400baf | 707,262 |
def create_lexicon(word_tags):
"""
Create a lexicon in the right format for nltk.CFG.fromString() from
a list with tuples with words and their tag.
"""
# dictionary to filter the double tags
word_dict = {}
for word, tag in word_tags:
if tag not in word_dict:
word_dict[ta... | 3a91671d559f5924ec9326520db6e11a1672fee4 | 707,263 |
import ipaddress
def ip_only(value):
"""
Returns only the IP address string of the value provided. The value could be either an IP address,
and IP network or and IP interface as defined by the ipaddress module.
Parameters
----------
value : str
The value to use
Returns
-----... | 149b202969c0ccb4e0c5e55417ce0231f1b5fc11 | 707,265 |
import random
def is_prime(number, num_trials=200):
"""Determines whether a number is prime.
Runs the Miller-Rabin probabilistic primality test many times on the given number.
Args:
number (int): Number to perform primality test on.
num_trials (int): Number of times to perform the Miller... | 78478437c08bcbd5e4c690466e4fe51bb4fad5ce | 707,269 |
def str2num(s):
"""Convert string to int or float number.
Parameters
----------
s : string
String representing a number.
Returns
-------
Number (int or float)
Raises
------
TypeError
If `s` is not a string.
ValueError
If the string does ... | 5dfaed567a66fc7d3ee46cbb70d9c408d38fcbfe | 707,271 |
from typing import OrderedDict
import inspect
def _get_new_args_dict(func, args, kwargs):
"""Build one dict from args, kwargs and function default args
The function signature is used to build one joint dict from args and kwargs and
additional from the default arguments found in the function signature. Th... | ad7553e7b778b8f7b499217c7ee4ad7328958809 | 707,273 |
def num_list(to_parse):
"""
Creates list from its string representation
Arguments:
to_parse {string} -- String representation of list, can include 'None' or internal lists, represented by separation with '#'
Returns:
list[int] -- List represented in to_parse
"""
if len(... | b444554e37434b5ae42ebc913bcc0f9b99c65ce9 | 707,275 |
def read_ground_stations_extended(filename_ground_stations_extended):
"""
Reads ground stations from the input file.
:param filename_ground_stations_extended: Filename of ground stations basic (typically /path/to/ground_stations.txt)
:return: List of ground stations
"""
ground_stations_extende... | 2492dc8d5c55f124696aafbec11d74e609c3f397 | 707,281 |
import ast
def get_module_docstring(path):
"""get a .py file docstring, without actually executing the file"""
with open(path) as f:
return ast.get_docstring(ast.parse(f.read())) | e253372bfb6f65907a5461332d14c414c2370c66 | 707,283 |
def transform(f, a, b, c, d):
"""
Transform a given function linearly.
If f(t) is the original function, and a, b, c, and d are the parameters in
order, then the return value is the function
F(t) = af(cx + d) + b
"""
return lambda x: a * f(c * x + d) + b | a47b3f4f3dc1e3ed5ddb6155bcd67b8297c298ed | 707,284 |
import json
def load_config(path='config.json'):
"""
Loads configruation from config.json file.
Returns station mac address, interval, and units for data request
"""
# Open config JSON
with open(path) as f:
# Load JSON file to dictionary
config = json.load(f)
... | 5522f023ed3293149613dcc2dc007e34d50f3fa8 | 707,288 |
import torch
def log_px_z(pred_logits, outcome):
"""
Returns Bernoulli log probability.
:param pred_logits: logits for outcome 1
:param outcome: datapoint
:return: log Bernoulli probability of outcome given logits in pred_logits
"""
pred = pred_logits.view(pred_logits.size(0), -1)
y ... | 6369d893cc9bfe5c3f642f819511798d01ae3ae9 | 707,289 |
import functools
def partial_at(func, indices, *args):
"""Partial function application for arguments at given indices."""
@functools.wraps(func)
def wrapper(*fargs, **fkwargs):
nargs = len(args) + len(fargs)
iargs = iter(args)
ifargs = iter(fargs)
posargs = (next((ifargs,... | 1b45e0bd8baea869d80c6b5963c6063f6b8fbdd4 | 707,290 |
def augment_features(data, feature_augmentation):
"""
Augment features for a given data matrix.
:param data: Data matrix.
:param feature_augmentation: Function applied to augment the features.
:return: Augmented data matrix.
"""
if data is not None and feature_augmentation is not None:
... | 687a7ff2a4b61131f5d95e1f7d6eb77d75bd6f06 | 707,291 |
def copy_keys_except(dic, *keys):
"""Return a copy of the dict without the specified items.
"""
ret = dic.copy()
for key in keys:
try:
del ret[key]
except KeyError:
pass
return ret | b1e57db9dbacbc2a7c502c36082f40598a0f4b90 | 707,292 |
import random
import math
def get_params(img, scale, ratio):
"""Get parameters for ``crop`` for a random sized crop.
Args:
img (PIL Image): Image to be cropped.
scale (tuple): range of size of the origin size cropped
ratio (tuple): range of aspect ratio of the origin aspect ratio crop... | 80838328fc9383731e1a853c8dc572228d1a4567 | 707,293 |
def getlineno(frame):
"""Get the line number from a frame object, allowing for optimization."""
# FrameType.f_lineno is now a descriptor that grovels co_lnotab
return frame.f_lineno | b8c8d6fb3ebb8784d10250a42526b31e185e9b7a | 707,295 |
def get_or_create(session, model, **kwargs):
"""
Creates and returns an instance of the model with given kwargs,
if it does not yet exist. Otherwise, get instance and return.
Parameters:
session: Current database session
model: The Class of the database model
**kw... | 4d3e4f0da5ca61789171db5d8d16a5fa06e975cc | 707,301 |
def soup_extract_enzymelinks(tabletag):
"""Extract all URLs for enzyme families from first table."""
return {link.string: link['href']
for link in tabletag.find_all("a", href=True)} | 7baabd98042ab59feb5d8527c18fe9fa4b6a50af | 707,306 |
def custom_field_sum(issues, custom_field):
"""Sums custom field values together.
Args:
issues: List The issue list from the JQL query
custom_field: String The custom field to sum.
Returns:
Integer of the sum of all the found values of the custom_field.
"""
... | 32c1cce310c06f81036ee79d70a8d4bbe28c8417 | 707,307 |
import pathlib
def list_files(directory):
"""Returns all files in a given directory
"""
return [f for f in pathlib.Path(directory).iterdir() if f.is_file() and not f.name.startswith('.')] | a8c5fea794198c17c2aff41a1a07009984a8e61f | 707,309 |
from typing import Union
def score_normalization(extracted_score: Union[str, None]):
"""
Sofa score normalization.
If available, returns the integer value of the SOFA score.
"""
score_range = list(range(0, 30))
if (extracted_score is not None) and (int(extracted_score) in score_range):
... | 74501e9351296037ecc90ae647155e3c6b76ae01 | 707,310 |
def clap_convert(txt):
"""convert string of clap values on medium to actualy number
Args:
txt (str): claps values
Returns:
number on claps (int)
"""
# Medium annotation
if txt[-1] == "K":
output = int(float(txt[:-1]) * 1000)
return output
else:
return int(txt) | 253e0e2be4f37f1994637bbfc80edfc5d72bc4e5 | 707,314 |
def effective_area(true_energy, reco_energy, simu_area):
"""
Compute the effective area from a list of simulated energy and reconstructed energy
Parameters
----------
true_energy: 1d numpy array
reco_energy: 1d numpy array
simu_area: float - area on which events are simulated
Returns
... | b17efa390a1ae14bb8ecb959740bad8c391b1d2e | 707,320 |
def fmt(n):
"""format number with a space in front if it is single digit"""
if n < 10:
return " " + str(n)
else:
return str(n) | 976acc22cafd6d6bdb4e251853f49a114b63ec21 | 707,324 |
def _always_run(*args, **kwargs) -> bool:
""" This returns False to indicate that the step is not already completed. """
return False | db31e0ac20ac0eef410fb051928308ce7414f5b6 | 707,327 |
def has_anonymous_link(node, auth):
"""check if the node is anonymous to the user
:param Node node: Node which the user wants to visit
:param str link: any view-only link in the current url
:return bool anonymous: Whether the node is anonymous to the user or not
"""
if auth.private_link:
... | c5941bce3f0110dfcd5e9bbb19bae0682c5e731f | 707,328 |
def _causes_name_clash(candidate, path_list, allowed_occurences=1):
"""Determine if candidate leads to a name clash.
Args:
candidate (tuple): Tuple with parts of a path.
path_list (list): List of pathlib.Paths.
allowed_occurences (int): How often a name can occur before we call it a cla... | 3b874e4ea6d8780483100e464e3325321c82689e | 707,331 |
import fsspec
def is_remote_filesystem(fs: fsspec.AbstractFileSystem) -> bool:
"""
Validates if filesystem has remote protocol.
Args:
fs (``fsspec.spec.AbstractFileSystem``): An abstract super-class for pythonic file-systems, e.g. :code:`fsspec.filesystem(\'file\')` or :class:`datasets.filesystem... | c40f9bb4845bbd1fc1a4cf9fce2c1b366cd22354 | 707,336 |
def get_element_attribute_or_empty(element, attribute_name):
"""
Args:
element (element): The xib's element.
attribute_name (str): The desired attribute's name.
Returns:
The attribute's value, or an empty str if none exists.
"""
return element.attributes[attribute_name].va... | dbc7f5c24d321c40b46f1c78950d7cf254719b5c | 707,337 |
def escape(line, chars):
"""Escapes characters 'chars' with '\\' in 'line'."""
def esc_one_char(ch):
if ch in chars:
return "\\" + ch
else:
return ch
return u"".join([esc_one_char(ch) for ch in line]) | f69409c92eacbbcab4232f7bb0ee244c77a4f219 | 707,339 |
def hex2int(s: str):
"""Convert a hex-octets (a sequence of octets) to an integer"""
return int(s, 16) | ecdb3152f8c661c944edd2811d016fce225c3d51 | 707,345 |
def get_mention_token_dist(m1, m2):
""" Returns distance in tokens between two mentions """
succ = m1.tokens[0].doc_index < m2.tokens[0].doc_index
first = m1 if succ else m2
second = m2 if succ else m1
return max(0, second.tokens[0].doc_index - first.tokens[-1].doc_index) | 84052f805193b1d653bf8cc22f5d37b6f8de66f4 | 707,352 |
def FindDescendantComponents(config, component_def):
"""Return a list of all nested components under the given component."""
path_plus_delim = component_def.path.lower() + '>'
return [cd for cd in config.component_defs
if cd.path.lower().startswith(path_plus_delim)] | f9734442bbe3a01460970b3521827dda4846f448 | 707,353 |
from bs4 import BeautifulSoup
def create_bs4_obj(connection):
"""Creates a beautiful Soup object"""
soup = BeautifulSoup(connection, 'html.parser')
return soup | b3956b13756e29cd57a0e12457a2d665959fb03d | 707,355 |
import toml
def parse_config_file(path):
"""Parse TOML config file and return dictionary"""
try:
with open(path, 'r') as f:
return toml.loads(f.read())
except:
open(path,'a').close()
return {} | 599164f023c0db5bffa0b6c4de07654daae1b995 | 707,356 |
def base_round(x, base):
"""
This function takes in a value 'x' and rounds it to the nearest multiple
of the value 'base'.
Parameters
----------
x : int
Value to be rounded
base : int
Tase for x to be rounded to
Returns
-------
int
The rounded value
... | e5b1a1b81c7baf990b7921fe27a20075c0305935 | 707,358 |
def encode_integer_leb128(value: int) -> bytes:
"""Encode an integer with signed LEB128 encoding.
:param int value: The value to encode.
:return: ``value`` encoded as a variable-length integer in LEB128 format.
:rtype: bytes
"""
if value == 0:
return b"\0"
# Calculate the number o... | b74832115a58248f4a45a880f657de6dd38b0d8d | 707,360 |
def expose(policy):
"""
Annotate a method to permit access to contexts matching an authorization
policy. The annotation may be specified multiple times. Methods lacking any
authorization policy are not accessible.
::
@mitogen.service.expose(policy=mitogen.service.AllowParents())
de... | 74caed36885e5ea947a2ecdac9a2cddf2f5f51b0 | 707,366 |
import base64
def didGen(vk, method="dad"):
"""
didGen accepts an EdDSA (Ed25519) key in the form of a byte string and returns a DID.
:param vk: 32 byte verifier/public key from EdDSA (Ed25519) key
:param method: W3C did method string. Defaults to "dad".
:return: W3C DID string
"""
if vk ... | 9991491ab486d8960633190e3d3baa9058f0da50 | 707,367 |
from typing import Dict
from pathlib import Path
import json
def load_json(filename: str) -> Dict:
"""Read JSON file from metadata folder
Args:
filename: Name of metadata file
Returns:
dict: Dictionary of data
"""
filepath = (
Path(__file__).resolve().parent.parent.joinpat... | 37d9f08344cf2a544c12fef58992d781556a9efd | 707,369 |
def get_short_size(size_bytes):
"""
Get a file size string in short format.
This function returns:
"B" size (e.g. 2) when size_bytes < 1KiB
"KiB" size (e.g. 345.6K) when size_bytes >= 1KiB and size_bytes < 1MiB
"MiB" size (e.g. 7.8M) when size_bytes >= 1MiB
size_bytes: File siz... | ebc9ba25c01dedf0d15b9e2a21b67989763bc8c8 | 707,370 |
import pathlib
def path_check(path_to_check):
"""
Check that the path given as a parameter is an valid absolute path.
:param path_to_check: string which as to be checked
:type path_to_check: str
:return: True if it is a valid absolute path, False otherwise
:rtype: boolean
"""
path = p... | 41b3537b0be2c729ba993a49863df4a15119db8b | 707,373 |
def gen_endpoint(endpoint_name, endpoint_config_name):
"""
Generate the endpoint resource
"""
endpoint = {
"SagemakerEndpoint": {
"Type": "AWS::SageMaker::Endpoint",
"DependsOn": "SagemakerEndpointConfig",
"Properties": {
"EndpointConfigName": ... | bc658e6aebc41cfddefe0e77b2d65748a84789c5 | 707,375 |
import random
def summary_selector(summary_models=None):
"""
Will create a function that take as input a dict of summaries :
{'T5': [str] summary_generated_by_T5, ..., 'KW': [str] summary_generted_by_KW}
and randomly return a summary that has been generated by one of the summary_model in summary_model
if summar... | b8a2336546324d39ff87ff5b59f4f1174e5dd54c | 707,380 |
from typing import Match
def _replace_fun_unescape(m: Match[str]) -> str:
""" Decode single hex/unicode escapes found in regex matches.
Supports single hex/unicode escapes of the form ``'\\xYY'``,
``'\\uYYYY'``, and ``'\\UYYYYYYYY'`` where Y is a hex digit. Only
decodes if there is an odd number of b... | 3fdb275e3c15697e5302a6576b4d7149016299c0 | 707,382 |
def check_answer(guess, a_follower, b_follower):
"""Chcek if the user guessed the correct option"""
if a_follower > b_follower:
return guess == "a"
else:
return guess == "b" | acd1e78026f89dd1482f4471916472d35edf68a7 | 707,384 |
from typing import Dict
def canonical_for_code_system(jcs: Dict) -> str:
"""get the canonical URL for a code system entry from the art decor json. Prefer FHIR URIs over the generic OID URI.
Args:
jcs (Dict): the dictionary describing the code system
Returns:
str: the canonical URL
""... | f111a4cb65fa75799e799f0b088180ef94b71cc8 | 707,386 |
def escape_html(text: str) -> str:
"""Replaces all angle brackets with HTML entities."""
return text.replace('<', '<').replace('>', '>') | f853bcb3a69b8c87eb3d4bcea5bbca66376c7db4 | 707,390 |
import torch
def calc_driver_mask(n_nodes, driver_nodes: set, device='cpu', dtype=torch.float):
"""
Calculates a binary vector mask over graph nodes with unit value on the drive indeces.
:param n_nodes: numeber of driver nodes in graph
:param driver_nodes: driver node indeces.
:param device: the d... | 2d2a08a86629ece190062f68dd25fc450d0fd84e | 707,391 |
def open_file(name):
"""
Return an open file object.
"""
return open(name, 'r') | 8921ee51e31ac6c64d9d9094cedf57502a2aa436 | 707,392 |
import math
def _bit_length(n):
"""Return the number of bits necessary to store the number in binary."""
try:
return n.bit_length()
except AttributeError: # pragma: no cover (Python 2.6 only)
return int(math.log(n, 2)) + 1 | bea6cb359c7b5454bdbb1a6c29396689035592d7 | 707,393 |
def with_metaclass(meta, *bases):
"""A Python 2/3 compatible way of declaring a metaclass.
Taken from `Jinja 2 <https://github.com/mitsuhiko/jinja2/blob/master/jinja2
/_compat.py>`_ via `python-future <http://python-future.org>`_. License:
BSD.
Use it like this::
class MyClass(with_metacla... | 0fe8e95fe29821e4cda8b66ff54ddd1b73e51243 | 707,396 |
from typing import List
def join_with_and(words: List[str]) -> str:
"""Joins list of strings with "and" between the last two."""
if len(words) > 2:
return ", ".join(words[:-1]) + ", and " + words[-1]
elif len(words) == 2:
return " and ".join(words)
elif len(words) == 1:
return ... | ecb2c1fa060657f2ea4173c4382a81c9b42beeb9 | 707,397 |
def is_url_relative(url):
"""
True if a URL is relative, False otherwise.
"""
return url[0] == "/" and url[1] != "/" | 91e1cb756a4554973e53fd1f607515577bc63294 | 707,398 |
import math
def to_half_life(days):
"""
Return the constant [1/s] from the half life length [day]
"""
s= days * 3600*24
return -math.log(1/2)/s | af7724dfb9442bf1f5e931df5dd39b31d0e78091 | 707,407 |
import inspect
def get_default_args(func):
"""
Return dict for parameter name and default value.
Parameters
----------
func : Callable
A function to get parameter name and default value.
Returns
-------
Dict
Parameter name and default value.
Examples
--------... | dcc75dceae1385868866d668aa021584547190df | 707,409 |
def sec_to_time(seconds):
"""Transform seconds into a formatted time string.
Parameters
-----------
seconds : int
Seconds to be transformed.
Returns
-----------
time : string
A well formatted time string.
"""
m, s = divmod(seconds, 60)
h, m = divmod(m, 60)
r... | 59fcfe2f53d11ea7daac736b59b5eaeb72172dba | 707,410 |
import base64
def create_api_headers(token):
"""
Create the API header.
This is going to be sent along with the request for verification.
"""
auth_type = 'Basic ' + base64.b64encode(bytes(token + ":")).decode('ascii')
return {
'Authorization': auth_type,
'Accept': 'applicatio... | 41ba1e22898dab2d42dde52e4458abc40640e957 | 707,420 |
import re
def normalize_archives_url(url):
"""
Normalize url.
will try to infer, find or guess the most useful archives URL, given a URL.
Return normalized URL, or the original URL if no improvement is found.
"""
# change new IETF mailarchive URLs to older, still available text .mail archive... | e8a5351af28338c77c3e94fdf2b81e22c7a6edfd | 707,422 |
def getIsolatesFromIndices(indices):
"""
Extracts the isolates from the indices of a df_X.
:param pandas.index indices:
cn.KEY_ISOLATE_DVH, cn.KEY_ISOLATE_MMP
:return dict: keyed by cn.KEY_ISOLATE_DVH, cn.KEY_ISOLATE_MMP
values correspond to rows element in the index
"""
keys = [n for n in indice... | 4e9200c722ce0c478d13eddcc799f4a8f7cab6db | 707,423 |
import ast
from typing import Optional
def get_qualname(node: ast.AST) -> Optional[str]:
"""
If node represents a chain of attribute accesses, return is qualified name.
"""
parts = []
while True:
if isinstance(node, ast.Name):
parts.append(node.id)
break
eli... | 0d08b25a50b7d159f5df3b0b17282725eb748f38 | 707,425 |
def get_reset_state_name(t_fsm):
"""
Returns the name of the reset state.
If an .r keyword is specified, that is the name of the reset state.
If the .r keyword is not present, the first state defined
in the transition table is the reset state.
:param t_fsm: blifparser.BlifParser().blif.fsm ob... | c65ea80f94f91b31a179faebc60a97f7260675c4 | 707,427 |
def border_msg(msg: str):
"""
This function creates boarders in the top and bottom of text
"""
row = len(msg)
h = ''.join(['+'] + ['-' * row] + ['+'])
return h + "\n" + msg + "\n" + h | cdd9d17ba76014f4c80b9c429aebbc4ca6f959c3 | 707,428 |
def _qual_arg(user_value,
python_arg_name,
gblock_arg_name,
allowable):
"""
Construct and sanity check a qualitative argument to
send to gblocks.
user_value: value to try to send to gblocks
python_arg_name: name of python argument (for error string)
gbl... | 7bf6717ee3dbeb533902773c86316d2bbdcd59a9 | 707,430 |
def overlapping_community(G, community):
"""Return True if community partitions G into overlapping sets.
"""
community_size = sum(len(c) for c in community)
# community size must be larger to be overlapping
if not len(G) < community_size:
return False
# check that the set of nodes in the... | da9e3465c6351df0efd19863e579c49bbc6b9d67 | 707,432 |
from typing import Any
def linear_search(lst: list, x: Any) -> int:
"""Return the index of the first element of `lst` equal to `x`, or -1 if no
elements of `lst` are equal to `x`.
Design idea: Scan the list from start to finish.
Complexity: O(n) time, O(1) space.
For an improvement on linear se... | 47e73d53ff68954aadc6d0e9e293643717a807d8 | 707,434 |
def checksum(number):
"""Calculate the checksum. A valid number should have a checksum of 1."""
check = 0
for n in number:
check = (2 * check + int(10 if n == 'X' else n)) % 11
return check | 8ada40ca46bc62bbe8f96d69528f2cd88021ad6a | 707,437 |
def instanceof(value, type_):
"""Check if `value` is an instance of `type_`.
:param value: an object
:param type_: a type
"""
return isinstance(value, type_) | 3de366c64cd2b4fe065f15de10b1e6ac9132468e | 707,438 |
def is_fouling_team_in_penalty(event):
"""Returns True if fouling team over the limit, else False"""
fouls_to_give_prior_to_foul = event.previous_event.fouls_to_give[event.team_id]
return fouls_to_give_prior_to_foul == 0 | ac1578af1092586a30b8fc9cdb3e5814da1f1544 | 707,440 |
import warnings
def lmc(wave, tau_v=1, **kwargs):
""" Pei 1992 LMC extinction curve.
:param wave:
The wavelengths at which optical depth estimates are desired.
:param tau_v: (default: 1)
The optical depth at 5500\AA, used to normalize the
attenuation curve.
:returns tau:
... | 04c89605e8ad4188c62b631e173a9c8fe714958a | 707,441 |
import math
def sigmoid(num):
"""
Find the sigmoid of a number.
:type number: number
:param number: The number to find the sigmoid of
:return: The result of the sigmoid
:rtype: number
>>> sigmoid(1)
0.7310585786300049
"""
# Return the calculated value
return... | 73730a39627317011d5625ab85c146b6bd7793d8 | 707,444 |
def get_name_and_version(requirements_line: str) -> tuple[str, ...]:
"""Get the name a version of a package from a line in the requirement file."""
full_name, version = requirements_line.split(" ", 1)[0].split("==")
name_without_extras = full_name.split("[", 1)[0]
return name_without_extras, version | 424b3c3138ba223610fdfa1cfa6d415b8e31aff3 | 707,445 |
import re
def is_valid_dump_key(dump_key):
"""
True if the `dump_key` is in the valid format of
"database_name/timestamp.dump"
"""
regexmatch = re.match(
r'^[\w-]+/\d{4}_\d{2}_\d{2}_\d{2}_\d{2}_\d{2}_\d+\.\w+\.dump$',
dump_key,
)
return regexmatch | 66fd7d465f641a96bd8b22e95918a6dcbefef658 | 707,448 |
def reverse_dict2(d):
"""Reverses direction of dependence dict
>>> d = {'a': (1, 2), 'b': (2, 3), 'c':()}
>>> reverse_dict(d) # doctest: +SKIP
{1: ('a',), 2: ('a', 'b'), 3: ('b',)}
:note: dict order are not deterministic. As we iterate on the
input dict, it make the output of this functio... | 2419538a13699015f8fefa156e89cf9b1960e358 | 707,450 |
import random
def Flip(p, y='Y', n='N'):
"""Returns y with probability p; otherwise n."""
return y if random.random() <= p else n | 072e170e3f37508a04f8bdbed22470b178f05ab9 | 707,451 |
def addneq_parse_residualline(line: str) -> dict:
"""
Parse en linje med dagsløsningsresidualer fra en ADDNEQ-fil.
Udtræk stationsnavn, samt retning (N/E/U), spredning og derefter et vilkårligt
antal døgnresidualer.
En serie linjer kan se således ud:
GESR N 0.07 0.02 -0.... | 6d1556cbd01f3fe4cd66dcad231e41fa6b1b9470 | 707,453 |
def fahrenheit_to_celsius(fahrenheit):
"""Convert a Fahrenheit temperature to Celsius."""
return (fahrenheit - 32.0) / 1.8 | 4aee3dd0b54450fabf7a3a01d340b45a89caeaa3 | 707,454 |
def username_in_path(username, path_):
"""Checks if a username is contained in URL"""
if username in path_:
return True
return False | 131a8fa102fd0a0f036da81030b005f92ea9aab0 | 707,463 |
def str_parse_as_utf8(content) -> str:
"""Returns the provided content decoded as utf-8."""
return content.decode('utf-8') | 75b8d5f1f8867c50b08146cc3edc1d0ab630280a | 707,464 |
def remove_start(s: str) -> str:
"""
Clear string from start '-' symbol
:param s:
:return:
"""
return s[1:] if s.startswith('-') else s | 03504a3094798f6582bcae40233f7215e8d4d780 | 707,466 |
def get_genome_dir(infra_id, genver=None, annver=None, key=None):
"""Return the genome directory name from infra_id and optional arguments."""
dirname = f"{infra_id}"
if genver is not None:
dirname += f".gnm{genver}"
if annver is not None:
dirname += f".ann{annver}"
if key is not Non... | ab033772575ae30ae346f96aed840c48fb01c556 | 707,475 |
def uniq(string):
"""Removes duplicate words from a string (only the second duplicates).
The sequence of the words will not be changed.
"""
words = string.split()
return ' '.join(sorted(set(words), key=words.index)) | 2e5b6c51bc90f3a2bd7a4c3e845f7ae330390a76 | 707,478 |
def generateListPermutations(elements, level=0):
"""Generate all possible permutations of the list 'elements'."""
#print(" " * level, "gP(", elements, ")")
if len(elements) == 0:
return [[]]
permutations = []
for e in elements:
reduced = elements[:]
reduced.remove(e)
... | 1894b6726bedaaf634e8c7ac56fc1abd9e204eef | 707,481 |
def clean_up_tokenization_spaces(out_string):
"""Converts an output string (de-BPE-ed) using de-tokenization algorithm from OpenAI GPT."""
out_string = out_string.replace('<unk>', '')
out_string = out_string.replace(' .', '.').replace(' ?', '?').replace(' !', '!').replace(' ,', ','
).replace(" '... | 0bd51ca7dbaa36569c0d2f18d510f1c6a92e1822 | 707,484 |
def pad_sents(sents, pad_token):
""" Pad list of sentences(SMILES) according to the longest sentence in the batch.
@param sents (list[list[str]]): list of SMILES, where each sentence
is represented as a list of tokens
@param pad_token (str): padding token
@returns sen... | 8f0eabfaaa18eafa84366a2f20ed2ddd633dacc6 | 707,488 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.