content
stringlengths
39
14.9k
sha1
stringlengths
40
40
id
int64
0
710k
def user_exists(cursor,username): """ Test whether a user exists, from its username Parameters: ========== cursor: Psycopg2 cursor Cursor of type RealDict in the postgres database username: Str Name of the user """ SQL = "SELECT count(*) AS nb FROM users WHERE username=%s...
c221cbb6dd3c99d1eacfc88c8f2161276680b938
17,646
def modify_leaves(f, ds): """Walks a data structure composed of nested lists/tuples/dicts, and creates a new (equivalent) structure in which the leaves of the data structure (i.e the non-list/tuple/dict data structures in the tree) have been mapped through f.""" if isinstance(ds, list): retu...
54df919ef7ebf94a70a603e321fbe6b47b68b7c1
17,648
def netmask_to_cidr(netmask): """ Convert netmask to cidr format Notes: code from https://stackoverflow.com/a/43885814 Args: netmask (string): netmask address Returns: int: cidr value """ return sum([bin(int(x)).count('1') for x in netmask.split('.')])
613c90a814d30d01494203d06a4b7ae231f19311
17,649
from typing import List def lines_to_list(lines: str) -> List[str]: """ Transform multi-line input to a list. """ return lines.splitlines(keepends=False)
35b3d803066525f645c45702ec1773470aec964f
17,651
def energy_to_wavelength(energy: float): """Conversion from photon energy (eV) to photon wavelength (angstroms)""" return 1.2398 / energy * 1e4
19c3b56852546330a6343d47fce742556b40e2ed
17,652
import re def to_camel(s): """Convert string s from `snake_case` to `camelCase`""" return re.sub(r"(?!^)_([a-zA-Z])", lambda m: m.group(1).upper(), s)
28ac46b93230fb567321adf940e0fd37131b4903
17,661
def parse_data(data: str) -> list: """ Takes a data input string, splits and returns the components. Example: Input: "1-3 a: abcde" Output: [1, 3, "a", "abcde"} """ reqs, text = [i.strip() for i in data.split(":")] req_occurances, req_letter = reqs.split() req_low, req_high = req_oc...
d0f974877292a11ef968edf05ca41afdbc7ae5e5
17,662
def orientation(p, q, r): """ Finds the orientation of an ordered set of vertices(p, q, r). p: First vertex represented as a tuple. q: Second vertex represented as a tuple. r: Third vertex represented as a tuple. returns: 0 : Collinear points 1 : Clockwise points 2 : Counterclockw...
3651c0b6eee3550c427ad03d229d947337e7eed1
17,670
def L1(y_output, y_input): """ L1 Loss Function calculates the sum of the absolute difference between the predicted and the input""" return sum(abs(y_input - y_output))
d1b53f4aa2a47b2fe3179c657e6337dcf951a980
17,671
from pathlib import Path def get_dataset_file(working_directory, resource_name, resource_extension): """ :param working_directory: the directory containing the the requested resource :param resource_name: the name of the resource file in the directory :param resource_extension: the file extension of ...
6a08a04940e0d2e169c8b89f47e14a9fcd646d35
17,672
def expand_test_result_df(df_test): """Adds columns to a DataFrame with test results Args: df_test DataFrame as produced by trainer.ModelTrainer, i.e. with columns 'tp', 'fp', 'fn', 'correct', 'total_examples' and 'examples_above_threshold' Returns: the input DataFrame with additional column...
dea64054f8fb372d9777b6bdc9b0064843bbd459
17,673
def is_image_file(filename): """ Check if given file is image file or not Parameters ------- filename: str input file path Returns ------- img_flag: bool flag for image """ IMG_EXTENSIONS = [ '.jpg', '.JPG', '.jpeg', '.JPEG', '.png', '.PNG', ...
3ddb6589a421b91e52cacb3b0bae75c1d682d981
17,674
def check_collision(board, shape, offset): """ See if the matrix stored in the shape will intersect anything on the board based on the offset. Offset is an (x, y) coordinate. """ off_x, off_y = offset for cy, row in enumerate(shape): for cx, cell in enumerate(row): if cell an...
f66e1739abf334c7b90ba5c129d18d67c4978e81
17,675
def dstport_to_icmptc(dstport): """ Destination port to ICMP type- and code - definition taken from https://www.erg.abdn.ac.uk/users/gorry/course/inet-pages/icmp-code.html https://www.iana.org/assignments/icmp-parameters/icmp-parameters.xhtml Args: dstport `int` destination port number ...
9a1697431205a18468ef06edec7f86f5056f9419
17,681
def _serp_query_string(parse_result): """ Some search engines contain the search keyword in the fragment so we build a version of a query string that contains the query string and the fragment. :param parse_result: A URL. :type parse_result: :class:`urlparse.ParseResult` """ query = pa...
277a1de9409384e5868f9cd8a473da7950e22d2d
17,683
def get_destination_filename(path, prefix="t", overwrite=False): """ Get the output file name. :param pathlib.Path path: Destination path :param str prefix: prefix of filename. :param bool overwrite: if True then :return: file name for output :rtype: str """ if overwrite: n...
af57d27b04fa1040fa0584ca7e6250101a32d77f
17,687
from typing import AsyncGenerator def mock_subscriber(topic_event) -> AsyncGenerator: """A mock subscriber.""" async def _f(): yield topic_event return _f()
25b65cddb2dfba1ff655e9675e6af4353bd40260
17,690
def filter_count_matrix(count_matrix, n_reads=50000, n_cells=2, cpm_thresh=0.5): """ Remove poorly sequenced cells and genes with low occurrence. Filter cells if the total aligned read counts falls below a provided threshodl. Filter genes with both low counts-per-million and low occurrence among ce...
66a9f36389afb2b7014a049e52a33c982593a124
17,692
def clean_dict(dictionary): """ Returns a new but cleaned dictionary. * Keys with None type values are removed * Keys with empty string values are removed This function is designed so we only return useful data """ newdict = dict(dictionary) for key in dictionary.keys(): if di...
c48f8894b554b7c3b5f8601a9ee7edc9964989e1
17,693
def luhn_checksum(s: str) -> int: """Compute Luhn's check digit over a string of digits""" LUHN_ODD_LOOKUP = (0, 2, 4, 6, 8, 1, 3, 5, 7, 9) # sum_of_digits (index * 2) evens = sum(int(p) for p in s[-1::-2]) odds = sum(LUHN_ODD_LOOKUP[int(p)] for p in s[-2::-2]) return (evens...
d28705e84d211282d842e3ea1c8be71b3fb88be8
17,694
def print_pretty_dict(d): """ Create a dictionary like a table in CLI. One line by key. The first line (header) is Wikipedia Language Name :param d: The dictionary :return: A pretty dictionary for your CLI """ d = dict(sorted(d.items(), key=lambda item: item[0])) pretty_dict = "{:<10} {:...
41c5ae87d4d0d441f367cf74aad06b0450c6e212
17,698
def markersdates(markers): """returns the list of dates for a list of markers """ return [m[4] for m in markers]
108b3f903eb9ca8f9d510821703c5a7704cddc5a
17,701
from tqdm import tqdm def tqdm_wrap(iterable): """Use tqdm if it is installed.""" try: return tqdm(iterable) except ModuleNotFoundError: return iterable
a7ac31102d75b58105378cf43657f1dbe2f8592e
17,703
def kmer_coverage(C, L, k): """Converts contig coverage to kmer coverage Args: * C: Coverage * L: Template length * k: hash length """ return C * (L - k + 1) / float(L)
b422b92e1c4269e24f43d88844383d56406a189b
17,707
def box(request): """ Parametrized fixture determining whether/how to transform fill_value. Since fill_value is defined on a per-test basis, the actual transformation (based on this fixture) is executed in _check_promote. Returns ------- boxed : Boolean Whether fill_value should be...
b2faac79c6d78fa36342457bde0dcb4204022ab0
17,708
def interface(host): """Return an IP address for a client connection given the server host. If the server is listening on '0.0.0.0' (INADDR_ANY) or '::' (IN6ADDR_ANY), this will return the proper localhost. """ if host == '0.0.0.0': # INADDR_ANY, which should respond on localhost. r...
868ae36fdc45af5e64e53ed2222c18d04fc0c9c6
17,709
import posixpath def split_path(path): """Convert PATH to (parent-path, name), unless it is None. """ return posixpath.split(path) if path is not None else None
2a1aed6ed265ec8fee20375a0db41f9d9f94df35
17,712
import hashlib def hash_large_file(file, chunk_size=1280000000, digest=True): """fast hashing of file see https://stackoverflow.com/a/1131238/5172579 """ with open(file, "rb") as f: file_hash = hashlib.sha1() chunk = f.read(chunk_size) while chunk: file_hash.updat...
7603d2464e48fac70bc74cd3af8c5748ebeb2760
17,719
from pathlib import Path def path_exists(filename: str) -> bool: """ Checks for the given file path exists. """ return Path(filename).exists()
689c20e3417923e3538a62e35c861d2fd0cc11c5
17,721
def checker(z): """ :param z: a 2d array of complex type. For each entry in z, it lies in an unique unit square with left-bottom corner at lattice site (m, n) where (m, n) are both integers. Return a bool array of the same shape with its corresponding entry is True if m, n have the same parity e...
3c5e17272441c5d33380ee217e1e518de67199b2
17,723
def compute_daily_returns(df): """Compute and return the daily return values.""" daily_returns = df.copy() # copy given dataframe to match size and column names # compute daily returns starting from row 1 as no data present for day before day 0 # another way to do this is: (df[1:]/df[:-1].values) - 1 ...
2b73673dab8bcb0dee4e8a890d720ca933b8981d
17,724
def _literal_to_r_str(value): """Convert a python value to a corresponding R string. >>> _literal_to_r_str(True) "TRUE" >>> _literal_to_r_str(6) "8" >>> _literal_to_r_str("test") "'test'" """ _literal_to_str = {True: "TRUE", False: "FALSE", None: "NULL"} try: return _lit...
6fc6445fb4295458973dd977363536f741ab05f1
17,725
def drop_quasi_zero(df, thresh=0.05): """ Drop Quasi Zero Features Returns a passed pandas DataFrame without columns containing too few non-zero values. Parameters ---------- df : pandas DataFrame Dataset whose columns will be dropped. thresh : float, optional Minimum p...
187254b59b34f7c788ea5a3c162d6b869e852e9a
17,728
import re def pascal_to_snake(string: str) -> str: """ Converts pascal-case to snake-case. >>> pascal_to_snake(string="HelloAndGoodMorning") # Returns "hello_and_good_morning" """ words = re.findall(pattern="[A-Z][^A-Z]*", string=string) words_lower_cased = list(map(str.lower, words)) retu...
2ef5f0056d099194ffbd1aa8062fefea7664f4eb
17,737
def fluid_properties(fluid_str): """ Return the physical density and kinematic viscosity for the prescribed fluid. """ fluid_lib = {'water':(1000., 1.0e-6), 'glycol':(965.3,0.06/965.3), 'glycerin':(1260.0,1.49/1260.0)} if fluid_str in list(fluid_lib.keys()): ...
ea2784b5b9c9767e43dba787910fd5c32da8a266
17,739
def losocv_split(subjectIDs): """Create leave-one-subject-out cross-validation train/test splits. Args: subjectIDs (list): subjectID corresponding to each example. Returns: splits (list of lists): each fold's train and test indices. subjectIDset (list): unique IDs, in held-out-test...
9f7d5051e34669a5c085cf08e65bcfd66eaaa9c7
17,741
import string def letter_for(index): """Convert an index into a letter (or letter pair). a-z, then aa-az-zz""" if index < 26: return string.ascii_lowercase[index] return (string.ascii_lowercase[(index // 26) - 1] # First letter in pair + string.ascii_lowercase[index % 26]) # Seco...
aad7edbbd8941339e93b8a732857258d28d73033
17,744
def KJKGtoBTULB(hkjkg): """ Convertie l'enthalpie en kJ/kg vers btu/lb Conversion: 1 kJ/kg = 0.429923 Btu/lb :param hkjkg: Enthalpie [kJ/kg] :return hbtulb: Enthalpie [btu/lb] """ hbtulb = hkjkg * 0.429923 return hbtulb
3b26742b2e56c7e265bf94d0af15f485e091f395
17,745
def merge_list(lst, *to_merged_list): """ Merge multiple lists into the first list :param lst: :param to_merged_list: :return: """ for item in to_merged_list: lst.extend(item) return lst
29b17583c73854363277a65862efc130ae19346a
17,750
def isstr(obj): """Return whether an object is instance of `str`.""" return isinstance(obj, str)
33e1cea9b8a60d224dc395f4446f175c0b967dd0
17,751
def convert_clip_ids_to_windows(clip_ids): """ Inverse function of convert_windows_to_clip_ids Args: clip_ids: list(int), each is a index of a clip, starting from 0 Returns: list(list(int)), each sublist contains two integers which are clip indices. [10, 19] meaning a 9 clip win...
05600f2eb248ce61359a02cbcd4bd75035c6a55f
17,752
def _is_compiled(url): """ Returns True if wheel with provided url is precompiled. The logic in this method is a less efficient version of -cp[0-9]{2}- regex matching. """ prefix = "-cp" start = 0 for _ in range(len(url)): start = url.find(prefix, start) if start == -1 o...
fada4e14da5c92f7189737a3c50041f9a93acfe1
17,760
def first_and_last_n_chars(s, n1=30, n2=30): """ Utility function to display first n1 characters and last n2 characters of a long string (Adjusts display if string is less than n1+n2 char long) :param s: string :return: string for display """ first_len = min(len(s), n1) first = s[:first_...
f23b02a65f1c8c03a71498b0bcb9cc2941fd8060
17,761
from pathlib import Path def create_folder(folder_name, folder_path=""): """ Create a folder with a given name in a given path. Also creates all non-existing parent folders. Parameters ---------- folder_name : str Name of the folder to be created. folder_path : str Optiona...
ed6f239c210cc9697fe6b4bb45189cc54abda970
17,764
def log_json(request_id, message, context={}): """Create JSON object for logging data.""" stmt = {"message": message, "request_id": request_id} stmt.update(context) return stmt
b04c7101fcbc8bd800bd888e726ff131da198854
17,766
def claim_account_legacy(request): """Render a page explaining that claim links are no longer valid.""" return {}
d48db70e437fad3d8048902e640226780d3f4fb4
17,767
def comma_conjoin(inlist, conjunction): """Parses the elements of a list into a string joined by commas, with an 'and' before the final element. Oxford comma! """ if len(inlist) == 0: return "" elif len(inlist) == 1: return str(inlist.pop()) elif len(inlist) == 2: return...
1a60d7e8752436796fc518832bfece1a97914ff0
17,768
def compare_data(plt_type, correct, given): """ Determines whether the given data matches any of the data found in the correct data. This handles plots of different types: if a histogram was plotted with the expected data for a line plot, it will return True. Args: plt_type (str): The expec...
0bbd217906d86c2117c8c1b7a66a768386ca116b
17,773
def UINT(value): # noqa: N802 """Converts a value that matches \d+ into an integer.""" if value is None: raise ValueError('None is not a valid integer') if not value.isdigit(): raise ValueError('Only positive numbers are allowed') return int(value)
3d58dadf97fe26d7bfa00acb3451a39a5e5845bb
17,777
import math def get_distance(loc1, loc2): """ Computes the Euclidian distance between two 2D points.""" x_diff = loc1.x - loc2.x y_diff = loc1.y - loc2.y return math.sqrt(x_diff**2 + y_diff**2)
3a603ace039ea887cabd8b16d2b04d84d939c112
17,778
def get_rank(target, ranks): """ Get rank of a target entity within all ranked entities. Args: target (str): Target entity which rank should be determined. ranks (list): List of tuples of an entity and its rank. Returns: int: Rank of entity or -1 if entity is not present in ranks. """ for i in range(len(r...
0e247669af757a5ffa5fff016262eb677f7c3cb8
17,781
def get_attributes(obj): """ Fetches the attributes from an object. :param obj: The object. :type obj: object :returns: A dictionary of attributes and their values from the object. :rtype: dict """ return {k: getattr(obj, k) for k in dir(obj) if not k.startswith("__")}
6e1cea3ed8ad2fa1c00f7c2eb86efb4a629e9f06
17,790
def bernoulli_lh(ho, ha, s, n): """ Returns the likelihood ratio for independently distributed bernoulli random variables. Parameters ---------- ho : float null hypothesis ha : float alternative hypothesis s : float or int number of successes in sample n : float or int total number of elements i...
95b52f3f48a173a6a40fab8ae7c776a7082ebb02
17,796
def get_predicted_gender(spanish_sent): """ Return the gender of the first entity in the spanish translation. """ first_word = spanish_sent.split()[0].lower() if first_word == "el": return "male" elif first_word == "la": return "female" else: return "neutral"
94f43d37f29af4e3f1314a5e177d2e8036036a0a
17,800
import torch def make_onehot_kernel(kernel_size, index): """ Make 2D one hot square kernel, i.e. h=w k[kernel_size, kernel_size] = 0 except k.view(-1)[index] = 1 """ kernel = torch.zeros(kernel_size, kernel_size) kernel.view(-1)[index] = 1 return kernel.view(1, 1, kernel_size, kernel_size)
be324887a77f454e9f2c306e1bc9eddd8c001bb8
17,801
def manual_expo_mode(state): """ Bool to express if mode is manual. """ return state["expo_mode"] == "manual"
b9797a0e85ef9474b8819555afc33cf020031fc1
17,802
def whitelist(squat_candidates, whitelist_filename="whitelist.txt"): """Remove whitelisted packages from typosquat candidate list. Args: squat_candidates (dict): dict of packages and potential typosquatters whitelist_filename (str): file location for whitelist Returns: dict: packag...
5d8305d7ee721988420a6035d2df9e0b52404b7b
17,804
def generate_family_characteristics(df, family_id, group_ids): """ Given either an HMIS or a Connecting Point dataframe, add columns regarding family structure. :param df: HMIS or Connecting point dataframe. :type hmis: Pandas.Dataframe. :param family_id: column name of family identifier. :typ...
f4d37d396352f6e9236e6710d8115bc6a8d3e632
17,809
import functools def int_ip_from_string(ip_string): """ Convert ip4 address from string representation into int (4 bytes). Parameters ---------- ip_string : string ip4 address as string (dot-separated) Returns ------- int 4-byte integer ip4 address representation ...
d6a2cd4d93c54887697396533203d1b716e53cfe
17,811
def get_values_as_str(history, key): """Retrieve values from sequence of dictionaries.""" return [i[key] for i in history]
46687f63ce519d532f44f4aa6eb836eb079cadba
17,815
def merge_compute(left, right): """ Merge two dictionnaries but computing integer values instead of overriding. Left override every right values except when both left and right value are integers then right value will be incremented by left value. Arguments: left (dict): The dict to merge ...
37823d5c3bd94c94685aed1f965c77d787900633
17,818
def verify_params(post_dict): """ Verify that a post dict contains the expected parameters. """ if ('target' not in post_dict) or ('source' not in post_dict): return False if not post_dict['target'] or not post_dict['source']: return False return True
b0dc66873e1771a898eb0b12c778bc2c4341e69f
17,820
def _get_special_ids(tokenizer): """Gets the ids of special [T] and [P] tokens.""" trigger_token_id = tokenizer.convert_tokens_to_ids('[T]') if trigger_token_id == tokenizer.unk_token_id: raise ValueError('Tokenizer does not have special [T] token.') predict_token_id = tokenizer.convert_tokens_t...
ad3458150df641a3ae3ae3ce5d4481b438345757
17,828
import shutil def mpi_executable(preferred_executable=None): """ Return an mpi executable found on the current system. Depending on your MPI implementation, the executable name to run an MPI application may differ. This function will check which one is available and return the first valid one ...
ab197a7591da0609a4af3eee57e8b8947ab19d9d
17,830
def abs2(numero): """ (num) -> num Calcula el valor absoluto de un número >>> abs2(10) 10 >>> abs2(-8) 8 >>> abs2(0) 0 :param numero: el numero a evaluar :return: el valor absoluto del número """ if numero < 0: # La palabra clave return se utiliza para reto...
826ab80cc1af250e9e332e72c81ffcc5a5383d83
17,838
import requests def fetch_output(input_prefix, input_value, output_prefix, enable_semantic_search=False): """Find APIs which can produce the output_prefix :arg str input_prefix: The prefix of the input, e.g. ncbigene, hgnc.symbol. :arg str output_prefix: The prefix of the output, e.g. ncbigene, hgnc.symb...
1ed8f27923695ab7587f49083070aecb040987f6
17,839
def _remove_duplicate_transactions(transactions, reference_transactions): """Returns a list of transactions that are not present in reference_transactions.""" return [t for t in transactions if t not in reference_transactions]
8e2ff00dd845acd9ab63f93b8d998fe897a7d21e
17,850
def get_outdir_simupara(fp, line): """ get output directory and simulation parameters (in format: time steps) :param fp: opened file :param line: current line :return: output directory and simulation parameters Note: output directory is '' if not specified and list of simulation parameters...
22da06da0466657a5905ba3333b270787cf98a58
17,854
def get_indexing(string): """ Parse numpy-like fancy indexing from a string. Args: string (str): string represent the indices to take a subset of from array. Indices for each dimension are separated by `,`; indices for different dimensions are separated by `;`. ...
327054d0387f4bda1f3345d2886541a20e96e962
17,857
import pytz def timezonize(timezone): """Convert a string representation of a timezone to its pytz object, or do nothing if the argument is already a pytz timezone.""" # Check if timezone is a valid pytz object is hard as it seems that they are spread arount the pytz package. # Option 1): Try to conv...
1145bb17bf9c50985d88770e8fa0437bfb3e9a18
17,859
import time def convert_to_timestamp(seconds): """ Converts an integer into a string 'HH:MM:SS'. We differ a bit from python's standard time library in that if a number is negative, instead of reversing back into the 24hr mark, we return 00:00:00. """ if seconds < 0: return '0:00' ...
45428766c440c15366030b07cac95c304cefee89
17,862
def unpack_string(byte_stream): """Return decoded ASCII string from bytestring. Decode a bytes object via UTF-8 into a string Args: byte_stream (bytes): arbitrary length Returns: string: UTF-8 decoded string """ out_string = byte_stream.decode("utf-8", "replace") return ou...
5caaf20a41a05fb0026cb9131dd4825f036ec837
17,863
import importlib def import_from_module_name(module_name): """Imports a module and returns it and its name.""" module = importlib.import_module(module_name) return module, module_name
87d38536dc23c3ef86bcc1d0b5b0ec937ba397d6
17,866
def get_range_around(range_value, current_item, padding): """ Returns a range of numbers around the given number. This is useful for pagination, where you might want to show something like this:: << < ... 4 5 (6) 7 8 .. > >> In this example `6` would be the current page and we show 2 item...
28a18ff5e998ed6b5eb7ec7a0aaf540037ac1946
17,870
def get_solved (sol_dict): """Returns the solved variables of a solution dictionary""" return filter(lambda k: sol_dict[k] is not None, sol_dict)
a712caa09be029f0ad7054248cce7762644a6644
17,877
def strip_stac_item(item: dict) -> dict: """ Strips a stac item, removing not stored fields :param item dict: input stac item :rtype: dict :return: stripped stac item """ strip = item s3_key = None for link in item["links"]: if link["rel"] == "self": s3_key = li...
1909b44f316875f0cd0d65fff8bd62329cd229e5
17,881
def prepare(raw_input): """ Input is organized in three chunks: (1) rules, (2) my ticket, (3) tickets nearby. Must be prepared following different rules. (1) label ':' lower 'or' upper ',' lower 'or' upper (2) header line "your ticket:" followed by one line of comma separated integers ...
a784da2ad5ef864d3114187766acd8af2b69b868
17,889
def string_empty(string: str) -> bool: """Return True if the input string is None or whitespace.""" return not (bool(string) or isinstance(string, str) and bool(string.strip()))
cca19df1eda7039f7299c49fcb9832ce11847524
17,895
def get_attr_flows(results, key='variable_costs'): """ Return all flows of an EnergySystem for a given attribute, which is not zero. Parameters ---------- results : dict Results dicionary of the oemof.solph optimisation including the Parameters with key 'param'. key : str ...
756ec66cdf7b01cdbc6b872b4f30cf27e4ff524f
17,897
from typing import Callable import hmac import hashlib def generate_hash_key(chain_url: str, privkey: bytes, strategy: Callable): """Generate a hash key to use as `client_id`, using the :mod:`hmac` library. The message is the concatenation of `chain_url` plus the `__name__` attribute of the `strategy`. ...
1bb6b69f06c6ecb245b8ea8b4c772ede872c460c
17,898
def _rename_artifact(ctx, tpl_string, src_file, packaging_type): """Rename the artifact to match maven naming conventions.""" artifact = ctx.new_file(ctx.bin_dir, tpl_string % (ctx.attr.artifact_id, ctx.attr.version, packaging_type)) ctx.action( inputs = [src_file], outputs = [artifact], ...
6c5bf6928e79bfaf20f222bea9815643aaff3dc5
17,901
def get_config_data(config_data): """ Parameters ---------- config_data : list containing config parameters Returns ------- [config parameters] : various parameters and values from the config file """ exp_type = config_data['RobotSettings']['commandFile'] reward_dur = config_da...
b6f8199547d8177660336c8c0aab09deddf96118
17,902
import six def is_list_of_strings(vals): """Returns True if val is a list (or enumerable) of strings. False otherwise""" try: # check if everything is a string for val in vals: if not isinstance(val, six.string_types): return False except: # vals is not...
61c48b7b43acc1ab8f86c47273606a830ccb0bab
17,905
def getPruning(table, index): """Extract pruning value""" if ((index & 1) == 0): res = table[index // 2] & 0x0f else: res = (table[index // 2] & 0xf0) >> 4 return res # return table[index] & 0xf
45e9e81bef153edfa7003f5256a3e9b169a6a2c0
17,909
import torch def append_homog(tensor: torch.Tensor, homog_value: float = 1.) -> torch.Tensor: """Appends a homogeneous coordinate to the last dimension of a Tensor. Args: tensor: A Tensor. homog_value: Value to append as homogeneous coordinate to the last dimension of `tensor`. (Default: 1.0...
d07361ded84608d0aa2d4587b5418be0a6f5c395
17,910
def get_fitness(solution): """Return the fitness value of the passed solution""" if not solution: return 0 # the fitness of a valid solution coincides with its value return solution.value
bd3abcb2600ee074ce33b543c7a19b58924e3415
17,911
def pretty_size(size, unit=1024): """ This function returns a pretty representation of a size value :param int|long|float size: the number to to prettify :param int unit: 1000 or 1024 (the default) :rtype: str """ suffixes = ["B"] + [i + {1000: "B", 1024: "iB"}[unit] for i in "KMGTPEZY"] ...
abeafa97d45212c0170b981e9448e63acc1a54d2
17,914
import logging import requests def request_image(image_url): """Attempts to download the file at the URL specified and, if available, returns it as a raw response object.""" if image_url is None: logging.error("Image URL is None") return None logging.info(f"Downloading roll image {ima...
c5d0847859b9e036ebf0121f1c8a71492d0923f6
17,916
def set_title(title=None, property_name=None, channel=None): """Set title for map. Parameters: title (str): If ``None``, try to set automatically from property (and channel) name(s). For no title, set to ''. Default is ``None``. property_str (str): Map proper...
6483c8df9fafaa7e46ef667801a24a921ae871da
17,919
from pathlib import Path def ready_for_postinstall(chroot): """True if the chroot path exists and nothing mounted inside, False otherwise""" path = Path(chroot) return path.exists() and not any(path.iterdir())
c684cf9f4940f4f6e102752a2456737b5de56cff
17,920
def transition_model(corpus, page, damping_factor): """ Return a probability distribution over which page to visit next, given a current page. With probability `damping_factor`, choose a link at random linked to by `page`. With probability `1 - damping_factor`, choose a link at random chosen fr...
c7ea20809acce0f9290f3b5890122c7d34acd416
17,923
def average_speed(s1 : float, s0 : float, t1 : float, t0 : float) -> float: """ [FUNC] average_speed: Returns the average speed. Where: Delta Space = (space1[s1] - space0[s0]) Delta Time = (time1[t1] - time0[t0]) """ return ((s1-s0)/(t1-t0));
8125fb0454433288b506ffd277fa6b1bd21b06c9
17,930
from typing import Coroutine from typing import Any import asyncio def await_async(task: Coroutine[Any, Any, Any]) -> Any: """Await async task in sync function. Parameters ---------- task : Coroutine task to be awaited, eg f() where f is async function. Returns ------- Any ...
9dc6c3301dcc91036e05059b695b3edba9de61a1
17,931
import socket import struct def send_packet(mac_str): """Send magic packet to given mac address :param mac_str: mac address string separated by : :return: """ def broadcast(magic): s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADC...
cd6a8fe49d43b1970995068302f611839b454187
17,940
import hashlib def hash_file(file_content): """Create an md5 of file contents""" the_hash = hashlib.md5(file_content.encode('utf-8')) return the_hash.hexdigest()
ba3b84edb78ccb70e4fb37b8cc6c8eb73c0d108b
17,944
from datetime import datetime def unrets_date(rets_date): """ Converts a RETS date (ISO 8601 format) into a Python datetime :param rets_date: a RETS/ISO 8601 date :type rets_date: str :rtype: datetime.datetime :return: rets_date as a Python datetime """ # For datetimes with microsecon...
9f8cae6880ac4d2f285eff856db09da0a39ec4ee
17,946
def add_nones(word): """Change word into a list and add None at its beginning, end, and between every other pair of elements. Works whether the word is a str or a list. """ def yield_it(word_string): yield None it = iter(word_string) yield next(it) ...
63c8437361f2f0cc200665d7cdf6a41aab7eaf67
17,948
import six def make_key(*args, **kwargs): """ Given any number of lists and strings will join them in order as one string separated by the sep kwarg. sep defaults to u"_". Add exclude_last_string=True as a kwarg to exclude the last item in a given string after being split by sep. Note if you on...
b5c48386304ab248518a7330605fbcfb37ecad23
17,950
def has_restart_file(job): """Check if the job has a restart file.""" return job.isfile("fort.77")
d6d5bd748722ab5bdc83461728d5a02e539d25ed
17,951
import hashlib def compute_file_checksum(path): """ Compute a SHA1 checksum for a file. """ with open(path, 'rb') as f: checksum = hashlib.sha1(f.read()).hexdigest() return checksum
d253d98039a916be19ee3ad1c3d050b2dd251c1e
17,955