content
stringlengths
35
416k
sha1
stringlengths
40
40
id
int64
0
710k
def _rav_geterr_ ( self ) : """Get the error >>> var = ... >>> print(var.error) """ return self.getError()
dd61827bc7702006b6eee0969d23fed2e643ba74
38,790
import os def process_exists(pid): """ Determine if process 'pid' exists. """ try: os.kill(pid, 0) except ProcessLookupError: return False # Doesn't exist except PermissionError: pass # Exists but not ours return True
ad10f02c91cbe162ab3dd819c94e50514a91f166
38,792
def cell_num_to_block_offsets(cell_num): """ :param cell_num: The cell number within the block. Precondition: 0 <= y < 9 :return: (y_offset, x_offset) where y_offset is the number of cells from the top and x_offset is the number of cells from the bottom """ return int(cell_num / 3), cell_num % 3
b19c100491c8a902e51df69f8b69dfe5418d2f4b
38,794
def to_node(lines, node): """ Returns all lines connected to a given node""" return list(lines[((lines.node_i == node) | (lines.node_e == node))].index)
65132478e0ffab8e4b8687d88a02b7efc35e065e
38,796
def multi_find(s: str, f: str): """Finds every occurrence of substring F in string S. Returns a list of indexes where each occurence starts.""" res = [] scanned = 0 while len(s) > 0: found = s.find(f) if found == -1: break res.append(found + scanned) s = s[found + 1:] scanned += found + 1 return res
b306ddab98c8b7da056879c4c1e1437954d508a0
38,798
def makeTypeMaps(types): """ Build maps that allow to find appropriate serializer (by object type) or deserializer (by prefix symbol). If serialized type does not match serializer class (true for embedded types) then Class.ptype is used. If a type does not have direct analog in Python (is He...
6e67f5242a12ae30950e1d38bc8b46bb49a2526d
38,799
def sub_symbols(pattern, code, symbol): """Substitutes symbols in CLDR number pattern.""" return pattern.replace('¤¤', code).replace('¤', symbol)
4d87e263ba53e99368fb82c8c93b3998834852ad
38,800
def get_K_loss_pp(has_pipe): """配管の線熱損失係数 Args: has_pipe(bool): 配管の断熱の有無 Returns: float: 配管の線熱損失係数 (W/mK) """ if has_pipe: return 0.15 else: return 0.21
6d5baf5303e442f2dce94dba7cfb78b68a45e50a
38,801
def recursive_factorial(num): """Recursive solution""" if num >= 2: return num * recursive_factorial(num - 1) return 1
0152d119b2c69f9b1a0aa3223681733ab9718085
38,804
def count_tuples(map): """ @brief counts non zero tuples in a map @param map BitArray containing the bitmap @return Count of non-zero bytes in the bitmap""" count = 0 if map != None: for bit in map.tobytes(): if bit != 0: count += 1 return count
63725c8dfb129aaf7fa25e0362563572958cf0fb
38,807
import os def is_writeable(path, check_parent=False): """ Check if a given path is writeable by the current user. :param path: The path to check :param check_parent: If the path to check does not exist, check for the ability to write to the parent directory instead :returns: True or Fa...
d015676d09a91601c8361a24544e865a686c7511
38,808
def get_sentence(root_node): """ Given a complete sentence like (ROOT (S ...)) or (ROOT (SQ ...)), returns the nested (S ...) or (SQ ...). """ return root_node[0]
db8256fc7cfe56e469cd983c8f2097162671d519
38,810
def divide(dividend, divisor): """ :param dividend: a numerical value :param divisor: a numerical :return: a numerical value if division is possible. Otherwise, None """ quotient = None if divisor is not None : if divisor != 0: quotient = dividend / divisor return qu...
e5e6678f7de33524444b3bcd40fa45c21f42c77d
38,811
import struct import binascii def make_chunk(type, data): """Create a raw chunk by composing chunk's ``type`` and ``data``. It calculates chunk length and CRC for you. :arg str type: PNG chunk type. :arg bytes data: PNG chunk data, **excluding chunk length, type, and CRC**. :rtype: bytes """ out = struct.pack...
f4ef2410c28437561b316d768d5cdbe7cbbadc15
38,813
def strip_lower(data): """对传入的字符串进行strip和lower操作并去掉空格 """ return data.lower().strip().replace(' ','')
1717265aa2bddda6127b8c144b11e0f2337af8d2
38,814
def first_index_k_ones_right(qstr, k, P): """ For a binary string qstr, return the first index of q with k (mod P) ones to the right. Return: index in [0, qstr.length] """ num_ones_right = 0 for j in range(qstr.length, -1, -1): if (num_ones_right - k) % P == 0: return j ...
ed258c584957c5b9a778eec555c4efe80505be85
38,815
def contour_coords(contour, source='scikit'): """Extract x, y tuple of contour positions from contour data. Scikit has reversed x, y coordinates OpenCV has an unusual numpy array shape (npts, 1, 2) Parameters ---------- contour: contour data source: 'scikit' or 'opencv' Output ---...
971f269fab6c476aed1be0a047f843ff0372fe08
38,817
def find(inp, success_fn): """ Finds an element for which the success_fn responds true """ def rec_find(structure): if isinstance(structure, list) or isinstance(structure, tuple): items = list(structure) elif isinstance(structure, dict): items = list(structure.items()) ...
cf5918af04ebf66d4eab6923e84c7ff2ebe0c7f6
38,818
def get_text(node): """Get the contents of text nodes in a parent node""" return node.text
f0ac82cd958f762e9e0e5425a73a49bc5b9eaa68
38,819
import re def get_argument_value(input_string, argument): """This function gets the value of the argument from the input_string. Inputs: - input_string: Input_string containing all arguments [string] - argument: The argument of interest to be gathered from the input_string [string] Outpu...
7b2662e16459e2500084e53303516a821cf255dc
38,820
def read_column_data_from_txt(fname): """ Read data from a simple text file. Format should be just numbers. First column is the dependent variable. others are independent. Whitespace delimited. Returns ------- x_values : list List of x columns y_values : list list o...
d115c85d6675150082af61de833a5614b80bf34b
38,822
import pickle def leer_desde_archivo(archivo, valor_por_defecto=None): """Lee del archivo archivo un registro y lo retorna junto con una variable booleana que indica si llegó al fin de archivo o no. El parámetro llamado archivo tiene que estar abierto en modo binario y para lectura (rb). Si se in...
8dbaf607a3bbc0464e75b85194fd3098f0126f10
38,823
def FeaturesToXYZ(geodataframe, attr, adjustment=0.0, mult=1.0): """Converts Linestring collections to points Parameters: GeoDataFrame geodataframe Object to convert string attr Attribute to convert float adjustment Optional bias value float mult Optional multiplier for unit c...
3ef4422d7155829f36f3ecd97e42d1e48e397a52
38,824
import os def get_env_setting(setting, default): """ Get the environment setting or return exception """ try: return os.environ[setting] except KeyError: return default
dd748782d5dd8903eed981ecde85710187ea4322
38,825
def hash_password(password): """ This function is for saving passwords in a discreet way @type password: string @param password: the password to be 'hashed' """ hashed = '' for ch in password: hashed = hashed + str(ord(ch)) return hashed[::-1]
f9db1dd40cf690de5911dc9901f25a4e406c2ed0
38,826
import random def mutate(solution): """mutate(solution) Returns a mutated solution by character shift by 1 place.""" workingset=list(range(ord(" "),ord("~")+1)) new_solution=[] for cell in solution: if random.random() < (1/20): #1 in 20 chance to mutate cell. #Mutation...
ae3ad411dc4c85008ff899b30b728d8a8f3bcf09
38,827
def _map_operation(operation): """Default function to map the operation to target""" return operation
8a42b9306ef570485e27ad62b58134d58a0604b9
38,828
import subprocess def do_subprocess_with_output(cmd): """ Standardize error processing Args: cmd (str): command to execute Returns: (str): output of command """ try: output = subprocess.check_output(cmd) return output except subprocess.CalledProcessError as c...
707934ac77cfe765f9234a6bf16f30359330c578
38,829
import os def _data_root_Linux(): """ Use freedesktop.org Base Dir Specfication to determine storage location. """ fallback = os.path.expanduser("~/.local/share") root = os.environ.get("XDG_DATA_HOME", None) or fallback return os.path.join(root, "python_keyring")
b64325692bc0b1a62d01e6dbad041c6c65d006cc
38,830
def validate_item_against_schema(schema, item): """Returns whether or not the given item has the same format as the given schema. Args: schema: A dictionary mapping field name to expected value type. item: A dictionary mapping field name to value. Returns: A boolean representin...
319e8b7c703c65fea20cb586d62bfb5140f346fb
38,831
def abband(matrix, vecin, vecout, neq, iband): """ Multiplies [ banded ]{vector} = {vector} """ for i in range(neq): jlim = max(0, i - iband + 1) for j in range(jlim, i): val = vecin[j] vecout[i] += val * matrix[j][i - j + 1] # jlim = min(iband, ne...
b5bf2ce9b5a678e662c31cbd409870df5d2aa494
38,832
def getNodeIdentifiersInRow(nodes, elementsCountAround, row): """ :param: row starting at 0 for apex :return: list of node identifiers in row """ nodeIdentifiers = [] nodeiterator = nodes.createNodeiterator() node = nodeiterator.next() remainingnodesinrow = 1 currentRow = 0 while...
daa3ea848a2226c378e6f11c6768ca50ed578671
38,833
import re def _extract_current_step(current_status_string): """ Attempts to extract the current step numeric identifier from the given status string. Returns the step number or None if none. """ # Older format: `Step 12 :` # Newer format: `Step 4/13 :` step_increment = re.search(r"Step ([...
2d1ee544c1d719ddbef1c175233d8304296ea33c
38,834
def _result_str_valid(result): """Check the format of a result string per the SGF file format. See http://www.red-bean.com/sgf/ for details. """ if result in ['0', 'Draw', 'Void', '?']: return True if result.startswith('B') or result.startswith('W'): score = result[2:] if s...
57fe041359dac8c97064b264881d8e192c687793
38,835
def make_class_name(pv): """ Make a class name based on a given PV. """ return '{}'.format(pv.title())
90c3820eb68e0afb8ec90c49b94f94129646dc3d
38,836
def get_edges(faces): """ 根据面得到相应的边 @faces: 模型的所有面 return: 模型的边 """ edge2key = dict() edges = [] edges_count = 0 for face_id, face in enumerate(faces): faces_edges = [] for i in range(3): cur_edge = (face[i], face[(i + 1) % 3]) faces_edges.appe...
bc12844bd979a54e9d4e5b559a3cc846aad5929e
38,837
def _no_constraint(info_list): """ If there is no constraint set, then anything passes. """ try: if len(info_list) == 0: return True except TypeError: # constraint not set (weirdness in DB) return True return False
083c3569ac5d1d48e18708b34cb20d4b586cd86f
38,841
def binary_search_base(nums: list, target: int) -> int: """ Time complexi O(logn) The basic binary search nums is a sorted list if multi targets in nums, return one target index else return -1 """ if not nums: return -1 left, right = 0, len(nums) - 1 while left < right: ...
1af211a911ef0e206fcf0b6e25a8fe0b9cedebf8
38,843
from pathlib import Path from typing import Tuple from typing import List def python_packages_find(package_path: Path, tracing: str = "") -> Tuple[Path, ...]: """Find the various python packages within a ROS2 package.""" # next_tracing: str = tracing + " " if tracing else "" if tracing: print(f"{t...
7a982d8e45a2b140cbd894ad83b856d5dd4811e6
38,844
def build_array(text): """Returns an array of numbers contained in a text file""" with open(text, 'r') as f: nums = {int(line.strip()) for line in f} return nums
6ef1580ca0b77b3e505274feeef692009e400edf
38,845
def _pd_df_cols_match_metadata_cols(df, table_metadata): """ Is the set of columns in the metadata equal to the set of columns in the dataframe? This check is irrespective of column order, does not check for duplicates. """ pd_columns = set(df.columns) md_columns = set([c["name"] for c in tabl...
5c793646dddad977d2ec61908932ac0fac096564
38,847
def process_config_str(config_str): """ Takes potentially multi-line RawConfigParser-returned strings, strips them, and splits them by line. :param config_str: String parsed in by RawConfigParser :return: List of strings broken up and trimmed. """ if config_str is not None: return [i.str...
192b29f7f9fe5b2f8401f80ef462491c750c6588
38,848
import os import logging def create_dir(dirname): """ dirs - a list of directories to create if these directories are not found :param dirs: :return: """ try: if not os.path.exists(dirname): os.makedirs(dirname) return True else: logging.info...
08aaa681f772382e234696be1887d0bc52d0ed32
38,849
def daysinmonth(year, month): """ Return days in month based on the month and year Parameters ---------- year : str month : str Returns ------- integer of the days in the month """ if year%4 == 0: daysinmonth_dict = { 1:31, 2:29, 3:31, 4:30, 5:31, 6:...
663e4449bb7273a5a08bc7b7953540f80ac3ad2c
38,850
import os def _should_wrap_non_coroutines() -> bool: """Return ``True`` IFF ``FALCON_ASGI_WRAP_NON_COROUTINES`` is set in the environ. This should only be used for Falcon's own test suite. """ return 'FALCON_ASGI_WRAP_NON_COROUTINES' in os.environ
fb1aecb7fcd029c92f009836ee4758d161d078db
38,853
def get_pokemon_names(cur): """Returns a list of pokemon names in the database (as strs) sorted in alphabetical order Args: cur: an open sqlite3 cursor created from a connection to the pokemon db """ new_list = [] query = ('SELECT name FROM pokemon') cur.execute(query) data = c...
f55fcaaf86072a6f5ec87b40c7d75ac121e41868
38,854
def truncate_text_by_num_tokens(text, max_tokens, tok_separator=" "): """ Truncate a text to left a maximum number of tokens. :param text: :param max_tokens: :param tok_separator: :return: The truncated text. """ _toks = text.split(tok_separator) return tok_separator.join(_toks[:min...
62cc97f101c37b6452cb5649706bdf6f5f47a68d
38,855
def loop_condition(first_count, second_count, third_count): """ Custom function used to break out of while loop :first_count: number of syllables in first line :second_count: number of syllables in second line :third_count: number of syllables in third line """ return first_count <= 5 and s...
434e5a1cfe2f9271756139eac10bcb08149f3cbd
38,856
from glob import glob from os import path def contain_dicom(folder_path): """Check if a folder contains DICOM images. Args: folder_path: path to the folder Returns: True if DICOM files are found inside the folder, False otherwise """ dcm_files = glob(path.join(folder_path, "*.dc...
4d346cfef7493b4cb6d276ffeeb7e9bde6e96efc
38,857
import re def format_submitter_id(node_name, *argv): """Format submitter id""" submitter_id = node_name for v in argv: submitter_id = submitter_id + f"_{v}" submitter_id = submitter_id.lower().replace(", ", "_") submitter_id = re.sub("[^a-z0-9-_]+", "-", submitter_id) return submitter_...
c5dd4782d90a340bcedf52d15908019bbba5344b
38,858
import os def get_mount_point(path): """Get path mount point.""" if not os.path.islink(path): path = os.path.abspath(path) elif os.path.islink(path) and os.path.lexists(os.readlink(path)): path = os.path.realpath(path) while not os.path.ismount(path): path = os.path.dirname(pat...
5a82dbdb7d5980810d8841fdda166909d4d64862
38,859
def form_line(ltokens=[], rtokens=[]): """Form line.""" if not isinstance(ltokens, (list, tuple)): return str(ltokens) + ';' ltext = ' '.join(map(str, ltokens)) rtext = ' '.join(map(str, rtokens)) if len(rtokens) > 0: return '{ltext} = {rtext};'.format(ltext=ltext, rtext=rtext) ...
53f0f09a44799a425df876c1d85318725aa5a794
38,860
from typing import Dict import types import pkgutil import importlib def import_submodules(package: str) -> Dict[str, types.ModuleType]: """Recursively import all submodules of a package""" results = {} for _, name, is_pkg in pkgutil.walk_packages((package,)): full_name = package + '.' + name ...
b0aa688050f4385a76eca86b1361cae187229625
38,861
def transform(order_data_dict: dict): """ #### Transform task A simple Transform task which takes in the collection of order data and computes the total order value. """ total_order_value = 0 for value in order_data_dict.values(): total_order_value += value return {"total_order...
2f6b7b96a2ca5285cb668aad2333395ee3f9c474
38,862
import json def list_liveNode_to_json(nodes,is_pretty=False): """Print a list of LiveNode in JSON format Arguments: nodes {LiveNode} -- List of LiveNode Keyword Arguments: is_pretty {Boolean} -- True to have pretty JSON (default: {False}) Returns: JSON -- JSON fo...
186cd107a456df7316730991193fcacbe95abb01
38,864
import os def get_var(name, default=""): """ Gets the text of an environment variable, or default if it doesn't exist. """ if name in os.environ: return os.environ[name] return default
22c2e555380d2c5f052d249f666c76c05ccc6b7c
38,867
import numpy def l2(pData1, pData2): """ Returns the l2 distance >>> x = numpy.array([1,2,3]); y = numpy.array([4,5,6]) >>> l2(x,y) 5.196152422706632 """ return numpy.linalg.norm(pData1 - pData2)
f6ac962798b179b328117251485fb0ff68a188ad
38,868
def stringquote(text): """escapes quotes as neccessary and returns a string representing the text""" if "'" in text: if '"' in text: return '"' + text.replace('"', '""') + '"' else: return '"' + text + '"' else: return "'" + text + "'"
81a88b41cf85ec8927d3f51c4d6448fc3b13366c
38,869
def check_ports(port_dictionary): """ This will run through the ports that are supposedly open and see if 22 is listed. If so, it will return the device type if it can be determined or False if not open Args: port_dictionary (dict) : dictionary of either one port or multiple ports of format {<p...
57527bc72827903a5583d481b8e420f3a388aa1d
38,872
def div(dividend, divisor): """ Takes two ints and returns a tuple (quotient, remainder) """ quotient = 0 while dividend - divisor >= 0: dividend -= divisor quotient += 1 return (quotient, dividend)
78ba5951df412e0599d834ebc2a71adf0be9370f
38,873
def make_rev_adict(adict): """ An adict maps text answers to neuron indices. A reverse adict maps neuron indices to text answers. """ rev_adict = {} for k,v in adict.items(): rev_adict[v] = k return rev_adict
827a288a6937d482d7d54a4509cd85ace5ee074e
38,874
def pluralize(number, singular, plural=None): """Helper function for getting the appropriate singular or plural variant of a word or phrase. pluralize(0, 'awoo') #=> "0 awoos" pluralize(1, 'awoo') #=> "1 awoo" pluralize(2, 'awoo') #=> "2 awoos" pluralize(1, 'box', 'boxen...
da7bbe4864d38717811cc468bbda4cc076c23cf1
38,877
def my_get_sodar_info(_self): """Method is used to patch cubi_tk.snappy.itransfer_common.SnappyItransferCommandBase.get_sodar_info""" return "466ab946-ce6a-4c78-9981-19b79e7bbe86", "/irods/dest"
b2bf796f998675fb6e688c69997f24e4e6401be0
38,879
from typing import Iterable def field_lookup(obj, field_path): """ Lookup django model field in similar way of django query lookup. Args: obj (instance): Django Model instance field_path (str): '__' separated field path Example: >>> from django.db import model >>> fro...
38bdf5efa75fc9f8273d1a40f719a700b86aa026
38,880
import time def time_spent_from(start_time: float) -> float: """Calculate time spent from start_time to now Example: >>> start_time = time.time() >>> ... >>> time_spent = time_spent_from(start_time) :param start_time: time in seconds since the epoch :return: time spent from start_time to...
e96c9cc6c0ae33f6f577e49ee5c6fb95dae682e6
38,881
import re def reduce_lengthening(text): """ This helper function takes any word with more than 2 repetitions of the same char (yaaaay for instance, has 4 a repeated), and returns the word with at most 2 repetitions. Can be useful to make similar words fall together: aaaaaah and aaah will both...
d67a323ef8b4ca18ea27452513bcb99f675ef25a
38,882
def get_combat_skills(lower: bool=False): """ Returns a list of the skills that contribute to combat level in no particular order. Args: lower: If the skills should be lowercase or titlecase. """ skills = [ "Attack", "Strength", "Defence", "Hitpoints", "Ranged", "Magic", "Prayer" ] return [s.low...
e7da123590719f50a80bbd503901931b1a5f1dc7
38,883
def safe_characters(filename): """ Converts special characters e.g. from YouTube Video titles to 'safe' filenames (initially Windows 10) """ characters = {"|": "_", '"': "'", ":": " -", "@": "", "#": "", "?": ""} for old, new in characters.items(): filename = filename.replace(old, new) r...
4a90e3d2eb7f5375a7c23aaff0f9a34f06208e2c
38,884
def parse_did(did): """Parses a Rucio DID and returns a tuple of (number:int, dtype:str, hash: str)""" scope, name = did.split(':') number = int(scope.split('_')[1]) dtype, hsh = name.split('-') return number, dtype, hsh
fc8ffd99743682895b4a7dc10cbbe911a0c6ca61
38,885
def compose_subject(raw_subject: str, tag: str = "", category: str = "") -> str: """Compose a subject containing a tag and a category. If any of tag or category is missing, don't print the corresponding part (without whitespace issues). :param raw_subject: The original subject :param tag: :par...
69fc7bd6bc5a4c6568f1b9a2642c7417d18f97b9
38,886
from datetime import datetime import click def validate_optional_timestamp(ctx, param, value): """Ensure that a valid value for a timestamp is used.""" if value: try: return datetime.strptime(value, "%Y-%m-%dT%H:%M:%SZ").replace( hour=0, minute=0, second=0 ) ...
ace2b46b6b36d078b450f264164b73f88ebc2537
38,887
def _star_wrapper(arg): """ Internal helper function used to allow multiple arguments for functions called by `mp_starmap`. """ (func, args) = arg return func(*args)
e7f8dbd1cb50c35648b7cd9939d61024d7f0ff90
38,888
def track_variable(name, line_used, smali_file): """ Tries to identify the last instance a variable was set on the file before the line where it was used :param str name: the name of the variable (e.g. p1, v2, etc.) :param int line_used: the line where the variable is being used :param str smal...
19451be4853cc43451bf32ca3bc16be6cdce5e37
38,890
def _transform_str_numeric_read_negocios_realizados(row): """Transformation fucntion from string to numeric for rows of table net_per_stock. Args: row (list): List of strings Returns: list: List of strings and numeric. """ row[8] = int(float(row[8])) row[9] = float(row[9]) ...
a298ddb509908cac73d4477f3af492378ef1a3af
38,891
import os def validate_image_size(fname): """ensure that the image size is smaller than 5mb""" size = os.path.getsize(fname) if size > 5242880: return "invalid" return "valid"
587eb0eeef92650cfe3f97368c11237bcf212d34
38,894
import operator def dfSubset(data, where): """ Return a subset of the data given a series of conditions .. versionadded:: 0.1.9 Parameters ---------- data: :py:class:`pandas.DataFrame`: DataFrame to view where: str or list or tuple Conditions to apply. Notes ----...
01ae55694f89a314ef00796017cb76d393ace90f
38,895
def _match_suffix(suffix, ffilter): """Return file type (textual description) for a given suffix. Parameters ---------- suffix : str File extension to check (must include the leading dot). ffilter : dict ffilter : dict Known file types. The keys contain descriptions (names),...
7fd59ba819ac0f151d5b8156b69282f97f8601a2
38,896
from typing import Iterable from typing import Any from typing import Tuple def grouped(iterable: Iterable[Any], n: int) -> Iterable[Tuple[Any, ...]]: """ Create groups of tuples comprising 'n' values from the given iter. s -> (s0, s1, s2, ..., s(n-1)), (sn, s(n+1), s(n+2), ..., s(2n-1))... """ ...
6f45ff7151ef2501dbd0da6da6d3c6876b0ea7dc
38,899
def compare_hashes(target_hash, file_hash): """ Will compare the hash of two files. """ return target_hash == file_hash
6c197bca4fdb3d5a38e9b16848ee5010ddf7958c
38,900
def unwrap(value): """ Unwrap a quoted string """ return value[1:-1]
4852eab462a8961deb1d29b0eb4359ab12c00378
38,901
import argparse def bool_from_string(raw_value): """Parse a boolean command line argument value""" if raw_value == 'True': return True elif raw_value == 'False': return False else: raise argparse.ArgumentTypeError( 'Value must be True or False, got %r instead.' % ra...
b04abb48b851a22b44cc9aa486afcab2c5b8bccd
38,902
def expand(data): """ Function to expand dot separated match variable names to nested dictionary structure """ # do sanity check on data if not isinstance(data, dict): return data, True ret = {} # expand match variable names to dictionary for key, value in data.items(): ...
60b9e77c1e2ac37132f013c9f482c6b8ffe66bd9
38,904
def update_from_one(row): """ Function to update rows that need updated from agreement to single_coordinator Parameter --------- row: Series Returns ------- updated: Boolean or other Examples -------- >>> import pandas as pd >>> row = pd.Series( ... { ....
76c6a92acce5f30e682e2a9cf3a4cc75181aeed3
38,905
def is_board_full(board: list) -> bool: """return true if board is full else false""" return all([i != " " for i in board])
920d1693f34162fd00636f48c4ef7cfcd17c9d8c
38,906
def _is_tcp_synack(tcp_flags): """ Passed a TCP flags object (hex) and return 1 if it contains TCP SYN + ACK flags and no other flags """ if tcp_flags == 0x12: return 1 else: return 0
7537f12321bb52667118fdf4ce75985c59e6bead
38,907
import re def parse_swift_recon(recon_out): """Parse swift-recon output into list of lists grouped by the content of the delimited blocks. Args: recon_out (str): CLI output from the `swift-recon` command. Returns: list: List of lists grouped by the content of the delimited blocks ...
6fd92e6dffab521edd3dfe414ca1902d4f1859fd
38,908
import random def slice_df(df, num_devices, date_start, date_end): """ num_devices = 1000 date_start = 2014-09-30 00:00:00 date_end = 2014-12-25 20:45:00 """ df2 = df[ (df['end_time'] >= date_start) & (df['end_time'] <= date_end) ] devices = df2['Device_number'].unique() sliced_devices...
757b5139c5cecaf5cfbbfcd6fc89e0fbac7e5b5d
38,910
def sam2fastq(line): """ print fastq from sam """ fastq = [] fastq.append('@%s' % line[0]) fastq.append(line[9]) fastq.append('+%s' % line[0]) fastq.append(line[10]) return fastq
3bc2fefea2594bd3130abe97db668324daa79adc
38,911
def get_emissions_probability(label_matches, given_tag, given_word, tag_counts): """Calculates the emissions probability of associating a given tag and word by the following formula: emissions_probability = (count of word associated with tag) / (count of tag) """ lookup_tuple = (given_word, given_tag) word_tag_fr...
cdf9ba0a1645c9bc38d7bcde11096326e001ffb7
38,912
def validate_password(password): """ ensure that any input password is at least length 6, has at least one upper case, at least one lower case, and at least one special character :param password: the password of the user :return: returns True if the password is valid, False otherwise """ spe...
e8ba6946e617ac224b9733a2f7ff6dc7256bdb86
38,913
import collections def get_recommendations_item_filtred(items, similarity_matrix, x, n=5): """ Returns recommendations for x from items, based on items similar to user's items """ similarities_sum = collections.defaultdict(int) sum_prod_sim_score = collections.defaultdict(int) for item, score...
6f9175ea293f10c2d3c3a95ad0f3c458c291d8e5
38,915
from typing import ByteString from unittest.mock import Mock def create_mock_process( returncode: int = 0, stdout: ByteString = b'success', stderr: ByteString = b'', ): """ Create a mock Popen process for later inspection. Defaults to a successfully ran process. :param returncode: what t...
b310ce45eca976d399ea91dbaa40c4d1a51c5cd3
38,916
from typing import OrderedDict def deepmerge(original, new): """ Deep merge two dictionaries (new into original) and return a new dict """ merged = OrderedDict(original) for key, val in new.items(): if key in original and isinstance(original[key], dict) and isinstance(val, dict): ...
f9b3cf7313f003fb8913c4cbb573eb9743fd6ffe
38,917
import random def random_num(): """ flask 只能返回字符串数据 :return: """ return '%s' % random.random()
9e91c4794f89583a56fccbbb0bd21f363dadd54b
38,919
def filter_keys(keys): """This api is used to take a string or a list of one string and split it appropriately to get the list of keys to look for while filtering a dictionary. It is first split on basis of semicolon(;) which acts like a separator of scenarios given. Next it's split on comma which is th...
f51b783bd5e7eb054e28d0bb6f3f1689c9d61dc7
38,920
def readOrder(filename): """Read an elimination order from a file Elimination orders are stored as unknown length vectors, format "[nvar] [v0] [v1] ... [vn]" Note: the same file format may also be useful for MPE configurations, etc. """ with open(filename,'r') as fp: lines = fp.readlines()...
49af53bcabb134a2717c339f8f51bbdfbfba328c
38,921
def lower_world(): """Convert world to lower""" return {'input':'HELLO', 'output': 'hello'}
b7c9aec7756c3b0cb975be2f8d7163e989ddf589
38,922
import numpy def fill_with_zeros(evecs, from_res, to_res, width): """ Pads an eigenvector array with 0s . from_res starts from 1 """ left_padding = [0.]*((from_res-1)*3) right_padding = [0.]*((width-to_res)*3) new_evecs = [] for evec in evecs: new_evec = [] new_evec.ext...
5a8ef0d8a0d1fbc680c010e5fb4db0722af49c16
38,923
def verifyIDcardValid(ID): """verifyIDcardValid(ID) Check ID card whethear it valid The checksum is 7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2 Using the first 17 number to multiply the corresponding checksum and add them all together, then module it to 11 to get the remainder, the rema...
7c6b2cb4f45a51ac64819cf2cbe9cb8cf0554422
38,924
from typing import Union import sys def validate_smoothing_window(arg_value: Union[str, int]) -> int: """ Validates the smoothing window for the trendline. Allowed values are 0 or integers >=2. :param arg_value: The input value :return: The input parsed to an int if it's valid """ try: parsed = int(arg_value)...
e93cd340f77a101b55916f0d45197f52eaa7dfd9
38,925