content stringlengths 35 416k | sha1 stringlengths 40 40 | id int64 0 710k |
|---|---|---|
import pyarrow as pa
def load_arrow(file) -> pa.Table:
"""Load batched data written to file back out into a table again
Example
-------
>>> t = pa.Table.from_pandas(df) # doctest: +SKIP
>>> with open("myfile", mode="wb") as f: # doctest: +SKIP
... for batch in t.to_batches(): # doctest... | d599caff58d48efefa9b4367ec9844a538081b1e | 44,889 |
def random_min_var(pbcids, actual_votes, xs, nonsample_sizes):
"""
Choose the county to audit by choosing the county that minimizes the
variance for the estimated number of final votes for A in that county.
This formula uses the normal approximation as seen in Rivest's estimation
audit paper: in p... | 4af8c280137d4d2d608710d5879ff9448e802067 | 44,890 |
import torch
import math
def count_qubits_gate_matrix(gate: torch.Tensor):
"""Get the number of qubits that a gate matrix acts on.
By convention, a gate matrix has the shape
(*optional_batch_dims, 2^k, 2^k)
where k is the number of qubits that the gate acts on. Note that
k might be smaller ... | def1082c7e598589cf09aa3dfe67ce6598a93990 | 44,891 |
from typing import List
from typing import Tuple
def logits_to_span_score(start_logits, end_logits, context_length, max_span_length=30):
"""
This is batched operation that convert start logits and end logtis to a list of scored, span.
Each example of the two logits will also depends on the context length.... | 55216cd67933d8d6150097dd62e0a209958dd243 | 44,893 |
def greatest_common_superclass(*types):
"""
Finds the greatest common superclass of the given *types. Returns None if
the types are unrelated.
Args:
*types (type):
Returns:
type or None
"""
if len(types) == 1:
return types[0]
mros = [t.__mro__ for t in types]
... | dedbb52f3927a8d53408c72073a7fb04a4c5435f | 44,894 |
def most_affected_area(affected_areas_count):
"""Find most affected area and the number of hurricanes it was involved in."""
max_area = 'Central America'
max_area_count = 0
for area in affected_areas_count:
if affected_areas_count[area] > max_area_count:
max_area = area
max_area_count = affected... | e7abbf76f2f7cf10183fefadca943bdac83c33be | 44,895 |
import re
def capitalize(nom):
"""Donne la capitalisation correcte pour un nom de région."""
nom = nom.lower()
# On split sur les non-mots, en les conservant
fragments = re.split(r"(\W)", nom)
cap_frag = []
for f in fragments:
if re.match(r"\W", f):
cap_frag.append(f)
... | f5c21d308c6168a94cd769a3fa121374ddebf416 | 44,900 |
import numpy
def nNans(arr,column=0):
"""
Counts up the number of occurances of NaN in a row of a 2-d array
"""
if len(arr.shape) != 2:
raise RuntimeError('nanRows works only on 2-d arrays, this array had shape %s' % (str(arr.shape)))
nans = arr[:,column] == numpy.nan
return len(numpy.nonzero(nans)[0]) | 776d1a41e9cdf2ce008c58d29bc7c9f3d2a3de5a | 44,901 |
import re
def word_list(raw):
"""
Converts raw sentences to list of words.
:param raw: sentence to be cleaned up
:return: list of words
"""
clean_words = re.sub(r"[^a-zA-Z]", ' ', raw)
return clean_words.split() | 25bd3d04c4dca62cbe724da677e0da54f883ec4e | 44,904 |
def FindPart(part: dict, mime_type: str):
"""
Recursively parses the parts of an email and returns the first part with the requested mime_type.
:param part: Part of the email to parse (generally called on the payload).
:param mime_type: MIME Type to look for.
:return: The part of the email with the... | ab557300860b6030acc5b851aa5bdb10ae2850cc | 44,905 |
def shape_select(dict_sizes, max_size):
"""takes a dict in parameter, returns list of shapes\
of blocker of at most max size"""
shapes = []
for size in dict_sizes:
if size is not None and max_size is not None and size <= max_size:
for item in dict_sizes[size]:
shapes.appe... | be209776c349df756ce37b34f6ea9bb819fc4313 | 44,906 |
from functools import reduce
def scalar_prod(scalars_list):
"""
This method returns the product of the list of scalars which it has as
input.
Parameters
----------
scalars_list : list[int|float|complex] | tuple[int|float|complex]
Returns
-------
complex|float|int
"""
if ... | b6ab3834e8e8eb175c8b3da92c042fd83458fbf3 | 44,907 |
def get_column_headers(df):
"""Return column headers for all count colums in dataframe."""
col_headers = [name for name in df.columns if 'ct' in name]
return col_headers | 3e08ce7d11b2cd911cc412f780806c7301b085af | 44,908 |
def strategy(history, memory):
"""
Defect every few turns, based on the fibonacci sequence.
i.e., defect turn 2 (1), turn 3 (1), turn 5 (2), turn 8 (3), turn 13 (5)
"""
if memory is None:
last_defection_turn = 0
prev_fibonacci = 1
current_fibonacci = 1
else:
last_... | 009710f3fb9eb4c5802b3beb0239afe2de6acdfb | 44,909 |
def trim_words(s, max_chars, separator=' '):
"""
Trim sentence at last word preceding max_chars
"""
if max_chars and len(s) >= max_chars:
head, sep, tail = s[:max_chars].rpartition(separator)
return (head or tail) + '...'
else:
return s | 1ef9a79734d81c9ce72beba4251d41358a4f2bbe | 44,910 |
def isDmzProxySecurityLevelValid( level ):
"""Indicates whether the supplied level is valid for secure proxy security."""
if (('high' == level) or ('medium' == level) or ('low' == level)):
return True
return False | ea00bd321e6e3aaf955cfbb017638cfbc93ce578 | 44,911 |
def create_cifar_filter_func(classes, get_val):
"""Create filter function that takes in the class label and filters if it
is not one of classes. If get_val is True, subtracts 50 from class label
first (since validation for CIFAR-50 is done on last 50 classes).
"""
if get_val:
return lambda x... | db2cb98798636a76ad6515bc5bbd00507e6f9fa8 | 44,912 |
def slice_function_graph(function_graph, cfg_slice_to_sink):
"""
Slice a function graph, keeping only the nodes present in the <CFGSliceToSink> representation.
Because the <CFGSliceToSink> is build from the CFG, and the function graph is *NOT* a subgraph of the CFG, edges of
the function graph will no ... | d88f6784ebae21e5a8d2132542daf662e8cb250f | 44,913 |
from typing import Counter
def repeating_bits(n: list[str], index: int) -> tuple:
"""
Find most and least repeating bit in given index
:param n: list of numbers as strings
:param index: index of bit to find
:return: tuple of most and least repeating bit
"""
bits = [int(i[index]) for i in n... | b002c35d38b793c173a0449e4b89f8dd459afd7d | 44,914 |
import csv
def load_asdp_ordering(orderfile):
"""
Loads an ASDP ordering produced by JEWEL from a CSV file
Parameters
----------
orderfile: str
path to order CSV file
Returns
-------
ordering: list
list of dicts containing entries for the following fields:
... | 430bdea030c6399e258dd49548a954069fe89851 | 44,915 |
def show_admin_tools(on=0):
"""Mostrar Ferramentas Administrativas no Painel de Controle
DESCRIPTION
Esta entrada lhe permite definir se o applet "Ferramentas
Administrativas" e mostrado no Painel de Controle.
COMPATIBILITY
Windows XP
MODIFIED KEYS
{D20EA4... | 1835fbcf93c21940e209a3b71bf91731395631a3 | 44,916 |
def funcname(fn, rep='-'):
"""
Gets the name of a function from a function object
"""
return fn.func_name.replace('_', rep) | c82b678e82cba0d4ad4bc598c08079717469027f | 44,917 |
import sys
def sol(arr, n, v):
"""
If V == 0, then 0 coins required.
If V > 0
minCoin(coins[0..m-1], V) = min {1 + minCoins(V-coin[i])}
where i varies from 0 to m-1
and coin[i] <= V
"""
dp = [sys.maxsize for i in range(v+1)]
... | 4df621e1821a89ec28601949b52fad568569ca17 | 44,919 |
def get_metric_BASE_T(map_dict, metric=None):
"""
:param map_dict: Parsed mapping.json as a dict
"""
if not isinstance(map_dict, dict):
raise
if metric is None:
return
for period in map_dict['period_colls']:
metrics = map_dict.get(str(period))
if not metrics:
... | f7ba0da4b80db796ee6bfb0150a5783bcf1f31bc | 44,921 |
def day_humidity_chart(qs_list, plot_func, width, height, colors):
"""
Returns a URL which produces one line for each queryset.
"""
data_list = [] # list of value lists
for date_qs in qs_list:
humidity = []
for rec in date_qs:
if rec is None:
humidity.ap... | e84aa381b69fd9cf7bdf6a69db2b612268f00df3 | 44,922 |
def _to_mumps_number(v):
"""Given a value, attempt to coerce it to either an integer or float."""
sign = 1
ndec = 0
try:
tmp = float(v)
if tmp.is_integer():
return int(tmp)
else:
return tmp
except ValueError:
v = str(v)
n = []
... | 410246c14e55de56209e6b19c7a94102ca03893b | 44,923 |
from re import sub
def unmodify(peptide):
"""
>>> from re import sub
>>> sub(r'\[(\-|\d|\.)+\]', '', 'A[-12.34]B')
'AB'
"""
peptide = sub(r'\[(\-|\d|\.)+\]', '', peptide)
peptide = sub(r'^.\.|\..$|n|c', '', peptide)
#peptide = sub(r'\..$', '', peptide)
#peptide = sub(r'\[.+\]', ''... | 7565d4c8f5b67ce138aeaea5d6d5c759768af618 | 44,924 |
def indent_lines(message):
"""This will indent all lines except the first by 7 spaces. """
indented = message.replace("\n", "\n ").rstrip()
return indented | 2315eff60b737d7c418d73e2fdd97851a1db6ff1 | 44,925 |
def generate_shard_args(outfiles, num_examples):
"""Generate start and end indices per outfile."""
num_shards = len(outfiles)
num_examples_per_shard = num_examples // num_shards
start_idxs = [i * num_examples_per_shard for i in range(num_shards)]
end_idxs = list(start_idxs)
end_idxs.pop(0)
end_idxs.append... | 8f059536a8ab2e36c89e5f6a6fe8dc4d827a782d | 44,927 |
import os
def get_signatures_with_results(vcs):
"""Returns the list of signatures for which test results are saved.
Args:
vcs (easyci.vcs.base.Vcs)
Returns:
List[str]
"""
results_dir = os.path.join(vcs.private_dir(), 'results')
if not os.path.exists(results_dir):
retu... | e561dde58e9df5b540c2ea51b59472dbbefb4753 | 44,929 |
def find_biggest_pattern_in_patterns(dict):
"""
dict: dictionary of translation vector->pattern
Returns the biggest pattern and its corresponding translation vector.
"""
max_length = -1
pattern = None
trans_vector = None
for key in dict:
if len(dict[key])>max_length:
... | 34e658369145ccb30d25ba5d1d80085a61f68413 | 44,931 |
def _installable(args):
"""
Return True only if the args to pip install
indicate something to install.
>>> _installable(['inflect'])
True
>>> _installable(['-q'])
False
>>> _installable(['-q', 'inflect'])
True
>>> _installable(['-rfoo.txt'])
True
>>> _installable(['proje... | 1a374c75fca3289f0f6f86321cc7b76eee4c7d3b | 44,932 |
import random
def simulated_multi_experiment(design_thing, models_to_fit, response_model):
"""Simulate an experiment where we have one response model, but have mulitple models
which we do parameter estimation with and get designs from."""
if response_model.θ_true is None:
raise ValueError("respon... | e459db2a9dc99fd0f8e53430fd8c9289b75db63e | 44,933 |
import os
import sys
def command_name():
"""Return a cleaned up name of this program."""
return os.path.basename(sys.argv[0]) | 366484a0511366181b584c0c2eac6277381fcb52 | 44,935 |
def gen_none():
"""Generate nothing!."""
return None | c1d9e506e7e4af8a987e71875a20d4bac9dc338d | 44,937 |
from typing import Counter
def sum_counters(counters):
"""Aggregate collections.Counter objects by summing counts
:param counters: list/tuple of counters to sum
:return: aggregated counters with counts summed
>>> d1 = text_analyzer.Document('1 2 fizz 4 buzz fizz 7 8')
>>> d2 = text_analyzer.Docu... | c73f374639851548a4e11249ae7faf0dc1b80956 | 44,939 |
import re
def remove_special_chars(headline_list):
"""
Returns list of headlines with all non-alphabetical characters removed.
"""
rm_spec_chars = [re.sub('[^ A-Za-z]+', "", headline) for headline in headline_list]
return rm_spec_chars | 641a8fd8083771386ec83f5f5c27c38b6bbebf0e | 44,940 |
import time
import calendar
def gen_date_list(begin_date, end_date):
"""Generates a list of dates of the form yyyymmdd from a being date to end date
Inputs:
begin_date -- such as "20070101"
end_date -- such as "20070103"
Returns:
date_list -- such as ["20070101","20070102","20070103"]
... | 7663b5329e0a7ac65910c1b2df39205758c75c58 | 44,941 |
def n(indexes):
"""Return n ranking index sets in colexicographical order.
>>> [n(ind) for ind in ((), (0,), (1,), (0, 1), (2,))]
[0, 1, 2, 3, 4]
"""
return sum(1 << i for i in indexes) | b4317c17173df5bd164ad34e8e9761b6afcad9ba | 44,943 |
def frames_to_time(frames, framerate):
"""Convert frame count to time (using framerate)."""
return frames / framerate | 398ce55c09706c286a682c86452f10d9bd8e1140 | 44,944 |
def int2verilog(val, vw):
"""
:param val: A signed integer to convert to a verilog literal.
:param vw: The word length of the constant value.
"""
sign = '-' if val < 0 else ''
s = ''.join((sign, str(vw), '\'sd', str(abs(val))))
return s | 42e82203cb5cfd4015664e49b94091d027979d23 | 44,945 |
def difference(
f_inverted_index,
s_inverted_index
) -> list:
"""
Operator "OR"
:type f_inverted_index: list
:type s_inverted_index: list
"""
if (not f_inverted_index) and (not s_inverted_index):
return []
if not f_inverted_index:
return []
if not s_invert... | fc8e5f840f6c09c93f8409624639d5c800b331d9 | 44,946 |
from pathlib import Path
def project_dir():
"""Return the root directory of the project."""
script = Path(__file__).resolve()
return script.parents[1] | 85b6d50222773ec5d67ac02493faa79357f81571 | 44,947 |
def get_index_names(df):
"""
Get names from either single or multi-part index
"""
if df.index.name is not None:
df_index_names = [df.index.name]
else:
df_index_names = list(df.index.names)
df_index_names = [x for x in df_index_names if x is not None]
return df_index_names | 143f7e86594d39ccb19ab1e4e36cd9933cb07304 | 44,949 |
import json
def parseinputquery(query):
""" Checks naively whether the input could be a MongoDB query-clause
If not returns a MongoDB text search query-caluse with given input
being the search term
"""
qc = None
if isinstance(query, dict):
qc = query
else:
try:
... | cf537cc66189b4beea08127ad2e75d3d3b6acc75 | 44,951 |
import re
def sanitize_path(path):
"""Replace illegal path characters and spaces in path."""
return re.sub(r"[^a-zA-Z0-9_\-/\.]", "", path.replace(" ", "_")) | c74db40399524f6deedc023ca76e828fc3d4019e | 44,952 |
def get_coordinates(region):
""" Define coordinates chr, start pos and end positions
from region string chrX:start-end. Return coordinate list.
"""
chromosome = region.split(":")[0]
coord = region.split(":")[1]
coord_list = coord.split("-")
begin = int(coord_list[0])
end = int(coord_list... | 3e76420ad607d5dfb195992fb5466b118bd67bcd | 44,953 |
def getSocketFamily(socket):
"""
Return the family of the given socket.
@param socket: The socket to get the family of.
@type socket: L{socket.socket}
@rtype: L{int}
"""
return socket.family | e67095574949dc12022676b2795010aff3a12446 | 44,956 |
def import_param_space(filename):
"""
gets the variable param_space from a file without executing its __main__ section
"""
content = ""
with open(filename) as f:
lines = f.readlines()
for l in lines:
if "if __name__ ==" in l:
# beware: we assume that the _... | 2f40f7c400b911acfc49726ae508cfee434652b5 | 44,957 |
def rename_part(oEditor, oldname, newname):
"""
Rename a part.
Parameters
----------
oEditor : pywin32 COMObject
The HFSS editor in which the operation will be performed.
oldname : str
The name of the part to rename
newname : str
The new name to assign to the pa... | cb255d54a11aa37a48958be651a93b3f80e3b85b | 44,958 |
import requests
import json
def address(coordinate, key, poitype=None, radius=None):
"""显示经纬度规定范围内的建筑信息和街道信息"""
url = "https://restapi.amap.com/v3/geocode/regeo?parameters"
parameters = {
"location": coordinate, # 经纬度坐标字符串
"key": key, # 高德web key
"radius": radius if radius else 1... | 90e0b86ae9281d30593d1c8c1a51e9dc38a5861a | 44,960 |
def get_shape_points2(cur, shape_id):
"""
Given a shape_id, return its shape-sequence (as a dict of lists).
get_shape_points function returns them as a list of dicts
Parameters
----------
cur: sqlite3.Cursor
cursor to a GTFS database
shape_id: str
id of the route
Return... | 7e7708a155f2f04510844565054fb32d0b770e1a | 44,961 |
def get_matching_card(card_list, card_to_match):
""" This function returns the card that matches the one passed in """
the_matching_card = None
for test_card in card_list:
if test_card.value == card_to_match.value and test_card != card_to_match:
the_matching_card = test_card
... | 7c67fa95465c131ef11703096c3bb8ac77531ed1 | 44,962 |
def generate_sorted(degree):
"""
Generates list of numbers in ascending order.
"""
lst = []
for i in range(2**degree):
lst.append(i)
return lst | 1dcf27801f4e253a87294dcb4aa742fdd12c525f | 44,963 |
def indices(A):
"""
Return a sequence containing all the indices for elements in A.
>>> indices([6, 3, 2, 9, 10])
[0, 1, 2, 3, 4]
"""
return range(len(A)) | da06e01da439144851b005fb22ec050932d8c5f0 | 44,964 |
def topic_word_set(topic):
"""topic_word_set. Takes a topic from an LDA model and returns a set of top
words for the topic.
Parameters
----------
topic : (int, [ (str, float)])
A topic from a LDA model. Input should be one element of the list
returned by get_topics.
"""
word... | e9ca50712155769bc699af9634fb79986965d91d | 44,967 |
from typing import List
def _erase_elements_from(items: List, start_i: int):
"""
Erase from the given 'i' onward
>>> _erase_elements_from([1, 2, 3], 0)
[None, None, None]
>>> _erase_elements_from([1, 2, 3], 1)
[1, None, None]
>>> _erase_elements_from([1, 2, 3], 2)
[1, 2, None]
>>>... | 5e3694272bca02dadbbf154a4132ea9dfdda8097 | 44,968 |
def get_ods_by_race_3rentan(xml):
"""
3連単 のページを読み込み、オッズを得る
"""
ods_3rentan = []
tag_tables = xml.find_all('table', \
attrs={'class': 'santanOddsHyo'})
for tag_table in tag_tables:
tag_tbody = tag_table.find('tbody', recursive=False)
if tag_tbody is None:
tag_... | f4cb6a5f370721432d561a0b200d12923e020edb | 44,969 |
def mapping(n, start1, stop1, start2, stop2):
"""Set the background color for the p5.renderer.
:param args:
:param args:
:param args:
:param args:
:param args:
:returns: """
return ((n - start1) / (stop1 - start1)) * (stop2 - start2) + start2 | 0910df41bcc986ac87c5d5d35597905118a91adc | 44,970 |
def cyclic_rotation_2(nums: list, k: int) -> list:
"""
This modifies the array nums in place though
"""
length = len(nums)
if length == 0:
return nums
k = k % length
nums[:] = nums[length - k:] + nums[:length - k]
return nums | 306ab9bbf02067aeea6513accd346c56b1ba2c5f | 44,971 |
import re
def hump_to_underline(hump_str):
"""
Transfer hump to underline
Args:
hump_str(string): hump code string
"""
p = re.compile(r'([a-z]|\d)([A-Z])')
sub = re.sub(p, r'\1_\2', hump_str).lower()
return sub | 9f91ccfbc3dcac284e75a40de88f0e668f113fdf | 44,972 |
import requests
def get_json(url, payload=None, verbose=True):
""" Get JSON from an online service with optimal URL parameters. """
r = requests.get(url, params=payload)
if verbose:
print("Fetched: {}".format(r.url))
if r.status_code != 200:
print("Error: {}.".format(r.status_code))
... | 02ec9a3648946c8cc9999a61573378bbb12174c1 | 44,973 |
def unpack(s):
"""Convenience function to get a list as a string without the braces.
Parameters
----------
s : list
The list to be turned into a string.
Returns
-------
string
The list as a string.
"""
x = " ".join(map(str, s))
return x | fa5933cb9f67ebff699ab5751f8b188f9764f693 | 44,974 |
def group_instance_count_json(obj):
"""
Test lifecycle parser
>>> group_instance_count_json(json.loads('{ "AutoScalingGroups": [ { "Instances": [ { "LifecycleState": "InService" } ] } ] }'))
1
"""
if not obj['AutoScalingGroups']:
return 0
instances = obj['AutoScalingGroups'][0]['Ins... | 141c165f11d9582e50c5e35cf2b4925b4d382692 | 44,975 |
import timeit
def tree_complexity(tree, words):
"""Estimate complexity of lookup with trie."""
start_time = timeit.default_timer()
for word in words:
tree.search(word)
return timeit.default_timer() - start_time | cb3fbf63100854a50c783db43b64c8fcb6b41cc0 | 44,976 |
import re
import json
def read_jsonc(file: str) -> dict:
"""Cコメント付きJSONファイルを読み込む
Args:
file (str): JSONファイル
Returns:
dict: JOSNオブジェクト
"""
with open(file, encoding='utf-8') as f:
text = f.read()
text = re.sub(r'/\*[\s\S]*?\*/|//.*', '', text)
return json.loads(text... | 1405783375dc7281a743f7d5bfd83734fa7e4c4c | 44,977 |
def chi_squared(*choices):
"""Calculates the chi squared"""
term = lambda expected, observed: float((expected - observed) ** 2) / max(expected, 1)
mean_success_rate = float(sum([c.rewards for c in choices])) / max(sum([c.plays for c in choices]), 1)
mean_failure_rate = 1 - mean_success_rate
return... | c519a8fa9a05d669d18b11e802a47d847dac5f63 | 44,978 |
def getOutputsNames(net):
"""
Get the names of the output layers
"""
# Get the names of all the layers in the network
layersNames = net.getLayerNames()
# Get the names of the output layers, i.e. the layers with unconnected outputs
return [layersNames[i[0] - 1] for i in net.getUnconnectedOutL... | 72470cf88735729313a153737963ac5eaa7e255d | 44,979 |
import os
def relative_module_path(module_file, relative_path):
"""Returns path relative to current python module."""
dir_path = os.path.dirname(os.path.realpath(module_file))
return os.path.join(dir_path, relative_path) | 48a1ca6f4b93175ce587cd973157db30bcd8694b | 44,980 |
import os
def find_image_paths(path, files):
"""Finds image paths from given path."""
# Loop for all files
file_paths = []
for k in range(len(files)):
# Data path
try:
os.listdir(path + "\\" + files[k] + "\\" + "Registration")
file_paths.append(path + "\\" + fil... | ee4dc85992cce83f549dc8fbccabb0d4081829c2 | 44,981 |
from functools import reduce
import operator
def _iterated_domfronts(cfg):
"""Compute the iterated dominance frontiers (DF+ in literatures).
Returns a dictionary which maps block label to the set of labels of its
iterated dominance frontiers.
"""
domfronts = {k: set(vs) for k, vs in cfg.dominance... | 8fdacf245bf0a47ba2f08f03900245f19bad6a2c | 44,982 |
def _is_short_code_start(block):
"""Start with SHORT_CODE_"""
if block.type == "text":
if str(block.title).startswith("<!-- SHORT_CODE_"):
return True
return False | d68c06888a6e3f135b8b633841b312bdc60100d6 | 44,984 |
import imghdr
import os
def get_real_ext(image_path, return_is_same=False):
"""@Image Utils
获取图像文件的真实后缀
如果不是图片,返回后缀为 None
该方法不能判断图片是否完整
Args:
image_path:
return_is_same: 是否返回 `is_same`
Returns:
ext_real, is_same
真实后缀,真实后缀与当前后缀是否相同
如果当前文件不是图片,则 ext_real... | 227dbb7c1bf524c5044791a89a7049aac7004cf3 | 44,985 |
def _msd_anom_1d(time, D_alpha, alpha):
"""1d anomalous diffusion function."""
return 2.0*D_alpha*time**alpha | ba4b2e3ec597f2a936fca73423e31642403a4b55 | 44,986 |
import sys
def filter_nan_cols(df, col):
"""Filtering nan columns if present
"""
if df[col].isnull().values.any():
msg = 'WARNING: nan values found in column: "{}". Filtering these nan rows\n'
sys.stderr.write(msg.format(col))
return df.dropna(subset=[col]) | fa80fe54c13ae6c5c88eb67c03deae16868a9f5a | 44,987 |
def get_output_size(dataloaders):
"""
Infer the expected output size and task to perform
Args:
dataloaders: dict of torch.dataloader objects
Return:
an int, inferred output size
a str, task to carry out
"""
# Find the max amount of unique labels among dataloaders
nb_labels = 0
labels_data_type = None
... | 1886e2b1ca9279846b761bc8efe259fc66550cac | 44,988 |
import numpy as np
def str_list_2_num(str_list):
"""
Take a list of strings to correlative numbers
"""
classes = np.unique(str_list)
num_list = []
# print(classes)
for current_string in str_list:
num = 0
flag = 'go'
for current_class in classes:
if ... | 5bf41f18298728a98f889f7f828f0eecb499e7a1 | 44,989 |
def list_flavors(flavor_table, level):
"""
:usage: Calling the function in the terminal (python list_flavors.py)
reads in the scaa_flavor_wheel.json file containing coffee flavors
wheel and creates flavor_table.json and flavor_table_processed.json
saved in the current directory for further processing.
... | 6266b09700f56f2bd01bf1a06ab30c22241b531b | 44,991 |
def create_basename(args):
""" Name to characterize the data. Can be used for dir name and file name. """
ls = args.drug_fea + args.cell_fea
if args.src is None:
name = '.'.join(ls)
else:
src_names = '_'.join(args.src)
name = '.'.join([src_names] + ls)
name = 'data.' + name
... | 0588972eeed81cef2ce9cb143da45bce444a0229 | 44,992 |
from pathlib import Path
def _validate_ignore_cells_with_warning(actual: str, test_nb_path: Path) -> bool:
"""Validate the results of notebooks with warnings."""
expected_out = [
"cell_2:3:1: F401 'glob' imported but unused",
]
expected = "".join(f"{str(test_nb_path)}:{i}\n" for i in expected_... | 9a505973a63cb04761951e4edf996e2ce27fa09e | 44,993 |
from pathlib import Path
def base_path():
"""
Use the Path library to define the file path to the test folder. To be used when loading or saving test data.
This works for almost all tests except for saving models in FCpredictor and XGBpredictor. For those use root_dir
"""
return Path(__file__).par... | f1836333477acedd6a8b1d11b0d1b3517006c0bc | 44,995 |
import importlib
import operator
def _evaluate(object, property=None):
"""Take a dotted string and return the object it is referencing.
Used by the Forward types."""
try:
object = importlib.import_module(object)
if property is None:
return object
except ModuleNotFoundError:
... | dd000f0992896093acb1ffebd8ef8b433f401cab | 44,997 |
import pickle as pkl
from typing import Any
import os
def unpickle(path :str) -> Any:
"""Function that loads a pickle file generated by [`pickle(path)`](./#pickle).
Arguments:
path: File path to a valid pickle file.
Returns:
The unpickled object.
"""
if not os.path.isfile(path):... | e1258dde3620533e3b9deb3271769ba170b4e3c8 | 44,998 |
def parse_pkg_list(output):
"""
:param output: show install active/inactive summary
:return: a list of active/inactive packages
"""
pkg_list = []
flag = False
lines = output.split('\n')
lines = [x for x in lines if x]
for line in lines:
if 'ctive Packages:' in line:
... | 221cb19b05f7e3b88695a722b59de9bba3b17b40 | 44,999 |
def is_permutation(n, d):
"""Checks to see if n is a permutation of the digits 0-d."""
n = [int(i) for i in str(n)]
if len(n) < d or len(n) > d+1:
return False
elif len(n) < d+1:
n.insert(0, 0)
while n:
i = n.pop(0)
if i in n or i > d:
return False
ret... | 7b06ba08c9efa07b82d3d51e9792b3e0499887f6 | 45,000 |
def m3c_config_str(config):
"""Change the dtype of parameters and make a appropriate string"""
int_parameters = {
'overlap': 6,
'r1_left_cut': 10,
'r1_right_cut': 10,
'r2_left_cut': 10,
'r2_right_cut': 10,
'quality_threshold': 20,
'length_threshold': 30,
... | d73daa7d10d6913c0fdc5f7180d365d024a87ee4 | 45,001 |
def bubble_sort(items):
"""Sorts a list of items in ascending order.
"""
for i in range(len(items)):
swapped = False
for j in range(len(items) - 1):
if items[j] > items[j+1]:
swapped = True
items[j], items[j+1] = items[j+1], items[j]
if not... | 16f392bfea089c146a8a59f6e886283893f0ea51 | 45,003 |
def verify_account_available(email):
"""
Check to see if this email is already registered
"""
#Run a query, use an ORM, use Twilio to call someone and ask them :-)
return True | e29af1103af6e7764e372d46ef4f118ac6e4ac14 | 45,004 |
async def remaining(github):
"""Helper to calculate the remaining calls to github."""
try:
ratelimits = await github.get_ratelimit()
except: # pylint: disable=broad-except
return 0
if ratelimits.remaining:
return int(ratelimits.remaining)
return 0 | c1614b51e21c4f1dd807ce35ba2196a0a9067bc1 | 45,007 |
def guard_duty_all(*_):
"""
author: spiper
description: Alert on GuardDuty events
playbook: (a) identify the AWS account in the log
(b) identify what resource(s) are impacted
(c) contact the point-of-contact for the account
testing: Fro... | 19e943eb0c292197b899c70cefe9c01e0bec2898 | 45,009 |
def getMinMaxOfRangeList(ranges):
"""
Get the min and max of a given range list.
"""
_max = max([x[1] for x in ranges])
_min = min([x[0] for x in ranges])
return _min, _max | b7fe06dab71df72a54873401f2c0955910ef8d7c | 45,010 |
from typing import List
from typing import Dict
import sys
def build_variable_table(definitions: List[str]) -> Dict[str, float]:
"""Parse the list of `-d` switches and return a dictionary associating variable names with their values"""
variables = {}
for declaration in definitions:
parts = declar... | 260267c85aff0f64e10ac7c773a980d30901b4ed | 45,011 |
import os
import errno
def mkdir(directory):
"""
recursivley create a directory if it does not exist
:param directory: path to the directory to be created
:return: directory
"""
directory = os.path.abspath(directory)
try:
os.makedirs(directory)
except OSError as e:
if ... | 7176d1e3cf9d252095deae76d680b0d6bfc8a091 | 45,012 |
import functools
def ensure_key_exists(func):
"""Decorator that checks if the provided key is valid"""
@functools.wraps(func)
def wrapped(*args, **kwargs):
self, key = args[0], kwargs.get('key', args[1])
if key not in self._defaults:
raise KeyError(f"The specified key is not i... | 6311784120d1c401e006713ea1c41330bb51800c | 45,014 |
import numpy
def inv_mass(pt1, eta1, phi1, pt2, eta2, phi2):
"""
Assumes massless particles (ok for photons/eles, probably need to update for heavier particles)
"""
mass = float(0)
mass = numpy.sqrt(2 * pt1 * pt2 * (numpy.cosh(eta1 - eta2) - numpy.cos(phi1 - phi2)))
return mass | ae30336c889ab621c5b722345685c78e28840710 | 45,015 |
def unique_list(l, preserve_order=True):
"""Make list contain only unique elements but preserve order.
>>> l = [1,2,4,3,2,3,1,0]
>>> unique_list(l)
[1, 2, 4, 3, 0]
>>> l
[1, 2, 4, 3, 2, 3, 1, 0]
>>> unique_list(l, preserve_order=False)
[0, 1, 2, 3, 4]
>>> unique_list([[1],[2],[2],[1... | dbc4c1a16538a6be8c114abb7411622eecb5b98c | 45,018 |
import json
def response_error400(err):
"""Return error response."""
data = {
"error": err,
"code": 400,
}
return {
"statusCode": 400,
"body": json.dumps(data)
} | af0b6d536e054971a79cd95e65afac6730baeaf9 | 45,020 |
import re
def extract_ref_numbers_from_bbl(df, filename=None):
"""Extract reference numbers from .bbl file and add them to df.
Args:
df (pd.DataFrame): dataframe containing the data items
spreadsheet.
Keyword Args:
filename (str): path to the .bbl file (created when c... | db518cd569f65ac715a8121c9a1c4b8311101458 | 45,021 |
def get_periodicity(self):
"""Gives periodicity of the axis.
Parameters
----------
self: Data1D
a Data1D object
Returns
-------
per, is_antiper
"""
per = 1
is_antiper = False
if "antiperiod" in self.symmetries:
if self.symmetries["antiperiod"] > 1:
... | bf53aadca7c75ea1e1760b8c6eb149f5f9450ee2 | 45,023 |
def mocked_wikiloader_response():
"""returns wikiloader fake response"""
return {"anecdote": "Une anecdote", "url": "un url"} | ebdb53c1370c96ee2ce5774998391b407afef922 | 45,024 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.