content
stringlengths
39
9.28k
sha1
stringlengths
40
40
id
int64
8
710k
from typing import OrderedDict def read_config(config_file_path): """ Function read a SU2 configuration file Function 'read_config' return a dictionary of the data found in the SU2 configuration file. Args: config_file_path (str): SU2 configuration file path Returns: data_dict ...
312e423faf60f4947cf4b57d75c5df50304c0501
414,549
def build_endpoint_rule_name(endpoint, method): """Build policy rule name for endpoint.""" return ('%(endpoint)s:%(method)s' % {'endpoint': endpoint, 'method': method.lower()})
6b564dacdc70804544c3f1ce3f5a1fbe33c390a2
582,549
def to_bytes(str): """Convert a text string to a byte string""" return str.encode('utf-8')
78457eb656a8a2ad82c993f19765663dfdd0bdf3
138,365
def filter_sessions_by_room(sessions, room): """only keep sessions within the room <room> Args: sessions: list of tuples room: str Returns: filtered sessions as list of tuples """ return [ [session[0].split(":")[0], session[1], session[2]] for session in sessions i...
2d53460ac7e4786652885009f5b6ccc212d21c5b
305,809
def find_ngrams(input_list: list, n: int) -> list: """ Return a list of n_grams from a list Args: input_list (list): list from which n_grams are extracted n (int): n gram length Returns: list: n-gram list """ if n == 1: return input_list else: retur...
851475b6ae19daed9c2b94fcf84d58822ccd96d2
517,567
def filter_out_dict_keys(adict, deny): """Return a similar dict, but not containing the explicitly denied keys Arguments: adict (dict): Simple python dict data struct deny (list): Explicits denied keys """ return {k: v for k, v in adict.items() if k not in deny}
a377c35f4eaedf0ed3b85eeaedbd45f7af0e8ec7
19,580
def _bulk_identity_factory(key_columns): """Return a function that accepts a dict mapping and returns its identity corresponding its key values mapped by `key_columns`. """ return lambda mapping: tuple(mapping.get(col.key) for col in key_columns)
29d60f29f95eb5e7f2ef3ecf28e2657ac0974924
617,609
def get_navigation(argv): """ return with_navigation flag from arg list """ if len(argv) > 3: return bool(argv[3]) return False
734a9ee44cc0864089f14482c7f3080336be6fe3
235,885
def generate_neighbours(image): """ Generate all neighbours of all pixels in the image :param image: :return: """ neighbour_dict = dict() for x in range(image.shape[0]): for y in range(image.shape[1]): neighbour_dict[str((x,y))] = list(filter(lambda pos: 0 <= pos[0] < ima...
e484a62624f0775ac90beac344bda48303f3a486
568,347
import yaml def get_yaml_from_topology_string(topology): """Transform a topology string into a dictionary of the same format used in the infrared provision.yml file. :param topology: Topology string in the format node: amount :type topology: str :returns: yaml representation of a provision.yml f...
2a8313af9fd97c463e34c73b7aea2c87c5d05c1c
347,513
def readFPs(filepath): """Reads a list of fingerprints from a file""" try: myfile = open(filepath, "r") except: raise IOError("file does not exist:", filepath) else: fps = [] for line in myfile: if line[0] != "#": # ignore comments line = line...
96d483360c411a27a3b570875f61344ef4dae573
706,883
def PyLong_FromSsize_t(space, val): """Return a new PyLongObject object from a C Py_ssize_t, or NULL on failure. """ return space.newlong(val)
ff5eecf8335d8cd2c96c8b996cab110075aaabd8
506,406
def factors(target): """Returns the factors of target""" _factors = [] i = 1 while i <= target : if target % i == 0: _factors.append(i) i+=1 return _factors
fc0d27f011238ddba12a5c286949a326c80aa5cb
312,449
def lightness_glasser1958(Y, **kwargs): """ Returns the *Lightness* :math:`L^*` of given *luminance* :math:`Y` using *Glasser et al. (1958)* method. Parameters ---------- Y : numeric *luminance* :math:`Y`. \*\*kwargs : \*\*, optional Unused parameter provided for signature c...
f1af67296158c0b6c7589f887df51f17ac700daf
644,751
import base64 def Base64EncodeProto(msg): """ Encodes the proto as a base64 string which is safe to pass around on command line. """ encoded_string = base64.b64encode(msg.SerializeToString()) return encoded_string
a22ebaa0d1e0020e8d0fcf10c9728232083a5949
416,762
def calculate_color( vertex_id: int, current_color: int, maxima: bool, messages: list, superstep: int ) -> dict: """UDF that calculates the color of the nodes. Based on Local Maxima First algorithm :param vertex_id: The id of the node/vertex :param current_color: The current color of the vertex :par...
6e2cd053309a05f8fc6aa489248cb4ce30d418b5
215,769
def get_bse(da, da_peak_times): """ Takes an xarray DataArray containing veg_index values and calculates the vegetation value base (bse) for each timeseries per-pixel. The base is calculated as the mean value of two minimum values; the min of the slope to the left of peak of season, and the min of...
3edaf6156bd9fdae15c3bf845eb3deb293489cfb
703,210
def get_class_name(cls): """Get the class full path name.""" return "{}.{}".format(cls.__module__, cls.__name__)
6dfdf76a71928507bc4cd0e19a881b0d34bee908
129,763
from typing import Union from typing import Sequence def format_as_iter(vals: Union[int, Sequence[int]], iters_per_epoch: int, time_scale: str): """Format data to be at iteration time scale. If values are negative, they correspond to the opposite time scale. For example if `time_scale="epoch"` and `val=-...
f9971ad6227b497834e4667f101a56c49b71507e
34,216
def special_load_rules(branch): """ Detect if the branch requires special conversion rules. """ try: return "__data_type__" in branch except TypeError: return False
3c5737fca3538df947f9d85c616ee5750b4edc0f
583,485
def velocity(Q, S): """ :param Q: Volume flow for thermodynamic conditions in pipe, m3/s :param S: Сross-sectional area of a pipe, m2 :return: Velocity of the natural gas, m/s """ return Q/S
92f362601623ed264df2af2892d467285284689e
280,819
from typing import Any def is_hashable(obj: Any) -> bool: """Determine if the given object is hashable. Example: >>> from collectionish.utils import is_hashable >>> >>> is_hashable([1, 2, 3]) False >>> is_hashable('boop') True """ try: hash(obj)...
a69d1c045c033fcd4d989f0359e47867eb17833a
229,751
from typing import Dict def get_all_sites(api) -> Dict[str, str]: """Returns all the StackExchange sites as a dict, api_site_parameter -> name""" # hacky way to get everything.. res = api.fetch('sites') return {s['api_site_parameter']: s['name'] for s in res['items']}
e5de50fe9e8752e412834c59fbe791c051cb594a
174,513
def remove_duplicate_values(array_like, tol=0.0): """ Removes duplicate values from list (when tol=0.0) or remove approximately duplicate values if tol!=0.0. """ unique_values = [array_like[0]] for element in array_like: element_is_duplicate = False for uval in unique_values: ...
afdad5db2aa00858aa9bcd29e1b64b744b2fb963
21,932
def is_string(value) -> bool: """ Is the value a string """ return isinstance(value, str)
e10e2c05d277313832500220929391d9cda1e84a
313,358
from datetime import datetime def unixtime_to_isotime(unixtime, microseconds): """ Converts a unix timestamp to a readable string timestamp :param unixtime: :param microseconds: If True microseconds will be visible :return: """ return datetime.fromtimestamp(unixtime).strftime('%Y-%m-%dT%H:...
35a157fe503f1903a3a900a2ccc7b9f16ad5f478
282,887
from typing import List def pattern_index(text: str, pattern: str) -> List[int]: """Return the indeces (1-based) of a pattern within text Arguments: text {str} -- text to search for pattern pattern {str} -- pattern to search for in text Returns: int -- index location of p...
60c7204818b00f301b07d1e4a9ffcd62173b6e3f
281,178
from typing import Tuple from typing import Union from typing import Collection from typing import Any def insert_into_tuple(tup: Tuple, pos: Union[int, Collection[int]], val: Any) -> Tuple[int, ...]: """ insert_into_tuple(tup: Tuple, pos: Union[int, Collection[int]], val: Any) -> ...
d536101bc20ceb6bc240c6e1cb7d30843827e251
271,634
def replace(line_val, seq): """ Replace special characters :param line_val: line as string :param seq: sequence number :return: changed value """ # replace TAB to ',' rtn = line_val.replace('\t', ',') # remove line break rtn = rtn.replace('\r\n', '') rtn = rtn.replace('\n', '...
100e2bc08f58e1ef9dc81db88a1df569309bb2ec
317,090
def linear_skew(phenotypes, selection_gradient): """Transforms the phenotype data to match the given selection gradient and stores them as gpm.data.phenotypes. Parameters ---------- selection_gradient : float, int. (default=1) The selection gradient defines the slope of the phenotype-fitness fu...
d3bb72e9b3acbf7501f3d31b98631bf67e36e4b1
601,121
def documentedEvenOdd(num): """ Returns the string "even", "odd", or "UNKNOWN". This would be a more verbose description of what this function might do and could drone one for quite a while Args: num (int): The number to be tested as even or odd Returns: str: "even" if the number is e...
b995693ccf65079b12c7eef4be59b0c13b198a36
428,710
import logging def _checker(value_list, source, data, flag): """ Checks if values in the list are in data (Syntax warnings or errors). :param list value_list: List of values to check :param str source: Name of source that's being checked :param dict data: Data being checked :param str flag: W...
99498f0127b074e12e19348c54fa16356be0835b
330,734
def RGBtoHSV(r, g, b): """Convert RGB values to HSV Algorithm is taken from https://www.cs.rit.edu/~ncs/color/t_convert.html """ # If we were given black, return black if r == 0 and g == 0 and b == 0: return 0,0,0 # We need RGB from 0-1, not 0-255 r /= 255 g /= 255 b /= 255...
412f27fb2d72208a4cd56e6ec53053684fc7cf12
474,666
def contains(dictionary, key): """Check if key exists in dictionary.""" return key in dictionary
23262a9e96ccc283a7357464790c44779e80313e
210,615
def GetGuestPolicyRelativePath(parent, guest_policy): """Return the relative path of an osconfig guest policy.""" return '/'.join([parent, 'guestPolicies', guest_policy])
20a3ce383921230b276d70fc44021496ab7fa959
582,997
def to_time_sec(time_str): """ Tries to convert `time_str` to a valid time non negative floating point number. Args: time_str (string): String representing non negative float - time in seconds. Returns: float: Time as non negative floating point number. ...
651af52101efea040fc7cf831547572a9f0474fd
481,849
from pathlib import Path from typing import List def remove_unused_files(directory: Path, module_name: str, need_to_remove_cli: bool) -> None: """Remove unused files. Args: directory: path to the project directory module_name: project module name need_to_remove_cli: flag for removing ...
1ce15a23a06a20b7f8be6fc583699289c7a76251
607,148
def is_post(request): """Return ``True`` if the method of the request is ``POST``. """ return request.method.upper() == 'POST'
a9fc74a866157c54916a1d00c0a0fd5eb890e3a1
162,939
from typing import List def split_badge_list(badges: str, separator: str) -> List[str]: """ Splits a string of badges into a list, removing all empty badges. """ if badges is None: return [] return [badge for badge in badges.split(separator) if badge]
6dc53d45cc8390422e5a511e39475ae969bf37c9
11,516
from boto.s3.connection import S3Connection from boto.exception import NoAuthHandlerFound def S3ConnectionWithAnon(access, secret, anon=True): """ Connect to S3 with automatic handling for anonymous access Parameters ---------- access : str AWS access key secret : str AWS sec...
3e640cfae9d580fe58d7f44588e2ffe7de9eb269
609,576
def get_classes(y) -> int: """ Get the total number of classes. Args: y : The labels list of the data. Returns: int: Number of total classes """ return int(y.shape[1])
f1f518cca3e5f7e43f2f93513be17283bcb0f443
79,881
import string def apply_object_attributes_to_template(template, value_object): """Generate a string from the template by applying values from the given object. If the template provided is not a template (not have any placeholders), this will not have any effect and template will be returned unchanged. ...
266085845a4e4283d9ffa897b4b0b7d2f8669001
13,019
def didGen64(vk64u, method="dad"): """ didGen accepts a url-file safe base64 key in the form of a string and returns a DID. :param vk64u: base64 url-file safe verifier/public key from EdDSA (Ed25519) key :param method: W3C did method string. Defaults to "dad". :return: W3C DID string """ if...
260a9f997050399b0ec1e75033835031840e68cc
565,501
def space_row(left, right, filler=' ', total_width=-1): """space the data in a row with optional filling Arguments --------- left : str, to be aligned left right : str, to be aligned right filler : str, default ' '. must be of length 1 total_width : int, width of line. if ne...
64c96ca83ab4c5fceec63c5aa4743ce398f9a48d
121,158
import time def get_timestamp(timestamp_format="%Y%m%d_%H%M%S", utc_time=False): """ Get a string representing the current UTC time in format: YYYYMMDD_HHMMSS The format can be changed if needed. """ if utc_time: time_tuple = time.gmtime() else: time_tuple = time.localtime() ...
39e3122a71dafbe1b70f82e35f8036fb90d8859b
432,814
def safe_divide(x: float, y: float) -> float: """This returns zero if the denominator is zero """ if y == 0.0: return 0.0 return x / y
dd438cbba16f739157b21a7bdd0e8b34cf7d0c71
576,274
from typing import Mapping def is_mappy(x): """ Return True if `x` is "mappy", i.e. a map-like object. "Mappy" is defined as any instance of `collections.Mapping`: >>> is_mappy({'a': 'b'}) True >>> from collections import defaultdict >>> is_mappy(defaultdict(list)) True >>> is_ma...
1feccf81fe737a64ff9df6e3c74df09a4839c898
257,225
def _andparam(params): """ string join parameter list with & """ return "&".join(params)
ca7cedf4dd1169dd83f83a97f707f2e43eeaa8f7
64,408
def evaluate_final(restore, classifier, eval_sets, batch_size): """ Function to get percentage accuracy of the model, evaluated on a set of chosen datasets. restore: a function to restore a stored checkpoint classifier: the model's classfier, it should return genres, logit values, and cost for a gi...
288d2f3780c65dd068a819a1b9ade4b6075c4f9c
100,872
def cqp(c): """Complex quadratic polynomial, function used for Mandelbrot fractal""" return lambda z: z**2 + c
e1209088e3dee290b2623a44498a55df023c57b6
380,643
def configure(simulator, co_simulation, nb_neurons=10000): """ configure NEST before the simulation modify example of https://simulator.simulator.readthedocs.io/en/stable/_downloads/482ad6e1da8dc084323e0a9fe6b2c7d1/brunel_alpha_simulator.py :param simulator: nest simulator :param co_simulation: bool...
09f701fccd1ba36500bd5f4a8198f47edd1b0a00
575,590
def change_to_id(obj): """Change key named 'uuid' to 'id' Zun returns objects with a field called 'uuid' many of Horizons directives however expect objects to have a field called 'id'. """ obj['id'] = obj.pop('uuid') return obj
aad9c05e5359d6ca5788413d02454f22e2d7d3be
259,400
def create_lexicon(word_tags): """ Create a lexicon in the right format for nltk.CFG.fromString() from a list with tuples with words and their tag. """ # dictionary to filter the double tags word_dict = {} for word, tag in word_tags: if tag not in word_dict: word_dict[ta...
3a91671d559f5924ec9326520db6e11a1672fee4
707,263
def get_max_val(_dict: dict): """ Returns the largest value of the dict of format {int: List[int]}""" return max(item for val in _dict.values() for item in val)
f317b8a6533a6a65fd524fdc3ae0a61dfd554b3a
286,367
def rect2math(r): """Convert rectangles to mathematical coordinates.""" return (r.x0,r.y0,r.x1,r.y1)
9eefb2dc1c5a6e783ead82cc9ba88e361a498ab4
601,785
def get_mask_from_lengths(memory, memory_lengths): """Get mask tensor from list of length Args: memory: (batch, max_time, dim) memory_lengths: array like """ mask = memory.data.new(memory.size(0), memory.size(1)).byte().zero_() for idx, l in enumerate(memory_lengths): mask[id...
129feda0dabdc5d3b264e82b4fb417723baba31c
676,154
def get_feature_channels_per_level(base_feature_channels, max_feature_channels, num_levels, decoder_min_channels=None): """Get the number of output channels for each of the encoder and decoder blocks. Args: base_feature_channels (int): number of the output channels of the first block in the encoder par...
f4c216d419b7006510bb19493a3be4a49484f9dc
246,867
def _get_segmentation_strategy(segmentation): """Get the baci string for a geometry pair strategy.""" if segmentation: return 'segmentation' else: return 'gauss_point_projection_without_boundary_segmentation'
267a10a7237b2d42f1988ad9e35eddc7febbe789
645,748
def _parse_input(obj, arg): """ Returns obj[arg] if arg is string, otherwise returns arg. """ return obj[arg] if isinstance(arg, str) else arg
e6b0b61d8a910b5ab1e60c6c0ad3f73a374647a5
465,666
def score_survey(star_list,field_list,overlap_bonus): """ Given the stars you want and a set of fields, scores the stars, sums it up. Parameters ---------- star_list : list list of Star objects field_list : list list of Field objects overlap_bonus Returns ...
1f258ceb59048e9130dd2fa341fe6fd67dd69421
159,838
import re def parse_sequence_idx_from_pattern(patt): """Extracts the (first) numeric sequence index from the given pattern. Args: patt: a pattern like "/path/to/frames/frame-%05d.jpg" Returns: the numeric sequence string like "%05d", or None if no sequence was found """ ...
576e9ed2f4c6769008f91bb4f2b8f18f547cf690
259,249
def comma_separated_int(s): """ Used as the 'dtype' argument to TextFileParser.add_field(), to parse integer fields which appear in text files with comma separators. """ s = s.replace(',','') return int(s)
1eecd58efadf780d37915b733b0b613147dc425f
621,942
import pathlib def try_relative(path): """Try making `path` relative to current directory, otherwise make it an absolute path""" try: here = pathlib.Path.cwd() return pathlib.Path(path).relative_to(here) except ValueError: return pathlib.Path(path).resolve()
ab40fa091253f599af1bd20695ab80b6d8580ef8
544,627
import re import socket def get_hostname() -> str: """ Get the stripped down version of the host name to be used for sudmodel_dir, ckpt names, scoping. Names had '.' and '-' in them which I want for scoping/file suffix. keeps only letters, numbers, _. """ return re.sub('\W+', '', socket.gethostname())
d83acd728afcf8a23a5102fef1978a4d8f598448
433,495
def number_normalization(value, fromvalue, tovalue): """数値を範囲内の値に正規化する。 value: 正規化対象の数値。 fromvalue: 範囲の最小値。 tovalue: 範囲の最大値+1。 """ if 0 == tovalue: return value if tovalue <= value or value < fromvalue: value -= (value // tovalue) * tovalue if value < fromvalue: v...
912c515991246204ebc4d5eae8ffedb1c6d5823b
10,891
import pprint def fmt_repr(obj): """ Return pretty printed string representation of an object. """ items = {k: v for k, v in list(obj.__dict__.items())} return "<%s: {%s}>" % (obj.__class__.__name__, pprint.pformat(items, width=1))
c2b32f393263f3e85f517e816414bd7136a804a5
181,584
def string_vector(v): """Convert [3] array to string""" return '[%5.3f,%5.3f,%5.3f]' % (v[0], v[1], v[2])
8a10262fe5c7e83987b097cb4bb29b2801fcff38
197,380
from typing import Dict from typing import Any def get_update_response_item(response) -> Dict[str, Any]: """ Deserializes the response of Update operation and deserialized DynamoDB objects :param response: The response of Update operation :return: A deserialized DynamoDB object """ return resp...
56b2143b136e008faa0f617746b083dbbadcb5d1
543,443
import typing def format_commit_sha(commit: str, repo: typing.Dict[str, typing.Any]) -> str: """ Format a GitHub commit SHA into a Markdown message. """ return f"[{commit[:7]}]({repo['html_url']}/commit/{commit})"
6524863411d72f69969518c21970f6e7f57f14fb
465,503
def read_file(file): """Reads en entire file and returns file bytes.""" BUFFER_SIZE = 16384 # 16 kilo bytes b = b"" with open(file, "rb") as f: while True: # read 16K bytes from the file bytes_read = f.read(BUFFER_SIZE) if bytes_read: # if ther...
293fe86c524f3f46945b8c1a0c37a148c300f9f1
174,380
def doc_metadata(doc): """Create a metadata dict from a MetatabDoc, for Document conversion""" r = doc['Root'].as_dict() r.update(doc['Contacts'].as_dict()) r['author'] = r.get('author', r.get('creator', r.get('wrangler'))) return r
b88c7158d143c51b7da4ef8d516d084234381e9c
513,188
def rgb2gray(img): """Convert a RGB image to gray scale.""" if len(img.shape) == 2: grayimg = img[:, :] elif img.shape[-1] >= 3: grayimg = 0.299 * img[:, :, 0] + 0.587 * img[:, :, 1] + 0.114 * img[:, :, 2] else: grayimg = img[:, :, 0] return grayimg
be42500e4c8c5bc78c8e34b9e228a89c816c7510
443,693
def first_role_id_in_roles(roles): """ Return the first role ID found in list of roles.""" for role in roles: if not isinstance(role, dict): continue role_id = role.get('role') if not role_id: continue return str(role_id).strip()
a5756270ac9f6c2e0e53af13001c6aa430608e26
353,329
from typing import Union from pathlib import Path from typing import List from typing import Dict import json def readJSONLFile(file_name: Union[str, Path]) -> List[Dict]: """ Read a '.jsonl' file and create a list of dicts Args: file_name: `Union[str,Path]` The file to open Return...
8e33fad766a255578179828dc76ec793c02f90b9
1,818
from typing import Sequence def my_dot(v0: Sequence[float], v1: Sequence[float]) -> float: """ Perform mathematical dot product between two same-length vectors. IE component-wise multiply, then sum. :param v0: any number of floats :param v1: same number of floats :return: single float """ dot = 0.0 for (a, b...
6a4742cbd47395de69ee88f5fe0baf696993b644
577,835
def order_keys(keys, orders): """Get ordered keys. :param keys: keys to be sorted. :type keys: list of str :param orders: the order of the keys. '.' is all other keys not in order. :type orders: list of str. :returns: keys as list sorted by orders. :raises: TypeError if keys or orders is ...
8f865f07ebd5538f5a289ffaaed0e705bf3c0b7c
415,968
def update_qTable(q_table, state, action, reward, next_state_value, gamma_discount = 0.9, alpha = 0.5): """ Update the q_table based on observed rewards and maximum next state value Sutton's Book pseudocode: Q(S, A) <- Q(S, A) + [alpha * (reward + (gamma * maxValue(Q(S', A'))) - Q(S, A) ] Args: ...
f267851a520c95259f363d89842ed7e50e5ddf30
80,171
def conv_output_shape(dimension_size, filter_size, padding, stride): """ Computes convolution's output shape. Parameters ---------- dimension_size : int Size of the dimension. Typically it's image's weight or height. filter_size : int Size of the convolution filter. ...
8923a3bbc315d38fbbf6a770d7b59db6f14670c3
160,922
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 NOT(logical_expression): """ Returns the opposite of a logical value: `NOT(True)` returns `False`; `NOT(False)` returns `True`. Same as `not logical_expression`. >>> NOT(123) False >>> NOT(0) True """ return not logical_expression
83ae11eb225b274ded4173df0ea202ccb4248f4a
146,084
import math def determine_padding(filter_shape, output_shape="same"): """Method which calculates the padding based on the specified output shape and the shape of the filters.""" if output_shape == "valid": return (0, 0), (0, 0) elif output_shape == "same": filter_height, filter_widt...
12ef1c8d624f0dfd161c8723736610fa86c9ce1d
681,154
def align_structures(reference_traj, target_traj): """ Given a reference trajectory, this function performs a structural alignment for a second input trajectory, with respect to the reference. :param reference_traj: The trajectory to use as a reference for alignment. :type reference_traj: `...
ba23ee847deb2ac54cbc3c8d973ce02e0c7f7db2
591,548
def get_cleanup_step(project, build): """Returns the step for cleaning up after doing |build| of |project|.""" return { 'name': project.image, 'args': [ 'bash', '-c', 'rm -r ' + build.out, ], }
d3eb71a936fe482627c13b73a442eaf776061def
409,163
import json def fake_data_set_data(fake_data_set): """Fake suggest api data set data. Uses fake_data_set file fixture to generate the data. """ with open(fake_data_set) as f: return json.load(f)
729daaa2fcbc46baddcc9048125df87b93834b5c
389,929
def find_ns_subelements(element, subelement_name, ns_dict): """ retuns list of subelements with given name in any given namespace Arguments: - element (ElementTee.Element): main element to search in - subelement_name (string): searched name of element - ns_dict: dict of ...
1bbd87025ba9cac503b4ceb7523485a9b33d5637
669,739
def number_with_precision(number, precision=3): """ Formats a ``number`` with a level of ``precision``. Example:: >>> number_with_precision(111.2345) 111.235 """ formstr = '%01.' + str(precision) + 'f' return formstr % number
b6b457d8ea0b69dc80d3c336f1232207d6aa357b
373,310
import requests def my_requests_request(method, url, **kwargs): """ :param method: method for the new :class:`Request` object. :param url: URL for the new :class:`Request` object. :param params: (optional) Dictionary or bytes to be sent in the query string for the :class:`Request`. :param data: (o...
8f86acea82c6cc8677f2a53ebcd30e4d0722c49d
122,415
def flatten_lists(*lists): """Flatten several lists into one list. Examples -------- >>> flatten_lists([0, 1, 2], [3, 4, 5]) [0, 1, 2, 3, 4, 5] Parameters ---------- lists : an arbitrary number of iterable collections The type of the collections is not limited to lists, ...
23c25da8ac99c440543efdd52a7a98f2f378bd8b
117,086
def convert_to_oneline(multiline: str) -> str: """Converts a multiline Sleep command to a single line. Args: multiline (str): The multiline Sleep command. Returns: str: A single-lined version of the same Sleep command. """ # Format wrapper so it sends as one-line oneline = ...
edf833ff0920673bbab1cff2122f66b22bac08cc
95,782
def filter_on_TCRB(df): """ Only take sequences that have a resolved TCRB gene for V and J. """ return df[df['v_gene'].str.contains('^TCRB') & df['j_gene'].str.contains('^TCRB')]
1fb6c8bddff58f178085b00db52589e14bd9fae1
359,423
def get_shap_values(model_manager, direct_id, target=None): """Get the SHAP values of features. Args: model_manager: ModelManager, an object containing all prediction models direct_id: the identifier of the patient's related entry in the target entity (e.g., the admission id). ...
201ecc08c87262f7dd3aa34f7b2164b6489de405
631,890
def o_to_matsubara_idx_b(o): """ Convert index in "o" convension to bosonic Matsubara index Parameters ---------- o 2*n Returns n ------- """ assert o%2 == 0 return int(o/2)
347313ac016033360910d94e19c7d3ef8bc3f7e3
16,408
from datetime import datetime import uuid def _get_file_name() -> str: """ Create a random file name. Returns: str: Randomised file name. """ return f'{datetime.now().strftime("%d-%m-%Y_%I-%M-%S_%p")}_{str(uuid.uuid4())[:8]}.avro'
3fb18df2c9b6326037b4aa3d9576ef7f8b87209b
579,606
def Pack(flatten, nmap_list): """Packs the list of tensors according to `.NestedMap` in `nmap_list`. `Pack` is loosely the inverse of `Flatten`. Args: flatten: A list of tensors. nmap_list: A list of `.NestedMap`. Returns: A list of `.NestedMap`, say ret is the returned list. We have 1. le...
4c0caff454f269dc91715d4dbd8a9a35fafabf86
642,994
import re def _escape(line): """ Escape the syntax-breaking characters. """ line = line.replace('[', r'\[').replace(']', r'\]') line = re.sub('\'', '', line) # ' is unescapable afaik return line
8b43b7ddf42af68866eb81fdf91036d28489f897
664,561
from datetime import datetime def convert_date_to_timestamp(date_to_convert): """ This function is useful to convert date (YYYYmmdd) to timestamp Args: date_to_convert (str): date (YYYYmmdd) to be converted in timestamp Returns: (timestamp): date_to_convert converted in timestamp ...
a43add163f3c303246ac92ad043cbff452e7cc6b
572,849
def passthrough_properties(field_name, *property_names): """ This function is designed to be used as a class decorator that takes the name of an attribute that different properties of the class pass through to. For example, if we have a self.foo object, and our property 'bar' would return self.foo.bar, ...
9771ff06c5645d48283d76757d48ad7989f69f9f
494,029
import itertools def all_pairs(seq): """Produce all pairs from seq, but not (a, a)""" return itertools.combinations(seq, 2)
b26676d21660f6aa1052d832e7f6bc3b7014befa
478,664
def capwords(s, sep=None): """capwords(s [,sep]) -> string Split the argument into words using split, capitalize each word using capitalize, and join the capitalized words using join. If the optional second argument sep is absent or None, runs of whitespace characters are replaced by a single space...
5fe61ed2da2ea011e8f989c2b40a84a90cb1addc
580,957
def _is_nth_child_of_kind(stack, allowed_nums, kind): """ Checks if the stack contains a cursor which is of the given kind and the stack also has a child of this element which number is in the allowed_nums list. :param stack: The stack holding a tuple holding the parent cursors ...
b03d28f7a0dde19d8bb585186944ceb5a3a9da7a
93,021