content stringlengths 39 14.9k | sha1 stringlengths 40 40 | id int64 0 710k |
|---|---|---|
def mode(ary):
"""
mode function
find the object with the biggest number of appears in the given ary
:param ary: input ary (some iterable object)
:return: the number with the largest appearence number
"""
dct = {}
for value in ary:
if value in dct:
dct[value]+=1
... | 29cdbd665f0e23347498f69895c622797451409a | 101,720 |
def _SecToUsec(t):
"""Converts a time in seconds since the epoch to usec since the epoch.
Args:
t: Time in seconds since the unix epoch
Returns:
An integer containing the number of usec since the unix epoch.
"""
return int(t * 1e6) | 45dbe09583e294e0c8178dfb7c0dcd00b1dc46b1 | 101,722 |
def check_if_directory_has_files(dirPath):
"""
Returns True if there is any files or folders in the argument given.
Otherwise, it will return False.
Requires one argument to be defined:
- A pathlib Path object
"""
hasFiles = any(dirPath.iterdir())
return hasFiles | 218beea8269d30d5601dc8f8d2d7af69e14d5a19 | 101,723 |
from typing import Tuple
from typing import List
def load_hurdat(filepath: str) -> Tuple[List[str], List[str]]:
"""
Extracts hurricane data from hurdat2.txt file
Parameters
----------
filepath : The pathname to the hurdat2.txt file
Return
------
tracks : List[str]
... | 1ec7eeb71d25176dfac5b8848ab29004acd3563d | 101,728 |
def ComptageMot(tree):
"""Retourne le nombre de mots de l'arbre tree."""
return tree.number_words() | 4a3a53b0b2e02cf315bf60abf670ce6469b33420 | 101,730 |
def convert_df_to_array(df_Data, column):
"""
Converts data frames to arrays
Parameters
----------
df_Data : pandas dataframe
input dataframe
columns : list
columns of the input dataframe
Returns
----------
array_val : array
array version of the dataframe
... | 576a16b34a3f8dd12a4de7b71aefebc5830ad7b8 | 101,733 |
import ctypes
def _get_openblas_version(openblas_dynlib):
"""Return the OpenBLAS version
None means OpenBLAS is not loaded or version < 0.3.4, since OpenBLAS
did not expose its version before that.
"""
get_config = getattr(openblas_dynlib, "openblas_get_config")
get_config.restype = ctypes.c_... | b53d1c03f7da36d5b2b62e3f7464d3e2ce89d197 | 101,734 |
def constrain(value, minv, maxv):
"""Returns the constrained value so that it falls between minv and maxv."""
return min(max(value, minv), maxv) | d2d4c2d19f58807e750d70d362adbc04f870389d | 101,738 |
import torch
def get_mask(idx, num_nodes):
"""
Given a tensor of ids and a number of nodes, return a boolean mask of size num_nodes which is set to True at indices
in `idx`, and to False for other indices.
"""
mask = torch.zeros(num_nodes, dtype=torch.bool)
mask[idx] = 1
return mask | 5e6d949df4816cee3c643a0c0ee42dc3fb78f7fd | 101,742 |
def get_class(class_name, module_name):
"""
Retrieves a class based off the module using __import__.
"""
if not isinstance(class_name, str) or not isinstance(module_name, str):
return None
try:
# requiring parameter `fromlist` to get specified module
module = __import__(modul... | 4c0b46c0d56e05454dff8bd395e61541a5ff80f9 | 101,749 |
def format_file(path, tool):
"""Format file with clang-format and return True."""
tool("-i", path)
return True | f18e74c25b68f60ae1e468a88ec0a4301b5be506 | 101,751 |
def mem(data):
"""Total memory used by data
Parameters
----------
data : dict of pandas.DataFrames or pandas.DataFrame
Returns
-------
str : str
Human readable amount of memory used with unit (like KB, MB, GB etc.).
"""
if type(data) == dict:
num = sum(... | 7a69b55ac647e79b4a402b9286975f280c2aa484 | 101,755 |
def coerce_tag(tag):
"""
Coerce a BeautifulSoup tag to its string contents (stripped from leading and trailing whitespace).
Used by :func:`parse_status_table()` to get the text values of HTML tags.
"""
try:
return u''.join(tag.findAll(text=True)).strip()
except Exception:
return... | ef20fe5c21c91c83a14abda9b4fa8261908c4974 | 101,758 |
import random
def fillTwoOrFour(board, iter=1):
"""
Randomly fill 2 or 4 in available spaces on the board.
Parameters:
board (list): game board
iter (int): number of times to repeat the process
Returns:
board (list): updated game board
"""
for _ in range(iter):
... | 8b9f55c98a14b35f6bc6e94c5d4fccdbf473a375 | 101,760 |
import secrets
import base64
def generate_password(length):
"""
Generates a secure random password, similar to `openssl rand -base64 [length]`.
"""
password_bytes = secrets.token_bytes(length)
password_b64 = base64.b64encode(password_bytes)
return password_b64.decode() | 35b0a2e107968693031cc2e747d73eacf3118dde | 101,773 |
def int2hexstrings(number_list):
"""
list of integers to list of 4-digit hex strings
>>> int2hexstrings([0, 1, 65535])
['0000', '0001', 'FFFF']
"""
return [str("{:04X}".format(n)) for n in number_list] | 278617f8e0e762725f9545b80baec323296990a6 | 101,780 |
def presence_of_all_elements_located(locator):
""" An expectation for checking that there is at least one element present
on a web page.
locator is used to find the element
returns the list of WebElements once they are located
"""
def _predicate(driver):
return driver.find_elements(*loca... | b2bd4729c003d099c19febf57eea4fee4abbfd41 | 101,783 |
def relu_prime(z):
"""
Derivative of the Rectified Linear Unit activation function
:param z: Pre-activation result
:return: derived input
"""
return (z > 0).astype(z.dtype) | 23b27c4703e4937d1191625996f3466861c7ed6a | 101,784 |
def load_forecastMock(key, lat, lon, units, lang): # pylint: disable=invalid-name
"""Mock darksky forecast loading."""
return "" | a7cfc7d4189ed614f0800c00dc11b267a5cbecca | 101,785 |
def get_short_usage_id(full_usage_id):
"""Extract 16 bits usage id from full usage id (32 bits)"""
return full_usage_id & 0xffff | 410d4ea8cb62b5c0b94db4f9e00c774b685fdd5f | 101,789 |
def bubblesort(x):
"""
Sort array by looping through array, swapping unordered
adjacent elements until the array is sorted
"""
assign, cond = 0, 0 # track assignments and conditionals
swapped = True # variable to determine whether elements in array have been swapped
assign += 1
# contin... | 5f99a8be64f87a7a71d7e01253dff4bf32530c68 | 101,793 |
import ast
def is_docstring(node):
"""Checks if a Python AST node is a docstring"""
return isinstance(node, ast.Expr) and isinstance(node.value, ast.Str) | 48aafe94c616982d2c0be23c5453b91a98c16fe8 | 101,794 |
from typing import Tuple
def split_grab_pattern(pattern: str, default_target: str) -> Tuple[str, str]:
"""Performes splits on grab patterns ("source=>target")
will fill in the given default target, if split does not present one
Args:
pattern (str): The pattern to split
default_target (... | 6bddcd22929960858f1ad70fbf858b752d8aebad | 101,803 |
def get_energy_stats(stats, energy):
"""Extract stats for a given energy type"""
if stats is None:
return None
return stats[stats['energy'] == energy] | 04af7a6ba58faebbe40ebace721acac3b898fa57 | 101,804 |
def _set_process_name(func, process_name):
"""_set_process_name
If process_name is not set on configuration file,
func.__name__ is used as the process_name
:param func:
:param process_name:
"""
if len(process_name) == 0:
process_name = func.__name__
return process_name | 4b68274bd3cbe336b03be7458e80c39a282fa13c | 101,805 |
def most_frequent(fills):
"""Find most frequent element in array"""
if len(fills) > 0:
return max(set(fills), key=fills.count)
else:
return '' | 303d153c16787e13b53ccb53f2d5dd5a46be66cf | 101,816 |
import json
def json_dump(obj, path):
"""Save a json object to a file."""
with open(path, 'w') as f:
return json.dump(obj, f, indent=2) | dc1ca23ed1322d860cf2c9236e56394489acf29e | 101,818 |
def groupByThree(lst):
"""
Given input [1,2,3,4,5,6,7,8,9]
outputs: [(1,2,3),(4,5,6),(7,8,9)]
"""
return zip(*[lst[x::3] for x in (0, 1, 2)]) | 7e2f80d3e27b0a75bcfd3507c4f9580b4c2cf1be | 101,824 |
def fmt(message, prefix):
"""
Formats the given message by adding `prefix` at the start of each line.
If the message is multi-line then split it according to the end-of-line
terminators and add the prefix string to the start of each line.
The `prefix` is not added to the beginning of a line if the ... | 30716443a640e03e2a78f7d072ba1885a83f9141 | 101,828 |
import re
def _out_slugify_string(key: str) -> str:
"""Convert a string to snake_case."""
string = re.sub(r"[\-\.\s]", "_", str(key))
return (string[0]).lower() + re.sub(
r"[A-Z]", lambda matched: f"_{matched.group(0).lower()}", string[1:]
) | f8936467c5e5e7ff7bcbdbd4db2f6cb8c0a48522 | 101,832 |
def _complete(states):
"""Returns as per Task.complete depending on whether ALL elements of the given list are at least that state
Priority is "none", "skipped", "revealed", "complete"; this returns the lowest priority complete value that any
list entry has.
"""
toReturn = "complete"
for st... | 5a25cda918d00307b52cfb94e26e504eb749633c | 101,834 |
def get_user_input(validation_function, defaut=''):
"""
Asks user for input and checks if it is valid by validating with
validation function.
:param: validation_function: function on which the user input is validated
against
:type validation_function: function
:param defaut: default ret... | 1949bd48d1fe78950caa63ce4871d3d6ccc8904a | 101,840 |
def to_string(data, use_repr=True, verbatim=False):
"""
Convert a single datum into a string
Simply return strings, recursively convert the elements of any
objects with a :attr:`__len__` attribute, and use the object's
own :attr:`__repr__` attribute for all other objects.
Args:
data (o... | 7b9a3a97e39f2a6562946211d011066321f9e902 | 101,843 |
def getByName(list, name):
"""
Return element by a given name.
"""
if list is None or name is None:
return None
for element in list:
if element.get('name') is None:
continue
if element['name'] == name:
return element
return None | 5dae082da8e6620b6ab44eed58f0fb012dce84eb | 101,844 |
import traceback
def safer_format_traceback(exc_typ, exc_val, exc_tb):
"""
Safely format an exception traceback into a safe string.
There are common attacks that try to write arbitrary data to a server's
log files. This can happen if, for instance, a malicious user triggers
a ValueError with a c... | 519b531173dc431473575533fd0b216613e0efea | 101,849 |
def BodyForce(f, a):
"""
Adds a body force/acceleration to the acceleration.
Parameters
----------
f: float, force/acceleration to add to the
a: array, acceleration of the particles
Returns
-------
array of acceleration
"""
a += ... | 9ffef5b107fcb380940d1ed69e62cbdc954f77fb | 101,850 |
import copy
def nested_element(element, depth):
"""Makes a nested `tree.Element` given a single element.
If `depth=2`, the new tree will look like
```xml
<element>
<element>
<element>
</element>
</element>
</element>
```
Args:
element: The `etree.Element` used to create a nest... | 5c11964541eebed8d8f9b65d18d5640b9917e77e | 101,852 |
def lift(x):
"""
Lift an object of a quotient ring `R/I` to `R`.
EXAMPLES:
We lift an integer modulo `3`::
sage: Mod(2,3).lift()
2
We lift an element of a quotient polynomial ring::
sage: R.<x> = QQ['x']
sage: S.<xmod> = R.quo(x^2 + 1)
sage: lift(xmod-7)
... | 0eb345764280709ceae00cb323a4a5b23beb49b6 | 101,853 |
import pathlib
def path_to_str(source: pathlib.Path) -> str:
"""Converts a pathlib.Path to a str."""
return str(source) | 825fec05f1f80f7876b8171b8e54a145bea60cc3 | 101,856 |
def combine_real_imag(real_data, imag_data):
"""Combines two float data arrays into one complex64 array"""
return real_data + 1j * imag_data | a9f3eb9f7e6f2d2b70cca941a2c14802f4a5d069 | 101,857 |
def get_sequence(pdbfile):
"""Return Aminoacid Sequence as list"""
seq = []
oresnum = -1
for line in open(pdbfile, 'r'):
if line[:4] != 'ATOM':
continue
resnum = int(line[22:26])
if resnum != oresnum:
seq.append(line[17:20])
oresnum = resnum
re... | e4b8e49942cd4ef2224b14282cd0b0195bac41c6 | 101,864 |
import yaml
def parse_config(file_list):
"""
Parse required options from a list of configuration files
:param file_list: list
list of config files to parse
:return: tuple
Dictionaries of the required simulation inputs
"""
corsika_dict = dict()
simulation_input = dict()
... | cba2fb046445fcfe84e214ef3cd4856e28b1b6fa | 101,865 |
def MakeFindPackage(modules):
"""
Make a useful find_package command.
"""
# Print a useful cmake command
res = 'find_package(VTK COMPONENTS\n'
for module in sorted(modules):
res += ' ' + module.replace('VTK::', 'vtk') + '\n'
res += ')'
return res | 9fd9f65ea628f4b2b7865be544658d5c5f150980 | 101,868 |
def is_directory_automatically_created(folder: str):
"""
Verifies the name of the directory -> if it contains a month it returns True, otherwise False.
"""
months = [
"(01)Janvier",
"(02)Fevrier",
"(03)Mars",
"(04)Avril",
"(05)Mai",
"(06)Juin",
"(0... | 7e78466a662d7bcd899d1a15994bf03b2cf8c3da | 101,869 |
def unionIntervals(intervals):
"""
unionIntervals(intervals)
Return a list of union interval(s) of the input intervals, e.g.,
given [[1,2], [4,6], [5,8]] will result in [[1,2], [4,8]].
PARAMETERS
intervals: list or sequence-like
list of lists/tuples defining the intervals, e.g., [[0,1], [5,... | c7ebbe93d35207ea6f48b8252df6610b729ee1f2 | 101,870 |
def power_ranger(power: int, minimum: int, maximum: int) -> int:
"""Count of values raised to power are in range [minimum, maximum]."""
return len([base**power for base in range(1, maximum+1)
if base**power >= minimum and base**power <= maximum]) | ce3f99efcd92f61c10da92cc5dfd32c8e5da30e7 | 101,871 |
def regularize_name(name,salutation_set={"Prof."}):
""" Regularize professor name into last-name-first form.
Processes name in form:
'Special' (e.g., 'DGS')
'Last, First [Middle]'
'First [Middle] Last'
'Prof. First [Middle] Last'
Special (i.e., one-word) names a... | 673f28d862e3049a00c260a04ff96afa198379ec | 101,875 |
def get_usergraph_feature_names(osn_name):
"""
Returns a set of the names of the user graph engineered features.
:param osn_name: The name of the dataset (i.e. reddit, slashdot, barrapunto)
:return: names: The set of feature names.
"""
names = set()
########################################... | 2395183a3086a38732ce07af4a5b7e2a23ddc68d | 101,881 |
def row_to_dict(field_names, data, null_to_empty_string=False):
"""
Converts a tuple result of a cx_Oracle cursor execution to a dict, with the keys being the column names
:param field_names: The names of the columns in the result set (list)
:param data: The data in this r... | 40810af495907d329572988909b645ffefdb36c6 | 101,883 |
def bounded_integer(lower, upper):
"""Accepts an integer in [lower, upper]."""
# type: (int, int) -> Callable[str, int]
def parse(s):
# type: (str) -> int
iv = int(s)
if iv < lower or iv > upper:
raise ValueError("{} is not in [{}, {}]".format(iv, lower, upper))
r... | 8ad85358bb3aed73310f023692ea88632b4d0ee8 | 101,885 |
def assert_one_click(session):
"""Asserts there has only been one click, and returns that."""
clicks = session.execute_script("return window.clicks")
assert len(clicks) == 1
return tuple(clicks[0]) | 9273aff7b2463c0ecc9ba599ba0da3697e764eca | 101,890 |
def resolve_translation(obj, _):
"""Convert 'translation' from bytes to string."""
return obj.translation.decode() | 0bcfd4f1f60be8cb44031c75f1acdde5ed44dc10 | 101,895 |
import time
def obfuscate_api_key(key, verbose=False):
"""Generates the obfuscated API key to attach while logging in.
Args:
verbose (bool): Defaults to False. If set to True, end result will be printed.
key (String): The API key
Returns:
int: Timestamp of generation
key:... | 28f57431f6bda990e9042625814a919d91d4f61c | 101,897 |
def load_default_OSINT_dict(avail_hosts):
"""
Loads the default OSINT for the CybORG environment.
Arguments:
avail_hosts : dictionary of all available hosts with names as keys and extra info as values
Returns:
parsed_OSINT : the parsed OSINT dict
"""
print("OSINT: No OSINT spec... | 7b69d5f5d831752cb278a02442d1fa1a8dbb13eb | 101,900 |
def docs_modified(file_paths):
"""Report if any file in the Doc directory has been changed."""
return bool(file_paths) | 91ed4efba66336e5beeb37ba136f497af389265b | 101,910 |
def unpack_row(row, cols):
"""Convert a suds row object into serializable format.
Transform a row of results objects received from the DFP API's
Publisher Query Language Service into a Python dict.
Args:
row: A row of suds object which include an array of values.
cols: An array of strings representing... | 13f5c8e7fddfd88c26166c29628360713acb8dfe | 101,915 |
def set_support_dimensions(loading_span=10e-3,support_span=20e-3):
"""set the jig dimensions
inputs:
loading_span:
default 10mm
support_span:
default 20mm
"""
dims = {'loading_span':loading_span, 'support_span':support_span}
dims['spanratio... | 96965dcacd03ec4fffc5f5d101a0e9e761336fc1 | 101,923 |
def roman_month(date):
"""Return the month of Roman date 'date'."""
return date[1] | e3174c16d6b76ee4d6707b24d0540663335f9999 | 101,925 |
import itertools
def prettylist(name, mylist, N=10, prefix='\t'):
"""Return formatted str: first N items of list or generator, prefix & name"""
try:
return('{}{}: {}...'.format(prefix, name, mylist[:N]))
except TypeError:
ans = itertools.islice(mylist, N)
return('{}{}: {}...'.forma... | f17c685b37ed089083cac0ee0ad4b8ceff05dcd7 | 101,928 |
def make_splits(df,
target,
time_step=0,
ntrain=0.8,
nval=0.15,
ntest=0.05):
"""
Split the dataframe in train, validation and test dataframe.
For models not autoregressive, it is necessary to modify the target variable to create... | 57f1128f3b9df06bd2343b5fda75c6fb72971c6c | 101,931 |
def compute_mean_C (counts, i, j):
"""
Computes the mean value <psi | Z_i Z_j |psi> with the results of the measures.
"""
total = sum(counts.values())
n = len( list(counts.keys())[0] )
# Probabilities of having ( psi & (2^i + 2^j) ) = ab with a, b in {0,1}
p_00 = 0
p_01 = 0
p_10 = 0... | 3255aaf23719b4ec28bd6b2e74e82fcd1e350ecd | 101,933 |
def _camel_case_to_snake_case(s: str) -> str:
"""Converts a CamelCase string to snake_case."""
out = []
last_was_uppercase = False
for c in s:
if c.isupper():
out.append(c.lower())
else:
if last_was_uppercase and len(out) > 1:
out[-1] = "_" + out[-... | 36abed4db978bb6cf05124a74cea38e1faef1cf2 | 101,940 |
def best_model_compare_fn(best_eval_result, current_eval_result, key):
"""Compares two evaluation results and returns true if the second one is
greater.
Both evaluation results should have the value for key, used for comparison.
Args:
best_eval_result: best eval metrics.
current_eval_result:... | 43947b3db0643d2ae4886cb2cb85f7393e1f9aa5 | 101,944 |
def _decimal_to_ddm(dd: float) -> tuple[int, float]:
"""Convert decimal degrees to degrees, decimal minutes"""
degrees, minutes = divmod(abs(dd) * 60, 60)
return int(degrees), minutes | 2e2fd81ea5e78c8b545b35b8365379ff5ef137fe | 101,945 |
def cursors_line_num(view):
""" Return list of 0-based line numbers of the cursor(s). """
return [view.rowcol(region.b)[0] for region in view.sel()] | 164acfdbd6d08693963dbb7f44d99694152b07ec | 101,949 |
def expose(func=None, label=None, client=False):
"""A function decorator which exposes the target to the API.
Arguments:
func -- The function to be decorated
Keyword arguments:
label -- The name under which to expose this function, if
different from its real name.
client -- If T... | 00970848c88108bab1525670fbeed493b183d7ad | 101,953 |
from dateutil import tz
from datetime import datetime
def get_human_time(timestamp, timezone=None):
"""Get human-readable timestamp from UNIX UTC timestamp.
Args:
timestamp (int): UNIX UTC timestamp.
timezone (optional): Explicit timezone (e.g: "America/Chicago").
Returns:
str: F... | b1213860bad7880ec818e6330a40230c2a6b5b3e | 101,956 |
def mapper_class(relation):
"""Return mapper class given an ORM relation attribute."""
return relation.property.mapper.class_ | 585ed4aa003c92db206b6bbdda713671806dc70a | 101,958 |
import itertools
import random
def select_item(items_with_profit_ratio):
"""Given a list of tuples of the form (item_index, item_profitability_ratio, item), select an item proportionally to its profitability ratio, and return its index"""
# find the cumulative profitability ratios, code based on random.choi... | 4bdf310047a8385ec535e9fbdb5f366c108be6aa | 101,959 |
def is_dirty(store, dataset):
"""Check if a dataset is dirty."""
ds = store.get_dataset(dataset)
return ds.repo.dirty | 3b7fcd49a485343e6ccb400c051d2213723cacd6 | 101,961 |
def _clean_delim(raw_delim):
"""Cleans a run delimiter.
"""
if raw_delim == '=':
return '=='
else:
return raw_delim | 7305bf93e859a979da3508fa3910901d2555e072 | 101,962 |
import torch
def get_3d_box(tensor):
"""Calculate 3D bounding box corners from its parameterization.
Input:
box_size: tuple of (length,wide,height)
heading_angle: rad scalar, clockwise from pos x axis
center: tuple of (x,y,z)
Output:
corners_3d: numpy array of shape (8,3) f... | 42f470d258945646e00e124e690f9ac58ee30ae8 | 101,964 |
def static_vars(**kwargs):
"""Decorator to create static variables for a function
Usage:
```python
@static_vars(i = 0)
def function(x):
i += 1
return x + i
function(0) # 1
function(0) # 2
function(10) # 13
```
"""
def decorate(func):
for k in kwargs:... | e52e3dc0caaf4102bb229c4bec68cec85b56d337 | 101,968 |
import re
def parse_chunked_data(data):
"""Parse the body of an HTTP message transmitted with chunked transfer encoding."""
data = (data or "").strip()
chunks = []
while data:
length = re.match(r"^([0-9a-zA-Z]+)\r\n.*", data)
if not length:
break
length = length.gro... | 431e65c1fbe708f211e6611a5e55d58b55d2c15e | 101,969 |
from typing import Dict
def sort_stats_by_kind(stats: Dict) -> Dict:
"""
Generate dict-of-dicts for statistics.
Returns
-------
Dict[str, Dict]
A dict-of-dicts, where the key is the kind of the statistics in each dict.
"""
failure = {}
report = {}
success = {}
for k, v... | 5bae8a5e1e05f1c3117882ff53a35bd1ee7768d8 | 101,972 |
def load_char_mappings(mapping_path):
"""
load EMNIST character mappings. This maps a label to the correspondent byte value of the given character
return: the dictionary of label mappings
"""
mappings = {}
with open(mapping_path) as f:
for line in f:
(key, val) = line.split()... | 8653f22d8490add375747f2e4f1e3aa0bc006f47 | 101,973 |
def ddir(obj):
"""
List of (dir(obj)) attributes of obj that don't start with an underscore
:param obj: Any python object
:return: A list of attribute names
"""
return [a for a in dir(obj) if not a.startswith('_')] | a5c0356ddfeae9555f73b2f6d90f96070fec9631 | 101,974 |
def dissolve_contiguous(input_gdf):
"""Dissolve geometries into one polygon then explode to ensure no multiparts.
Args:
input_gdf (geopandas.GeoDataFrame): Geodataframe with polygon geometry column.
Returns:
geopandas.GeoDataFrame: Polygon geodataframe with cleaned internal boundaries.
"... | dc6522589f5b7aea52ad8109ab98c5ec8fcfae29 | 101,978 |
from typing import Optional
from typing import List
def _get_password_option_args(password: Optional[str]) -> List[str]:
"""
Get password option arguments.
:param password: the password (optional).
:return: empty list if password is None, else ['--password', password].
"""
return [] if passwo... | 4a887a204fd841a0aea364cbf0efd4b720de24f5 | 101,980 |
def write_alarm_msg(radar_name, param_name_unit, date_last, target, tol_abs,
np_trend, value_trend, tol_trend, nevents, np_last,
value_last, fname):
"""
writes an alarm file
Parameters
----------
radar_name : str
Name of the radar being controlled
... | f734983e1aa59cb9c17a2e3988d870625f9aee3d | 101,983 |
def get_midpoint(point_a, point_b):
"""Finds the midpoint of two points.
Args:
point_a: Tuple (x, y) point.
point_b: Tuple (x, y) point.
Returns:
Tuple of (x, y) midpoint.
"""
x1, y1 = point_a
x2, y2 = point_b
return (x1 + x2) / 2, (y1 + y2) / 2 | 9be080b4ecc3f4bdb8dbdd65da04823c436f86ef | 101,984 |
from typing import Counter
def check_outliers(df,list):
"""
Check for upper and lower limit
Parameters
----------
df : dataframe
dataframe to be inspected
list : list
list of columns less id
Returns
-------
outlier_index_unique : list
index of rows wi... | d12f08f14254c135f95c74185564b2d637ecd5e5 | 101,990 |
def nonempty_lines(text):
"""Returns non-empty lines in the given text."""
return [line for line in text.split('\n') if line] | 40cc5c22fc8bef4c0387ae348af3cc63f8705de1 | 101,991 |
def remove_duplicates(names, versions, versions_dict):
"""Remove the versions that exist in versions_dict.
Args:
names (list): A list with names
versions (list): A list with versions
versions_dict (dict): A dict names as keys
versions_dict example:
{'name': {'version': 'foo... | be7edc4581a687adce674519012992a5fda56015 | 101,992 |
def algorithm_1(array: list) -> int:
"""
Algorithm 1 - Brute Force
A straightforward way to solve the problem is to go through all possible
subarrays, calculate the sum of values in each subarray and maintain the
maximum sum.
The variables [i] and [j] fix the first and last index of the suba... | 2830fbde752a4316cc7e0879a3baeee42ecdd813 | 102,002 |
def uncap_sentence(sent):
"""
Workaround for tweets: sometimes the entire sentence is in upper case. If more than 99%
of the sentence is in upper case, this function will convert it to lower case.
:param sent: the tweet
:return: the sentence, lower cased if it is all in upper case
"""
ssent ... | e311c8f8ba3f995162a2235333c056785856810b | 102,009 |
def waseem_to_binary(label: str) -> str:
"""
Turn Waseem labels into binary labels.
:label: String as label.
:returns (str): label
"""
if label.lower() in ['sexism', 'racism', 'both']:
return 'abuse'
else:
return 'not-abuse' | 25cd90bdd626e8d14844bc5d44a0de044b04699c | 102,010 |
def GetSubmoduleName(fullname):
"""Determines the leaf submodule name of a full module name.
Args:
fullname: Fully qualified module name, e.g. 'foo.bar.baz'
Returns:
Submodule name, e.g. 'baz'. If the supplied module has no submodule (e.g.,
'stuff'), the returned value will just be that module name ... | 0ee42fa620f0c4727ba5c519d837ecd8f8230627 | 102,011 |
def is_leap(year):
"""Returns true if the given year is a leap year, false otherwise."""
# Every year that is exactly divisible by four is a leap year, except for years that are
# exactly divisible by 100, but these centurial years are leap years, if they are exactly
# divisible by 400.
# @see https... | 5efc4d4a4c27a02dcc057aec16f915009ba45f5b | 102,012 |
def get_seasons(df):
"""
Changes months into season
Parameters
----------
df : dataframe
the forest fire dataframe
Returns
-------
Array
Seasons the months are associated with
"""
seasons = ["NONE"] * len(df)
for x in range(0, len(df)):
m = df.loc[x... | bee62e066ee8439fb04ada471e3ebebe16d27365 | 102,015 |
def pandas_barplot(data, x, hue, y, x_order=None, hue_order=None, horizontal=True, stacked=True, **kwargs):
"""Create a barplot using pandas plot functionality
Mainly allows for stacked barplots
Parameters
----------
data : DataFrame
DataFrame with columns x and y
x : str
x def... | 0201c427867e531d9719ffefc61821db31eed52a | 102,026 |
def has_fusion(args):
"""Returns whether some kind of Fusion reference is given
"""
return args.fusion or args.fusions or \
args.fusion_tag | 08377f211dbd48c404ef0488089a9b2923ee296e | 102,029 |
def concat(ext):
"""Returns a genrule command to concat files with the extension ext."""
return "ls $(SRCS) | grep -E '\.{ext}$$' | xargs cat > $@".format(ext=ext) | 8e7dcb680616a38d3818e4dc4dab8534cab037e8 | 102,034 |
def chunk(seq, count):
"""Splits given sequence to n chunks as evenly as possible.
Args:
seq: Sequence to split
count: Number of chunks
Returns:
List of chunks
"""
avg = len(seq) / float(count)
res = []
i = 0.0
while i < len(seq):
res.append(seq[int(i):... | 35bcd80917a3a82db40d116cc3846c1ab7493194 | 102,035 |
import re
def grep(source, pattern):
"""Run regex PATTERN over each line in SOURCE and return
True if any match found"""
found = False
p = re.compile(pattern)
for line in source:
if p.match(line):
found = True
break
return found | 1f4f7f45f7a2e0dbe9fa52464707ea8ae2a97491 | 102,036 |
def add_path(tdict, path):
"""
Create or extend an argument tree `tdict` from `path`.
:param tdict: a dictionary representing a argument tree
:param path: a path list
:return: a dictionary
Convert a list of items in a 'path' into a nested dict, where the
second to last item becomes the key... | ea5e596a7e8a3c6c47fa966bfd6f091797c60974 | 102,038 |
from typing import List
import requests
from bs4 import BeautifulSoup
import re
def get_keywords(url: str) -> List[str]:
"""
Returns the keywords of a given url.
Parameters:
url (str): a website url
Returns:
all_keywords_list (List[str]): list with all keywords as strin... | 4a140d1dec9a19bbd401371dafd3726d49ab0d79 | 102,039 |
def prune_seg_tree(seg_tree, prob_threshold=0):
"""
Args:
seg_tree (list of dicts):
In order of splits as done by SegmentationModel.
E.g. 0-4, then 0-3, then 0-1, then 1-3, then 1-2, then 2-3, then 3-4
Each dict contains data about that segment.
'... | 9e65541ae37fdfa068f03cb00f408ab08ad88583 | 102,040 |
def _tag_block(block, tag):
"""Add the open and close tags to an input block."""
return f'<{tag}\n' + block + f'\n{tag}>\n' | bdd53897ec782b37e150592838ea11c58ae1d793 | 102,048 |
def unfresh_token(user):
"""Return unfresh token from user fixture
:param user: Pytest fixture
:return: Unfresh JWT access token
"""
return user.get_access_token() | 490fd3788b5c4a2110501016469496a494a784f3 | 102,051 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.