content stringlengths 35 416k | sha1 stringlengths 40 40 | id int64 0 710k |
|---|---|---|
def get_package_names(pyproject):
"""
Get package names
:param dict pyproject: pyproject.toml body.
:return: Package names
:rtype: list
"""
package_names = []
for pkg in pyproject["package"]:
if pkg["category"] == "main":
package_names.append(pkg["name"])
return... | 9d12deab1613c4780a7b53d6f13233b72b51cf23 | 27,356 |
import random
def sim_detections(gt, tpr, fpr):
"""Simulates detection data for a set of ground truth cluster labels and an
annotator with a specified TPR and FPR.
Returns an array of with same length as input gt, where 1 indicates the
simulated annotator detected a cluster and 0 indicates an undetec... | ad8d0ac4423333c64ab1db8b838cba4ed7da4291 | 27,357 |
def update_csv_data_dict(csv_data, first_column, *other_columns):
"""
Update a csv dictionary for a given first column
:param csv_data: The csv data dictionary to add the row to.
:param first_column: The first column of the row to add.
:param *other_columns: The further columns of the row to add.
... | 34abbef2c026bc520a7f4048cd00b6710414294d | 27,361 |
import unittest
def run_student_tests(print_feedback=True, show_traces=True,
success_required=True):
"""Run a suite of student submitted tests.
Tests must be located in /autograder/source/student_tests/
Args:
print_feedback (bool): Print success or failure message
s... | e262b6d5e8c74ca9085aa943a5d58670314d781d | 27,362 |
import torch
def rotated_box_to_poly(rotated_boxes: torch.Tensor):
""" Transform rotated boxes to polygons
Args:
rotated_boxes (Tensor): (x, y, w, h, a) with shape (n, 5)
Return:
polys (Tensor): 4 corner points (x, y) of polygons with shape (n, 4, 2)
"""
cs = torch.cos(rotated_boxe... | 52f0aa5f225006162bbbd676d1319477802cb49e | 27,363 |
import torch
def maybe_cuda(what, use_cuda=True, **kw):
"""
Moves `what` to CUDA and returns it, if `use_cuda` and it's available.
Args:
what (object): any object to move to eventually gpu
use_cuda (bool): if we want to use gpu or cpu.
Returns
object: the s... | ad9f8aa37c4d32000690768d5c18f327ff3bc76c | 27,364 |
import logging
def get_logger(
log_level=logging.INFO,
msg_format="%(asctime)s - %(levelname)s - %(filename)s:%(funcName)s:%(lineno)s"
"- %(message)s",
cls_name=__name__,
):
"""
Instantiate a new logger.
Args:
log_level = One of the log reporting levels defined in the logging modu... | 154518079694a57f44ebe2c83a5e19ff8c4b2396 | 27,365 |
import os
import base64
import re
def gen_oauth_nonce():
"""
Generate oauth nonce for Twiter API
- Get random 32 bytes data
- Base64 encode
- Pick only word characters
"""
random = os.urandom(32)
encoded = base64.b64encode(random)
words = re.sub('[^\w]', '', str(encoded))
return words | cc8ec7209727caed58acac56936df2db0318689a | 27,367 |
def load_RIRE_ground_truth(file_name):
"""
Load the point sets defining the ground truth transformations for the RIRE
training dataset.
Args:
file_name (str): RIRE ground truth file name. File format is specific to
the RIRE training data, with the actual data expectd to... | 9c7747b6fad1a10fb8cbb32162a3423e31fa40f3 | 27,368 |
def subdivide(x_1, x_2, n):
"""Performs the n-th cantor subdivision of the interval (x_1, x_2), a subset [0, 1]"""
if n == 0:
return []
new_x_1 = 2 * (x_1 / 3) + x_2 / 3
new_x_2 = x_1 / 3 + 2 * (x_2 / 3)
return (
subdivide(x_1, new_x_1, n - 1)
+ [new_x_1, new_x_2]
+ ... | ee2cc0ba214d363555224e4b70c10976c63d7dec | 27,369 |
import functools
def graph_conv_wrapper(func):
""" Applies graph convention to a function using pytorch convention """
@functools.wraps(func)
def wrapped_func(*args, **kwargs):
new_args = [x.permute(0, 3, 1, 2) for x in args]
ret = func(*new_args, **kwargs)
return ret.permute(0, 2,... | 945babc661cf121fcfa2563a997c2f72f5fb44e3 | 27,370 |
import os
def txt_file_path_list(folder):
"""Returns sorted list of paths to ~.txt files found in specified folder."""
filenames = os.listdir(folder)
txt_files = []
for file in filenames:
if file[-3:] == 'txt':
txt_files.append(os.path.join(folder, file))
else:
... | 246b7771915210e64e649bcfeafdda3df5a1cd03 | 27,371 |
def _get_ref(info: list) -> str:
"""Get the workspace reference from an info tuple"""
return f"{info[6]}/{info[0]}/{info[4]}" | fbd7bb479abc090b643fa1f1ecfcdd84dee18f62 | 27,373 |
import re
import inspect
def parse_pyvars(code: str, frame_nr: int = 2):
"""Looks through call stack and finds values of variables.
Parameters
----------
code : str
SuperCollider command to be parsed
frame_nr : int, optional
on which frame to start, by default 2 (grandparent frame... | 381d698d3905ee306f75ad888d07c1107e398251 | 27,374 |
def cli(ctx, q, page=1, page_size=10):
"""Search for tools in a Galaxy Tool Shed.
Output:
dictionary containing search hits as well as metadata for the
search. For example::
{u'hits': [{u'matched_terms': [],
u'score': 3.0,
u'tool': {u'description': u'conver... | 793e2149274e4d84e8884f17b0163a5aa28d3119 | 27,375 |
def P_f(x):
""" Projection onto the free cone (x in R) """
return x | a24e0636747becf32b321c0b3539a996a8acd63b | 27,377 |
import itertools
def get_mismatches_from_one(sequence, list_let, nb_mis):
""" Return all the sequences possible from sequence with mismatch = nb_mis"""
nb_let = len(list_let)
list_seq_final = []
len_seq = len(sequence)
nb = range(len_seq)
list_mismatch_place = list(itertools.combinations(nb, n... | 3341cfb936a6a52df8fcd4eb1c2786f1f588bbb1 | 27,378 |
def build_lcp_lr(LCP, n):
"""Builds LCP-LR dictionary from LCP array"""
LCP_LR = {}
def _build_lcp_lr(left, right):
if left + 1 == right:
common_prefix = LCP[right]
else:
mid = (left + right) // 2
common_prefix = min(_build_lcp_lr(left, mid), _build_lcp_lr(mid, right))
LCP_LR[(left, ... | 3b9e3d3c91e96901d6d7a3e4965d15acbca25476 | 27,379 |
def _get_lines(file_obj):
"""Return all the lines in file_obj."""
return [line.strip() for line in file_obj.readlines()] | 07b2bcab4ad9f4f48e5c633752c088791eee4c2d | 27,380 |
def binary(e):
"""
@purpose: Returns a binary representation of the integer passed
@parameter: e - The integer to be converted to binary
@precondition: A positive integer value is passed
@postcondition: A list of integers representing binary value of the integer,
@Complexity:
Best Case: ... | 5412cb4647de46acfe010862c0771bdc88e941e7 | 27,381 |
def cov(C):
"""
Attributes:
C (array-like, dtype=float, shape=(n,n)): Confusion matrix
Returns:
cons (float): Coverage constraint function value
"""
return 1 - C[:, 0].sum() | f8cbaafaeb2003687b3344d683b4f3555cba58e6 | 27,383 |
import os
def load_expectation(expectation_file_name, strip=True): # pragma: no cover
"""Return (unicode) str containing text in *expectation_file_name*.
Expectation file path is rooted at tests/expectations.
"""
thisdir = os.path.dirname(__file__)
expectation_file_path = os.path.abspath(
... | c3b7c68939b9802a4cf71d4b3472cf74127470cc | 27,385 |
def discovery_topic_is_device_config(topic):
"""Return True if the discovery topic is device configuration."""
return topic.endswith("config") | ffb313d9a35312bf8dd6f9c5ad97a9b1dc9ab2fd | 27,387 |
def get_monoalphabetic_decryption(data: str, key: str) -> dict:
"""
Monoalphabetic cipher. Part for decryption.
For decryption (operate with unicode code): c[i] = c[i] - key_code
Where key_code = key[0] + key[1] + ... + key[len[key] - 1] (operate with unicode code)
The structure of the function is s... | 2ded86d0ed9c51a23c80db8342458965ef0d1b3c | 27,391 |
def replace_value_with_key(s, replace_dict):
"""In string s values in the dict get replaced with their key"""
for key in replace_dict:
s = s.replace(replace_dict[key], key)
return s | 6e9c173d6121ac2c90838fa98a9f5d8e88da4ac6 | 27,393 |
def markDuplicate(key, idea, oldest_idea_id):
"""
Mark duplicate. Mark is for statistics purpose.
:return: marked key, IDEA
"""
# If idea is present
if idea:
# Equality of ID's in tuple and idea, if true mark will be added
if oldest_idea_id != idea.id:
# Add True mark... | 8ee5ceb8df6931642732b3f039a18f818b82713a | 27,395 |
def METARtemp(val):
"""convert temp to METAR"""
f_temp = float(val)
i_temp = int(round(f_temp, 0))
f1_temp = int(round(f_temp * 10., 0))
if i_temp < 0:
i_temp = 0 - i_temp
m_temp = "M%02i" % (i_temp,)
else:
m_temp = "%02i" % (i_temp,)
if f1_temp < 0:
t_temp =... | 5fcfa315109911a0061908960c05521840614abd | 27,396 |
def format_class_name(name):
"""
Formats a string to CapWords.
:param name: string to format
:type name: str
:return: string with the name in CapWords
:rtype: str
"""
fixed_name = name.title().replace("_", "")
return fixed_name | 064369048205aaf5afe872844ceff4605b6f1498 | 27,397 |
import json
def bot_factory(app_client, admin_authorization_header):
"""
Generate a bot with the specified name and protocol, return its id (user_id) and token.
"""
def gen(name, protocol):
data = { 'name': name, 'protocol': protocol }
r = app_client.post('/api/bots', data=json.dum... | 5ea30e56c958aaae7d6b05b46941a40ed1ec0c7c | 27,399 |
def check_results(candidate_answers, acceptable_answers):
"""
Return a list containing the ranking of all elements of the list
`candidate_answers` which are also in the list of
`acceptable_answers`.
"""
total = 0
for i, answer in enumerate(candidate_answers):
for acceptable_answer in... | 4e75b82f72532d7797792fe8da4a4e3dd9d7c974 | 27,400 |
def get_attr(d: dict, t: str):
"""获取字典`d`下的`t`"""
try:
return d[t]
except:
return None | eba3fd6c7bb3eeae453db64b1260fdf7c0ed7f6f | 27,401 |
from typing import Union
from pathlib import Path
import subprocess
def is_git_ignored(filename: Union[str, Path]) -> bool:
"""
Check if file is git-ignored. Supports nested .gitignore files.
"""
folder = Path(filename).parent
filename = Path(filename).name
try:
p = subprocess.run(
... | b5ac515ad98e140d6a95ec82915c2876093918dc | 27,403 |
def split_seconds(seconds):
"""Split seconds into [day, hour, minute, second, ms]
`divisor: 1, 24, 60, 60, 1000`
`units: day, hour, minute, second, ms`
>>> split_seconds(6666666)
[77, 3, 51, 6, 0]
"""
ms = seconds * 1000
divisors = (1, 24, 60, 60, 1000)
quotient, result = ... | a37493b93130274f25e722d324a84dbdb7f5d03c | 27,404 |
import time
def wait_on_job(job):
"""Block until the async job is done."""
while job.status() != 'done':
time.sleep(.05) # pragma: no cover
return job | e08190d6a8dee960e7e3f3490ed934203f0aa7ff | 27,405 |
def pkcs7_pad(plaintext: bytes, block_size: int=0x10) -> bytes:
"""
Pad a message using the byte padding algorithm described in PKCS#7
This padding scheme appends n bytes with value n, with n the amount of padding bytes.
The specification describing the padding algorithm can be found here:
http... | fc6e910b428622ac6a9d59b46f04b6c0f7b2a783 | 27,406 |
def convert_null_to_none(value):
"""
this is to convert '' or nan to None for a list
:param value: list or value
:return: value
"""
if isinstance(value, list):
value = [None if x == '' else x for x in value]
else:
value = None
return value | cb33abd018420165b16818bf9054bf702b4f3a2c | 27,407 |
from datetime import datetime
import pytz
def get_appropriate_object_from_model(object_set, is_queryset=False):
"""
Tools:
- publish_status = {1: always on, 0: conditionally on, -1: always off, NULL never published}
OK - this is how the game is played:
Rule 0: only ob... | 3b0bc31423c3f3eb71dab792c579db703826abce | 27,408 |
def countSelectedPairs(all_selected_idx, print_msg = True, string = 'Major merger cut: '):
"""
Function to count selected pairs from the list of lists outputted by ball tree
@all_selected_idx ::
"""
count_selected_pairs = 0
for j, mm in enumerate(all_selected_idx):
if len(... | a8e7b66c218c833d91f8660032ec9715eaa76862 | 27,409 |
def get_arrival_from_pick(arrivals, pick):
"""
return arrival corresponding to pick
:param arrivals: list of arrivals
:type arrivals: list of either obspy.core.event.origin.Arrival
or microquake.core.event.origin.Arrival
:param pick: P or S pick
:type pick: eithe... | 4b4e1df275601aa3990a22dc471541808a1bbbef | 27,410 |
def delete_prefix(prefix: dict, session, fqdn) -> int:
"""Call API to delete the prefix."""
id = prefix["id"]
result = session.delete(f"http://{ fqdn }/api/ipam/prefixes/{ id }/")
return result | 96cf4d689636ac3117ed38ac39d39612257761a6 | 27,411 |
def is_pc_router_interface(config_db, pc):
"""Check if portchannel is a router interface"""
pc_interface_table = config_db.get_table('PORTCHANNEL_INTERFACE')
for intf in pc_interface_table:
if pc == intf[0]:
return True
return False | 35da3dce6a4ca4ad3b9dfde3723dede6dd4ecef3 | 27,412 |
import gzip
import json
def load_json(filename):
""" Load JSON from text file or gzip """
if filename.endswith("gz"):
f = gzip.open(filename, "rt")
else:
f = open(filename, "rt")
return json.load(f) | 3601d835d394c00f79cf6c5900df810b33b2f11d | 27,415 |
def get_events(sc):
""" Get all event_logs and reverse order to make ascending. """
events = sc.getstatus('event_logs')
events.reverse()
return events | 3b8387fd96183b0dd5279891ab15e3f69af579ce | 27,416 |
import json
def load_evaluation(filename):
"""Load single evaluation file. Adds the filename for reference"""
data = None
with open(filename) as fin:
try:
data = json.loads(fin.read())
data['filename'] = filename
except json.JSONDecodeError:
print(f"Coul... | 472392989f96185d5071d51f10d7bcaa234cdf1e | 27,417 |
import torch
def giou_loss(pred,
target,
weight,
avg_factor=None):
"""GIoU loss.
Computing the GIoU loss between a set of predicted bboxes and target bboxes.
"""
pos_mask = weight > 0
weight = weight[pos_mask].float()
if avg_factor is None:
avg... | 5a65efeff6244d1691fabf85c3d110e66a2cc43a | 27,418 |
import torch
def quaternion_linear_rotation(input, r_weight, i_weight, j_weight, k_weight, bias=None, quaternion_format=False):
"""
Applies a quaternion rotation transformation to the incoming data:
The rotation W*x*W^t can be replaced by R*x following:
https://en.wikipedia.org/wiki/Quaternions_and_s... | bec280bda0b2138514d3fa9ebd879e3ee25fb541 | 27,420 |
def parse_program(line):
"""Parse line to tuple with name, weight and list of programs above."""
program, *above = line.split(' -> ')
name, weight = program.split()
return name, int(weight[1:-1]), above[0].split(', ') if above else [] | 0ebcec6f32602d0bfcbfe857d49bcd46a20f528a | 27,422 |
import click
def networkx_to_dict(ngraph, verbose=True):
"""Turn the networkx data into a dict structure that can be consumed by the dataviz
Note
--------
The network data is extracted as follows
> xx = G.nodes(data=True)
> for x in xx:
print(x[1])
('respiratory tract infections'... | 678a214c86b2810c79d3223dc5832b922a9fbfc4 | 27,423 |
def namespaceable(request, namespaces, abc):
"""Return either helper class."""
if request.param == 'main':
return namespaces.Namespaceable
else:
return abc.NamespaceableABC | 014c6f763296aa9de22ab534d8e06c655959f9b5 | 27,424 |
def entry_check(entry):
"""
check if entry is a dict and has a key entry.
If list return dict {'entry': entry}
:param entry
:return: entry_dict
"""
# print("entry type:", type(entry))
if isinstance(entry, dict):
# print("keys:", entry.keys())
if 'entry' in entry:
... | 41e788a02edbf56938878fda045ebf65b7bb5df7 | 27,425 |
from typing import Tuple
def is_tuple_list_type(t) -> bool:
"""
Allowed only `Tuple[Type1, ...]`
:param t:
:return:
"""
if not hasattr(t, '__origin__'):
return False
# Python36: List, Python37+: list
if not t.__origin__ in (Tuple, tuple):
return False
return t.__ar... | 0be0fe167b0934e46d5b315da3552eb8a534ff05 | 27,426 |
import re
def check_state_keys(state, keys_regex):
"""check if keys exists in state using full python paths"""
regex = re.compile(keys_regex)
for k, v in state.items():
if regex.findall(k):
return True
return False | 423bbd9a01c7240d0c73f1f7370e38164d3ae63f | 27,427 |
import subprocess
def BuildBinary(build_dir, binary_name):
"""Builds the given binary in the given directory with Ninja.
Returns True on success."""
return subprocess.call(["ninja", "-C", build_dir, binary_name]) == 0 | 91545bee67981e7c14707f6e09f1f1370d268ae7 | 27,429 |
import re
def is_drive_letter(path):
"""Check wheter specified path is a drive letter"""
return re.match('^[a-zA-Z]{1}:$', path) | bbef9719ce0a0a4910fa021003238aecbe0810f8 | 27,430 |
def convert_fasta_to_string(filename):
"""Takes a genome FASTA and outputs a string of that genome
Args:
filename: fasta file
Returns:
string of the genome sequence
"""
assert filename.split('.')[-1] == 'fasta' # assert correct file type
with open(filename) as f:
sequenc... | 4bb2a8228a08b2debfb5d8fab9cf08c05390f24f | 27,431 |
def harmean(series, n):
"""
调和平均值: 求series在n个周期内的调和平均值
计算方法:
harmean(x, 5) = 1 / [(1 / x(1) + 1 / x(2) + 1 / x(3) + 1 / x(4) + 1 / x(5)) / 5]
例:
harmean = tafunc.harmean(df["close"], 5) # 求5周期收盘价的调和平均值
注:
1. n包含当前k线
2. 调和平均值与倒数的简单平均值互为倒数
3. 当n为有效值, 但当前的k线数... | 2152568e3cb75296cad5c4ef117779d850467a17 | 27,432 |
import os
def get_files_to_push(local_path, device_path):
"""Get a list of the file(s) to push.
Parameters
----------
local_path : str
A path to a local file or directory
device_path : str
A path to a file or directory on the device
Returns
-------
local_path_is_dir :... | 819a4c5890c95783b060ed7a1a126ad8be088042 | 27,433 |
def unauthorized(e):
""" custom 401 """
return '<h1>hey, you there, no wandering around here</h1>', 401 | 2243fb48421026fee1fde66096d80a3d09fa88fb | 27,434 |
def calculate_gc(read):
"""Returns GC count."""
return (read.lower().count("g") + read.lower().count("c")) / len(read) * 100.0 | aeae6346abbfb634ccd871e9ab191a404916961f | 27,436 |
def identity(x):
"""Identity functions, useful as semantic action for rules."""
return x | 359ef0c72e231f9b815e928a3f908d3cf5772f81 | 27,437 |
def tree_struct_sep(lines):
"""Separates tree structure from rest of the data.
This is done to get an excepted format for the column_parser
"""
indx = None
for line in lines:
if line.startswith('; ********'):
indx = lines.index(line)+1
break
return lines[:indx],... | c896fb01d9565569dc4d5b9a1c43b84173892287 | 27,438 |
def nplus1loader(loadopt, attrs, nested=True):
""" N+1 loader for attributes, be it a column or a relationship
Give it a list of attributes, of '*' to handle them all.
Args:
attrs: Currently, only supports '*'.
See `nplus1loader_cols()` and `nplus1loader_rels()` for fine-tuning.
... | 7fa5b44ebe8db9fa578d208b2b788e326d0bbb1f | 27,439 |
import sys
def get_evaluator(method, parent):
"""
Get an evaluator.
Parameters
----------
method : str
The name of the evaluator.
parent : Selector
The selector using the evaluator.
Returns
-------
Evaluator
The initialized evaluator.
"""
return g... | 5168e75c902440685dcde1c46f40481f02a23496 | 27,440 |
def pascal_triangle(n):
"""
Returns a list of lists of integers
representing the Pascal’s triangle of n.
"""
if n <= 0:
return []
result = [[1]]
while len(result) is not n:
tmp = [1]
for i in range(len(result[-1]) - 1):
tmp.append(result[-1][i] + result[-... | 1175816ec7b7e657543decf4be4478424bfabb79 | 27,443 |
def dsr_bc(D_eq):
"""
Beard and Chuang drop shape relationship function.
Arguments:
D_eq: Drop volume-equivalent diameter (mm)
Returns:
r: The vertical-to-horizontal drop axis ratio. Note: the Scatterer class
expects horizontal to vertical, so you should pass 1/dsr_bc
"""
... | 1687a0f762fa4b846563c0c327f0a93296c2a8f8 | 27,444 |
def apps(request):
"""
Directory to extract files to
"""
apps = request.config.option.apps
return apps.split(',') | aa571a60803634dfcad61994a4af086fe14c5763 | 27,445 |
def validate_email_destination(os_mailbox, os_email):
""" return True iff O.S. mailbox record is a destination linked to given O.S. email record """
destinations = os_email.get('destinations', None)
return os_mailbox['id'] in destinations | e230dbc91aad7b62025361818ed4ffe61b3df33b | 27,446 |
def units_map(param, mm=False):
"""
Units of parameters
"""
L = "cm"
if mm:
L = "mm"
if param in ("temps", "Tl", "Tt", "T"):
unit = " [mK]"
elif param[0] == "I":
unit = " [A]"
elif (
param[:2] == "r0"
or param[0] in ("L", "W", "R", "A")
or ... | 357fb51de327e15d7fceb23023916036a48e128b | 27,449 |
def get_sections_in_range(sections, time_range):
"""get sections in a certain time range (e.g., in the train_ranges)
Args:
sections: list of tuples (<onset>, <offset>) or (<label>, <onset>, <offset>)
time_range: (list of) tuple(s) (<onset>, <offset>)
Returns:
"""
if isinstance(tim... | 044ca7ddc3f4cf71077bc6ef236fcb396f73da62 | 27,450 |
def snap(point,shape,snapRange=20):
""" snap 'point' if within 'snapRange' from the border defined by 'shape' """
snapped = list(point)
if snapped[0] < snapRange: snapped[0] = 0
if snapped[0] > shape[1]-snapRange: snapped[0] = shape[1]
if snapped[1] < snapRange: snapped[1] = 0
if snapped[1] > shape[0]-snapR... | 42c0b6e124944f327489767179fc4fc422cbaedc | 27,451 |
def make_front_matter(title, weight):
"""Makes the front matter needed for Hugo."""
return f"""---
title: {title}
linkTitle: {title}
weight: {weight+1}
type: docs
---
""" | 8d51b39fae382a579fdbeedcc28fd9955368fe01 | 27,452 |
def collide_parent_tree(widget, x, y):
"""Returns whether (x, y) collide with the widget and all its parents.
"""
if not widget.collide_point(x, y):
return False
parent = widget.parent
while parent and hasattr(parent, 'to_parent'):
x, y = parent.to_parent(x, y) # transform to paren... | 5019692635194b9313811ed6a8caffe891965bb8 | 27,453 |
import os
import csv
def load_auto_reply_settings(auto_reply_for_non_player_file):
"""
读取关键词csv文档,返回keyword_dict对象
"""
if os.path.exists(auto_reply_for_non_player_file):
auto_reply_dict = dict() # {编号: [回复类型, 回复文件名称或内容, 视频描述]}
with open(auto_reply_for_non_player_file, 'r') as f:
... | c7cf7d7ea8d054ddfd3551725687b33af6ff5959 | 27,455 |
def get_median(distribution):
"""
Median lies exactly midway of your distribution, when arraged in an order.
Parameter: a list containing the distribution of the sample or population
Returns: the median of the distribution
"""
n = len(distribution) # distribution size
# for median, first s... | 06c8f3f5735d80a406e9db72aca3db73812f92aa | 27,456 |
import sys
import traceback
def extract_function_name():
"""
Extracts failing function name from Traceback
by Alex Martelli
http://stackoverflow.com/questions/2380073/\how-to-identify-what-function-call-raise-an-exception-in-python
"""
tb = sys.exc_info()[-1]
stk = traceback.ex... | 4559ee47370089c72225aa76b6dc089de835bdac | 27,458 |
def concat(s):
"""This function takes a more user friendly regex (E.g: 'abc'), and
inserts '.' concat operators where appropriate. (E.g: 'a.b.c')"""
my_list = list(s)[::-1] # convert regex string to a reverse ordered list
# characters with special rules
special_characters = ['*', '|', '(', ')', '+... | 6d413e3f00f000d6fca3083bf116ea14dbc7b962 | 27,459 |
def get_src_path_root(src_path: str) -> str:
"""returns the root directory of a path (represented as a string)"""
if "\\" in src_path:
return src_path.split("\\", 1)[0]
elif "/" in src_path:
return src_path.split("/", 1)[0]
return src_path | 8df673721aa505f1647871b8df25ccabd0402fd9 | 27,460 |
def posok(state,x):
"""
检测目标位置是否符合要求
"""
y=len(state)
for i in range(y):
if abs(x-state[i]) in (0,y-i):
return False
else:
return True | 5d5e99876b6c8dbf7bb4618c23839432f3a9edb3 | 27,461 |
def numpow(series, n, m):
"""
自然数幂方和
计算方法:
numpow(x, n, m) = n ^ m * x + (n - 1) ^ m * x.shift(1) + (n - 2) ^ m * x.shift(2) + ... + 2 ^ m * x.shift(n - 2) + 1 ^ m * x.shift(n - 1)
注意: 当n为有效值但当前的series序列元素个数不足n个, 函数返回 NaN 序列
Args:
series (pandas.Series): 数据序列
... | 6dbd88cbe06f03bf32a3beaef6c41dcf39ec1a1e | 27,463 |
def clean_nan(data, data_column):
"""Takes pandas dataframe of data and removes all rows containing NaN"""
data.dropna(subset=[data_column, \
'Quality'], inplace=True)
return data | 3b41fad6b60951f57dd309f5bc5920ca467652f1 | 27,464 |
import torch
def calc_pairwise_distance(X, Y):
"""
computes pairwise distance between each element
Args:
X: [N,D]
Y: [M,D]
Returns:
dist: [N,M] matrix of euclidean distances
"""
rx=X.pow(2).sum(dim=1).reshape((-1,1))
ry=Y.pow(2).sum(dim=1).reshape((-1,1))
dist=... | 3a8c502163ea2788cd4fc79d44d6f2d2f04d24d8 | 27,465 |
def response_timeout():
"""Server timeout response."""
return b"SPAMD/1.0 79 Timeout: (30 second timeout while trying to CHECK)\r\n" | 92d1a467821919cb2d1aa1f23e64dd2df783bd9e | 27,466 |
def str_to_address(v):
"""
:type v: str
"""
if not v:
return None
host, port = v.split(":", 1)
return host, int(port) | 843d324b159808dc7addecc2a6b19eef48c555c9 | 27,467 |
def get_size(driver, size_id):
"""
Return a ``NodeSize`` corresponding to a given id.
:param driver: The libcloud driver to query for sizes.
"""
try:
return [s for s in driver.list_sizes() if s.id == size_id][0]
except IndexError:
raise ValueError("Unknown size.", size_id) | 197d0bcec335d5d03aa4f1a71e856b027ed7db3a | 27,468 |
def samefile(path1, path2):
"""Return True if both pathname arguments refer to the same file or
directory.
:type path1: bytes | unicode | os.PathLike
:type path2: bytes | unicode | os.PathLike
:rtype: bool
"""
return False | 16212c294b76cc0bfe335fde5b060204953e03ef | 27,469 |
from typing import Any
def non_english_lang_code(request: Any) -> str:
"""
Get all non-English language codes, but one per request.
NOTE This is not currently used. Once a set of non-English
language codes which are known to pass the test are identified,
this can be used to test all of them one a... | 80ad26b3ded55e34b61b3b9fdb0b83b62c34dc21 | 27,470 |
import time
def createDateTimeString(now=None):
"""Return datetime as string (e.g. for saving results)."""
if now is None:
now = time.localtime()
return str(now.tm_year) + str(now.tm_mon).zfill(2) + \
str(now.tm_mday).zfill(2) + '-' + \
str(now.tm_hour).zfill(2) + '.' + \
s... | 340d4c2e044622d3602b454bf601fcf1bd12ae12 | 27,471 |
def pssm_recovery_range(struct,pssm_map,min,max):
"""return percent pssm recovery fro residues within a range of b factors"""
pssm_recovery = 0.0;
struct_size = 0.0;
for residue in struct.get_residues():
score= residue.get_list()[1].get_bfactor()
#print score
if score >= min and score <= max:
residue_name ... | f2a0157d4b561bf782d87cf8c8f41abf68fb188c | 27,473 |
def fully_qualified_name(cls):
"""Return Fully Qualified name along with module"""
return ".".join([cls.__module__, cls.__name__]) | 118e1acae269cae23f848ed0f983f0e58c2b2359 | 27,474 |
def check_navn(navn, limit=2, remove='Ja Nei Nå Dem De Deres Unnskyld Ikke Ah Hmm Javel Akkurat Jaja Jaha'.split()):
"""Removes all items in navn with frequency below limit and words in all case as well as all words in list 'remove'"""
r = {x:navn[x] for x in navn if navn[x] > limit and x.upper() != x and not x... | de70a4e7b38e85cfcd794c55030464243ca76304 | 27,475 |
def map_cursor_to_dict(cursor, columns):
"""
Map Cursor results to the dict
"""
results = []
for row in cursor.fetchall():
results.append(dict(zip(columns, row)))
return results | b388a03e9bc2b2e99b8277f4ec16ab379cc4cb64 | 27,476 |
def point2str ( pnt ):
""" point2str( pnt )
format a 3d data point (list of 3 floating values) for output to a .scad file.
Also used to do equality comparison between data points.
@param pnt - list containing the x,y,z data point coordinates
@returns '[{x}, {y}, {z}]' with coordinate values forma... | 8d47a8d3c29be082ec3a45250f845f1e00633fab | 27,477 |
def collect_params(model):
"""Collect optim params for use with dent."""
params = []
for p in model.parameters():
if p.requires_grad:
params.append(p)
return params | 50245b8f331625ea2d68e37b70ba3a2a8bbe6350 | 27,479 |
def _get_extra_configmaps_and_metrics(resource_name, resource_qsets):
"""
configmap used for logbeat
"""
extra_configmaps, metrics = [], []
for res in resource_qsets:
cms, mts = res.get_extra_configmaps_and_metrics(resource_name)
extra_configmaps.extend(cms)
metrics.extend(mt... | 9ba3f2b65de06fda84464a567c8fa320d0abd007 | 27,480 |
import hashlib
def sha384(s):
"""Compute the SHA384 of a given string."""
return hashlib.sha384(s.encode("utf-8")).hexdigest() | e62256c30c781f85f6ed56a1086747b83637229f | 27,481 |
def compute_momentum(df, window=1):
"""Return momentum."""
df['Momentum'] = (df['Price'] / df['Price'].shift(window) - 1)
return df.fillna(0) | fb74bbd365cae4eaa3b35d1dd6c7c6ee5b9211eb | 27,482 |
def compute_center(detections):
"""Compute the center for each detection.
Args:
detections: A matrix of shape N * 4, recording the pixel coordinate of
each detection bounding box (inclusive).
Returns:
center: A matrix of shape N I 2, representing the (x, y) coordinate
... | 794b64de7ef7b1327bb0bb90982ac8d67c0a0fea | 27,484 |
import re
import os
def _get_version():
"""Read the __version__ value from src/domino_ingestion/version.py.
We can't import the package because we're the installation script for the package,
so we use regex and read the python file as a raw text file.
"""
version_regex = re.compile(
r"""^... | dea500da7a425ec20b6534cb07894904d6a63f93 | 27,485 |
def subdict(d, nested_keys=None):
""":return the dict nested hierarchically indicated by nested_keys
or None if key list is incorrect
:param nested_keys list of keys or a single keys
"""
if not isinstance(nested_keys, (tuple, list)):
nested_keys = [nested_keys]
for k in nested_keys:
... | ceabc9ebfaccfe857e827698192a1c231db7bcde | 27,486 |
import re
def LegalizeName(name):
""" Return a file name suitable for uploading to Google Storage.
The names of such files cannot contain dashes or other non-identifier
characters.
"""
return re.sub(r'[^A-Za-z0-9_/.]', '_', name) | 1f5028b93b919beeeb2c2b25c8d29e0e4ac00e7a | 27,488 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.