content stringlengths 35 416k | sha1 stringlengths 40 40 | id int64 0 710k |
|---|---|---|
def unflatten_verifications(old_verifications):
""" Convert verifications from v2 to v1 """
new_verifications = {}
for verification in old_verifications:
key = verification['key']
del verification['key']
new_verifications[key] = verification
return new_verifications | a3ce1af2991304576b5e3dd3459b86b9e6b6557c | 29,425 |
import os
def load_smoothing_parameter_file(file_name):
"""Reads and parses the smoothing parameter file"""
par = {}
with open(file_name, 'rU') as handle:
for line in handle:
if line:
fields = line.rstrip(os.linesep).split()
try:
v = ... | 29ec17fcaaceeeba2a3dd9b0b7f346f32925e8b7 | 29,427 |
def clean_advance_reservation(text):
""" The advance reservation field identifies whether or not advance
reservations are required to use these facilities (day use areas). If there
is not recorded answer (blank) we default to 'no reservation required'.
Returns 'True' if reservation required, False other... | 8f707074f62ff605935737e3a6fa4cf2dc492de2 | 29,428 |
import copy
def transform(N, max_r=None):
"""
(Nondestructively) transform the list of values by averaging them with
neighboring zeros.
The maximum r value is assumed to be len[N] unless specified otherwise with
max_r. This enables use of defaultdict instead of list to specify N vals.
Identi... | c73d791c41428e22d486e2fe1dca9d9b29b3d3c6 | 29,429 |
def checksubstate(repo, baserev=None):
"""return list of subrepos at a different revision than substate.
Abort if any subrepos have uncommitted changes."""
inclsubs = []
wctx = repo[None]
if baserev:
bctx = repo[baserev]
else:
bctx = wctx.p1()
for s in sorted(wctx.substate):
... | 26efd3a222905352bba78ecd906d4eaeb509f586 | 29,430 |
def _set_kwargs_quiet(kwargs, quiet=True):
"""
Enable quiet switch in keyword cmd_args
:param kwargs:
:param quiet:
:return:
"""
kwargs['quiet'] = quiet
return kwargs | e7865d35a1d8a81ae6e0c3a1753b65c85a30d55e | 29,431 |
def _get_question_features(conv_id, QUESTIONS):
"""
Given conversation id and a dictionary QUESTIONS
Returns an one-hot vector of length 8, the Xth entry being 1 iff the conversation contains question type X.
"""
ret = {}
for ind in range(8):
ret['question_type%d'%(ind)] = 0
if c... | 7e81b6aed3f7fdd4aae1cd9e8cafdb43ebea2586 | 29,433 |
def get_mirror_type(should_mirror_in, should_mirror_out):
"""
This function return the type of mirror to perform on a Jira incident.
NOTE: in order to not mirror an incident, the type should be None.
:param should_mirror_in: demisto.params().get("incoming_mirror")
:param should_mirror_out: demisto.p... | 2fe47a6ad13305c0c07e91bfc86cbb4dd64ab450 | 29,434 |
import re
def escape_json_string(string: str) -> str:
""" Makes any single escaped double quotes doubly escaped. """
def escape_underescaped_slash(matchobj):
""" Return adjacent character + extra escaped double quote. """
return matchobj.group(1) + "\\\""
# This regex means: match .\" ex... | a241845cdf46a96d79d38a410c497cadfd615205 | 29,435 |
def secant( fp , a , b , epsilon=1e-5 ):
"""
secant( fp , a , b , epsilon ).
This is a root-finding method that finds the minimum of a function (f) using secant method.
Parameters:
fp (function): the first derivative of the function to minimize
a (float): inferior born of the initial uncertain... | 44276e18dc3db30521a5173eb7824da38d3e65e0 | 29,437 |
def validate_csv(row0, required_fields):
"""
:param row0:
:param required_fields:
:return: a tuple, True if all requirements are met and a dictionary with the index for all the fields
"""
for field in required_fields:
if field not in row0:
return False, {}
field_pos = {}
... | 6a126f22a86fbcfa4192ec4f9104faab7efd6b3f | 29,439 |
from typing import Sequence
from typing import Callable
from typing import Any
def batch_by_property(
items: Sequence, property_func: Callable
) -> list[tuple[list, Any]]:
"""Takes in a Sequence, and returns a list of tuples, (batch, prop)
such that all items in a batch have the same output when
put i... | 733dae3d31219dafbe115f12263a3da735409c30 | 29,440 |
def recipeParameter(func):
""" Internal decorator for all recipe parameters. """
def wrapper(self):
if not self._gotMeta:
self.getMeta()
try:
return func(self)
except KeyError:
return None
return wrapper | 8f7f4db14df06107774c2ec5be397603d0f04bc8 | 29,441 |
import os
import ast
def generate_ast(path):
"""Generate an Abstract Syntax Tree using the ast module."""
if os.path.isfile(path):
with open(path, 'r') as f:
return ast.parse(f.read())
raise IOError('Input needs to be a file. Path: ' + path) | 1573464fe61e345219e3affc45adf2202c0cccb7 | 29,442 |
def fix_short_sentences(summary_content):
"""
Merge short sentences with previous sentences
:param summary_content: summary text
"""
LEN_95_PERCENTILE = 20
# merge short sentences
ix = 0
fixed_content = []
while ix < len(summary_content):
sentence = summary_content[ix]
... | 6d093eb1d3fd865098f486bc135990a921879909 | 29,444 |
def float01(flt):
"""Float value between 0 and 1"""
flt = float(flt)
if flt < 0 or flt > 1:
raise ValueError("Input must be between 0 and 1!")
return flt | 952f7753ad2c2b227cb1fc4e677f8c4a9dc3ae6a | 29,445 |
import warnings
def reassign_topology(structures, new):
"""Take Packmol created Universe and add old topology features back in
Attempts to reassign:
- types
- names
- charges
- masses
- bonds
- angles
- torsions
- impropers
- resnames
Parameters
----------
... | 57c158df54604788cfbd638569bd338f4ee97cae | 29,446 |
import json
def parse_behavior(risky_flows):
"""
build incidents from risky flows
"""
incidents = []
for flow in risky_flows['data']:
incident = {
'name': "{rule} {int_}:{int_port} : {ext}:{ext_port}".format(
rule=flow['riskRule']['name'],
int_=f... | 68ac8b0c8312a24deecabed793f87652500a907c | 29,448 |
import os
import random
def generate_splits(path_input, val_ratio, test_products):
""" Generate train and validation split accoring to ratio and tes split read from test products file"""
all_indices = [f for f in os.listdir(path_input) if
os.path.isfile(os.path.join(path_input, f)) and os.p... | 6abff73d51d093de997e6c2d55e8f39f6ebb1d5e | 29,449 |
def transpose_func(classes, table):
"""
Transpose table.
:param classes: confusion matrix classes
:type classes: list
:param table: input confusion matrix
:type table: dict
:return: transposed table as dict
"""
transposed_table = {k: table[k].copy() for k in classes}
for i, item... | 6c59feef2b735076c5768e086ef2e91331b78a73 | 29,450 |
from functools import reduce
def traverse_dict_children(data, *keys, fallback=None):
"""attempts to retrieve the config value under the given nested keys"""
value = reduce(lambda d, l: d.get(l, None) or {}, keys, data)
return value or fallback | 2c6f28259136bd8248306b7e759540fc3877d46f | 29,451 |
def dov(init):
"""Usage:
dictionaryOfVariables = {....}
@dov
def __init__(self,...):
Decorates __init__ so that it takes a STATIC dictionary of variables and computes
dynamic mandatoryVariables and optionalVariables dictionies. Obviously easy to
rewrite to take a dynamic dict... | a3e8d3e82d951200e60adf15efb6d5a9b76e34f6 | 29,452 |
def get_idxs_in_correct_order(idx1, idx2):
"""First idx must be smaller than second when using upper-triangular arrays (matches, keypoints)"""
if idx1 < idx2: return idx1, idx2
else: return idx2, idx1 | 05963c4f4b692b362980fde3cf6bb1de1b8a21e0 | 29,453 |
import os
def filename_handler_ignore_directive(fname):
"""A filename handler that removes anything before (and including) '://'.
Args:
fname (str): A file name.
Returns:
str: The file name without the prefix.
"""
return fname.split(f":{os.path.sep}{os.path.sep}")[-1] | 555cfeae0017600bc0096693b845f7b502d994a7 | 29,454 |
from typing import Dict
from typing import Any
def source_startswith(cell: Dict[str, Any], key: str) -> bool:
"""Return True if cell source start with the key."""
source = cell.get("source", [])
return len(source) > 0 and source[0].startswith(key) | a3dab1e72488a5075832432f36c6fc10d9808a7f | 29,455 |
def categories_to_columns(categories, prefix_sep = ' is '):
"""contructs and returns the categories_col dict from the categories_dict"""
categories_col = {}
for k, v in categories.items():
val = [k + prefix_sep + vi for vi in v]
categories_col[k] = val
return categories_col | f513fda8f369e7ac48de9306bda9e98889ed06d0 | 29,457 |
import os
import sys
def default_python_path(work_dir="."):
"""set and return the Python path by appending this work_dir to it."""
work_dir = os.path.abspath(work_dir)
python_path = os.pathsep.join(sys.path)
python_path += os.pathsep + work_dir
return python_path | 6809cbcc6157377802178239892438e3f9de2deb | 29,458 |
from bs4 import BeautifulSoup
import re
import json
def parse_rune_links(html: str) -> dict:
"""A function which parses the main Runeforge website into dict format.
Parameters
----------
html : str
The string representation of the html obtained via a GET request.
Returns
-------
... | cea14b4d572cad7ca42b3b4ff7bd1b6c52a1e608 | 29,460 |
def format_path(path):
""" Attempt to pretty print paths """
build = ""
for rule in path:
if not build:
build += str(rule) + '\n'
else:
string = str(rule)
lines = string.split('\n')
halfway = len(lines) / 2
build += "\n".join([('\t-... | 360598645f42f0a2bf745eda573ca66fab085427 | 29,463 |
import os
import imp
def load_module(filename):
"""Load a Python module from a filename or qualified module name.
If filename ends with ``.py``, the module is loaded from the given file.
Otherwise it is taken to be a module name reachable from the path.
Example:
.. code-block: python
pb... | c274ba83c5c0745fc66d5458a40ee5285699948d | 29,464 |
def _sabr_implied_vol_hagan_A4(
underlying, strike, maturity, alpha, beta, rho, nu):
"""_sabr_implied_vol_hagan_A4
One of factor in hagan formua.
See :py:func:`sabr_implied_vol_hagan`.
A_{4}(K, S; T)
& := &
1
+
\left(
\\frac{(1 - \\bet... | 704f4db60570cc18ad16b17d9b6ba93747d373d4 | 29,466 |
import numpy as np
def tif_stitch(tiles, saved_locs, im_shape):
"""Creates a background mask the size of the original image shape and uses it to stitch the tiles back together.
"""
stitched_im = np.zeros(im_shape)
for key in saved_locs.keys():
location = saved_locs[key]
im = tiles... | d7340fc614e6bbfc3b932367892009d4e711202b | 29,467 |
def get_number_from_numerical_spec(spec):
""" Return the number from a numerical spec. """
assert isinstance(spec, int) or isinstance(spec, str), f"'input' has invalid type {type(spec)}."
if isinstance(spec, str):
try:
return int(spec)
except ValueError:
raise ValueEr... | 68b133de6e6090774262aec6fcbaccc8f90132eb | 29,468 |
def make_body_section_text(avl_body_section):
"""This function writes the body text using the template required for the AVL executable to read
Assumptions:
None
Source:
None
Inputs:
avl_section.origin [meters]
avl_section.chord [meters]
... | 4896c556c0f543cafc2141599e8c5ab6b6493d28 | 29,473 |
import glob
def get_sorted_files(files):
"""Given a Unix-style pathname pattern, returns a sorted list of files matching that pattern"""
files = glob.glob(files)
files.sort()
return files | 9bed6be4c57846c39290d4b72dba1577f9d76396 | 29,474 |
import os
def import_plants_csv(result_dir, structures=None, files=('features.csv', 'ranking.csv')):
"""
Import PLANTS results csv files
:param result_dir: PLANTS results directory
:type result_dir: :py:str
:param structures: only import files in structure selection, import all
... | b83d61946c3ffdfbee85167a0c4b17850505ed87 | 29,475 |
def removeDuplicates(nums):
"""
:type nums: List[int]
:rtype: int
"""
i = 0 # current check point
for val in nums:
if val != nums[i]:
i += 1
nums[i] = val
return i + 1 | 49a717e0133d58b097811f930d9b47d1188f6825 | 29,476 |
import sys
def current_version():
"""Current system python version"""
return sys.version_info | e1efe2447b9544c0b9723e9d050869464f032096 | 29,477 |
from typing import Dict
from typing import Any
def modify_namelist_template(
namelist_template: str,
placeholder_dict: Dict[str, Any]
):
"""
Placeholders in the form of %PLACEHOLDER_NAME% are replaced within the
given namelist template.
Parameters
----------
namelist_template ... | 2a872b20caf871ff6406e04a91d69ee2f33ba66c | 29,479 |
from typing import Optional
import subprocess
def process(stdin: str, capture_output=True) -> Optional[str]:
"""
wrapper for subprocess.
:param capture_output:
:param stdin: stdin
:return: stdout
"""
p = subprocess.run(stdin.split(), capture_output=capture_output)
if capture_output:
... | e3e0ad01fda3b836e73f77c86834a3b45d9b4c3e | 29,480 |
import pickle
def load_results(path, filename):
"""
load result from pickle files.
args:
path: path to directory in which file is located
filename: name of the file (without pickle extention)
"""
with open(path+filename+'.pickle', 'rb') as handle:
return pickle.load(han... | 6f76914cdbb25c4c5f81bc2bd61b61da5b34777a | 29,481 |
def _interaction_df_to_edge_weight_list(interaction_table, threshold=0.0):
"""Convert from df to edge_list."""
edge_weight_list = [
tuple(sorted([row['e1'], row['e2']]) + [row['intensity']])
for idx, row in interaction_table.iterrows()
if row['intensity'] > threshold
]
return edg... | 24f2798edd940165c6c4e4abd81327ade3f7a8fc | 29,483 |
import itertools
def generateSubSequences(k, ch):
"""
generates all subsequences of ch with length k
"""
seq = ["".join(c) for c in itertools.product(ch, repeat = k)]
# discussion about the best way to do this:
# https://stackoverflow.com/questions/7074051/what-is-the-best-way-to-generate-all-possible-th... | e2f43a197cd0f4beb46c704afe3713765f99e8f3 | 29,484 |
from pathlib import Path
def create_target_absolute_file_path(file_path, source_absolute_root, target_path_root, target_suffix):
"""
Create an absolute path to a file.
Create an absolute path to a file replacing the source_absolute_root part of the path with the target_path_root path
if file_path is ... | 0d24f8544752967815bd8ddceea15b371076c500 | 29,485 |
def query_prefix_transform(query_term):
"""str -> (str, bool)
return (query-term, is-prefix) tuple
"""
is_prefix = query_term.endswith('*')
query_term = query_term[:-1] if is_prefix else query_term
return (query_term, is_prefix) | d33dd4222f53cba471be349b61e969838f6188d5 | 29,486 |
import re
import copy
import json
def test_for_data(_):
"""测试用例"""
data = list()
# 公司名称中包含年份
res_date = re.search(r"\d{2,4}-\d{1,2}-\d{1,2}", _["org_name"])
if res_date:
# 置否原始数据,然后新增一条
new_data = copy.deepcopy(_)
_["valid"] = 0
data.append(_)
_ = new_data
... | 2710a4842ce671bc17347fc0586ef1c8c0628fec | 29,487 |
def consolidate_conversion(x):
"""
Collapses the conversion status to Yes or No.
"""
xl = x.str.lower()
if any(xl.str.startswith('purchase')) or any(xl.str.startswith('converted')) or \
any(xl.str.startswith('y')) or any(xl.str.startswith('processed')) or \
any(xl.str.startsw... | fa9e8c93705d9d1941c12aeae293dc32750853d2 | 29,489 |
def combination_sum_bottom_up(nums, target):
"""Find number of possible combinations in nums that add up to target, in bottom-up manner.
Keyword arguments:
nums -- positive integer array without duplicates
target -- integer describing what a valid combination should add to
"""
combs = [0] * (ta... | 00feff267ff21f5132d98ac9c3171869fc150bfa | 29,490 |
def fix_msg(msg, name):
"""Return msg with name inserted in square brackets"""
b1 = msg.index('[')+1
b2 = msg.index(']')
return msg[:b1] + name + msg[b2:] | 66544f811a9cead0a40b6685f60a7de8f219e254 | 29,491 |
def reshape_as_vectors(tensor):
"""Reshape from (b, c, h, w) to (b, h*w, c)."""
b, c = tensor.shape[:2]
return tensor.reshape(b, c, -1).permute(0, 2, 1) | 79044cc2061d0a4368922c3dc6c1324eb5fe315b | 29,493 |
from functools import wraps
def memoized(function):
"""
Caches the output of a function in memory to increase performance.
Returns
-------
f : decorated function
Notes
-----
This decorator speeds up slow calculations that you need over and over
in a script. If you want to keep th... | 885999e6cdcbb165570beae901ed6701df966f64 | 29,494 |
def get_common_items(list1, list2):
"""
Compares two lists and returns the common items in a new list. Used internally.
Example
-------
>>> list1 = [1, 2, 3, 4]
>>> list2 = [2, 3, 4, 5]
>>> common = get_common_items(list1, list2)
list1: list
list2: list
returns: list
"""
... | 4978429d7d255270b4e4e52e44159e934cbd5ba5 | 29,497 |
def validate_eyr(value: str) -> bool:
"""Expiration must be between 2020 and 2030, inclusive"""
try:
return int(value) in range(2020, 2031)
except (TypeError, ValueError):
return False | 8b9cacda3eafeba6e26779430bb80218051f2f24 | 29,498 |
from typing import List
def cut_list_with_overlap(input_list: list, norm_seg_size: int, overlap: int,
last_prop: float) -> List[list]:
"""Cut the split list of text into list that contains sub-lists.
This function takes care of both overlap and last proportion with the input
lis... | 5f3b912907bcfbb41bae1df048601def5c6dbef6 | 29,499 |
def craft_post_header(length=0, content_length=True):
""" returns header with 'content-length' set to 'num' """
if content_length:
header = b"POST /jsproxy HTTP/1.1\r\nContent-Length: "
header += "{}\r\n\r\n".format(str(length)).encode()
else:
header = b"POST /jsproxy HTTP/1.1\r\n\r... | 4d556541ccd9bce18dad2bebffaaab7851673ef8 | 29,500 |
def Powerlaw(x, amp, index, xp):
"""
Differential spectrum of simple Powerlaw normlized at xp
:param x: Energies where to calculate differential spectrum
:param amp: Amplitude of pl
:param index: Index of pl
:param xp: Normalization energy
:return: differential spectrum of a Powerlaw at ener... | 6e31d7a85998f762ff27305a38535487db6592fb | 29,501 |
def set_mates(aset):
"""Set the mates in a set of alignments."""
def mate_sorter(aln):
"""Sort the alignments in order of mate."""
return (
aln.supplementary_alignment,
aln.secondary_alignment,
not aln.first_in_pair)
aset.sort(key=mate_sorter)
if len... | 50b499e8d03e049fefd8a9e29db4b267d7e1399f | 29,502 |
import math
def number_of_combinations(n, i):
""" This function gets the binominal coefficients n and i.
Returns the number of ways the i objects can be chosen from among n objects."""
return int((math.factorial(n)) / (math.factorial(i) * math.factorial(n - i))) | cf78abaa64948732965ee912a5247610a7c8d909 | 29,503 |
def get_by_tag_name(element, tag):
"""
Get elements by tag name.
:param element: element
:param tag: tag string
:return: list of elements that matches tag
"""
results = []
for child in element.findall('.//'):
if tag in child.tag:
results.append(child)
return resul... | d1e2d196cae5c3a0de00c624f5df28c988eaa088 | 29,504 |
def clamp(value, min=0, max=255):
"""
Clamps a value to be within the specified range
Since led shop uses bytes for most data, the defaults are 0-255
"""
if value > max:
return max
elif value < min:
return min
else:
return value | 2d6e01daddc3603527021e4dbab261f82b3f8862 | 29,505 |
def clamp_value(value, minimum, maximum):
"""Clamp a value to fit within a range.
* If `value` is less than `minimum`, return `minimum`.
* If `value` is greater than `maximum`, return `maximum`
* Otherwise, return `value`
Args:
value (number or Unit): The value to clamp
minimum (nu... | 1224b7ed098781d66721dceef5c837470f1195a6 | 29,507 |
import os
import yaml
def _load_config():
"""Load the Helm chart configuration used to render the Helm templates of
the chart from a mounted k8s Secret."""
path = f"/etc/jupyterhub/secret/values.yaml"
if os.path.exists(path):
print(f"Loading {path}")
with open(path) as f:
... | 658284176edb6327be4615c0ec347f13606fc8b3 | 29,508 |
def earlyexit_loss(output, target, criterion, args):
"""Compute the weighted sum of the exits losses
Note that the last exit is the original exit of the model (i.e. the
exit that traverses the entire network.
"""
weighted_loss = 0
sum_lossweights = sum(args.earlyexit_lossweights)
assert sum... | 49eb0fd896621dc678eb4de1d482a0e80eb00d8e | 29,509 |
def make_signatures_with_minhash(family, seqs):
"""Construct a signature using MinHash for each sequence.
Args:
family: lsh.MinHashFamily object
seqs: dict mapping sequence header to sequences
Returns:
dict mapping sequence header to signature
"""
# Construct a single hash ... | c6366811536f1e32c29e3a00c91267bde85969fa | 29,510 |
def promote_window(gate_gen1, gate_item2):
"""
:param gate_gen1: the generator of the gates objects
:param gate_item2: the current gate 2 object
:return: promoted gate 1 , new middle list , promoted gate 2
"""
try:
temp_gate = next(gate_gen1)
except RuntimeError:
return gate... | e69ff90a31fb3de3335dedbd3f17cd6f24fe44bf | 29,512 |
def equivalent(m1, m2):
"""Test whether two DFAs are equivalent, using the Hopcroft-Karp algorithm."""
if not m1.is_finite() and m1.is_deterministic():
raise TypeError("machine must be a deterministic finite automaton")
if not m2.is_finite() and m2.is_deterministic():
raise TypeError("machin... | ad0c67b167de8987d90fe9d41cec25f8deea81ea | 29,514 |
def divide_no_nan(a, b):
"""
Auxiliary funtion to handle divide by 0
"""
div = a / b
div[div != div] = 0.0
div[div == float('inf')] = 0.0
return div | e037bd1f7d5ed6e2aaf545e1fc5454dbcf719c38 | 29,515 |
import socket
def resolve_fqdn_ip(fqdn):
"""Attempt to retrieve the IPv4 or IPv6 address to a given hostname."""
try:
return socket.inet_ntop(socket.AF_INET, socket.inet_pton(socket.AF_INET, socket.gethostbyname(fqdn)))
except Exception:
# Probably using ipv6
pass
try:
... | 2e7680fe3a4ea174f3f7b22e4991a3a65e5e4995 | 29,516 |
def personalizar_url(termo_de_pesquisa):
"""
Função para pesquisar produtos e personalizar a url de pesquisa
IN: 'smart tv 4k': str
OUT: https://www.magazineluiza.com.br/busca/iphone 11/?page={}
"""
template = 'https://www.magazineluiza.com.br/busca/{}/'
termo_de_pesquisa.replace('', '+')
... | 92c3fa9a6f79cfef5d43d8eef1d6aadbc88b814f | 29,517 |
def empty_rule(*args):
"""An empty rule for providing structure"""
return {} | e42c8ecbfc1dd47f366734ad0a4294733954cfe5 | 29,518 |
from pathlib import Path
def field_name_from_path(path):
"""Extract field name from file path."""
parts = Path(path).stem.split('.')
field_name = parts[-1]
if len(parts) > 1:
if parts[-1] in ('bam', 'sam', 'cram'):
field_name = parts[-2]
return field_name | 9d21b760bccb6557f5450921482d76917ba13981 | 29,519 |
import sys
def import_class(full_name, subclassof=None):
"""
Import the Python class `full_name` given in full Python package format
e.g.
package.another_package.class_name
Return the imported class. Optionally, if `subclassof` is not None and is
a Python class, make sure that the import... | 2b0d3acc462e016e4d6d9bdc65210bb126ddc756 | 29,520 |
def binaryStringDigitDiff(binstr1, binstr2):
"""
Count the number of digits that differ between two
same-length binary strings
Parameters
----------
binstr1 : string
A binary (base-2) numeric string.
binstr2 : string
A binary (base-2) numeric string.
Returns
-------... | be39c7dbc30f6e49263a880254a021ff6873d240 | 29,521 |
import os
def find_all_event_files(dir_path):
"""find all event files in directory `dir_path`.
:param dir_path: directory path
:type dir_path: str
:return: list of file path.
"""
file_path_list = []
for root, dirs, files in os.walk(dir_path):
for file_name in files:
... | 822efba29bbd5c7ad5050f73f8859b2824f1789e | 29,522 |
def nodes(topology):
"""Get the nodes in the topology
This function returns a list containing all nodes in the topology. When
iterating through all nodes in the list, nodes_iter is preferable.
"""
return topology.nodes() | ec631e7ff22d993d3e21974ffbe035e2a03f99dc | 29,523 |
from datetime import datetime
def timestamp_to_datetime(timestamp):
"""Generate datetime string formatted for the ontology timeseries
Args:
timestamp (float, timemstamp): Timestamp value as float
Returns:
str: Returns the timestamp with the format necessary to insert in the Ontology
... | b894c3610842bf62387cbed77047fe4cc4d577a5 | 29,524 |
def rem(args):
"""MODIFICATION Removes sub-string (requires one argument)
"""
f=args.split()[1]
def _f(input):
return [ i.replace(f, '') for i in input ]
return _f | b46f626ad767693735fde87ade3aee8a37a13e0a | 29,525 |
def setdiag(G, val):
"""
Sets the diagonal elements of a matrix to a specified value.
Parameters
----------
G: A 2D matrix or array.
The matrix to modify.
val: Int or float
The value to which the diagonal of 'G' will be set.
"""
n = G.shape[0]
for i in range(0,n):
... | 74a1e2899a8575f04692f74ad01e122b3639d2b1 | 29,526 |
import re
def list_nameservers():
"""Append a nameserver entry to /etc/resolv.conf"""
with open('/etc/resolv.conf', 'r') as dnsservers:
entries = dnsservers.readlines()
dns = []
for entry in entries:
if re.match("\s*nameserver", entry) is not None:
dns.appen... | 1fef764c7652d50387c828539d962049ad4195c6 | 29,527 |
def forest_without(root, vals):
"""Removes nodes with specified values. Yields the remaining roots."""
def dfs_root(node):
if not node:
return
if node.val in vals:
yield from dfs_root(node.left)
yield from dfs_root(node.right)
else:
yield ... | 5fd3badc8d1e55d352be2fecd12535b643fa34e2 | 29,528 |
def get_operation_full_job_id(op):
"""Returns the job-id or job-id.task-id for the operation."""
job_id = op.get_field('job-id')
task_id = op.get_field('task-id')
if task_id:
return '%s.%s' % (job_id, task_id)
else:
return job_id | 6c0258d5c2053a5320d78340979fe60c8ea88980 | 29,530 |
def add_to_list(api_call):
"""Change API request to a list of replays by managing potential KeyError.
:param api_call: Request object
:return: list of replays.
"""
the_list = api_call.json()['list']
return the_list | 5d742d44f96df1cb0b1b422468d220abaaab6fbe | 29,531 |
def make_too_big():
"""
Returns a string too big to store as custom data (> 20MB).
"""
return "12" * 20 * 1024 * 1024 | db5177357d9e6c4b0b22b35cdded1d8f7a6269ab | 29,532 |
def get_conditions(worksheet):
"""
Get the conditions displayed on a worksheet.
args:
worksheet (seeq.spy.workbooks._worksheet.AnalysisWorksheet): Worksheet
returns:
conditions (pandas.DataFrame): Displayed Conditions
"""
display_items = worksheet.display_items
if len(display_items) == 0:
raise ValueErr... | f3fe0bd58f9a0344f047e3ae6eef6bdefa325c21 | 29,534 |
def TailFile(fname, lines=20):
"""Return the last lines from a file.
@note: this function will only read and parse the last 4KB of
the file; if the lines are very long, it could be that less
than the requested number of lines are returned
@param fname: the file name
@type lines: int
@param lines... | 39f2f07421f150df16061219790e49f222f284e7 | 29,535 |
import argparse
def parse_args():
"""Parse CLI arguments"""
ocm_cli_binary_url = ("https://github.com/openshift-online/ocm-cli/"
"releases/download/v0.1.55/ocm-linux-amd64")
parser = argparse.ArgumentParser(
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
... | b278cdd1ebc43088eec940fc80dfe746f6a9f744 | 29,536 |
def assign_x_in_same_rows(sorted_df):
"""
:param sorted_df: dataframe sorted on min_x values
:return: dataframe assigning squares in the same x row
"""
df = sorted_df.reset_index()
x_assignments = []
group = 0
min_x = df.ix[0, 'min_x']
for row in sorted_df.iterrows():
x = r... | d9877c45ca12f12cfebc6a88a257a28594ea70ca | 29,537 |
def get_df_subset(df, column_one, value_one, column_two, value_two):
"""
Takes a dataframe and filters it based on two columns and their matching values
"""
return df.loc[(df[column_one] == value_one) & (df[column_two] == value_two), :] | 4971af24f33b12d00a2385b7c5ee295630f385de | 29,538 |
import os
def get_dir(instr,pathsup):
"""
folder = get_dir(instr,pathsup)
folder = get_dir(s,1) # get the inner most folder
Parameters
----------
instr : STRING
PATH.
pathsup : INTEGER
Defines the number of folders away from the innermost.
Returns
-------
oust... | 4ace513dc7fb74f7eafa6f0f091b2c2068826a1d | 29,539 |
def zoom_to_roi(zoom, resolution):
"""Gets region of interest coordinates from x,y,w,h zoom parameters"""
x1 = int(zoom[0] * resolution[0])
x2 = int((zoom[0]+zoom[2]) * resolution[0])
y1 = int(zoom[1] * resolution[1])
y2 = int((zoom[1]+zoom[3]) * resolution[1])
return ((x1,y1),(x2,y2)) | cd77da9a67713ed7f76f4d41a7b7bee7e2f54a78 | 29,540 |
def get_ext(path):
"""Get file extension.
Finds a file's extension and returns it.
Parameters
----------
path : str
The path to a file.
Returns
-------
str
The file extension including leading "."
"""
return path[path.rfind(".") :] | 80ba4fb8686b2a7454240a56aa0c3a7d41636f27 | 29,541 |
def _engprop(l): # {{{1
"""Print the engineering properties as a HTML table."""
lines = [
"</tbody>",
"<tbody>",
'<tr><td colspan="6" align="center"><strong>Engineering properties</strong></td></tr>',
'<tr><td colspan="3" align="center"><strong>In-plane</strong></td>',
'... | e6bbaa4a39265b2703aa623a99a73f5b4e471023 | 29,544 |
def convert_codonlist_to_tuplelist(seq_codons, codon_to_codon_extended):
"""Convert a list of triplets into a list of tuples, using a swaptable.
The swaptable is a dict of triplet: triplets, and determines the
allowed swaps.
"""
codon_extended = [None] * len(seq_codons)
for i, codon in enumerat... | c4121f51aa0152f8e7683380667d06f0b79903f1 | 29,547 |
def _check_model(model):
"""Check model input, return class information and predict function"""
try:
n_classes = len(model.classes_)
predict = model.predict_proba
except:
n_classes = 0
predict = model.predict
return n_classes, predict | 9dbf14724f1407c65a7b9e306f32e28eb37b66ee | 29,548 |
import typing
import hashlib
def create_sf_instance(entity_name: str, property_label: str) -> typing.Tuple[str, str]:
"""Creates a slot filling instance by combining a name and a relation.
Arguments:
entity_name: ``str`` The name of the AmbER set to fill into the template.
property_label: ``s... | 02e69115261b148c7fdb270864095c63bbdb2278 | 29,549 |
def ensure_keys(dict_obj, *keys):
"""
Ensure ``dict_obj`` has the hierarchy ``{keys[0]: {keys[1]: {...}}}``
The innermost key will have ``{}`` has value if didn't exist already.
"""
if len(keys) == 0:
return dict_obj
else:
first, rest = keys[0], keys[1:]
if first not in ... | e8d87444ed8961d8d650b49c8670dca1496623b1 | 29,550 |
def to_plist(head):
"""scans from head onwards, returns python list"""
plist = [head.val]
current = head
while current.next:
plist.append(current.next.val)
current = current.next
return plist | 95cf048cd51a931c6381a90d455b721c4766473f | 29,551 |
def uint_double(k):
"""Substitute for corresponding C function in the mini_double package
The cython extension 'mini_double' is used for code generation.
Depending on the details of the build process, it may not yet be
available when the code is generated. So we take this function as
a substitute ... | 760d9b1dbbd6975879b97bdc3d808cda7980c93e | 29,553 |
import re
def middle_coord(text):
"""Get the middle coordinate from a coordinate range.
The input is in the form <start> to <end> with both extents being in
degrees and minutes as N/S/W/E. S and W thus need to be negated as we only
care about N/E.
"""
def numbers_from_string(s):
"""F... | 4e8148102ff04969279690922ddce5bd767fed55 | 29,554 |
def fakefunction(*args, **kwargs):
"""
:dsc: Simple wrapper to attache this to classes of module when we end up with a fake attribute
"""
return None | bd3d270395d8a7de4185d88f01dd76c1c28ec9ed | 29,555 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.