content stringlengths 39 14.9k | sha1 stringlengths 40 40 | id int64 0 710k |
|---|---|---|
import math
def _tree_depth(num_leaves: int, arity: int):
"""Returns the depth of the tree given the number of leaf nodes and arity."""
return math.ceil(math.log(num_leaves) / math.log(arity)) + 1 | 8633da9e1079cd9338126d1174c0e632d49662bd | 42,965 |
from typing import Any
def _rebase_entity_dict(
entity_dict: str, group: dict[str, Any], base_channel_no: int
) -> dict[int, Any]:
"""Rebase entity_dict with base_channel_no."""
new_fields = {}
if fields := group.get(entity_dict):
for channel_no, field in fields.items():
new_fields... | d1b0e6ad0f2e4acb7b333aaacfa10d00449bf0e0 | 42,966 |
def __top_frond_right(dfs_data):
"""Returns the frond at the top of the RF stack."""
return dfs_data['RF'][-1] | faf59ef6af0ea2bd4045fa7de46b67e4ff3e9410 | 42,971 |
def evaluate_sampler( sampler_fn, obs, action ):
"""
:param sampler_fn:
fn(o,k) Function returning sample value
[p1,p2..] List of values per-arm
p1 Scalar value for all arms
:param obs:
:param action:
:return:
"""
if callable(sampler_fn):
sampl... | 10baa933330cb7fc81529ad8091f479d180de34a | 42,973 |
import copy
def unwind(data, max_depth = 1000, stop_term = ''):
""" Unwind nested dictionaries by repeating higher level fields.
Args:
max_depth: (int), maximum depth to unwind.
stop_term: (str), stop unwinding once this term appears as a key in dict.
Returns:
... | ab2ae7ec74d7ec8d84ee885e5760cd9685db2387 | 42,977 |
import math
def delta_angle_degrees(from_angle_degrees, to_angle_degrees):
"""Calculates the shortest signed delta angle."""
delta = to_angle_degrees - from_angle_degrees
return delta - 360.0 * math.floor((delta + 180.0) / 360.0) | a86f5596aef5580aedceb050bef6ed8317ebd9d4 | 42,981 |
def slowComplete(prefix, list_of_words, top):
"""
For a given prefix, provide top suggestions from this list of words.
Parameters
----------
prefix: Signal word used here
list_of_words: a file that has the example format
top: top many suggestions as output
Return
------
the top k recommendations with given ... | 87ddf8727ba8418d3a1d28e0a9153fea7a9532fb | 42,982 |
def get_folder_items(bucket_items, folder_prefix):
"""
Returns items in bucket which belong to a folder
:param bucket_items: items in the bucket
:param folder_prefix: prefix containing the folder name
:return: list of items in the folder without the folder prefix
"""
return [
item['... | 1890be035b994e9e37d9f4a5f174121d174a3fb8 | 42,985 |
from typing import Tuple
def bbox_center(p: Tuple[float, float],
q: Tuple[float, float]) -> Tuple[float, float]:
"""
Return middle point between two points p and q.
"""
(min_lon, min_lat), (max_lon, max_lat) = p, q
center = min_lon + (max_lon - min_lon) / 2, min_lat + \
(ma... | 017a31d06de4bed0ca2f1e8d63bfe7d7234cfaef | 42,989 |
import math
def generate_timecode(ms: int) -> str:
"""
Convert a duration in seconds to ISO8601 hh:mm:ss.sss format
"""
hours = math.floor(ms / (60 * 60 * 1000))
minutes = math.floor(ms / (60 * 1000)) % 60
seconds = math.floor(ms / 1000) % 60
milliseconds = ms % 1000
return (
s... | 817a0d7f8732547f9c30943548870e84533ad18a | 42,990 |
def map_args(tree, args):
"""
Given a tree and a list of arguments, produce the tree with the arguments
instead of integers at the leaves of the tree.
E.g. for tree = [[1, 2], [3, 4]] and args = [a, b, c, d] we get
[[a, b], [c, d]].
"""
(s, t, a) = tree
if a[0] == 1:
return ... | ffe0b977d508d33227586a56dee8cae36f21b31b | 42,991 |
def _TransformOperationName(resource):
"""Get operation name without project prefix."""
# operation name is in the format of:
# operations/projects/{}/instances/{}/.../locations/{}/operations/{}
operation_name = resource.get('name')
results = operation_name.split('/')
short_name = '/'.join(results[3:])
re... | 542968ede55b0da7176f03d9515a5144d6316757 | 42,992 |
import re
def find_col_index(header, col_name):
""" Extracts the column index of the given variable in the data.
Given a list of headers, searches the list for one that first one that contains
the col_name. Uses regex match to search through each header.
Parameters
----------
header : list o... | a5504c2e4bd14966de2b332963bc518e378bd348 | 42,999 |
def formatMultiplier(stat : float) -> str:
"""Format a module effect attribute into a string, including a sign symbol and percentage symbol.
:param stat: The statistic to format into a string
:type stat: float
:return: A sign symbol, followed by stat, followed by a percentage sign.
"""
return f... | 5ab9df157d54a5414fc9cba46d0f73512a8a6c4c | 43,002 |
def camel2snake(text):
"""Convert camel case to snake case. This assumes the input is valid camel
case (if you have some weird hybrid of camel and snake case, for instance,
you'd want to do some preprocessing first).
Parameters
----------
text: str
Camel case string, e.g. vaderSentiment... | 120345ba898777a31adfe720b6ca1041fe39907c | 43,004 |
def _ok_to_all_filter(x):
"""This is the default filter function."""
return True | bf78924eb68b21f736366007f083bfb09c8dedcd | 43,010 |
def compare(a, b):
"""None-aware comparison helper for Lisplet.
>>> compare(None, None)
0
>>> compare(None, 12)
-1
>>> compare(12, None)
1
>>> compare(12, 12)
0
>>> compare(12, -12)
1
>>> compare(-12, 12)
-1
"""
if a is None:
if b is None:
... | c5fd25f613dc0727c0db0a10dbad4ef3b3d93235 | 43,014 |
def center_crop_numpy(img, cropx, cropy):
"""
Givenn an image numpy array, perform a center crop.
Args:
img : numpy image array
cropx : width of crop
cropy : height of crop
Returns:
cropped numpy image array
"""
y,x = img.shape[:-1]
startx = x//2... | ab69271a947906a6ea515f6846d5c09614b15853 | 43,019 |
import json
def extract_genres(genres_str):
"""Extracts the genres in string form as a list of genres
Arguments:
genres_str {string} -- string containing the genres
Returns:
list -- the extracted genres
"""
genres_str = genres_str.replace("'", '\"')
genres_json = json... | 34dcc0ad7927f61610ac393f71bc744fff18e215 | 43,025 |
import time
def cookie_to_har(cookie):
"""
Convert a Cookie instance to a dict in HAR cookie format.
"""
c = {
'name': cookie.name,
'value': cookie.value,
'secure': cookie.secure,
}
if cookie.path_specified:
c['path'] = cookie.path
if cookie.domain_specifie... | bcfe6258a95b4eea0632023399b3540db6574426 | 43,027 |
def questionize_label(word):
"""Convert a word to a true/false style question format.
If a user follows the convention of using `is_something`, or
`has_something`, for a boolean value, the *property* text will
automatically be converted into a more human-readable
format, e.g. 'Something?' for is_ a... | d69e100a3b37f2632a6e0400c395f99fcba00b4c | 43,029 |
def is_not_empty_value(value):
"""
Checks for empty response values. Demisto recommends returning the None type if a value is empty,
rather than an empty string/list.
"""
return value != "" and value != [] and value != [""] | 202edb774c04b00095be9c96b65614b1dbfdbb28 | 43,030 |
import math
def get_distance(a, b):
"""Return Euclidean distance between points a and b."""
return math.sqrt(pow(a.x - b.x, 2) + pow(a.y - b.y, 2)) | 89c66e586a37a88dbce25460ad3310a035044c73 | 43,031 |
def square_crop(im, target_size=None):
""" Crop image to `target_size`. If that's None the image is squared
to the smallest size
"""
w = im.size[0]
h = im.size[1]
target_size = target_size if target_size else min(w, h)
dx = (w - target_size) / 2
dy = (h - target_size) / 2
return im.crop((dx, dy, d... | 28fb58b21ca4b15e6d48c9345fb31aa333cd7276 | 43,038 |
def output(s):
"""Convert to text output format."""
out = ' 1 2 3 4 5 6 7 8 9\n'
out += ' +-----+-----+-----+\n'
for i in range(9):
out += str(i + 1) + '|'
for j in range(9):
v = s[i * 9 + j]
if v == 0:
out += ' '
else:
... | f0c80b7ec7350813dd80f2aab8c1f6f3e05847da | 43,040 |
def annotate(origin, reference, ops, annotation=None):
"""
Uses a list of operations to create an annotation for how the operations
should be applied, using an origin and a reference target
:param origin: The original iterable
:type origin: str or list
:param reference: The original target
... | d6012776b26d90944af535ce04a9d25e6298ffe7 | 43,044 |
from typing import Dict
from typing import Callable
import torch
def evaluate_dict(
fns_dict: Dict[str, Callable], source: torch.Tensor, target: torch.Tensor, reduction: str = "mean"
) -> Dict:
"""Evaluate a dictionary of functions.
Examples
--------
> evaluate_dict({'l1_loss: F.l1_loss, 'l2_loss... | 3ff55304f2b16440683ed80b7f5447ef6e9782da | 43,047 |
def replace_apostrophes(input: str) -> str:
"""Treats the presence of apostrophes so it doesn't break the XPath filter expression.
Args:
input (str | int): input
Returns:
str: XPath filter expression with apostrophes handled.
"""
if not isinstance(input, str):
return str(in... | 11df3265a8ed69999bf43d427dd8ec66ee88ccfb | 43,048 |
import json
def j(d):
""" Print dict as json view """
try:
d.pop('_id', None)
return json.dumps(d, indent=4, default=str, ensure_ascii=False)
except:
return d | ce4fe6c15df9c5e73b6ec00cb6795ada4629eb47 | 43,054 |
from typing import Dict
from typing import Any
def rename_dict_keys(input_dict: Dict[str, Any], prefix: str) -> Dict[str, Any]:
"""
Creates a copy of an input_dict with keys carrying the prefix specified
"""
current_keys = input_dict.keys()
new_keys = [prefix + i for i in current_keys]
new_d... | 32bdd0a6f8046bb6528d2cdaf45c237c972996d1 | 43,060 |
def _get_mapping_dict(ch_names: list[str]) -> dict:
"""Create dictionary for remapping channel types.
Arguments
---------
ch_names : list
Channel names to be remapped.
Returns
-------
remapping_dict : dict
Dictionary mapping each channel name to a channel type.
"""
... | 782cda9c43749f71241dbef65f5654eafd7e07f4 | 43,066 |
import shutil
def find_program(*programs):
"""Returns the path to the first program in PATH with a name in `programs`.
Returns None on failure."""
for prog in programs:
val = shutil.which(prog)
if val:
return val
return None | 92d3c49f9b7738c203f4dd1f55252052001ed5b3 | 43,073 |
def calculate_overlap_area(cloth: list) -> int:
"""
Calculate the total area of overlapping claims
:param cloth: List of claims made on each square inch of the cloth
:return: Area of overlapping claims
"""
area = 0
for row in cloth:
for col in row:
area += (len(col) >= 2... | fa357c69e095571670ef8650c53d577b42ce09b1 | 43,074 |
def isotopeMaxBD(isotope):
"""Setting the theoretical max BD shift of an isotope
(if 100% incorporation).
Parameters
----------
isotope : str
name of isotope
Returns
-------
float : max BD value
"""
psblIsotopes = {'13C' : 0.036,
'15N' : 0.016}
... | 7fff5bc6a54034e68357af6a08e000de34d59283 | 43,081 |
import re
def parse_frequency(freq):
"""
Parses a frequency string and returns the number of seconds.
Supported formats: 1s, 1m, 1h, 1d, 1w, 1y
"""
m = re.search('^(\d+)(s|m|h|d|w|y)$', freq.lower())
if m is None:
raise ValueError('Input not in required format')
multipliers = {
... | f08306fcf95ca86a4caa5344e629974c5c20d008 | 43,082 |
def construct_doc2author(corpus, author2doc):
"""Make a mapping from document IDs to author IDs."""
doc2author = {}
for d, _ in enumerate(corpus):
author_ids = []
for a, a_doc_ids in author2doc.items():
if d in a_doc_ids:
author_ids.append(a)
doc2author[d]... | 4f07174d9569019fa2488320052952e110addaeb | 43,083 |
def versionless(package):
"""
Removes the version from the package reference
"""
return package[:1+package[1:].find('@')] | 2f52ab9bb406df8a2e74ee56c8f4631cfa83ee6d | 43,084 |
def is_valid_field(field, allow_quote=False, minimum=None, maximum=None):
"""
Validates a generic user inputted field, such as a "name" for an
object. For now, it basically only validates whether single quote
characters should be allowed in the string.
:type field: str
:param field: The data t... | 375b96d891a37115d8a367bc228e020f719da946 | 43,085 |
def set_bits(n, start, end, value):
"""Set bits [<start>:<end>] of <n> to <value> and return <n>"""
mask = ( 1 << end ) - ( 1 << start )
return (int(n) & ~mask) | (int(value) << start) & mask | 203fb5d94750534dbeb136dc3e580be2f7c9d68d | 43,088 |
def _process_string(value):
"""Strip a few non-ascii characters from string"""
return value.strip('\x00\x16') | 5a318bb0336d5b358ef856c39f88bd5037880a2c | 43,094 |
import requests
def request_weather(url):
"""request the weather from openweathermap.org API. Returns a dict of the json file"""
response = requests.get(url)
response_dict = response.json()
return response_dict | c6ae4d38cb849b7956a505a2f0c15c2c1bc98da0 | 43,099 |
def get_reason_from_exception(ex):
"""
Turns an exception into a string similar to the last line of a traceback.
"""
return '{}: {}'.format(ex.__class__.__name__, str(ex)) | 2c8b5d3114c6b950eaef1383f2e88d380f38c965 | 43,101 |
def shrink(pos, fact_x, fact_y=None):
""" Shrink networkx positionings """
if fact_y is None:
fact_y = fact_x
return {i: (x*fact_x, y*fact_y) for i, (x, y) in pos.items()} | 075ced8c46bd9181bed5e9de206e853fb2a508bd | 43,102 |
def is_scalar(x):
"""True if x is a scalar (constant numeric value)
"""
return isinstance(x, (int, float)) | 243786089e4fa7d1a05fa3b8873b87b43ece20a7 | 43,107 |
import functools
def update_wrapper(wrapper, wrapped, assigned=functools.WRAPPER_ASSIGNMENTS,
updated=functools.WRAPPER_UPDATES):
""" Update a wrapper function to look like the wrapped function.
Modified version to support partial and other non-__dict__ objects.
See functools.u... | e40b2abcdd1593f87418340b769484ebea2f4746 | 43,110 |
import json
def read_json(file_path):
"""
Function to read a json file into a data dictionary structure
:param file_path: Path and name of json file to read
:return: A data dictionary with the json content as dict
>>> read_json('./data/test/test_puzzle.json')
{'train': [{'input': [[0, 0, 0, 0... | dbf06a8002f1bda0963eebc2045e9716fb69d938 | 43,113 |
import re
def natural_sort_key(text):
"""
Sort numeric parts of text numerically and text parts alphabetically. Example:
>>> sorted(["9 Foo", "10 Foo", "9A Foo"], key=natural_sort_key)
['9 Foo', '9A Foo', '10 Foo']
"""
return [int(part) if part.isdigit() else part for word ... | a34793ef0b98cf91d2aac8807bcb60e47e197b1c | 43,116 |
def get_subreport_zeros_and_ones(subreport, n_bits):
"""Gets the number of zeros and ones that have each column within the submarine report.
Args:
subreport (): Subset to count from.
n_bits (int): How many bits have each binary number.
Returns:
tuple: Zeros and ones that each column... | 2c8f2839a78690e7056761513d804948e8d1a79d | 43,117 |
def checkCardInHandClicked(game, clickX, clickY):
"""
Returns the card in current player's hand that was clicked, else None
"""
for card in reversed(game.currPlayer.hand): # Reversed so checked from top layer down on gui
if card.imageObj.collidepoint(clickX, clickY):
return card | 17e8293c1536e3a99f5e24a43cceb0a090a78f5d | 43,121 |
import types
def iscoroutine(object):
"""Return true if the object is a coroutine."""
return isinstance(object, types.CoroutineType) | e2b60ba01ddf3a9863be2773128d35cb12adf1c4 | 43,122 |
def mask_shift_set(value, mask, shift, new_value):
"""
Replace new_value in value, by applying the mask after the shift
"""
new_value = new_value & mask
return (value & ~(mask << shift)) | (new_value << shift) | e6ed92669b7f4fb85a4d96cf130dcdf9ffe3d950 | 43,123 |
from typing import Callable
def raise_not_implemented_gen(message: str) -> Callable[[], None]:
"""
Make a function that will raise a NotImplemented error with a custom
message
"""
def not_implemented() -> None:
raise NotImplementedError(message)
return not_implemented | 03aac0a266c686db439ff179c80b0c213a5bb033 | 43,124 |
import torch
def sentences_similarity(first_sentence_features, second_sentence_features) -> float:
"""
Given two senteneces embedding features compute cosine similarity
"""
similarity_metric = torch.nn.CosineSimilarity()
return float(similarity_metric(first_sentence_features, second_sentence_featu... | f7ba47162e9a2348eba23a134c474f400fc3da3a | 43,130 |
def Capitalize(text : str):
"""Returns Capitalized text."""
return text.capitalize() | 955db0a852c14b654fcf489d3f77ce6dbca6bf95 | 43,131 |
def get_param_dict(job, model_keys):
"""
Get model parameters + hyperparams as dictionary.
"""
params = dict((" ".join(k.replace(".__builder__", "").split(".")),
job.get("hyper_parameters." + k, None))
for k in model_keys)
return params | 0cbb24dde3ab28b41b2b5af6fe6f3bdfc66da9bb | 43,132 |
import time
def get_interval_number(ts, duration):
"""Returns the number of the current interval.
Args:
ts: The timestamp to convert
duration: The length of the interval
Returns:
int: Interval number.
"""
return int(time.mktime(ts.timetuple()) / duration) | 2fe90e1e40f7a1d76c8a4410295c5bd80e5e83e6 | 43,138 |
from typing import Tuple
def unit_center(
indices: Tuple[int, int], image_size: Tuple[int, int], stride: int
) -> Tuple[float, float]:
"""Get single prior unit center.
:param indices: current unit's indices tuple
:param image_size: image shape tuple
:param stride: stride for feature map
:retu... | 91f0a2070a26d8335c0e8d2cfd1c80eb59c98b8d | 43,142 |
def __get_int_ordinals(string):
"""
Return the integer ordinals of a string.
"""
output = ""
for char in string:
output += str(ord(char)).rjust(3, " ") + ", "
output = output.rstrip(", ")
return output | 8260716a23773bf0eb7434c0601539fcd1fcc285 | 43,145 |
def modulo(a, b, c) :
"""
Calculates modulo
"""
#print "Modulo of %0d^%0d mod %0d is %0d" % (a, b, c, (int(a)**int(b)) % int(c))
#print a,b,c;
return ((int(a)**int(b)) % int(c)) | eba9d0f633eaa307c4f35020c33496968b939fe6 | 43,147 |
def items_list(mapping, items):
"""Return a list of values from `mapping` in order of the given `items`."""
return [mapping[item] for item in items] | 1707b4339c13aa59c56210c0ae54c882c270d759 | 43,152 |
def get_file_options_string(args):
""" Create a string containing the relevant flags and options based on the
file options from the arguments.
Parameters
----------
args: argparse.Namespace
The parsed arguments
"""
overwrite_str = ""
if args.overwrite:
overwrite_str = ... | f5939692c0ef43b1ae26b97539d276c88c2503b1 | 43,157 |
def sum_of_ints(n):
"""Return the sum of 1 to n"""
return ((n + 1) * n) >> 1 | fa548544d25303deca43e8ea8e1d2fc8f766252a | 43,158 |
import random
def generate_answers(question_3, question_5, range_3, range_5, sample_size=32):
"""
Helper function that generates answers with response times in
a certain range
:param question_3: The question in block 3
:param question_5: The question in block 5
:param range_3: Range of respons... | 6d84284df73cb36bd0602ee4151af72b84bf8ba3 | 43,164 |
def get_date(isoformattime: str) -> str:
"""Extract {YYYY-MM-DD} from ISO 8601 formatted time string.
Parameters
----------
`isoformattime`: `str`\n
An ISO 8601 formatted time string.
Returns
-------
`str`\n
A string containing the date portion of the original time string.
... | 65cf41b841f6133529aada5e914efe25c0bfd503 | 43,166 |
import ast
def ParseTryjobBuildbucketId(msg):
"""Find the buildbucket-id in the messages from `cros tryjob`.
Args:
msg: messages from `cros tryjob`
Returns:
buildbucket-id, which will be passed to `cros buildresult`
"""
output_list = ast.literal_eval(msg)
output_dict = output_list[0]
if 'build... | e664f8ae73ce05d6c87e861e2690fdd06611d6fa | 43,168 |
def to_string(cls):
"""
Return the string representation of a syntax class or a
syntax class instance. Return 'string' by default.
"""
return getattr(cls, 'typed_name', 'string') | 25be3480a9518df3c45137c072f6fe050b4da050 | 43,169 |
import re
def _format_kv_name(setting_path):
"""Return normalized name for use as a KeyVault secret name."""
return re.sub("[^0-9a-zA-Z-]", "-", setting_path) | a722253a065abaa7e4e876e9390c24df47be7af5 | 43,172 |
import re
def ellipsicate(message: str, max_length: int = 40, strip: bool = True) -> str:
"""Return a shortened version of a string if it exceeds max_length.
This will turn 'bizbazfrobnicator' into "biz ... tor".
"""
msg = re.sub(r'\s+', ' ', str(message)) # only allow ' ' for whitespace
if stri... | feb61e075421b55cf50f835f7ebe55171485249b | 43,177 |
import ipaddress
def first_subnet(subnets, version=4):
"""
Returns the first subnetwork of a list, filtered by version
"""
for subnet in subnets:
network = ipaddress.ip_network(subnet)
if network.version == version:
return subnet
return "" | 2d60489d0f87f0dade643cccadee281ebabc9c46 | 43,179 |
def create_record_set(model, X, y):
"""Create a record set for AWS model training"""
X_float = X.astype("float32")
if y:
y_float = y.astype("float32")
return model.record_set(X_float, labels = y_float)
else:
return model.record_set(X_float) | fff904a26bd12ec597f998daafa4709fc663f227 | 43,182 |
import requests
def make_api_call(csv_target):
"""Make http request to IEX Trading API and return useful dataset"""
my_string = ','.join(str(row['symbol']) for row in csv_target)
url = "https://api.iextrading.com/1.0/tops/last?symbols={0}".format(my_string)
response = requests.get(url)
data = resp... | c067c81b167918707eb18ae8acf7f3d07ad31290 | 43,185 |
def buffer(geom, urban_rural):
"""Create DHS cluster buffers
Buffer size:
- 2km for urban
- 5km for rural (1% of rural have 10km displacement, but ignoring those)
Metric units converted to decimal degrees by dividing by width of one decimal
degree in km at equator. Not an ideal buffer ... | ab5264f85ff3da21c23dba937879550fa3c4ac49 | 43,192 |
import math
def calc_saturated_vapour_pressure_air_FAO(temp_air):
"""Saturated vapour pressure of air at temp_air in kPa
From: http://www.fao.org/3/X0490E/x0490e0k.htm
"""
return 0.611 * math.exp((17.27 * temp_air) / (temp_air + 237.3)) | 722b1f5ae8b9b76c56d7c0a5a5961b53e0328fbe | 43,193 |
from typing import Iterable
from typing import Tuple
def get_maximum_path(tree_level_strings: Iterable[str]) -> Tuple[int, Iterable[int]]:
"""Get maximum path value and maximum path for a given tree, represented as level strings.
Solution idea: Compute maximum path from *bottom up*. Hence, the time complexit... | eafc3dfc82bc120742efac5cce793b44db22692a | 43,198 |
def standardize(data, mean, std):
"""Standardize datasets using the given statistics.
Args:
data (np.ndarray or list of np.ndarray): Dataset or list of
datasets to standardize.
mean (number): Mean statistic.
std (number): Standard deviation statistic.
Returns:
n... | c5011d651f7b42f1069da6304f0be8d605ec0b53 | 43,208 |
def api(uri):
"""
Given a URI that uses the ConceptNet API, such as "/c/en/test", get its
fully-qualified URL.
"""
return "http://api.conceptnet.io" + uri | 07cbc671f5c190ecfbed3d04b00392ce4a393f43 | 43,212 |
def potential_reciprocity(s, G):
"""For authors, check whether an acknowledged commenter is author and
has coauthors; for commenters, check whether she is author and has papers
without authors of the paper she is acknowledged on.
"""
if isinstance(s, list):
return any(c in G.nodes() and len(... | ad5a4434a0a0510af719d4d0a964caf11c1a1d24 | 43,213 |
import logging
def handle_depricated_arguments(args):
"""Warn about depricated arguments, use them when possible."""
if hasattr(args, 'block') and args.block:
if hasattr(args, 'coverage'):
logging.warning("--block is depricated, using --coverage %s.",
args.blo... | 9e10e19e310a241c67c5136085a7fd26b24f60cc | 43,218 |
def is_pft(df):
"""Check if df is a per-pft dataframe."""
col_names = df.columns.values
return 'Total' in col_names | 57c5c8f7951f569411e9308809f31aea8a65c160 | 43,225 |
def drop(num, iterator):
"""Drop the first n elements on an iterator"""
try:
for _ in range(num):
next(iterator)
except StopIteration:
return iterator
return iterator | 0e6f05b2a68410523d949e26037ed31dd0409088 | 43,227 |
def uniform(feature, bins):
"""Equal width bin, take a uniform distribution for the sample value range.
Args:
feature: pd.Series, model feature values.
bins: int, split bins of feature.
Returns:
the list of split threshold of feature.
"""
t = (feature.max()-feature.min()... | 1ea90dbc477457499a2ceb2c20ac9bca34e5e7a9 | 43,229 |
def identity(x, *arg, **kw):
""" Identity layer that returns the first input, ignores the rest arguments. """
return x | 7b041be55defb0d9e82f0d028745b15b13ac9df5 | 43,232 |
def getBasePath(request):
""" Get base path where page dirs for attachments are stored. """
return request.rootpage.getPagePath('pages') | c640a83bea5109cfd8652cf3e2e6237f188a10e4 | 43,233 |
def HasAbstractFieldPath(abstract_path, store):
"""Whether a store contains abstract_path.
Makes no provision for repeated fields. I suppose if we did we'd
have it mean, that /any/ of the repeated subfields had such a
subpath but, we happen to not need it.
Args:
abstract_path: the path to test.
... | 465f4c8cc98cf557c9c2036254b985b132071d93 | 43,234 |
def render_dashboard(category, tabs, prefix):
"""Renders a dashboard config string.
Follows this format:
{
name = 'dashboard_name'
dashboard_tab = [
tab('tab-name', 'test-group-name'),
...
]
}
"""
if '\'' in prefix:
raise ValueError(prefix)
... | 64be8cab5e93f53ad2f9b46ed6c21d483b90def5 | 43,235 |
import pickle
def unpickle(filename: str) -> object:
"""
Unpickles a file and returns the object
"""
pickleIn = open(filename, "rb")
pickledObject = pickle.load(pickleIn)
pickleIn.close()
return pickledObject | 891347cfc1f491a40d797332c2967f7b293630af | 43,240 |
def highcharts_plot_view(context):
"""
Dependencies for highcharts_plot_view gizmo.
"""
return ('tethys_gizmos/vendor/highcharts/js/highcharts.js',
'tethys_gizmos/vendor/highcharts/js/highcharts-more.js',
'tethys_gizmos/vendor/highcharts/js/modules/exporting.js') | 05be05ed63964d14e76576ba64134053b7a2745f | 43,247 |
import itertools
def fast_forward_to_length(sequences, length):
"""
Return an itertools.dropwhile that starts from
the first sequence that has the given length.
>>> list(fast_forward_to_length([list(range(n)) for n in range(6)], 4))
[[0, 1, 2, 3], [0, 1, 2, 3, 4]]
"""
return itertools.drop... | 41650d1bede05d96bfb1c1ceb4b94eee2a1c6f53 | 43,248 |
import re
def parse_text_annotations(ann_file):
""" Parses BRAT annotations provided in the .ann file and converts them
to annotation spans of (start_position, end_position, entity_class).
Args:
ann_file (str): full path to the BRAT .ann file.
Returns:
annotations... | 1537f2c044b4562bdc5b2ff89ee74254c399192f | 43,249 |
def _evaluate_expression(frame, expression):
"""Helper function to evaluate expression in the context of input frame
and throw error if evaluation failed. The evaluated SBValue is returned.
"""
result_value = frame.EvaluateExpression(expression)
if result_value is None or (
result_value.GetE... | ef1e51443c0a22b61e1e0a0b9ea2703f8411321a | 43,250 |
import hashlib
def gravatar(email, size=48):
"""
Simply gets the Gravatar for the commenter. There is no rating or
custom "not found" icon yet. Used with the Django comments.
If no size is given, the default is 48 pixels by 48 pixels.
Template Syntax::
{% gravatar comment.user_email [si... | 62a6e47047c5be668995ce8c283f424b2dd28594 | 43,252 |
def get_user_path(path, root):
"""
Gets the path used as the key in the database,
e.g. "/2017/2017 08-19 Yosemite"
:param path: path on the local disk where the photo or dir
is located
:param root: path on the local disk that is the root of all
photos and dirs
"""
user_path =... | 68d41043bf8cc3f168e50fc597e32d144d88655a | 43,255 |
import math
def euc_dst(pnt0, pnt1):
"""return the distance between pnt0 and pnt1,
using the euclidean formula.
`pnts` are geographic and result is in meters.
Args:
pnt0 (list): an xyz data list
pnt1 (list): an xyz data list
Returns:
float: the distance beteween pnt0 and pnt1
... | 8bfb4cd2bb30e2c448e4ec9ea63e0cc7c655b50c | 43,258 |
def get_int_ip(ip):
"""get ip address from ip/mask info
Args:
ip (str): ip with mask
Returns:
str: ip address
"""
return ip.split("/")[0] | 15f7f6dd6b3a8dfdd6b664eba1487eeb33404130 | 43,261 |
def convert_coordinates(coords, stac=False):
"""
Converts footprint coordinates that have been retrieved from the metadata of source SLC scenes stored in an
:class:`~pyroSAR.drivers.ID` object OR a product extent retrieved using :func:`spatialist.vector.Vector.extent` to
either `envelop` and `center` fo... | 361eeef4322fd1976f025e51835c049df23eafa7 | 43,265 |
import importlib
def _load_driver(backend, **kargs):
"""Load the correct backend driver for data persistent."""
bk_module = importlib.import_module('backend', __package__)
driver_cls = getattr(bk_module, str.capitalize(backend) + 'Backend')
return driver_cls(**kargs) | 79066605cf32c99fa8d9b583d333c1b19d6b4a6d | 43,276 |
import sqlite3
def get_schema(db):
"""
Get database's schema, which is a dict with table name as key
and list of column names as value
:param db: database path
:return: schema dict
"""
schema = {}
conn = sqlite3.connect(db)
cursor = conn.cursor()
# fetch table names
curso... | f50ec1eeb237a3c7be6eb34ffc8e197fed333811 | 43,278 |
def get_labels_for_ids(labels, ids, ids_are_one_indexed=False):
"""Get the human-readable labels for given ids.
Args:
labels: dict, string-ID to label mapping from ImageNet.
ids: list of ints, IDs to return labels for.
ids_are_one_indexed: whether to increment passed IDs by 1 to account for
the b... | bc39fe8e7ccaac9ba2abc8a5a2e2fa0a779c82bf | 43,282 |
def div(a, b):
"""Divide a by b."""
return a / b | 0a951296d520391c765f5867eb9d5000b4614aea | 43,291 |
def sum_posts(kinesis_actors):
"""Sum all posts across an array of KinesisPosters
"""
total_records = 0
for actor in kinesis_actors:
total_records += actor.total_records
return total_records | e3198a37d4678383321e0624b6a2ffe2ca8cc038 | 43,294 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.