content stringlengths 39 9.28k | sha1 stringlengths 40 40 | id int64 8 710k |
|---|---|---|
def _GetCurrentCommand(trace=None, include_separators=True):
"""Returns current command for the purpose of generating help text."""
if trace:
current_command = trace.GetCommand(include_separators=include_separators)
else:
current_command = ''
return current_command | aad81fe61ef31f04b5d9e3b1fd3de98a3e0f0258 | 284,330 |
import hashlib
def activity_hash(dataset):
"""Return the hash string that uniquely identifies an activity.
Uses the following fields, in order:
* name
* reference product
* unit
* location
* start date
* end date
An empty string is used if a field isn't pr... | cdec16ba7d018fb0b45739d394d8e44653bd359c | 582,714 |
import math
def read_file(input_file: str) -> dict:
"""
Read the file and extract relevant data
Parameters
----------
input_file : string
HiTrack filename
Returns
-------
data: dict of lists of lists
{'gps': list of lists, 'alti': list of lists, 'hr': list of lists, '... | 0bd52a1741d861e1f13cdec212938a9a727ea2e0 | 244,615 |
import re
def strip_html_tags(text):
"""
Strip HTML tags from text generated from Markdown script
:param text: text in HTML
:return: text without HTML Tags
"""
htmlPattern = re.compile(r'<\w+>|</\w+>')
return htmlPattern.sub('', text) | a93fdaefa4d20dfcc647f5a3cd8fa801709668a4 | 120,821 |
def labelwell(platemap, labelby, iterrange, **kwargs):
"""Returns label for each row of a stipulated column.
Used to return the appropriate, formatted label from a specified platemap at every well. Empty wells will always return 'empty', wells without a label will return a blank string.
:param p... | 28f06612efb07e67045cc18edda922aee0410499 | 496,705 |
def sum_abs_of_all(sequence):
"""
What comes in:
-- A sequence of numbers.
What goes out:
Returns the sum of the absolute values of the numbers.
Side effects: None.
Examples:
sum_all([5, -1, 10, 4, -33])
would return 5 + 1 + 10 + 4 + 33, which is 53
sum_all([10, -... | 42d1a3e0aa5cf96ed11f898129a37f0b835d2bfb | 348,268 |
def to_vintagestory_axis(ax):
"""Convert blender space to VS space:
X -> Z
Y -> X
Z -> Y
"""
if "X" in ax:
return "Z"
elif "Y" in ax:
return "X"
elif "Z" in ax:
return "Y" | ce585cf95d9663f566ae65d3baa46a2e793bf301 | 78,967 |
def palette_val(palette):
"""Convert palette to matplotlib palette.
Args:
palette List[tuple]: A list of color tuples.
Returns:
List[tuple[float]]: A list of RGB matplotlib color tuples.
"""
new_palette = []
for color in palette:
color = [c / 255 for c in color]
... | d04b8b7190e0a0a54700121219044ba4f29d025e | 516,061 |
def _get_persons(event):
"""Get string of persons from event"""
persons = []
for person in event['persons']:
persons.append(person['public_name'])
return ', '.join(persons) | b6201056e37c54ca336395205ee8a730b4ac0899 | 475,344 |
def repr_long_list(seq):
"""
>>> repr_long_list(list(range(100)))
'[0, 1, 2, ..., 98, 99]'
"""
if len(seq) < 8:
return repr(seq)
else:
return repr(seq[:3])[:-1] + ', ..., ' + repr(seq[-2:])[1:] | 9978a1439d66cbd1c2015cb799cace7aeaac411c | 69,612 |
def _rnl_daily(tmax, tmin, ea, fcd):
"""Daily net long-wave radiation (Eq. 17)
Parameters
----------
tmax : ee.Image or ee.Number
Daily maximum air temperature [C].
tmin : ee.Image or ee.Number
Daily minimum air temperature [C].
ea : ee.Image or ee.Number
Actual vapor p... | d639ac04b5ca9efb42ebf023398a0d79b437f31c | 528,152 |
def c_terminal_proline(amino_acids):
"""
Is the right-most (C-terminal) amino acid a proline?
"""
return amino_acids[-1] == "P" | f54563ff59973d398e787186a1c390da03ff8999 | 36,768 |
def del_char_idx(inline, idx):
"""
Del char at the position given by the index idx.
Args:
inline(str): Input string.
idx(int): An index position.
"""
return inline[:idx] + inline[idx+1:] | 0f41fc9f0e6b4ce6b88af8f323e9f2f49501a5c2 | 322,593 |
def _modified_dict_keys_and_values(adict, func):
"""Get a new dictionary with key and value strings modified by func."""
return dict((func(key), func(value)) for key, value in adict.iteritems()) | c46067fc15111f95c2d9bf07fefc75abc0b28f66 | 163,933 |
import torch
def prepare_batch(sample, use_cuda=False):
"""Prepares a batch for training/validation by moving it to GPU
Args:
sample (dict | :obj:`torch.Tensor` | list): The batch to prepare
use_cuda (bool): Move to cuda
Returns:
(dict | :obj:`torch.Tensor` | list): The batch, on... | ab7280f1b909a3e7ab5a823a3ddfbe2979b09e8a | 233,340 |
def append_tag(image_tag, append_str):
"""
Appends image_tag with append_str
:param image_tag: str, original image tag
:param append_str: str, string to be appended
"""
return f"{image_tag}-{append_str}" | b35ad32be77d473237ff6c47afba253400a031b2 | 53,826 |
from datetime import datetime
def get_file_age(file):
"""Returns the age of file.
Args:
file: A PosixPath object representing a file.
Returns: An int represeting the age in days.
"""
return (datetime.today()
- datetime.fromtimestamp(file.stat().st_mtime)).days | 5d62ce19ea5b4fd2d34c4c1ecd0240d85b1af085 | 582,659 |
def _set_parameter(config, parameter):
"""
Checks for parameter value and sets if present
:param config: bit configuration list
:param parameter: the configuration item to set
:return: string with value of parameter
"""
if parameter in config:
return config[parameter]
else:
... | 14a7d116db6731c8e0b287d9a73d701bbb404d26 | 147,421 |
def get_content_iter_with_chunk_size(content, chunk_size=1024):
"""
Return iterator for the provided content which will return chunks of the specified size.
For performance reasons, larger chunks should be used with very large content to speed up the
tests (since in some cases each iteration may result... | c1550aef62e58b459feb66bde6c2a506e5de31be | 96,273 |
def get_L_DHW_d_t(L_dashdash_k_d_t, L_dashdash_w_d_t, L_dashdash_s_d_t, L_dashdash_b1_d_t, L_dashdash_b2_d_t,
L_dashdash_ba1_d_t):
"""1時間当たりの発電ユニットによる浴槽追焚を除く給湯熱負荷 (30)
Args:
L_dashdash_k_d_t(ndarray): 1時間当たりの台所水栓における太陽熱補正給湯熱負荷 (MJ/h)
L_dashdash_w_d_t(ndarray): 1時間当たりの洗面水栓における太陽熱補正... | 1e4354a3bed5554b65257847900752c1a0389269 | 157,187 |
def mean(seq):
"""Arithmetic mean."""
return sum(seq) / len(seq) | f5a4f7f2a39ab4e5fc57a03b5d2a0a588e93bc32 | 211,436 |
def k8s_url(namespace, kind, name=None):
"""
Construct URL referring to a set of kubernetes resources
Only supports the subset of URLs that we need to generate for use
in kubespawner. This currently covers:
- All resources of a specific kind in a namespace
- A resource with a specific name ... | 8d54770990fb500da1a42df891e21d1dce18bef9 | 684,334 |
def as_twos_comp(value: int) -> int:
"""Interpret number as 32-bit twos comp value."""
if value & 0x8000_0000 != 0:
# negative
flipped_value = (~value) & 0xFFFF_FFFF
return -(flipped_value + 1)
else:
# positive
return value | 013357f70dd51977d745e3d42ea33efc838c8515 | 439,967 |
def _has_exclude_patterns(name, exclude_patterns):
"""Checks if a string contains substrings that match patterns to exclude."""
for p in exclude_patterns:
if p in name:
return True
return False | 72c0401e1e7073a2ca42e1f99b98e4a1ab834bd3 | 690,023 |
def get_volumetric_scene(self, data_key="total", isolvl=0.5, step_size=3, **kwargs):
"""Get the Scene object which contains a structure and a isosurface components
Args:
data_key (str, optional): Use the volumetric data from self.data[data_key]. Defaults to 'total'.
isolvl (float, optional): Th... | 836fb5f3158ed5fe55a2975ce05eb21636584a95 | 705,838 |
import glob
import csv
def write_colocated_data_time_avg(coloc_data, fname):
"""
Writes the time averaged data of gates colocated with two radars
Parameters
----------
coloc_data : dict
dictionary containing the colocated data parameters
fname : str
file name where to store th... | 2e786c6df8a617f187a7b50467111785342310c5 | 708,019 |
def encode_file(body, filename):
"""
Encode a file in a binary form and return a mime content type
and encoded binary data
:param body: binary data to encode
:param filename: name of file with data to encode
:return: content_type, body
"""
boundary = '--------------MIME_Content_Boundary... | f19b6bc99c4d541eb5b9ec8228ea815d36e07ee4 | 500,770 |
def _format_config(file_value, effective_value, name=None, envvar_name=None):
"""
Construct a string to show on a terminal, indicating the value and
possibly other useful things such as the setting name and whether
it is being controlled by an environment variable.
>>> _format_config('x', 'x')
... | 1f76594ca31ddf522973580d09b74b7f093e6409 | 221,363 |
def split_ver(v):
"""Covert the string '1.2.3' into the list [1,2,3]
"""
return [int(x) for x in v.split('.')] | df9b1d4cc6c63cbf82cc0a06374f6a9e73702308 | 606,119 |
def polynomial_redshift(d):
"""
Polynomial approximation of calculating redshift corresponding to a given
distance.
Parameters
----------
d: float
A luminosity distance, in Mpc.
Returns
-------
z: float
The redshift corresponding to the input distance.
... | 87b313351551da98371d23de8b0122b83ecb1a72 | 255,195 |
import json
def parse_file(filepath: str):
"""[loads a json file and returns a python object]
Args:
filepath (str): [path to json file]
Returns:
[type]: [a python object]
"""
f = open(filepath)
data = json.load(f)
f.close()
return data | c56f3a8870a3583fd895b01dc3ca142263600dcb | 58,877 |
def is_alive(thread):
"""Helper to determine if a thread is alive (handles none safely)."""
if not thread:
return False
return thread.is_alive() | 9665f09b0c661d7ef0b65704ab8f501fff081cdd | 69,498 |
import base64
def b64e(s):
"""b64e(s) -> str
Base64 encodes a string
Example:
>>> b64e("test")
'dGVzdA=='
"""
return base64.b64encode(s) | 2562f5d18ac59bbe4e8a28ee4033eaa0f10fc641 | 701,446 |
from typing import Any
from typing import Tuple
def exec_command(node, **kwargs: Any) -> Tuple:
"""
Return the results of the command executed.
Args:
node: The node to be used for executing the given command.
kwargs: The supported keys are
sudo - Default false, root p... | e9ef5bbc4691143adbe0a41e6065231edfb54156 | 212,637 |
import torch
def all_params(model: torch.nn.Module) -> torch.Tensor:
""" Returns an array of all model parameters, given either from a Module or a state_dict """
return torch.cat([x.detach().view(-1) for n, x in model.state_dict().items() if n != "word_embeddings.position_ids"]) | 70c0a87784eb4e54d480c5b230ad44d32d0f1e10 | 551,612 |
def get_items(request, client):
""" Get items using the request with the given parameters
"""
# query results
result = client.quick_search(request)
# get result pages
items_pages = [page.get() for page in result.iter(None)]
# get each single item
return [item ... | f8b15e7d3f63cb4f1e42bfb15850f07d35fc6fe0 | 656,320 |
def compress(word):
"""
This function takes a string as an argument and returns a new string
such that each character is followed by its count, and any adjacent
duplicate characters are removed.
"""
result = ""
if len(word) == 0:
return result
else:
count = 1
for ... | 89d0686746a490a2b0e511862312de84f4e7d857 | 330,657 |
import math
def water_saturation_vapour_pressure_iapws(t):
"""Returns the water vapour pressure according to W. Wagner and A. Pruss (1992) J. Phys. Chem. Reference Data, 22,
783–787.
See http://www.kayelaby.npl.co.uk/chemistry/3_4/3_4_2.html
Valid only above the triple point. The IAWPS formulation 199... | aa424bc63b3165bc439dacbf8748f478654a15b2 | 696,592 |
def _capitalize(word: str) -> str:
"""Capitalizes the given word.
:param word: the word to capitalize
:return: the word with the first letter capitalized (any other uppercase characters are preserved)
"""
if word == "":
return word
return word[0].upper() + word[1:] | 8f16e0c1508525be3d5ce360e96b1b042ef12b29 | 584,972 |
def format_trec_results(qid: str, doc: str, rank: int, score: float, run_id='RunId'):
"""
Produce a TREC formatted str of results.
:param qid: Query Id
:param doc: Document
:param rank: Rank position
:param score: Ranking score
:param run_id: Name for this run
:return String in TREC form... | dc5095ab2a5d98c1d5096ebbd85e08e792bff477 | 56,572 |
import requests
def GetStockPriceJson(symbol, size, stock_key):
"""
Summary: Gets JSON response with stock data from AlphaVantage API
Inputs: symbol - string representing stock's ticker symbol
size - string denoting size of response, "compact" means 100 days' data will be returned, "full" mea... | 01218eace05ad1cd1f83dafc15f36a510aae825a | 239,368 |
def read_file(path):
"""Read entire file content as string."""
with open(path) as file:
return file.read() | a81082fa9e010c10e6490f672d28e1009c568f5c | 567,765 |
def add_relationship_to_entities(rel_map):
"""
Purpose:
define entity relationship
Args:
rel_map: the relationship map
Returns:
graql_insert_query - graql query
"""
graql_insert_query = (
"define "
+ rel_map["rel1"]["entity"]
+ " plays "
+ r... | 28c65d98b086ab9abd94f75a884feafa32d991cd | 532,167 |
def import_from(module: str, name: str):
""" Import a module with the given name (Equivalent of `from module import name`)
Args:
module (str): The namespace of the module
name (str): The name to be imported
Returns:
The imported class, function, and etc
"""
module = __impo... | a2632f58c0606b8fbc3500a70c6ed79c46c1a2c3 | 173,309 |
import math
def _(element: float):
"""
Handles Fortran NINT style rounding of a floating point value. Whether the
number is positive or negative, the integer portion of the number is
increased (without regard to sign) if the decimal portion of the number
is >= 0.5
"""
return (
math... | c14bc73881c1ee5729080c1e2b03e6203627ac1a | 408,770 |
def caps_from_underscores(string):
"""Converts words_with_underscores to CapWords."""
words = string.split('_')
return ''.join([w.title() for w in words]) | 66e56350026d14d23d3dfd9e28d46d8e12d06320 | 539,758 |
from typing import Callable
def pushcall(call: Callable, from_other_thread: bool = False) -> None:
"""pushcall(call: Callable, from_other_thread: bool = False) -> None
Pushes a call onto the event loop to be run during the next cycle.
Category: General Utility Functions
This can be handy for calls ... | b56b8d63bd265010e5daf94ee46e59bd194c13bf | 70,961 |
import json
def RenderValue(value):
"""Convert a Python value to a string with its JavaScript representation."""
return json.dumps(value, sort_keys=True) | 9e8f33f5d38a5c5e4c89e69fdbf270da39e538e2 | 568,027 |
def parse_keywords(strings=[]):
"""Parse keywords specifications from the given list of strings.
>>> kw = sorted(parse_keywords(['_', 'dgettext:2', 'dngettext:2,3', 'pgettext:1c,2']).items())
>>> for keyword, indices in kw:
... print((keyword, indices))
('_', None)
('dgettext', (2,))
('... | 59a47787000758e96a016e506dbabda2fa13756c | 550,114 |
def lookup_values_count(lookup_table):
"""
Return the number of value columns in a lookup table.
"""
# NOTE: ignore the first column, which contains the lookup time.
return lookup_table.dtype['value'].shape[0] | d5015c264094ef5a92a8ecca5147f7eb72981518 | 163,688 |
import time
def get_rfc3339_time(secs=None):
"""Return <secs> in RFC 3339 date/time format (pass secs=None for current date).
RFC 3339 is a subset of ISO 8601, used for '{DAV:}creationdate'.
See http://tools.ietf.org/html/rfc3339
"""
return time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime(secs)) | f0f2ea482ea01fbcd635b61406c584c0f7aad0cc | 397,882 |
def get_requires(filename):
""" Function used to read the required dependencies (e.g. in 'requirements.txt')
"""
requires = []
with open(filename, "rt") as req_file:
for line in req_file:
requires.append(line.rstrip())
return requires | 4c4df470846a2812e79fe5349371c287b3a5ea95 | 101,363 |
from typing import Counter
def sum_all_dates(counters):
"""Sum up all the counters for each court across all dates.
:param counters: A dict of name-counter pairs.
:return: A counter object with counts for every court across all dates.
"""
by_court = Counter()
for court, counter in counter... | ac3b5c2e1352507533fc0ddead3206a007ed7309 | 116,639 |
def filter_stories(stories, triggerlist):
"""
Takes in a list of NewsStory instances.
Returns: a list of only the stories for which a trigger in triggerlist fires.
"""
lists = []
for i in stories:
for triggers in triggerlist:
if triggers.evaluate(i)==True:
li... | a91aa78452fb0a75753a0687a7938a565b2b87f0 | 28,829 |
import math
def number_of_divisors(input_number):
"""Returns the number of divisors of input_number"""
res = 0
# check for square root divisor
if math.sqrt(input_number) % 1 == 0:
res += 1
# check for other integer divisors
for num in range(1, int(math.ceil(math.sqrt(input_number))))... | 44886479c4b9ea48ee3e5471b3341076e5e42ad5 | 430,493 |
def node_cmp(n1, n2):
""" Sort nodes by cost """
if n1.cost < n2.cost:
return -1
elif n1.cost > n2.cost:
return 1
# Returning 0 allows for stable sorting, i.e. equal objects stay in
# the same order, which should provide a bit of a performance boost,
# as well as a bit of consist... | fa4086eb819acb20b7da13a9ea479067748fc79f | 148,350 |
def cleanly_separate_key_values(line):
"""Find the delimiter that separates key from value.
Splitting with .split() often yields inaccurate results
as some values have the same delimiter value ':', splitting
the string too inaccurately.
"""
index = line.find(':')
key = line[:index]
value = line[index + 1:]
r... | d790f6bca2b52ee87bce01467a561901ba08655d | 41,527 |
from datetime import datetime
def int_to_date(d):
"""
Converts an integer representation of a date to a date object or None.
"""
if d == 0:
return None
return datetime.strptime(str(d), '%Y%m%d').date() | 421244c7fff05fbd9b2b96785abafd20672e7fab | 562,693 |
import string
def parse_letternumber(st):
"""
Parse CDMS's two-letter QNs
From the CDMS docs:
"Exactly two characters are available for each quantum number. Therefore, half
integer quanta are rounded up ! In addition, capital letters are used to
indicate quantum numbers larger than 99. E. g. ... | 2473fb314e5f16b4da81c1ce7535f0c23667ace3 | 97,231 |
def _unsigned_zero(dtype):
"""
Given a numpy dtype, finds its "zero" point, which is exactly in the
middle of its range.
"""
assert dtype.kind == 'u'
return 1 << (dtype.itemsize * 8 - 1) | 6fcbc9ec4c563beb9a7fbf50a29fd5960912498f | 124,449 |
def MinPositiveValue(data):
"""
This function determines the minimum positive value of a provided data list
Input:
- *data*
Output:
- *minimum positive value*
"""
return min([elem for elem in data if elem > 0]) | 845aa2ac786d987f470f829e36737e43334dddc0 | 128,705 |
def freq_in_kmskpc(vo,ro):
"""
NAME:
freq_in_kmskpc
PURPOSE:
convert a frequency to km/s/kpc
INPUT:
vo - velocity unit in km/s
ro - length unit in kpc
OUTPUT:
conversion from units where vo=1. at ro=1.
HISTORY:
2013-09-01 - Written - Bovy (IAS)... | 64f772917dfd78e1029e07d7987f9999bd171e39 | 602,964 |
import io
import json
def read_json_object(json_filename, encoding="utf-8"):
"""Reads and returns a single JSON object from the specified text file,
raising an error if the file cannot be parsed or if it does not contain
exactly one JSON object as a dictionary."""
# Strip comments while keeping line and colu... | b92f132c559218a0deac024d9870fc4fd4f43d5e | 199,017 |
def rivers_with_station(stations):
"""Returns a list of the names of rivers with a monitoring station"""
# Creates a set of rivers with monitoring stations
rivers = set()
for station in stations:
if station.river is not None:
rivers.add(station.river)
# Converts set into alphab... | c1a8f6d2fe140101600325297ba3e28239ef2bce | 258,395 |
import json
def load_json_data(response):
"""Decode json from response"""
return json.loads(response.data.decode('utf8')) | e49184794886c45a150c6e72a0cebd2cb0fc97b5 | 505,979 |
def trim(d, prepended_msg):
"""remove the prepended-msg from the keys of dictionary d."""
keys = [x.split(prepended_msg)[1] for x in d.keys()]
return {k:v for k,v in zip(keys, d.values())} | a7bf495750713a51c74dfd95dbbabcbab76f1910 | 34,587 |
def diplay_img_info(img, divisor, use_RGB):
""" This function displays the information of the image dimensions as a print"""
nr_z_slices = img.shape[1]
nr_timepoints = img.shape[0]
x_dim = img.shape[-2]
y_dim = img.shape[-2]
x_div = x_dim//divisor
y_div = y_dim//divisor
print(img.shape)... | 19119f7bcfcaa6e17ef3fedba76793dd05ac3f77 | 590,626 |
def RIGHT(string, num_chars=1):
"""
Returns a substring of length num_chars from the end of a specified string. If num_chars is
omitted, it is assumed to be 1. Same as `string[-num_chars:]`.
>>> RIGHT("Sale Price", 5)
'Price'
>>> RIGHT('Stock Number')
'r'
>>> RIGHT('Text', 100)
'Text'
>>> RIGHT('Te... | d45021b3d9f89d2cc5ad8533d194a8c6ead87d17 | 680,490 |
def build_texts_from_movies(path_to_movie_dat):
"""
Extracts genre text from movies.dat to create semantic embeddings
:param path_to_movie_dat:
:return: dict of text list keyed by movie_id
"""
texts = {}
with open(path_to_movie_dat, "r", encoding="ISO-8859-1") as f:
for line in f:
... | e98a8e5eedee7a983431246f0e4968d6f4daaa40 | 20,002 |
def perm(n, k):
"""Return P(n, k), the number of permutations of length k drawn from n
choices.
"""
result = 1
assert k > 0
while k:
result *= n
n -= 1
k -= 1
return result | 08dea796e3358ae490813baf7331ae10b30b0baf | 139,957 |
import re
def find_email(text):
"""
Extract email from text.
Parameters
----------
text: str
Text selected to apply transformation
Examples:
---------
```python
sentence="My gmail is abc99@gmail.com"
find_email(sentence)
>>> 'abc99@gmail.com'
```
... | c1ebb0d851576aebc277fa48f7e3d2569a695d31 | 56,236 |
def get_iface_speed(iface):
""" Converts iface speed from bps to DNS-friendly string """
speed = iface["iface_speed"]
if speed:
speed = int(iface["iface_speed"])
else:
return None
if speed < 1536000:
return None
elif speed == 1536000 or speed == 1544000:
return "... | 16149a97b76b7f7a61433c665d5ca222c95ec01d | 608,506 |
import re
def is_valid_id(id):
"""checks if an id is valid
Args:
id (str): The id of a note
Returns:
bool: True if the id is valid
"""
if re.match(r'^[0-9a-f]{9}$', id):
return True
else:
return False | 449868ff3198b39d69721a336a451ed64d9d1c20 | 578,069 |
import random
def _sample(iterable, sample_count):
"""
Choose a random sampling of items from an iterator.
(you will get Nones if sample_count is less than iterable length)
"""
rand = random.SystemRandom()
result = [None] * sample_count
for i, item in enumerate(iterable):
if i < ... | 8897c7acd7ddd6bce41c563861be95922fdcac7e | 384,209 |
def nearest_index(index_array, value):
"""Find the position in an increasing array nearest a given value."""
# find the index of the last data point that is smaller than the 'value'
# we are looking for ....
ind1 = len(index_array.compress(index_array < value))
# if we are at the very end of the a... | 185c5b898a49663b97f6dc690c053b8acf342d9a | 351,775 |
def build_template(cfg: dict) -> dict:
"""
Build string's template dictionary
:rtype: dict
:param cfg: representation of the config
:return: dictionary to be used with Template().substutute() function
"""
task = cfg['main']
def concat(*dictionaries: dict) -> dict:
res = dict()
... | 48d62dc71d7d0a7bc7cb186696afc4a5800cb83c | 485,290 |
import torch
def extract_kpt_vectors(tensor, kpts, rand_batch=False):
"""
Pick channel vectors from 2D location in tensor.
E.g. tensor[b, :, y1, x1]
:param tensor: Tensor to extract from [b, c, h, w]
:param kpts: Tensor with 'n' keypoints (x, y) as [b, n, 2]
:param rand_batch: Randomize tenso... | fa80de574fe369b770807d8a273e295ca395a9c5 | 217,000 |
def extract_episode_details(season, episode_response):
"""Clean and extract episode details response.
Take an episode details response and cleans the data.
Extract the relevant fields needed to construct an
Episode object.
Args:
season: The season number
episode_response: An episod... | dc236736d69a1521961adf09ad871a4b1c0a49d4 | 593,288 |
def find_anychar(string, chars, index=None, negate=0):
"""find_anychar(string, chars[, index]) -> index of a character or -1
Find a character in string. chars is a list of characters to look
for. Return the index of the first occurrence of any of the
characters, or -1 if not found. index is the inde... | 3ea0ad8f0d8eb45d1dc9834f577404b9e7a06492 | 142,753 |
def datetime_to_estudent(date):
"""Take a datetime object and return a compatible string.
(2017, 5, 4) -> 04-May-2017
"""
string = date.strftime('%d-%b-%Y')
return string | 0e2e271e937a32b8690dfe486c6161886c557e3e | 119,697 |
def get_columns(api, config):
"""
Get the trello column ids for a trello board given a api handle and the id
of the board.
:param api: A trollo Boards api handle.
:param dict config: The configuration data (see note below for details).
:return: A tuple of column trello ids
.. note::
... | 524755b8f0c9ea0aa25c07bc5f9b2e16373a682a | 244,584 |
import csv
def get_header_csv(csv_file, cols_delimiter):
"""
Get header of a csv
:param csv_file: path to the csv file
:param cols_delimiter: delimiter between columns
:return: header of csv as a list of strings
"""
with open(csv_file, "r") as f:
reader =... | bb8adef2b73b4d84d29469927f0b964fc6b10349 | 449,943 |
def estimate_norm(X):
"""Estimates the mean and standard deviation from a data set
Parameters:
X : numpy.ndarray
A 2D numpy ndarray in which the rows represent examples while the
columns, features of the data you want to estimate normalization
parameters on
Ret... | db9ce74adeed6ef891a1b339c323d98cdac94fe4 | 175,510 |
def format_pval(pval, significant_figures=2):
"""
Helper function to format pvalue into string.
"""
return '{:g}'.format(float('{:.{p}g}'.format(pval, p=significant_figures))) | ebe7f11265360d1033d6b8eb5a81b86794ebb1ca | 492,398 |
def find_null_net_stations(db, collection="arrival"):
"""
Return a set container of sta fields for documents with a null net
code (key=net). Scans collection defined by collection argument.
"""
dbcol = db[collection]
net_not_defined = set()
curs = dbcol.find()
for doc in curs:
i... | 582dc0a0b14e091e3b54fb3c2040669216ec4bf5 | 24,460 |
from pathlib import Path
def coffee_layout_dir(testdata: Path) -> Path:
"""
Returns the layout directory containing:
- has-multiple-sizes -- coffee-inspired sizes
- has-only-one-size
"""
return testdata / "layouts" | 0e471b5f1e6fdab17f981cae82110f5990d920f4 | 262,331 |
def maximum_toys(prices, k):
"""https://www.hackerrank.com/challenges/mark-and-toys/problem
Mark and Jane are very happy after having their first child. Their son loves toys, so Mark wants to buy some. There
are a number of different toys lying in front of him, tagged with their prices. Mark has only a cer... | c236fc2dd102c2f63a864a1bd477b2f3d6565ea7 | 416,304 |
def harm(x,y):
"""Harmonic mean of x and y"""
return x*y/(x+y) | 7054a8a05e6d20fa39efd31ac62a5d5c4c51f061 | 680,201 |
from typing import Type
from typing import Iterable
from typing import Optional
import inspect
def get_closest_parent(target: Type, classes: Iterable[Type]) -> Optional[Type]:
"""
Find which class in given list is the closest parent to
a target class.
:param target: class which we are comparing of
... | 5048ed91e3d7790b445b749e23a29d66437b11e6 | 257,590 |
def extract(num):
"""
Given a max 3 character number, extract and return hundredth, tenth and one value
Parameters
----------
num: string
Number in string
Return
----------
hundredth: int
Hundredth number
tenth: int
Tenth number
one: int
One numb... | d03c6068619ed8e901474ad74aaad7a30d2b0353 | 381,239 |
def bb_frontprint(bb):
""" Returns a rectangle that defines the front face of a bounding box.
"""
x1,y1,z1 = bb[0]
x2,y2,z2 = bb[1]
return (x1,z1), (x2,z2) | 303e31711fcd647e6f5523902f0c3a60accbdd19 | 562,318 |
import re
def get_template_keys_from_string(template_string):
"""
Retrieve all the keys from the template string which are identified by '{{ <key_name> }}'.
:param template_string: the template in a string
:type template_string: string
:return: the list of the template keys corresponding to secre... | e63864590d6a4d1dfc7439a306186f409f325c3b | 508,388 |
from typing import List
from typing import Tuple
def count_stats(errors: List[str]) -> Tuple[int, int]:
"""Count total number of errors and files in error list."""
errors = [e for e in errors if ': error:' in e]
files = {e.split(':')[0] for e in errors}
return len(errors), len(files) | 93e4cd6fce6d484f1a18d924931ec04c4463ea7f | 462,455 |
import uuid
def generate_job_id(group_uuid):
"""
Generates a job ID
"""
return "{}.{}".format(group_uuid, uuid.uuid4()) | a0aab5e36899930af720e156e0856b43041b5f67 | 65,302 |
def factorial_iter(n: int):
"""Iteartively compute factorial of n."""
result = 1
for i in range(1, n+1):
result = result * i
return result | 31a30f71161a5a840e9db9ef6d1d2459e41e83dc | 282,683 |
def keys_to_ints(d):
"""
Takes a dict and returns the same dict with all keys converted to ints
"""
return {int(k): v for k, v in d.items()} | 17088f54c5808e42c0d6589cea8829c6819ccc7e | 123,750 |
import copy
def expand_list(list_1d: list) -> list:
"""Expand 1d list to 2d
Parameters
----------
list_1d : list
input list
Returns
-------
list_2d: list
output 2d list
"""
list_2d = copy.deepcopy(list_1d)
if not isinstance(list_1d[0], list):
list_2d =... | 5c594076650dbc2a50be64cbb5cb55ea2f6d184f | 72,826 |
from typing import Union
def _prepare_positions(position_start: Union[int, None],
position_end: Union[int, None],
aln_len: int) -> dict:
"""
Prepare a dictionary with start and end position for sequence trimming.
Arguments:
position_start (int, None):... | b299ae7e5d4b57cd9ba8174a39ab7d3057aa850f | 464,005 |
def axprops(dct):
"""Filters `dct` for properties associated with a plot axes.
Example:
>>> # Note how kwargs gets split into axes/line properties.
>>> def myplotter(ax, x, y, **kwargs)
>>> ax.set(**axprops(kwargs))
>>> ax.plot(x, y, kwargs)
"""
# List of included axis properti... | 8eeaf0814a08a325cdee9f58272c19f4ae12c88e | 122,969 |
def series_is_type(series, type):
"""Checks whether the given column is of the provided python type
Args:
series (pd.Series):
type: A python type
Returns:
bool
"""
idx = series.first_valid_index()
if idx == None:
return False
else:
return isinstance(... | 7f1d76912d3f5cad85a6057bd2068b8810b19afe | 234,487 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.