content stringlengths 39 14.9k | sha1 stringlengths 40 40 | id int64 0 710k |
|---|---|---|
def argmin(pairs):
"""
Given an iterable of pairs (key, value), return the key corresponding to the smallest value.
Raises `ValueError` on empty sequence.
>>> argmin(zip(range(20), range(20, 0, -1)))
19
"""
return min(pairs, key=lambda x: x[1])[0] | 39f9c00f95ee9ba4257b3533cd15f5a6a263156d | 52,262 |
def _convert_exception(exception):
"""Convert an Exception into a failure document for publishing."""
return {'errmsg': str(exception),
'errtype': exception.__class__.__name__} | 3b3f1a93ae18e05df1f02a54df874dc5fb51b643 | 52,264 |
def example_function(myinput: int) -> int:
"""
Returns the given parameter without change.
This function is just for demo purposes and should be removed when the template
is used for an actual project.
Args:
myinput: The parameter to return.
Returns:
The given parameter withou... | 9c599f24075b837b64facbcef0eadf07462f1454 | 52,269 |
import torch
def bbox_cxcyah_to_xyxy(bboxes):
"""Convert bbox coordinates from (cx, cy, ratio, h) to (x1, y1, x2, y2).
Args:
bbox (Tensor): Shape (n, 4) for bboxes.
Returns:
Tensor: Converted bboxes.
"""
cx, cy, ratio, h = bboxes.split((1, 1, 1, 1), dim=-1)
w = ratio * h
... | d0f2e04a6089d0fd1d1feed559285d27d4665864 | 52,270 |
def square(n):
""" (int) -> int
Return a number squared.
>>> square(7)
49
>>> square(12)
144
"""
return (n * n) | abd1322034261cdc7281caaec14978ed7aec2760 | 52,273 |
import gzip
import pickle
def load_sim(filename):
"""
Utility function that loads a system together with simulation results.
Parameters
----------
filename: string
Name of inputfile
Returns
-------
system: Builder object
A discritized system.
result: dictionary
... | ff135fa8521cc2ead823544583aa8d54b45a9e15 | 52,279 |
def const(a):
"""
The constant function. A function that returns a constant value.
a -> b -> a
"""
return lambda b: a | 1dc9fe5b12ac20fbb68cffb743b4cd4dce77c017 | 52,283 |
def maxTuple(tuples):
"""Return the tuple whose first element is largest."""
maxTuple = None;
maxValue = 0.0;
for tuple in tuples:
if tuple[0] > maxValue:
maxValue = tuple[0]
maxTuple = tuple
return maxTuple | 1ad6c1b31008493efac751d4ea21c16ec20d041f | 52,289 |
import base64
def featB64encode(feat):
"""Base64 encode feature.
:param feat: feature
:type feat: :class:`numpy.ndarray`
:return: str
"""
return base64.b64encode(feat) | af509e6f3c67739f374c2762735d25b4ab80185c | 52,291 |
def name_relative_to(parent_abspath, child_abspath):
""" Determine the relative name of a child path with respect to a parent
system.
Args
----
parent_abspath : str
Asbolute path of the parent.
child_abspath : str
Absolute path of the child.
Returns
-------
str
... | 49e58743cec5822859eb4913fb64888201ec317e | 52,293 |
def append(l: list, obj: object) -> list:
"""Extend or append to list"""
if isinstance(obj, list):
l.extend(obj)
else:
l.append(obj)
return l | 21996e2f36baf323a44459b8d9eb9602f87df761 | 52,295 |
def tensor_extend_new_dim(x, dim, n):
"""Extending the tensor along a new dimension with a replica of n.
Args:
x (Tensor): tensor to be extended
dim (int): the value indicating the position of the newly
inserted dimension
n (int): the number of replica along dim
Returns:... | 06296948f98a57e74caadba97eed392c62599201 | 52,299 |
def read_timestamp(metric):
"""Read the timestamp from the given metric and convert it to the
format used by time.time()."""
return metric.timestamp / 1000.0 | b065a3977df6dc6c78a803aad003d6ff170fa989 | 52,311 |
import re
def _expand_h(string):
""" Convert Huawei-style port ranges into list of ports """
result = []
for element in re.split('(?<!to) (?!to)', string):
m = re.match('(\d+) to (\d+)', element)
if m:
for num in range(int(m.group(1)), int(m.group(2)) + 1):
resu... | 37334477e7bf830a8c430040b26187bfe7c13e5d | 52,312 |
def df_column_to_strings(person_df, column_name):
"""
Function is intended to take a particular column from a dataframe and convert
the values in said column into a string that can be used for a query (e.g. only
searching amongst a specific set of persons).
Parameters
----------
person_... | 2df20f4fa373f81d7b551df2bfc22571b8d3173d | 52,313 |
def fts_pattern(pattern):
"""Convert a pattern to an fts representation."""
fts = [f'{patt}*' for patt in pattern.split(' ') if patt]
return ' '.join(fts) | 615e8fdf64e3ea213d3d05002ef1d34be589145e | 52,317 |
import torch
def generate_sorted_element_mask(previous_actions, input_length: int) -> torch.Tensor:
"""
Generates a mask that prevents actions from attending to elements of the unordered set that have already been
placed into the ordered sequence.
Args:
previous_actions: List of previous actio... | c7b0bf85e2b1cad0737eba23847009116ac9ed9b | 52,321 |
def getframemodname(frame):
"""Given a frame return the module name"""
globals = frame.f_globals
if globals.has_key('__name__'):
return globals['__name__']
return None | 98d0735f1bc1a492ddfd432626d73bd284fa2eab | 52,322 |
def field_provides(field, ifaces):
"""Does field provide at least one of the interfaces specified?"""
_pb = lambda iface: iface.providedBy(field)
return any(map(_pb, ifaces)) | 91aa226118d00f69e7e2e56e2aabc8c9424e5797 | 52,323 |
from typing import List
async def standard_tweet_info(
as_json: dict,
) -> tuple[str, List[str], List[str], List[str]]:
"""
Returns the text, tickers, images, and hashtags of a tweet.
Parameters
----------
as_json : dict
The json object of the tweet.
Returns
-------
tuple... | 65e91d3ea01d7b1c3ed5e6cfb2370faa4bd9d107 | 52,324 |
import json
def artifact_file(tmpdir, artifact_content, artifact_filename,
artifact_file_created):
"""
This fixture creates a tempdir and writes the artifact_filename file
with the artifact_content passed in via the fixture. Then it returns the
path of the file. If artifact_content i... | fb00f64c01e08613fc6f7d7a5b2a75663019f491 | 52,328 |
def _make_safe(decorator, original):
"""
Copy the function data from the old function to the decorator.
"""
decorator.__name__ = original.__name__
decorator.__dict__ = original.__dict__
decorator.__doc__ = original.__doc__
return decorator | 75f765865082576716833d9d16dbcb87037a0997 | 52,330 |
import math
def _neq_per_residue(row_freq):
"""
Compute the Neq of a vector of frequencies coresponding to one residue.
The vector is a row of the frequency matrix.
This function is intended to be called from the `numpy.apply_along_axis` function.
Parameters
----------
row_freq : 1D numpy... | 7b34d676bfc60df378ba20b2634e204b23e336cd | 52,333 |
from typing import OrderedDict
def get_star_ids_from_upload_file(fullpath):
""" Get and return all star ids from a given WebObs upload text file.
:param fullpath: upload text file name [string].
:return: list of all star IDs, no duplicates, preserving order found in file [list of strings].
"""
tr... | 82f172a1455e02b728d7337894805e68798abf04 | 52,334 |
def good_mac(mac):
"""
Convert dash separated MAC to colon separated
"""
return mac.upper().replace('-', ':') | 1df09a84dac7c379bedf97846842c20b62a33206 | 52,337 |
import builtins
import re
def safer_eval(statement, locals):
"""A safer eval function. Does not allow __ or try statements, only includes certain 'safe' builtins."""
allowed_builtins = ['True', 'False', 'str', 'bytes', 'int', 'float', 'len', 'any', 'all', 'sorted']
for name in allowed_builtins:
lo... | b56d35919d1dbf75acf8509ee816e74fa2ab8192 | 52,344 |
def get_scop_labels_from_string(scop_label):
"""
In [23]: label
Out[23]: 'a.1.1.1'
In [24]: get_scop_labels_from_string(label)
Out[24]: ('a', 'a.1', 'a.1.1', 'a.1.1.1')
"""
class_, fold, superfam, fam = scop_label.split('.')
fold = '.'.join([class_, fold])
superfam = '.'.join([fold,... | 59e869748a673b9ec210a719b9f887fad3a0f6b3 | 52,346 |
def get_min_max(nums):
"""
Return a tuple(min, max) out of list of unsorted integers.
Args:
nums(list): list of integers containing one or more integers
"""
if len(nums) == 0: raise ValueError('nums must not be empty')
if len(nums) == 1: return (nums[0], nums[0])
min_, max_ = nums[0]... | 6f1beeaf5e165283106c85d79973b2fd6fbc33e4 | 52,348 |
def optimize(model):
"""
Carry out reduce optimization
Parameters
----------
model
mmtbx model object that contains H atoms
H atoms should be at approprite distances
Returns
-------
model
mmtbx model object with optimized H atoms
"""
# hierarchy object --> has hierarchy of struct... | 5ffc8cef6af9e2f8051caabdc57b0bece5a291fa | 52,350 |
import difflib
def diff(before, after):
"""Diff two strings"""
lines = difflib.Differ().compare(before.splitlines(), after.splitlines())
return "\n".join(lines) | 785e71526d8f36a7d7c405aadc6e07024c3d9d1f | 52,354 |
def contains_duplicate(nums: list[int]) -> bool:
"""
Args:
nums: array of possibly non-distinct integers
Returns: True if `nums` contains duplicate elements, False otherwise
Examples:
>>> contains_duplicate([1,2,3,1])
True
>>> contains_duplicate([1,2,3,4])
Fals... | b09b64a4f4904b597d974abbf57d9e675efb4611 | 52,362 |
def validate_multiple_lists_length(*lists) -> bool:
"""Validates that a list of lists is of the same length
Args:
lists(list): a list of lists to be checked
Retuens:
b(bool): True if all list of the same length, False else.
"""
list_len = -1
for l in lists:
try:
... | 7874614f1e500c5d312abd4636c03df100fe6b7b | 52,366 |
def type_check(*args):
"""
Checks if all types in args are correct
:param args: List[Tuple[object, type]] = list of objects and their estimated types
:return: bool = True or raises an error
"""
for arg in args:
if type(arg[0]) != arg[1]:
raise TypeError(f"Type of '{type(arg[0... | be618f2cafb963a74949e0d17fea7bc414d5d86b | 52,367 |
def read_weather_inputs(ClockStruct, weather_df):
"""
clip weather to start and end simulation dates
*Arguments:*\n
`ClockStruct` : `ClockStructClass` : time paramaters
`weather_df` : `pd.DataFrame` : weather data
*Returns:*
`weather_df` : `pd.DataFrame`: clipped weather data
"""
... | d434b034c39222f80444a79c5dede04c6052977a | 52,369 |
def _get_species_name_from_line(htmlline):
"""Inside a htmlline, return the genus and species name of a specimen.
Args:
htmlline (str): A string of html, should be from AntWeb.
Returns:
str: Genus and species
"""
a = "?genus="
b = "&species="
genus = htmlline.split(a)[-1].... | 443d7a305700b9b43838ac11a6ff968e752659ae | 52,370 |
def _find_aerosols(obs, is_falling, is_liquid):
"""Estimates aerosols from lidar backscattering.
Aerosols are lidar signals that are: a) not falling, b) not liquid droplets.
Args:
obs (ClassData): The :class:`ClassData` instance.
is_falling (ndarray): 2-D boolean array of falling hydromete... | 7df68593dfcded48a20614e5714e3c6f12317cbf | 52,378 |
import typing
def get_restriction_time(string: str) -> typing.Optional[int]:
"""
Get user restriction time in seconds
:param string: string to check for multiplier. The last symbol should be one of:
"m" for minutes, "h" for hours and "d" for days
:return: number of seconds to restrict or None... | 0581bf779a8b44eff970f38985b9af968471d0de | 52,381 |
def each_class_max(W):
"""Determine if a unique walk matrix demonstrates each class max.
Each class max is defined as:
For each class C[i] in W there exists a walk length L[x] such that
C[i] has larger number of walks of length L[x] than all other classes.
Parameters
----------
W : Numpy ... | cf4b5822fa5080cb2c343a20331e352ff4eccfaa | 52,386 |
def supply_space(max_length, target_str):
"""
使用空格将指定字符串补充到特定宽度,如果字符串本身已经超过了这个宽度,那么就不处理
Args:
max_length: 目标宽度
target_str: 需要补充的字符串
Returns:
target_str: 调整后的字符串
"""
if max_length > len(target_str):
target_str = " " * (max_length - len(target_str)) + target_str
... | cf866c68dc77c8f938b413d1bb04273ac1ec4be0 | 52,387 |
def call_with_context(ctx, func, *args, _context_callable=False, **kwargs):
"""
Returns the value of func(*args, **kwargs) within the context
Set '_context_callable=True' if your contextmanager needs to be called first
"""
if _context_callable:
ctx = ctx()
with ctx:
return func(*... | 0ded4d39d983af4d69c5bb3c5b271b4015327cd2 | 52,388 |
def removesuffix(s: str, suffix:str) -> str:
"""Removes the suffix from s."""
if s.endswith(suffix):
return s[:-len(suffix)]
return s | 538ca2ef7021b01f09a7c9db56069639a9389d95 | 52,390 |
def get_padding(shape1, shape2):
""" Return the padding needed to convert shape2 to shape1 """
assert len(shape1) == len(shape2)
h_diff, w_diff = shape1[1] - shape2[1], shape1[2] - shape2[2]
padding_left = w_diff // 2
padding_right = w_diff - padding_left
padding_top = h_diff // 2
padding_bottom = h_diff ... | 7092cb8aa11111800ecfba108b9ea7cf00e14ade | 52,391 |
def checkAnswer(guess, a_followers, b_followers):
"""Take the user guess and followers count and returns True / False"""
if a_followers > b_followers:
return guess == "a"
else:
return guess == "b" | f1e19c81795d53c80165b0b2a1d6c1bc4e21a27f | 52,392 |
import hashlib
import time
def compute_file_checksum(path, read_chunksize=65536, algorithm='sha256'):
"""Compute checksum of a file's contents.
:param path: Path to the file
:param read_chunksize: Maximum number of bytes to be read from the file
at once. Default is 65536 bytes or 64KB
:param alg... | a0b86ee70f4349809aed62195efdb2969faaacd4 | 52,394 |
def gen_wtml(base_dir, depth, **kwargs):
"""
Create a minimal WTML record for a pyramid generated by toasty
Parameters
----------
base_dir : str
The base path to a toast pyramid, as you wish for it to appear
in the WTML file (i.e., this should be a path visible to a server)
depth : ... | e0a98299b21f7e8403a56e06c03f5736f94806d8 | 52,395 |
import binascii
import zlib
def unpack_chunk(chunk_data: str) -> bytes:
"""
Unpacks a previously packed chunk data back into the original
bytes representation
:param chunk_data:
The compressed, base64 encoded string to convert back to the
source bytes object.
"""
if not chunk... | 5978ede0f699de1b9954670e355989d626dae9ed | 52,396 |
def insert_manifest(cursor, workspace_id, spec):
"""manifest情報登録
Args:
cursor (mysql.connector.cursor): カーソル
workspace_id (int): ワークスペースID
spec (Dict)): manifest情報のJson形式
Returns:
int: manifest_id
"""
# insert実行
cursor.execute('INSERT INTO manifest ( wo... | 15f5e2ae29a9169583d6c30bc46c3a56a4357883 | 52,404 |
def overlap(span, spans):
"""Determine whether span overlaps with anything in spans."""
return any(
start <= span[0] < end or start < span[1] <= end
for start, end in spans
) | 35c593c57517303744cd9fd5c0858cbef15ffff9 | 52,405 |
from typing import Dict
def preprocess_sd(sd: Dict):
"""
Removes module. from state dict.
Args:
sd: input state dict
Returns:
preprocessed state dict
"""
preprocessed = {}
for key in sd.keys():
preprocessed[key[7:]] = sd[key]
return preprocessed | db0e1b30cc2b5702f88205fb6027d6e4df64b4ed | 52,408 |
def pre_shared_key_id_getter(self):
"""Return the ID field / endpoint_name field
:param self: Instance of the entity for which this is a custom method.
:type self: mbed_cloud.foundation.PreSharedKey
:return: Entity ID (which shadows the endpoint name)
:rtype: str
"""
# The underlying value... | 9d8b12d31cbd6e951c956294cce55342d20efff7 | 52,409 |
def _format_comment(comment, comm_char):
"""Format a multiline comment."""
return '\n'.join(f'{comm_char} {_line}' for _line in comment.splitlines()) | ecbf797e32f0ba0d4e779bcbe043e487d3d65b88 | 52,410 |
from typing import List
def Unique(ls:List, **sort_args):
"""Return a sorted list of unique elements.
Args:
ls (List): The input list (or other iterable).
sort_args: Args for calling `sorted` on the subpaths in format of (path, full_path), only works if `ordered` is True. Notice that the sort... | 691277a847010957d085ad19648ac2b8db4c3706 | 52,416 |
import re
def add_subgroup_columns_from_text(
df, text_column, subgroups, expect_spaces_around_words=True
):
"""Adds a boolean column for each subgroup to the data frame.
New column contains True if the text contains that subgroup term.
Args:
df: Pandas dataframe to process.
text_column:... | c82a2d85f7df5c0cfb69055c472f00a44e32cd18 | 52,419 |
def clamp(value, min_v, max_v):
"""return rectified value (i.e. the closest point in [`min_v`, `max_v`])"""
return max(min_v, min(value, max_v)) | f4beb1ecfc57a59840a428e3443937744c3a8f83 | 52,425 |
def transform_gcp_vpcs(vpc_res):
"""
Transform the VPC response object for Neo4j ingestion
:param vpc_res: The return data
:return: List of VPCs ready for ingestion to Neo4j
"""
vpc_list = []
# prefix has the form `projects/{project ID}/global/networks`
prefix = vpc_res['id']
projec... | 46a997c9bc51f5be96f5ae95c47290c97b887a34 | 52,434 |
def isfloat(value):
"""Returns if a given value can be converted to a float or not.
Args:
value: Input value of each type
Returns:
bool: Boolean if the input value can be parsed to a float"""
try:
float(value)
return True
except:
return False | 3a0acb0d06d149761844ff3e01c30839129351c5 | 52,438 |
def I_box(m,w,l):
"""Moment of a box with mass m, width w and length l."""
return m * (w**2 + l**2) / 12 | 60287d37634c185b2e2632e5ce295d1127f3dd21 | 52,439 |
import math
def grade(zscore) -> str:
"""
Assigns a color based on a 3-point gradient of red-white-green
Returns 6-digit hexadecimal string based on zscore.
"""
def clamp(x):
"""Clamps rgb value to (0, 255)."""
return max(0, min(x, 255))
red = (255, 0, 0)
white = (255,... | 570c50e27866e5c438f0b407550517ca69e05927 | 52,444 |
def process_sample(G, sample):
""" Interpret the DQM solution in terms of the partitioning problem."""
# Display results to user
group_1 = []
group_2 = []
sep_group = []
for key, val in sample.items():
if val == 0:
group_1.append(key)
elif val == 1:
group... | 5217f01a97a10ceba9ce9a8f24eacc31ddae09ca | 52,446 |
def file_read(path, encoding='utf-8', errors='strict'):
"""
Return a file's contents as a string
"""
with open(path, 'r', encoding=encoding, errors=errors) as f:
return f.read() | 3e93b41f9ed3323fbfc3c39ce069570000ba08f7 | 52,453 |
def reverse(v):
"""
Reverses any iterable value
"""
return v[::-1] | e652b4046e3e1b473bcea4408dea33cc0ba1cee6 | 52,455 |
def round_thousands_to_1dp(value: float) -> float:
"""
Rounds values to 1dp in steps of 1000.
Rounds values greater than 1B to nearest 100M
Rounds values > 1B and >= 1M to nearest 100k
Rounds values > 1M and >= 1k to nearest 100
Rounds values less than 1000 to 1dp.
If value is not a number, ... | 2478bf43e09daef37b8d274ce5ea5c6bae4f7ddf | 52,456 |
def string_to_intlist(s):
"""Takes a normal string and returns a list of numerical values (codepoints)"""
return [ord(c) for c in s] | 6b54ea37ac3c02ed732cabbd349c102cc72fd96d | 52,458 |
from pathlib import Path
import csv
def get_csv(path: Path) -> list:
"""
Read CSV with lead column like HEADER (1), COMMENT (0..N), DATA (1..N).
:param path: Path of the csv-file (;-separated)
:return: list(dict) with keys like in HEADER row.
"""
def map_line(line: list, fields: dict) -> dict... | c2f43099b5acd5f21366e402b2eee6dd839b8e0a | 52,465 |
import collections
def find_container(intersections):
""" Returns the container node.
Parameters
----------
intersections: List[Intersection]
Full list of intersections of ray with a scene.
Returns
-------
Node
The container node
... | e1f380c30db5d8e5f13ded00dd01f126ca2b7472 | 52,466 |
import pathlib
def file_get_extension(filepath,
with_extension_dot=False,
only_last_extension=False):
"""returns the extension of a file by a provided filepath\n
with_extension_dot (default: False): True, will include the dot e.g. '.txt'\n
only_last_extension ... | 762b47905ae9598aa607a66323fefc5b507cc385 | 52,468 |
import json
def get_metrics_collections(file_paths):
"""
Reads the json files to be averaged and returns the json contents
:param file_paths: A list of file paths
:return: A list of dictionaries, which represent the metrics obtained
from one run of Collector
"""
metrics_collections = []
... | 4db2fbf3b0e63629a76a64bc4e4107fff8680e3f | 52,469 |
def get_monitor_group(subparser):
"""
Retrieve the monitor group for the argument parser.
Since the monitor group is shared between commands, we provide a common
function to generate the group for it. The user can pass the subparser, and
the group is added, and returned.
"""
# Monitoring vi... | 92ef507213c62cf5e6c9518a9b6866bcb9f0c3b7 | 52,472 |
def _normalize_names(name):
"""Normalize column names."""
name = name.strip()
name = name.strip("*")
return name | 435e6ec6ddc06bd73131fd2594a388d3175f42a5 | 52,474 |
def subs_potentials(A,B,tol):
"""Difference between two sets of data of the same length
Args:
A/B: the arrays (2D)
tol: the tolerence of the difference
Returns:
C: a new aaray (2D)
"""
C = A
for i in range(len(A)):
C[i,0] = A[i,0]
if abs(A[i,1] - B[i,1]) ... | e2ad4999bf9fccf3532f93d66df70f17ba684ca5 | 52,476 |
def sanitize(value):
"""Makes sure filenames are valid by replacing illegal characters
:param value: string
"""
return value.replace('/', '_') | 94f72e2bf1d1cf08dde9ae6c192ed1b68a875900 | 52,478 |
import requests
def fetch_local_weather(lat, lon, API_key=""):
"""
Retrieve current weather from api.openweathermap.org.
WARNING: Free API allows a maximum of 60 requests/minute
Documentation: http://openweathermap.org/current#geo
Returns a dict decoded from the API's JSON response
Returns 'N... | e18913665c29cbf946f10b5ffb729291c3d56909 | 52,485 |
def second_tensor_invariant(A):
"""
Calculates the second tensor invariant of a symmetric 3x3 matrix.
Returns a scalar.
"""
I2 = ( (A[1,1] * A[2,2]) + (A[2,2] * A[0,0]) + (A[0,0] * A[1,1])
- A[1,2]**2 - A[2,0]**2 - A[0,1]**2 )
return I2 | ff3eda7db0334371033199cbfde7631e3d3f574f | 52,486 |
def greedy(graph):
"""Calculates and returns shortest tour using greedy approach.
Runs in O(n^2). Provides approximate solution.
Args:
graph: instance of a Graph.
Returns:
list: sequence of nodes constituting shortest tour.
"""
tour = []
available_nodes = set(graph.nodes(... | b2145adb162e99532cf14574acc7b08ec058f480 | 52,489 |
import math
def solve_tilted_rectangle(xend, yend, length, width, angle, padding=0.0,
pad_upper=True):
"""
Given a rectangle of a certain length, width and orientation,
knowing the coordinates of the centre of one end of the
rectangle, return the coordinates of the corn... | 7208f27aa51aaf1abe81bd9f5180a63fede7f1f8 | 52,491 |
def hypothesis(theta0, theta1, x):
"""Return our hypothesis, or guess, given the parameters and input value"""
return theta0 + (theta1 * x) | 676745e28959d7b7bf99018236175b5b3ae84d90 | 52,494 |
import json
def load_dict(d):
"""Function that loads json dictionaries"""
with open(d,
'r',
encoding='utf-8') as in_f: # load reference dict (based on training data) to settle disputes based on frequency
dic = json.load(in_f)
in_f.close()
return dic | 55d79180d48ed9b4bb1701ce1cf89a65951076b1 | 52,497 |
def stones(n, a, b):
"""Hackerrank Problem: https://www.hackerrank.com/challenges/manasa-and-stones/problem
Manasa is out on a hike with friends. She finds a trail of stones with numbers on them. She starts following the
trail and notices that any two consecutive stones' numbers differ by one of two values... | 6181d26e3b90d5da15bcaabde6624a595a70a77e | 52,498 |
def position_order(open: list, close: list):
"""
Pair open position order with close position orders
:param open: a list of orders that may have an open position order
:param close: a list of orders that may have an close position order
:return: A tuple containing a pair of an open order with a clos... | b70a0740c59168c29226c2e083a6268ec14ad0a6 | 52,503 |
def GreedyMatching(edges, max_count: int):
"""Find matching greedily.
Edges are picked sequentially from top of input.
So, useful for greedy matching with weights as well."""
M = set()
matched_nodes = set()
for u, v in edges:
if u not in matched_nodes and v not in matched_nodes:
... | a45b1ca1a4664ab9a282dfde8b7e0c59692caf98 | 52,504 |
import statistics
def getMergeOperation(datatype):
""" FIO log files with a numjobs larger than 1 generates a separate file
for each job thread. So if numjobs is 8, there will be eight files.
We need to merge the data from all those job files into one result.
Depending on the type of data, we must su... | 12e34b3f6c35c3b0fbdd44bb49e7db814185eccb | 52,506 |
def GenericInteractHandler(widget, new_value, column_name, index):
"""Generic callback for interactive value updates."""
widget.update_dataframe(new_value, column_name, index)
return new_value | f0e09a1a761dc6916291eca415944e5c5b583d71 | 52,510 |
def should_be_dark_extensions(time_current: int, time_dark: int):
"""Determines if dark mode should be active like the extensions do"""
return time_dark <= time_current | 2a8db4acbfc686cd99d050b822bfe443a5099186 | 52,511 |
import struct
def bytes_2_double(bytes_double_string, is_little_endian=False):
"""
将8字节的bytes串转换成float.
:param bytes_double_string:
:param is_little_endian:
:return:
"""
# 小端数据返回
if is_little_endian:
return struct.unpack('<d', bytes_double_string)[0]
# 大端数据返回
return str... | cf0ff4a933ce745543b920e70c6846e4cab9f6f6 | 52,518 |
import random
def rnd(words):
"""
Picks a random word from the list.
Parameters
----------
words : list of str
list of valid words.
Returns
-------
string
the guess word.
"""
return random.sample(words, 1)[0] if words else "" | 52636d5ffb130fefe3bc4ec79e394bf7efd4e608 | 52,519 |
import re
def s3_remove_root_path(key):
"""
Remove root element from path
"""
file_link_path = re.sub(r"^[^/]+\/", "", key)
return file_link_path | 15b4f446d902df58b5beb8e3b09d0d98016c0e76 | 52,522 |
def from_min_to_day(time, organisation=None):
"""
Convert a str time with minutes as a unit (i.e. a task duration), into
another str rounded time with an 8-hour day as a unit.
If an organisation is given as parameter, we use its field `hours_by_day`
to know how long a working day lasts.
"""
... | 808d82ca8a6c0dc3124092ae7c5c9a99410ad7f6 | 52,523 |
def filter_by_datasets(data, datasets):
""" Given a list of datasets, limit the data frame to reads coming from
only thoes datasets """
# Validate dataset names first
permitted_datasets = set(list(data.dataset))
for d in datasets:
if d not in permitted_datasets:
raise ValueE... | e4753015a54e6adeb9d942a997c9441bc460fe14 | 52,525 |
import json
def parse_inputs(path_to_arguments):
"""
Function to parse the file with the hyper-parameters of the network.
Parameters
----------
path_to_arguments : string
Contains the path to a '.json' that will describe the hyper-parameters
of the... | c31ed092a1894e9221554522be15a90ea48da938 | 52,526 |
def preprocess_sents(sentences_list):
"""Clean up sentences predicted by TRAM"""
prepocessed_sents = []
for s in sentences_list:
# Replace any new lines separating parts of the sentence
s = s.replace('\n', ' ')
# Replace any double spaces which might result from previous step with a... | 4cabaf784b080f8fbf1a84d44719e934749c577d | 52,531 |
def divide(a, b):
"""Divide two numbers.
Parameters
----------
a : int, float
The dividend
b : int, float
The divisor
Return
------
int, float: the quotient
"""
return a / b | 732b5f6ce0ea5840f45e5158ca5a49748bb25e31 | 52,534 |
import struct
def encode_nibbles(val, val2):
"""Encode two values as two nibbles in a byte
Specs:
* **Nibble**: MSN LSN
* **Byte**: 0b0000 0000
* **Indexes**: 7654 3210
* **Values**: val2 val
Requirement:
* Only values (0-15) allowed
"""
assert ... | 736574176071c4a522a03f5c04b2aa5714e772aa | 52,537 |
import re
def GetBIOSStrAndIntAttributeHandles(attr_type, attr_val_table_data):
"""
From pldmtool GetBIOSTable of type AttributeValueTable get the dict of
attribute handle and its values based on the attribute type.
Description of argument(s):
attr_type "BIOSInteger" or "BIOSString... | 8201b5dc07cc1c3ed906ea23205fcf787711abd0 | 52,544 |
def av_good_mock(url, request):
"""
Mock for availability, best case.
"""
return {'status_code': 301, 'text': 'Light side'} | f66006908d9155d02d934c0438639b2797a9ddfd | 52,549 |
import jinja2
def sif(variable, val):
""""string if": `val` if `variable` is defined and truthy, else ''"""
if not jinja2.is_undefined(variable) and variable:
return val
else:
return "" | dc64cb59595dcbcf1e050da422b11eb8b28fa799 | 52,550 |
def is_model_field_changed(instance, field_name: str) -> bool:
"""
Compares model instance field value to value stored in DB.
If object has not been stored in DB (yet) field is considered unchanged.
:param instance: Model instance
:param field_name: Model attribute name
:return: True if field va... | 148138ae5833598b938979f0d1f4e407d0ea8fce | 52,551 |
def get_child_node_frequency(df):
"""
Returns the frequency of each childQID
: param df : Dataframe to analyze
: return freq : Dictionary of childQIDs and their frequencues
"""
freq = df['childQID'].value_counts().to_dict()
return freq | ae58534e53e984f91ef3b4ff1baaf79186b6c380 | 52,553 |
def _compare_first_n(series_1, series_2, n):
"""
Utility function that sees if the first n rows of a Pandas series are the same
"""
for i in range(n):
if series_1.iloc[i] != series_2.iloc[i]:
return False
return True | a06059cebd758a12953fc31eb4b06867ea3851b0 | 52,562 |
def jaccard_index_calc(TP, TOP, P):
"""
Calculate Jaccard index for each class.
:param TP: true positive
:type TP : int
:param TOP: test outcome positive
:type TOP : int
:param P: condition positive
:type P : int
:return: Jaccard index as float
"""
try:
return TP / ... | 13f5a53ca114db2b3af928db0ab9fac885ad2923 | 52,565 |
def cli(ctx, invocation_id):
"""Get a detailed summary of an invocation, listing all jobs with their job IDs and current states.
Output:
The invocation step jobs summary.
For example::
[{'id': 'e85a3be143d5905b',
'model': 'Job',
'populated_state': 'ok',
... | d5e83ecdc061e8161a5f7ca7ac9bcda864293b7d | 52,567 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.