content
stringlengths
39
14.9k
sha1
stringlengths
40
40
id
int64
0
710k
def _is_ctl(c): """Returns true iff c is in CTL as specified in HTTP RFC.""" return ord(c) <= 31 or ord(c) == 127
8c2cb3bdb46dcea2c895d6503f7bfd71aa4af389
62,103
def partition(ls, ls_size): """Partitions list into a list of lists. Useful for dividing up a population into batches in order to process each batch in a different process. :param ls: list to be partitioned. :param ls_size: length of sublist. :return: partitioned list """ parition_num ...
f556a50ac7aba5fd61a8e4b186de71c97fad46fe
62,108
def construct_frag_tuple(frag): """ Build the fragment tuple given the fragment name. Args: frag (str): the fragment name Returns: tuple: the (chain,fragname,fragno) tuple name """ ch, resnum = frag.split('-') res, num = resnum.split(':') return ch, res, int(num)
7ec5fea63bd3cef42e3d95aa7a3509274a735eba
62,111
import requests def fetch_cloudnet_model_types() -> list: """Finds different model types.""" url = f"https://cloudnet.fmi.fi/api/models" data = requests.get(url=url).json() models = [model['id'] for model in data] model_types = [model.split('-')[0] for model in models] return list(set(model_ty...
037fe48bfebb49365b1c04902ac3375a403c002d
62,114
def indent_code(code_str, indent): """Indent a snippet of code with indent number of spaces""" if code_str == "" or indent == 0: return code_str if code_str[0] != '\n': code_str = ' ' * indent + code_str idx = code_str.find('\n') while (idx != -1 and idx < len(code_str) - 1): ...
b63d9fc420b3e165be04e32f931f154b737ca739
62,115
def extract_sequence(region, sequence_file, fai): """ Get a sequence region from an indexed sequence file. :param region: A tuple of the genomic coordinates with elements: name, pos, end. :param sequence_file: Open file to extract sequences from. :param fai: Dictionary of FAI records keyed by seque...
67b17edb2a9e9ebb12fd0a0f7415d359026b5d27
62,118
from typing import List from typing import Dict def limit_intent(raw_data: List[Dict[str, str]], intent: str, max_qty: int) -> List[Dict[str, str]]: """ Limit the number of examples of the specified intent-class in the dataset to the maximum quantity defined. Parameters ----------- - **raw_data**...
f3e07337183d08b1365a07b4503c0af6b9766de0
62,123
import torch def get_embeddings(tokens_tensor, segments_tensor, model): """Obtain embeddigs for word, position, and sequence. adapted from: https://github.com/huggingface/pytorch-pretrained-BERT/blob/ 2a329c61868b20faee115a78bdcaf660ff74cf41/pytorch_pretrained_bert/ modeling.py#L264-L277) Args: toke...
479c144a805e91c5eda35a7c93c9ebcf0adb0bc1
62,124
def depth(d, level=1): """ Get the maximum depth of a dictionary. Parameters ---------- d : dict Dictionary to determine depth level : recursive variable LEAVE EQUAL TO 1 (recursive function) Returns ------- (int) The maximum depth of the dictionary (i.e., the most ...
ac1930adbaad80221acfbe077890775b6b07a825
62,128
def sample_var(sequence_of_values): """A function that computes the unbiased sample variance.""" mean = float(sum(sequence_of_values))/float(len(sequence_of_values)) SSD = sum([(float(x)-mean)**2 for x in sequence_of_values]) return SSD/(len(sequence_of_values)-1)
f781dbc9754ba84eabc6362e36b14da9ac5b0a43
62,129
def get_parser_defaults(parser): """ Given an argparse.ArgumentParser pre-configured with args/options via add_argument, return a dictionary of {dest: default}, containing the options attribute names and their default value. :param parser: A pre-configured parser instance. :type parser: argpars...
7f81181cd84e2de323e4f88cbdee44c29b31dca7
62,130
def get_recursive(d, names): """ Recursively get dictionary keys The ``names`` argument should be a list of keys from top level to bottom. Example:: >>> get_recursive({'foo': 'bar', 'baz': {'fam': 12}}, ['baz', 'fam']) 12 """ n = names.pop(0) if not names: return d[n]...
979c58a7223e04b87d237a97f74c6af8d6de9f75
62,131
def is_heading_style(style): """ True if this is a style used as a heading """ return 'Heading' in style.name[:len('Heading')]
2c37d16d9f262694f7c6facab74f4ed10da3c507
62,134
def get_age_breakdown(members): """This function will retrieve all the ages of the members, and return the number of adults, seniors, children, infants, and the total number of family members. """ infants = 0 children = 0 adults = 0 seniors = 0 for member in members: if member.age < 2: infants = inf...
102978468dbb4e0dde5f5a43ff4ce012338a0f15
62,140
def median(data): """Returns the median of data. Arguments: data (list): A list of numbers. Returns: float: Median of the provided data. """ n = len(data) if n < 1: return None if n % 2 == 1: return sorted(data)[n//2] else: return sum...
63d564f294387ee8764d775584848a6e8eb17bed
62,144
def policy_validation_settings(**kwargs): """ Set policy validation settings. This is used when policy based tasks are created and `validate_policy` is set to True. The following kwargs can be overridden in the create constructor. :param bool configuration_validation_for_alert_chain: default Fa...
225394bd4ebeb6d3f23c83fac3a33c026ba305dd
62,152
import json def read_json(file_name): """Read json file with test definition.""" structure_dic = {} with open(file_name) as json_file: structure_dic = json.load(json_file) return structure_dic
7eafa27af46fc6e313b7ceb8cab2cc95b73f8adb
62,154
def is_valid_year(year): """ Check if year's value is valid :param year: int :return: boolean """ return 2030 >= year > 1970
ac40569b4d2cd21c8ba9b20b5af11e9404b245ff
62,155
def extract_name(module_name): """ extracts the module name. :param module_name: :return: <str> the module name without the version. """ return module_name.split('_v')[0]
b2b25532f65ce4717025f2203214797e601e87b0
62,161
from typing import Mapping from typing import Any import json def load_channels_metadata(metadata_path: str) -> Mapping[str, Any]: """ _summary_ Args: metadata_path (str): _description_ Returns: Mapping[str, Any]: _description_ """ f = open(metadata_path, "r") data = jso...
bca0ef6004f72a1af581a9017df718b0d4949fe0
62,162
import collections def _sort_packages(pkgs): """Sort the MSL packages by the name of the package. Parameters ---------- pkgs : :class:`dict` The MSL packages. Returns ------- :class:`collections.OrderedDict` The packages sorted by name. """ return collections.Orde...
7196747d262b1443123f6c7cc73f4128a5b3a8ca
62,163
def sequences_to_fasta(sequences): """Formats sequence dictionary as FASTA.""" return "\n".join( f">{header}\n{sequence}" for header, sequence in sequences.items() )
bc0fed5f379bf5a964204ca0c30f31430296e7b6
62,165
import torch def reparameterize(mu: torch.Tensor, logvar: torch.Tensor) -> torch.Tensor: """ Applies reparametrization trick to obtain sample from latent space. Args: mu: the latent means of shape batch_size x latent_size. logvar: latent log variances, shape batch_size x latent_size. ...
233190d0bd02b5cbf0296d17732c11caa0a03130
62,166
def print_django(inst): """ Produce textual version of django object's fields/values - can be printed to the screen. """ fields = [f.name for f in inst._meta.fields] return "".join("{}: {}\n".format(k, getattr(inst, k)) for k in fields)
3aa930b453374675f265aafd3b729e2e1d07aad2
62,168
import pathlib def read(fname: str) -> str: """Get the content of a file at the root of the project.""" return pathlib.Path(pathlib.Path(__file__).parent, fname).read_text(encoding="utf-8").strip()
9e69843b703109ce847c1253ec768d89701fe53f
62,171
def autoscale(bp, optimal=6): """ >>> autoscale(150000000) 20000000 >>> autoscale(97352632) 10000000 """ slen = str(bp) tlen = slen[0:2] if len(slen) > 1 else slen[0] precision = len(slen) - 2 # how many zeros we need to pad? bp_len_scaled = int(tlen) # scale bp_len to range (0...
4138ff37b3ee98fbe7e7ca3c961714327f274bb5
62,172
from typing import Any from typing import List def default_uncollate(batch: Any) -> List[Any]: """This function is used to uncollate a batch into samples. The following conditions are used. >>> import torch >>> from pprint import pprint >>> batch = {"input": torch.zeros([5, 3, 224, 224]), "target": t...
f851c81069355fe219245f1c8df99e6615e8134d
62,173
def count_lines(filename): """Open file, count newlines, then return (filename, line_count) tuple.""" with open(filename, 'rb') as file_to_read: chunk_size = 8192 line_count = 0 while True: chunk = file_to_read.read(chunk_size) if chunk: line_count...
afd7eb49345434403c51399bceb0f921affa1d37
62,179
def resource_id(source_id: str, checksum: str, output_format: str) -> str: """Get the resource ID for an endpoint.""" return f"{source_id}/{checksum}/{output_format}"
0e14b52b7dd2d4da6a4027b639ed273ef1c35e20
62,180
def insert_school(mongo_collection, **kwargs): """insert a new document.""" return mongo_collection.insert_one(kwargs).inserted_id
d4aef58c6486d51e60bfc51712057e73ccdd1a37
62,182
def _sam_readline(sock): """ read a line from a sam control socket """ response = bytearray() while True: c = sock.recv(1) if c: if c == b'\n': break response += c else: break return response.decode('ascii')
ac35ce3bdd6a4e28eba0b25adae5e53b8b794aa6
62,186
def get_parent_id(an_id: str) -> str: """ given an id - get the parent id. for most items - it will be the id before the last / for .json or .xml - it will be the id up to the .json/.xml """ parent_id = an_id.rsplit("/", 1)[0] if an_id.find(".xml") > 0: parent_id = an_id[: an_id.find...
340e113b082a3baacf682ba32ce1301f73928a83
62,194
from typing import Tuple def _square_to_grid(square: str) -> Tuple[int, int]: """ Converts the string name of the square into the grid location """ row_val = square[0] col_val = square[1] col = ["8", "7", "6", "5", "4", "3", "2", "1"].index(col_val) row = ["a", "b", "c", "d", "e", "f", "g"...
641c195ed483cf2a217210f111379618800b168f
62,196
from datetime import datetime import pytz def get_run_time(creation_time): """ Get the time difference between resource creation time and current time in hours """ current_time = datetime.utcnow().replace(tzinfo=pytz.UTC) diff = current_time - creation_time days, seconds = diff.days, diff.seco...
2b868f81f1ce21a1cc448def1a636bc9db21c0a8
62,197
from pathlib import Path import tempfile import shutil import six def create_temp_dir_with_constant_name(name): # type: (six.text_type) -> Path """ Create temporary directory but with constant name. :param name: tmp directory name. :return: path object to new tmp directory. """ tmp_dir_pat...
f0d5e514d25b3438de5b4f6a750b35aa44fb1b74
62,201
def _reverse_search_options(search_options): """ Reverse the search_options to map a UID to its numeric version >>> search_options = {1: {'uid': 'Computer.name'}} >>> _reverse_search_options(search_options) {'Computer.name': 1, 'name': 1, 1: 1} """ rev = {} for k, v in search_options.it...
603f33338f25fdc0e88c7e4b4cfd0f5204a4cc8a
62,205
def format_line_stats(kmer_stats): """Create a parsable string for the calculated kmer stats.""" fields = ("total_kmers", "unclassified_kmers", "ambiguous_kmers", "kmer_support") formatted_str = "\t".join(str(kmer_stats[x]) for x in fields[:3]) formatted_str +=...
e60a6b6e7dee0851ddf7f85a5999bb5d9111f7d3
62,207
def _ensure_forecast_measurement_compatibility(forecast, measurement): """Checks that a forecast is compatible with the measurement (observation or aggregate) it is compared to. Criteria: * matching variable * interval length of measurement is less than or equal to that of the forecast. *...
94654077c0c6f229bdba62d2ca2735a03417376a
62,208
def should_deploy(branch_name, day_of_week, hour_of_day): """ Returns true if the code can be deployed. :param branch_name: the name of the remote git branch :param day_of_week: the day of the week as an integer :param hour_of_day: the current hour :return: true if the deployment should continue...
8d8ba7657e9393d588c7019839acc859c56e63f9
62,210
def get_total_cost(meal_cost: float, tip_cost: float) -> float: """Calculate the total meal cost from the tip cost and meal cost.""" return meal_cost + tip_cost
93a8285e54f4b9233105789c2a5d5ceedef25bb8
62,216
def search_person(lista, nombre): """ Buscar persona en lista de personas. Buscamos un nombre en una lista de instancias de la clase Person. En caso de que se encuentre regresamos su indica, en otro caso regresamos -1 Hay que tener cuidado con este valor porque -1 es un valo...
1f95d41b06c49402550855e01d10b25b3b40fa8a
62,219
def _list_to_matcher(matcher_list): """Converts a matcher as a list to a dict matcher.""" return {"default": matcher_list}
df5fecf3e979699d537b9e5fe2176c79c79264fb
62,221
def common_ancestors(ind1, ind2): """ Common ancestors of ind1 and ind2. Recursively searches ancestors for both individuals, and then performs a set intersection on on each set of ancestors :param ind1: the first individual :param ind2: the second individual :type ind1: Individual ...
e0f7e8c8521e656053067a129dcaa0dfd14b7c29
62,224
from typing import Optional import re def _GetQueryId(filename: str) -> Optional[str]: """Extract query id from file name.""" match = re.match(r'(.*/)?q?([0-9]+[ab]?)\.sql$', filename) if match: return match.group(2)
c0768cec58eb5dd6a8ede18ce4ae0d5976b8db9e
62,227
def similarity_to_pattern(similarity: int) -> str: """ Inverse of pattern_to_similarity for 5 digit in base 3. :param similarity: str :return: pattern """ pattern = '' for i in range(5): pattern += str(similarity % (3 ** (i + 1)) // 3 ** i) return pattern
8fe9e6d4b6e20bcc3acfd52c674b475054084008
62,235
def _server_list_custom_func( client, resource_group_name=None): """ List servers by resource group name or subscription """ if resource_group_name: return client.list_by_resource_group(resource_group_name) return client.list()
8795a4475d2fb61259036e77c3d483d89a7a9d34
62,236
import re def parse_shader_error( error ): """Parses a single GLSL error and extracts the line number and error description. Line number and description are returned as a tuple. GLSL errors are not defined by the standard, as such, each driver provider prints their own error format. Nvidia ...
7b299394d93acc5235ea5e4116c874f03fab6615
62,241
from typing import Final from typing import get_origin def is_final_type(tp: type) -> bool: """ Test if the given type is a final type. """ return tp is Final or get_origin(tp) is Final
410d1067ed377e1268cf812b16bd758cf64c6e52
62,245
import json def pretty_response(response): """Return a pretty-formatted response.""" return json.dumps(response, indent=2, sort_keys=True)
9f748567b3ac38746c2357a103dbb245a24c2a3e
62,246
def ConstantRank(j, state, decision, collision): """Constant rank no matter what.""" return [state.memories[j]]
b8d5c4819229c59097ee760efcbbe0226cec492f
62,247
def _get_variable_read_op(variable, graph): """ Returns the /read operation for a variable """ return graph.get_operation_by_name(variable.name.split(':')[0] + '/read')
d454415edb11f8a3f9bdc5790331db5b2bf94a95
62,251
def convert_exponent_alpha(exponent): """Convert a powerlaw exponent to the expected DFA alpha value. Parameters ---------- exponent : float Aperiodic exponent value, representing a 1/f distribution. Returns ------- alpha : float Predicted DFA alpha value for the given expo...
2ebcf472f28dbb319c3cbbcb014cec7e2eeaba38
62,252
def truncate_series_top_n(series, n=24): """ take a series which can be interpreted as a dict, index=key, this function sorts by the values and takes the top-n values, and returns a new series """ return series.sort_values(ascending=False).head(n)
8b8d651fe58ec7d1024d9e09e6952837f451bf3f
62,253
def array_to_grader(array, epsilon=1e-4): """Utility function to help preparing Coursera grading conditions descriptions. Args: array: iterable of numbers, the correct answers epslion: the generated expression will accept the answers with this absolute difference with provided values ...
cf608271e821da48a62c67a932ce0413aac19466
62,259
def extract_gn_build_commands(build_ninja_file): """Extracts from a build.ninja the commands to run GN. The commands to run GN are the gn rule and build.ninja build step at the top of the build.ninja file. We want to keep these when deleting GN builds since we want to preserve the command-line flags to GN. ...
64b57222721df2809ce6ef9746cc703b24a99662
62,260
def findLowTempIndex(lowTempMassFrac, X, Z): """ Find the index for the LA08 data which has the same mass fractions X and Z. """ idx = 0 for i in range(lowTempMassFrac.shape[0]): if lowTempMassFrac[i, 1] == X and lowTempMassFrac[i, 3] == Z: idx = i break if idx ...
38334c6f9f1f13b47f0ee558442d4e68683dd59d
62,262
def unique_experiment_identifier(chosen_hyperparam_indices): """ Returns a unique identifier to save the eval metrics. chosen_hyperparam_indices is a list of the indices of the hyperparameters in their respective lists that we are using in this configuration. """ # Store output ID. output_id = "" # Output is ...
4f3b8477b85bd3d5b3a3d595d02ed92677c93287
62,268
def rigids_from_tensor4x4(m): """Construct Rigids object from an 4x4 array. Here the 4x4 is representing the transformation in homogeneous coordinates. Args: m: Array representing transformations in homogeneous coordinates. Returns: Rigids object corresponding to transformations m """ ...
b94db458eb8cb4fd9b3f1b57901c3b3fdadaf971
62,269
def render_template(env, filename, values=None): """ Render a jinja template """ if not values: values = {} tmpl = env.get_template(filename) return tmpl.render(values)
b072cc2cea557eff1546ff7a6a4e8a55fc358ab0
62,272
def toys(w): """Hackerrank Problem: https://www.hackerrank.com/challenges/priyanka-and-toys/problem Priyanka works for an international toy company that ships by container. Her task is to the determine the lowest cost way to combine her orders for shipping. She has a list of item weights. The shipping comp...
6fde143e4760eefd3dc38b3ea1bdf38a9abe4129
62,273
def powop(a, b): """Method to raise a to power b using ** operator.""" return a ** b
c997b5ca4b9c9a398e0ca2a5cfee9dd825e07a16
62,274
def _get_fields(events): """ Returns a list of all fields in the given event set. @param events: The events as a list of dictionaries. @type events: list(dict(str: str)) @return: All the fields. @rtype: set(str) """ fields = set() for event in events: fields.update(list(even...
1028e30ea761f4d8397a042863a243e71172539c
62,279
def cohens_d(mu_1, mu_2, std): """ Compute the standardized effect size as difference between the two means divided by the standard deviation. Parameters ---------- mu_1 : float Mean of the first sample. mu_2 : float Mean of the second sample. std : float > 0 Pooled...
1321194f1a5c1d4b93f9735423549ce57232cfdf
62,281
def str_remove(df, column_name: str, pattern: str = ''): """Remove string patten from a column Wrapper around df.str.replace() Parameters ----------- df: pd.Dataframe Input dataframe to be modified column_name: str Name of the column to be operated on pattern: str, default ...
f27d956bacaeaa35568f79105acbdec89e236e0e
62,286
import json def JsonObj(data): """Returns json object from data.""" return json.loads(str(data))
5efca3a024b6c312d769caf7dfa642aeff929ec1
62,290
def is_simplified(G): """ Determine if a graph has already had its topology simplified. If any of its edges have a geometry attribute, we know that it has previously been simplified. Parameters ---------- G : graph Returns ------- bool """ edges_with_geometry = [d for u, v,...
29bcb5acb3147d341d0aac47bf6ee720e25b221e
62,291
def is_valid_ecl(ecl: str) -> bool: """ (Eye Color) - exactly one of: amb blu brn gry grn hzl oth. :return: Status of field (true = valid). :rtype: bool """ colours = ["amb", "blu", "brn", "gry", "grn", "hzl", "oth"] if ecl not in colours: return False return True
ad390b223b21003673fb1de8cda8b27cc047c7b0
62,292
def SizeScale(size): """ Rescale the size (currently only convert to float). :param size: a string :return: a float """ return float(size)
42127b3624388381cfc9293516fb30fd7cfbcd55
62,295
from typing import List from typing import Tuple from typing import Any import configparser def config_items(path: str) -> List[Tuple[Tuple[str, str], Any]]: """Return config file option, value pairs.""" config = configparser.ConfigParser() config.read(path) res = [] for section in config.section...
0c7b8cc1b5bafe0aea4552b3f6a488dbe84bde2e
62,296
def inconsistent_typical_range_stations(stations): """A function which returns a list of stations that have inconsistent data (for typical range) from a given list of stations.""" inconsistency_list = [] for check in stations: inconsistency_check = check.typical_range_consistent() if inconsi...
ee11815836e04d791376367827f2678ebc958a7b
62,297
import requests def post_service3(url, rhythm_key_pair): """Using our existing user data from s1, we use this function to poll s3 with a post request for a new note length. Keyword Arguments: url: The url of service 3. rhythm_key_pair: A key pair rhythm list dictionary. """ serv...
d95207fd4306d678a0048a2f5f78d19f91c1e42c
62,300
def is_apple(filename): """ check if the file is either a .app or a .ipa osX file """ with open(filename, "rb") as f: # magic bytes in .app files if f.read(4) == b"\xcf\xfa\xed\xfe": return True f.seek(0) data = f.read(200) # .app and the word "Payload...
2b5383245bd9c47d04b4a681094c9c2ea5fa5aa9
62,304
import math def calc_hist_length_per_net(batch_count, epoch_count, plot_step): """ Calculate length of history arrays based on batch_count, epoch_count and plot_step. """ return math.floor((batch_count * epoch_count) / plot_step)
916b65439fa9ee3f10d90abc290ea8d4f1465465
62,312
def template_preferences(pulses_plugin, template_sequence): """Preferences corresponding to the template sequence. """ infos = pulses_plugin.get_item_infos(template_sequence) return infos.metadata['template-config']
4e5cdd017e7444c7782f788563139c204850b64c
62,315
def check_value(value: bytearray, size_value: int) -> bool: """ Check the correctness of the variable. This function checks the type ('bytes' or 'bytearray') and whether the size of the 'value' variable matches the 'size_value' value. Args: value: The variable that you want to check. ...
4a80852f366cf96e7742cf68fcbf58ef51d86b40
62,323
from typing import Any def listify(value: Any): """ Encapsulate value in a list if it isn't already. """ if isinstance(value, list): return value return [value]
8cdd5b0ca8fe31f2cc5da23b9a18cb316e6c06b9
62,331
import hashlib import struct def return_hash_of_GZ(fname, kwArgCheck = None, ignoreModificationTime = True): """ This function returns the SHA512 hash of the passed GZ file as if the first "Modification Time" field is set to zero. Using this function it is possible to discover that the only binary dif...
61a5f5a16acf74319e1c770cf8d78c92aa8418b3
62,334
import json def template_response(data, templating_dict): """ Change data from the Grafana dashboard API response based on the dashboard templates :param data: Data from the Grafana dashboard API :param templating_dict: dictionary of {template_name, template _value} :return: panel_info with al...
772e02283a9679fe5ea6b6a9f41ac5156c98a66a
62,340
def _get_docstring_type_name(var_doc: str) -> str: """ Get the string of argument or return value type's description from docstring. Parameters ---------- var_doc : str Docstring's part of argument or return value. Returns ------- type_name : str Argument or return ...
fe07d6bb9869b4fcac404a3da6cdb0480880076b
62,345
def dblp_key_extract(entry): """Return dblp key if the bibtex key is already a DBLP one, otherwise return none.""" if entry["ID"].startswith("DBLP:"): return entry["ID"][5:] else: return None
0f2c9c03c9957306d35eb0156db632a4612c7b68
62,348
def STARTSWITH(x, y): """checks if 'x' startswith 'y'""" return x.startswith(y)
e810c4b5ebcfcc6b7849416b372ce4296de73d6c
62,349
import itertools def cartesian_params(*paramList): """Make a test function or method parameterized by cartesian product of parameters .. code-block :: python import unittest from nose2.tools import cartesian_params @cartesian_params((1, 2, 3), ('a', 'b')) def test_nums(num, ch...
61e9b4ef4bc93b90a4a4bb59e0a96146e1d644ba
62,350
import re def strip(string, decimal='.'): """ Strip non-decimal characters out of string. """ return re.sub(r'[^\d{}]+'.format(decimal), '', string)
40d62b2656f48046299c8d4c476e1ae55e41251f
62,351
import inspect def classname(val): """ Returns a qualified class name as string. The qualified class name consists of the module and the class name, separated by a dot. If an instance is passed to this function, the name of its class is returned. Parameters ---------- val : instance or c...
d7c94c256207d413a2ff7935df9dfebb513f955e
62,354
def mk_fit_dict(coeff, order, func, xmin=None, xmax=None, **kwargs): """Generate a dict that is formatted for using func_val. Parameters ---------- coeff : array Coefficients of the fit order : :class:`int` The order of the function to be used in the fitting. func : :class:`str`...
ef4d7a19c3b25c1353e18ff8f42d50e588cd2794
62,355
from typing import Sequence def false_positive_rate(y_true: Sequence, y_pred: Sequence) -> float: """Calculates the false positive rate binary classification results. Assumes that the negative class is -1. """ assert set(y_true).issubset({1, -1}) assert set(y_pred).issubset({1, -1}) false_pos...
8668d01c2628062efef67b04c912ef315d37fa13
62,357
def rename_candidate_hugo(candidate, renamings): """Renames a candidate name according to a renaming map.""" name_expr = candidate.split(".") base_name = name_expr[0] if base_name in renamings: base_name = renamings[base_name] name_expr[0] = base_name result = ".".join(name_expr) return result
eff58e01b4197ccf2a20d58a88f9c443d277a376
62,362
def award_types(row): """ "Award Type" for FPDS transactions if award <> IDV (`pulled_from` <> 'IDV'): use `contract_award_type` elif `idv_type` == B &`type_of_idc` is present: use "IDV_B_" + `type_of_idc` elif `idv_type` == B & ("case" for type_of_idc_description for spe...
1fb6a6b6408c5e2a31d72ed03767dc1158311aaf
62,363
def labelIndex2Name(label_index): """Convert label index into name of piece""" return ' KQRBNPkqrbnp'[label_index]
ebe9903b9e342d864f180f0c4d1c720bef7274a7
62,368
def midpointint(f, a, b, n): """ Computes the Midpoint integration rule of f from a to b using a python for loop. """ running_sum = 0 for i in range(n): running_sum += f(a + ((b-a)/float(n))*(i + .5) ) return running_sum * (b-a)/float(n)
c99ce4440b8173fcc9e52002c653cb04dd4c7d88
62,371
def auto_repeat( obj, n, force=False, check=False): """ Automatically repeat the specified object n times. If the object is not iterable, a tuple with the specified size is returned. If the object is iterable, the object is left untouched. Args: obj: The obj...
e7d369a2f3bc4f3c745943451ba96304a9e00460
62,373
from datetime import datetime def str2iso(input_string: str) -> datetime: """ Convert a specific type of ISO string that are compliant with file pathing requirement to ISO datetime. :return: """ iso_datetime = datetime.strptime(input_string, "%Y-%m-%d %H:%M:%S") return iso_datetime
bd57ff70d8f8f377ad396a60b326f1dd2166aac8
62,380
def get_top_n_indexes(val_list: list, n: int = 3) -> list: """ returns the indexes of the highest values in the list Params: ------- val_list : list of values from wich highest N are to returned as index position Returns: ------- top_indexes : list of indexes cont...
f98b1198580247560230a653fe93eb46891c0cfa
62,382
import hashlib def get_sha1_truncated_id(s: str) -> str: """ Return a truncated hash of any given string. Used on bbox and bbox sections to keep track of duplicate runs / work without having to store the entire lon,lat,lon,lat string every time. """ return hashlib.sha1(s.encode("UTF-8")).hexdigest...
67e0fe08862a6bbafb45f0d0a35e7ffc78380fba
62,386
def bisection_method(f, left, right, value, tol=1e-6, max_iters=1e12): """ Simple bisection solver, which works well for finding roots of monotonic functions """ mid = (left+right)/2 i = 1 # utilising the knowledge that the function is monotonically decreasing while (abs(f(mid) - value) > to...
96c9b224c4b0ed843f8833b615ca31e0d90422f7
62,389
def create_question_list(question_list): """ Function that creates a string for the questions_list given.""" string = "+".join([str(id) for id in question_list]) return string
024694ee7d3b86dd9f2dd495d03031134619dcc6
62,390
import pytz def datetime_as_utcdatetime(dt): """ Return a timezone-aware datetime as a UTCdatetime as specified in https://www.openarchives.org/OAI/openarchivesprotocol.html#Dates, §3.3. Note that the OAI-PMH specifcation mandates that the "Z" (zulu) specifier be used for the timezone as opposed ...
822f7b8f391dccd64a8e2d9386734fb693cb930f
62,391
def strip_comments(line): """Removes all text after a # the passed in string >>> strip_comments("Test string") 'Test string' >>> strip_comments("Test #comment") 'Test ' >>> strip_comments("#hashtag") '' >>> strip_comments("Test#comment") 'Test' """ if "#" in line: ...
c21948eae449eb6037d7abc40cce467d00edf426
62,393
def get_relationship(from_id, to_id, rel_name, properties): """reformats a NetworkX edge for `generate_data()`. :param from_id: the ID of a NetworkX source node :param to_id: the ID of a NetworkX target node :param rel_name: string that describes the relationship between the two nodes :para...
17516c972a1b6cf2893c7b4c7ea96d6ab9969f01
62,394
def _get_element_or_alt(data, element, alt): """ if :element: is in dict :data: return it, otherwise return :alt: """ if element in data: return data[element] else: return alt
a1a40105d6804c6bbd28af34b4216704c2bc498c
62,396