content stringlengths 35 416k | sha1 stringlengths 40 40 | id int64 0 710k |
|---|---|---|
def make_word(letters, beginnings=[], endings=[]):
"""Return word dictionary"""
return {
'word': ''.join(letters),
'letters': letters,
'beginnings': beginnings,
'endings': endings,
} | 0b53fd8e26d2ca80e8c54ffa08f9473fb7b9f902 | 10,379 |
def mutate(mushroom, i):
""" Randomly flips one bit in a mushroom bit string"""
return mushroom ^ 1 << i | ffac7c56cfe455928fcbb833d363441ef9a2a8a7 | 10,384 |
def avoid_multiple_update(func):
"""Decorator to prevent handlers to update multiple times."""
def wrapper(self, attr, old, new):
if self.in_update:
return
self.in_update = True
func(self, attr, old, new)
self.in_update = False
return wrapper | d35e9add88ddb62d1368ff0fbf94e9637518c249 | 10,385 |
import numpy as np
def create_slice_mask(plane_dict, infile_dims):
"""Create a binary array defining a mask covering the area below a given
plane in the 3D image.
:type plane_dict: dict
:param plane_dict: A dictionary matching z voxel coordinates to
corresponding (x,y) coordina... | ca25e627dc93b3828b7ea49c139e1f9fc5950f6e | 10,386 |
def unsigned_to_signed(seq, width):
"""
Convert unsigned integer to signed.
"""
out = []
k = pow(2, width)
for x in seq:
if x >= k/2:
x -= k
out.append(x)
return out | b7b90ff4de576bee2e91af27f6fc3b509608ef34 | 10,387 |
def containerhasprefix(obj, prefix):
"""
Returns whether obj's container starts with prefix.
"""
return obj.container.name.startswith(prefix) | dcf4b14cfa1ac15355e7db5110be55b623e35f20 | 10,389 |
def _variance(mean_variance, samples):
"""Perform final variance calculations.
`mean_variance` and `samples` were pre-recorded with
`options.record.reduction._variance`.
This operation only calculates total running variance.
This function is applied on per-recording basis (per layer to be exact).... | 0bcc9705205304d8338843a3c09c8ae1f2314bb6 | 10,390 |
import six
def choose_part_ranges(content_length, minimum_part_size):
"""
Returns a list of (offset, length) for the parts of a large file.
:param content_length: content length value
:type content_length: int
:param minimum_part_size: a minimum file part size
:type minimum_part_size: int
... | 28acbe2df14d6f54a95ab74c18e410a076354187 | 10,391 |
import requests
def check_user_permission(access_token, job_requires):
"""
Check if user has permission to run the job or not
Args:
access_token(str): the access token
job_requires(dict): requirements so that job can run
{
"arborist_url": "http://arborist-servi... | c1069364b8d59965f78367e64b88206062c60b2b | 10,392 |
def slice_array_d50(df,idNode):
"""
This function allows to slice the array resulting from the create_array function. The slicing is performed
by a boolean mask in which the array is filtered according to the ID_Node specified by the user and then
only the columns corresponding to time and mean diameter... | 565c4ea76de08a493f028e32052fcef60e7f42dd | 10,393 |
def to_upper(string):
"""The upper case version of a string"""
return string.upper() | 8d3bb60b7b4704479cb642b9ab910f7a1469fd44 | 10,394 |
def _after_arg(arg_name):
"""Return a finder for argument after arg_name."""
def generate(transform):
"""Generate three args, OTHER, arg_name and ARGUMENT."""
return "ONE {0} {1}".format(arg_name, transform("ARGUMENT"))
return generate | 0a0306760e8e9a2ad356a4f2d9ae2c6b76d53d2e | 10,396 |
import torch
def get_src_xyz_from_plane_disparity(meshgrid_src_homo,
mpi_disparity_src,
K_src_inv):
"""
:param meshgrid_src_homo: 3xHxW
:param mpi_disparity_src: BxS
:param K_src_inv: Bx3x3
:return:
"""
B, S = mpi_d... | 91492ba8782607e8500de5b886f9339b041a3513 | 10,397 |
def trimmed_split(s, seps=(";", ",")):
"""Given a string s, split is by one of one of the seps."""
for sep in seps:
if sep not in s:
continue
data = [item.strip() for item in s.strip().split(sep)]
return data
return [s] | 192c75f7e346860010031cf9e621d7bb5664dde4 | 10,398 |
def descendant_selected(node):
"""Returns true if this node or a descendant of it is selected.
Use as e.g.: {% if descendant_selected node %}
"""
if node.selected:
return True
for child in node.children:
if descendant_selected(child):
return True
return Fals... | 974b95b8d658ec173ccbbf9488f309529c1f0d86 | 10,399 |
def mock_clipboard(monkeypatch, request):
"""Fixture mocking clipboard IO.
This mocks pandas.io.clipboard.clipboard_get and
pandas.io.clipboard.clipboard_set.
This uses a local dict for storing data. The dictionary
key used is the test ID, available with ``request.node.name``.
This returns th... | 7acf72b45050d35cd57ddf9310304950610744c5 | 10,403 |
def fileNumber(filePath):
"""
Get the number of the file. foo.0080 would return 0080
"""
num = filePath.split('.')[-1]
return int(num) | 731918660f0c145c15ba99c2f5eb8be9745e8576 | 10,404 |
def get_top_adj(full_results, num):
"""
Takes dictionary of results from run_adj_analysis and number of top results to return.
Returns the top num adjectives associated with male pronouns and female pronouns.
:param full_results: dictionary from result of run_adj_analysis
:param num: number of ... | 0eddb189f79bc9b18f2994f2a99aef1b07181691 | 10,405 |
def manhattan_distance(x, y):
""" Returns the Manhattan (City Block) distance between two lists
"""
return sum(abs(a - b) for a, b in zip(x, y)) | 4887024603a8fe3398ec80a17d1d70fbe15fdfab | 10,407 |
def starting_coordinates():
"""
Starting coordinates on a pixel matrix.
"""
return (10, 10) | 68f8b493e36cba56808cfbcea6a4ee9368e0c720 | 10,409 |
def strip_html_tags(i_string):
"""
Quick solution to remove html tags being returned in episode description.
Will probably replace eventually.
"""
strippable = ('<p>', '</p>')
spaces = (' ',)
breaks = ('<br>',)
for s in strippable:
i_string = i_string.replace(s, '')
for... | 9454c7ee5e9006756426ca1fdecb97df8beb2cc4 | 10,410 |
import copy
import collections
def get_db_data(relation_data, unprefixed):
"""Organize database requests into a collections.OrderedDict
:param relation_data: shared-db relation data
:type relation_data: dict
:param unprefixed: Prefix to use for requests without a prefix. This should
... | 0e2a30624f35f49119ae9bd275153d5e9fdf7503 | 10,412 |
def convert(tree,fileName=None):
"""
Converts input files to be compatible with merge request #412, where we switch from custom
XML pathing to standard XPATH nomenclature.
@ In, tree, xml.etree.ElementTree.ElementTree object, the contents of a RAVEN input file
@ In, fileName, the name for the raven in... | 841f491370dc07d77f9af5428d78486136220ce9 | 10,413 |
def get_username(prompt: str) -> str:
"""Prompt the user for a username"""
username = input(prompt)
return username | c6d6119ba9b2b1ec9408501afb04b513aa9b4965 | 10,416 |
def remove_low_information_features(feature_matrix, features=None):
"""Select features that have at least 2 unique values and that are not all null
Args:
feature_matrix (:class:`pd.DataFrame`): DataFrame whose columns are feature names and rows are instances
features (list[:class:`f... | 0377b2b87d04ddaa89e332ed72c12a05b4a1c3e6 | 10,417 |
import hashlib
def md5_password(password, salt):
"""获取原始密码+salt的md5值
"""
trans_str = password + salt
md = hashlib.md5()
md.update(trans_str.encode('utf-8'))
return md.hexdigest() | cbb4306bfa1e11957a56d5ace5d810ac421f5d83 | 10,418 |
def bit(value, position, length=1):
"""
Return bit of number value at position
Position starts from 0 (LSB)
:param value:
:param position:
:param length:
:return:
"""
binary = bin(value)[2:]
size = len(binary) - 1
if position > size:
return 0
else:
return ... | f639eae3d3f260b5b0d29ddd6a3ad99c89267704 | 10,420 |
def diff_template(page, label=None):
"""
Return a Template:Diff2 string for the given Page.
"""
if label is None:
label = page.title()
return f"{{{{Diff2|{page.latest_revision_id}|{label}}}}}" | 48cca6ad78ce2e0f2e1ce4902d56734fccf45030 | 10,421 |
import re
def make_dataset_name(name):
"""Dataset name contains "letters, numbers, -, _" only, any other content will be replaced with "-"
"""
def may_replace(c):
if re.match("\w", c) is None:
if c == '-':
return c
else:
return "_"
e... | bf97474ffcb0c5e0354c724ca4defea1b04f8939 | 10,422 |
def averageOfNumbers():
""" averageOfNumbers
Outputs the average of a series of numbers entered by the user.
returns:
The average of the numbers input by the user.
"""
numbers = []
amount_of_numbers = input("How many numbers do you wish to input? ")
for x in range(1, int(amount... | 3403bf775f0675e0f54dc18f5146e37989fc0ce2 | 10,423 |
import math
def calc_entropy(data, base=2):
"""
Calculate the entropy of data. Using documentation from
scipy.stats.entropy as the basis for this code
(https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.entropy.html).
:param data: Measure the entropy of this object
:return: Calcu... | 72a9d111120415471c7d54e11c862ce8ebde4a55 | 10,424 |
def getValidPaths(author_collabs, year):
"""
selects the neighbours with valid paths
returns a list where each result is a tuple of author name, collaborations < year
"""
valid_neighbours = list()
for n in author_collabs:
valid_collabs = list()
for c in author_collabs[n]:
... | b9cc56b3bee490296afb9448c6082eb0206a74e7 | 10,425 |
def count_unplayed_cards(r, progress):
"""Returns the number of cards which are not yet played, including cards
which are unplayable because all those cards (or cards of a value below it)
are already discarded"""
n = 0
for suit in r.suits:
n += 5 - progress[suit]
return n | 445b1b3d07aff4c2010fc482cb7f5b55a8250bac | 10,426 |
def toFENhash(fen):
""" Removes the two last parts of the FEN notation
"""
return ' '.join(fen.split(" ")[:-2]) | bc2575ce35f8d2678753369d2b3a4d050388891f | 10,428 |
def remap_lads(lad_name):
"""Some LADs of MSOA census data do not match
the LAD geographies of the LAD population data
"""
if lad_name == 'E06000048':
lad_mapped = 'E06000057' #Northumberland
elif lad_name == 'E08000020':
lad_mapped = 'E08000037'
elif lad_name == 'E07000097':
... | 46e13886a4541fcd5a47870d845db717373084cc | 10,429 |
def validate(detector, val_data, metric):
"""Test on validation dataset."""
metric.reset()
for img, label in val_data:
# scores, bboxes = detector.detect(img)
scores, bboxes = detector.ms_detect(img)
metric.update(bboxes, scores, label)
return metric.get() | 7b9f3a5405ea40eba37765d7fbc5b204203c96de | 10,430 |
def _construct_request_parameters(args: dict, keys: list, params={}):
"""A helper function to add the keys arguments to the dict parameters"""
parameters = {}
if params is not None:
for p in params:
parameters[p] = params[p]
for (arg_field, filter_field) in keys:
value = ar... | a268ddf8612014a4a4012eab8cfae50d1437be1e | 10,432 |
from typing import Dict
from typing import List
from typing import Tuple
def votes_per_month(values: Dict[str, List[str] | Tuple[str]]) -> Dict[str, Dict[str, int]]:
"""
:param values: a dictionary formatted like: {month: list of votes}
:returns: dictionary every person for every month
"""
all_per... | acff0d2aaff68b12430c7d28f7f7f7b0f08aaa3c | 10,433 |
def move_cursor(move):
"""Return move value for cursor."""
return {
'left': -1,
'right': 1,
}[move] | 333c3b6b0a8b3e936250f47b16019420da2a3670 | 10,434 |
import math
def gcd(*nums):
"""
Find the greatest common divisor (GCD) of a list of numbers.
Args:
*nums (tuple[int]): The input numbers.
Returns:
gcd_val (int): The value of the greatest common divisor (GCD).
Examples:
>>> gcd(12, 24, 18)
6
>>> gcd(12, 2... | ea3b2f55ab1db530a2c0e5d472c053b9e538f3e0 | 10,436 |
import cmath
def rotate_points(points, phase_shift):
"""
Rotate a point about the origin.
Arguments:
points: iterable(complex)
Points to rotate in the complex plane.
phase_shift:
Magnitude of rotation in radians.
Returns:
rotated_points: list(complex)
... | e9ae43774bc8f5ac770413f6e758d41223fb3c00 | 10,438 |
def tupleize(func):
"""A decorator that tuple-ize the result of a function. This is useful
when the evaluation function returns a single value.
"""
def wrapper(*args, **kargs):
return func(*args, **kargs),
return wrapper | 2a2a9d709177868bd47571f86ae026d666b2593b | 10,439 |
def vocabulary(word_counts):
"""
:param word_counts: dictionary of each word count
:return: list of vocabulary
"""
vocabulary = list(map(lambda x: x[0], sorted(word_counts.items(), key=lambda x: -x[1])))
return vocabulary | 2e7b77fe8e69ba4dd6c9136c3e80b16f02a56d49 | 10,440 |
import torch
def rejoin(chunked, initial_shape):
"""
Rejoins chunked tensor, removing the padding as necessary
>>> eq = lambda a, b: torch.all(torch.lt(torch.abs(torch.add(a, -b)), 1e-12))
>>> x = torch.arange(end=4) + 3
>>> y = torch.arange(end=15) + 2
>>> mesh = x.view(-1, 1) @ y.view(1, -1... | 6bcf5bf07b813b79245b50c72e67a98e575df5f9 | 10,441 |
def transient_provider(func):
"""
Decorator to mark a provider as transient
"""
func.transient = True
return func | 2f540fc3099c3fc71ac49ce44dbd69a042b9e39f | 10,442 |
def validate_keep(keep):
"""validates the value of the keep parameter
If it's not coercable to an int or equal to the special string values,
raise a ValueError. Otherwise, return `keep`.
:param keep: value to validate
:type keep: int or str
:return: the validated value of keep
:rtype: eith... | 5a1d03140eeab9bef1f3ae417c3d3fc77b8499bd | 10,443 |
import os
def default_database():
"""
Returns DATABASE if env is set
"""
return os.environ.get('DATABASE', '') | a4e1ccfd916e76e0ed8eea79ca519711cbcaced1 | 10,444 |
def levensthein_dist(input_command: str, candidate: str) -> int:
"""
Implement the Levenshtein distance algorithm to determine, in case of a non-existing handle,
if theres a very similar command to suggest.
:param input_command: The non-existing handle the user gave as input
:param candidate: The (... | 02506be8655f97a60665a507cfa62cb9703590ef | 10,446 |
import inspect
import subprocess
def process(execute_kwargs=None):
"""Function for execute a set of command lines"""
if not execute_kwargs:
execute_kwargs = {}
commands = execute_kwargs["commands"]
if not isinstance(commands, list):
commands = [execute_kwargs["commands"]]
output_... | 2c265bde354974a215085a897e57dd897528b095 | 10,449 |
from datetime import datetime
def _is_start_date_before_end_date(start: datetime, end: datetime) -> bool:
"""Whether the start date is before the end date.
Args:
start: The start date of an event.
end: The end date of an event.
Returns:
True if valid, otherwise returns False.
... | 4a296d6673f6beb704b590893088c50a97184764 | 10,450 |
import os
def get_data_folder():
"""
Returns the location of the folder containing data files.
"""
path = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'data')
return os.path.normpath(path) | 3c9e99506bbdaabc1449ca1da2ecaf6afc498b97 | 10,451 |
def ConvertIndexListToSet(index_list):
"""Creates a set containing the indices of all '1' entries in the index
list
"""
return set(i + 1 for i, j in enumerate(index_list) if j == 1) | 78d0769de4b22aabd0d0ea2f906958a929da5299 | 10,452 |
from typing import Tuple
def decrypt(text_enc: Tuple[int, int]) -> str:
"""Function that decrypt the tuple of tokens
and re-convert them into string.
:param text_enc: the tuple of the text encrypted
:return: the text decrypted
"""
encrypted = text_enc[0] ^ text_enc[1]
decrypted = encrypte... | 0496d90818ef310b885341dad2d91823eadf97e2 | 10,453 |
def count_words(text):
"""
this function counts words
param sentence: string containing words
"""
if not isinstance(text, str):
raise TypeError("word counter accepts only strings")
normal_word_splits = text.split(" ")
new_words = []
for asplit in normal_word_splits:
if "\... | 773d07a4092298b292601d19bba596f1e8e9bcc2 | 10,455 |
def lisser(chaine):
"""Retourne la chaîne lisser.
On lisse une chaîne en remplaçant certains schémas comme
" de le " par " du ".
"""
schemas = (
(" le a", " l'a"),
(" le e", " l'e"),
(" le hom", " l'hom"),
(" le hum", " l'hum"),
(" le i", " l'i"),
("... | 39e6c406b3708e1f5c4fd6e9845fb3e860761ef4 | 10,456 |
def moveZeroes(nums):
"""
:type nums: List[int]
:rtype: None Do not return anything, modify nums in-place instead.
"""
j = 0
for i in range(len(nums)):
if nums[i] != 0:
nums[j] = nums[i]
j += 1
k = len(nums)-j
while (k > 0):
nums[-k] = 0
... | 909f0dcac374dd8242dae4a13460ced4383dde3b | 10,457 |
import argparse
def get_argument_parser():
"""Set up command line arguments and usage."""
parser = argparse.ArgumentParser()
parser.add_argument(
'location',
type=str,
help='file or directory containing unit tests'
)
parser.add_argument(
'--pattern',
'-p',
default='^(test_.*|.*_test... | 0b60c62918693fe2c1a246c2461fe8a63749ef26 | 10,460 |
def get_mentored_team(mentor, hackathon):
""" Retrieve all mentored teams for a Judge at a Hackathon """
mentored_teams = None
mentored_teams = mentor.mentored_teams.filter(
hackathon=hackathon).order_by('display_name')
return mentored_teams | de6e25b3c116b4bca4c4559b3a204d46ed5b38ba | 10,461 |
def get_ranges(uid_number, inc=0):
"""
Return two block ranges to be used to create subnets for
Atmosphere users.
NOTE: If you change MAX_SUBNET then you should likely change
the related math.
"""
MAX_SUBNET = 4064 # Note 16 * 256
n = uid_number % MAX_SUBNET
# 16-31
block1 = (... | b364a9051a8c8a9ea68dcee76fc7b993e30c13af | 10,462 |
def returnRectangles(a,x):
""" Returns 2D discrete integral array using the rectangle method
The calculation for each array element is
:math:`(\Delta y_i = 0.5(a_{n-1}+a_{n})*(x_{n-1}-x_{n})`
Parameters
----------
a : numpy.ndarray
Description: Array of y(x) function with N+1 elements
... | dd9931bcc2eae7d6712d4e809b23e3145ee4555b | 10,463 |
def strip_id(url):
"""Get MP database ID from url."""
url = url.split('/')
return url[-2] | fa4ae6a3f58067b99fd5f89a2d1f10b49bc27f5e | 10,464 |
def find_channel(channel_name, source):
"""
Search for channel by name on the given object
"""
name = channel_name.lower()
for channel in source.channels:
if channel.name.lower() == name:
return channel
return None | 2b9feb9f60986392137deb6c8364e6c2d7e5efd4 | 10,466 |
def conf(db, context, log, fields):
"""Perform CONF command.
This is supposed to adjust the configuration of the Crusher database.
"""
"""Configure the database."""
db.configure(fields[1])
"""Copy the configuration command to the log."""
log.write("{}\t{}\n".format(fields[0], fields[1]))
... | 89ac0019a1b2beccc6852f57616239a776575be2 | 10,467 |
def get_metadata(data):
"""Gets metadata from the input cloutformation file content."""
return data['Metadata'] | 5fed88a19704430272b73751938f34a3a7a09d8d | 10,468 |
import socket
def get_ip_and_port():
"""The network information function.
"""
s = socket.socket(
family=socket.AF_INET,
type=socket.SOCK_DGRAM,
proto=0,
fileno=None)
s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 0)
s.connect(('<broadcast>', 0))
ip, port ... | e26e2b7462eedb967380c163f8d848b0e00df369 | 10,470 |
import pytz
def to_naive_utc(dtime):
"""convert a datetime object to UTC and than remove the tzinfo, if
datetime is naive already, return it
"""
if not hasattr(dtime, 'tzinfo') or dtime.tzinfo is None:
return dtime
dtime_utc = dtime.astimezone(pytz.UTC)
dtime_naive = dtime_utc.replace... | 4d76ef2a3a5f11efeeedb9f920bc15b55c996da3 | 10,471 |
def get_true_positives(data, classifier):
"""Find the total positives that also are selected by our classifier."""
return data[data["foundSegment"] & classifier(data)].size | 2d1581e5f9ade4ff299557c76f3a9507c4dc5a55 | 10,474 |
def fill_coords(datafr):
"""
Interpoleert op cellen met NaN waarden
:return DataFrame
"""
# df_dropped_na = datafr.dropna()
# nonNA = list(df_dropped_na.index.values)
#
# for i in range(len(nonNA) - 1):
# prev_lat = datafr.at[nonNA[i], 'latitude']
# diff_lat = abs(datafr... | 2fed07b6c594551bcf96484fceae3f57d52ebf83 | 10,477 |
def precision_at_k(vanilla_topk, fair_topk):
"""
calculate precision @ K
:param vanilla_topk: top K nodes in vanilla mining result
:param fair_topk: top K nodes in debiased mining result
:return: precision @ K
"""
topk = set(fair_topk)
groundtruth = set(vanilla_topk)
return len(topk.... | 073abf75d0a66d492541d13c799b67c1b09662f8 | 10,478 |
import hashlib
import json
def param_to_hash(param_dict):
"""Generate a hash for a fixed hyperparameter setting"""
config_hash = hashlib.md5(json.dumps(param_dict, sort_keys=True).encode("utf-8")).hexdigest()
return config_hash | 5302000372023af0d2ea44ca3e5497741cd84e58 | 10,479 |
def lower(series):
"""Transform all text to lowercase."""
return series.str.lower() | fd8f443ff8cb27700bceed3a2b2843befbc932a3 | 10,480 |
def parse_account(s):
""" parse entity and account string """
return s.strip().split('.') | acb14bd71a670e67b306f022792702dc2677539a | 10,482 |
import torch
def chunk_rays(rays,start,delta):
"""
rays: a dictionary
"""
rays_chunk = {}
for k,v in rays.items():
if torch.is_tensor(v):
v = v.view(-1, v.shape[-1])
rays_chunk[k] = v[start:start+delta]
return rays_chunk | 8015d1d69b77e2a7fab6b33d30a104982aedfa9c | 10,483 |
def normalize_job_id(job_id):
"""Convert the job id into job_id, array_id."""
job_id = job_id.split('.')[0]
if '[' in job_id:
job_id, array_id = job_id.split('[')
job_id = job_id.strip('[]')
array_id = array_id.strip('[]')
if not array_id:
array_id = None
else... | 6eb83b54f8a0cec8c094372a5e5446334a1863c3 | 10,485 |
import random
def select_ip_from_network(network):
"""
Randomly selects an IP address from a particular network
:param network: Network from which to select the IP address
:return: IP address as integer from network
"""
max_address = network.address | ((1 << (32 - network.prefix)) - 1)
ret... | 7356b6cedd5bc78933484e0cba9a8f84d1507b07 | 10,487 |
import json
import requests
def query(query, experiment_id, host, verify_cert=True):
"""
Query the MDML for an example of the data structure that your query will return. This is aimed at aiding in development of FuncX functions for use with the MDML.
Parameters
----------
query : list
Des... | 3080ab6322a2756fdc6cb4da8ccc81b96154cbb4 | 10,488 |
import os
def attemptFileClear(fName,later):
"""
Attempts to remove the file. If not possible, store it in "later".
@ In, fName, string, name of file to remove
@ In, later, list, list of files to remove later
@ Out, later, list, list of files to remove later
"""
try:
os.remove(fName)
exce... | 208dcce6ffa1a6de65a93f0b14befe019ddb20c6 | 10,489 |
def GetPercentage(number, total):
"""Returns the float percentage that a number is of a total."""
if not number:
return 0
return float(number) / total * 100 | 46e2a5b2b4a3fa648792a461852f84e886810a7f | 10,491 |
import re
def parse_billing_code_col(s:str):
"""Split billing code into separate fields for code_type and code. E.g., 'MSDRG .... 001'."""
l:list = s.split()
if 'MS-DRG' in s:
code_type, code = l[0], l[4]
elif re.search('CPT|HCPCS', s):
code_type, code = l[0], l[1]
else:
co... | 78865842a457c0226184ace94334d0934a0e0a5c | 10,493 |
def DetermineLocaleType(locale_str):
"""Determines the locale 'type' for a given locale name.
Returns:
(string) Always one of the following strings,
'world' If the locale name refers to the world.
'country' If the locale name looks like a country ID.
'region' If the locale name ... | 52ac86d8e011d9d01b6f31ed6a27d535a55b26a4 | 10,495 |
def get_model(instance):
"""Get model by instance."""
return instance._meta.model | e386449ecd49d5874fb704c683c17d4492ea6f6c | 10,497 |
def force_slashend(path):
"""
Return ``path`` suffixed with ``/`` (path is unchanged if it is already
suffixed with ``/``).
"""
if not path.endswith('/'):
path = path + '/'
return path | 2e2be0dbb88fb380e581f49af532ea7b5724d918 | 10,498 |
def unfuse_right(A, shp):
"""
Reverses fuse_right.
"""
d, chiL, chiR = shp
A = A.reshape((chiL, d, chiR)).transpose((1, 0, 2))
return A | 31d2e50d3a5ca715dc04ee9305db76cbc566de3e | 10,500 |
def lift(cra, crb):
"""Returns the relative uplift in conversion rate.
Parameters
----------
cra: float
Conversion rate of Group A
crb: float
Conversion rate of Group B
Returns
-------
float
Relative uplift in conversion rate
"""
return ((crb - cra) / cra)... | 2489fef702153657f007751bc5234d11d8333f75 | 10,502 |
import ast
def load(symbol_id: str) -> ast.Name:
"""Returns an AST Name node that loads a variable."""
return ast.Name(id=symbol_id, ctx=ast.Load()) | 94a76bdac89a9e7b1f766832dd2aef63469704ac | 10,503 |
def _NegGrad(_, grad):
"""Returns -grad."""
return -grad | c2a2800e1d80c3151019425e3871c235485c9324 | 10,504 |
from typing import OrderedDict
def init_vec(f, names, data):
"""Initialize resizable 1d arrays to hold the outputs."""
# Iterate over 'names' and columns of 'data'
dset = [
(name, f.create_dataset(name, data=d, maxshape=(None,)))
for name, d in zip(names, data.T)
] # -> list
retu... | ed024e176da68d1a6753da305cea0a36d21e0e7a | 10,505 |
def clean_url(url):
"""
Reformat a URL with all querystrings stripped
:param url: The URL
:return: A clean URL
"""
return url[:url.find('?')] | 56edc6db7b59e1550a68377dcdcb80a83b79e854 | 10,506 |
def level_is_rtl(lev):
"""
Return True if `lev' is a Right-to-Left level, False otherwise.
"""
return lev & 1 | 5c3d6127bcef2f17b347c7c26a86f723f25ab6a7 | 10,510 |
def GroupBuilder(size, builderFunc, indAttr):
"""size - the number of members of the group
indAttr - a list of [size, possList, probList] for IndividualBuilder
file - the csv file to rebuild an existing group from"""
individualSize = indAttr[0]
possList = indAttr[1]
probList = indAttr[2]
... | 8bd144c71acd177518b12ce2dd209d2838c6fff4 | 10,511 |
def _read_timestamp(file):
"""Get start and end time from timestamp csv file."""
try:
with open(file, 'r') as f:
rows = f.readlines()
starttime, endtime = float(rows[0].split(",")[0]), float(rows[-1].split(",")[0])
starttime, endtime = starttime / (10**3), endtime / (10**... | be403b62623f45e6cf43c6239c1c068a48987183 | 10,513 |
import torch
def generate_padding_mask(x: torch.Tensor, length: torch.Tensor) -> torch.Tensor:
"""
Args:
x: tensor of shape [batch_size, length]
length: tensor of shape [batch_size]
Returns:
float tensor of shape [batch_size, length]
"""
assert x.dim() == 2
assert lengt... | d475cfa6eb81525745bed8613827c59bac57aa5d | 10,515 |
def object_func(x, A, b):
""" Objective function for the optimization for L-BFGS-B
"""
y = A * x - b
return 0.5 * y.dot(y) | 8a9453f6f93f4b7c7e2f5202a2a81750df5c27df | 10,518 |
def has_prefix(sub_s, d):
"""
:param sub_s:
:return:
"""
for key in d:
if key.startswith(sub_s):
return True | c9544f3937a47eb7d9b18b4209acd3fa9283de12 | 10,520 |
def bayesdb_generator_modelnos(bdb, generator_id):
"""Return list of model numbers associated with given `generator_id`."""
sql = '''
SELECT modelno FROM bayesdb_generator_model AS m
WHERE generator_id = ?
ORDER BY modelno ASC
'''
return [row[0] for row in bdb.sql_execute... | e7cbb96679f25815df6a28e3eb89ad61e4b20e09 | 10,522 |
from typing import List
def format_terminal_call(cmd: List[str]) -> str:
"""
Format commands to/from the terminal for readability
:param cmd: List of strings much like sys.argv
:return: Formatted string used for display purposes
"""
return ' '.join(cmd).replace("--", " \\ \n\t--") | 63af43a7d8a5cb708f8a9f6d7467e62e378876b4 | 10,523 |
from typing import Dict
import yaml
def load_config_file(file_path: str) -> Dict:
"""
Load a YAML config file. Uses UnsafeLoader
:rtype: Dict
"""
with open(file_path, 'r') as yaml_file:
cfg = yaml.load(yaml_file, Loader=yaml.UnsafeLoader)
return cfg | 52024a77e8e940f919245bb7b5093043f6d2158c | 10,524 |
def is_latin_square(row_length: int, array: str) -> bool:
"""Return whether array is a latin square."""
# check horizontally
row = 1
column = 0
numbers = []
for index, digit in enumerate(array):
# check for new row
if index % row_length == 0:
row += 1
col... | f85721f93f27b72797702849375992e43314a847 | 10,525 |
import argparse
def _get_argparser():
"""to organize and clean format argparser args"""
parser = argparse.ArgumentParser()
parser.add_argument(
'arg-1',
help='desc'
)
parser.add_argument(
"--optional-arg-1",
action="store",
dest="optional_arg_1",
... | c30acede95e36de05361a50d8060f497e52afbee | 10,529 |
from typing import Optional
import os
def guess_requirements_path(django_directory_path: str,
project_name: str) -> Optional[str]:
"""Guess the absolute path of requirements.txt.
The logic is as the follows:
1. If "requirements.txt" exists in the given directory, return it... | 3a01319bcdd7c90e2357deb9b93cec09650784f8 | 10,530 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.