content
stringlengths
39
9.28k
sha1
stringlengths
40
40
id
int64
8
710k
def ensure_dtype(data): """ To ensure that input file and output file are comparable, data types should be the same in all files. #Input: @data: pandas DataFrame #Output: @data_trans: transformed pandas DataFrame with corrected dtype """ # dtypes taken from Hestia website data_tr...
bb99607a93cd5ef383c754e5d2dba62ed5478c06
657,851
import re def encode(name, system='NTFS'): """ Encode the name for a suitable name in the given filesystem >>> encode('Test :1') 'Test _1' """ assert system == 'NTFS', 'unsupported filesystem' special_characters = r'<>:"/\|?*' + ''.join(map(chr, range(32))) pattern = '|'.join(map(re.es...
1c8df18bde7535b8d7729bc708fd041236bd10fd
682,697
def collect_reducer_count(values): """Return the number of values >>> collect_reducer_count(['Sheep', 'Elephant', 'Wolf', 'Dog']) 4 """ return len(values)
f398326ffb9932a8a033d158140f065cff6d6453
657,975
def observer(*fields): """ Observer decorator The `observer` decorator takes `*args` which represent django field names that should be observed for mutations. The `ObserverMixin` is responsible for monitoring the fields for mutation & acting on it but the decorator takes the list of fields to ...
7e49023470e677a3c56ae293daf47c628216c023
33,048
def libc_version(AVR_LIBC_VERSION): """ Example: 10604 -> 1.6.4 """ s = str(AVR_LIBC_VERSION) ls = [s[0], s[1:3], s[3:5]] ls = map(int, ls) ls = map(str, ls) return '.'.join(ls)
a600f5f1dc8a2959ac210fd955dc30f3201bf745
306,607
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
def to_ascii(text): """ Force a string or other to ASCII text ignoring errors. Parameters ----------- text : any Input to be converted to ASCII string Returns ----------- ascii : str Input as an ASCII string """ if hasattr(text, 'encode'): # case for existin...
44183b27e56912e99fb1d865ffd94497c50a6620
181,838
def _replace_keys(kwargs, replacements): """Replace illegal keys in kwargs with another value.""" for key, replacement in replacements.items(): if key in kwargs: kwargs[replacement] = kwargs[key] del kwargs[key] return kwargs
85e73ba58206c28a9bfa88599c65505febc91394
198,356
def commuting_sets_by_indices(pauli_sums, commutation_check): """ For a list of pauli sums, find commuting sets and keep track of which pauli sum they came from. :param pauli_sums: A list of PauliSum :param commutation_check: a function that checks if all elements of a list ...
4e5a7413f363a3c315df665c21cf5c00a3020df9
269,300
def initCalc(hOverR, R0, boxwidth, nParticles, nSmooth=32, ndim=3): """ Initial derivations from settings Parameters ---------- hOverR : float Ratio of scale height to distance from star RO : float Distance to star boxwidth : float Width of the simulation box. ...
08225910f9aeb82d7982419d92142413473a8338
139,536
def make_list(items): """ Turn the items into a multicolumn itmeize list `items` is a list of (string, bool) tuples where the string is the participant name and the bool indicates whether the participant has been eliminated """ def color(name, eliminated): return (f'\\textcolor{{elim...
24e2b6727626405e6fb77593c681a325cd41fcfb
166,553
def scale_net_input_data(data): """Rescale data, presumably obtained from an 8-bit grayscale image, to the range [0, 1] for feeding into the network. """ return data / 255.
cd088dcf53333efc9e698ab9b7c37dab8e9d4767
334,059
from typing import Tuple def get_channel_values(digitalOut, func) -> Tuple: """Get the result of applying 'func' to all DigitalOut channels.""" return tuple(func(channel_index) for channel_index in range(digitalOut.count()))
0f8fffa2bae965e72fe386ae356c8f11b14db9fc
653,910
from typing import Tuple def default_pruning_sparsities_loss(extended: bool) -> Tuple[float, ...]: """ The default sparsities to use for checking pruning effects on the loss :param extended: extend the sparsties to return a full range instead of a subset of target sparstiies :return: the spar...
3af38c848b984860830572e7f1126acb0d907d4c
325,695
def get_issue_info(obj): """Retrieve IssueTrackerIssue from obj. Args: obj: Instance of IssueTracked object. """ if hasattr(obj, "audit"): issue_obj = obj.audit.issuetracker_issue else: issue_obj = obj.issuetracker_issue return issue_obj.to_dict() if issue_obj else {}
e9d1a493a3e47cf871827a70354fb40f0b948908
567,748
def set_op1_str(nvols): """ Build the operand string used by the workflow nodes Parameters ---------- nvols : int Returns ------- strs : string operand string """ strs = '-Tmean -mul %d -div 2' % (int(nvols)) return strs
dd06e4fc1ed2872b341cac88f940d2bc39294a0d
95,913
def split_text(text: str, line_length: int) -> str: """ :param text: The text to split. Keeps original line breaks. If impossible to break words in a line, it will remain as is. :param line_length: The max line length. Must be higher than 1. :return: The message, split over multiple lines to keep wi...
70430bf584d6b332cb5e6721bd79ae0af59ca8ed
179,108
def zero_indices(values): """Gets the indices of values that evaluate to false ("zeros").""" return [i for i, x in enumerate(values) if not x]
b71440f0eb895c1b432568656e38fc6557e18fd9
303,660
from typing import List from typing import Iterable def argmax_over_index_set(lst: List[float], index_set: Iterable[int]) -> List[int]: """ Computes the argmax function over a subset of a list. In contrast to the related `np.argmax` function, this returns a list of all indices that have the maximal v...
c9e0e76ecd61eb81bf87cc69a4b6e7c90cc08caa
341,554
def filter_by_book_style(bibtexs, book_style): """Returns bibtex objects of the selected book type. Args: bibtexs (list of core.models.Bibtex): queryset of Bibtex. book_style (str): book style key (e.g. JOUNRAL) Returns: list of Bibtex objectsxs """ return [bib for bib in ...
ca3b46772930a6f6e28b6fc0ee4d175ee8d69c3c
703,474
from typing import List def assert_optional_type_hints(contents: List[str]) -> List[str]: """ Find parameters with default value None and add Optional[type] to them. :param contents: list of lines in file :return: list of lines in file """ i = 0 while i < len(contents) - 1: line ...
d95a3eec4c3e2ef0874d5ee974c614eecdddc8a7
668,142
import torch def interp(x: torch.Tensor, xp: torch.Tensor, fp: torch.Tensor) -> torch.Tensor: """One-dimensional linear interpolation for monotonically increasing sample points. Returns the one-dimensional piecewise linear interpolant to a function with given discrete data points :math:`(xp, fp)`, evalua...
0ff3efc776a9ed1b5261f89067fd14cbbd2ba485
301,631
def minmax_seq(a): """Find mix & max in a list by sequential algorithm. - Time complexity: O(n). - Space complexity: O(1). """ if a[0] < a[1]: cur_min, cur_max = a[0], a[1] else: cur_min, cur_max = a[1], a[0] for i in range(2, len(a), 2): if i + 1 < len(a): ...
bfa80767f1b110a9fe44d3b8162e7bd2b85ff8b4
356,237
def compute_ema(ema0, y_value, alpha=0.1): """ema_t+1 = (1-α)ema + αy""" assert isinstance(y_value, (int, float)), "y_value has to be a number" return (1-alpha)*ema0 + alpha*(y_value)
3751b27e56a7849589eaa7282fb67d9f03a5062c
424,574
def get_tagged_atoms_from_mol(mol): """Takes an RDKit molecule and returns list of tagged atoms and their corresponding numbers. Parameters ---------- mol: rdkit.Chem.Mol RDKit molecule. Returns ------- atoms: List[rdkit.Chem.Atom] List of tagged atoms atom_tags: Li...
b32d57a2feb7196907cdf70bf62371f58fe66c6a
71,117
def count_file_lines(file_name: str) -> int: """ Count the number of line in a file """ with open(file_name, encoding='utf-8') as f: return len(f.readlines())
96d49242214bf9048747ba15633a600fc4978ee9
212,968
def topic_record_subject_name_strategy(ctx, record_name): """ Constructs a subject name in the form of {topic}-{record_name}. Args: ctx (SerializationContext): Metadata pertaining to the serialization operation. record_name (str): Record name. """ return ctx.topic + "-...
a4a29c93f2b13319889ce242a4fbe0e8254598a0
225,703
def arcs2d(arcs): """Convert arcseconds into degrees.""" return arcs / 3600.0
0570463fa2c0a2723959f43767319b9a8d6c75e4
686,024
def _segregate_NREM_runs(runs, min_separation): """ Differentiate successive runs of NREM based on gap durations separating them. Stage 2 of detecting NREM cycles - minimum separation of successive runs Parameters ---------- runs : pd.DataFrame Successive NREM runs with onsets and offs...
b443654d7991e38872cdb7d6dd01d39e76f40529
415,953
import math def round_to_n(x: float, n_digits: int) -> float: """Round a floating point to n significant digits Args: x (float): Number to round n_digits (int): Number of digits to keep Returns: float: Rounded version of x with n_digits digits """ ...
e7eab22122f741ed6b583fb6e4ce3abb0fa91271
669,393
def is_subj(tok): """ Is this token a subject of its parent token. """ return "subj" in tok.dep_
9a6d1b4ac759bac39d3ca14e929e9a0e96fb8c9a
282,612
import csv def count_samples_from_tsv(phenofile, keep_hpos, invert=False): """ Count number of samples in phenofile with at least one of keep_hpos """ n = 0 with open(phenofile) as fin: for sid, phenos in csv.reader(fin, delimiter='\t'): hits = [h in phenos.split(';') for h i...
ad6e9c87c31236598aabeb66e6fac613a5c3db21
528,119
def get_max_id(corpus): """Get the highest feature id that appears in the corpus. Parameters ---------- corpus : iterable of iterable of (int, numeric) Collection of texts in BoW format. Returns ------ int Highest feature id. Notes ----- For empty `corpus` retu...
ef0fe6612f01b1434fc8c375c899f3a83c26dcea
254,662
def kwargs_to_flags(**kwargs): """Convert `kwargs` to flags to pass on to CLI.""" flag_strings = [] for (key, val) in kwargs.items(): if isinstance(val, bool): if val: flag_strings.append(f"--{key}") else: flag_strings.append(f"--{key}={val}") retu...
aa672fe26c81e7aaf8a6e7c38354d1649495b8df
707,025
def case_default_panels(case_obj): """Get a list of case default panels from a case dictionary Args: case_obj(dict): a case object Returns: case_panels(list): a list of panels (panel_name) """ case_panels = [ panel["panel_name"] for panel in case_obj.get("panels", [...
b59cf15cce29b2ce7c88d1ad91acce0b8c0e122b
291,409
def list_remove_repeat(x): """Remove the repeated items in a sequence.""" y = [] for i in x: if i not in y: y.append(i) return y
fe22b084887e00e4f25d85d388e18f4439a6a7a1
176,297
def generate_output(advisory_id: str, details: dict) -> str: """ Generates the output for the given advisory_id and list of CPEs :param advisory_id: Advisory ID from the OVAL XML file :param details: Dictionary containing a list of CPEs and repositories for the advisory_id :return: Output to displa...
06f19ea4988d95cba7c1afb23ad228b8f838fbb0
606,142
def to_int(s, default=0): """ Return input converted into an integer. If failed, then return ``default``. Examples:: >>> to_int('1') 1 >>> to_int(1) 1 >>> to_int('') 0 >>> to_int(None) 0 >>> to_int(0, default='Empty') 0 ...
9e102ee1bbd116584575930477c78f6c139e5da2
330,289
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 convertAtoInt(s): """ Convert little endian hex string to integer. B402 -> 02B4 -> 692 """ v = '' while len(s): v = v + s[-2:] s = s [:-2] return int(v, 16)
fb866f865ffb0e5c32f7b1757e6693d72adddb55
563,207
def get_free_area(space_region, obstacle_map): """ Return the total free area in space region, accounting for obstacles. Args: space_region: tuple of form (origin_x, origin_y), (range_x, range_y) obstacle_map: dict of form {id: (x, y), (range_x, range_y)} Returns: float area ...
3ed8603cd43cb65695c6a03bbcc164518ff9665d
188,385
import re def sanitize_k8s_name(name, allow_capital_underscore=False, allow_dot=False, allow_slash=False, max_length=63, suffix_space=0): """From _make_kubernetes_name sanitize_k8s_name cleans and c...
c67ed0ac6efa9659d19f4d0e59401f8e94c3b9f4
162,418
def list_games(interface): """ Sends a request to retrieve a list of games to join/currently played and outputs the response json. Returns the json and response. """ response = interface.get_request('/games/') json = response.json() for i in range(len(json)): json[i]['ref_number'] =...
a4e82ee7dde05e1c2faaa98197f2183a8950fa49
455,099
def remove_substrings(text, to_replace, replace_with=""): """ Remove (or replace) substrings from a text. Args: text (str): raw text to preprocess to_replace (iterable or str): substrings to remove/replace replace_with (str): defaults to an empty string but you replace su...
765247ffd7ee4caa33a3afffbca7e47799bc0b16
582,832
def _nb_models_and_deficit(nb_targets, potential_targets): """ Calculates the number of models to learn based on the number of targets and the potential targets Args: nb_targets: number of targets potential_targets: attributes that can be used as targets Returns: nb_models: number ...
9e664401ae9502be3675b3645bb9382666d9a017
240,539
def ask_yes_no(question): """ Ask the user a yes or no question via commandline :param question: The question to be displayed :return: True if the user answered with yes, False otherwise """ while True: print(question + " [y/n] ") choice = input().lower() if choice in ['...
f049c08408d6f8bd4b429c6f8bc287e5f1c7c9d7
417,700
def right_triangle_calc(n): """ Returns right triangle of level n Formula derived from right triangle definition (n+1)choose2 """ return int((n*(n+1))/2)
828a87f2c2690599f2b7c0dc8b8762b8552c5d54
396,026
def clean_url(url): """ Strips the ending / from a URL if it exists. Parameters ---------- url : string HTTP URL Returns ------- url : string URL that is stripped of an ending / if it existed """ if url[-1] == '/': return url[:-1] return url
e5d5015adf4e06064a0d4d5638284bf1341f1a28
672,553
import requests import json def get_results_list(hda_dict): """ Generates a list of filenames to be available for download Parameters: hda_dict: dictionary initied with the function init, that stores all required information to be able to interact with th...
b27f004e1b3a88ff94708ed65b3d450ea653c9fb
425,566
def valid_paths(view): """Return list of view paths except for Nones""" paths = [v.file_name() for v in view.window().views()] paths = [p for p in paths if p is not None] return paths
b5612da62b2cf7411a0452614397253f20b632c5
93,106
def get_pixel_dist(pixel, red, green, blue): """ Returns the color distance between pixel and mean RGB value Input: pixel (Pixel): pixel with RGB values to be compared red (int): average red value across all images green (int): average green value across all images blue (int...
1a53a06b54ceef4ebaa450e9df7ff75aa2858371
377,632
def getObjectLabel(objectData, objectName): """ Returns the object label specified in object_data.yaml :param objectName: :return: """ if objectName not in objectData: raise ValueError('there is no data for ' + objectName) return objectData[objectName]['label']
d733a1d2107b38a8d5b49b6288319959fe9dafcf
231,600
def determine_classes_based_on_gain_in_r2_score(dataset): """This function determines the class of each row in the dataset based on the value of column 'gain_in_r2_score' """ gains = dataset['gain_in_r2_score'] classes = ['good_gain' if i > 0 else 'loss' for i in gains] dataset['classes'] = classes retur...
5b1beb6a6043aae976c737d73284851d2ff56188
488,362
def make_title(passage_name, process=True, line_end=''): """Make a valid page header from a name""" passage_name = passage_name.lower() if process else passage_name return f':: {passage_name}{line_end}'
c148285fc49a32bf612f32eeb98671aaf4c1ab8a
659,601
def list_add(lists_of_lists): """Element-wise sum of list of lists Parameters ---------- lists_of_lists: list List of numbers Returns ------- list """ assert len(lists_of_lists) > 0 new_ls = [0] * len(lists_of_lists[0]) for sublist in lists_of_lists: for i, ...
67290590ba443250b637fea85491fc2e3aae9b7f
257,735
def sum_2_level_dict(two_level_dict): """Sum all entries in a two level dict Parameters ---------- two_level_dict : dict Nested dict Returns ------- tot_sum : float Number of all entries in nested dict """ '''tot_sum = 0 for i in two_level_dict: for j in...
6b5be015fb84fa20006c11e9a3e0f094a6761e74
708,615
def user_identity_lookup(user): """ Specifies which field will be used to identify the jwt subject """ return user.id
2c23079edaaaa4bbe45ce78b93ac17fabc765730
127,561
import random import string def random_user(n): """generate a random user id of size n""" chars = [] for i in range(n): chars.append(random.choice(string.ascii_lowercase)) return ''.join(chars)
21d8ec2ef8b275ffca481e4553ec396ff4010653
703,714
import re def cleanPropertyName(s): """ Generate a valid python property name by replacing all non-alphanumeric characters with underscores and adding an initial underscore if the first character is a digit """ return re.sub(r'\W|^(?=\d)','_',s).lower()
21b0b8241306b439de4d83e850cd4d6b8a9f8eec
495,261
import inspect def _has_default(parameter: inspect.Parameter) -> bool: """Check if parameter has a default value""" return parameter.default != inspect.Parameter.empty
77eb90e5f6ed5d62527a5531f974a5779a1e21ff
488,885
def _GenerateUpdateMask(args, target_fields): """Constructs updateMask for patch requests. Args: args: The parsed args namespace from CLI target_fields: A Dictionary of field mappings specific to the target. Returns: String containing update mask for patch request. """ arg_name_to_field = { ...
ddc6474b04a0bdc4095265dc5951dc3c47d18766
516,199
def is_subset(subsampling, reference): """Return whether indices specified by ``subsampling`` are subset of the reference. Args: subsampling ([int] or None): Sample indices reference ([int] or None): Reference set. Returns: bool: Whether all indices are contained in the reference s...
66e924370b0698bb0f1c2b73d058cf99d4543259
87,352
def login(client, user, password): """Return the User instance after logging the user in.""" assert client.login(username=user.username, password=password) return user
32c1d621b515086cf1811b146ca10a26ebc1d6fa
635,533
def _to_hhmmss(seconds): """ Converts seconds to hh:mm:ss,ms time format """ total_secs = float(seconds) hours = int(total_secs / 3600) mins = int((total_secs - (hours * 3600)) / 60) secs = total_secs - (hours * 3600) - (mins * 60) hours = '{:02d}'.format(hours) mins = '{:02d}'.format(mins)...
5538f5844a7be5ad0fe1e78c3288b8184f885147
432,743
def has_magnet(self): """Return if any of the Holes have magnets Parameters ---------- self : LamHole A LamHole object Returns ------- has_magnet : bool True if any of the Holes have magnets """ has_mag = [hole.has_magnet() for hole in self.hole] return any(has...
16b52b586b4057d33bb5e636fb41f86403d21852
96,182
def make_biplot_scores_output(taxa): """Create convenient output format of taxon biplot coordinates taxa is a dict containing 'lineages' and a coord matrix 'coord' output is a list of lines, each containing coords for one taxon """ output = [] ndims = len(taxa['coord'][1]) header = '...
4c461fb160544333109a126806cea48047103db1
666,409
from typing import Tuple def split_iban(iban: str) -> Tuple[str, str, str]: """Split `iban` into country_code, check_digits and bban.""" country_code, check_digits, bban = iban[:2], iban[2:4], iban[4:] return country_code, check_digits, bban
3826bbf346d0290d4b9a1577fc907d08eb44f3a7
498,625
def reliability_calc(RACC, ACC): """ Calculate Reliability. :param RACC: random accuracy :type RACC: float :param ACC: accuracy :type ACC: float :return: reliability as float """ try: result = (ACC - RACC) / (1 - RACC) return result except Exception: retu...
f33d1d81dffb21c8379b6e135c967809061dcf10
690,439
from typing import Dict from typing import Any def check_first_element_and_populate_current(attribute_details: Dict[str, Any], key: str) -> str: """ Retrieve the value of requested key from the first element of the list :param attribute_details: list of properties from which the value is the be retrieved...
af516cf4e4f5519fbaa971513eafe7a5bb48fcdb
236,874
def emote_list_to_string(emote_list): """Convert an EmoteList to a string.""" # Use string.join to glue string of emotes in emoteList separator = " " return separator.join(emote_list)
50171852ba183fe366ad20e6281c3c867f700ffb
537,797
from pathlib import Path def splitext(fname): """Splits filename and extension (.gz safe) >>> splitext('some/file.nii.gz') ('file', '.nii.gz') >>> splitext('some/other/file.nii') ('file', '.nii') >>> splitext('otherext.tar.gz') ('otherext', '.tar.gz') >>> splitext('text.txt') ('te...
ab0327b781f08ca11eefd5295c546cd94e186779
272,572
def unit(x): """ Optimizes the rendering of time. .. runpython:: :showcode: from jupytalk.benchmark.mlprediction import unit print(unit(34)) print(unit(3.4)) print(unit(0.34)) print(unit(0.034)) print(unit(0.0034)) print(unit(0.00034)) ...
19231cf1f1afdcff69211e627bd97f0de23d4efa
575,300
def percentage_birts_by_month(df, years_greater_than=1980): """Take the prepared df and calculage the average births (avg_births) and percent above average (percent_above_average) for each month. Args: df (pd.DataFrame): The prepared birth data (created using df_birth_no_geo_prep). Req...
9948505aa9c51a5259c98b47a6668149f584946f
302,242
def locToLatLong(location): """ :param location: location in string format :return: latitude and longtitude in float format """ long, lat = str(location).split(',') long = float(long.split(':')[-1]) lat = float(lat.split(':')[-1][:-1]) return lat, long
7776b4b3a4d5d7491b632a82c7b59312ffb8ea65
691,859
import functools import operator def prod(xs): """Product (as in multiplication) of an iterable. """ return functools.reduce(operator.mul, xs, 1)
87381e7da37b9164767720f2886d5ce47b8df778
105,431
def isatty(stream): """Check if a stream is a tty. Not all file-like objects implement the `isatty` method. """ fn = getattr(stream, 'isatty', None) if fn is None: return False return fn()
3498d6694a602c95efb2e2268c424e5333f38c9d
580,188
def dict2args(data): """Convert a dictionary of options to command like arguments. Note: This implementation supports arguments with multiple values. """ result = [] for k, v in data.items(): if v is not False: prefix = "-" if len(k) == 1 else "--" flag = f"{prefix}{...
1659ad70c033ca4d6401ccf50fb99294b1d0c30d
177,048
def EncodePrivate(sk): """ Encode a private key into bytes (exactly 32 bytes for both do255e and do255s). """ return bytes(sk)
4763eb9bedf0b5d802b3ed3cd9441941c4567710
639,641
def build_msg(request, msg_type, name, drink): """Personalize SMS by replacing tags with customer info""" msg = request.form.get(msg_type) msg = msg.replace('<firstName>', name) msg = msg.replace('<productType>', drink) return msg
2a22f1b48717d9a874e2397791f734fce483e703
21,410
from typing import OrderedDict def parse_manifest(manifest): """ Parses a ballot manifest. Identifiers are not necessarily unique *across* batches. Input ----- a ballot manifest in the syntax described above Returns ------- an ordered dict containing batch ID (key) and ballot ide...
e93fe98e5d5d11dc17a492d33a8fa05b04e8a800
507,944
def gc_content_percent(sequence): """ Calculates the GC-content percentage of the input sequence Returns the percentage as an integer out of 100 """ gc = sequence.count('G') + sequence.count('C') atcg = len(sequence) percent_gc = (gc * 100) / atcg return percent_gc
3e2344096df626556f1f0947d7a13dcd8e9ff600
641,250
def filter_dict(source, d): """Filter `source` dict to only contain same keys as `d` dict. :param source: dictionary to filter. :param d: dictionary whose keys determine the filtering. """ return {k: source[k] for k in d.keys()}
612096842e0b73f524ddc57ad1f9bd8e0d8f49b9
74,294
def register_with(registry): """ Register a passed in object. Intended to be used as a decorator on model building functions with a ``dict`` as a registry. Examples -------- .. code-block:: python REGISTRY = dict() @register_with(REGISTRY) def build_empty(base): ...
42fcc5b5084be32173a9a14bb7e73c7ce3068a62
264,001
def greet_by_name(name): """Returns a greeting to the given person.""" greeting = "Hello, " + name + "!" return greeting
2c2e8ebda1a2556a719728b5ce0d21ee588b9860
515,521
def transformUnits(size): """ Transform the number of size param (received in MB) into an appropriate units string (MB/GB)""" if size > 1024: return "%.02f" % (float(size) / 1024.0) + " Gb" else: return str(size) + " Mb"
f04e42f0ae2ed29bc5a329fb90661f26f2f485fc
410,574
def get_test_methods(testcase): """ Retrieve a list of test method names from a TestCase instance. """ return [s for s in dir(testcase) if s.startswith('test_')]
5f6faa48273f5268b1f3cfe5c307c970a5fbd2fa
609,693
def get_group(name, match_obj): """return a blank string if the match group is None""" try: obj = match_obj.group(name) except: return '' else: if obj is not None: return obj else: return ''
8ea0e942e6c9fbf7eadbfeb5bbac20b01d2a5750
631,556
def FlagIsRequired(flag_dict): """Returns whether a flag is required or not. Args: flag_dict: a specific flag's dictionary as found in the gcloud_tree Returns: True if the flag's required, False otherwise. If the passed dictionary does not correspond to a flag (does not contain the 'required' key), ...
c5520a55e1d8c2b6e0bd1c975b92c7099ca8b1b9
335,839
def viz_b(body): """Create HTML b for graphviz""" return '<B>{}</B>'.format(body)
3dfdf329977826b5ed791f1896538dacc18a041f
652,131
from typing import Any def str_lmd(expr: Any, indent: int = 0): """Convert str into a proper lambda function definition.""" s = str(expr) call = s.lstrip("<lambda>(").rstrip(")") return " " * indent + f"lambda {call}"
734ef45b3d4af5c61cf41a92d47bb3bdd00c8e5e
393,117
import random def successful_starts(success_prob, num_trials): """Assumes success_prob is a float representing probability of a single attempt being successful. num_trials a positive int Returns a list of the number of attempts needed before a success for each trial.""" tries_before_s...
c05cf8e95e7a311bfeeecaf84a990c308fa718ca
490,073
def aggregate_permuted_network(observed_networks): """This method handles the case where multiple observed networks are generated (e.g. from models produced by different random seed initializations of an unsupervised feature construction algorithm). We handle analysis of multiple networks by aggregating...
d56ebab767a32942a9d292277dbea591f00eee27
86,907
def is_prime(num): """ Checks if the given number is a prime number or not. """ if num > 1: for i in range(2, num): if (num % i) == 0: return False else: return True else: return False
ff96a841fa24a180de0921859925a0b5061555e5
182,800
def TimeDeltaToSeconds(delta): """Converts a datetime.timedelta to integer seconds. Args: delta: a datetime.timedelta object. Returns: the integer seconds for the timedelta. """ return delta.seconds + (delta.days * 3600 * 24)
20cf1a8d4d3ac0387012dae08213422c42b596cd
423,767
import math def _equal(source, target): """Treats slightly differing floats as equal.""" # type-dependent treatment: # the lookup server yields floats with lower accuracy then the direct storage broker, # i.e. comparison will fail at '1646312878.401044' == '1646312878.401' if isinstance(source, f...
ce15a07fdaf251f5d19b38e5007fa1036811cb61
228,084
def t_INT(t): """Return the parsed int value.""" return t
e5b664ccd22e5499d0c0ea4f4397f741011a4fe1
211,887
def vector_check(vector): """ Check input vector items type. :param vector: input vector :type vector: list :return: bool """ for i in vector: if isinstance(i, int) is False: return False if i < 0: return False return True
c59fc20bb92dca0f119b01e96eeba4a19f85c58a
473,227
def get_headers(environ): """ Returns headers from the environ """ headers = {} for name in environ: if name[0:5] == "HTTP_": headers[name[5:]] = environ[name] return headers
6b3a5a1edf7bbb633b67cb7bae1a2c9590cfb9d2
312,920
import six import importlib def import_class(cls_path): """ Imports a class from dotted path to the class """ if not isinstance(cls_path, six.string_types): return cls_path # cls is a module path to string if '.' in cls_path: # Try to import. module_bits = cls_path.spl...
1d237a81a28778cdcab6f549d692178d091cb006
120,481
import base64 def encode(file): """ A base64 encoder for Images :param file: Path of the Image which should be encoded. !IMPORTANT! file ending e.g.: eecevit.jpg :return: the encoded Image as base64 String """ with open(file, "rb") as image_file: encoded_string = base64.b64encode(imag...
5e76d861ca255f3be91d1337754477269e4ca1e2
507,975