content stringlengths 35 416k | sha1 stringlengths 40 40 | id int64 0 710k |
|---|---|---|
import argparse
def parse_args():
"""Process input arguments"""
parser = argparse.ArgumentParser(description=__doc__,
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('functional', metavar='F',
help="Functionally anno... | 5e80c5baf4591cdc2d9f1219d4a5235f151d7f28 | 41,641 |
def get_default_query_ids(source_id, model):
"""
Returns set of Strings, representing source_id's default queries
Keyword Parameters:
source_id -- String, representing API ID of the selection source
model -- Dict, representing current DWSupport configuration
>>> from copy import deepcopy
... | 766b69d32433d586dc086eec7ee1c27c312b7724 | 41,644 |
def celsius_to_kelvin(temperature):
"""Convert from Celsius to Kelvin
:param temperature: degree understood to be in Celsius
NOTE:
Celsius to Kelvin formula: K = °C + 273.15
Add 273.15.
"""
return temperature + 273.15 | 5ddca76af51ef4199c1c6e1568c938c69bcea2d1 | 41,645 |
def constant_series(z):
"""
returns 1 + z + z ** 2 + ...
"""
return 1 / (1 - z) | d1dcf5f45068f2b5b24bbef35e71b2c1d329a743 | 41,646 |
def multiplica(x, y, z=None):
"""Multiplica x,y,z
Multiplica x, y, z,. O programador pode omitir a variavel z caso nao tenho
necessidade de usa-la
:param x: float
:param y: float
:param z: float
:return: float
"""
if not z:
return x * y * z
else:
return x * y | c7ed1bb7c259b27e4a1c802db9b85eaefc9555fd | 41,648 |
import aiohttp
from typing import List
from typing import Tuple
async def get_html_blog(
session: aiohttp.ClientSession,
url: str,
contests: List[int],
) -> Tuple[str, str, List[int]]:
"""Get html from a blog url.
Args:
session (aiohttp.ClientSession) : session
url (str) : blog u... | 1e0a0a573f1733370a1a59f37ca39a5cd0a5bb9c | 41,650 |
def query_string_to_kwargs(query_string: str) -> dict:
"""
Converts URL query string to keyword arguments.
Args:
query_string (str): URL query string
Returns:
dict: Generated keyword arguments
"""
key_value_pairs = query_string[1:].split("&")
output = {}
for key_value_p... | 9382d1c12cc2a534d9edbf183a3fcd3ea7b38968 | 41,651 |
import collections
def group_transcripts_by_name2(tx_iter):
"""Takes a iterable of GenePredTranscript objects and groups them by name2"""
r = collections.defaultdict(list)
for tx in tx_iter:
r[tx.name2].append(tx)
return r | a2fce0dfa8ba5e0b7321e977d1dbc8455ab6dfd1 | 41,653 |
def run_operation(task):
"""Run a particular task, simulating some failures on its execution."""
return task.run() | cbb7c33b6ee71356a7f609f02a3ed529af4942b4 | 41,654 |
def get_var_mode(prefix):
"""Returns False if { in prefix.
``prefix`` -- Prefix for the completion
Variable completion can be done in two ways and completion
depends on which way variable is written. Possible variable
complations are: $ and ${}. In last cursor is between
curly braces.
"""
... | ab080ae0ea2bce0ce2b267a2e7be839a6a982fb2 | 41,655 |
def lol2str(doc):
"""Transforms a document in the list-of-lists format into
a block of text (str type)."""
return " ".join([word for sent in doc for word in sent]) | 61f58f715f1a923c368fb0643a1cf4d7eddefb73 | 41,657 |
def mrr_voltage_to_delta_lambda(v, alpha, k, gamma, n_g, lambda_0):
"""
description: micro-ring resonator (MRR) wavelength modulation, \delta\lambda=\delta\n_eff\times\lambda/n_g, \deltan_eff=\gamma k \delta T=\gamma k \alpha v^2\\
v {torch.Tensor ro np.ndarray} voltage \\
alpha {scalar} voltage square ... | bff733aec6d6ea88d5239a264cd44e241329a53e | 41,658 |
import textwrap
def _pretty_longstring(defstr, prefix='', wrap_at=65):
"""
Helper function for pretty-printing a long string.
:param defstr: The string to be printed.
:type defstr: str
:return: A nicely formated string representation of the long string.
:rtype: str
"""
outstr = ""
... | 19008289620b86b8760a36829cbaa97d117a8139 | 41,659 |
def kronecker(x, y):
"""
Returns 1 if x==y, and 0 otherwise.
Note that this should really only be used for integer expressions.
"""
if x == y:
return 1
return 0 | d28e9c101f61e04445b4d87d91cc7919e1921714 | 41,661 |
def drop_unadjusted_fields(mapping):
"""Drops all fields beyond mapping[0:12], except for the cigar and alignment type field.
Args:
mapping ([type]): [description]
"""
# print("mapping before drop:", mapping)
# Find the cigar and mapping-type fields.
keep_fields = list()
for field i... | 3716cb16cd77865ab48df918ef448cf8cfe7f400 | 41,662 |
import struct
import os
def get_image_size(data):
"""Determine dimensions from image file data."""
b = data.read(56)
size = len(b)
width = height = 0
if size >= 10 and b[:6] in [b'GIF87a', b'GIF89a']:
width, height = struct.unpack('<hh', b[6:10])
elif size >= 24 and b.startswith(b'\x89PNG') and b[12:16] == ... | f7b9b9a96521251f0bceef9cab21907467661de8 | 41,665 |
from pathlib import Path
import sys
def update_item_image(item_name, slot, items):
"""
This function will update the item image in the item slot selection window.
:param item_name: the name of the item image to update
:param slot: the slot the image for
:param items: the items list
:return: th... | 48a1583e97d86a513358c01fe0ec6d4f2eb78e0d | 41,666 |
import argparse
def argument_setup():
"""Set up the command line argument parser.
Parameters:
None
Returns:
The parsed arguments.
"""
parser = argparse.ArgumentParser()
parser.add_argument("-t", "--type", type=str,
help="File type")
parser.add_argu... | a5973ddd348f5c25b8e1ceb7dc1c424d3d02b7d3 | 41,668 |
def space_join(conllu,sentence_wise=False):
"""Takes conllu input and returns:
All tokens separated by space (if sentence_wise is False), OR
A list of sentences, each a space separated string of tokens
"""
lines = conllu.replace("\r","").strip().split("\n")
lines.append("") # Ensure last blank
just_text = []
... | e3e752906b57090f56c2678031f295c5a8e66f29 | 41,669 |
def cumsum(arr):
""" Cumulative sum. Start at zero. Exclude arr[-1]. """
return [sum(arr[:i]) for i in range(len(arr))] | b629695089e731855b47c8fb3e39be222aeba1db | 41,670 |
def first(it):
"""Get the first element of an iterable."""
return next(iter(it)) | 535f9028d96e0e78bc310b4a8e75e558c9217172 | 41,671 |
def _rkck(y,dydt,t,f,dt,args=()):
"""
Take one 5th-order Cash-Karp Runge-Kutta step.
Returns
-------
array_like
The change in `y` during this step.
array_like
An error estimate for `y`.
"""
a2=0.2;a3=0.3;a4=0.6;a5=1.0;a6=0.875;b21=0.2 # noqa
b31=3.0/40.0;b32=9.0/40.... | 70abfe7b29b03dc92341fce914a3315d4edf8fb6 | 41,672 |
import os
def basename(file_name):
"""
Returns basename of a file without the preceding directory
"""
return os.path.basename(file_name) | fd0786cfe15d4fee27cbb2189a3a6740545c90e3 | 41,673 |
from typing import Dict
import hashlib
import base64
def headers_sdc_artifact_upload(base_header: Dict[str, str], data: str):
"""
Create the right headers for sdc artifact upload.
Args:
base_header (Dict[str, str]): the base header to use
data (str): payload data used to create an md5 con... | 6895fff6d1a26cfb8009a3fedd2dcc9357efbe40 | 41,674 |
def valid_boolean(boolean_as_hopefully_int) -> int:
"""Use this to parse an argument as if it were boolean, and get back an int 0 or 1.
In sqlite a 'boolean' is actually an int which takes the value 1 or 0, with 1 representing True.
Raises ValueError if passed an un-parse-able value.
"""
try:
... | 7f58ff0bd969bcbf07f8c11d07bf939d723504d4 | 41,675 |
def content_disposition_value(file_name):
"""Return the value of a Content-Disposition HTTP header."""
return 'attachment;filename="{}"'.format(file_name.replace('"', '_')) | 9d7f50b95ab409013af39a08d02d6e7395abe545 | 41,676 |
def decode_dataset_id(dataset_id):
"""Decode a dataset ID encoded using `encode_dataset_id()`.
"""
dataset_id = list(dataset_id)
i = 0
while i < len(dataset_id):
if dataset_id[i] == '_':
if dataset_id[i + 1] == '_':
del dataset_id[i + 1]
else:
... | 08b31b17f8bda58379e7541eaedb1d1a128e9777 | 41,679 |
def _add_tag(tags, label: str) -> bool:
"""Adds the tag to the repeated field of tags.
Args:
tags: Repeated field of Tags.
label: Label of the tag to add.
Returns:
True if the tag is added.
"""
for tag in tags:
if tag.label == label:
# Episode already has the tag.
return False
... | 932399e97ae823ef0922929dc5123a587c06b211 | 41,680 |
def get_admin_net(neutron_client):
"""Return admin netowrk.
:param neutron_client: Authenticated neutronclient
:type neutron_client: neutronclient.Client object
:returns: Admin network object
:rtype: dict
"""
for net in neutron_client.list_networks()['networks']:
if net['name'].ends... | bbb96a3da0967e74d9229537ca8afbcbfbd786e8 | 41,681 |
def _partial(middleware, handler):
"""
Custom partial in order to propagate original fn attributes
"""
async def partial(request):
response = await middleware(request, handler=handler)
return response
partial.__name__ = handler.__name__
partial.__module__ = handler.__module__
... | 7f36a03733fa0020c2e2211a007eb47f8b9a3a52 | 41,683 |
import os
def join(iterable):
"""Join iterable's items as a path string
>>> join(('a', 'b')) == os.path.join('a', 'b')
True
"""
items = tuple(iterable)
if not items:
return ''
return os.path.join(*items) | 425eb1bd753e9c1d98d55f32bc31612dc7519449 | 41,684 |
def listener_protocol(protocol):
"""
Property: Listener.Protocol
"""
valid_protocols = ["TCP", "UDP"]
if protocol not in valid_protocols:
raise ValueError('Protocol must be one of: "%s"' % (", ".join(valid_protocols)))
return protocol | 2dd6709f3fb508ece3ebd04e5d129f9201c9687a | 41,685 |
def fitdict(target_keys, input):
"""
Assigns values of the required words in target_keys to
a new list, indexed indentically with sortedKeys()
Meant to be used to assign an object values to the merged
frequency set
"""
list = [0] * len(target_keys)
count = 0
for x in target_keys:
... | 387ab0c856301844e0cad6d4545e1334a8ba7975 | 41,686 |
def binary_search(target,bounds,fn,eps=1e-2):
""" Perform binary search to find the input corresponding to the target output
of a given monotonic function fn up to the eps precision. Requires initial bounds
(lower,upper) on the values of x."""
lb,ub = bounds
i = 0
while ub-lb>eps:
... | be5416bd6cdd53ff5fd8f58c489d7cf036dcd6a6 | 41,687 |
def inverse(x):
"""Returns whatever input as one over the input"""
return 1/x | d53824471643d8a21b5f21a9dd04f8a3a5411cb9 | 41,689 |
from typing import List
def format_learning_rates(learning_rates: List[float]) -> str:
"""
Converts a list of learning rates to a human readable string. Multiple entries are separated by semicolon.
:param learning_rates: An iterable of learning rate values.
:return: An empty string if the argument is ... | 06c7395ba609be49ae57db618fe0e739b247de66 | 41,691 |
def add_buffer_to_intervals(ranges, n_channels, pad_channels=5):
"""Extend interval range on both sides by a number of channels.
Parameters
----------
ranges : list
List of intervals [(low, upp), ...].
n_channels : int
Number of spectral channels.
pad_channels : int
Numb... | 44548e70f0cbdc8d1f3df59ba7402ebc6aae0f41 | 41,692 |
def has_required_vowels(text, no_of_vowels=3):
"""Check if there are the required number of vowels"""
# Set up vowels and vowel count
vowels = 'aeiou'
vowel_count = 0
# count vowels in text until it reaches no_of_vowels,
# at which point, return True, or return False otherwise
for characte... | 395958ac12f6015bec2d6122670d485d41b2d1b8 | 41,695 |
import torch
def _unpack_from_convolution(x, batch_size):
"""
Moves the last dimension to the desired position while preserving ordering of the others.
Parameters
----------
x : :class:`torch.Tensor`
Input tensor of shape ... x n
dim : int
Dimension to move the last location.
... | 8df80e8f6e6037774027fd49f368d16c1a825b55 | 41,698 |
def myfunc():
"""
Demonstrates how to write a doctest.
Prefix with `>>>` and ideally place in an `Example:` block.
You can also change Example, Ignore will
Prefix with `>>>` and ideally place in an `Example:` block.
CommandLine:
# it would be nice if sphinx.ext.napoleon could handle thi... | 9598cc794439bcde8a43f1a8d2a87f402ef42796 | 41,699 |
def update_settings(settings, updates, files):
"""Return updated settings."""
updates = {key: str(files.get(val, val)) for key, val in updates.items()}
for attr, value in updates.items():
setattr(settings, attr, value)
return settings | 7d9ddd6559a1bacc751a58c6f119ef78bb3a0437 | 41,700 |
def image_prepare(image):
"""Clip negative values to 0 to reduce noise and use 0 to 255 integers."""
image[image < 0] = 0
image *= 255 / image.sum()
return image.astype(int) | c244a9a9e613215796b1a72b4576e0e39885d65e | 41,701 |
def parse_value(value):
"""
Tries to convert `value` to a float/int/str, otherwise returns as is.
"""
for convert in (int, float, str):
try:
value = convert(value)
except ValueError:
continue
else:
break
return value | 7bab352a5bbcfe0eb9de19f7252d9d759950b01e | 41,702 |
import os
def get_basename(obj):
"""Get the :func:`~os.path.basename` of a file.
Parameters
----------
obj : :term:`path-like <path-like object>` or :term:`file-like <file object>`
The object to get the :func:`~os.path.basename` of. If the object does not
support the :func:`~os.path.b... | 679794de917dd27f0f7f5c75372c845e708956de | 41,703 |
def flatten(xs):
"""Flatten a 2D list"""
return [x for y in xs for x in y] | 5b3fc103f699cbb0ef56f0457f482f35d0c3e4af | 41,707 |
def _encoding_base_info(base_info):
"""
Encoding base info
Args:
base_info(dict): base info
"""
encoded_info = list()
for symbol, base in base_info.iteritems():
item = {
'symbol': symbol,
'base': base
}
encoded_info.append(item)
return... | e4a56a6063e06f858811c278468cc8cd19055d07 | 41,709 |
def caption_fmt(caption):
""" Format a caption """
if caption:
return "\n== {} ==\n".format(caption)
return "" | e6e94efa5f16f9b0590e912e68ee1e3acfb4d54a | 41,712 |
def rgbi2rgbf(rgbf):
"""Converts a RGB/integer color into a RGB/float.
"""
return (int(rgbf[0]*255.0), int(rgbf[1]*255.0), int(rgbf[2]*255.0)) | eca27cee4f43653f42b96c84c72a5332927e1dc0 | 41,713 |
def node_count(shape):
"""Total number of nodes.
The total number of nodes in a structured grid with dimensions given
by the tuple, *shape*. Where *shape* is the number of node rows and
node columns.
>>> from landlab.utils.structured_grid import node_count
>>> node_count((3, 4))
12
"""... | f3f460967346afbb25098db6ebb7ea8db45e2870 | 41,715 |
def serialize(f):
"""
Turn the abstract syntax tree into tidy data (i.e. one row per record).
"""
records = []
for core in f['cores']:
for sample in core['samples']:
record = {}
record['well name'] = f['file']['well name']
record['country'] = f['file']['co... | 081ff42fde7cbe6fc499d88b077bb2ae6e8da81b | 41,716 |
def Madd(M1, M2):
"""Matrix addition (elementwise)"""
return [[a+b for a, b in zip(c, d)] for c, d in zip(M1, M2)] | 0e01c5be64f7c7b7c0487080ef08c560bacd6fc1 | 41,717 |
def handle_exceptions(err):
"""Custom Application Error handler."""
return err.to_dict() | 457421ed26cffc82c140c2da34df6131285220ae | 41,719 |
def convert_to_pronoun(day):
"""Take input "day" as a datatype integer, and convert to datatype string"""
if day == 0:
return "Monday"
if day == 1:
return "Tuesday"
if day == 2:
return "Wednesday"
if day == 3:
return "Thursday"
if day == 4:
return "Friday"
if day == 5:
return "Saturday"
if day == 6:... | 80f26ec77e563063ae790d2908f0fc4fcca92ab8 | 41,720 |
def bubble_sort(li):
""" [list of int] => [list of int]
Bubble sort: starts at the beginning of the data set.
It compares the first two elements, and if the first is
greater than the second, it swaps them. It continues doing
this for each pair of adjacent elements to the end of the
data set. It ... | d2730adae8e2ddec4943d5e9a39e2a5e34eaaaaa | 41,721 |
def get_bgp_attrs(g, node):
"""Return a dict of all BGP related attrs given to a node"""
if 'bgp' not in g.node[node]:
g.node[node]['bgp'] = {'asnum': None, 'neighbors': {}, 'announces': {}}
return g.node[node]['bgp'] | 9345cb12b263a2aec48f000e84b5b115a158c62f | 41,722 |
def convert_event_schema(schema):
""" Convert event schmea to record schema
"""
spots = list()
asocs = set()
spot_asoc_map = dict()
for event_type, definition in schema.items():
spots += [event_type]
spot_asoc_map[event_type] = list()
for arg in definition['参数']:
... | a06c437d598ff2b39504c82c5234ac98254cb4eb | 41,726 |
def GenerateAndroidResourceStringsXml(names_to_utf8_text, namespaces=None):
"""Generate an XML text corresponding to an Android resource strings map.
Args:
names_to_text: A dictionary mapping resource names to localized
text (encoded as UTF-8).
namespaces: A map of namespace prefix to URL.
Returns:... | 3561769bff337d71a3ee02acd39f30746e89baf9 | 41,728 |
def cross(u, v):
"""
return the cross product of 2 vectors.
"""
dim = len(u)
s = []
for i in range(0, dim):
if i == 0:
j,k = 1,2
s.append(u[j]*v[k] - u[k]*v[j])
elif i == 1:
j,k = 2,0
s.append(u[j]*v[k] - u[k]*v[j])
else:
j,k = 0,1
... | 81759774df8ab2b9d79e802fb811024fb45bbf3e | 41,729 |
def similar_lists(list1, list2, eps=1e-3):
"""Checks elementwise whether difference between two elements is at most some number"""
return all(map(lambda pair: abs(pair[0]-pair[1])<eps, zip(list1, list2))) | 09f8d5eea57eb19e3c64ce6f76603ab13a7e37ac | 41,730 |
def normalized_difference(x, y):
"""
Normalized difference helper function for computing an index such
as NDVI.
Example
-------
>>> import descarteslabs.workflows as wf
>>> col = wf.ImageCollection.from_id("landsat:LC08:01:RT:TOAR",
... start_datetime="2017-01-01",
... end_d... | bfb74cbdae173d31811533f42f88e5165489f5ae | 41,733 |
import numpy
def gen_symm_lookup(n_symm_el, orb_symm):
"""Generate a list of all spatial orbitals of each irrep in the point
group.
Parameters
----------
n_symm_el : (unsigned int)
number of distinct irreps in this group
orb_symm : (numpy.ndarray, unsigned int)... | da3a02e8da71837b793ed67a6ba317a505a3f545 | 41,734 |
import re
def match(message):
"""
"ceph package"
:returns: a package name if we matched, or None if not.
"""
pattern = re.compile('^(\S+) package\??$')
m = re.match(pattern, message)
if not m:
return
return m.group(1) | 0c085e9dff42415611a2b9749ade793cbb080676 | 41,735 |
def _jd2mjd( jd ):
"""
The `_jd2mjd` function converts the Julian date (serial day number)into a
Modified Julian date (serial day number).
Returns a float.
"""
return jd - 2400000.5 | 01f4db238d092ab235374c5ab64517754ef075de | 41,736 |
def tokenTextToDict(text):
"""
Prepares input text for use in latent semantic analysis by shifting it from
a list to a dictionary data structure
Parameters
----------
text : list of strings
A list of strings where each string is a word and the list is a document
Returns
-------
... | c712eaa06d540486792d59d45f0b489ddb12df56 | 41,738 |
def search(array, value, dir="-"):
"""
Searches a sorted (ascending) array for a value, or if value is not found,
will attempt to find closest value.
Specifying dir="-" finds index of greatest value in array less than
or equal to the given value.
Specifying dir="+" means find index of least va... | 9284ed8f826f3a472d9149531b29f12a8875870c | 41,739 |
def readFile(filename, offset, length):
""" Read length bytes from the file named by filename starting at
offset """
absoffset = abs(offset)
abslength = abs(length)
try:
f = open(filename, 'rb')
if absoffset != offset:
# negative offset returns offset bytes from tail of... | 50260817872e34eb74c812e791ef62a829d1219c | 41,740 |
import logging
def first_good_peak(peaks):
"""return only the relevant peak information in the form of a dict."""
if len(peaks[0]) == 0:
logging.warning('FIRST_PEAK: No peaks found, returning empty peak information')
return {'peak': 0, 'left': 0, 'right': 0}
if peaks[1]['left_ba... | 5df5fe03b4eb2028aa5891f186686de3d8151f50 | 41,742 |
def _make_ss_flux(reaction_str):
"""Format reaction identifier to match steady state flux parameter.
Warnings
--------
This method is intended for internal use only.
"""
return "v_" + reaction_str | 68270b4767ec7bc9c860b0063e17197583afdf69 | 41,743 |
def query_params(params, key, def_value, short_hand=None):
"""
updates params dict to use
:param params:
:param key:
:param def_value:
:param short_hand:
:return:
"""
if key not in params and short_hand:
# value is associated with shorthand, move to key
params[key] = ... | 35a5e3f42b779a439896a1e3a17aa7442194f945 | 41,744 |
from typing import Tuple
def adjust_range(in_range: Tuple[float, float]) -> Tuple[float, float]:
""" 将y方向的显示范围扩大到1.1 """
ret_range: Tuple[float, float]
diff = abs(in_range[0] - in_range[1])
ret_range = (in_range[0] - diff * 0.05, in_range[1] + diff * 0.05)
return ret_range | e82002ec7d6ca5a17bae8e147d1c2bd2cf1fff94 | 41,745 |
from pathlib import Path
def get_cache_dir() -> Path:
"""
Returns a cache dir that can be used as a local buffer.
Example use cases are intermediate results and downloaded files.
At the moment this will be a folder that lies in the root of this package.
Reason for this location and against `~/.ca... | 6f8655b9d8a145e7c018293456ac88546c78a34d | 41,747 |
def create_description(body) :
"""
Artificially create a description from main content of page (only, in case of no meta description).
"""
# extract all long sentences (possible candidates)
candidates = sorted([sentence for sentence in body.split('.')],key=lambda s : s.count(" "), reverse=True)
... | 550700bdb3087895582c7cf98a660e2a3ebbd47a | 41,749 |
def img_resize_bilinear(grid, w2, h2):
"""
From techalgorithm.com
"""
w = len(grid[0])
h = len(grid)
newgrid = []
x_ratio = (w-1)/float(w2)
y_ratio = (h-1)/float(h2)
for i in range(0, h2):
y = int(y_ratio * i)
y_diff = (y_ratio * i) - y
newrow = []
... | 175d82d2cd36cf74fd858743f9269ed3bca18a1b | 41,751 |
import sys
import os
def GetFlagValue(flagvalue, strip=True):
"""Converts a raw flag string to a useable value.
1. Expand @filename style flags to the content of filename.
2. Cope with Python3 strangness of sys.argv.
sys.argv is not actually proper str types on Unix with Python3
The bytes of the arg ... | 15dcb966c8246260ef3748af0c0993c46d89f487 | 41,752 |
def represents_int(string: str):
"""Checks if a `string can be turned into an integer
Args:
string (str): String to test
Returns:
bool
"""
try:
int(string)
return True
except ValueError:
return False | bc5cfb39e3b89309a7d29608d9bafb28ae67cd18 | 41,754 |
def parse_brackets(line: str) -> tuple[int, str]:
"""
Returns the index at which closing brackets don't align anymore,
or if all closing ones do match, the string needed to complete it.
"""
stack: list[str] = []
opening_map = {
")": "(",
"]": "[",
"}": "{",
">": "... | 3df3bc7bf6d1513b3d387023485949645b19e81c | 41,755 |
import requests
import re
def pubchemsyns(identifier):
"""this function allows retreival of data from the PugRest API @ PubChem"""
apipath = "https://pubchem.ncbi.nlm.nih.gov/rest/pug/compound/"
# retrieve full record if available based on name
searchpath = 'name/' + identifier + '/synonyms/json'
... | b802e20354155f0382c124da6b36374c6dbf4a2e | 41,756 |
def string_is_float(str_float):
"""
判断一个字符串是否是浮点数的字符串,整型也不是浮点数
:param str_float:
:return:
"""
is_float = True
try:
int(str_float)
is_float = False
except ValueError:
try:
float(str_float)
except ValueError:
is_float = False
re... | d816be827ffef75b10686d6b8e6beb5d2ca95a7d | 41,757 |
def client_error(message, http_status_code=400):
"""
Simple util function to return an error in a consistent format to the calling
system (API Gateway in this case.
:param message:
:param http_status_code:
:return:
"""
return "ERROR::CLIENT::{}::{}".format(http_status_code, message) | ea6f1a3073b856eb2f08b84b62cf9c95d9a62de4 | 41,759 |
def checkPrice(p):
"""
:param p: users entered price
Takes the expiration date and checks if it meets the required specifications.
If it does then return true, if it does not they return false.
"""
if (10 <= int(p) <= 100):
return True
else:
return False | ae750c2c37289c2568cbaa6af9d1f0f5603e5d33 | 41,760 |
def set_of_county_tuples(cluster_list):
"""
Input: A list of Cluster objects
Output: Set of sorted tuple of counties corresponds to counties in each cluster
"""
set_of_clusters = set([])
for cluster in cluster_list:
counties_in_cluster = cluster.fips_codes()
# convert to... | e141b3bf4184052acac388259eb90b69577f3332 | 41,761 |
def air_to_vac(air_wvs):
"""
following the vald conversion
http://www.astro.uu.se/valdwiki/Air-to-vacuum%20conversion
"""
s = air_wvs/1.0e4
n = 1 + 0.00008336624212083 + 0.02408926869968 / (130.1065924522 - s**2) + 0.0001599740894897 / (38.92568793293 - s**2)
return air_wvs*n | e5a4c11d580a96bff7d523bb1b9aafc2bedcf4a5 | 41,762 |
def get_zamid_s(zamid):
"""Gets the state of a nuclide from a its z-a-m id. 1 = first excited state, 0 = ground state.
Parameters
----------
zamid: str
z-a-m id of a nuclide
"""
s = int(zamid[-1])
return s | 750108113619f5176bf75e479b52989f9546f876 | 41,763 |
import os
def get_exec_path():
""" Get the path to this executable
Returns:
the path as a string of this script
"""
path = os.path.join(os.path.dirname(os.path.abspath(__file__)), __file__)
if path.endswith('.pyc'):
return path[:-1]
else:
return path | 0789c252d3714450fba722a2ef568a559c5fa940 | 41,766 |
import os
def buildmap(start_location, map_string, partial_match=True):
"""
Given a start location and a string value, this function returns a list of
file paths containing the given string value, down in the directory
structure from the start location.
:param start_location: directory from where... | 77f75917dc08ceaa60ffb5b9ebd97781e9f0b54b | 41,767 |
def parse_range_expr(range_expr):
""" Parse a range expression into a (min,max) pair """
not_found = -1
min_val = None
max_val = None
if range_expr is None:
return (min_val, max_val)
sep = "+/-"
pos = range_expr.find(sep)
if pos >= 0:
mid_str = range_expr[:pos]
ex... | 2a11f95d6567d85b20abb49fc9a73f4167e72b06 | 41,768 |
def extract_ep_dataset_args(args, split):
""" Extract dataset specific args to see if the dataset can be loaded from a cached copy"""
ep_attrs = ["seed", "data_path", "tokenizer_path", "tokenizer_type", "context_tokenizer_path",
"max_text_len", "episode_len", "pretrained_context_embedding_path"]... | b9a891fbcbdde634becbc446d608d39f60141d07 | 41,769 |
def show_mac_to_dictionary(show_mac_address=''):
""" from show mac address returns a dictionary, Indexed by Interface(short name) as per output.
Dictionary: [Int_name_short], List
List: (mac_address, Vlan_number_text). (('0100.0ccc.cccc','345'),('0100.0ccc.cccc','345'),(,),...)
:param show_mac_address... | ad5d26a5369e7e1071fdd82511c322b97237b62f | 41,770 |
import os
def give_unique_name(file_name):
"""
Создание уникального имени файла для исходного имени файла.
Функция создана для корректности работы сервера в случае получения двух разных файлов с одинаковыми именами.
"Уникальность" обеспечивается добавлением числа в начало имени файла.
Соответствен... | 28eab07e2fda60f02f91607194a85465ebaad034 | 41,772 |
def set_slices(DA,**axes2inds):
"""
return a copy of DataArray DA, where several slices are taken along named axes,
specified by keys ax1=ind1, ax2=ind2, etc.
"""
Out = DA
for (ax,ind) in axes2inds.items():
Out = Out.axis[ax][ind:(ind+1)]
return Out | f3aa91ee51d58e7e3926a049a8b10bcb556a9190 | 41,773 |
def get_buff_header():
"""something to keep things straight for raw data from socket deal"""
s = [
'recv',
'seqnum',
'sync',
'msiz',
'cksum',
' source',
'destin',
'sel',
'dsiz',
' tsh',
' counter',
(18 * ' ') + 'start',
'pstat',
'num',
'fsrate',
... | 3e2b70be4bae0fbac6eed5c408012e4e1697e486 | 41,776 |
def ceil(a, b):
"""
Returns the ceiling of a on b
"""
c = float(a) / float(b)
if c == int(c):
return int(c)
return int(c) + 1 | f6c7d46f05512d0766d4f9b39cdff224ed7d9bb7 | 41,777 |
def market_cap(df, min_cap=200):
"""filters out stocks that don't meet the min_cap minimum capitalization
criteria.
:df: dataframe
:min_cap: minimum market_cap number (*1 million) for stocks to include in
stock universe (default = 200)
:returns: Dataframe with stocks that have market capita... | 01f716510f3d172e262fcd220ce6affab1e22e19 | 41,778 |
def _get_edge_weight_distributions(observed_network,
permuted_networks,
max_possible_edge_weight):
"""Helper function that returns the null distribution of each
observed, weighted edge.
"""
edge_weight_distributions = {}
for edge ... | 9984f7636da417264cf6ce59382b329a74d50beb | 41,779 |
def attach(item, action):
"""Attaches a parse action to an item."""
return item.copy().addParseAction(action) | 7cbfbcee8316a009168ce577a6a178aa9d8384f1 | 41,780 |
import struct
def convert_short(value: int):
""" Range of smallint in Pg is the same with short in c,
although python type is int, but need to pack the value in short format """
return bytearray(struct.pack("h", value)) | 7c9939323b08e70d5e1ffc49049569da6f656e71 | 41,782 |
from typing import List
def arraysum(array: List[int]) -> int:
""" Get the sum of all the elements in the array.
arraysum
========
The `arraysum` function takes an array and returns the sum of all of its
elements using divide and concuer method.
Parameters
----------
array: List[int]
... | 8a2ea3bd6391f7ed402f07b381d561c816a7c68d | 41,783 |
import torch
def save_model(network, path):
"""
Save (trained) neural network to a file.
Intended to save trained models, but can save untrained ones as well.
Parameters
----------
network: pytorch object
Pytorch object or custom pytorch object containing model information.
path:... | 173c123b00f18635d3aa271f4b5d1789ee9a81f8 | 41,784 |
def related_action(action=None, **kwargs):
""" Attach a *Related Action* to a job.
A *Related Action* will appear as a button on the Odoo view.
The button will execute the action, usually it will open the
form view of the record related to the job.
The ``action`` must be a method on the `queue.job... | 1ba1f85580572cc698bd66b5793fbb74c5785de8 | 41,785 |
def ReadPairs(filename):
"""Read pairs and match labels from the given file.
"""
pairs = []
labels = []
with open(filename) as f:
for line in f:
parts = [p.strip() for p in line.split()]
pairs.append((parts[0], parts[3]))
labels.append(1 if parts[1] == par... | ab1c0a34f94c61b2d999a10a2fabab57790280b7 | 41,786 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.