content
stringlengths
35
416k
sha1
stringlengths
40
40
id
int64
0
710k
def has_single_uses_stmt_only(stmt): """Check to see if this statement has exactly one 'uses' substatement without defining its own properties """ # First, check 'uses' substatements usess = stmt.search('uses') if len(usess) != 1: return False # Then check local property definition...
56bdf78decb351287bff564eac8da5c21027a795
45,170
def display_menu_prompt(): """display function for the menu prompt""" return input("Enter the ordinal of the setting to update (enter q to exit): ")
59ff19f300bfe81c36cd409823c5fa5547ad87a9
45,171
def featgen(a_tree): """Generate features for the given BitPar tree. Args: a_tree (dsegmenter.bparseg.constituency_tree.CTree): BitPar tree for which we should generate features Returns: list: string features """ assert a_tree.leaves(), "Tree does not contain leaves." # add u...
882959c96315c2606bb56c25bb9bd650b4c6e1fa
45,175
def str2_bool(v): """ This function converts a string to bool if this is the case. If the value received is of type bool, it is just returned. If it is a string and has one of these values "yes", "true", "t", "1" regardless of whether it is uppercase or not, it will return a bool with a true v...
bfd12b9983b6da4039f76127c1b7fbb9aa0cb841
45,176
def process_issue_results(data): """Process the data returned by the issues GraphQL request. Args: data: The data returned Returns: issues: A list of dicts; each dict is the data for some of the results """ edges = data.get("data").get("repository").get("issues").get("edges") issues = [] fo...
42a9aae67df7dc824c495983e63b88163c269c36
45,177
def cal_base_aggregates(lst, input_df): """ Used to calculate basic aggregations sum(), min(), max(), mean(), median(), any(), count() """ out = 0 if lst == "sum": out = input_df.sum() if lst == "min": out = input_df.min() if lst == "max": out = input_df.max() ...
824a24df44c4f5837b91cc4ee26ffd3a5ddbd4c7
45,178
def SizeBenefitAccDth(t): """Accidental death benefit per policy""" return 0
0f7e72beb0ebdedc53e1a4ed08a2584f9811ed6f
45,179
def exp_moving_avg(cur, prev=None, alpha=.05, steps=None): """exponential moving average""" if prev is None: return cur avg = alpha * cur + prev * (1 - alpha) return avg / (1 - alpha ** steps) if steps else avg
2f12e3425ee6190c4bf0a8ce7938abaaadf05052
45,180
def annot_type(ann): """ Returns what type of annotation `ann` is. """ return tuple(sorted(set(ann) & {'bbox', 'line', 'keypoints'}))
5dd7b11e264c918429dcac61903e6f80fe6e0cfe
45,181
def clean_parquet_data(df): """ Cleans parquet data """ # subset of English-only tweets df = df[df['lang'] == 'en'].reset_index(drop=True) # gather lengths of tweets df['tweet_length'] = df['full_text'].apply(lambda x: len(x)) # remove tweets that are abnormally long df = df[df['twee...
5e31069e6ab3edab06bf13bb04a5c3daa630a4d7
45,183
import io def remove_multiple_newlines_in_txt(txt: str) -> str: """ This function will remove multiple, sequential newlines in text (str) data. :param txt: a str containing the text to be cleaned. :return: a str containing the text with multiple, sequential newlines removed. """ clean_txt = '' ...
9b1be808c4253b0f2b58b1985b10417a65b7cdeb
45,184
def name_to_shortname(name): """take the first two letters from the first and from the last name.""" if name.count(' ') >= 1: name = name.lower() name = name.split(' ') name1 = name[0] name2 = name[len(name)-1] return name1[0:2]+name2[0:2] else: return ''
0ccb0e19cd9fc60f6bb9deeceddfb26e839b1ed7
45,185
def get_adts_hdr(data_size): """ AAAAAAAA AAAABCCD EEFFFFGH HHIJKLMM MMMMMMMM MMMOOOOO OOOOOOPP 11111111 11110000 0110000H HH0000MM MMMMMMMM MMM11111 11111100 """ hdr_size = 7 hdr_bin = "1111 1111 1111 0001 0110 000{}0000{}1 1111 1111 1100".format( "010", # as 2ch or "001" as 1ch ...
906663313e24c53b5723583e6d2f6f6a474876d6
45,186
import subprocess def download_video(vid, outfile, container_format): """ Returns boolean indicating success or failure """ url = f"https://youtube.com/watch?v={vid}" download_format = "bestvideo+bestaudio/best" if container_format == "mp4": download_format = "mp4" ret = subproce...
5155b239d25f14276bc6ffb3911d4e7702c8d784
45,188
def raw_remove_comments(input): """ takes a raw string """ comment = False out = "" empty = True for elem in input: if comment == False: if elem == "%": comment = True empty = False else: out += elem els...
91c836fb2a95b013cbefc6c59bc73c2fd9004f6c
45,190
import os def _get_dir_basename(dirname): """Gets the base name of the directory.""" return os.path.basename(os.path.abspath(dirname))
a98b74ddbfc5ef316d21603f2008da89b620ad0b
45,191
import argparse def get_parser(): """ Gets argument parser of the command-line version :return: argument parser """ _parser = argparse.ArgumentParser(description='Search for a tag and value in multiple API pages') _parser.add_argument('--command-line', help='Shows command line dialog', ...
bbfef73bd5969e90f98ea38f767032a169048a5a
45,192
import subprocess def julia_version(exe): """ Return the version of the julia executable `exe` as a string. Parameters: exe - the path to a possible Julia executable. """ words = subprocess.run( [exe, '-O0', '--startup-file=no', '--history-file=no', '--version'], check=True, capture_o...
8d32fca71d347f5c080612018c8af098a5734e53
45,193
def check_row(row): """ :param row: str, the user's input :return: bool, if the format is correct """ if len(row) != 7: return False # Check if row[1], row[3], row[5] is space for i in range(3): if not row[1 + 2 * i].isspace(): return False # Check if row[0...
010864e1610467453c9cb27d7015a613ac0ca072
45,194
def _fake_dropout_factory(): """Returns an dropout-like mapping that leaves the input unchanged.""" return lambda x, deterministic: x
05eb6aaa0be353f2e4a788caf7a832ef9e26c351
45,195
import importlib def _import_class(cls: str): """Take a string FQP and return the imported class or identifier clas is of the form "package.module.klass". """ mod, name = cls.rsplit(".", maxsplit=1) module = importlib.import_module(mod) return getattr(module, name)
b2b3cddf49b88f99b35c6720d12d96dfa007441c
45,196
def naive_matching(target, original): """ target:需要匹配的字符串,比如 efg original:字符集合 abcdefghijkl """ len_t = len(target) len_o = len(original) i, j = 0, 0 while i < len_t and j < len_o: # 找到首字母 if target[i] == original[j]: print(i, j) i, j = i + 1, j +...
8083296f82d30ac51f5b7447bf27fefed53f3bb0
45,197
import os def replace_name_part(paths, replace_this, with_this): """Replace the replace_this string with the with_this string in the file names from the paths list provided""" # initialize a counter for the files file_counter = 0 # initialize a list to store the failed paths failed_paths = [] ...
b703374c6200aaa9575f9d4ae3b2b742a8c66376
45,199
def read_files(filename): """ Reads a file line by line and commits it to a variable. Takes a file and reads it line by line, commiting each line to memory. Returns the variable as a tuple with each line as an item. Args: filename: the location of the file to be read. Returns: Ret...
e21597f55f515614255eac5992a6ac75179a249f
45,200
def message_to_pretty_string(incoming_message): """ Args: incoming_message: dict Returns: str """ try: formatted_message = "{0} | {1} | {2} | [errno:{3}] | {4} | {5} | data: {6} | {7}".format( incoming_message['result'], incoming_message['action'], ...
2c9147146067d2e02879320d5f2bac94a0160be9
45,209
def uniq(elems): """Generate a set of unique objects""" output = {} id = 0 for elem in elems: duplicate = False # look up for duplicates for oid, other in output.items(): if elem == other: # creating a relationship elem.set_id(oid) ...
4939308a450ec863637e5e9abe561e4a8cb86407
45,210
from urllib import error, request def fetch(url): """ This simply downloads the given url or fetch landing page from the given url :param url: website url :return: length of the landing page from the given url :rtype: str """ try: data = request.urlopen(url).read() return ...
c80c20b91b02ce837a97e6c46c8deaa305417a1e
45,211
def make_readable(seconds): """ Write a function, which takes a non-negative integer (seconds) as input and returns the time in a human-readable format (HH:MM:SS) HH = hours, padded to 2 digits, range: 00 - 99 MM = minutes, padded to 2 digits, range: 00 - 59 SS = seconds, padded to 2...
30ba121c84526dda77705908b1486c46d1e5f8d4
45,212
def get_current_domain(r): """ From original source, structures website domain name """ return '{scheme}://{host}'.format( scheme='https' if r.is_secure() else 'http', host=r.get_host(), )
66ef8a7e79fc211ce7db42b47eeccce19459d605
45,214
import time def millitime(*a, **kw): """The difference, measured in milliseconds, between the current time and midnight, January 1, 1970 UTC. >>> e = millitime() >>> type(e) <type 'int'> """ ts = time.time(*a, **kw) return int(ts * 1000)
926c615f1596588f3ac02c5936a3f7c6f39bd67f
45,215
def create_schema(): """Create schema for the given index that is queried. Useful if there are no results returned. :return: schema of index """ return {"schema": "to_be_created"}
e8c8b8c02ffffd2ec38d782d94217c7f2e6d2870
45,216
def cli(ctx, active=False): """Update the job lock status by setting ``active`` to either ``True`` or ``False``. If ``True``, all job dispatching will be blocked. Output: """ return ctx.gi.jobs.update_job_lock(active=active)
e5d06422907ec0ff3b90d82ca4a06769acfcac69
45,217
def port(request): """ Destination port override for tests """ return request.config.getoption('--port')
fab1a2a9b34dfb8e94ae42687c498dba358e4fdc
45,218
def template_used(response, template_name): """ :response: respone from django test client. :template_name: string with path to template. :rtype: bool """ templates = [t.name for t in response.templates if t.name] assert template_name in templates, templates return True
c52a3afc9f2592aa92ef6d8efda6c689a3e2d0bb
45,219
def check_var_constraints(var_constraints, rule_walks): """ Check variable constraints of the rule. Parameters: var_constraints (list): variable constraints from the rule rule_walks (pd.DataFrame): all walks matching the rule Returns: rule_walks (pd.DataFrame): all walks matchi...
b379526ee6a288b2a7de1ca224edf19be698acc9
45,221
from typing import Iterator from typing import Tuple from typing import Any def _duplicate_avoiding_dict(pairs: Iterator[Tuple[Any, Any]]): """ The default output_type of CollectionParser.delimited_pairwise. Returns a dict from key-value pairs while ensuring there are no duplicate keys. """ ret =...
5be688e4e509997c4cf10403d7b7599b07cf83e5
45,222
import os def _expvars(path): """Alias to os.path methods to expand vars and user in path. Args: path(str): Path Returns: str: Modified path """ return os.path.expanduser(os.path.expandvars(path))
515533263463a36b62437a7bbb1b9b23c784b858
45,226
from typing import Optional import sys import subprocess def recommended_executable(program_name: str) -> Optional[str]: """Shows the program which would be executed based on path.""" if sys.platform == 'win32': program_locator = 'where' else: program_locator = 'which' try: re...
9bf1793c63f0813946f73636e06c7dea418555c2
45,227
def fix_alignment (src_tag_dict, standard_tag, lang): """Fix no alignment. Make the length of each sentence in source language the same as the target language. Then evaluate the performance easily.""" final_tag = {} for sentence in src_tag_dict.keys(): final_tag[sentence] = [] for i in ...
ef56ca0fee0648a152b4b3d472a91bf9278dae77
45,228
def both(f, g): """Return a commentary function that says what f says, then what g says. NOTE: the following game is not possible under the rules, it's just an example for the sake of the doctest >>> h0 = both(say_scores, announce_lead_changes()) >>> h1 = h0(10, 0) Player 0 now has 10 and Play...
d355e3c2eb666702752a386825745a36a11675ef
45,229
def smart_mul(x, y): """ 0- and 1- aware multiply, to prevent computation graph from getting very large """ if x == 0 or y == 0: return 0 elif x == 1: return y elif y == 1: return x else: return x * y
8c6005df2ddd6c46b3c253c240aeab8dc70e5a02
45,230
def remove_extra_spaces(inputstr): """Remove extra spaces in *inputstr* so that there are only single spaces. Parameters ---------- inputstr : str Returns ------- str """ while ' ' in inputstr: inputstr = inputstr.replace(' ', ' ') return inputstr.strip()
78578fa75d3416a3da9b7a542337c7ce19291888
45,231
def flatten_tree(tree: dict, full: bool = False) -> dict: """ Flatten an execution tree to make it easier to read. Task trees are often a single node nested several levels deep. These trees may be collapsed into a list. The execution order is the same, but it's easier for a human to read. Before: ...
77b133b80d70256643e22d1b778c1bdecb00badf
45,232
def f(z): """ A complex function of the user's design. """ return 0
e33a84edd127822a9bfc10540e5b24cdf765ef08
45,233
import pathlib def mzcompose_location(mz_root: str) -> pathlib.Path: """Return the absolute path to mzcompose. MZ_ROOT is expected to be set via pyactivate. """ return pathlib.Path(mz_root, "bin", "mzcompose")
80de24e6d4ea4bde9e846b2f7e942ed64a0d0e3f
45,234
from typing import Dict from typing import Tuple def apply(dfg: Dict[Tuple[str, str], int]) -> Dict[Tuple[str, str], float]: """ Computes a causal graph based on a directly follows graph according to the heuristics miner Parameters ---------- dfg: :class:`dict` directly follows relation, should b...
c022aa8da1d5436f62b000619959a14db75672b2
45,235
from datetime import datetime def get_timestamp(): """ Get the time now, formatted as YYYY/MM/DD-HH:MM:SS Returns: (str): The properly formatted date right now. """ now = datetime.now() return now.strftime("%Y/%m/%d-%H:%M:%S")
e99d9390269d59b8aa3cd932596f8d8e9b533c90
45,236
def center(x, y, canvas_w, canvas_h, object_w, object_h): """ Returns a positional tuple that will centre a surface on another surface. """ # Do some math and return a positional tuple for use in the outer scope return x + canvas_w // 2 - object_w // 2, y + canvas_h // 2 - object_h // 2
91603a33d381b8de5074e7b522e257c2b20e177b
45,237
def is_valid(value, matcher, require): """Determine if a value is valid based on the provided matcher. :param str value: Value to validate. :param matcher: Compiled regular expression to use to validate the value. :param require: Whether or not the value is required. """ ...
d67ee9f6dbc6136703e5c0bf42b04c6a7547b0d3
45,239
def shape_to_strides(shape): """ Constructs strides from shape (for objects with no special strides). """ strides = [] curstride = 1 for s in reversed(shape): strides.append(curstride) curstride *= s return list(reversed(strides))
8bea7683eeff0cf4f8c528aa59058cb19ff48d7c
45,240
def fahrenheit_vers_celsius(t: float) -> float: """convertit une température t exprimée en degrés Fahrenheit en son équivalent en degrés Celsius """ return (t - 32) * 5/9
bb63e776c4979deb8e42adb71dd415790e17a8f9
45,241
def is_segmentable(partic_id): """ A function that returns True if the participant's interview clip is not in the manually identified set of troubled clips. The clips below were not segmentable do to excessive static, proximity to the virtual interviewer, volume levels, etc. """ troubled = s...
58859f155d315311f353d31df4dcee47bd21ceb6
45,242
def quote(env, args): """Returns its argument; stops evaluation: (quote (1 2 3)) = (1 2 3) """ if len(args) > 1: raise ValueError( "Function quote expectes one argument, got: '{}'" .format(args) ) else: return args.car()
4b652a61b535dc36cd5449ad609c07aac82e4615
45,243
def int_to_bytes(num, lens): """ int转bytes :param num: 整数 :param lens: 目标bytes的字节长度 :return: bytes类型 """ int_bytes = int(num).to_bytes(lens, byteorder='big') return int_bytes
2dee2d30ba5fb93cd9f8b74a0dc16e9c0ca20dad
45,245
import select def read_ready(*read_fds, timeout=None): """Returns a list of file descriptors that are ready to be read. Args: *read_fds (int): Integers that refer to the file descriptors. timeout (float): A timeout before returning an empty list if no file descriptor is ready. Non...
ac0005928ca836c08f5064f34bb7093c695e2220
45,246
def solar_geometric_mean_longitude(julian_century): """Returns the Solar Geometric Mean with Julian Century, julian_century.""" solar_geometric_mean_longitude = ( 280.46646 + julian_century * (36000.76983 + julian_century * 0.0003032) ) % 360 return solar_geometric_mean_longitude
ef414d97cf620be1a367e3b3dc2b8ba8c7aa5a68
45,247
import logging def get_logger(name, level, fmt=None): """ Get logger from logging with given name, level and format without setting logging basicConfig. For setting basicConfig in paddle will disable basicConfig setting after import paddle. Args: name (str): The logger name. level...
ef8bc7864f0369b95dd7d08c4ef40cd5916a7d3a
45,248
import argparse def parse_args(args): """Parses command line arguments""" parser = argparse.ArgumentParser(prog="discover", description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) parser.add_argument("-m", "--model", type=str, required=True, ...
0ae8ae5174bf657a6facfc8bdeac262e1a24c992
45,249
from typing import List def ks_filter_ascending(features: List[dict]) -> List[dict]: """ Filter out ascending path/rows from a STAC query """ return [f for f in features if int(f['properties']['landsat:wrs_path']) < 100 and int(f['properties']['landsat:wrs_row']) < 100]
e55b80ee10cdc786d8418836532ca1cdfe7adfda
45,250
import json def get_ignore_info(request): """Extract a dict of residues to ignore from the post request""" ignore_dict = request.POST.get("ignore") return json.loads(ignore_dict)
a200378b959b4d5b5b560df6e4d101909c086894
45,253
def export(varname): """Returns "export varname={formated value}\\n" """ var = str(globals()[varname]) frmted_var = var.strip("'\"").replace("\"", "\\\"").replace(r"\n", r"\\n") return f"export {varname}=\"{frmted_var}\"\n"
0c0e0d09cfbc8784fc4ce7e265b5be4e534dc4ff
45,254
import secrets def _make_token(num_bytes=16): """ Creates a cryptographically-secure, URL-safe string (for Python 3.6+) """ return secrets.token_urlsafe(num_bytes)
6b23ff243380619d92a0e36da14fc1b5a64ca519
45,255
import os import glob def _get_conventions(return_type): """ Get available SOFA conventions. Parameters ---------- return_type : string, optional ``'path'`` Return a list with the full paths and filenames of the convention files ``'name'`` Retur...
bb7d34218e433bf9ca3bb8baa4f70f53480ac091
45,256
def properties_to_dict(filepath): """ Convert Java .properties file to a dict Only include non-commented lines """ out = {} with open(filepath) as prop_file: for line in prop_file.readlines(): line = line.strip() if line and (not line.startswith('#')): ...
d425bfa4a3e3d10b8a3625232d55a098b914db03
45,257
def specific_time_range(data_frame, min_range, max_range): """ :param max_range: :param min_range: :param data_frame: :return: """ return data_frame[min_range:max_range]
abb7ef1e698ad773aca0b7d5db9674b03e01a9bf
45,261
from typing import Dict from typing import Any import importlib def get_contract_definition(contract_name: str) -> Dict[str, Any]: """Returns the abi JSON for a contract name.""" try: return importlib.import_module("artifacts." + contract_name).__dict__ except ModuleNotFoundError: raise Ty...
f5870b512bc2abbee501b061ea550690354b9646
45,262
def parse_sources(sourcedef): """parse a source definition such as 'src1:1.0,src2' into a sequence of tuples (src_id, weight)""" sources = [] totalweight = 0.0 for srcdef in sourcedef.strip().split(','): srcval = srcdef.strip().split(':') src_id = srcval[0] if len(srcval) > ...
9462ca2f27f8a210aa55e72f82ed56cca152140d
45,264
def prep_key(key): """ Prepare key. :param key: Key to use. 8-character hexadecimal, with or without 0x. :type key: str """ if key is None: key = input("PGP KEY (0x12345678): ") return key
d30ca3a15fb53034ba0eca7edeb35f7a5e308337
45,266
def assert_equals(source_dict, expected_dict): """ Check equality with expected values in dictionary keys. Args: - source_dict (dict): the dict containing the keys/values that should conform to expected values - expected_dict (dict): the dict containing keys of the ...
884d3bbb46d32f52fc758bffd8e7f4787ceb4b5f
45,269
def import_cmd(cmd): """Return the full module name of a fully-quallified function call """ #print 'cmd', cmd lp = cmd.index('(') ftoks = cmd[:lp].split('.') imp = '.'.join(ftoks[:-1]) return imp, cmd
b0912967afbabf43ff5cc5d0eedf808e68d8cede
45,270
def is_end_of_file(empty_line_count): """ Checks whether reading of file reaches bottom of file """ return empty_line_count > 5
c6ba5121180c7bb10beed460c10ed285e7aedecb
45,271
import sys def _called_with_wrong_args(factory): """Check whether calling a function raised a ``TypeError`` because the call failed or because something in the factory raised the error. :param factory: the factory function that was called :return: true if the call failed """ tb = sys.exc_...
f1426b3ab101779c8e672611977ccd35c6f81901
45,272
from pathlib import Path import argparse def valid_dir(path): """Helper method for parse_args to convert to Path and verify if the directory exists. Args: path: path to directory from parse_args() Returns: The absolute path of the given directory if it exists Raises: argpars...
9d4698a6ea258aadbddd2876d9804a817e982be2
45,273
def approx_pretty_size(total_bytes) -> str: """ Return a humane and pretty size approximation. This looks silly bellow 1KB but I'm OK with that. Don't call this with negative total_bytes or your pet hamster will go bald. >>> approx_pretty_size(50) '1KB' >>> approx_pretty_size(2000) '2K...
dc9a15fed28e0bb9d5ca9d51d2f15a10887c70ea
45,275
def get_time_with_unit(time): """This method sets seconds in minutes, hours or days.""" sec_in_min = 60 sec_in_hour = 60 * 60 sec_in_day = 24 * 60 * 60 if time % sec_in_day == 0: time = time / sec_in_day unit = 'days' elif time % sec_in_hour == 0: time = time / sec_in_h...
9c6dd5230de7a3e213cb935af56a874711d14e3b
45,276
def is_implicit_newline(raw): """should we add a newline to templates starting with *, #, :, ;, {| see: http://meta.wikimedia.org/wiki/Help:Newlines_and_spaces#Automatic_newline_at_the_start """ sw = raw.startswith for x in ('*', '#', ':', ';', '{|'): if sw(x): return True re...
f4d2ed48b378cdbd1e4cc5d0bd2816154b2afb1f
45,277
def literally(obj): """Forces Numba to interpret *obj* as an Literal value. *obj* must be either a literal or an argument of the caller function, where the argument must be bound to a literal. The literal requirement propagates up the call stack. This function is intercepted by the compiler to alt...
eff86e0db241abfa895c1fcc69dee7cb99ad6370
45,279
import json def get_dict(body_string): """ Generates dict from message body :param string :return dict object """ body_string = json.dumps(body_string) body_string = body_string.replace("'", "\"") body_string = json.loads(body_string) message_body_obj = json.loads(body_string) ...
469bd091078552ee613cd5faaa4a53b14303ac63
45,280
def clean_names(name): """Function to clean local authority names in various datasets in order to join data from different sources. """ strings = [ " Metropolitan Borough Council", " Metropolitan District Council", " Royal Borough Council", "Royal Borough of ", "L...
a31f3f5935226dea0efade0ff81fa72dbff2e272
45,281
import string def prettify_permission_name(perm_name: str) -> str: """Takes a internal D.py permission name (such as send_tts_messages) and converts it to a prettified form suitable for showing to users (send_tts_messages -> Send TTS Messages)""" pretty_perm_name = string.capwords(f"{perm_name}".replace('_', ...
fea3a27a9f3a9f1c80641b571705a3d43a4678d3
45,283
def c_to_f(temp): """ Converts Celsius to Fahrenheit. """ return temp * 9/5 + 32
49071c9f52b47e3ae2d03133d68e63071ac8eb00
45,284
def argspec_args(argspec, constructor, *args, **kwargs): """ Return (args, kwargs) matching the argspec object :param argspec: argspec to use :type argspec: argspec :param constructor: is it a constructor ? :type constructor: bool :param args: :type args: :param kwargs: :type kw...
0fb5c402ab7ff15ef57069ac4f0671469f67be72
45,286
import os def hasLsf(): """Returns True only if LSF is available""" ret = os.system("which bsub > /dev/null") return (ret == 0)
99a940cfe824eeb2b1add3c2c8919ad38f937d37
45,287
def prio_dscp_map(duthosts, rand_one_dut_hostname): """ This fixture reads the QOS parameters from SONiC DUT, and creates priority Vs. DSCP priority port map Args: duthosts (pytest fixture) : list of DUTs rand_one_dut_hostname (pytest fixture): DUT hostname Returns: Priority ...
9538063704fc0a09599f7a8577781d0900e92404
45,289
def lerp(value1, value2, amt): """Calculates a number between two numbers at a specific increment. The amt parameter is the amount to interpolate between the two values where 0.0 equal to the first point, 0.1 is very near the first point, 0.5 is half-way in between, etc""" return value1 + amt * (v...
b94f21d3c6f646102f74560c815a3304a741e391
45,290
def search(pd_db, year=0, author='', journal='', author1='', title='', doi='', byindex=False): """ search panda database by keywords """ if ("author1" not in pd_db.columns) and ("author" in pd_db.columns): pd_db["author1"] = [ x.split(' and ')[0] for x in pd_db['author'].values ] if year != 0: ...
ea04736876d9b83b342d22a9e3f7d15bb5f12278
45,295
def split_folds(X, y, fold_series, test_fold): """Take a dataset whose observations have been grouped into folds, then perform a train-test split. X, y: feature and target DataFrames. fold_series: Series containing the fold numbers of the observations. test_fold: Integer, the fold number that w...
38051e584c427ffe77273fbbcdd764b6fe432b2f
45,296
import time def str2time(sTime, timeformat="%Y-%m-%d %H:%M:%S"): """字符串转化为时间戳 Arguments: sTime {str} -- 时间字符串 Keyword Arguments: timeformat {str} -- 时间字符串格式 (default: {"%Y-%m-%d %H:%M:%S"}) Returns: int -- 时间戳 """ oTime = time.strptime(sTime, timeformat) ...
f7e775636005031ea80c2602137906828c977218
45,297
def ffs(x: int) -> int: """Find first set - returns the index, counting from 0 (from the right), of the least significant set bit in `x`. """ return (x&-x).bit_length()-1
1d9fef75b58bba59e0ddb442115d1f5c62dd7844
45,298
def radon_cyclomatic_complexity_parser(stdout, stderr, previous_reports=None): """ Example line: F 31:0 get_datetime - A """ lines = stdout.split('\n')[:-1] summary = {'A': 0, 'B': 0, 'C': 0, 'D': 0, 'E': 0, 'F': 0} for line in lines: words = line.split(' ') if len(words) == ...
c11a74f2d06bc70f1dab0293118fb0eb75ae58e6
45,300
import re def _validhex(hexstring): """_validhex(hexstring) validate a string as being a hex color value """ if len(hexstring) == 7 and hexstring[0] == '#' and \ re.match('[0-9A-Fa-f]', hexstring[1]) and \ re.match('[0-9A-Fa-f]', hexstring[2]) and \ re.match('[0-9A-Fa-f]', hex...
e1559e4996b5a0f2c6e0c1fab66ff8af5bf9698a
45,301
from typing import TextIO from typing import Tuple def run(inp: TextIO) -> Tuple[int, int]: """Solution for 2021 Day 2""" data = inp.read().splitlines() horizontal = 0 depth = 0 instructions = [(item.split()[0], int(item.split()[1])) for item in data] for direction, distance in instructions: ...
71f89f65195cb2dea8a25261a368cfc969110ba2
45,302
import logging def is_logging_to_tty(): """Return true iff all logging destinations are terminal devices.""" if not logging.root.handlers: logging.basicConfig() assert logging.root.handlers for handler in logging.root.handlers: if not (isinstance(handler, logging.StreamHandler) and handler...
bb74626a55b64b65a532c2fb09313841614cb89b
45,303
def all_services(request): """Return all test services.""" return request.param
165df889ce0e2729aaed431fbdc1020b6d3cf034
45,305
def _reformat_mspass_error( mserr, prefix_message, suffix_message="Some requested metrics may not be computed" ): """ Helper for below used to reformat a message from ccore functions that throw a MsPASSError. Needed to produce rational messages from different error metric calculations. :para...
469755c1251e98ab1ab15708956e0d3bba048627
45,306
def lost_techs(): """Find research that was canceled due to the building being destroyed.""" query = """ select ois.match_id, ois.player_number as number, destroyed::interval(0) as timestamp, technologies.name as value from object_instance_states as ois join ( select max(obje...
9fbb345205aae382a914437e2f516e422325df4d
45,307
def get_largest_mol(mol_list): """ Given a list of rdkit mol objects, returns mol object containing the largest num of atoms. If multiple containing largest num of atoms, picks the first one Args: mol_list(list): a list of rdkit mol object. Returns: the largest mol. ""...
f8d2692c34c5a49ecdeb6c3f3c5345091651c182
45,309
def zip_dict(*dicts: dict, default=None) -> dict: """ Takes a list of dicts, and creates a union of all dicts with the values from each dict as elements of a tuples zip_dict({a: 1, b: 2}, {a: 2, c: 3}) == {a: (1, 2), b: {2, None}, c: {None, 3}} """ keys_sets = tuple(set(d.keys()) for d in dicts) ...
66c66856829ac0cc4f9f256e0778ad8b335d9fd1
45,310
def patternhost(pattern, user): """ Given a 'something-%s-example.org' format, return that with %s replaced (once) by the username in question. """ return pattern % user
96127b71b701f2e112bced8fd7e299001bdefea7
45,311
def capitalize(txt: str) -> str: """Trim, then turn only the first character into upper case. This function can be used as a colander preparer. """ if txt is None or ( not isinstance(txt, str) and repr(txt) == "<colander.null>" ): return txt txt = str(txt).strip() if txt == ...
30ccfddfa4baa9f91caf7a0ca4b924d65f8401e6
45,312