content stringlengths 39 14.9k | sha1 stringlengths 40 40 | id int64 0 710k |
|---|---|---|
def _edge_is_between_selections(edge, selection_a, selection_b):
"""
Returns ``True`` is the edge has one end in each selection.
Parameters
----------
edge: tuple[int, int]
selection_a: collections.abc.Container[collections.abc.Hashable]
selection_b: collections.abc.Container[collections.ab... | 808ee767b44a05fb8258a2bef5621d22131e6467 | 20,050 |
from pathlib import Path
def get_file_path(path: Path, fn: str) -> Path:
"""
Find an available path for a file, using an index prefix.
Parameters
----------
path: Path
file path
fn: str
filename
Returns
----------
path
file path
"""
paths = path.gl... | 54182f627cded53f5f6dabb5b32965bd1693a4ac | 20,058 |
import logging
def get_logger(name=None):
"""Return a logger to use.
Parameters
----------
name : None or str, optional
Name of the logger. Defaults to None.
Returns
-------
logging.Logger
logger object.
"""
return logging.getLogger("bids-schema" + (".%s" % name i... | e1bf5e385615a26391b5121752300e53d8e288d5 | 20,063 |
def _binary_search(array, elt):
"""Modified binary search on an array."""
start = 0
end = len(array) - 1
while start <= end:
mid = (start + end) // 2
if elt == array[mid]:
return mid + 1
if elt < array[mid]:
end = mid - 1
else:
start =... | 857e7d0d32522b11f30027eff4294efd6b5f5ac0 | 20,064 |
def dynamic_filter(func):
"""Function decorator that sets the wrapped function's 'dynamic_filter'
attribute to True.
"""
func.dynamic_filter = True
return func | a59cae5d20c367a1966cb35ca1c5b80ccd9d895a | 20,068 |
def actual_svg(pathname: str) -> str:
"""Read SVG image from disk."""
with open(pathname, "r") as file:
svg = file.read()
return svg | ba7ae52d3bdbae1d3112a183de2f484f4bcc066d | 20,073 |
def squash_flags(flags):
"""Remove lowercase flags if the respective uppercase flag exists
>>> squash_flags('abc')
'abc'
>>> squash_flags('abcC')
'ab'
>>> squash_flags('CabcAd')
'bd'
"""
exclude = ''.join(f.upper() + f.lower() for f in flags if f == f.upper())
return ''.join(f f... | 1484a7f4b1764e1c48dc4eb07e15db98a7bb9881 | 20,075 |
def empty_stack(stack, graph):
"""
Pops the items in the stack. If they have no head, they are assigned
a ROOT head
:param stack:
:param graph:
:return:
"""
for word in stack:
if word['id'] not in graph['heads']:
graph['heads'][word['id']] = '0'
graph['dep... | 323a841f359d3a9823bd6e43d3de7540b3f2a6df | 20,084 |
import logging
def render_disassembly(dis, match_offset, match_len, context_lines=4):
"""
Accepts a DecodeGenerator from distorm and returns a string that will be directly rendered in the ICE yara results page
dis: DecodeGenerator from distorm.Decode()
match_offset: offset into the file where the matc... | ce719252bae1f5833e788922832cf11207f63deb | 20,088 |
from typing import Counter
from typing import Tuple
from typing import List
def order_counts(counts: Counter[Tuple[int, ...]]) -> List[int]:
"""
Helper method for organising two-qubit correlations.
:param counts: Counter object as returned by BackendResult, giving two qubit counts for desired correlation
... | 7c538da5655d00da4399e0b33ededf4c86978848 | 20,091 |
def boundary_substraction(
*,
boundary: tuple[tuple[int, ...], ...],
subtracted: tuple[tuple[int, ...], ...],
) -> tuple[tuple[int, ...], ...]:
"""From a boundary composed of tuples of node number segments, subtracts the subset
of those segments contained in the subtracted tuple.
Arguments:
... | 67047475ddff113c8b34637cb4686fb37b8377ee | 20,093 |
from datetime import datetime
def get_daily_filename(date: datetime = datetime.today()) -> str:
"""Returns the filename for the given date in the format:
'yyyy-mm-dd-nnn-day.md'
:param date [datetime.datetime] : Date for filename, defaults to datetime.today().
:return (str) : Filename
"""
iso... | 0e954aec6de6914842417315b43a36ecbca9acdf | 20,094 |
def get_num_pages(page_souped):
"""
This gets the number of pages to search through.
:param page_souped: <class 'bs4.BeautifulSoup'>, a page that has been passed through BeautifulSoup().
:return: int, the number of pages to search through
"""
span_parsed = page_souped.find_all(lambda tag: t... | 6930feb28b8a264433cbce93ed573b0c6172250b | 20,096 |
def copy_worksheet(workbook, worksheet):
"""
Creates a copy of the worksheet.
:param workbook: The workbook the worksheet is from.
:param worksheet: Worksheet to copy.
:return: A copy of the worksheet.
"""
return workbook.copy_worksheet(worksheet) | d650f9f056c1fa951dc1de28c362015726798f26 | 20,105 |
def get_answer(current_row):
"""Returns the answer text value og HTML element"""
return current_row.find_all("td", class_="risp")[0].text.strip() | 14e91c250d6f28b98534fe7839e47b3650750152 | 20,106 |
def _split_scene(images, cameras, top_down, captions):
"""Splits scene into query and target.
Args:
images: A tensor containing images.
cameras: A tensor containing cameras.
top_down: A tensor containing the scene seen from top.
captions: A tensor containing captions.
Returns:
A tuple query,... | cb1aa58dcd3f3bd33f113fef7b38399effa484a7 | 20,108 |
import requests
from pathlib import Path
def download_url(url,download_path):
"""
Download an url
url: url to download
download_path: path where to save the downloaded url
"""
r = requests.get(url, stream = True)
if not Path(download_path).exists():
print("Downloading fil... | 2d95aeb5dbad228fa8a09279b5084f750c5b4362 | 20,110 |
def truncate(message, from_start, from_end=None):
"""
Truncate the string *message* until at max *from_start* characters and
insert an ellipsis (`...`) in place of the additional content. If *from_end*
is specified, the same will be applied to the end of the string.
"""
if len(message) <= (from_start + (fr... | 44e37164aff5912d37a3dc27217e498b1c14efff | 20,112 |
def get_key_padding_mask(padded_input, pad_idx):
"""Creates a binary mask to prevent attention to padded locations.
Arguements
----------
padded_input: int
Padded input.
pad_idx:
idx for padding element.
Example
-------
>>> a = torch.LongTensor([[1,1,0], [2,3,0], [4,5,0... | 234d5f947b7042c5edad68e9b8162e4bbf6963f3 | 20,113 |
from typing import Iterable
import torch
from typing import Dict
from typing import List
def cluster_strings(strings: Iterable[str]) -> torch.Tensor:
"""
given a list of strings, assigns a clustering, where
each pair of identical ground truth strings is in the same
cluster
return a torch.LongTenso... | 7821fa946e7a07be13411f54913ee71f1e67dc3a | 20,116 |
def format_conditions(**kwargs):
"""Converts an arbitrary number of lists to a list of dictionaries. Useful
for specifying the conditions in pmutt.io.chemkin.write_EA
Parameters
----------
kwargs - keyword arguments
Lists of the conditions where each index corresponds to a run
R... | a7ee7dcb6abff418c9795c9a1e604cab2bfbbe19 | 20,118 |
def prefix(values, content):
"""
Discover start and separate from content.
:param list[str] values:
Will scan through up to the one ``content`` starts with.
:param str content:
The value to scan, will separate from the start if found.
:raises:
:class:`ValueError` if no sta... | 2bce07c6a33925434768e339e27ad44bbe543a26 | 20,125 |
from typing import List
def get_row(row: List[str], cells_per_row: int, cell_tag: str):
"""
:param row: list of cell contents
:param cells_per_row: how many cells per row
:param cell_tag: tag name for the cell, td and th being the possibilities known.
:return: html describing the row
"""
h... | cb919c311af3314e2c1eb25bb0949c836312f96c | 20,129 |
def gen(symbol, s1, s2, s3):
"""
Generate one quaternary formula.
:param symbol: Mask object
:param s1: Mask object
:param s2: Mask object
:param s3: Mask object
"""
result = '(' + symbol.outer
for s in [s1, s2, s3]:
result += ','
if len(s.outer) == 0:
re... | a3817b32521d420caa90f0b3c6511395030e48a9 | 20,131 |
def comp(z1, z2, tol):
"""Return a bool indicating whether the error between z1 and z2 is <= tol.
If z2 is non-zero and ``|z1| > 1`` the error is normalized by ``|z1|``, so
if you want the absolute error, call this as ``comp(z1 - z2, 0, tol)``.
"""
if not z1:
z1, z2 = z2, z1
if not z1:
... | 6c51adbae99f9d642b7e46010c96b3b1cf8ba44d | 20,135 |
def _as_dict(module):
"""
Returns publicly names values in module's __dict__.
"""
try:
return {k: v for k, v in module.__dict__.iteritems() if not k[0:1] == '_'}
except AttributeError:
return {} | 5904d111040219f7f4b4c2f82e4d9f86cbe1c401 | 20,137 |
from typing import List
def keys_remove_dollar_suffixes(keys : List[str]) -> List[str]:
"""Removes dollar suffixes from keys."""
result = []
for key in keys:
i = key.find("$")
if i != -1:
result.append(key[:i])
else:
result.append(key)
return result | 355f521b04fd00a27130bf714559208b062fe79a | 20,150 |
def _get_or_create_personal_context(user):
"""Get or create personal context for user"""
personal_context = user.get_or_create_object_context(
context=1,
name='Personal Context for {0}'.format(user.id),
description='')
return personal_context | 6dc3cce9a0073db480608d1766e4892dfa66e310 | 20,152 |
import numbers
def all_numeric(data):
"""
Tests if all values in an iterable are numeric.
Args:
data: An iterable claiming to contain numbers
Returns:
A list containing a boolean indicating whether all of the
values were numbers and then a list of the genuine numeric values
... | b7ed6f5c37cb5cf41a3c5a337e686a4144d531dc | 20,157 |
def create_names(instances, Ns, str_format):
"""
Create a list of names for spectra loaded from task instances.
:param instances:
A list of task instances where spectra were loaded. This should
be length `N` long.
:param Ns:
A list containing the number of spectra loaded fr... | f7d734e712769d86c3ca31483790c6a1e46c3962 | 20,160 |
def fluid_saturation(vol_fluid=50, vol_pore=100):
"""Returns the fluid saturation given the fluid volume and pore volume."""
return float(vol_fluid/vol_pore) | 30d608e384076ae94626a7f4351e58fe3d0e05bc | 20,163 |
def get_signed_polygon_area(points):
"""
Get area 2d polygon
:param points: list[DB.UV]
:type points: list[DB.UV]
:return: Area
:rtype: float
"""
area = 0
j = points[len(points) - 1]
for i in points:
area += (j.U + i.U) * (j.V - i.V)
j = i
return area / 2 | 960d5a3e5bff125fb560580f81b5103fa8147789 | 20,174 |
def sec_to_exposure_decimation(sec):
"""
Convert seconds to exposure and decimation.
The algorithm is limited since it multiplies decimation by 10 until the
resulting exposure is less than 65_535. This is not perfect because it
limits decimation to 10_000 (the next step would be 100_000 which is
... | c880a371bc3aa9420de094df4815a876bb504b33 | 20,176 |
def color_int_to_rgb(value: int) -> tuple[int, int, int]:
"""Return an RGB tuple from an integer."""
return (value >> 16, (value >> 8) & 0xFF, value & 0xFF) | ff68ff63032470d09c9222a7883b7c8848770985 | 20,178 |
def generate_fibonacci_series(n):
"""Generate fibonacci series from 0 to nth term
args:
n->nth term of fibonnaci series
Returns:
A list of numbers of fibpnacci series to the nth term
"""
n1 = 0
n2 = 1
count = 0
fibonacci_series = []
if not isinstance(n, int):... | 8796ff1bc97a944b644ee7fe869e4b2407b6994e | 20,192 |
def generate_catalog_mags(instrument_mags, color, model):
"""
Generate catalog magnitudes from instrumental magnitudes
given a model that relates the two.
"""
return instrument_mags + model(color) | 0b39a7dae5eb1f573c62b25b7053acebf28e91d2 | 20,194 |
from typing import List
def generateBasisIndexList(basisStrList: List[str], sysLevel: int) -> List[int]:
"""
Return a list of integers which indicates the basis indices according to the input basis string list.
For example, ``generateBasisIndexList(['00', '01', '10', '11'], 3)`` will return:
``[0, 1, ... | aa11cd27a134b5ec432e957578908a64e2c1cc9e | 20,197 |
def get_urn_from_raw_update(raw_string):
"""
Return the URN of a raw group update
Example: urn:li:fs_miniProfile:<id>
Example: urn:li:fs_updateV2:(<urn>,GROUP_FEED,EMPTY,DEFAULT,false)
"""
return raw_string.split("(")[1].split(",")[0] | fa96086f79462354f70a19e4475da9e62a3e0046 | 20,198 |
def close_window(driver, w):
"""Close the window associated with the given window handle."""
driver.switch_to.window(w)
return driver.close() | f0b8cc5abd6703f5a1a056ffb24925d1d4e2c8e0 | 20,202 |
def disable(f):
"""Mark a test as disabled."""
f.__test__ = False
return f | afd3851496472d65748ea67a1f3e4860f379451c | 20,206 |
from typing import List
from typing import Tuple
def tuple_zip(list1: List, list2: List) -> List[Tuple]:
"""Creates tuples of elements having same indices from two lists.
doctests:
>>> tuple_zip([1, 2], ['x', 'y'])
[(1, 'x'), (2, 'y')]
>>> tuple_zip([1, 2, 3, 4], ['a', 'b', 'c', 'd'])
[(1, 'a... | dbd3a162dc55ea70122483591c82c187fe4f1411 | 20,212 |
def NoneSafeType(_type):
"""
A hack for a "None-safe" typecaster. Given a type, it casts all
values to that type as the type would, except that None is always
cast to None.
"""
def caster(value):
if value is None:
return None
else:
return _type(value)
... | d8b763ec10ba16faf151dc20acf68fcb35286197 | 20,213 |
def isTruthy(value):
"""Converts any value to a boolean value; just uses the 'bool' built-in function,
except that strings like 'FALSE', 'false' and 'False', and strings that are
numeric values equal to 0, return False.
"""
if str(value).lower() == 'false':
return False
try:
... | bfc7b3547c77f1d8642c0078c80740d632813b45 | 20,225 |
def p2a(p, m1, m2):
"""
It computes the separation (Rsun) given m1 (Msun), m2 (Msun) and p (days).
"""
yeardy=365.24
AURsun=214.95
p = p/yeardy
a = AURsun*(p*p*(m1 + m2))**(1./3.)
return a | a0c5d8c0d7b961e8017217f22f54aa2a70daf5a0 | 20,231 |
def calculate_bootstrap(bootstrap_size, length):
"""
Calculate the bootstrap size for the data of given length.
Parameters
----------
bootstrap_size : int, float, default=None
Bootstrap size for training. Must be one of:
- int : Use `bootstrap_size`.
- float : Use `bootstrap_size * n_samples`.
- None :... | f6d0856322ac43638fd75b94838f9b04a6acabd1 | 20,235 |
def totM(m1, m2):
"""The total mass shows up in Kepler formulae, m1+m2
"""
return( m1+m2 ) | 1be75e653582e7f9eaafaf07d1f946735eb6f66e | 20,241 |
from pathlib import Path
def tmp_dir(tmp_path) -> Path:
"""
Returns `Path` to the temporary directory.
If It not exists - creates and returns it.
"""
dir_path = tmp_path / "tmp_dir"
if not dir_path.exists():
dir_path.mkdir()
return dir_path | 39c61278f942cc9cbfd531bf3e7be296ca012d77 | 20,247 |
def generate_batch_spec(mode, batch_size):
""" Generates a spec describing how to draw batches
Args:
mode: one of ['train', 'test', 'val']
"""
assert mode in ['train', 'test', 'val']
# on a more complicated dataset this would include useful arguments
# such as whether to augment the data... | 232991fc65e037f5c860f8ca9dc2fa832b7062e8 | 20,250 |
def get_star_column_number(line):
""" For a line in a star file describing a column entry (e.g., '_rlnEstimatedResolution #5'), retrieve the value of that column (e.g. 5)
"""
column_num = int(line.split()[1].replace("#",""))
return column_num | 3cd4e981b1486167fdad0e6cbfeb5b36e88c4a1a | 20,251 |
from typing import Iterable
from typing import List
def flatten_lists(list_of_lists:Iterable) -> List:
""" Flatten a list of iterables into a single list
This function does not further flatten inner iterables.
Parameters
----------
list_of_lists : typing.Iterable
The iterable to flat... | 5ba8f5add9f8f1fd7fad50fbaea765655b183718 | 20,253 |
def _convert_float32_to_float64(data):
"""
Converts DataArray values of float32 to float64
:param data: Xarray dataset of coverage data
:returns: Xarray dataset of coverage data
"""
for var_name in data.variables:
if data[var_name].dtype == 'float32':
og_att... | 1a66c6de0de7ff2c79d7e03c017b79b78cb43639 | 20,256 |
def _pisano_period_len(modulo):
"""
In number theory, the nth Pisano period, written π(n),
is the period with which the sequence of Fibonacci numbers taken modulo n repeats.
Args:
modulo: modulo
Returns:
length of Pisano period
"""
init_array = [0, 1]
idx = 1
while ... | 776db9e0e8fd2af28159b9616018ff000dd55154 | 20,265 |
def potency_tensor(normal, slip):
"""
Given a fault unit normal and a slip vector, return a symmetric potency
tensor as volume components (W11, W22, W33), and shear components
(W23, W31, W12).
"""
v = [
normal[0] * slip[0],
normal[1] * slip[1],
normal[2] * slip[2],
]
... | 87c1a08d74e8e2dfdd51f32a19ee44dd543a4c4c | 20,266 |
def extract_doi_suffix(protocol_doi):
"""
DOIs come in a format like 'dx.doi.org/10.17504/protocols.io.bazhif36'.
We just need the 'protocols.io.bazhif36' element to form our query url.
"""
return protocol_doi.split("/")[2] | 9dbb9d44b9159bd9b3168169e17c6a0d66fe95d8 | 20,268 |
import re
def fenced_bootstrap(block):
"""Set up a fenced block for bootstrap prettify highlighting."""
pattern = re.compile(r'```(?P<lang>\w+)?(?P<code>.*?)```', re.MULTILINE|re.DOTALL)
match = pattern.match(block)
if not match:
return block
lang = match.groupdict().get('lang', None)
... | 34140706556e0aa4fa80b946eb2f4fbbb3018d02 | 20,270 |
def find_token_by_position(tokens, row, column):
"""Given a list of tokens, a specific row (linenumber) and column,
a two-tuple is returned that includes the token
found at that position as well as its list index.
If no such token can be found, ``None, None`` is returned.
"""
for index, tok in ... | d5493b596761bc7620aac2f54c0ccd9cc8982d7b | 20,271 |
def read_txt_file(file_name):
"""Read the content of a text file with name `file_name` and return content as a list of lines"""
with open(file_name, 'r') as file:
lines = file.readlines()
return lines | 0231bd41327ae9c082502d9cf5c712978d88df26 | 20,272 |
from typing import List
import math
def chunks(arr, m) -> List[list]:
"""分割列表,但是子list元素个数尽可能平均
Args:
arr: 待分割的list
m: 分成几份
Returns:
分割后的每个子list都是返回结果list的一个元素
"""
n = int(math.ceil(len(arr) / float(m)))
return [arr[i : i + n] for i in range(0, len(arr), n)] | 040b75647fcdd72cac561bb43019c50c64dec51d | 20,279 |
import torch
def flatten_parameters_wg(model):
"""
Flattens parameters of a model but retains the gradient
:return: 1D torch tensor with size N, with N the model paramters
"""
return torch.cat([p.view(-1) for p in model.parameters()]) | 1bdf6779099e37dce5179ce1fe5e63472ea72fbf | 20,280 |
def rpc_plugins_list(handler):
"""
Return information regarding enabled plugins in the server.
:return: A dictionary representing enabled plugins and their meta-data.
:rtype: dict
"""
plugin_manager = handler.server.plugin_manager
plugins = {}
for _, plugin in plugin_manager:
plugins[plugin.name] = {
'des... | d534e3ba9379947821fc2a49b0439b4a4269d9ff | 20,289 |
def list_instruments(snap):
"""
List instruments from a snapshot
"""
return (list(snap['station']['instruments'].keys()) +
list(snap['station']['components'].keys())) | a4abe5bc9884d80b014bbf6eb4688349114ed664 | 20,291 |
def insertion_sort(some_list):
"""
https://en.wikipedia.org/wiki/Insertion_sort
Split the array into a "sorted" and "unsorted" portion. As we go through the unsorted portion we will backtrack
through the sorted portion to INSERT the element-under-inspection into the correct slot.
O(N^2)
"""
... | ce5be31c03aa925f567c9880cd81281cf3c5af96 | 20,292 |
def Nop(x):
"""empty function for tree traversal"""
return True | 120feb2ba4e1eaa291eb8db4a5586bfd8478f8f2 | 20,294 |
def doNothing(rawSolutions):
"""
Contrary to its name, this function returns its input argument in a list structure, whose sole element is said input argument.
"""
return [rawSolutions] | 8a59f34dba4bcd00a0d69eb2875d8b5407fb737f | 20,297 |
from typing import Dict
from typing import Any
from typing import List
def validate_required_keys_for_add_asset(valid_json: Dict[str, Any], required_keys: List[str]) -> bool:
"""
Check if the required keys for adding an asset are present or not
:param valid_json: The valid input asset JSON
:param req... | e6dd5fe20891af30fa997e19b8c08716340fe7b5 | 20,298 |
def create_user(txn, email, password):
"""Creates a user node."""
query = """
MERGE (a:User {email: $email,
password: $password})
"""
return txn.run(
query,
email=email,
password=password) | 0ce6800de8ea4be5891ae38017bcc6b1e97e7ddd | 20,313 |
from datetime import datetime
def isday(yyyymmdd):
"""Is the yyyymmdd formatted as 'YYYY-MM-DD' such as '2020-03-18'"""
try:
datetime.strptime(yyyymmdd, '%Y-%m-%d')
return True
except ValueError:
return False | 9ec31aa0cc4d924d5ae0df2510fb6258df6668a2 | 20,315 |
import re
def parse_variable_declaration(srcline):
"""Return (name, decl) for the given declaration line."""
# XXX possible false negatives...
decl, sep, _ = srcline.partition('=')
if not sep:
if not srcline.endswith(';'):
return None, None
decl = decl.strip(';')
decl =... | ce84f493845fe7a8d72b62bfb69a34ee25114e18 | 20,318 |
def get_exception_name(node):
"""
Find the name of an exception
Args:
node: Parso node containing the raises statement
Returns:
str: The exception name
"""
name = node.children[1]
while not name.type == 'name':
name = name.children[0]
return name.value | 0ab7841a4a1044c990fc8d8490d2ff040bd45d05 | 20,321 |
def calculate_depth_loss(est_depths, gt_depths, loss_type="l1"):
"""Calculate loss between estimated depthmap and GT depthmap
Args:
est_depths: [B,1,H,W]
gt_depths: [B,1,H,W]
loss_type: Choose loss type from ['l1','l2']
"""
assert est_depths.dim() == gt_depths.dim(), "inconsiste... | fbe65b8c9f5e8546e0f633f07b65e22be84df67d | 20,324 |
def _intersect_point2_circle(P, C):
"""
Returns True if point P lies with circle C.
@type P : Point2 instance
@type C : Circle instance
"""
return abs(P - C.c) <= C.r | 58522af7eed88e90c6377be5393da82d8ff99529 | 20,329 |
def reshape_pivot(df_in):
"""
Reduce df to crucial subset then pivot on cases and genes.
"""
df = (df_in[['case_barcode', 'Hugo_Symbol', 'mutation_count']]
.copy()
.pivot(index='case_barcode', columns='Hugo_Symbol', values='mutation_count')
.fillna(0)
... | 1f95f1bb496f2a3734cb32d10f748c4ccb936cbc | 20,332 |
from datetime import datetime
from dateutil import tz
def date_iso(date):
"""Convert a datetime string into ISO 8601 format.
HTML date format agrees with ISO 8601 (see also, :RFC:`3339`), ie::
YYYY[-MM[-DD]][Thh[:mm[:ss[.s]]]T]
For more information:
* `Date and Time Formats:
<https:/... | 0fa1e5ee9087caeaea302e6dc4bfe70262c9507a | 20,334 |
def kill_process(device, process="tcpdump"):
"""Kill any active process
:param device: lan or wan
:type device: Object
:param process: process to kill, defaults to tcpdump
:type process: String, Optional
:return: Console ouput of sync sendline command after kill process
:rtype: string
"... | 8b892b79c07feff586ddd0576cc18ab92551c322 | 20,336 |
import json
def read_test_file(path):
"""Read a test file.
Parameters
----------
path : str
The path to a test file.
Returns
-------
typing.Tuple[str, typing.List[str]]
"""
with open(path) as f:
dct = json.load(f)
return dct['text'], dct['sentences'] | a416a4031ff355134004dde233d741899a35b28b | 20,339 |
def make_xml_name(attr_name):
""" Convert an attribute name to its XML equivalent by replacing
all '_' with '-'. CamelCase names are retained as such.
:param str attr_name: Name of the attribute
:returns: Attribute name in XML format.
"""
return attr_name.replace('_', '-') | f1463c4592edd40c20f030cbd9add83a3cf93577 | 20,342 |
import typing
def query_bt_info(
start: typing.Dict[str, typing.Any],
composition_key: str,
wavelength_key: str,
default_composition: str = "Ni"
) -> dict:
"""Query the necessary information for the PDFGetter."""
if composition_key in start:
composition = start[composition_key]
... | 520f006a9fdf479089230f6af123b2a9e8838de9 | 20,343 |
def other(player):
""" Returns the given player's opponent.
"""
if player == 'X':
return 'O'
return 'X' | e23ed765c5331ae47d284e71835b6c0897612b5c | 20,345 |
def get_module(module_name: str):
"""
Retrieves a module.
"""
try:
# import importlib
# module = importlib.import_module(module_name)
# requiring parameter `fromlist` to get specified module
module = __import__(module_name, fromlist=[''])
return module
except ... | 76d9ebd5b7a8a2450f4a740720152f85bf56ef76 | 20,346 |
import re
def check_package_name(package_name):
"""Check that package name matches convention
Args:
package_name: The package name to validate
Returns:
A boolean determining whether the package name is valid or not
"""
m = re.match('[a-z0-9_]{3,30}', package_name)
return (m != None and m.group(0... | 28d22f69d3926152aabbb835ada8bb8d31553a01 | 20,347 |
import random
def gen_ipaddr(ip3=False, ipv6=False, prefix=()):
"""Generate a random IP address.
You can also specify an IP address prefix if you are interested in
local network address generation, etc.
:param bool ip3: Whether to generate a 3 or 4 group IP.
:param bool ipv6: Whether to generate... | 173551883ab17f033f043dbbf5fe7f2c8e87c2ff | 20,349 |
def determine_layers_below_above(layers, values, elevation):
"""Determine the layers below and above the current elevation
Args:
layers [<str>]: All the pressure layers to load for each parameter
values [<LayerInfo>]: All the interpolated layers information
elevation <float>: The elevat... | bc0b0846037fd9a415c091264213684ee088174c | 20,357 |
def get_suffix_side(node, matcher):
"""Check if (not) adding char node to right syllable would cause creating word suffix.
Return 1 if char node should be added to right,
-1 if to left,
0 if cannot determine."""
if node.next.syllable is None or node.next.syllable.is_last() is False:
return 0... | c46ed8605c0eef77059804802e7151b75b0388b0 | 20,358 |
def _sanitize_git_config_value(value: str) -> str:
"""Remove quotation marks and whitespaces surrounding a config value."""
return value.strip(" \n\t\"'") | 8945955e6ac4811a637d9df6eac0f7f29a5e55eb | 20,360 |
def is_urn(s: str):
"""Test if is uuid string in urn format"""
return type(s) == str and s.startswith("urn:uuid:") | 7f5bbf7dad8e86a687230c29a50f3218198a8286 | 20,366 |
def get_snirf_measurement_data(snirf):
"""Returns the acquired measurement data in the SNIRF file."""
return snirf["nirs"]["data1"]["dataTimeSeries"][:] | 2781c241aac66167e94f6873492d62a200081688 | 20,372 |
import json
def parse_sw(sw_file):
""" Parse stopword config. """
with open(sw_file, "r", encoding="utf-8") as sw_stream:
sw = json.load(sw_stream)
assert isinstance(sw["wordlist"], list)
for word in sw["wordlist"]:
assert isinstance(word, str)
stopword = sw["wordlist"]
retur... | 8dc46a61c195f0ff47bbc825dd816c780ef6f0b5 | 20,373 |
def num_ints(lst):
"""
Returns: the number of ints in the list
Example: num_ints([1,2.0,True]) returns 1
Parameter lst: the list to count
Precondition: lst is a list of any mix of types
"""
result = 0 # Accumulator
for x in lst:
if type(x) == int:
result = resul... | cba6c06bc1618dae1b7a6f515e7f9b42ca88187b | 20,375 |
def without_keys(d: dict, *rm_keys):
"""Returns copy of dictionary with each key in rm_keys removed"""
return {k: v for k, v in d.items() if k not in rm_keys} | 256597224426708c38369ba635b4fa1df15591be | 20,377 |
def retry_if(predicate):
"""
Create a predicate compatible with ``with_retry``
which will retry if the raised exception satisfies the given predicate.
:param predicate: A one-argument callable which will be called with the
raised exception instance only. It should return ``True`` if a retry
... | e02401ba7eb9af88565e06c0013135bfcf711521 | 20,379 |
def next_pow2(n):
""" Return first power of 2 >= n.
>>> next_pow2(3)
4
>>> next_pow2(8)
8
>>> next_pow2(0)
1
>>> next_pow2(1)
1
"""
if n <= 0:
return 1
n2 = 1 << int(n).bit_length()
if n2 >> 1 == n:
return n
else:
return n2 | a94ee5064ae2f3540b65b03b85ab82290c26addd | 20,388 |
def merge_annotations(interaction_dataframe, columns):
"""Merges the annotations for a protein-protein interaction.
Given two columns of a protein-protein interaction dataframe, each of
which contains a type of annotation data, this function returns the merged
set of those annotations.
E.g. Column... | e5dcacc645e1110c1515f5630cd9197a8b7656bd | 20,389 |
import math
def angle_between(pos1, pos2):
""" Computes the angle between two positions. """
diff = pos2 - pos1
# return np.arctan2(diff[1], diff[0])
return math.atan2(diff[1], diff[0]) | ee69333fbd188fe977ac64f91275962b34246ed4 | 20,394 |
def not_none(elem):
"""Check if an element is not None."""
return elem is not None | f91a28efc42e3d50515bb783d3f16a64cdcf9490 | 20,398 |
def format_weather_header_for_HELP(itype, iunits, city, lat=None):
"""
Prepare the header for the precipitation, air temperature and
global solar radiation input weather datafile for HELP. The format of the
header is defined in the subroutine READIN of the HELP Fortran source code.
"""
fheader =... | 7d848481b7316cef4094c2d24b9978665a1c2e1d | 20,399 |
def wilight_to_hass_hue(value):
"""Convert wilight hue 1..255 to hass 0..360 scale."""
return min(360, round((value * 360) / 255, 3)) | 5a9021185f7bbb9bf1351b2df55207063ee49f9a | 20,407 |
def convert_triggers(events, return_event_ids=False):
"""Function to convert triggers to failed and successful inhibition.
Trigger codes:
stop_signal: 11,
go: 10,
response: 1,
stop_signal_only: 12,
failed_inhibition_response: 2,
failed_inhibition: 37,
successful_inhibition: 35
... | 69eca81afe81c4f161ee69e3a02f2e5706c1c5ee | 20,408 |
import random
def intRndPct(n, pct=20):
"""
Randomize an integer
Parameters
----------
n : int
pct : int, optional
Randomization factor in %. The default is 20.
Returns
-------
int
Randomized integer
"""
return int(n * (100.0 + random.uniform(-pct, pct)) ... | 5ef784b83d7e9e5c033932ec41d5426b775ece35 | 20,410 |
def user_index_by_id(slack_id, users):
"""
Returns index of user in users list, based on it's Slack id
:param slack_id:
:param users:
:return: Index in users or False
"""
found_users = [user for user in users if user['id'] == slack_id]
if len(found_users) == 0:
#... | ec5fb9b382f71f1df4fa7778285679307c634c39 | 20,413 |
from pathlib import Path
import json
def load_json(path: Path):
"""
Loads authentification keys/tokens.
:param path: JSON file to load the keys from
:return: Dictionary containing the key-file information
"""
with open(path, mode='r', encoding='utf8') as file:
return json.load(file) | e7368431970682451669603098d56c1c991750a5 | 20,416 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.