content stringlengths 39 9.28k | sha1 stringlengths 40 40 | id int64 8 710k |
|---|---|---|
def human_readable_size(byte_count, unit="B", binary_marker='i'):
""" Converts a number of bytes into a human-readable size string. """
SUFFIXES = {
0: "",
1: "k" + binary_marker,
2: "M" + binary_marker,
3: "G" + binary_marker,
4: "T" + binary_marker,
5: "P" + bi... | 593e96802e2045f63b0140aeba1e59b063cc5f7a | 333,234 |
def const(x, *args, **kwargs):
"""const: returns x ignoring other arguments"""
return x | fd5a9490b81e5c3fa1cca0cd4cfa197ca0903cde | 266,112 |
def _cleanSimData(simData):
""" Remove unnecessary columns
Args:
simData (pandas data frame): Simulation data
Returns:
pandas data frame: Data frame with sim data
"""
simData.drop(columns=["doy", "weekDaySLP", "summer",
"winter", "intermediate"], inplace=T... | 20acbb8b43cbb79956b1a60e72daeee297fcf9eb | 551,932 |
def pixel_perfect_figsize(image, dpi=80):
"""Return the Matplotlib figure size tuple (w, h) for given image and dpi.
Parameters
----------
image : array, shape (M, N[, 3])
The image to be plotted.
dpi : int, optional
The desired figure dpi.
Returns
-------
figsize : tup... | a5b6cf66a02792e90fabe67d3b42e392724f1a6f | 336,253 |
def instance_with_scenario_name(instance_name, scenario_name):
"""Format instance name that includes scenario."""
return f"{instance_name}-{scenario_name}" | 2ce13b41e604e7caaa2d9ccc1a7f042dfa223244 | 661,261 |
def nz(df, y=0):
""" Replaces NaN values with zeros (or given value) in a series.
Same as the nz() function of Pinescript """
return df.fillna(y) | 5d0b940b88d7c8dfb7109d5e1a2538784231db1c | 682,489 |
def get_job_main_info(job):
"""
Return a dictionary with the pieces of information that will be presented on the terminal.
:param job: A Job object provided by ScrapingHub
:return: A dictionary
"""
info = job.info
main_info = {
'id': job.id,
'spider': info.get('spider'),
... | b23679cfe8e4996d120e958929f7663d5662d1cf | 669,475 |
from typing import Any
import json
def from_json(s: str, **kwargs: Any) -> object:
"""
Convert a JSON string to an object representation. For usage, see json.loads(...).
"""
return json.loads(s, **kwargs) | c82bbb38dc0300ddfbc2cba140536886ddbd9b14 | 617,261 |
def ensure_directory(file_path):
"""Checks the given file path for a directory, and creates one if not already present.
Args:
file_path: a pathlib.Path
returns the err message if permission issue, else is None
"""
if not file_path.exists():
try: file_path.mkdir()
except Excep... | 384f6f40b3af97b3b00cc5e9957badc24c4396b3 | 587,936 |
import six
def original_options(options):
"""
Return the input options with their original names.
This is used to undo the name change the click package applies
automatically before passing the options to the function that was decorated
with 'click.option()'. The original names are needed in case... | 4a0e0b0b294710cbf8b88da6e0fdbc844b429db6 | 476,384 |
def compare_str(str1: str, str2: str) -> bool:
"""Compare two string and ignore \n at the end of two strings."""
return str1.rstrip() == str2.rstrip() | de0203d12ef009016e07fdf3ba4de6cd64f7a3e2 | 267,929 |
def compute_min_refills(distance: int, tank: int, stops: list):
"""
Computes the minimum number of gas station pit stops.
>>> compute_min_refills(950, 400, [200, 375, 550, 750])
2
>>> compute_min_refills(10, 3, [1, 2, 5, 9])
-1
Example 3:
>>> compute_min_refills(200, 250, [100, 150])
... | 41dff6085f3b46b191c40c3dde9b68ee3ee41e3e | 705,036 |
def isCircleCrossingSquare(square,circle):
"""Detect the collision of a square and a circle."""
qx,qy,qr=square
cx,cy,cr=circle
return abs(qx-cx)<=qr/2+cr and abs(qy-cy)<=qr/2+cr | 1db8decb040db04003f71374b1339d381fcd0b3e | 544,301 |
def room_url_for_room_id(roomid):
"""
room schedule url from room id
"""
template = 'https://www-sbhome1.zv.uni-wuerzburg.de/qisserver/rds?state=wplan&act=Raum&pool=Raum&raum.rgid={}'
url = template.format(roomid)
return url | 85dc6cba30c1a11044f4aabd15fda9747e971e41 | 356,518 |
from typing import Optional
def fillna(raw_text: Optional[str]) -> str:
"""
>>> fillna("I'm")
"I'm"
>>> fillna("")
''
>>> fillna(None)
''
"""
if not raw_text:
return ""
return raw_text | ed195af8a55589150b36eb4ee630e6b7b9af7d3f | 356,129 |
def dunder_partition(key):
"""Splits a dunderkey into 2 parts
The first part is everything before the final double underscore
The second part is after the final double underscore
>>> dunder_partition('a__b__c')
>>> ('a__b', 'c')
"""
parts = key.rsplit('__', 1)
return tuple(parts)... | afd33d6e03de982bb7b71b0e7817fc5f1ae7207f | 667,993 |
def name( path ):
"""Extracts the resource name."""
return path[1+path.rfind('/'):] | 7e8448e5b1c62c30e7ae28c80580731aa9f6f9fb | 10,250 |
def read_landmarks(f_landmarks):
"""
Reads file containing landmarks for image list. Specifically,
<image name> x1 y1 ... xK yK is expected format.
:param f_landmarks: text file with image list and corresponding landmarks
:return: landmarks as type dictionary.
"""
landmarks_lut = {}
... | 9c4bf6b405f4fb49ace8badb4b3151cc457bbf84 | 701,094 |
import requests
def _get_repo_list(token: str) -> list:
"""
Retrieves the list of repositories for the given username.
:param token:
The GitLab access token
:return:
A JSON object with the list of repositories
"""
url = 'https://gitlab.com/api/v4/projects'
headers = {
... | 56b0c2e7c4ffc57abfc2b5c75ba99edbfd0d38bc | 430,060 |
def _reduce_sampled_fluxes(sampled_fluxes, reactions):
"""
Reduces the input dataframe of sampled fluxes to a subset of
selected reactions.
Parameters
----------
sampled_fluxes : pandas.Dataframe
The calculated fluxes, output of sampling. For each reaction,
n fluxes will be calc... | b6d6a618a0435b9e4f28fe4b10c611e9d269b698 | 631,515 |
def pearsonr(pred, target):
"""
Pearson correlation between target and prediction.
Mimics `scipy.stats.pearsonr`.
Parameters:
pred (Tensor): prediction of shape :math: `(N,)`
target (Tensor): target of shape :math: `(N,)`
"""
pred_mean = pred.float().mean()
target_mean = tar... | 533cd8ce0e99186907bd7ed9d0a5728c57049080 | 201,491 |
def indent(data: str, spaces: int) -> str:
"""
Indent every line in 'data' by 'spaces'
"""
result = []
for line in data.splitlines():
result.append(" " * spaces + line)
return "\n".join(result) | 3d83311d46b98aa277fe86a782c0391d1cd83827 | 346,931 |
def create_contours_obj(canvas, contour_groups, colors=None, **kwargs):
"""Create and return a compound object for ginga `canvas`, consisting
of a number of contour polygons. `contour_groups` is a list of
numpy arrays of points representing polygons, such as returned by
calc_contours() or get_contours(... | 996b0082d3db00460fdfd93b7cec14474d618a41 | 308,990 |
def make_ordinal(num):
"""
Create an ordinal (1st, 2nd, etc.) from a number.
"""
base = num % 10
if base in [0,4,5,6,7,8,9] or num in [11,12,13]:
ext = "th"
elif base == 1:
ext = "st"
elif base == 2:
ext = "nd"
else:
ext = "rd"
return str(num) + ext | d92069f2d1a88adeb1c72e7551adc75af84beb31 | 89,183 |
from typing import Dict
def sra_id_to_app_input(sra_id: str) -> Dict:
"""Generate input from app for sra_fastq_importer
Set split files to false so we no merging is needed
Args:
sra_id:
Returns:
dictionary containing
"""
return {"accession": sra_id, "split_files": False} | bf1ca62df98932a05cb6fce476a361273f86c35e | 690,645 |
def __update_agent_state(current_agent_state, transition_probability, rng):
"""
Get agent state for next time step
Parameters
----------
current_agent_state : int
Current agent state.
transition_probability : ndarray
Transition probability vector corresponding to current state.
... | 4d447f196ac6a326720cdf69c67286fe5053e5fc | 19,597 |
import time
def unix_time_millis(dt):
""" Convert datetime to unix timestamp """
return int(time.mktime(dt.timetuple())) | 88e306d345452505b94693984da6df7fe292277d | 416,315 |
def get_sorted_paths(paths, highest_first=True):
"""Return a generator that will yield the items of 'paths' sorted highest first if `highest_first` is True. This will work for numbers as well as strings."""
return sorted(paths, key=lambda x: x[0], reverse=highest_first) | 17e2280dfa51b01aac8ec261e59cc7699b9e11a7 | 477,343 |
def text_to_list_of_lines(text):
"""Convert text into a list of lines, each being a list of words."""
return [line.split() for line in text.strip().split('\n')] | cbc7647e4c12432488aa7e59ff99e34a6c6e8c92 | 502,296 |
def parse_int(value):
"""
Parse an int, interpreting an empty string as 0.
"""
return int(value) if value.strip() != '' else 0 | 6f0a4360e3273fea848ee11e691bc45a0cd61813 | 225,324 |
def countissue(s):
"""Count number of issues"""
if s:#check if Nonetype.
if s=='None':
#if type(s)==str or type(s)==float:#Handle
return 0
else:
return len(s)
else:#if empty
return 0 | e1960898476b7a20377293d413b10c9f0ab9b1bb | 678,270 |
def unique_name(name, nlist, max=1000):
"""return name so that is is not in list,
by appending _1, _2, ... as necessary up to a max suffix
>>> unique_name('foo', ['bar, 'baz'])
'foo'
>>> unique_name('foo', ['foo', 'bar, 'baz'])
'foo_1'
"""
out = name
if name in nlist:
for ... | c22b93846882cd98ade73c91bdb6a8dc23931e9a | 512,571 |
def list_records_params(req):
"""
Extract the appropriate request parameters for a ListRecords request
:param req: flask request object
:return: a dictionary of parameters
"""
from_date = req.values.get("from")
until_date = req.values.get("until")
oai_set = req.values.get("set")
res... | 712482b49406f12fa761d19d90c1b13cb3d9b9ee | 484,525 |
from typing import Dict
from typing import Any
def get_network_config(network_name: str) -> Dict[str, Any]:
"""Get the network configuration
Args:
network_name (str): The name of the network to get the configuration for
Returns:
Dict[str, Any]: The network configuration
"""
nn_co... | 1f76fdf249e942a149cb6b5febedeb85a22c3077 | 497,717 |
def attr_populated(obj, attr):
"""Return True if attr was populated in obj from source JSON."""
return not not getattr(obj, '_populated_' + attr, False) | 5a37a1c07c0aaa87409fbc7fe0a8298c0e266859 | 592,990 |
import string
def simplestring(length, offset=0):
"""
Deterministically generates a string.
Args:
length: Length of the string
offset: Offset of the string
Returns:
A string formed of lowercase ASCII characters.
"""
return "".join(
[
string.ascii_lo... | 8e1fb53b7790d8a9b95815cc861c47d5f5281c1d | 588,572 |
def get_singleton_scaffolds(scaffoldgraph):
"""Get singleton scaffolds within a scaffold graph.
Singleton scaffolds represent scaffolds that are direct members of only
one compound in the current collection.
Parameters
----------
scaffoldgraph : ScaffoldGraph
A ScaffoldGraph object to ... | 6847bd77c6ee0be6e5e16aa6885c826309db9554 | 475,053 |
def point_distance(p1, p2):
"""Return the distance between two points.
Parameters
----------
p1 : (float, float)
(x,y) values of point 1
p2 : (float, float)
(x,y) values of point 2
Returns
-------
float
the distance between the two points
"""
x1, y1 = p1... | 373ca3c1d3ead67e49e892e3a01e3c522b8b6710 | 548,324 |
def get_backend_properties_url(config, backend_type, hub=None):
"""
Util method to get backend properties url
"""
hub = config.get('hub', hub)
if hub:
return '/Network/{}/devices/{}/properties'.format(hub, backend_type)
return '/Backends/{}/properties'.format(backend_type) | 001194c1ae2fa924a14d6abf215427f00161ecca | 353,120 |
def matches_value_in_range(range_start, range_stop, range_step, value):
"""Helper function that matches the value with the nearest value in the
given range.
:param int range_start: The start of the range.
:param int range_stop: The end of the range.
:param int range_step: The gap between two value ... | db4dce08873ebe3ba98ffedf8f3e4177a9ebe74b | 234,775 |
def define_limit_offset(request):
""" Define limit and offset variables from request.args """
if request.args:
try:
limit = int(request.args['limit'])
offset = int(request.args['offset'])
except:
# Default limit and offset
limit = 12
offset = 0
else:
# Default limit and offset
limit = 12
of... | 31ef7fbc70ec67c0d646024c580b591238cfecbf | 47,591 |
def create_instance(cls_info):
"""
Creates instance of a class specified in cls_info.
cls_info's format is (class_name, args, kwargs)
e.g.:
create_instance((dict, None, None))
"""
cls, args, kwargs = cls_info
if args is None:
args = []
if kwargs is None:
kwargs = {... | 04e24d26e07a4f1117dd6ef049fc172c15ca7c13 | 387,387 |
def _zone_group_topology_location_to_ip(location):
"""Takes a <ZoneGroupMember Location=> attribute and returns the IP of
the player."""
# Assume it is of the form http://ip:port/blah/, rather than supporting
# any type of URL and needing `urllib.parse`. (It is available for MicroPython
# but it req... | e3b038b92d4fcb24650dd6905847c9ca3f1fa13e | 35,628 |
import logging
def bad_request(err):
"""Return a custom 400 error."""
logging.warning(err)
return 'The browser (or proxy) sent a request that this server could not understand.', 400 | f5f9ef65d58226f079512bb08f8b57918cc9446c | 127,359 |
def is_string_type(s):
"""
True iff s is a string.
"""
return type(s) == type('') | 4865ed3806057fca5a96663d40c6ddcdb2be333c | 119,140 |
def references(name, tag):
"""Returns references for space weather dataset
Parameters
----------
name : string
Name of space weather index, eg, dst, f107, kp
tag : string
Tag of the space weather index
"""
refs = {'dst': {'noaa': ''.join([
'See referenece list and ... | 0734d643ba0cb385e1cc33f22d336b88dfe8e1f3 | 508,007 |
def get_site_by_request(request):
"""
Return the current site from the given request
:param request: request to get the site from
:return: site value in the request
"""
return getattr(request, 'site', None) | bb862c66833e369ce015e41187d08695b5494c88 | 144,834 |
def skip(s,n):
"""
Returns a copy of s, only including positions that are multiples of n
A position is a multiple of n if pos % n == 0.
Examples:
skip('hello world',1) returns 'hello world'
skip('hello world',2) returns 'hlowrd'
skip('hello world',3) returns 'hlwl'
skip... | d08feaaac4fc1afa3f61d160845a4cfb45feb2a6 | 174,725 |
def floating_range(buckets):
"""
Computes a equal distributed list of bucket thresholds
Args:
buckets (int): Number of buckets
Returns:
List: List of bucket thresholds of length buckets
"""
return [x / 100 for x in list(range(0, 100, int(100 / (buckets - 1)))) + [100]] | 85378532714d73c40ac6b657c12edab9936e582c | 390,889 |
def join(*args):
"""Forms join instruction."""
inputs = [arg[0] for arg in args]
return {
'cmd': 'join',
'inputs': inputs,
'args': args,
} | cb20ae8629ef6d36678bc3b16849302456570a4d | 645,012 |
import textwrap
def wrap_headlines(dbhead, width=75):
"""
wraps lines of a restraint header to prevent too long lines in
SHELXL. wrapping is done with = at the end of a line and ' ' at
start of the next line
:param dbhead: header with restraints
:param width: wrap after width characters
>>... | ecbcede24ad7c02f9ce0fc5a076464811d9f76d8 | 310,948 |
def is_ascii(string):
"""
Returns true if the string only contains ASCII characters,
False otherwise.
"""
try:
string.encode('ascii')
except UnicodeEncodeError:
return False
return True | defafb1561e078e0356bbc9099d90b796659760a | 310,329 |
import base64
def b64_encode(value: bytes) -> bytes:
"""
URL safe base 64 encoding of a value
:param value: bytes
:return: bytes
"""
return base64.urlsafe_b64encode(value).strip(b"=") | 40a7dfbec7ec390a71cdacc5ab54ce8e2a092754 | 28,084 |
def create_exp_id(exp_network,
num_layers,
num_neurons,
batch_size,
num_epochs,
learning_method,
regularization):
"""Create identifier for particular experiment.
Parameters
----------
exp_network... | 4791c6cb0c0d60f00da83a75af237dc113f565a3 | 422,608 |
import codecs
import json
def get_pyobj_from_json(str_or_path):
"""
This function takes either a json string or a path to a json file,
it loads the json into memory and returns the corresponding Python
object.
"""
try:
# see if treating str_or_path as a path works
fp = codecs.o... | 413b06385c6f50d90f94638bf301bc184a5fd574 | 220,117 |
def sanitize_code(code):
"""
Sanitize code removing unnecessary characters
Params:
code (str): target code
Returns: the sanitized code
"""
if code:
code = code.replace('-', '')
code = code.ljust(7, '0')
return code | 714a081ab390d85e9dfb961ba8a89c2abe0cab9a | 621,164 |
def is_external_artifact(label):
"""Determines whether a label corresponds to an external artifact."""
# Label.EXTERNAL_PATH_PREFIX is due to change from 'external' to '..' in Bazel 0.4.5.
# This code is for forwards and backwards compatibility.
# Remove the 'external' check when Bazel 0.4.4 and earlie... | f0c7025c940532ec6d08a29bdb440f43c27312a9 | 566,898 |
def inverse_datum_def(datum_def: list):
"""
Reverse the order of the datum definition list and prepend 'inv' to each
layer.
Parameters
----------
datum_def
A list describing the layers of a datum definition.
Returns
-------
list
The provided list reversed with 'inv'... | 5b39761d3799a605d6386ca612a55aefe8ec40b4 | 565,891 |
import json
def read_config(config_file):
""" Read parameters from config file.
Keyword arguments:
config_file -- json file containing input parameters
Return:
coef -- dictionary containing coefficients
input_conf -- dictionary containing input parameters
output_conf -- dictionary co... | 30622fbbf542528254742848aaff47d8fa5e40c5 | 369,851 |
import json
def load_json(file_source, file_name):
""" Load a JSON data dictionary.
Parameters
----------
file_source, file_name : str
Where is the file stored and what is its name.
Returns
-------
data : dict
Loaded json dictionary.
"""
f = open(file_source + fil... | cf548b21c59abfadcf23350784945c488d653816 | 406,769 |
def map_or_apply(obj, fn):
"""
If the first argument is iterable, map the function across each item in it and
return the result. If it looks like a queryset or manager, call `.all()` and
map the function across the result of that. If it's is a single item, just call
the function on that item and ret... | 64d06b611142e2578402f1ed4015d6558bc116e9 | 521,142 |
def coco_categories_dict_from_df(df, category_id_col, category_name_col,
supercategory_col=None):
"""Extract category IDs, category names, and supercat names from df.
Arguments
---------
df : :class:`pandas.DataFrame`
A :class:`pandas.DataFrame` of records to fi... | 3fcf4cf8bac900ea7aa48a5918d15eb70feb9c3a | 532,631 |
def markov_forward(p0, A):
"""Calculate the forward predictive distribution in a discrete Markov chain
Args:
p0 (numpy vector): a discrete probability vector
A (numpy matrix): the transition matrix, A[i,j] means the prob. to
switch FROM i TO j
Returns:
p1 (numpy vector): the predictive probabili... | c4bb47422833055a9f6683917a17d868850e0b52 | 599,963 |
import torch
def get_laplacian_kernel_3x3(alt=False) -> torch.Tensor:
"""
Utility function that returns a laplacian kernel of 3x3
https://academic.mu.edu/phys/matthysd/web226/Lab02.htm
http://homepages.inf.ed.ac.uk/rbf/HIPR2/log.htm
This is called a negative Laplac... | c74816a855e95d72ae877cda38bd8799f2b4a3f9 | 319,711 |
import torch
def default_optimizer(params, nb_iters, learning_rate=0.5):
"""
Create a default optimizer for :class:`trw.train.MeaningfulPerturbation`
Args:
params: the parameters to optimize
nb_iters: the number of iterations
learning_rate: the default learning rate
Returns:
... | d633d9bb1a7fdeecb2aaa7405cf03c46f2fbc69a | 160,500 |
def get_layer_nr_id(name):
"""
For the given full layer parameter name, e.g.
language_model.model.encoder.layer.11.attention.output.dense.bias return the
numeric layer number (11) and the id ("attention.output.dense.bias")
"""
if name.startswith("language_model.model.encoder.layer."):
su... | 2690e23f069413e357bfd7644ae679696f2e7d8c | 423,489 |
def yields_from_leung_nomoto_2018_table10(feh):
"""
Supernova data source: Leung & Nomoto, 2018, ApJ, Volume 861, Issue 2, Id 143, Table 10/11
The seven datasets are provided for Z/Zsun values of 0, 0.1, 0.5, 1, 2, 3 and 5.
Using Zsun = 0.0169 the corresponding FeH values are -1, -0.301, 0.0, 0.301, 0.4... | 4a03971e14c80d013259afefdbece6e2c67ccdf8 | 19,349 |
def stringified(value, converter=None, none="None"):
"""
Args:
value: Any object to turn into a string
converter (callable | None): Optional converter to use for non-string objects
none (str | bool | None): Value to use to represent `None` ("" or False represents None as empty string)
... | 5518dd946c3670e79a81a47182b94bda6c3c52f3 | 514,614 |
def flatten(x):
"""
Flatten lists of lists of any depth. Preserves tuples.
"""
result = []
for el in x:
if hasattr(el, "__iter__") and not isinstance(el, str) and type(el)!=tuple and not issubclass(type(el), tuple):
result.extend(flatten(el))
else:
result.appe... | 9040facd784890f5dd96cc4c69637c9d5883cc67 | 347,442 |
def asn1_length(n):
"""Return a string representing a field length in ASN.1 format."""
assert n >= 0
if n < 0x7f:
return chr(n)
r = ""
while n > 0:
r = chr(n & 0xff) + r
n >>= 8
return r | 8d6d555089d823cb39bcdc3fe728c1b1fab01cff | 81,307 |
def compose_slice_query(search_type, search_term):
"""Extract a filter query given a form search term and search type
Args:
search_type(str): example -> "case:"
search_term(str): example -> "17867"
Returns:
slice_query(str): example case:17867
"""
slice_query = None
if ... | e24b4a05fbfbe44e73c903375a22b51cae91b895 | 86,137 |
import json
from typing import OrderedDict
def load_json_string(json_input):
"""Load a JSON-String."""
inpt = json.loads(json_input, object_pairs_hook=OrderedDict)
return inpt | 3c715575fffa51d94a4faaf5c3b29e0181da3548 | 499,115 |
def get_alarm_descriptions(
self,
data_format: str,
default_values: bool,
) -> list:
"""Get alarm descriptions and type details
.. list-table::
:header-rows: 1
* - Swagger Section
- Method
- Endpoint
* - alarm
- GET
- /alarm/descripti... | df329965c15a7c9ecc5c81b2005216c40df98a1c | 305,100 |
import typing
def flatten_list(list_of_lists: typing.List[typing.List[typing.Any]]) -> typing.List[typing.Any]:
"""flatten a 2 level deep nested list into a single list
Parameters
----------
list_of_lists: typing.List[typing.List[typing.Any]]
2 level nested list
Returns
-------
... | eab91121f66cefc1ab7e43f5644544360f1e678c | 659,135 |
from typing import Iterable
from typing import Any
from typing import Tuple
def tuple_from_iterable(val: Iterable[Any]) -> Tuple[Any, ...]:
"""Builds a tuple from an iterable.
Workaround for https://github.com/python-attrs/attrs/issues/519
"""
return tuple(val) | 7880b1395f14aa690f967b9548456105b544d337 | 3,308 |
def find_data_in_soup(soup, tag: str, class_id:str) -> str:
"""
Returns the text of a given tag / class id
within a Beautiful Soup objhect()
"""
return soup.find(tag, class_=class_id).get_text() | cfd7adaef45f21e1a945b293e5b767a6a0753677 | 434,157 |
def add_args(parser):
"""
Create parser for command line utility.
:meta private:
"""
data_grp = parser.add_argument_group("Data")
proj_grp = parser.add_argument_group("Projection Module")
contact_grp = parser.add_argument_group("Contact Module")
inter_grp = parser.add_argument_group("I... | 7c44797757db29883990f1d4ac4fe4cb8ba9ed7a | 228,607 |
def validate_ecoli(seq_list, metadata_reports):
"""
Checks if the uidA marker and vt markers are present in the combinedMetadata sheets and stores True/False for
each SeqID. Values are stored as tuples: (uida_present, verotoxigenic)
:param seq_list: List of OLC Seq IDs
:param metadata_reports: Dicti... | 2d038799d6cce9588215893835ea6ae62139d07f | 97,136 |
def get_suit_of_card(position_of_card, deck):
"""Returns the suit of the card that has the specific position in the deck"""
suit_int = deck[position_of_card][0]
if suit_int == 0:
return "Spades"
elif suit_int == 1:
return "Hearts" | 0ebef9b82530684d6056ec2d0f11a9ab4babdbe8 | 98,709 |
def format_pylist_to_mathematica_legend(labelname_syntax, pylabel_list):
"""
Helper funciton. convert python list to be mathematica list for the legend
Parameters
-------------
labelname_syntax : str
label type syntax in the Wolfram Mathematica .
pylabel_list : list
the lis... | 26d42e5330c89dac5351507ca3a37e4d2f8e03c8 | 607,790 |
def select_by_hour(df, hour="All"):
"""
This function takes in a string designating a time window and returns instances from a dataframe which fall
within this time window.
Required argument:
- df: pandas dataframe, contains movie showtimes
Optional argument:
- hour: string, designates a t... | c79c596d75b0c33c68ecb30efdf6031abb340ab0 | 579,765 |
import re
def clean_whitespace(text):
"""Replace whitespace characters with a simple space.
Parameters
----------
text : str
The text to clean
Returns
-------
clean_text : str
The text with whitespace replaced
"""
if not isinstance(text, str):
return None
... | 81425799e7e68a7d7c42204e1b9578a7133d0378 | 379,967 |
def get_object_dir_prefix(objhash):
"""Returns object directory prefix (first two chars of object hash)"""
return objhash[0:2] + "/" | 0b44010ce1a2b5fb25667e85103815667afa95c3 | 342,013 |
def does_contain_unicode(name: str) -> bool:
"""
Check if name contains unicode characters.
>>> does_contain_unicode('hello_world1')
False
>>> does_contain_unicode('')
False
>>> does_contain_unicode('привет_мир1')
True
>>> does_contain_unicode('russian_техт')
True
"""
... | 0470aa98e257585e981ef4e850ed3ce98c72b479 | 119,749 |
def tlbr2bbox(top, left, bottom, right, oper=int):
"""
tlbr = [top, left, bottom, right]
to ->
bbox = [x(left), y(top), width, height]
"""
x_pos = oper(left)
y_pos = oper(top)
width = oper(right - left)
height = oper(bottom - top)
return [x_pos, y_pos, width, height] | 6234cf0296095c3b0eeb8e3e00667c60cfbe361f | 440,993 |
def sphere_sre(solution):
"""
Variant of the sphere function. Dimensions except the first 10 ones have limited impact on the function value.
"""
a = 0
bias = 0.2
x = solution.get_x()
x1 = x[:10]
x2 = x[10:]
value1 = sum([(i-bias)*(i-bias) for i in x1])
value2 = 1/len(x) * sum([(i... | 38987c77a6586a0bfab1d94cc4a1511e9418349f | 697,867 |
import re
def sanitize_host_name(name):
"""Return a sanitized version of the given name, suitable for use as a hostname."""
return re.sub('[^A-Za-z0-9]+', '-', name)[:63].strip('-') | 8997b036ced083fb0910a64ec48d6feb45aa4667 | 388,543 |
def age_format(value):
""" Custom formatting for age, converting from days to years. """
value = value / 365.2524
return "{:,.2f} years".format(value) | a3297c2e7d5f16eacd0de485cd0296fda524577b | 487,101 |
def insertIntoPath(original, insertion='rest'):
""" Insert a string after the first block in a path, for example
/my/original/path,insertion
/my/INSERTION/original/path
"""
slashIndex = original.index('/',1)
newString = '%s/%s%s' % (original[0:slashIndex], insertion, original[slashIndex:len(orig... | d43a5ea7c428202da9058d45bab289027a873e46 | 363,896 |
import dill
def run_dill_encoded(what):
"""
Run a function that's been encoded with Dill (this allows me to do multiprocessing).
http://stackoverflow.com/a/24673524
"""
fun, args = dill.loads(what)
return fun(*args) | 70e5ccd8fa8e2b369cb45f80993bb6196287fc28 | 589,271 |
def _is_kanji(char):
""" Check if given character is a Kanji. """
return ord("\u4e00") < ord(char) < ord("\u9fff") | 6c785eca322002b80ff20212d1a914e538d684ab | 656,654 |
def greet(name):
"""
Greets a person.
:param name: a string input.
:return: None if string empty or None else greets the name.
"""
if name == "" or name is None:
return None
else:
return "hello " + name + "!" | 40d94316218fac1513ccdcebe5b0b738facfbc6f | 393,030 |
def create_symbol(
client, symbol_file, point, drawing=None, replace_values=None, sheet=None
):
"""Add a symbol instance to a drawing.
Args:
client (obj):
creopyson Client
symbol_file (str):
Name of the symbol file.
point (dict):
Coordinates for t... | 82a90571de8f3a988659d6da8b20afe37044c8eb | 644,272 |
def get_countries(market):
"""
Get a comma-separated list of countries the Market's serves
"""
country_list = list(set([str(country) for country in market.countries_served.all()]))
country_list.sort(key=lambda country: country)
return ", ".join(set(country_list)) | 9ed65c7244a171fb288f834042f7c2da86f7b9d5 | 88,838 |
def get_structure_info(structure):
"""Get information from a directory structure definition.
Parameters
----------
structure : dict
Definition of the directory.
Returns
-------
names : list of str
List of all the folder names (at any level).
paths : list of str
... | e1a4962dea615d528ce28bd63bfb943fc134c0c3 | 250,655 |
def values_by_key(dct, keys, fill_val=None):
""" return dictionary values for specific keys, filling missing entries
"""
return tuple(dct[key] if key in dct else fill_val for key in keys) | 5fb9ff1fab4a54d11412e7b038545307ace8e363 | 216,947 |
def team_info(team, purpose):
"""
Function that displays and returns the information about the tean.
Params:
team(dict) contains all information about requested team
purpose(string) like "console"
Example of team stats displayed:
ARSENAL FC
FOUNDED: 1886
... | b94df8a22b7571e8f05d4547d734c95fa7939ea3 | 155,488 |
def is_translator(permission):
"""
based on settings.CMS_CONTEXT_PERMISSIONS
given a permission code (int)
returns a dict{} with translator permission info
"""
if not permission > 0: return {}
allow_descendant = True if permission > 1 else False
return {'only_created_by': False,
... | 8e732ad0dab89df4f63de0f8d9260604d61d7ae0 | 508,360 |
import torch
def construct_length_mask(seq_lengths):
"""
construct sequence length mask to rule out padding terms.
:param seq_lengths: a list or 1D Tensor containing the lengths of the sequences in a batch
:return: a 2D Tensor containing the mask
"""
max_sequence_length = max(seq_lengths)
... | 5b3215cd34e95e6e6ef7db564abf679751bcb9b1 | 583,702 |
def count_params(net, exclude=[]):
"""
Count parameters for net.
:param net: mxnet.gluon.Block
Net or block to be counted parameters for.
:param exclude: list of mxnet.gluon.nn.Block
Blocks to be excluded.
:return: int
The number of parameters of net.
"""
exclude_para... | 5aa12631d781e53fdce9b47ff7fad9cec9354779 | 564,800 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.