content stringlengths 35 416k | sha1 stringlengths 40 40 | id int64 0 710k |
|---|---|---|
def _get_file_list(data):
"""
获取用例文件列表
"""
files = []
files_name = []
for index, d in enumerate(data):
print("index:", index)
print("d:", d)
case_file = {
"id": index, "label": d["file"], "children": []
}
if len(files) == 0:
files.a... | b206e7954929a26aad9e36283a14c10ac9c88cc4 | 694,738 |
def split_fqn(title):
""" Split fully qualified name (title) in name and parent title """
fqn = title.split('/')
if len(fqn) > 1:
name = fqn.pop()
return (name, '/'.join(fqn))
else:
return (title, None) | 5595cbc5bf312f4eedf1987925ed08ae0f840087 | 694,741 |
def make_dict_from_csv(fn):
"""
convert listing of partial permutations with multiplicity into dict
input file should have one line for each "type" of ballot
- first entry is number of ballots of this type
- successive entries are ranked candidates (no non-votes or repeats)
- all candidates are ... | 2ca1dd45b7d92f036462753c5016983eea66dcd4 | 694,742 |
def _replace_special_characters(str_special_chars):
"""
Replaces special characters in a string with their percent-encoded counterparts
':' -> '%3A'
'/' -> '%2F'
',' -> '%2C'
(e.g. "1/1/9" -> "1%2F1%2F9")
:param str_special_chars: string in which to substitute characters
:re... | c488f10cd817673e853fce1651d6444e2fa2a97b | 694,744 |
import sys
def _next_argument():
"""Return the next argument as a string
The next argument is returned. Options (strings starting with -) are ignored. The argument is removed from the
sys.argv-list.
Returns:
String with the next argument.
"""
for idx in range(1, len(sys.argv)):
... | d6aa4a018a80976863327bb9a635857f91b24cff | 694,745 |
def collect_reports(number_of_workers, report_queue):
"""pulls reports off the report queue until it has grabbed 1 poison pill for each worker process
returns the reports"""
list_of_bad_players_inventories = []
poison_pills_found = 0
while poison_pills_found < number_of_workers:
report = rep... | d90f557568be7b3d084bd192d5b2a92288340db2 | 694,746 |
def bit_or(evaluator, ast, state):
"""Evaluates "left | right"."""
res = evaluator.eval_ast(ast["left"], state) | evaluator.eval_ast(ast["right"], state)
return res | c16ad4fd4daccf2d0f05785b7cc4032ff1b78c18 | 694,747 |
def has_tags(available, required):
"""
Helper method to determine if tag requested already exists
"""
for key, value in required.items():
if key not in available or value != available[key]:
return False
return True | c70ee7ab13b2f68625b8814ef5dd40eb21c9c3f1 | 694,748 |
def unique_type(data):
""" get the unique types of a list of data """
tps = [type(_) for _ in data]
tpunique = []
while len(tps)> 0:
tp = tps[0]
tpunique.append(tp)
tpcount = tps.count(tp)
for i in range(tpcount):
tps.remove(tp)
return tpunique | d9a97166c05ebe331b969aff58ed3d9875f4cb86 | 694,749 |
def is_snapshot_task_running(vm):
"""Return True if a PUT/POST/DELETE snapshot task is running for a VM"""
snap_tasks = vm.get_tasks(match_dict={'view': 'vm_snapshot'})
snap_tasks.update(vm.get_tasks(match_dict={'view': 'vm_snapshot_list'}))
return any(t.get('method', '').upper() in ('POST', 'PUT', 'DE... | 26088c4583d35e5d9b069b7f5046301f5e127feb | 694,750 |
def add_setup(setup=None, teardown=None):
"""decorate test functions to add additional setup/teardown contexts"""
def decorate_function(test):
def wrapper(self):
if setup:
setup(self)
test(self)
if teardown:
teardown(self)
retur... | a13ca16e3aa88ca4fd638ec666aaeaa95c090280 | 694,751 |
from typing import Dict
from typing import Any
from typing import List
def get_region_sizes(settings: Dict[str, Any]) -> List[int]:
""" Compute size of each layer in network specified by `settings`. """
dim = settings["num_tasks"] + settings["obs_dim"]
region_sizes = []
for region in range(settings["... | c8a1880ff67bdf3bc2658162cd6827927e9c4737 | 694,752 |
def get_classification_task(graphs):
"""
Given the original data, determines if the task as hand is a node or graph classification task
:return: str either 'graph' or 'node'
"""
if isinstance(graphs, list): # We're working with a model for graph classification
return "graph"
else:
... | e64620b31e68631d883e8e3d635d2147fe85cf78 | 694,753 |
import unicodedata
def code_points(text, normalize=None):
"""Return the sequence of unicode code points as integers
If normalize is not None, first apply one of the unicode normalization
schemes: NFC, NFD, NFKC, NFKD.
More details on normalization schemes in:
https://docs.python.org/3/library/u... | a01d39b2272803b75e567d190858301db9eb9251 | 694,754 |
def datetime_to_string(dt, hms=True):
"""
:param dt: Day with format datetime
:param hms: Boolean, if True "%Y-%m-%d %H:%M:%S" is returned
:return: String of the date with format: "%Y-%m-%d", if hms True string of the date with format: "%Y-%m-%d %H:%M:%S"
"""
if hms:
return str(dt.year) ... | c4abb250a5d6ef98e742fe92a29db5329256a5dc | 694,755 |
def find_unique_name(name, names, inc_format='{name}{count:03}', sanity_count=9999999):
"""
Finds a unique name in a given set of names
:param name: str, name to search for in the scene
:param names: list<str>, set of strings to check for a unique name
:param inc_format: str, used to increment the n... | 6b48426df7340f88f657097bfa8d35e32cd790f6 | 694,756 |
def get_nextupsegs(graph_r, upsegs):
"""Get adjacent upsegs for a list of segments
as a single flat list.
Parameters
----------
graph_r : dict
Dictionary of upstream routing connections.
(keys=segments, values=adjacent upstream segments)
upsegs : list
List of segments
... | cc38dd78bd0af8cce2c0a96106bea58d1e9d0b17 | 694,757 |
import json
def df_json(df_desc):
"""
Convert & manipulate describe by updating JSON
Parameters:
pandas.core.frame.DataFrame
Returns:
list of JSON including column_name
"""
op_json = json.loads(df_desc.to_json())
for col_name in op_json:
op_json[col_name]['column_name'] =... | 5b6a721770ccb0989893fd552faa64cbea2a1dee | 694,758 |
def build_texts_from_gems(keens):
"""
Collects available text from each gem inside each keen in a list and returns it
:param keens: dict of iid: keen_iid
:return: texts: dict of iid: list of strings with text collected from each gem.
"""
texts = {}
for keen in keens.values():
for gem... | b9b94f4a1035f03746bd3b18755c02b19a97b27b | 694,759 |
def filterResultsByRunsetFolder(runSets, form):
"""
Filters out results that don't have the specified runsetFolder name
"""
ret = []
for runset in runSets:
if runset.runsetFolder == form['runset'].value:
ret.append(runset)
return ret | a9416fa8f96aa2dc370c23260f65bfb53114e09a | 694,760 |
import platform
def get_iana_protocols():
"""Parse the local file of IANA IP protocols and return a dictionary of protocol number to name.
:rtype:dict[int,str]
"""
os_dist = platform.system()
if os_dist == "Linux":
protocols_file_path = "/etc/protocols"
elif os_dist == "Windows":
... | 5899d4ff43452de36a3d8764332fd34e5338e2dd | 694,761 |
import csv
def read_list( csvFile ):
"""Returns a list which has been stored as a csv file"""
with open( csvFile ) as csvFile:
reader = csv.reader( csvFile, quotechar='|' )
out = [ ]
for row in reader:
out += row
return out | 9fcb5b01496b39915e0169d0a19efc91a779aaf1 | 694,762 |
import os
def dccTest():
"""Returns true or false after checking if the `KRAKEN_DCC` environment
variable is set to use this plugin.
.. note::
The variable value to activate the Maya plugin is: `Maya`.
Returns:
bool: True if the environment variable is set to use this plugin.
""... | 78ec12c48e92e32c1c3a6ef94f4fd7b678aae478 | 694,763 |
def _sqrt_nearest(n, a):
"""Closest integer to the square root of the positive integer n. a is
an initial approximation to the square root. Any positive integer
will do for a, but the closer a is to the square root of n the
faster convergence will be.
"""
if n <= 0 or a <= 0:
raise Va... | ba0836616adafefcf4f76ce59961826820eed186 | 694,765 |
def sanitize_filename_windows(name):
"""Turn the filename into a legal windows filename.
See http://support.grouplogic.com/?p=1607
"""
name = name.decode('utf-8')
name = name.encode('ascii', 'ignore')
name = name.replace('"', "'")
name = name.replace(" ", "_") # Personal preference
nam... | 8fb0def759ba55b072ac3f70f74cbcbc1307fc7c | 694,766 |
import typing
def __evict__(
sorted_hits: typing.List[int],
cache_hits: typing.Dict[int, typing.Dict[str, int]],
size_to_recover: int,
) -> typing.Tuple[list, int]:
"""Select how many to evict.
:param sorted_hits: List of current hits sorted from lower to higher.
:param cache_hits: Cache hits... | 56ee2471df745222192a691a1eacfce05eeecb9d | 694,768 |
def match_info(match,requested_team):
"""
Functions that returns the list called match_information. In conjunction with other function, it is used to display information about the games.
Param: match is list
"""
match_information = []
if match["score"]["winner"] == "HOME_TEAM":
match_... | 62b34a3df44b067c87318f90ad5af46c72114ce4 | 694,769 |
def split_by_last_word(string_list):
"""
split list of strings list by last word
Args:
string_list: list(str), list of text in form of str
Returns:
list,list
the list of text with last word removed and the last word text list
"""
# return [ ' '.join(s.split()[... | 0b0efa5a11d5efba5a9372fadadb5816882468c8 | 694,770 |
def find_net(table_coordinates):
"""
Finding net coordinates, taking avg of x1 and x4 (mid points of table)
"""
top_x = table_coordinates[1][0]
bottom_x = table_coordinates[4][0]
avg = int((top_x+bottom_x)/2)
return avg | e8d8821977362c641be0ca7621802e774caf5adf | 694,771 |
def _get_v1_error_from_json(_json_error, _fail_on_no_results):
"""This function extracts error details (if present) from a Community API v1 response.
:param _json_error: The API response in JSON format
:type _json_error: dict
:param _fail_on_no_results: Defines if an exception should be raised if no re... | 12c785b049e199b3917b36abff388b6999879deb | 694,772 |
import math
def hill_func (x, Pmin, Pmin_inc, K, n, repress=False):
""" Hill function used for fitting
"""
if x < 0.0:
x = 0.0
if repress == True:
return Pmin + Pmin_inc*( math.pow(K,n) / (math.pow(K,n)+math.pow(x,n)) )
else:
return Pmin + Pmin_inc*( math.pow(x,n) / (math.pow(K,n)+math.pow(x,n)) ) | c8728b1abb7417e9050602e4904ae0dd199cccdd | 694,773 |
def analysis_find_numbers( database, arg_five_or_seven_numbers):
"""Find numbers
"""
found_five = {}
found_euro = {}
for key, numbers in database.items():
for vals in numbers:
if len(arg_five_or_seven_numbers) >= 5:
numbers_five = [vals[0],vals[1],vals[2],vals[3]... | e6606cdc62efa622b30906101c86cbcceb3c4118 | 694,774 |
def is_clique(G, nodes):
"""Returns True if and only if `nodes` is an independent set
in `G`.
`G` is an undirected simple graph. `nodes` is an iterable of
nodes in `G`.
"""
H = G.subgraph(nodes)
n = len(H)
return H.number_of_edges() == n * (n - 1) // 2 | 13d91a326b33f8bec0957f44350bca460ccd485c | 694,775 |
def clamp(v, lo, hi):
"""Return v clamped to range [lo, hi].
>>> clamp(1, 2, 3)
2
>>> clamp(4, 0, 1)
1
>>> clamp(6, 5, 8)
6
"""
assert lo <= hi
if v < lo:
return lo
elif v > hi:
return hi
else:
return v | 5b2213be8f7ce24bfb3addb6c3ff436a62ff1dbd | 694,776 |
def collatz_sequence(seed):
"""Given seed generates Collatz sequence"""
sequence = [seed]
counter = seed
# pylint: disable=misplaced-comparison-constant
while 1 != counter:
# pylint: disable=misplaced-comparison-constant
counter = (int(counter/2) if 0 == counter%2 else 3*counter+1)
... | 37195042d6feae7d9ea26ebfea8c35a9436c8c11 | 694,777 |
import sys
def extract_module_locals(depth=0):
"""Returns (module, locals) of the funciton `depth` frames away from the caller"""
f = sys._getframe(depth + 1)
global_ns = f.f_globals
module = sys.modules[global_ns['__name__']]
return (module, f.f_locals) | 21892cf93211211a16d0c913879d0a59205d91c9 | 694,778 |
import csv
def loadFlags(file):
"""Takes in a filename/path and reads the data stored in the file. If it is
a single column of data returns a 1D list, if it is multiple columns of
data returns a 2D list. Note the first line is skipped as it assumes these
are column labels.
"""
with op... | cfd48269ed94b47dfd2c12e6a7f66f8106253f15 | 694,779 |
def _read_windex(fn):
""" Return word index as dict of words to int pointers """
with open(fn) as f:
return dict((w.strip(), int(n)) for w,n in zip(f, f)) | 366330ce84dfe7834104a6b641cfae3b1dcfa8d3 | 694,781 |
from typing import List
from typing import Dict
import asyncio
def loop_info() -> List[Dict]:
"""Show information about running loop."""
loop = asyncio.get_event_loop()
return [
{
"running": loop.is_running(),
"policy": str(asyncio.get_event_loop_policy().__class__).split("... | ac42e33b1448964d95080902301558572090fd4d | 694,782 |
def fopen(ref):
"""
Open a file and return a list of lines.
"""
return [i.split() for i in open(ref).readlines()] | 689d74d626de2a84a1a28f219c634f3eb043ec76 | 694,783 |
import colorsys
def hsl_to_rgb(hue, saturation, lightness):
"""Takes a colour in HSL format and produces an RGB string in the form
#RRGGBB.
:param hue: The Hue value (between 0 and 360).
:param saturation: The Saturation value (between 0 and 100).
:param lightness: The Lightness value (between 0 ... | a7d0ab91bc01c04f2ecf5afa8255f639e5758a6c | 694,785 |
def is_overlapping(segment_time, previous_segments):
"""
Checks if the time of a segment overlaps with the times of existing segments.
Arguments:
segment_time -- a tuple of (segment_start, segment_end) for the new segment
previous_segments -- a list of tuples of (segment_start, segment_end) for the... | 27b817a76829eb7eba63d3fd22376e4164a7bf39 | 694,786 |
import types
def ascii_only(input_text):
"""
Map Word Text to best ASCII equivalents
See the 'findunicode.py' program for how to search for these
:param input_text: (str) input text
:return: (str) Ascii only text
"""
replacements = {
160 : u'-',
174 : u'r', # Regi... | b7f16ac74f3637acb992a9efb918e7d1da2b326b | 694,787 |
def make_regex(pattern, escape=False):
"""Build regular expression corresponding to `pattern`."""
def re_group(r):
return r'(' + r + r')'
def re_or(r1, r2):
return re_group(re_group(r1) + '|' + re_group(r2))
def re_opt(r):
return re_group(r) + '?'
asterisk = '*'
res =... | 46f38f71f19f3f7e0cf718a47683615cee0b048e | 694,789 |
def gir_merge_dicts(user, default):
"""Girschik's dict merge from F-RCNN python implementation"""
if isinstance(user, dict) and isinstance(default, dict):
for k, v in default.items():
if k not in user:
user[k] = v
else:
user[k] = gir_merge_dicts(us... | 49196cc305c8acb454d9d3d8d9b6ddbabd67dff8 | 694,790 |
import json
def ler_arquivo(local: str) -> list:
"""
Essa função serve para ler um arquivo JSON e devolver um dicionário
:param local: str, local onde se encontra o arquivo JSON
:return: list, lista de dicionário com os dados do arquivo JSON
"""
with open(local, encoding='UTF-8') as arquivo:
... | 02f4f9460ad359939c120f605657bca6cf905a60 | 694,791 |
import re
def get_derived_table(view_list):
"""
This function extracts the derived table clause from a view file, if it exists.
:param view_list: view file broken down list
:type view_list: list
:return: a list of the derived table clause for a view file
"""
derived_list = []
for li... | 1fe5546f387037ec393f8f4cfc4e86c09e9d74c3 | 694,792 |
def calculate_delta(a, b):
"""Delta distance between two coords.
:type a: tuple
:param a: starting coord
:type b: tuple
:param b: goal coord
:rtype: interger
"""
dx = abs(a[2] - b[2])
dy = abs(a[1] - b[1])
dz = abs(a[0] - b[0])
return dx + dy + dz | 1a91e5b85962dedbed43017a6188d5a59d8f8415 | 694,793 |
import sys
def SecFinder(SecID):
"""
"""
_SecID = str(SecID).lower()
_SecID = _SecID.replace('section','')
_SecID = _SecID.replace('shape','')
_SecID = _SecID.replace('type','')
_SecID = _SecID.replace('member','')
_SecID = _SecID.replace('chord','')
_SecID = _SecID.replace('rack',... | 8a69baf3fb4664747359172fb9d1f2bbd1edcef9 | 694,794 |
import typing
import ipaddress
def format_address(address: typing.Optional[tuple]) -> str:
"""
This function accepts IPv4/IPv6 tuples and
returns the formatted address string with port number
"""
if address is None:
return "<no address>"
try:
host = ipaddress.ip_address(address... | 28c735fd60f69f8bb0f038b136fc9b8d1b938a91 | 694,795 |
def get_x_ranges(table):
"""
table = [
['2', 'A'],
['K', 'J', '10' ...],
...,
]
"""
ranges = []
for column in table:
lefts = [card.box.left for card in column]
rights = [card.box.left + card.box.width for card in column]
left = min(lefts)
... | e62b0bd72ff416527eda5339234b3fe6c8bf9d75 | 694,796 |
import json
def refundCardTransactionPayload(amount, reason, merchant_refund_reference, refund_time):
"""
Function for constructing payload for refundCardTransaction API call.
Note: All parameters are of type String unless otherwise stated below.
:param amount: Integer - Amount to be refunded
:pa... | 6c54a5177acf1d79bc1d06e709ca9a81ffb6c9b7 | 694,797 |
def round_to(x, base=1, prec=2):
"""
Round to nearest base with precision.
:param x: (scalar) - value to be rounded from
:param base: (scalar) - value to be rounded to
:param prec: (int) - number of decimal points
:return rounded_val: (scalar) - rounded value
"""
try:
return rou... | d8c041a99d948458ced6942f037592da225fa9e4 | 694,798 |
def select_sort(inputlist):
"""
简单选择排序
:param inputlist: a list of number
:return: the ascending list
"""
length = len(inputlist)
for i in range(length):
minimum = i
for j in range(i, length):
if inputlist[j] < inputlist[minimum]:
minimum = j
... | c6163f0d7c0b5048c067d6f8d0adfd08bfb02728 | 694,799 |
def definir_orden_builtin(a: str, b: str, c: str) -> str:
"""Devuelve tres palabras en orden alfabético de izquierda a derecha.
:param a: Primera palabra.
:a type: str
:param b: Segunda palabra.
:b type: str
:param c: Tercera palabra.
:c type: str
:return: Las tres palabras en orden alf... | 7cb1a5916a2917b942121de52020c7323c695ba8 | 694,800 |
def check_position(ball_, points_):
"""
The function return coordinates ball.
"""
points_cords = points_
ball_cords = ball_
for obj in points_cords:
if(obj.cords == ball_cords):
current_point_cord=obj.point_pos
return current_point_cord | bb2a003caffc4c7caf20d61b4e9e0ba7eef06b2f | 694,801 |
def positive_sent(args, premise, verbose=True):
"""Check whether root verb is negated"""
# If 'not' is in the lemma list
if 'not' in premise.lemmas:
# Get all "not"
NOT_tokens = [t for t in premise.tokens if t.lemma == 'not']
for not_t in NOT_tokens:
... | 0a822c223a395f70a3961711dead446d629a385f | 694,802 |
import six
def cached(method):
"""
Decorate `method`, to cache its result.
Args:
method: The method whose result should be cached.
Returns:
The decorated method.
"""
results = {}
@six.wraps(method)
def wrapper(*args, **kwargs):
cache_key = (args, tuple((k, kw... | d5dd2ac223d835287e22e1067300118905d56041 | 694,803 |
def get_node_val(node, val_type):
"""Return the value as a string of a child node of the specified type,
or raise ValueError if none exists"""
for child in node.children:
if child.expr_name == val_type:
return child.text.strip('"')
raise ValueError("No value of specified type.") | d501dd7ba20620e844a5d4d2d33112e64a9dfef0 | 694,804 |
from typing import List
def find_mine(field: List) -> List[int]:
"""Finds mine location.
Examples:
>>> assert find_mine([[0, 0, 0], [0, 1, 0], [0, 0, 0]]) == [1, 1]
"""
return [
[top_index, inner_index]
for top_index, top_value in enumerate(field)
for inner_index, inne... | 8fdf9b299b7869dbbfabf4fe654a6dd5fa9b5f9a | 694,805 |
def _make_pretty_arguments(arguments):
"""
Makes the arguments description pretty and returns a formatted string if `arguments`
starts with the argument prefix. Otherwise, returns None.
Expected input:
Arguments:
* arg0 - ...
...
* arg0 - ...
...... | b6e7571c3d0e432649edf8295d3aa640140c551f | 694,806 |
import torch
def nested_stack(params, roll: bool = False):
"""Form a tensor from a nexted list of tensors.
This function is a generalization of torch.stack. For proper usage,
it's important that params is a nested list with shape consistent with
and array. The innermost elements of that nested list s... | 9b8b56eb15f55cbc5bf0b726e7aaf7fd3d476ada | 694,807 |
def count_features_type(features):
""" Counts three different types of features (float, integer, binary).
:param features: pandas.DataFrame
A dataset in a panda's data frame
:returns a tuple (binary, integer, float)
"""
counter={k.name: v for k, v in features.columns.to_series().groupby(... | 7c759ac9289e7f2cdb542d67ad30bf36e06749c8 | 694,808 |
def pkgconfig_script(ext_build_dirs):
"""Create a script fragment to configure pkg-config"""
script = []
if ext_build_dirs:
for ext_dir in ext_build_dirs:
script.append("##increment_pkg_config_path## $$EXT_BUILD_DEPS$$/" + ext_dir.basename)
script.append("echo \"PKG_CONFIG_PATH=$... | 7b056b2509b09ea2cd163dd0fc2420ad59030060 | 694,809 |
import re
def default_cleaner_fn(fld):
""" Return a copy of the given field cleaned up by removing any unwanted characters. """
if (isinstance(fld, str)):
return re.sub("[\"\'\\\\]", "", fld) # remove quotes and backslashes
else:
return fld | 7f9bacfe981f1b3591cde5cc7ae04b654689b0c4 | 694,810 |
def get_numversion_from_version(v: str) -> tuple[int, int, int]:
"""Kept for compatibility reason.
See https://github.com/PyCQA/pylint/issues/4399
https://github.com/PyCQA/pylint/issues/4420,
"""
version = v.replace("pylint-", "")
result_version = []
for number in version.split(".")[0:3]:
... | 9fb58832b43efb4a8fd7b493e06f2f277c9b466f | 694,811 |
def get_pagination_parameters(request, paginator, paginated):
"""
Prepare and return the template parameters needed for pagination.
Thanks to https://gist.github.com/sbaechler/5636351
Args:
``request`` (django.http.HttpRequest): The request object.
``paginator`` (django.core.paginator... | 0dd54bffdf31a3cf78bfdc510ac20a901e3adc5e | 694,812 |
from typing import Tuple
def extend_shape(original_shape: Tuple, new_size: int, axis: int = 0) -> Tuple:
"""Extend a dimension of a shape tuple"""
shape = list(original_shape)
shape[axis] = new_size
return tuple(shape) | c48e2559900e88ec6c808735ac017c65bc82741a | 694,813 |
import string
def validate_ISBN10(isbn):
"""
Validate ISBN10 code. Returns the ISBN or False if is not valid.
"""
isbn = isbn.replace("-", "").replace(" ", "")
if len(isbn) == 10 and not [x for x in isbn if x not in (
string.digits + "X")]:
total = 0
for i in range(9)... | 0bc0a4fe0bde01a240895129ee99410fb9d383e0 | 694,815 |
import os
def fix_jinja(txt):
"""appends empty line to file, if missing"""
return (
os.linesep.join([s for s in txt.splitlines() if not s.strip() == ""])
+ os.linesep
) | 338c634fee7c1a48cd574d953f1cbbcd2d25a2d1 | 694,816 |
def _resource_for_help(pkg_info, help_file):
"""
Get the resource name that references the help file in the given help
package. The help file should be relative to the document root of the
package.
"""
return "Packages/%s/%s" % (pkg_info.doc_root, help_file) | 39214fe39db71935a85763e1731c0da97fe9e74b | 694,817 |
def tokenize_message(message):
"""return a list of normalized words."""
return (message
.lower()
.replace(".", " .")
.replace(",", " ,")
.replace("?", " ?")
.replace("!", " !")
.replace(":", " :")
.replace("'s", " 's")
... | 4e5bc88985912f48ea276e9ad77880c32a85542f | 694,818 |
def str2bool(v):
"""
Convert a string to a boolean
:return boolean: Returns True if string is a true-type string.
"""
return v.lower() in ('true', 't', '1', 'yes', 'y') | 32dc16194fa6096e53e1a0b21f0287c31a7cd824 | 694,819 |
def get_subplotspec_list(axes_list, grid_spec=None):
"""Return a list of subplotspec from the given list of axes.
For an instance of axes that does not support subplotspec, None is inserted
in the list.
If grid_spec is given, None is inserted for those not from the given
grid_spec.
"""
sub... | b51d540a7c3c8fa2b1f5a9d628abe69302678de8 | 694,820 |
def adjustbufsize(
bufsize: int, bits: int) -> int:
"""Adjust buffer size to
account for bit depth
Args:
bufsize: initial estimate
of buffer size
bits : bit depth of bitmap
(1, 4, 8, 24) bits
Returns:
An adjusted int value of the
... | 9130c0fa174d9daf6dffabba67c77e9d85b29c13 | 694,821 |
def and_(a, b):
"""Same as a & b
"""
return a & b | a07f69143fd9eaa3b27bb07ee72c04efa31c5b7f | 694,823 |
import re
def generate_top_kmer_md_table(t_kmer_dic, g_kmer_dic,
top=5,
val_type="c"):
"""
Given k-mer count dictionaries for genomic and transcript context set,
generate a markdown table with top 5 k-mers (sorted by decending
dictionary va... | f0be470a6b2e10a5f786cd7d01c6b09b7f1e395e | 694,824 |
import argparse
def parse_args():
"""Parse input arguments."""
parser = argparse.ArgumentParser(
description='3DT BDD format dataset generation',
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('set', choices=['gta', 'kitti'],
... | 80b92fe9f64fb40d9accd041d050e143e4174560 | 694,825 |
def schedule(year=None, month=None, day=None, week=None, day_of_week=None, hour=None, minute=None,
second=None, start_date=None, end_date=None, timezone=None):
"""Schedule a function to be executed according to a crontab-like schedule
The decorated function will be executed according to the schedu... | 051ed1fbdf113834bcff626b3679f1dc6ea5580c | 694,826 |
def to_template_dict(obj):
"""Extract the CFN template dict of an object for test comparisons"""
if hasattr(obj, 'to_dict') and callable(obj.to_dict):
return obj.to_dict()
elif isinstance(obj, dict):
return dict((key, to_template_dict(value))
for (key, value) in obj.item... | 4f5440fb4e5d73d5a6acb2f758bf6e6bb8182d52 | 694,827 |
def reset_grads(model, require_grad):
"""reset_grads"""
for p in model.parameters_dict().values():
p.requires_grad = require_grad
return model | 47a3e799e8ab95d9500add8911dc7ceda42c93a9 | 694,828 |
import os
def comment(string):
"""return string as a comment"""
lines = [line.strip() for line in string.splitlines()]
return '# ' + ('%s# ' % os.linesep).join(lines) | 2d7040129ff1f1b985a2761c6ecce28ce1560aa9 | 694,829 |
def get_default_ext(delim):
"""Retrieves the default extension for a delimiter"""
if delim == ',':
return "csv"
if delim == '\t':
return "tsv"
return "txt" | 37e27bebcb6c1fbfe3d794d3d2ac34d9909ed40c | 694,830 |
def to_camel(s):
"""Convert an underscored title into camel case. 'PARENT_ORGANISATION_ID' => 'parentOrganisationId'"""
bits = [(x.lower() if i == 0 else x.title())
for (i, x) in enumerate(s.split("_"))]
return "".join(bits) | 34400be6a346d886b2fca562b737b7811b871af1 | 694,831 |
def get_first_image_in_list(body_response, name_filter=None):
"""
Gets the first image in the list
:param body_response: Parsed response (Python dic)
:param name_filter: If this arg is set, this method will filtered by name content
:return: First image in list (that contains name_filter in its name)... | a20db4ac9cd165d6853f8a96d1739d7d25a718f8 | 694,832 |
def vcr_config():
"""Common configuration for all vcr tests."""
return {"filter_headers": ["authorization"], "ignore_localhost": True, "record_mode": "new_episodes"} | 2576975562b0cab12aac6abba69519f3fae7360b | 694,833 |
import numpy
def plane_pt_to_3d_point(pos, trans_matrix):
"""
Transform plane point position eg. P(x, y, 0, 1) to 3d point eg. P'(X, Y, Z, 1)
@param pos: <array_like> position
@param trans_matrix: <numpy.array> transformation matrix
@return: <Tuple> 3d position
"""
orig_matrix = numpy.arra... | 1cc4bee4c0de4dbc811572113b17e2b95bfbce7e | 694,834 |
import csv
import json
from typing import Counter
def convert_newsqa(file_path):
"""
Converts NewsQA dataset to jtr format.
Args:
file_path: path to the NewsQA CSV file (data/NewsQA/)
Returns: dictionary in jtr format
"""
# meta info
if '/' in file_path:
filename = file_p... | 0e48883e179f2d440ac8c72c8a5ff9344f595f1f | 694,835 |
def _zones_to_regions(zones):
"""
Return list of regions from the input list of zones
:param zones: List of zones. This is the output from `get_zones_in_project()`.
:return: List of regions available to the project
"""
regions = set()
for z in zones:
# Chop off the last 2 chars to tu... | 83c59cc6c2a9fc6e36a64044dc8ccc73ec039801 | 694,836 |
def cond(conditions, value):
"""Returns a function, fn, which encapsulates if/else, if/else, ... logic.
R.cond takes a list of [predicate, transformer] pairs. All of the arguments
to fn are applied to each of the predicates in turn until one returns a
"truthy" value, at which point fn returns the result... | 942f7c474294863515ad7607d5474bbc91ba8936 | 694,837 |
import numpy
def insert_function_sinc(x):
""" Insertion with Sinc function
:param x: 1D vector
:return: 1d vector
"""
s = numpy.zeros_like(x)
s[x != 0.0] = numpy.sin(numpy.pi * x[x != 0.0]) / (numpy.pi * x[x != 0.0])
return s | 1ddf6d9fcc07dcfcec26c272b6d44df662ed34a6 | 694,838 |
import re
def is_valid_fqdn(host):
"""Reasonable attempt at validating a hostname
Compiled from various paragraphs outlined here
https://tools.ietf.org/html/rfc3696#section-2
https://tools.ietf.org/html/rfc1123
Notably,
* Host software MUST handle host names of up to 63 characters and
... | 42b7e4b7f249590ac74482c680d61ae82d3903fd | 694,839 |
def to_year_count(d):
"""
date > n years
"""
return d.year | 2665ad98d7252a4e097bdf959d39f8f92bac5fa3 | 694,840 |
def task_check():
"""Pre-deployment check"""
return {'actions': [], 'task_dep': ['test', 'lint']} | 51bb907b2d25d312e76164dce4c3c4aacecc66b2 | 694,841 |
def get_band_height(element):
"""
Return height the the specified element.
:param element: current jrxml element being processes.
:return:
"""
return float(element['child'][0]['band']['attr']['height']) | 5968319f36f4a541c922c7422c734077173ca113 | 694,842 |
import re
def reformat_ISBNs(text: str, match_func) -> str:
"""Reformat ISBNs.
:param text: text containing ISBNs
:param match_func: function to reformat matched ISBNs
:type match_func: callable
:return: reformatted text
"""
isbnR = re.compile(r'(?<=ISBN )(?P<code>[\d\-]+[\dXx])')
tex... | a440d65e4bd747c28fb186e8b76389e8bb59526c | 694,843 |
import os
def has_horovodrun():
"""Returns True if running with `horovodrun` using Gloo or OpenMPI."""
return "OMPI_COMM_WORLD_RANK" in os.environ or "HOROVOD_RANK" in os.environ | dd810f5a8aaf497147281290afa458f4eb8b37fe | 694,844 |
import requests
def check_connection(uname, pword):
"""Check if a connection with CNES Pepscan be established
:param uname:
:param pword:
:return:
"""
response = requests.get(
'https://peps.cnes.fr/rocket/#/search?view=list&maxRecords=50',
auth=(uname, pword), stream=True
... | 2025103c0dfd5355d2d4a1ab3e340ae8e1ac6a47 | 694,846 |
import sys
def read_file(name, normalize=True):
""" Read a file. """
try:
with open(name, 'r', encoding='utf-8') as f:
# read the data
data = f.read()
if normalize:
# normalize line endings
data = data.replace("\r\n", "\n")
return data
except IOError as e:
(errno,... | 5ef4072381d150997f0807c5bef69abba67f5726 | 694,847 |
def get_memory_usage(pandas_df):
"""
Returns the number of bytes used by a pandas dataframe
"""
return pandas_df.memory_usage(deep=True).sum() | 7ed31e0f20269224ea0517a71045992106df9030 | 694,848 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.