content stringlengths 39 14.9k | sha1 stringlengths 40 40 | id int64 0 710k |
|---|---|---|
def convert_proxy_to_string(proxy):
""" This function convert a requests proxy format to a string format """
return proxy['http'].split('//')[1] | 7e4fbb7b075fb2139fda83b52f562699c85a6b32 | 28,692 |
def ReadFile(path, mode='r'):
"""Read a given file on disk. Primarily useful for one off small files."""
with open(path, mode) as f:
return f.read() | cf007c6fcf826eccde7f42b87542794f1d4d8cb0 | 28,693 |
from typing import List
def scale_row(row: List[float], scalar: float) -> List[float]:
"""
Return the row scaled by scalar.
"""
return [scalar * el for el in row] | d44901244199b9d39529a3e3bccc7a9eab9d332e | 28,697 |
def get_action_value(mdp, state_values, state, action, gamma):
""" Computes Q(s,a) as in formula above """
result = 0
for to_state in mdp.get_all_states():
transition_probability = mdp.get_transition_prob(state, action, to_state)
reward = mdp.get_reward(state, action, to_state)
resul... | 226d8e01054552ae1108d3d83e0e438ddc821df9 | 28,702 |
def convert_shell_env(env):
"""Convert shell_env dict to string of env variables
"""
env_str = ""
for key in env.keys():
env_str += "export {key}={value};".format(
key=key, value=str(env.get(key)))
return env_str | 4f777dbeb2534529dbf76e2b5a203e4b2de7ed63 | 28,704 |
import requests
def get_identity_token(scopes='https://www.googleapis.com/auth/cloud-platform'):
"""
Getting an identity token from a google authorization service.
:param scopes: https://cloud.google.com/deployment-manager/docs/reference/latest/authorization
:return: bearer token
"""
host = '... | 70acf41bd322b70ce7d258688698d511e0c2211b | 28,707 |
def split_comma_separated(text):
"""Return list of split and stripped strings."""
return [t.strip() for t in text.split(',') if t.strip()] | 5030ff3dac88de0ef82f929cfcc5adf913b124a0 | 28,711 |
import pickle
def read_pickle(name):
"""
Reads a pickle file
:param name: Path to the pickled file to read
:return: The deserialized pickled file
"""
with open(name, "rb") as input_file:
return pickle.load(input_file) | 4021e5f3aeba9824d07998658d88f9971843585f | 28,717 |
from typing import List
from typing import Dict
def build_final_outputs(outputs: List[Dict], old_new_dict: Dict) -> List[Dict]:
"""
Receives outputs, or a single output, and a dict containing mapping of old key names to new key names.
Returns a list of outputs containing the new names contained in old_new... | 930d9026ad731c8689110a2fd1bef0b3b13e79d9 | 28,718 |
def transform_box_format_gt(box):
"""x1,y1,x2,y2 to x1, y1, w, h"""
x1, y1, x2, y2 = box.x1, box.y1, box.x2, box.y2
return [x1, y1, x2 - x1, y2 - y1] | 10b32ec5f51a2ee5a558bf74345df4528c65b0ec | 28,719 |
def calc_corr_matrix(wallet_df):
"""Calculates the Pearson correlation coefficient between cryptocurrency pairs
Args:
wallet_df (DataFrame): Transformed DF containing historical price data for cryptocurrencies
"""
corrmat_df = wallet_df.corr()
return corrmat_df | 7d76f496783f129749888d7913a93919a5570273 | 28,722 |
import re
def parse_tags(s):
"""
Return a list of tags (e.g. {tag_a}, {tag_b}) found in string s
"""
return re.findall('{(\w+)\}*', s) | 28849f326ff6019b9e41ee6fa0f48cfebff0811e | 28,724 |
def count_parameters(model) -> int:
"""Count parameters in a torch model.
Parameters
----------
model : torch.nn.module
The model from which you want to count parameters.
Returns
-------
int
Total number of parameters in the model.
"""
return sum(p.numel() for p in ... | a3f398bb5969cd4d81c1702089698a2ed9d79d31 | 28,727 |
import csv
def get_csv_log_file_data(folder_list):
""" The Function takes a list of folders and returns combined list of entries
and the folder of the entry, taken from from the driving_log.csv file."""
csv_lines = []
# For the driving_log.csv file from imput list of folders:
# In this ... | 1945fae6695116052864c1a93f19e2198b24662f | 28,730 |
import logging
def clean_geolocation_data(geolocation_data, attr_to_remove=None):
"""Remove attributes from geolocation data.
If no attributes are provided, return a copy of the same data.
:param geolocation_data: Full geolocation data
:type: dict
:param attr_to_remove: List of attributes to rem... | 9ef7a5c2777b556b81c1d21ec775ae6963c857ca | 28,734 |
def h3(text):
"""h3 tag
>>> h3('my subsubheading')
'<h3>my subsubheading</h3>'
"""
return '<h3>{}</h3>'.format(text) | 196d30c7b3b0e6219ef4ce3a2edfd42a3bb13f46 | 28,738 |
def get_skin_cluster_influence_objects(skincluster):
"""
Wrapper around pymel that wrap OpenMaya.MFnSkinCluster.influenceObjects() which crash when
a skinCluster have zero influences.
:param skincluster: A pymel.nodetypes.SkinCluster instance.
:return: A list in pymel.PyNode instances.
"""
... | ebb686bc4ca718db104fccb08b4332de1df9d3d3 | 28,739 |
def find_sum_of_arithmetic_sequence(requested_terms: int, first_term: int, common_difference: int) -> int:
"""
Finds the sum of an arithmetic sequence
:param requested_terms:
:param first_term:
:param common_difference:
:return: the sum of an arithmetic sequence
"""
return int((requested... | fc4f3fec94737674096ff9e0a22c6001690c6101 | 28,742 |
def render_compiled(compiled, variables):
"""Render from compiled template with interpolated variables."""
template, partials = compiled
return template(variables, partials=partials) | 3c13acf96ac3b59bcd5c2a1f3f3dbc19fd210c80 | 28,753 |
def requirements(section=None):
"""Helper for loading dependencies from requirements files."""
if section is None:
filename = "requirements.txt"
else:
filename = f"requirements-{section}.txt"
with open(filename) as file:
return [line.strip() for line in file] | 2e4b7f9f4d8c8d0cd3cfa749f03785d2bba6a26b | 28,754 |
def route(rule, **options):
"""Like :meth:`Flask.route` but for nereid.
.. versionadded:: 3.0.7.0
Unlike the implementation in flask and flask.blueprint route decorator does
not require an existing nereid application or a blueprint instance. Instead
the decorator adds an attribute to the method ca... | c7f33af4e8fa10090e5b6a90532707fd59688885 | 28,755 |
def remap_column_names(data_names, name_map):
""" Remap data array column names using dictionary map.
For each column name that matches a key in name_map, the column name is replaced with
that key's value.
Args:
data_names (str, nx1 tuple): list of column names taken from structured np array
... | 4863d8b9ce1986df4bd85f543014208428ea85cb | 28,756 |
def radical(n, *args, **kwds):
"""
Return the product of the prime divisors of n.
This calls ``n.radical(*args, **kwds)``. If that doesn't work, it
does ``n.factor(*args, **kwds)`` and returns the product of the prime
factors in the resulting factorization.
EXAMPLES::
sage: radical(2... | 846549ba03bcc38cd25a49cb5a2bd51c16cc2e54 | 28,762 |
def findPeakCluster(index, build_list, df, peak_gap):
"""
Recursively finds members of a peak cluster starting from the peak with
the smallest size.
Parameters
----------
index : TYPE Integer
DESCRIPTION. The index of df that corresponds to the
rows (i.e. peaks)... | f808d67a234df45f117b653ca16890ce9c4e982e | 28,769 |
def clamp(low, high, x):
"""
Clamps a number to the interval [low, high]
"""
return low if x < low else (high if x > high else x) | 1393af569f83369a7aa0c22cfaded9ed8e9d112a | 28,771 |
def valid(neighbor, rows, columns):
"""Find out if neighbor cell is valid
Args:
neighbor (List of integers): Neighboring cell position
rows (int): Number of rows on the board
columns (int): Number of columns on the board
Returns:
[boolean]: True if valid, False otherwise
... | 5f832c2a8b06aa98e378c1614078e36f8a9fc2e5 | 28,773 |
def get_sample_name(filename):
"""Extract sample name from filename."""
return filename.split('/')[-1].split('.')[0] | 378dd429f0796930bfeb24e3a8fa51bcde32fb60 | 28,777 |
import re
def getTags(text):
""" Grep the tags in text and return them as a dict """
# 'Name' 'Version' 'Type' 'Author' 'Origin' 'Category' 'ID'
# 'URL' 'Desc' 'Date' 'Flags' 'RefCount' 'Signature' 'MASFile'
# 'BaseSignature' 'MinVersion'
# Name=134_JUDD
tags = {}
for line in text:
... | 92a536b36e0c9ea78bef1ffd97ff69d4e448a0ac | 28,778 |
def _filter_none_elems_from_dict(dict_: dict):
""" Given a dict (call it m), returns a new dict which contains all the
non-null (non-none) elements of m.
Args:
dict_: The dict to return the non-null elements of.
Returns:
A new dict with all the non-null elements of <dict_>.
"""
... | a8b95a1e9f36e90b5c96a4e95b05fcba069d4a93 | 28,779 |
def check_layout_layers(layout, layers):
"""
Check the layer widget order matches the layers order in the layout
Parameters
----------
layout : QLayout
Layout to test
layers : napari.components.LayerList
LayersList to compare to
Returns
----------
match : bool
... | 7d5c3ed65e0588f430341345d6e0fb0856aacaeb | 28,784 |
def isSignedOff(message):
"""
Check whether a commit message contains Signed-off-by tag
"""
for line in message.splitlines():
if line.startswith('Signed-off-by'):
return True
return False | 79248d9438ac1fc1cbce18ae8af236f0960d42e2 | 28,785 |
def read_file(file_path):
"""
Reads input file.
Args:
file_path (str): path of input file.
Returns:
list: content of the file.
"""
with open(file_path, 'r') as file:
return file.read().strip().split('\n') | 27008dcbd9bd9336240e68c9514ae6170c18df78 | 28,795 |
import json
def read_json_file(filename):
"""Read JSON file
Read JSON file as dictionary
Args:
filename(str): Filename
Returns:
dict: Dictionary with file content
"""
with open(filename, 'r') as json_file:
json_str = json_file.read()
try:... | dbc7360d44bb964f1d59186806f552c844d311e1 | 28,798 |
def FindFieldDefByID(field_id, config):
"""Find the specified field, or return None."""
for fd in config.field_defs:
if fd.field_id == field_id:
return fd
return None | b49766575864dac1d65a8a245827d00fcd345be1 | 28,802 |
def as_an_int(num1):
"""Returns the integer value of a number passed in."""
return int(num1) | 32971d8def38efacb150ff511e400700f78c0907 | 28,808 |
import json
def dump_json(obj, format = 'readable'):
"""Dump json in readable or parseable format"""
# Parseable format has no indentation
indentation = None
sep = ':'
if format == 'readable':
indentation = 4
sep += ' '
return json.dumps(obj, indent = indentation, separators =... | 2b6efb9202def6651bf4deb1ebc5e34f44c6c438 | 28,810 |
def format_element(eseq):
"""Format a sequence element using FASTA format (split in lines of 80 chr).
Args:
eseq (string): element sequence.
Return:
string: lines of 80 chr
"""
k = 80
eseq = [eseq[i:min(i + k, len(eseq))]for i in range(0, len(eseq), k)]
return("\n".join(eseq)) | 1e492b341d5ecea3f44ac9fe7246964a98f016a7 | 28,811 |
from typing import List
def _calculate_german_iban_checksum(
iban: str, iban_fields: str = "DEkkbbbbbbbbcccccccccc"
) -> str:
"""
Calculate the checksum of the German IBAN format.
Examples
--------
>>> iban = 'DE41500105170123456789'
>>> _calculate_german_iban_checksum(iban)
'4... | dd9edcc1047caae8822d7a70f02d934db67504db | 28,813 |
def w_acoustic_vel(T,S,Z,lat):
""" Calculate acoustic velocity of water dependent on water depth,
temperature, salinity and latitude. After Leroy et al. (2008)
J. Acoust. Soc. Am. 124(5). """
w_ac_vel = 1402.5 + 5 * T - 5.44e-2 * T**2 + 2.1e-4 * T**3 + 1.33 * S - 1.23e-2 * S * T + 8.7e-5 * S * T**2 + 1.... | d1b8cac0c2bb65d76eb0125faf981a5b1ad1e31e | 28,817 |
def find_service_by_type(cluster, service_type):
"""
Finds and returns service of the given type
@type cluster: ApiCluster
@param cluster: The cluster whose services are checked
@type service_type: str
@param service_type: the service type to look for
@return ApiService or None if not... | fd04adce95c71499e17a143d7c94c0cf1aa603c9 | 28,818 |
def resolve_stack_name(source_stack_name, destination_stack_path):
"""
Returns a stack's full name.
A dependancy stack's name can be provided as either a full stack name, or
as the file base name of a stack from the same environment.
resolve_stack_name calculates the dependency's stack's full name ... | ffee297a7ce1f25cecd1832ced3c8dc9fd729e90 | 28,823 |
def get_induced_subgraph(graph, nodes):
"""Get the nodes-induced subgraph G[S] for a graph G and a subset of nodes S"""
return {node: graph[node].intersection(nodes) for node in nodes} | 58955db6d38dae86f24b756a6bfc67886300eaf5 | 28,826 |
def merge_two_lists(list_one, list_two):
"""
Function merge two lists in a list. Then return the sorted list.
Input lists don't change.
:rtype: list
:return: sorted list
"""
# Copy lists by value
temp_list_one = list_one[:]
temp_list_two = list_two[:]
mergedlist = []
while... | bd0bae58ad54725b55da64404b2635e71881907f | 28,828 |
def filter_stories(stories, triggerlist):
"""
Takes in a list of NewsStory instances.
Returns: a list of only the stories for which a trigger in triggerlist fires.
"""
lists = []
for i in stories:
for triggers in triggerlist:
if triggers.evaluate(i)==True:
li... | a91aa78452fb0a75753a0687a7938a565b2b87f0 | 28,829 |
def remove_namespace(tree):
"""
Namespace can make Splunk output ugly. This function removes namespace from all elements
e.g element.tag = '{http://schemas.microsoft.com/win/2004/08/events/event}System'
:param tree: xml ElementTree Element
:return: xml ElementTree Element with namespace removed
... | b2f4431ffcd33b26321271ea55da24386c10adac | 28,836 |
def elide_sequence(s, flank=5, elision="..."):
"""Trims the middle of the sequence, leaving the right and left flanks.
Args:
s (str): A sequence.
flank (int, optional): The length of each flank. Defaults to five.
elision (str, optional): The symbol used to represent the part trimmed. De... | df318fec488dec46e0f99a0c035b0a962be59844 | 28,840 |
from typing import Mapping
def find_path(g: Mapping, src, dst, path=None):
"""find a path from src to dst nodes in graph
>>> g = dict(a='c', b='ce', c='abde', d='c', e=['c', 'z'], f={})
>>> find_path(g, 'a', 'c')
['a', 'c']
>>> find_path(g, 'a', 'b')
['a', 'c', 'b']
>>> find_path(g, 'a', ... | ea3c48ef552b1393448c36579b11c5bc09c5cced | 28,841 |
from typing import Any
from typing import Dict
def metadata(user_model: Any) -> Dict:
"""
Call the user model to get the model metadata
Parameters
----------
user_model
User defined class instance
Returns
-------
Model Metadata
"""
if hasattr(user_model, "metadata"):
... | 6fa8df5a8d842c8fbccfa6d8447732da4263a124 | 28,848 |
def rgb_clamp(colour_value):
"""
Clamp a value to integers on the RGB 0-255 range
"""
return int(min(255, max(0, colour_value))) | f4dce9746fecd32cb432f03a056451a34d6f265a | 28,852 |
import pyarrow
def _is_column_extension_type(ca: "pyarrow.ChunkedArray") -> bool:
"""Whether the provided Arrow Table column is an extension array, using an Arrow
extension type.
"""
return isinstance(ca.type, pyarrow.ExtensionType) | 606c2fad0486df8f4995925021111eb1cb78f3c4 | 28,853 |
import string
import random
def generate_password(length: int) -> str:
"""Return random password of specified length."""
choice = string.ascii_letters + string.digits
password = ""
for character in random.choices(choice, k=length):
password += character
return password | 3ef64b60ea893fe37aad5ca41cad6f1363f48412 | 28,864 |
def wrap_it_in_a_link(html, url):
""" Wrap a link around some arbitrary html
Parameters:
html - the html around which to wrap the link
url - the URL to link to
Returns:
The same html but with a link around it
"""
return "<a href='" + url + "'>" + html + "</a>" | 606ca401982a4f5474e03063e26e402e690557fc | 28,871 |
def is_even(number: int):
"""Return True if the number is even and false otherwise"""
return number % 2 == 0 | 0fe6ff55e5a84caedda3523bad02b8d144ab0657 | 28,873 |
def get_frame_IDs(objects_archive, start, end, every):
"""
Returns list of ID numbers of the objects identified in each frame.
Parameters
----------
objects_archive : dictionary
Dictionary of objects identified in a video labeled by ID number
start, end, every : ints
start =... | 4826a4d226460e07fbd015e59a052d9792e8ac6a | 28,875 |
def plan_exists(plan):
"""This function can be used to check if a plan trajectory was computed.
Parameters
----------
plan : :py:obj:`!moveit_msgs.msg.RobotTrajectory`
The computed robot trajectory.
Returns
-------
:py:obj:`bool`
Bool specifying if a trajectory is present
... | e2eb384119ed55cb3561e9485bddc3a221a03f92 | 28,876 |
def suggest_patience(epochs: int) -> int:
"""Current implementation: 10% of total epochs, but can't be less than 5."""
assert isinstance(epochs, int)
return max(5, round(.1 * epochs)) | e1631576d63dc3b62df636fb555739158035a25a | 28,882 |
def measure_diff(fakes, preds):
"""Measures difference between ground truth and prediction
fakes (float array): generated "true" global scores
preds (list list): list of [video_id: int, criteria_name: str,
score: float, uncertainty: float]
in ... | 824052778fe02620d52ad0ff5987e1f62363d7fc | 28,884 |
def stringify(vals):
"""Return a string version of vals (a list of object implementing __str__)
Args:
vals (List[any]): List of object that implements __str__
Returns:
str: A string representation
"""
if type(vals) == list:
return '_'.join([str(e) for e in vals])
else:
... | cbd681b2435a919a91a7eeb905ca3279a9baeea6 | 28,885 |
import logging
def get_stream_handler(
formatter: logging.Formatter, level: int
) -> logging.StreamHandler:
"""
Create a ready-to-go stream handler for a Logger.
Parameters
----------
formatter : logging.Formater
Formatter to apply to the handler.
level : int
Level to appl... | 2c6de5bec9fbcb3f7f76c1c21c0db2091b649c96 | 28,886 |
def print_to_log(message, log_file):
"""Append a line to a log file
:param message: The message to be appended.
:type message: ``str``
:param log_file: The log file to write the message to.
:type log_file: ``Path``
"""
with open(log_file, "a") as file_handle:
message.rstrip()
... | cc79449ac082e3e1053e43bfe6d87c7b617c1923 | 28,887 |
def get_prefix_repr(prefix, activities):
"""
Gets the numeric representation (as vector) of a prefix
Parameters
-------------
prefix
Prefix
activities
Activities
Returns
-------------
prefix_repr
Representation of a prefix
"""
this_pref_repr = [0] * ... | 3a194ba988ed5d1889e64df011cd7437e0354ce7 | 28,892 |
def sanitizeFilename(filename: str) -> str:
"""
Remove invalid characters <>:"/\\|?* from the filename.
"""
result = ''
for c in filename:
if c not in '<>:"/\\|?*':
result += c
return result | 90068166ee5ca26cbe4713f2d4edb96be92b961c | 28,893 |
def format_time_delta(delta):
"""
Given a time delta object, convert it into a nice, human readable string.
For example, given 290 seconds, return 4m 50s.
"""
d = delta.days
h = delta.seconds / 3600
m = (delta.seconds % 3600) / 60
s = delta.seconds % 60
if d > 0:
return '%sd... | 8b795cdb716f78dc7c0be5b7454a9d63cd703463 | 28,899 |
import re
def check_url(url):
""" Check if url is actually a valid YouTube link using regexp.
:param url: string url that is to be checked by regexp
:return: boolean True if the url matches the regexp (it is a valid YouTube page), otherwise False
"""
youtube = re.compile(r'(https?://)?(w{3}\.)?(y... | ab0874af82ebe4d7e9435a57a96feb8339da9e70 | 28,901 |
def termcap_distance(ucs, cap, unit, term):
"""termcap_distance(S, cap, unit, term) -> int
Match horizontal distance by simple ``cap`` capability name, ``cub1`` or
``cuf1``, with string matching the sequences identified by Terminal
instance ``term`` and a distance of ``unit`` *1* or *-1*, for right and... | 731c4e02378a626c6a3c3dd7ee30848d88cc2f8a | 28,905 |
def _bytes_to_string(value: bytes) -> str:
"""Decode bytes to a UTF-8 string.
Args:
value (bytes): The bytes to decode
Returns:
str: UTF-8 representation of bytes
Raises:
UnicodeDecodeError
"""
return value.decode(encoding="utf-8") | b33508db0184f21854c734bbef126ec39d95c7b1 | 28,907 |
def merge(intervals):
""" Turns `intervals` [[0,2],[1,5],[7,8]] to [[0,5],[7,8]].
"""
out = []
for i in sorted(intervals, key=lambda i: i[0]):
if out and i[0] <= out[-1][1]:
out[-1][1] = max(out[-1][1], i[1])
else:
out += i,
return out | b0a9eb30f81132f0af568f442465bdd9ce19ab83 | 28,908 |
def date_day_of_week(date):
"""Return the day of the week on which the given date occurred."""
day_of_week = date.strftime('%A')
return day_of_week | 14e5a60b3089f2ec1aed18f71929c73ea1b50731 | 28,909 |
import torch
def scatter_embs(input_embs, inputs):
"""
For inputs that have 'input_embs' field passed in, replace the entry in input_embs[i] with the entry
from inputs[i]['input_embs']. This is useful for the Integrated Gradients - for which the predict is
called with inputs with 'input_embs' field wh... | d0966c15f51b1b692995cd25076e455bea8a2b8a | 28,910 |
def sanitizeStr(data):
"""
Escape all char that will trigger an error.
Parameters
----------
data: str
the str to sanitize
Returns
-------
str
The sanitized data.
"""
data = " ".join(data.split())
new_msg = []
for letter in data:
if letter in ['"... | 6fcd1455a01997d526cfd178d98ee3e9eca3c888 | 28,915 |
from typing import OrderedDict
def group_unique_values(items):
"""group items (pairs) into dict of lists.
Values in each group stay in the original order and must be unique
Args:
items: iterable of key-value pairs
Returns:
dict of key -> lists (of unique values)
Raises:
... | cd25d657117b34fe408c27149ddf034f3956383d | 28,917 |
import io
import csv
def scanlist_csv() -> io.StringIO:
"""
Generates a placeholder ScanList.csv
"""
header = [
"No.",
"Scan List Name",
"Scan Channel Member",
"Scan Channel Member RX Frequency",
"Scan Channel Member TX Frequency",
"Scan Mode",
... | c5c4a8e6d860c3984c7c4af4ab869ca521b1c8cd | 28,918 |
def getTableRADecKeys(tab):
"""Returns the column names in the table in which RA, dec coords are stored, after trying a few possible
name variations.
Args:
tab (:obj:`astropy.table.Table`): The table to search.
Returns:
Name of the RA column, name of the dec. column
... | 93807fe56826ac680605b0494af60ddc6a5014a8 | 28,920 |
def format_channel_link(name: str, channel_id: str):
"""
Formats a channel name and ID as a channel link using slack control sequences
https://api.slack.com/docs/message-formatting#linking_to_channels_and_users
>>> format_channel_link('general', 'C024BE7LR')
'<#C024BE7LR|general>'
"""
retur... | 2745a21960c7a2200e07e28bc5644a09f609b8ba | 28,927 |
import pickle
def load_pickle(filepath_str):
"""
Load pickled results.
Inputs:
filepath_str: path to the pickle file to load
Returns:
loaded pickle file
"""
with open(filepath_str, 'rb') as pickle_file:
return pickle.load(pickle_file) | a7cd817327e928a8d1f3ff3290923e9b878d2a06 | 28,928 |
def local_ij_delta_to_class(local_ij_delta):
"""
:param local_ij_delta: tuple (i, j) returned from local_ij_delta
:return: a value 0-5 for the each of the possible adjecent hexagons, or -1 if
the (i,j) tuple is representing a non-adjecent hexagon coordinate
"""
if (local_ij_delta == (0,... | ed16645346353304c62b4c6bd7e73ee7b3fb2ead | 28,930 |
def prior_creator(vector, priors_lowbounds, priors_highbounds):
"""
Generates flat priors between *priors_lowbounds and *priors_highbounds for parameters in *vector
:param vector: array containing parameters optimized within flat priors
:param priors_lowbounds: array containing lower bound of flat prio... | 6351b1946daf2f956b45dc181d7192aa2e70fbbf | 28,934 |
def to_string(pkt):
"""Pretty-prints a packet."""
name = pkt._name
detail = ''
if name == 'AppleMIDIExchangePacket':
detail = '[command={} ssrc={} name={}]'.format(
pkt.command.decode('utf-8'), pkt.ssrc, pkt.name
)
elif name == 'MIDIPacket':
items = []
fo... | ecdd0dfe3dd9bb2cb24351567520fd821619e19c | 28,939 |
def delete_after(list, key):
"""
Return a list with the item after the first occurrence of the key
(if any) deleted.
"""
if list == ():
return ()
else:
head1, tail1 = list
if head1 == key:
# Leave out the next item, if any
if tail1 == ():
... | 047ad50c25c1c6a2f2d25c5fba1d813b45bd1e17 | 28,945 |
def repeat(a, repeats, axis=None):
"""Repeat arrays along an axis.
Args:
a (cupy.ndarray): Array to transform.
repeats (int, list or tuple): The number of repeats.
axis (int): The axis to repeat.
Returns:
cupy.ndarray: Transformed array with repeats.
.. seealso:: :func... | 4a7a9382b9aa125dc66c2aaf8da0567c49d9aaf3 | 28,948 |
def getsupportedcommands(qhlp, dostrip=True):
"""Parse qHLP answer and return list of available command names.
@param qhlp : Answer of qHLP() as string.
@param dostrip : If True strip first and last line from 'qhlp'.
@return : List of supported command names (not function names).
"""
qhlp = qhlp... | 90cce0dd689f836b57788632681d33f3f717d239 | 28,955 |
def to_rational(s):
"""Convert a raw mpf to a rational number. Return integers (p, q)
such that s = p/q exactly."""
sign, man, exp, bc = s
if sign:
man = -man
if bc == -1:
raise ValueError("cannot convert %s to a rational number" % man)
if exp >= 0:
return man * (1<<exp),... | 3dccd2acc324d8b748fe95290c49d961f1c636e1 | 28,957 |
def int2ascii(i: int) -> str:
"""Convert an integer to an ASCII character.
Args:
i (int): Integer value to be converted to ASCII text.
Note:
The passed integer value must be <= 127.
Raises:
ValueError: If the passed integer is > 127.
Returns:
str: The ASCII charac... | f46ed05d425f9277ea6c97a0f8bafb070b15091c | 28,958 |
def get_from_dict_or_default(key, dict, default):
"""Returns value for `key` in `dict` otherwise returns `default`"""
if key in dict:
return dict[key]
else:
return default | 14ad53c4cac7f554cfa537edeaf7a11e1e8ecac3 | 28,963 |
import math
def distance_formula(x1: float, y1: float, x2: float, y2: float) -> float:
"""
Distance between two points is defined as the square root of (x2 - x1)^2 + (y2 - y1) ^ 2
:raises TypeError: Any of the values are non-numeric or None.
"""
return math.sqrt(((x2 - x1) ** 2) + ((y2 - y1) ** 2... | 5c1a4706365a2347bc23d7efcc74caa003405c0e | 28,965 |
def validate_asn(asn):
"""
Validate the format of a 2-byte or 4-byte autonomous system number
:param asn: User input of AS number
:return: Boolean: True if valid format, False if invalid format
"""
try:
if "." in str(asn):
left_asn, right_asn = str(asn).split(".")
... | 14806fc04132c06dbb75abb2ceefd0340b7845e6 | 28,967 |
import math
def get_points_distance(point1, point2):
"""
Gets the distance between two points
:param point1: tuple with point 1
:param point2: tuple with point 2
:return: int distance
"""
return int(math.sqrt((point1[0] - point2[0]) ** 2 + (point1[1] - point2[1]) ** 2)) | 40af84836715b49ba531fe5113e40230110d49b9 | 28,971 |
from typing import Tuple
import unicodedata
def validate_ae(value: str) -> Tuple[bool, str]:
"""Return ``True`` if `value` is a conformant **AE** value.
An **AE** value:
* Must be no more than 16 characters
* Leading and trailing spaces are not significant
* May only use ASCII characters, exclud... | aee3ec59ea1965bd745f1527368053c5c04e5c4b | 28,972 |
def state2bin(s, num_bins, limits):
"""
:param s: a state. (possibly multidimensional) ndarray, with dimension d =
dimensionality of state space.
:param num_bins: the total number of bins in the discretization
:param limits: 2 x d ndarray, where row[0] is a row vector of the lower
limit... | c2a0cb48864e58481681e8c72074e618dda7ddb8 | 28,973 |
import pickle
def load_db(pathname):
"""
returns the stored database from a pickle file
Parameters
----------
pathname: string
Returns
-------
database: dictionary mapping names to profiles
"""
with open(pathname, mode="rb") as opened_file:
database = pic... | 2ca73cfaf500fd6a841cfb9dc12c3b21d320ac69 | 28,974 |
def mkcol_mock(url, request):
"""Simulate collection creation."""
return {"status_code": 201} | 313fb40302c282d102d6846980ce09ea3600c50c | 28,989 |
def dict2bibtex(d):
""" Simple function to return a bibtex entry from a python dictionary """
outstring = '@' + d.get('TYPE','UNKNOWN') + '{' + d.get('KEY','') + ',\n'
kill_keys = ['TYPE','KEY','ORDER']
top_keys = ['AUTHOR','TITLE','YEAR']
top_items = []
rest_items = []
for k in d.keys():
if k in top_keys:
... | 1ffbc9ec9754acf9904c959be05e0585302435a3 | 28,990 |
def generate_system_redaction_list_entry(newValue):
"""Create an entry for the redaction list for a redaction performed by the system."""
return {
'value': newValue,
'reason': 'System Redacted',
} | 22d7831106c6dd5350a3c86b51facc273835a1e6 | 28,994 |
from typing import Union
def _print_result(
start_quantity: Union[int, float],
start_unit: str,
end_unit: str,
end_quantity: Union[int, float],
) -> str:
"""
Function to create final output string for conversion.
:param start_quantity: Integer or float starting quantity which needed conve... | 26228ea4c3064894748e5352ea117393031ee79b | 28,995 |
import importlib
def get_version(version_module_name):
"""Load currently declared package version."""
version_module = importlib.import_module(version_module_name)
# always reload
importlib.reload(version_module)
version = f"{version_module.__version__}"
print(f"version is {version}")
re... | 156d7e18e96ea0716011e0ca0536d38eaa078b9e | 28,996 |
def _expand_task_collection(factory):
"""Parse task collection task factory object, and return task list.
:param dict factory: A loaded JSON task factory object.
"""
return factory.tasks | 1d2c0b2a763b9e3c78b4bea8d012575038a5804c | 28,999 |
from textwrap import dedent
def dedent_docstr(s, n=1):
"""Dedent all lines except first n lines
Args:
s (type): some text to dedent
n (int): number of lines to skip, (n == 0 is a normal dedent,
n == 1 is useful for whole docstrings)
"""
lines = s.splitlines(keepends=True)
... | ce9d89bbba7ef6784e707fcae0ea6b127ee3cdcd | 29,003 |
def _split_path(loc):
""" Split S3 path into bucket and prefix strings """
bucket = loc.split("s3://")[1].split("/")[0]
prefix = "/".join(loc.split("s3://")[1].split("/")[1:])
return bucket, prefix | 46ace1084e7688847d60fe34e4b3958c89cfbd31 | 29,004 |
def GetStepStartAndEndTime(build, full_step_name):
"""Gets a step's start_time and end_time from Build.
Returns:
(start_time, end_time)
"""
for step in build.steps or []:
if step.name == full_step_name:
return step.start_time.ToDatetime(), step.end_time.ToDatetime()
return None, None | ef3d2a017ad6aa1e0b5c9c974a64d715ae62d1c1 | 29,008 |
def compute_pascal(n):
"""
Compute the nth row of Pascal’s triangle
Parameters
----------
n : integer
which row too compute
Returns
-------
pascal_n : a list of integers
The nth row of Pascal’s triangle.
"""
pascal_n = [1]
prev = 1
for k in range(1,n+1)... | 54b2d5ca80412d2da4da4e9f09dff25026205d3d | 29,012 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.