content stringlengths 35 416k | sha1 stringlengths 40 40 | id int64 0 710k |
|---|---|---|
import pathlib
def find_component(path: pathlib.PurePath):
"""
Extracts the likely component name of a CSV file based on the path to it
:param path: path to a CSV file
:return: likely component to use
"""
# pylint: disable=no-else-return
if path.parent.name.isnumeric():
# Probably ... | 2cdf37ed07a1c535f59c6318f402c66fe4248fc2 | 21,149 |
from typing import List
def create_cave(depth: int, tx: int, ty: int) -> List[List[int]]:
"""
Creates the cave according to the cave generation rules.
Since the cave is essentially infinite a constant size padding is applied
around the target coordinates to make the pathfinding feasible. Note that
... | 20537fab61614aece67b20f9d33bd8ade3259637 | 21,151 |
import logging
def logging_setup(logging_handler, logging_level) -> logging.Logger:
""" Init logger object for logging in rubrik-sdk
For more info - https://docs.python.org/3/library/logging.html
Args:
logging_level(int): Log level
logging_handler (Handler): Handler to log
Returns... | c1e301183baf7a121467738d56c5c68883b5fca5 | 21,152 |
def nice_macaddress(mac):
""" MAc address in shape 01:23:45:67:AB """
text = mac.replace('.', '').replace('-','').upper() # a little pre-processing
# chunk into groups of 2 and re-join
out = ':'.join([text[i : i + 2] for i in range(0, len(text), 2)])
return out | e9307fe00c66c1fd55615f224256ef6086c81ba4 | 21,153 |
import ast
def create_function(name, args, body):
"""
Create a function node
:param name: Name of the functions
:param args: Arguments of the function
:param body: Body of the function
:return: Instance of `ast.FunctionDef`
"""
return ast.FunctionDef(name=name, args=args, body=body, decorator_list=[]) | cdec8520a642fbfd46975eceb5682244811d808b | 21,154 |
import re
def extract_template(pattern):
"""Extracts a 'template' of a url pattern given a pattern
returns a string
Example:
input: '^home/city
(-(?P<city_name>bristol|bath|cardiff|swindon|oxford|reading))?$'
output: 'home/city(-{})?'
"""
pattern = pattern.strip('$^')
pattern... | 4d36c5f0b6d3ac4072b376119d78b083419143c4 | 21,156 |
import sys
def get_caller_name(_stackdepth: int = 0) -> str:
"""
Gets the name of the calling function.
"""
return sys._getframe(_stackdepth + 1).f_code.co_name | 45042bb51fc65ba744b22724cd3dc29bebf6920b | 21,157 |
import requests
def newSDDCGroupGr(proxy_url,sessiontoken,gw,group_id,member_of_group):
""" Creates a single SDDC group and adds 'member_of_group' to the group membership"""
myHeader = {'csp-auth-token': sessiontoken}
proxy_url_short = proxy_url.rstrip("sks-nsxt-manager")
# removing 'sks-nsxt-manager'... | 0de12306ac80888c887b2be5368cb7c5978afadc | 21,161 |
def add_a_half(rectangle):
"""Adds 0.5 to a rectangle (2x2 coordinates)"""
return [(x + 0.5, y + 0.5) for x, y in rectangle] | 6cd1e1a71419b486706a47e7a216b530a9bf6e73 | 21,162 |
def accuracy_best(items):
"""The best possible accuracy on the given items"""
return (items.modal_response == items.target).mean() | 7c9bbb2e1bb02f46966359ee8ec9d2d9723fcd1d | 21,163 |
import io
import yaml
def dumps_yaml(obj):
"""Attempt to dump `obj` to a YAML string"""
stream = io.StringIO()
yaml.dump(obj, stream=stream, default_flow_style=False)
return stream.getvalue() | 9699b47c438fc87376c862cca46d5ce6e0089400 | 21,165 |
import re
def striptags(text):
"""
striptags; markuped text should be cleared to use
most of times this function is used as shortcuts.
::text: String; markuped text is expected
"""
return re.sub(r'\[[^>]*?\]', '', text) | 5ba7430d11612686f50b544a4d807454aae4aad0 | 21,166 |
from pydantic import BaseModel # noqa: E0611
def is_base_model_type(type_):
"""
Whether ``type_`` is a subclass of ``BaseModel``.
"""
if not isinstance(type_, type):
return False
return issubclass(type_, BaseModel) | d0a195460a70a978244e75503896b9bdbd147c9b | 21,167 |
def linear(data):
"""Completes data records with missing data (0 or None) using linear
interpolation. Works only if first and last data points have valid data"""
data = list(data)
last_data_pt = 0
i = 0
interpolate = False
for i in range(len(data)):
dt = data[i]
if not dt['d... | 740b8a66da49f87eede90173b009be0504b166a7 | 21,168 |
def flip_bbox(bbox, size, y_flip=False, x_flip=False):
"""
bbox : see before
size (tuple): 2 values before resized, (height, width)
y_flip (bool):
x_flip (bool):
Return: ~numpy.ndarray
"""
H, W = size
bbox = bbox.copy()
if y_flip:
y_max = H - bbox[:, 0]
y_min = ... | 43a3776d8e75692980f5d6acf2a8c20a8b0bdc5a | 21,169 |
import os
def find_executable(name):
"""
:type name: str
:rtype: str
"""
path = os.environ.get('PATH', os.path.defpath)
seen = set([os.path.abspath(__file__)])
for base in path.split(os.path.pathsep):
candidate = os.path.abspath(os.path.join(base, name))
if candidate in s... | 4d53bd95821432060cb047e30fb1102d1d5ad81c | 21,171 |
def _in_voltage_range(comp, low_voltage_limit, high_voltage_limit, internal=False):
""" Return True if :obj:`comp` is within the voltage limits.
These limits are given in the settings file and is a way of
restricting which components one puts into the contingencies.
Parameters
==========
comp:... | 39219d69df20a9ce1dd1af8daebeca75ee6620af | 21,172 |
def extract_2d_info(img_meta, tensor):
"""Extract image augmentation information from img_meta.
Args:
img_meta(dict): Meta info regarding data transformation.
tensor(torch.Tensor): Input tensor used to create new ones.
Returns:
(int, int, int, int, torch.Tensor, bool, torch.Tensor)... | 8807e24a849aedc1cc460859b4c2088318c13489 | 21,173 |
import math
import random
def train_test(data, val_ratio=0.2, test_ratio=0.2, shuffle=True, seed=42):
"""Split a list into training and test sets, with specified ratio.
By default, the data is shuffled with a fixed random seed.
The data is not mutated.
:param data: list of data objects
:param va... | 42c999ce21d1f60c8bba88f10ed833ce9576057c | 21,176 |
def set_difference(set_a, set_b):
"""
compare two sets and return the items
which are in set_b but not in set_a
"""
diff = set_b - set_a
return diff | 583a83bac0a95c46050a2626c7d4092a71d62a4e | 21,177 |
def _get_extension_for_entry(intake_entry):
"""
Given an intake catalog entry, return a file extension for it, which can
be used to construct names when re-uploading the files to s3. It would be
nice to be able to rely on extensions in the URL, but that is not
particularly reliable. Instead, we infe... | 514a9583e5305f0bc5baca023c9f64ea7d3070c1 | 21,178 |
import re
def split_dump_pattern(pattern):
"""Split a comma separated string of patterns, into a list of patterns.
:param pattern: A comma separated string of patterns.
"""
regex = re.compile('\s*,\s*')
return regex.split(pattern) | ba32147a07cf31dc4a59d18fe10872a19bf7d209 | 21,179 |
def get_branch_list(nodes, exit_index):
"""Computes the branch list for the control flow graph.
Args:
nodes: A list of control_flow.ControlFlowNodes.
exit_index: The index of the exit node.
Returns:
A Python list representing the branch options available from each node. Each
entry in the list cor... | 8c92087289649ad457340d3a1af781b791b4666c | 21,180 |
def get_user_choice():
"""Prompts the user for its choice and return it."""
user_input = input('Your choice: ')
return user_input | 32b5e7e6404d32626d883cdf9e80ddc29345ec28 | 21,181 |
def convert_names_to_highlevel(names, low_level_names,
high_level_names):
"""
Converts group names from a low level to high level API
This is useful for example when you want to return ``db.groups()`` for
the :py:mod:`bob.bio.base`. Your instance of the database should
already ... | db3a568e5f5465736b3134903f725ce19dfe56d4 | 21,182 |
def _traverse(item, path):
"""
Traverse item.
Else return None.
Path is a str separated by '.'
"""
if isinstance(path, str):
return _traverse(item, path.split("."))
if len(path) == 0:
return item
head = path[0]
tail = path[1:]
if hasattr(item, head):
r... | 31f847b876ca0333975adf4ed9ba026c0843a317 | 21,183 |
def get_load_config_timestamp(pefile_object):
"""
Retrieves the timestamp from the Load Configuration directory.
:param pefile.PE pefile_object: pefile object.
:return: Recovered timestamps from PE load config (if any).
None if there aren't.
:rtype: int
"""
timestamp = 0
if hasattr... | 4b04afa7d844ce05761fa5b8f484540a1ae243a4 | 21,184 |
def analyze_O_in_set(
data_dict_i,
group_i,
df_magmoms,
magmom_cutoff=None,
compenv=None,
slab_id=None,
active_site=None,
):
"""
"""
#| - analyze_O_in_set
compenv_i = compenv
slab_id_i = slab_id
active_site_i = active_site
sys_w_not_low_magmoms = False
sy... | 6296f6636e9734f56536063cc8723364626e9f54 | 21,185 |
def swap(array, size=0):
""" size=0: [2, 3, 5, 7, 11] -> [11, 7, 5, 3, 2] ; size=2: [2, 3, 5, 7, 11] -> [3, 2, 7, 5, 11] """
if size == 0: size = len(array)
a = [array[i:i + size] for i in range(0, len(array), size)]
a = [item[::-1] for item in a]
return [item for sublist in a for item in sublist] | 7f5fc18fe8d31e8092a17eb716ff100500cc8d05 | 21,186 |
def soft_timing(Nframes, time, fpsmin=10, fpsmax=20):
"""determines time & fps; aims for target time, but forces fpsmin < fps < fpsmax.
example usage: target 3 seconds, but force 10 < fps < 25:
import QOL.animations as aqol
for i in range(50):
code_that_makes_plot_number_i()
... | e6698e8665398c9d2996f2532d3455caaf77d253 | 21,187 |
def upilab5_4_6 () :
"""5.4.6. Exercice UpyLaB 5.10 - Parcours vert bleu rouge
Écrire une fonction dupliques qui reçoit une séquence en paramètre.
La fonction doit renvoyer la valeur booléenne True si la séquence passée en paramètre contient des éléments dupliqués,
et la valeur booléenne False sinon.
Exemple 1 : L’... | 19a6111c463870a79de716c8724e218beb7d7630 | 21,188 |
import struct
def read_message(_socket):
"""
Function read message from certain socket
:param _socket: created socket for communication with server
:return: received byte array
"""
total_read = 0
now_reade = 0
now_buf = bytearray(4)
total_buf = bytearray(0)
# time.sleep(1)
... | 495e9069851db2fd92af67f4ce56dae6a1baaa75 | 21,189 |
def _must_prepend(ref, alts):
"""Return whether the preceding reference base must be prepended.
Helper for satisfying the VCF spec.
"""
alleles = alts + [ref]
if any(not allele for allele in alleles):
return True
snp = all(len(allele) == 1 for allele in alleles)
return not snp and a... | 3c5b61e4333e5c9fef6b4041b0364ac05de98986 | 21,190 |
def remove_none_entries(obj):
"""Remove dict entries that are ``None``.
This is cascaded in case of nested dicts/collections.
"""
if isinstance(obj, dict):
return {k: remove_none_entries(v) for k, v in obj.items() if v is not None}
elif isinstance(obj, (list, tuple, set)):
return ty... | 48e36752c078e793e756cf84faf46af809fc4942 | 21,191 |
import os
import glob
def get_sqlite_filepaths_from_directory(directory):
"""Returns a list of filepaths."""
filepaths = []
os.chdir(directory)
for filepath in glob.glob("*.sqlite"):
filepaths.append(filepath)
return filepaths | 4b82ce18b45317636406d27d396d0ed0a60f44e5 | 21,192 |
import ast
def has_docstring(node):
"""Retuns true if given function or method has a docstring.
"""
docstring = ast.get_docstring(node)
if docstring is not None:
return not docstring.startswith('mys-embedded-c++')
else:
return False | 7d6b1be6d48ba39fb871cf517080f352c56ac14c | 21,193 |
def type_uniform_op2_match(result_type, op0_type, op1_type, **kw):
""" Type match predicates:
a 2-operand where operands and result format must
match
"""
return result_type == op0_type and op0_type == op1_type | 27b1988f49dc77641035fac25828b148af30f6e5 | 21,194 |
import json
def encode_pretty_printed_json(json_object):
"""Encodes the JSON object dict as human readable ascii bytes."""
return json.dumps(
json_object,
ensure_ascii=True,
indent=4,
sort_keys=True,
).encode("ascii") | e91ccef7379de9e062b8b456b02d99b04f8871e1 | 21,195 |
def get_file_contents(fn: str) -> str:
"""
Read the contents of file.
:return: a string.
"""
with open(fn, 'r') as infile:
return ''.join((line for line in infile)) | 2d11ac1d8d1e50973a1c45fd0ed27ae9dd8d700e | 21,196 |
def format_field(relation_name, field):
"""Util for formatting relation name and field into sql syntax."""
return "%s.%s" % (relation_name, field) | 5e2fd795779f198a64a176da218f879046ab49f5 | 21,197 |
def is_binary(node):
"""Is the subtree under `node` a fully bifurcating tree?"""
for internal_node in node.preorder_internal_node_iter():
if len(internal_node.child_nodes()) != 2:
return False
return True | 5dbb0cee276417a9f8397e82be79d6f7cbf7564d | 21,198 |
def validate_initial_digits(credit_card_number: str) -> bool:
"""
Function to validate initial digits of a given credit card number.
>>> valid = "4111111111111111 41111111111111 34 35 37 412345 523456 634567"
>>> all(validate_initial_digits(cc) for cc in valid.split())
True
>>> invalid = "14 25 ... | 3a40c24d1200ea70c84035b66a7cd756a8abf32e | 21,199 |
import numpy
def to_xyz(color):
"""Convert a Toyplot color to a CIE XYZ color using observer = 2 deg and illuminant = D65."""
def pivot(n):
return (numpy.power((n + 0.055) / 1.055, 2.4) if n > 0.04045 else n / 12.92) * 100.0
r = pivot(color["r"])
g = pivot(color["g"])
b = pivot(color["b"]... | ba3ed1617a4af8a43ce89281d727d65e765e595e | 21,200 |
def assign_crowd_dist(problem, frontier):
"""
Crowding distance between each point in
a frontier.
"""
l = len(frontier)
for m in range(len(problem.objectives)):
frontier = sorted(frontier, key=lambda x:x.objectives[m])
frontier[0].crowd_dist = float("inf")
frontier[-1].crowd_dist = float("inf")
... | f224c0276123946ccd159ca58ed8dce1ff81d3a3 | 21,201 |
def j2k(j, E, nu, plane_stress=True):
"""
Convert fracture
Parameters
----------
j: float (in N/mm)
E: float
Young's modulus in GPa.
nu: float
Poisson's ratio
plane_stress: bool
True for plane stress (default) or False for plane strain condition.
Re... | 9ae849e78ba1136209accb56afa411803c0940a3 | 21,203 |
import sys
def prepare_args(executable, flag_options=None, value_options=None):
"""
Args:
executable: path to the executable
flag_options: positional arguments for executable
value_options: keyword arguments for executable
Returns:
list with command-line entries
"""
... | 10c553a7e431d1470db19a8e20224d05fd958c03 | 21,204 |
def _match_names(pattern, names):
"""Match names to patterns and return a tuple of matching name with
extracted value (stripped of suffix/prefix)."""
result = []
for name in names:
match = pattern.match(name)
if match:
result.append((name, match.group("name")))
return ... | 8e5b4d55e3d068cc7bd3ea553e3096e43bff6795 | 21,206 |
def to_int_percent(items):
""" Converts a list of numbers to a list of integers that exactly sum to
100. """
nitems = len(items)
total = sum(items)
if total == 0:
return [0] * nitems
perc = [100 * p // total for p in items]
s = sum(perc)
i = 0
while s < 100:
if ite... | 2caf6b1a1149b2bd932176f8398b094b2fa0f3e0 | 21,207 |
import re
def lazyIsMatch(s, p):
"""
:type s: str
:type p: str
:rtype: bool
lazyIsMatch uses the build-in Python regex engine to do wildcard matching. It's the lazy approach, and the one that should actually be used 🙂
"""
try:
# the replace lets ? match any character, but because... | a214962de016cbb2a01dc21def180bbdc014ec49 | 21,208 |
import gzip
def openGzipOrText(fPath,encoding=None) :
"""Opens a file for reading as text, uncompressing it on read if the path ends in .gz"""
if str(fPath).lower().endswith('.gz') :
return gzip.open(fPath,'rt',encoding=encoding)
else :
return open(fPath,'rt',encoding=encoding) | c9497814182ba1c884acb5de488e10dcd5cafc1d | 21,209 |
def get_parent_technique_id(sub_tid):
"""Given a sub-technique id, return parent"""
return sub_tid.split(".")[0] | 4dcfc1e3558e20a58c754a17f5730865804f4b9d | 21,210 |
def lineStartingWith(string, lines):
""" Searches through the specified list of strings and returns the
first line starting with the specified search string, or None if not found
"""
for line in lines:
if line.startswith(string):
return line
else:
return None | 7d6b8fa259a8514721443a37195d678c7d8ac21b | 21,211 |
from pathlib import Path
def _get_file_from_folder(folder: Path, suffix: str) -> Path:
"""Gets this first file in a folder with the specified suffix
Args:
folder (Path): folder to search for files
suffix (str): suffix for file to search for
Returns:
Path: path to file
"""
... | 3e941b5dfaa394baa0baa9c1675a62020c85d8ae | 21,212 |
import copy
def _normalize_barcodes(items):
"""Normalize barcode specification methods into individual items.
"""
split_items = []
for item in items:
if item.has_key("multiplex"):
for multi in item["multiplex"]:
base = copy.deepcopy(item)
base["descr... | 6f576d7789cc045b81abe8535942cf0c0abd912a | 21,213 |
from datetime import datetime
def strptime(date_string, format): # pylint: disable=redefined-builtin
"""
Wrapper around :meth:`datetime.strptime` which allows to pass keyword arguments
.. seealso:: :meth:`datetime.strptime`
:param date_string: Input date to parse
:type date_string: str
:par... | 483aabb0cd51e666169dc659bd4a26c98424d064 | 21,215 |
import sys
def stdout():
"""
Returns the stdout as a byte stream in a Py2/PY3 compatible manner
Returns
-------
io.BytesIO
Byte stream of Stdout
"""
return sys.stdout.buffer | 0fe8e053616159aedc514078ddaefa977229da4c | 21,217 |
import os
def path_to_data_dir():
"""Path to Data directory
Returns:
str: Absolute path to data directory
"""
return os.path.join(os.path.dirname(__file__), "data_files") | 575dd1afee6a3218069659c0a592b0395c2754eb | 21,220 |
import subprocess
def system(cmd):
""" system() equivalent to Matlab one
cmd = (code,params)
returns 0 if no error as well as the standard output
note: os.system() is depreciated and does not capture the output
"""
out = subprocess.run(cmd,capture_output=True, text=True)
return... | 6c6bd47ac567a0a46b46616feacd40aaf6330d77 | 21,221 |
def __to_float(num):
"""
Try to convert 'num' to float, return 'num' if it's not possible, else
return converted :code:`num`.
"""
try:
float(num)
return float(num)
except ValueError:
return num | 642d2a247066028c95623641a61f8eb523025d15 | 21,222 |
def calc_minutes(hhmm):
"""Convert 'HH:MM' to minutes"""
return int(hhmm[:2]) * 60 + int(hhmm[3:]) | 09de4c4f01860f67aa8628a50db8eb89f0815000 | 21,223 |
def is_stop_word(word, nlp):
""" Check if a word is a stop word.
:param word: word
:param nlp: spacy model
:return: boolean
"""
return nlp(word)[0].is_stop | 5eaae33e299b0cd51f8e9b72517e14a128fb46fa | 21,224 |
def format_80(s):
"""
Split string that is longer than 80 characters to several lines
Args:
s (str)
Returns:
ss (str): formatted string
"""
i = 0
ss = ''
for x in s:
ss += x
i += 1
if i == 80:
i = 0
ss += ' \ \n'
return ss | 6de52ef72f7bfaa237c43390cecea22a85fc88b3 | 21,225 |
import inspect
def func_body(fun):
"""Code inspection magic for use with timeit"""
data = [l.strip() for l in inspect.getsource(fun).split("\n")[1:]]
return "\n".join(data) | 27d7f717dbfd468f1c87dea255db9764137f361b | 21,227 |
from typing import Counter
def get_dic_sentiment(labels):
"""
:param labels: (Series) --> predictions of the sentiment analysis
:return: (dic) --> dictionary with the number of positive, negative and neutral values
"""
dic_sentiment = dict(Counter(labels))
if -1 in dic_sentiment:
... | c3880b126aad445ba234ab2275698f6c53dba9f1 | 21,228 |
import os
def are_the_same(file_path_1, file_path_2, buffer_size=8 * 1024):
"""
通过逐块比较两个文件的二进制数据是否一致来确定两个文件是否是相同内容
REF: https://zhuanlan.zhihu.com/p/142453128
Args:
file_path_1: 文件路径
file_path_2: 文件路径
buffer_size: 读取的数据片段大小,默认值8*1024
Returns: dict(state=True/False, msg=m... | 7d60bd3ecca21392530e1aa12ded89c68eb8e913 | 21,230 |
def check_panagram(
input_str: str = "The quick brown fox jumps over the lazy dog",
) -> bool:
"""
A Panagram String contains all the alphabets at least once.
>>> check_panagram("The quick brown fox jumps over the lazy dog")
True
>>> check_panagram("My name is Unknown")
False
>>> check_p... | b340c61820aaf674eaf79f712ea2dd64b4aa5690 | 21,232 |
def df_query_with_ratio(df_in, query, ratio_name='ratio'):
"""
This function calls the .query() method on a DataFrame
and additionally computes the ratio of resulting rows
over the original number of rows.
The result is a tuple with the filtered dataframe as first
element and the filter ratio a... | 46f0cad6494ff142bc9cd1a139e6cfe16cde8ac5 | 21,233 |
import torch
def cthw2tlbr(boxes):
"""
Convert center/size format `boxes` to top/left bottom/right corners.
:param boxes: bounding boxes
:return: bounding boxes
"""
top_left = boxes[..., :2] - boxes[..., 2:]/2
bot_right = boxes[..., :2] + boxes[..., 2:]/2
return torch.cat([top_left, bo... | c425f97a244e8433b07c5ec6839e0ca090d6e6bc | 21,234 |
def add_normalized_intensity_column(df, internal_std_col='MZ283'):
"""Add "MZ###_MZ###" columns to DataFrame of normalized peak intensities.
:param df: dataframe. Requires internal_std_col in a column.
:param internal_std_col: str. The title of column with internal standard used for normalizing the data.
... | e0d23baca6b948924b96e7c5f8458f49766427ea | 21,235 |
def get_location_by_offset(filename, offset):
"""
This function returns the line and column number in the given file which
is located at the given offset (i.e. number of characters including new
line characters).
"""
with open(filename, encoding='utf-8', errors='ignore') as f:
for row, l... | 434b60a80fffd8068ea6d90ead92d914127f3b3e | 21,236 |
def _E1(d, r, w, q, M):
"""
Solve Eq. 15
"""
return (2. * r * w / (w**2 + w * q + q**2) + M) / d | 99c06cb6c3278204c76315511361f808be14578c | 21,237 |
def padding_same(input, kernel, stride=1, dilation=1):
"""
Calculates padding for applied dilation.
"""
return int(0.5 * (stride * (input - 1) - input + kernel + (dilation - 1) * (kernel - 1))) | 3b4d360b860d1a556c64f7f3de0a98046d3267a4 | 21,238 |
def scale_to_percent(val, min, max):
"""
Utility function to scale a given value to a percentage within a range
"""
current = val
# first, ensure that current is within our defined min/max
if val < min:
current = min
elif current > max:
current = max
# now, we scale... | 7397f16e8c9ee014ceec62065ad830d3451484f5 | 21,239 |
import argparse
def _parse_args():
"""Return namespace of command-line input."""
parser = argparse.ArgumentParser(
description=
'Modify blank-space characters in '
'given file. This script considers '
r'`\n` and `\r\n` as line endings. '
'For more inform... | 4978c2244ef5dae8282a05724ad71e32cd9386ad | 21,240 |
def get_node_exec_options(profile_string, exec_node_id):
""" Return a list with all of the ExecOption strings for the given exec node id. """
results = []
matched_node = False
id_string = "(id={0})".format(exec_node_id)
for line in profile_string.splitlines():
if matched_node and line.strip().startswith("... | c7b6329b9caca6feb3bf00c1e9559887d03e4139 | 21,242 |
import os
import sys
def opt_ext(path_no_ext, ext, **kwargs):
"""
If the path exists, returns it.
If not, and if path + dotext exists, returns it.
Else, returns None.
kwargs:
@print_error: boolean.
If True, prints not found message to stderr in none is found.
Default: False
@opt... | 185286de719eaec183afd4a168135984eb910fab | 21,243 |
def replace_arg_simple(new_arg_name: str, old_arg_name: str):
"""
A much more simple version of replace arg.
Replaces one arg name for another.
Does not change function signatures.
Compatible with functions containing *args or **kwargs.
:param new_arg_name: The new name of the argument.
:p... | 6fc93e01ecb0d1ff4b9d795242e5ee3f7f430b2c | 21,244 |
def leaf_2(key):
"""Returns the key value of the leaf"""
return key | d67bc6527028bbc7ffabb5d88cbff149e1ddea4c | 21,246 |
import numpy
def RemoveNegativeEdgeWeights(node_weights, Gamma):
""" This method transforms a graph with edge weights Gamma into an equivalent graph
with non-negative edge weights.
"""
N = len(node_weights)
m = Gamma.min()
if m < 0:
print("m=", m)
print("node_weights=", node_we... | a08646bedfeebb17820131058949dfe102d331a0 | 21,247 |
def denormalize_images(imgs_norm):
""" De normalize images for plotting
"""
imgs = (imgs_norm + 0.5) * 255.0
return imgs | ed050b241ab63385119324ac6927c30be7a9d237 | 21,248 |
def drop_zombies(feed):
"""
In the given Feed, drop stops with no stop times,
trips with no stop times, shapes with no trips,
routes with no trips, and services with no trips, in that order.
Return the resulting Feed.
"""
feed = feed.copy()
# Drop stops of location type 0 that lack stop... | 1d51dd42c6530f9f5dead54c16d9e8567463d3b1 | 21,249 |
import os
import pwd
def find_local_username():
"""Find the username of the current user on the local system."""
for name in 'USER', 'LOGNAME':
if os.environ.get(name):
return os.environ[name]
entry = pwd.getpwuid(os.getuid())
return entry.pw_name | dba6f6cf9be024ebef8fc2f8898c54fd6bac4c6a | 21,253 |
def KeyLEQ(key1, key2):
"""Compare two keys for less-than-or-equal-to.
All keys with numeric ids come before all keys with names. None represents
an unbounded end-point so it is both greater and less than any other key.
Args:
key1: An int or datastore.Key instance.
key2: An int or datastore.Key instan... | 5f0bce3c7140cf0ff2f2ab19fd3c092a0159e63d | 21,255 |
def mock_get(pipeline, allowDiskUse): # pylint: disable=W0613,C0103
"""
Return mocked mongodb docs.
"""
return [
{'_id': 'dummy_id_A', 'value': 'dummy_value_A'},
{'_id': 'dummy_id_B', 'value': 'dummy_value_B'},
] | ee7c0062758c1bcb36a4cad88eb7b3575b37df11 | 21,256 |
def iou_from_bboxes(bb1, bb2):
"""
bbox = (xmin,ymin,xmax,ymax)
"""
assert bb1[0]<bb1[2], bb1
assert bb1[1]<bb1[3], bb1
assert bb2[0]<bb2[2], bb2
assert bb2[1]<bb2[3], bb2
# find intersection
xmin = max(bb1[0], bb2[0])
xmax = min(bb1[2], bb2[2])
ymin = max(bb1[1], bb2[1])
... | 3e0f0b4238db9e1e0f7b0b7a395467fcdb352cab | 21,257 |
def circulation_patron_exists(patron_pid):
"""."""
return False | 10a65d68446f77b42cfb094195e5b2f9f333f05d | 21,258 |
import subprocess
def tail(fname, n_lines, offset=None):
""" replicates the tail command from unix like operations systems
Args:
fname (str): filename
n_lines (int): the number of lines
Note:
this is dependent upon the tail command in the unx operating system
this sho... | 86fc35ce5b4e18f05eeae4c6e262ff422a7849ee | 21,259 |
def string_is_empty(text):
"""
判断字符串是否为空
:param str:
:return:
"""
if text is None:
return True
if text == "":
return True
return False | 576a59c47057ace35a4d928dcbd6ded3254f8ea7 | 21,260 |
def chr(i: int) -> str:
"""chr."""
return '\0' | c7a89d8616a9890ea051e30b923160df37d8d953 | 21,261 |
def remove_repeated_id(longer_list, shorter_list):
"""
Retorna uma lista de números que não se repetem nas 2 listas
:param longer_list: lista que sempre será maior
:param shorter_list: lista que sempre será menor ou igual a longer_list
:return: list
"""
result = []
for id in longer_list... | 2c47ff47f342e326d1ab30b627d2daa32cbe4f24 | 21,262 |
def quick_sort(num_list=[]):
"""Quick sorts a number list"""
if type(num_list) != list:
raise TypeError("The argument for quick_sort must be of type list.")
if len(num_list) <= 1:
return num_list
choice = num_list[len(num_list) // 2]
greater = [num for num in num_list if num > choi... | f38f537a803667f453196891998e8fa19fd6157c | 21,263 |
def roce(net_income, preferred_dividends, average_common_equity):
"""Computes return on common equity.
Parameters
----------
net_income : int or float
Net income
preferred_dividends : int or float
Preferred dividends
average_common_equity : int or float
Average common eq... | dd800458e2379a72bbe8377b979cc3572ec0c525 | 21,264 |
import torch
def get_interior_points(N=300):
"""
randomly sample N points from interior of [-1,1]^d
"""
return torch.rand(N, 1) * 6 - 3 | ae85b4bbbe11018fa7a3c53f60dafcb3e23ac915 | 21,265 |
def _is_int_in_range(value, start, end):
"""Try to convert value to int and check if it lies within
range 'start' to 'end'.
:param value: value to verify
:param start: start number of range
:param end: end number of range
:returns: bool
"""
try:
val = int(value)
except (Valu... | 54ed477b4d6f603a48a1104d60c00433b1cc47db | 21,267 |
def int_(value):
""":yaql:int
Returns an integer built from number, string or null value.
:signature: int(value)
:arg value: input value
:argType value: number, string or null
:returnType: integer
.. code::
yaql> int("2")
2
yaql> int(12.999)
12
yaq... | f966b765b46ca2da3e9f7776d88862a741090305 | 21,268 |
from typing import OrderedDict
import torch
import os
def load_ckpt_weights(model, ckptf, device='cpu', mgpus_to_sxpu='none', noload=False, strict=True):
"""
MultiGpu.ckpt/.model 与 SingleXpu.model/.ckpt 之间转换加载
m2s: MultiGpu.ckpt -> SingleXpu.model ; remove prefix 'module.'
s2m: SingleXpu.ckpt -> Mult... | aea9240047aff78063883d4e092ede9574eafa2d | 21,269 |
import os
def _ls_tree(directory):
"""Recursive listing of files in a directory"""
ret = []
for root, dirs, files in os.walk(directory):
ret.extend([os.path.relpath(os.path.join(root, fname), directory) for
fname in files])
return ret | 9d7a22d601bf09b00f0e710f540d89a6b7754672 | 21,271 |
def isstdiofilename(pat):
"""True if the given pat looks like a filename denoting stdin/stdout"""
return not pat or pat == b'-' | feff8e9c76be62c32cc46a7b02c3bf76da30179e | 21,272 |
import bisect
def _RevisionState(test_results_log, revision):
"""Check the state of tests at a given SVN revision.
Considers tests as having passed at a revision if they passed at revisons both
before and after.
Args:
test_results_log: A test results log dictionary from GetTestResultsLog().
revision... | e6f49854e92c228dc620acb569d7232ecf27507c | 21,276 |
def set_labels(ax, columns, y, table_position):
"""
Set the table either on the left or right.
"""
if table_position=='left':
ax.yaxis.set_label_position("right")
ax.yaxis.tick_right()
bbox=(-max(0.125*len(columns),0.3), 0, max(0.125*len(columns),0.3), (len(y)+1)/len(y))
els... | 07494d90927693aea39e40303f24b44b6cd8ff28 | 21,278 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.