content stringlengths 39 14.9k | sha1 stringlengths 40 40 | id int64 0 710k |
|---|---|---|
def read_bib(fname):
"""Reads in .bib file"""
print("Reading {}".format(fname))
with open(fname, 'r') as bibfile:
data = bibfile.read()
return data | a39bed3ad6feee5f2ad19d12ae49ff01f0fc40df | 73,809 |
def admin_pc_client(admin_pc):
"""Returns the client from the default admin's ProjectContext """
return admin_pc.client | e870e216b7a21c9e879d1bd12a5255f224c62310 | 73,811 |
def isascii(s):
"""Returns True if str s is entirely ASCII characters.
(Compare to Python 3.7 `str.isascii()`.)
"""
try:
s.encode("ascii")
except UnicodeEncodeError:
return False
return True | ab0969a89ebdf23b8c6ec2d34ecd3f67b616b30a | 73,812 |
import random
def random_range(max):
"""
A range from 0 to a randomly chosen end between 1 and `max`. The smallest range would thus be `range(0, 1)` while
the largest would be `range(0, max)`.
"""
assert max >= 1, f"max {max} must be greater than or equal to 1"
return range(0, random.randint(... | a82bcc620a0307b2e06298c935e159b50df68428 | 73,814 |
def validate_etextno(etextno):
"""Raises a ValueError if the argument does not represent a valid Project
Gutenberg text idenfifier.
"""
if not isinstance(etextno, int) or etextno <= 0:
msg = 'e-text identifiers should be strictly positive integers'
raise ValueError(msg)
return etext... | 2a6c479f66651d2b84b6551fc1888a248d1df00d | 73,815 |
def merge_two_dicts(x, y):
"""A quick function to combine dictionaries.
Parameters
----------
x : dict
Dictionary 1.
y : dict
Dictionary 2.
Returns
-------
dict
The merged dictionary.
"""
z = x.copy() # start with keys and values of x
z.update(y) ... | 539ca0fae147943a6c33c761303c96e829e8f45d | 73,816 |
def is_next_south_cell_empty(i, j, field):
"""
check if next below cell is empty
:param i:
:param j:
:param field:
:return: True if next below cell is empty, False otherwise
"""
if i == len(field) - 1:
if field[0][j] == '.':
return True
return False
if fie... | 4b06dcba61eff2769fd78176f259f79e98ca2a1d | 73,817 |
def _channel_info_to_flattened_name(channel_info):
"""
Simple method to generate a flattened channel name.
"""
if channel_info['start_index'] == -1:
return channel_info['base_name']
elif channel_info['start_index'] == channel_info['end_index']:
return '{0}{1}'.format(channel_info['ba... | a2e767ef98d9d843c93b3548c88f0ec1be582e0f | 73,822 |
def get_normalized_hostname(env):
"""
Get the best hostname we can find in the provided environment.
If the request came in on an alternate port, it will be
appended to the result.
"""
host = env.get('HTTP_HOST', env['SERVER_NAME'])
if(host.find(':') == -1):
host += ':' + env['SERVER_PORT']
return host | a175e8437d10a1b9e7ce66b24d9023963b87a20c | 73,829 |
def _centered_text_position(img, num_lines, line_height):
""" Center text in the middle of the image depending on how many lines the text is """
x_position = 15
textbox_center = num_lines*line_height/2
image_center = img.height/2
y_position = image_center - textbox_center
return (x_positio... | 83cde42f954b0dd84a26adce9169dc343f75b0ef | 73,830 |
def fake_idtoken_processing_hook3(id_token, user, token, **kwargs):
"""
Fake function for checking scope is passed to processing hook.
"""
id_token['scope_of_token_passed_to_processing_hook'] = token.scope
return id_token | 7f7dcd367936d77c473b36cd0b9aaefa6ff6b7ca | 73,833 |
from typing import Optional
from typing import Union
from typing import List
def _check_pattern_list(
patterns: Optional[Union[List[str], str]],
key: str,
default: Optional[List[str]] = None,
) -> Optional[List[str]]:
"""Validate file search patterns from user configuration.
Acceptable input is a... | a5156afd8d30babac062e0628309160acd5068a4 | 73,835 |
def get_task_run_df(enki, task_id):
"""Return a dataframe containing all task run info for a task."""
enki.get_tasks(task_id=task_id)
enki.get_task_runs()
task = enki.tasks[0]
return enki.task_runs_df[task.id] | fb7b5832ce38219b00ab2314527b806ccb68b277 | 73,838 |
from typing import List
import torch
def collate_fn(batch_items: List[dict]):
"""
Collate and pad fields in dataset items
"""
x, y = [], []
input_specs_lengths, output_text_lengths = [], []
texts = []
audios = []
sample_rates = []
for i in range(len(batch_items)):
x.append(... | cfb36a8ad0033f435d8b8ffa369d3cf85e7b27ca | 73,839 |
def number_to_name(number):
"""Take integer number as input (0-1-2-3-4) and returns string (rock-spock-paper-lizard-scissor)
"""
if number == 0:
return "rock"
elif number == 1:
return "spock"
elif number == 2:
return "paper"
elif number == 3:
return "lizard"
... | e0a5dd4ceb35ee0d7c2f86f95fb34f4bf1fe2da3 | 73,849 |
import math
def cooccur_probability_fn(counts):
"""Returns function for computing entailment probability.
Args:
counts: Dict mapping unigrams / bigrams (joined using "|||") to their
counts.
Returns:
Function handle to compute entailment probability.
"""
def _cooccur_probability(ngram, table... | 5919365b2142ddb86ffaf11966c9e72d7dc22971 | 73,851 |
def scaling_term(k, n):
"""Term that scales measure between zero and one
k size of the neighbourhood
n number of datapoints
"""
if k < (n / 2.0):
return 2.0 / ((n * k) * (2 * n - 3 * k - 1))
else:
return 2.0 / (n * (n - k) * (n - k - 1)) | bc29fd056811196ec2212f248761a847e0cce9c9 | 73,860 |
def chunk(vs, size):
"""Chunk list `vs` into chunk of size `size`"""
chunks = [vs[i : i + size] for i in range(0, len(vs), size)]
if not chunks or len(chunks[-1]) != size:
raise ValueError(f"list {vs} can not be chunked in {size}s")
return chunks | 3e6b0938db4898503c36544a7b87896b0bfad59f | 73,865 |
def _basify_factors(factors):
"""Convert `(f_i, k)` factors to Basic expressions. """
if type(factors) is tuple:
return factors[0], [ (g.as_basic(), k) for g, k in factors[1] ]
else:
return [ (g.as_basic(), k) for g, k in factors ] | 40a4090bfc7fb72794f888f7f39ea7e64e5f99d2 | 73,868 |
import logging
def process_response(response, records):
""" Examines the response from PutRecords, returning any records that couldn't be sent.
"""
if response['FailedRecordCount'] == 0:
return []
result = []
dropped_record_count = 0
for ii in range(len(response['Records'])):
... | 45e19dccbb6d77c5fe8b5ff6849bab3801da0ac1 | 73,869 |
from datetime import datetime
def recast_timestamp(ms: int):
"""Recast millisecond epoch offsets to DateTime"""
try:
return datetime.fromtimestamp(ms / 1000.0)
except TypeError:
return None | 6d89074ad13e7eb0e96949b8463015fda1124e45 | 73,874 |
def apply_mask(values, mask):
"""
Convenience method to filter out values from a list according to some binary masking array.
@param values: The list that should be filtered.
@param mask: The masking array, must have the same length as the `values` array.
@return: A list that contains only the selec... | 4651b627b24730392dae98bc0502672a551a101c | 73,878 |
def imgstr(imgloc):
"""html img tag"""
istr = ('<div style="display: block; text-align: left;">'
'<a href="{0}"><img src="{0}" border="0" height="200"></a></div>')
return istr.format(imgloc) | 1d61f89286d7a558d822a6ef11ab095592eee6a2 | 73,879 |
import random
def k_fold_cross_validation(k: int, num_data: int, shuffle: bool = True) -> tuple:
"""
Splits a number of training data into k folds, which can be used for k-fold-cross-validation.
Parameters
----------
k: number of folds for cross validation.
num_data: Total amount of data value... | 022028007bc553dcd383147ff59c0a2883b33783 | 73,888 |
def get_bpath(f):
"""
Return a string that corresponds to the base path of the data.
NB: For openPMD 1.0.0, the basePath is always of the form
'/data/%T' where %T is replaced by the actual iteration which
is present in the file.
Parameters:
-----------
f: am h5py.File object
"""
... | 5ea70083d6b7294e109fa0483e8f332fd555d387 | 73,894 |
def get_permission_codes(permission_resources):
"""
Generate a list of resource code that the user can access to
:param permission_resources: Resources that user can access to
:return: a list of resource code that the user can access to
"""
permission_codes = []
for resource in permission_r... | ec33d2ec28d0ffa02e3b92a29fa8b3b0fd5203ac | 73,895 |
def parse_ratings(ushpa_data):
"""
Parse ushpa data from bapa.services.ushpa.get_pilot_data
to return a string such as 'P2, H3'.
"""
rating_dict = {
'BEGINNER': '1',
'NOVICE': '2',
'INTERMEDIATE': '3',
'ADVANCED': '4',
'MASTER': '5'
}
pg = ushpa_data.... | 74bfe8ca352f22fdead8119cb815a26c929ae47d | 73,897 |
def smooth(x, y):
"""
Smooth a curve
"""
xs = x[:]
ys = y[:]
d = 0
for i in range(0, len(ys)):
num = min(len(ys), i+d+1) - max(0, i-d)
total = sum(ys[max(0, i-d):min(len(ys), i+d+1)])
ys[i] = total/float(num)
return xs, ys | 0e0b9b030413bb14a930ac86b55d5a3949826df6 | 73,898 |
def flatten_dict(nested: dict) -> dict:
"""Take a nested dictionary and flatten it. For example:
{'a': {'b': 'c'}} will be flattened to {'a_b': c}
Args:
nested: a dictionary to be flattened
Returns:
Dict. flattened version of the original dictionary
"""
ans = {}
for key, val... | 1c3e37ed3aad9838c20a02e7757e3fe47d4e4513 | 73,899 |
def ns(state, *namespaces):
"""Set command namespaces to be included
By default only the root namespace is enabled. The 'ns' command enables commands present in specified namespaces.
This works by setting "active_namespaces" state variable.
The "root" namespace is appended to the active_namespaces if n... | 711f74b2555b398f60336391bd0d52165131a4b6 | 73,900 |
import typing
def reset_database() -> typing.List[str]:
"""
Returns a statement that resets the database, i.e., deletes everything.
Returns
-------
out: str
Neo4j statement
"""
return ['MATCH (n) DETACH DELETE n', 'CALL apoc.schema.assert({},{},true)'] | 617e9ddbf0e658136fea6b64c12c032d1447e1d3 | 73,901 |
def rebin(image, rebinned_shape, factor):
"""
Parameters
----------
image : 2D np.array
the larger PSF grid
rebinned_shape : iterable with size 2
shape of the image after rebinning
factor : int
smoothing factor
Returns
-------
2D np.array
the rebinne... | 73464543d11b09ce6af2b1f60b7d735349002f77 | 73,902 |
def smart_truncate_l(content, begin_index=0, prefix='') -> str:
"""
truncate a text from the left, splitting at word boundaries.
this means that the start of the text may be removed.
:param content: the content to truncate
:param begin_index: the string index to begin at. If the character at the ind... | 4d8691d6ee3a7b5157568d0c64d376740c0fddda | 73,906 |
def parse_lookup_table(lookup_table_file):
"""Parses a lookup table to determine regions.
This allows the hemisphere splitting to adapt with updated lookup tables.
:param lookup_table_file:
:return:
"""
labels_dict = dict()
with open(lookup_table_file, "r") as lookup_table:
for line... | 6960dddbe5e76120d2c18f5ebf951ea59e0d1a93 | 73,908 |
import torch
def seq_mask_from_lens(lengths, max_len=None):
"""
Creates a boolean mask from sequence lengths.
If the `lengths` is of shape (...), the `mask` is of shape (..., max_len).
The last dimension is of shape (max_len) and consisting of consecutive
`True`s and `False`s. The number of `True`... | 1f606b30d95ed6255249b63dc97a1ac2c2bc4346 | 73,909 |
from typing import Union
def next_page(page: str) -> Union[None, str]:
""" Given the contents of a Letterboxd page, returns
the relative path to the next page to parse. It
handles the pagination of any type of page,
from followers, to following, to movies watched,
etc.
Ret... | f0d041548a91553a512907f951813912a50f6182 | 73,915 |
def merge(*dicts):
"""Returns a dict that consists of the rest of the dicts merged with
the first. If a key occurs in more than one map, the value from the
latter (left-to-right) will be the value in the result."""
d = dict()
for _dict in dicts:
d.update(_dict)
return d | 9a624f0b440b1bf0281918abaa7988968495a39d | 73,917 |
def get_human_readable_resolution(ds):
"""Get human readable resolution string
Returns a human readable resolution string.
I.e "1 km", "500 m" or "0.1 deg".
Requires the resolution to be available by 'rioxarray'
Parameters
----------
ds : xr.DataSet
The dataset to read the... | c12ac11f13d347a35e180a1a6081cdf3f7a09a9a | 73,919 |
def _normalize_scale(t, a=0, b=1):
"""Perfoms an afine translation to normalize an interval.
Args:
t (numpy.ndarray): Array of dim 1 or 2 with at least 2 values.
a (float): Starting point of the new interval. Defaults 0.
b (float): Stopping point of the new interval. Defaults 1.
Re... | 5330539ba857b5d6c7759ae99a63b29c817b216e | 73,923 |
def colourful_text(text, color):
"""add color to text
Args:
text (str): [description]
color (str): red, green, yellow, blue, black, none
Returns:
str: coloured text
Examples:
>>> s = String()
>>> s.colourful_text("比如Convolutional Neural Network,CNN对应中文是卷积神经网络。"... | 52d13e28f728b9a51fb587e9fc0e05ffaafa3de6 | 73,925 |
def max_seq_len() -> int:
"""Mock maximum sequence length."""
return 8 | 1f58c6cab80e750af42a9b3fccf80cb73f6b49c7 | 73,931 |
def get_symbol_name(symbol):
"""Returns __name__ attribute or empty string if not available."""
if hasattr(symbol, "__name__"):
return symbol.__name__
else:
return "" | a2ffae1dba71ab83b61ba933fde36e6448a47c68 | 73,932 |
def date2String(date_time):
"""This function is used to take a datetime object and convert it to a string
representing the month, day, and time in 12 hour form"""
day = str(date_time.strftime("%b")) + " " + str(date_time.day)
time = date_time.strftime("%I:%M %p")
displayDate = day + ", " + time
... | c5ce14d7bc2603d1068ac4309035b6cf36d660b0 | 73,940 |
def is_array_field(test_dataframe, test_field):
"""Tests if the column test_field in test_dataframe is an array field
:param test_dataframe: dataframe to test
:param test_field: column name to test
:return: True or False
"""
if test_dataframe.empty:
raise ValueError("No data saved from d... | 285416097ec68c5f4d4231d0d65bb830fd35ccc0 | 73,943 |
def mirror_lines(string):
"""Given a multiline string, return its reflection along a vertical axis.
Can be useful for the visualization of text version of trees."""
return '\n'.join(line[::-1] for line in string.split('\n')) | e02ea859e44a7d7d779d26a177710bc1bcc201af | 73,948 |
def raster_preparation(purged_spike_train, event_start_frames,
camera_framerate=120., window_size=10):
"""
Parameters
----------
purged_spike_train : np.ndarray
The spike train without spikes that precede or succeed tracking, relative to tracking start.
event_start_fra... | 3dda58b7cd95a399623ef7572f228adef1762634 | 73,949 |
def _name(ii):
"""Use this to make the model name for source number `ii`."""
return 'gauss2d.source_{0:02d}'.format(ii) | 90aab1b92d592609c5a4325f69d05f1121f844f6 | 73,953 |
import errno
def is_out_of_memory_error(exception):
"""Returns true iff exception is an instance of OSError and error code represents an out of memory error."""
return isinstance(exception, OSError) and exception.errno == errno.ENOMEM | d840b856a85d6a5ba669f7f9ec239b83e63f782d | 73,960 |
def GetBuildLogPathInGCS(logs_folder, build_id):
"""Gets a full Cloud-Storage path to a log file.
This is a simple convenience function that mirrors the naming convention that
the Blueprints Controller API uses for log files.
Args:
logs_folder: string, the full Cloud Storage path to the folder containing
... | e866ee3f58d79ab82e089fcdc5170b16bfd9d43a | 73,962 |
def convert_force(voltage):
"""
Formula used to convert sensor data voltage reading into Newtons as per
predetermined sensor calibration curve
Calibration curve - Oct 24 2018
grams N voltage
0 0.000 298.7
100 0.981 334.2
300 2.943 405.9
500 4.905 47... | e3a9a12b24e42496454c6e5fcb6704f896638ed7 | 73,963 |
def is_a_power_of_2(x: int) -> bool:
"""Check if an integer is a power of two.
Args:
x (int): Number to check
Returns:
bool: True if the number is a power of two
"""
# https://stackoverflow.com/questions/57025836/how-to-check-if-a-given-number-is-a-power-of-two
return x > 0 an... | 3a5ca905740945628832c5d428fcf2d9e699bb65 | 73,964 |
def create_export(service, matter, request_body):
"""
Creates an export in the given matter, with the given request_body (which is the actual JSON for the request).
"""
return service.matters().exports().create(matterId=matter, body=request_body).execute() | ddc6abe6452f41ae86390d98220a697c82c58dcb | 73,966 |
import math
def poisson_prob(n, _lambda):
"""The probability of k occurrences of a random variable having poisson distribution with expected value mu
:param n: number of occurrences
:type n: int
:param _lambda: expected value
:type _lambda: int
:return: probability of k
:rtype: float
... | 378e327a1d3524bccb900fc61585514ebc999d61 | 73,975 |
import hashlib
def read_hash_local(weights):
"""Reads local SHA256 hash from weights.
Parameters
----------
weights : str or pathlib.Path
Path of the file containing weights.
Returns
-------
local_hash : str or None
SHA256 hash of weights file.
Notes
-----
Re... | c3e2ef7e2b747b73c7d0aadd5a3883556870893f | 73,978 |
def is_even(x: int) -> bool:
"""Checks if x is an even number"""
return x/2 == x // 2 | b08f8c62c22481d1ae0b148bc07b63bbba2c1ae7 | 73,980 |
from sympy.polys.domains import QQ
def dup_content(f, K):
"""
Compute the GCD of coefficients of ``f`` in ``K[x]``.
Examples
========
>>> from sympy.polys import ring, ZZ, QQ
>>> R, x = ring("x", ZZ)
>>> f = 6*x**2 + 8*x + 12
>>> R.dup_content(f)
2
>>> R, x = ring("x", QQ)... | 5380f740421dab0ddf5d5892d090c252447725b5 | 73,982 |
def slashappend(s):
"""Append "/" to 's' if it doesn't aleady end in "/"."""
if s and not s.endswith('/'):
return s + '/'
else:
return s | 12ac5cde7b2a5ddf18be25e34602b047dc14a633 | 73,985 |
import torch
def get_bert_sentence_embeddings(encoded_layers):
"""Obtain sentence embeddings by averaging all embeddings in the second last layer for a sentence."""
sent_emb = torch.mean(encoded_layers[-2], 1)
return sent_emb[0] | 5ca57a542b3336192ec38a58c040a4c4727e137b | 73,992 |
def avg_mutation_rate(alignment :list):
"""
Counts number of POLYMORPHIC sites on an alignment.
-> no distinction on whether mutation carried by 1 or several sequences
Used to estimate the age of the most recent common ancester.
Parameters:
alignment (list): !should be a compatible ... | e1586ebab8e2fb2c4ef72dec21fc922d24dd2e97 | 73,996 |
def normalize(data, reference):
"""
Normalize data according to a reference data's mean
and standard deviation
"""
return((data-reference.mean())/reference.std()) | 455f6aa9b29a18341a68d82883767a49799bffe5 | 73,998 |
def is_same(text0: str, text1: str, ignored: list):
"""Compare the content of two text. If there are different words in text0 and text1 and the word in text0
does not contain ignored substring, return False. Else return True."""
def should_ignore(word):
for w in ignored:
if w in word:
... | 870453a917f8e3a1eff3918f5c69662fde6b65d1 | 73,999 |
def find_pudc_b(db):
""" Find PUDC_B pin func in grid, and return the tile and site prefix.
The PUDC_B pin is a special 7-series pin that controls unused pin pullup.
If the PUDC_B is unused, it is configured as an input with a PULLUP.
"""
grid = db.grid()
pudc_b_tile_site = None
for tile... | c7b528ec9f5fbe636663e78ea5bb671e3c8fc36e | 74,000 |
import re
def clean_name(naam):
"""
Clean the name of a company to get a better match with the url
Parameters
----------
naam: str
Original name of the company
Returns
-------
str:
Clean name
"""
# de naam altijd in kleine letters
naam_small = naam.lower()... | c76026f6d7f2bf205974cafc6c4e17a5bb6552e2 | 74,001 |
import re
def extract_result_types(comment):
"""Extracts a list of result types from the given comment.
We allow annotations in the comment of the matcher to specify what
nodes a matcher can match on. Those comments have the form:
Usable as: Any Matcher | (Matcher<T1>[, Matcher<t2>[, ...]])
... | beebb985abedef560868b8cdd9d84a1c423eaa8d | 74,008 |
def tra_number_atoms(snapshots):
"""
Get atom number, time and iteration from multiple snapshots.
Args:
snapshots (list[:class:`.Snap`]): snapshots the atomic information
Returns:
(tuple): tuple containing:
- list[int]: number of atoms in each snapshot
- list[f... | 10f2600c354bbf0126e7a5127d4ac348a3190b82 | 74,012 |
import hashlib
def generateCbsdReferenceId(fcc_id, serial_number):
"""creates encoded cbsd_reference_id using sha1 with fcc_id and serial number of cbsd.
"""
return str(fcc_id + '/' + str(hashlib.sha1(serial_number).hexdigest())).encode('utf-8') | aa82c669d1e73e09fa878fab7d73198158e4e72e | 74,014 |
def make_generic_usage_message(doc):
"""Construct generic usage error
:param doc: Usage documentation for program
:type doc: str
:returns: Generic usage error
:rtype: str
"""
return 'Unknown option\n{}'.format(doc) | dfa60740a3504440ba6a58f96a464b76b4fd9f95 | 74,015 |
def _getAction(subAssignments):
"""
Given a group of assignments with same odID, find if this group is stationary/vertical/move. Each will be treated differently in cesium and folium.
Parameters
----------
subAssignments: :ref:`Assignments`
An assignment dataframe with the same odID
Return
------
string
... | 8d49bbdda4345a282d9cdb9bc026108be6acfc97 | 74,018 |
def create_sudoku(filename):
"""
Creates a list from an input file of integers.
Exits the application if wrong format is given as input.
A correct inputfile consists of integer values separated by spaces,
as instruced per assignment.
Parameters:
filename (string): Filename that holds the su... | 03a374fb4e589a12ce871d69237e66ba1b499ce5 | 74,021 |
import time
import random
import math
def slow_prime_check(number):
"""This function is an intentionally slow and simple prime number check."""
# average wait time ~50ms.
time.sleep(100 / 1000 * random.random())
for i in range(2, int(math.sqrt(number)+1)):
if number % i == 0:
ret... | 2440ce2d07eed954ce30b69f2bf29230b19f3506 | 74,025 |
def _strip_prefix(path, prefix):
"""Strip prefix if matched exactly."""
if path.startswith(prefix):
path = path[len(prefix):]
return path | 5b164b07a384dba038fc48ba0381c3be73d05ea5 | 74,026 |
def make_reg_05h_byte(channel: int) -> int:
"""
Make the byte for REG2 (channel)
Channel control (CH) 0-83. 84 channels in total
18 default for SX1262, 23 default for SX1268
850.125 + CH *1MHz. Default 868.125MHz(SX1262),
410.125 + CH *1MHz. Default 433.125MHz(SX1268)
:param channel: The... | b03fe31af5c3708c069a8eeb62db970f2af7667f | 74,034 |
def gemerate_database_info(inputs, targets, allow_unfound=False):
"""
Construct db info from input nodes and target nodes.
:param inputs: list of input nodes
:param targets: list of target nodes
:param allow_unfound: don't check if names are valid
Builds a list of the db names for the nodes.
... | 25c0a82a4cd87c56b914057d8ab102ddb3ca5531 | 74,038 |
import torch
def optimal_symmetric_circulant_precond_column(
col_toeplitz: torch.Tensor,
) -> torch.Tensor:
"""
compute the first column of the circulant matrix closest to
the Toeplitz matrix with provided first column in terms of the
Froebenius norm
"""
n = col_toeplitz.shape[-1]
b = ... | 616cc4663207579b5dd130fa817d0def9c133ded | 74,040 |
from typing import Dict
def map_values(d: Dict, fn) -> Dict:
"""
Run `fn` over values of `d` and return new dictionary.
"""
return {k: fn(v) for k, v in d.items()} | d48d59d5754a3cfa2a8de71635f31808dd1a617c | 74,041 |
import json
def json_decode(s):
""" Decodes a json string to a dict. """
if not s:
return None
return json.loads(s) | 9549e6a0f6615fcbb8d7f5ec0687ac1bc3626079 | 74,042 |
def default_rule(pk):
"""Set default operator."""
return pk.operators["2.7.1.a"] | 15f236737340e714b75173ed2ad323ea434bf385 | 74,043 |
import requests
def list_owned_scenes(user_id, jwt):
"""
List all owned scenes
Args:
user_id: rfclient.owner
jwt: rfclient.api.api_token
Returns:
list of scenes
"""
def make_request(headers, page, page_size=1000):
return requests.get(
'https://{host}... | dfdbd6fe80b3a9ad6da1e7f7bd9d0df690239245 | 74,047 |
def _unique_parnames(names):
"""
Given a list of parnames, including possible duplicates, returns a new list
of parnames with duplicates prepended by one or more underscores to make
them unique. This is also case insensitive.
"""
upper_names = set()
unique_names = []
for name in names... | fd5359b524c56ec2fddb1e002213cb826c608444 | 74,048 |
def vector_addition_cpu(size, scalar, in_a, in_b):
"""VectorAddition CPU implementation."""
return [in_a[i] + in_b[i] + scalar for i in range(size)] | ca5c00887b0f19c60eebcd39d623e654928806d3 | 74,057 |
from pathlib import Path
def get_rel_path_len(data_root: str, fpath: str) -> int:
"""Determine the length of a relative path (depth in file system tree).
Args:
data_root
fpath
Returns:
rel_path_len: integer
"""
data_root_len = len(Path(data_root).parts)
path_len = len... | 0f62fecd1993f8938b0c0305be7799185ecf6c55 | 74,058 |
def get_min(df):
"""Get minimum voltage of ECG recording
Args:
df (DataFrame): DataFrame with ECG data
Returns:
float: minimum voltage found in ECG recording
"""
min_val = df['voltage'].min()
return min_val | ea453111d2d06ac640190b8d17653668784de5a6 | 74,060 |
def utf8_encoding(t):
"""UTF-8 Encoding. Note that the exa values are shown with a '%'.
>>> utf8_encoding("A")
'A'
>>> utf8_encoding("Año")
'A%C3%B1o'
"""
return "".join("%%%X" % ord(x) if ord(x) > 127 else x for x in t) | 274a5515c9239ef909ce0f112aa7902a0a5384d6 | 74,064 |
import csv
def extract_scan_params_csv(scan_params_csv):
"""
Function to extract the site-based scan parameters from a csv file
and return a dictionary of their values
Parameters
----------
scan_params_csv : string
filepath to the scan parameters csv file
Returns
-------
... | 6eca6f69612767d5be60b768190572ef1deb1d32 | 74,066 |
def dump_deb822(fields):
"""
Format the given Debian control fields as text.
:param fields: The control fields to dump (a dictionary).
:returns: A Unicode string containing the formatted control fields.
"""
lines = []
for key, value in fields.items():
# Check for multi-line values.
... | 2673a49e21ec39c65634caec7a2880b24178ee64 | 74,067 |
def prfar(self, lab="", option="", phi1="", phi2="", nph1="", theta1="",
theta2="", ntheta="", val1="", val2="", val3="", **kwargs):
"""Prints pressure far fields and far field parameters.
APDL Command: PRFAR
Parameters
----------
lab
Parameters to print:
PRES - Acoustic... | 553fdc4866cb20ab193e2b7c09a2be04156767b2 | 74,070 |
def williams_correction(n, a, G):
"""Return the Williams corrected G statistic for G goodness of fit test.
For discussion read [1]_ pg 698-699.
Parameters
----------
n : int
Sum of observed frequencies.
a : int
Number of groups that are being compared.
G : float
Unc... | bdc1e0c88608d047989950787b66af0439f2b266 | 74,072 |
def convert_value_to_option_tuple(value, helpstr=None):
"""Convert a value to a tuple of the form expected by `Link.options`
Parameters
----------
value :
The value we are converting
helpstr : str
The help string that will be associated to this option.
Returns
-------
... | 96a398859690b288d0e134feed266bb26cd4a038 | 74,073 |
def countBits(n):
""" count_bits == PEP8 (forced mixedCase by CodeWars) """
return '{:b}'.format(n).count('1') | 2b86a72a2f062384f7dd7552e90fa115730ad611 | 74,081 |
def parse_flags(raw_flags, single_dash=False):
"""Return a list of flags.
If *single_dash* is False, concatenated flags will be split into
individual flags (eg. '-la' -> '-l', '-a').
"""
flags = []
for flag in raw_flags:
if flag.startswith("--") or single_dash:
flags.append(... | 9e70d625f6c5d2ace4c0669b5e32b3e5f27a42b8 | 74,085 |
def lower(text: str):
"""
Converts text to lowercase as part of text preprocessing pipeline.
"""
return text.lower() | dbcb0f3d459cbda2d02f9075b0d0cbdec64bcd50 | 74,088 |
def integer_divisors(n):
"""Returns a list of all positive integer divisors of n."""
n = abs(n)
r = []
for i in range(1, n/2+1):
if n % i == 0:
r.append(i)
r.append(n)
return r | cce352b92638a3f5277734920d3cc9d03b8957c4 | 74,090 |
def get_namespace(type_or_context):
"""
Utility function to extract the namespace from a type (@odata.type) or context (@odata.context)
:param type_or_context: the type or context value
:type type_or_context: str
:return: the namespace
"""
if '#' in type_or_context:
type_or_context =... | 6b84732b23c5e09731927a75b4aeeda8752750b0 | 74,093 |
def create_blocks(message, download_link=''):
"""
Create blocks for the main message, a divider, and context that links to Shipyard.
If a download link is provided, creates a button block to immediately start that download.
For more information: https://api.slack.com/block-kit/building
"""
mess... | 0f1a9bb9a739958fae395500fd025efc848cca34 | 74,097 |
def convert_volts_to_amps(adc_volts):
"""
* f(0.5V) = -20A
* f(4.5V) = 20A
* f(U) = 10*U - 25 [A]
"""
return 10 * adc_volts - 25 | 1da610110b578cc80bd4495600d2e98b9a254029 | 74,098 |
import time
def baseline_creation_payload(catalog_identifier: int, repo_identifier: int, device_details: dict) -> dict:
"""
Creates the JSON payload required to create the baseline
Args:
catalog_identifier: The ID for the target catalog
repo_identifier: The ID of the repository associated... | 61ae9de5e2ffb7824e196f22d8c1f14e2590408b | 74,100 |
def execute_http_call(session, url):
"""Executes an http call with the given session and url"""
return session.get(url) | 4f3c9cd6773814e02172a7719e866dd868491146 | 74,106 |
def query_doctypes(doctypes):
"""ES query for specified doctypes
Args:
doctypes (list)
Returns:
ES query (JSON)
"""
return {"query": {"terms": {"doctype": doctypes}}} | d69f689ac762569558bd90ddabbf0d135fcf7bdf | 74,108 |
def window_maker(list_name, filled_list, window_size, slide_size):
"""Make a bed file of sliding windows."""
for scaffold, start, end in filled_list:
width = window_size
step = slide_size
if width <= end:
list_name.append((scaffold, start, width))
else:
l... | 02f5f293b2ba49efdd7c31a955776a6df5e19f42 | 74,110 |
def _distribution(gtfs, table, column):
"""Count occurrences of values AND return it as a string.
Example return value: '1:5 2:15'"""
cur = gtfs.conn.cursor()
cur.execute('SELECT {column}, count(*) '
'FROM {table} GROUP BY {column} '
'ORDER BY {column}'.format(column=c... | cb00d98d2222b763dd501c6b52fef367f622d929 | 74,113 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.