content
stringlengths
39
9.28k
sha1
stringlengths
40
40
id
int64
8
710k
def is_wrapped(transformer): """Check if a transformer is wrapped. Args: transformer: A transformer instance Returns: bool: True if transformer is wrapped, otherwise False. """ return hasattr(transformer, "is_wrapped")
a6be022672838fc43505478db9939afa46583a03
191,524
def all_attrs_missing(record): """Checks if all attributes have missing values, excluding ID and Class""" return all(value == '?' for value in record[1:-1])
95edc3fcb42645e438b7c3267c4996f02085b0eb
623,130
import re def extract_line_from_file(filename, str_search, num=False, integer=False): """ uses regular expression to search a string in a file :param filename: the file to be searched in :param str_search: the string to search for :param num: should a number be extracted? :param integer: shoul...
5c0ea116d528397e0bccd35236f309557a5c52ae
194,446
import re def getWordCharCount(w): """ Char count for a word.""" rus = len(re.findall(r"[а-я]",w)) eng = len(re.findall(r"[a-z]",w)) c = len(w) return c, rus, eng
648a398aa3fe3bf25965b1635975ae104ba0f847
383,801
from pathlib import Path def valid_path(path): """Validate the user-supplied path is a existing directory.""" if Path(path).is_dir(): return path else: raise NotADirectoryError(f'Could not find the directory: {path}')
2fa7b62fef5cc05fabaadcef30a3e100fdcb83e9
428,674
def output_formatter(value): """ Output formatter for environment variable values. Parameters ------------ value Value to format. Returns -------- :class:`str` Formatted value. """ if value is not None and not isinstance(value, bool): return str(value) ...
e0bd03f9580ee17d9464178a43b1406e763d1d73
659,363
def get_rank(arr): """ Given a one-dim gradient tensor, return the ranks of all gradients. NOTE: This function is similar to compute_rank but has no constraints on the idxs. """ arr_idx = sorted( [(idx, grad) for idx, grad in enumerate(arr)], key=lambda t: t[1], reverse=True ) arr_r...
6c775699977a5c7f443a3458566f4d3101a13d78
547,816
def base10toN(num: int, base: int=12): """Change to given base upto base 36 is supported. Parameters ---------- num : int Integer to be transform to new base. base : int Based to use write the integer. Return ------ str String with number...
4dd41abf8ae1bc20ecc450bce6eecbbf1ba34f62
457,417
def add_single(arr, val): """ Return sum of array and scalar. """ return [i + val for i in arr]
f089514decec318d8df8954d423d90c2d5b63e0b
105,005
def convert_array_to_dictionary(x, y, int_to_topic_code): """ Convert data in array format to a dictionary keyed by topic code. :param x: the array of articles. :param y: the integer indexes of the topic classes. :param int_to_topic_code: dictionary of integer indexes to topic codes. :retur...
92a47551916925b95d78e73c5825db99fa5370db
279,878
def mid(p1, p2): """ Returns the midpoint between 2 3D points """ return (p1[0]+p2[0])/2, (p1[1]+p2[1])/2, (p1[2]+p2[2])/2
25da46ae7710c4da6cfc650d3480fbf15e82f152
281,579
def _GetCoveredBuilders(trybot_config): """Returns a dict mapping masters to lists of builders covered in config.""" covered_builders = {} for master, builders in trybot_config.iteritems(): covered_builders[master] = builders.keys() return covered_builders
e759be62c1c57045dca98e40f83beda6a7ddf7e5
8,974
def valid_chrom(arg): """Check if a string represents a valid chromosome""" arg = arg.lower() if arg[:3] == 'chr': return True if arg.isdigit() or arg in ('x', 'y', 'mt'): return True if arg[:8] == 'scaffold' or arg[:2] == 'gl' or arg[:3] == 'par': return True return Fals...
7b1483cbff37bf222a9539719a288d0e6909dbc8
612,375
def expand_date(df): """Adds columns with year, month, day, hour, day of year, week, weekday. Args: dataframe w/ datetime index Returns: copy of dataframe with columns added """ df = df.copy() df['year'] = df.index.year df['month'] = df.index.month df['day'] = df.in...
8473099e01f7dd36858137e88bcd7ad8a381efc9
522,935
import re def is_line_function_definition(line: str) -> bool: """Returns true if the corresponding line (of a python file) is the start of a function definition. Excludes functions that start with `__` which indicates a private function. Args: line: a line in a python file """ return boo...
faf550e59d7eac5686b6881df515db8ab3caedcf
693,255
def read_line(filename): """Helper method to open a file and read a line from it. Args: filename (str): Path to the file. Returns: str: Line read from the file. """ try: with open(filename) as text_file: return text_file.readline() except Exception: ...
74b99fdabced0b090114f933bd355c26a0533571
131,270
def sub_test_noiser(new_bots, old_bots, turn, should_noise, test_other): """ sub test function to check if noiser worked Parameters ---------- new_bots: bots after noising old_bots: bots before noising turn: which turn is it now? 0,1,2,3 should_noise: should the noiser do something right no...
b289499e82ef6c0e58d9d78fc06786e8108634ff
160,717
def levenshtein(s: str, t: str) -> int: """Levenshtein distance algorithm, implementation by Sten Helmquist. Copied from https://davejingtian.org/2015/05/02/python-levenshtein-distance-choose-python-package-wisely/""" # degenerate cases if s == t: return 0 if len(s) == 0: return len(...
4e1d192756808c4b9e562fb60b87fca74a4f4b68
81,055
def validate_transaction(spend_amounts, tokens_amounts): """ A transaction is considered valid here if the amounts of tokens in the source UTXOs are greater than or equal to the amounts to spend. :param spend_amounts: amounts to spend :param tokens_amounts: existing amounts to spend from :retur...
5a1de72aefe6d5d401864defc46c225afc218dba
669,347
def in_call_stack(frame, bp_loc, arg_dict, _): """Only break if the given name is in the current call stack.""" name = arg_dict.GetValueForKey('name').GetStringValue(1000) thread = frame.GetThread() found = False for frame in thread.frames: # Check the symbol. symbol = frame.GetSymbol() if symbol ...
a99fef225d186cb6bd6e56e9a3d5bf74925fc95b
281,109
def check_numbers(num_a, num_b): """ Checks to see if the two numbers are evenly divisible by each other. """ div_result = num_a % num_b if div_result == 0: return True, int(num_a / num_b) div_result = num_b % num_a if div_result == 0: return True, int(num_b / num_a) re...
b8e9215dd26c629062781ce3cbb1dc93b8afd3ae
558,997
import fnmatch def filter_channel_priority(channels, key, priorities=None): """ This function takes a dictionary containing channels keys and returns a new one filtered with the given priorities list. All channels matching the first pattern in the list will be retrieved. If one or more channels a...
2c10d4ead5ebfcbbfc19cdc030c61faa9128ea1d
352,564
def version_str_to_tuple(version): """Split version string to tuple of integers.""" return tuple(map(int, (version.split("."))))
c31e5f6055442df31d549dba3f6235ab7505dfc8
153,189
def batch_sum(x): """Sums a tensor long all non-batch dimensions""" return x.sum(tuple(range(1, x.dim())))
f62ae269a632b9b4ef95d8e9d0276e0fad16b203
632,551
def recursive_parse_xml_to_dict(xml): """Recursively parses XML contents to python dict. We assume that `object` tags are the only ones that can appear multiple times at the same level of a tree. Args: xml: xml tree obtained by parsing XML file contents using lxml.etree Returns: Pytho...
d4a3082dfd1bd03a46b2ecaf89ef725e98f59b77
237,507
from typing import List import socket def _find_n_open_ports(n: int) -> List[int]: """Find n random open ports on localhost. Returns ------- ports : list of int n random open ports on localhost. """ sockets = [] for _ in range(n): s = socket.socket(socket.AF_INET, socket.S...
91c990d1fb7c3029eb5ebb2fccacfedc8c300a21
365,485
def construct_increment_confirmation_attempts_query(graph_uri, poststuk_uri): """ Construct a SPARQL query for incrementing (+1) the counter that keeps track of how many times the service attempted to send out a conformation for a certain message without succes. :param graph_uri: string :param post...
5614e318083d493b5e5e7482beebbe9fc303832a
571,712
def get_asg_plotlabels(g, fxn, reshist, t_ind): """ Assigns labels to the ASG graph g in the given fxn from reshist at time t so that it can be plotted Parameters ---------- g : networkx graph The graph to get labels for fxn : FxnBlock Corresponding function block for the graph ...
f247e30e03e7333725c21065a4beab0c6d3e3e21
577,319
def validate_is_string_or_number(var): """ Checks if the input is either a str, int or float. :param var: input :raises: TypeError if not :returns: True """ valid_types = (str, int, float) if not isinstance(var, valid_types): raise TypeError("Input is not a string or a number:" ...
ff48389e4be7c2648a3b1e4290cc2fb25661f9ea
181,315
def edits0(word): """ Return all strings that are zero edits away (i.e. the word itself). """ return{word}
06836ba7da2a02eb7d9e9d1a2d12d74fc10f95e8
49,235
import torch def se2_element(G): """ Returns three new tensors corresponding to x, y and theta attributes of the group elements specified by the se2 group elements in matrix formulation. Args: G (`torch.FloatTensor`): matrix formulation of the group elements. Returns: (`torch.Flo...
bf54b3a83df120607a04288b2626bd643e08f6c6
210,527
import math def R(x, y): """ Return the polar coordinates (r, theta) of the point (x, y) """ r = math.hypot(x, y) theta = math.atan2(y, x) return r, theta
bfbb43b63b5dc8ca316d7705cef64553a457d672
558,528
from typing import Callable def raises(e: Exception) -> Callable: """Return a function that raises the given exception when called. Args: e: The exception to be raised. Returns: A function that can take any arguments, and raises the given exception. """ def f(*args, **kwargs): ...
d7ad75ee6cca97f90eca861c794dd385a7c809df
265,086
def snd(tup): """``snd :: (a, b) -> b`` Extract the second component of a pair. """ _x, y = tup return y
794bff44744897444ce66450920304522f600cb0
300,453
def temp_output_file(temp_folder, temp_output_filename): """Create a file path to for the output file.""" return temp_folder.join(temp_output_filename)
cbfb5bc72ec4e91dec1eb12b83139a274f518597
214,895
import torch def _interp_array(start: torch.Tensor, end: torch.Tensor, num_steps: int) -> torch.Tensor: """Linearly interpolate 2D tensors, returns 3D tensors. Args: start: 2D tensor for start point of interpolation of shape [x,y]. end: 2D tensor as end point of interpolation of ...
232ca65e13d4896c7c0e580bd48f8629b4622573
630,975
from pathlib import Path def is_doorstop_item_file(file_name, *args): """ Returns whether the given file is most likely to be a file that represents a doorstop item """ if not file_name: return False file_name = Path(file_name) if file_name.suffix != ".yml": return False ...
0df41af3186823ec2477f9b42c0eb41e3f3bc915
350,789
def S_IFMT(mode): """Return the portion of the file's mode that describes the file type. """ return mode & 0o170000
ae5fdc44ce7d7f94b04c424b5f8e885a6d0c97f1
684,632
def is_combined_texture_plan(plan): """ If true, this texture is composed of three other single-channel textures, which are copied into the R, G, and B channels of the destination image. """ return 'r' in plan and 'g' in plan and 'b' in plan
6b795628e07bb9e73fae621c41ba06a230ff18ba
144,909
def snake_to_camel(word): """ changes word snake to camel case example: my_plan -> MyPlan """ return ''.join(x.capitalize() or '_' for x in word.split('_'))
06e2704fcaaf7c65d2be4c5c104f55f1df1fb207
114,107
def max(x, y): """Maximum""" return max(x, y)
8ce365a5c5932020377107e9c9bbddf548474795
349,461
def to_gcal_datetime(date, time): """Convert date and time to google formatted datetime. Arguments: date -- datetime object time -- time string containing the time Return: gcal_datetime -- formatted date string """ gcal_datetime = '{}-{:>02}-{:>02}T{}:00+08:00'.format( ...
cdbb34548092414ee32b186bcd6198d5286fe723
450,008
def population_attributable_fraction(a, b, c, d): """Calculates the Population Attributable Fraction from count data Returns population attribuable fraction a: -count of exposed individuals with outcome b: -count of unexposed individuals with outcome c: -count of exposed in...
a5f1618e9d4a62376ea7237449db065d6ae7ca55
474,786
import textwrap def wrap(s): """ Wrap lines of text, retaining existing newlines as paragraph markers. >>> print(wrap(lorem_ipsum)) Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nos...
f77a6b98b9a5ab729245fdfd9dfa1c9c823737d4
661,827
def get_timestamps(files, idx): """Extract timestamps from a pose or relocalization file.""" lines = [] for p in files.parent.glob(files.name): with open(p) as f: lines += f.readlines() timestamps = set() for line in lines: line = line.rstrip('\n') if line[0] == '...
a856117394aaa3906a60a8bb2b6590dcb00d41e7
388,905
def _fix_coords(coords, offset): """Adjust the entity coordinates to the beginning of the sentence.""" if coords is None: return None return tuple([n - offset for n in coords])
59eb86a89d9a68f357fb02e6abb91380332d8299
587,122
import re def idsub(tag): """In aSc, "id" fields may only contain ASCII alphanumeric characters, '-' and '_'. Substitute anything else by '_'. """ return re.sub('[^-_A-Za-z0-9]', '_', tag)
3299b7a88e512e32686780e31e52b71565cf6944
668,166
def say_hello(to): """Say hello to someone (or the whole world).""" return f"Hello {to}!"
1d345824048aba9777b3ce3fadee3aed90f6dcd2
544,293
def rates_for_yr(rates_all_years, sim_year): """ Filter specific rates for a given year Parameters ---------- rates_all_years : pandas DataFrame rates, to be filtered by year sim_year : int year being simulated Returns ------- pop_w_rates : pandas DataFrame ...
616cec13b0a686c2c7504c187c31dafaa7f88b6f
701,936
def _thermr_input(endfin, pendfin, pendfout, mat, temperatures=[293.6], angles=20, iprint=False, err=0.001, emax=10, **kwargs): """Write thermr input for free-gas. Parameters ---------- endfin : `int` tape number for input ENDF-6 file pendfin : `int` ...
4ad4332bc7fc2d9b78f886e415d3aa844c2d8ea0
507,643
def is_eiffel_event_type(event, event_type): """ Checks if an event is of a given type. :param event: the Eiffel event as a dict :param event_type: the Eiffel event type :return: True if meta.type equals event_type """ return event['meta']['type'] == event_type
9fa4c66825ef194f1b54ac4771829f519c14bde5
433,356
def _get_num_args(call_stmt): """ Get the number of arguments in a call statement. """ return len(call_stmt.args) + len(call_stmt.keywords)
96f18fe2b3a924c77c30730626e4b1c146896fc9
227,354
def get_console_input(prompt): """Get console input.""" return input(prompt)
8c9d751fd64650f89c9d5df777f53245d60b9fb8
234,782
import re def validate_version(version: str): """ Validates the provided version is in the form 'M.m'. Returns: The same string provided as input if the format is valid. Raises: ValueError If the provided version does not match the expected pattern. """ version_re = re.compil...
9dd2ef9e0d19db7825260a4ae2b595c83459849a
267,501
def socketexpose(func): """Decorator to expose functions over websocket""" func.socketexposed = True return func
6facf29ea38d37f44944fcab55889b6e3ec9aa9c
165,581
def store(src, rel, dst): """ Returns an SQL statement to store an edge into the SQL backing store. :param src: The source node. :param rel: The relation. :param dst: The destination node. """ smt = 'INSERT INTO %s (src, dst) VALUES (?, ?)' return smt % rel, (src, dst)
1fcb76ff722fbf0a43c125a4ff42405b12d54ec6
9,603
def SelectColumn(lig_dict, colname): """ Prune the dictionary, only attribute in colname will be left. :param lig_dict: a tree like dictionary :param colname: what attribute you want to keep. :return: a new dictionary """ lig_new = dict() for k in lig_dict: lig_new[k] = {sk:v fo...
766c28ccf7f9e15151ddc2fd55a1fc707c150ec1
244,842
def comp(DNA: str, pat_len: int) -> list: """Sort all substrings of pat_len length :param DNA: the string to pull substrings from :type DNA: str :param pat_len: the length of substrings to pull :type pat_len: int :returns: all substrings, sorted :rtype: list (of strs) """ if not DN...
04cddfb893fe1e4b0b03d9997b53ac80b8f6e606
655,009
def get_ycbcr_bands(image): """Returns a tuple of the 3 bands (Y, Cb, Cr).""" color_transformed = image.convert(mode='YCbCr') return color_transformed.split()
b1a4a5656af3aac7787309d21dfd2e0bdecc0f7f
594,213
import hashlib import pprint def get_dict_hash(d, shorten: bool = True): """ Create string that uniquely identifies the given dict :param d: :param shorten: if `True`, will return only the first 8 characters of the hash :return: """ # pretty print (necessary to keep a consistent order for ...
62bdbb5a61e47a11d36f8a1fed12a47edb61491c
484,576
from typing import Any import struct def pack_into(fmt: str, buffer: bytearray, offset: int, *args: Any) -> int: """ Pack data with struct.pack_into and given data format. return the size of the output data with that format. Use offset += pack_into() to update the offset for next call """ stru...
f7d461b693cc59062481f7941573ff485235ab38
341,909
def is_palindrome(num: int) -> bool: """Checks if a number is a palindrome.""" return str(num) == str(num)[::-1]
bb6b271a1fbf77efb08091b625acd0ee932f292d
642,902
def bandwidth_converter( number, *, from_unit, to_unit, from_time="seconds", to_time="seconds" ): """ Bandwidth Calculator. Convert data rate from one unit to another. Arguments: number (int): number to be converted Keyword arguments: from_unit (str): convert from this da...
93068fb52bc3cd04615749e61a6ecea54b2eda0f
645,208
def close_parens_needed(expr): """Return the number of left-parentheses needed to make 'expr' balanced. >>> close_parens_needed("1+2") 0 >>> close_parens_needed("(1 + 2)") 0 >>> close_parens_needed("(1 + 2") 1 >>> close_parens_needed("(1 + (2 *") 2 >>> close_parens_needed...
ad93df4989dc35d5a60f8e00e2c1cc13893d2ca2
399,592
def context_to_airflow_vars(context): """ Given a context, this function provides a dictionary of values that can be used to externally reconstruct relations between dags, dag_runs, tasks and task_instances. :param context: The context for the task_instance of interest :type context: dict """ ...
50dcdc37c708cfb18f8a39d5fd8380782f3ef8d2
178,239
def cols(rows): """ >>> a = [ ... [1, 2], ... ['a', 'b'], ... [4, 5], ... ] >>> for c in cols(a): ... print(c) [1, 'a', 4] [2, 'b', 5] >>> a = [ ... [1, 2, 3], ... ['a', 'b', 'c'], ... ] >>> for c in cols(a): ... print(c) [1, 'a'] [2, 'b']...
3cf7ffdb7fd93f72edab1745c1c1e7b6be6f2174
275,508
def calc_candidates(sudoku, row, col): """Return a set of candidates of the sudoku at (row, col). Args: sudoku (Sudoku): The :class:`Sudoku` instance for which the candidates are calculated. row (int): The row of the field col (int): The column of the field. ...
dc91a345892dab6bb852ba8e1f7543005c64e27e
310,142
def dna_to_rna(seq): """ Convert a DNA sequence to RNA. """ # Determine if original sequence was uppercase seq_upper = seq.isupper() # Convert to lowercase seq = seq.lower() # Swap out 't' for 'u' seq = seq.replace('t', 'u') # Return upper or lower case RNA sequence if seq...
dc07509d175976c8efd4d1e0e19ca801259ca8df
524,243
def make_vect(point1, point2): """makes a vector out of 2 points Args: point1: first point point2: second point Returns: vector of 2 points (tuple) """ return ((point2[0] - point1[0]), (point2[1] - point1[1]))
ae2041d60b34c1d23a5f94bc75c8c8a412e62acb
424,591
import torch import math def double_phase_amp_phase(amplitudes, phases, three_pi=True, mean_adjust=True): """converts amplitude and phase to double phase coding amplitudes: per-pixel amplitudes of the complex field phases: per-pixel phases of the complex field three_pi: if True, outputs values in ...
888557d96922d60d04ff0e1246055a71157ec8fd
569,782
def find_one_row(substr, df, col_name): """ Return one row from `df`. The returned row has in `col_name` column a value with a sub-string as `substr. Raise KeyError if no row is found. """ for name in df[col_name]: if substr.lower() in name.lower(): return df[df[col_name] == nam...
b577bc3e6e7fed7b9f110d94a38c74d6293e17e9
110,962
def manhattan(t1b: tuple, t2b: tuple) -> int: """For parm pair of coordinate tuples, each (x, y). Return the Manhattan distance between them.""" t1x, t1y = t1b t2x, t2y = t2b return abs(t1x - t2x) + abs(t1y - t2y)
71ad347a8a05087e861176cfcb8533646060f880
650,511
from pathlib import Path def enterprise_1_9_artifact() -> Path: """ Return the path to a build artifact for DC/OS Enterprise 1.9. """ return Path('/tmp/dcos_generate_config_1_9.ee.sh')
b43fb03fe608f3cac6269eef091d6770150b0a91
128,934
import math def create_xp_table(start=1, end=100, base_xp=10, exponent=1.5): """ Creates an experience/level table Keyword Arguments: start {int} -- [description] (default: {1}) end {int} -- [description] (default: {100}) base_xp {int} -- [description] (default: {1000}) ex...
09e0a74311f2c4d35bdcbd467716c7e49d18bcb4
500,011
def get_applicable_styles(node): """ Generates a list of dictionaries that contains all the styles that *could* influence the style of an element. This is the collection of all styles from an element and all it parent elements. Returns a list, with each list item being a dictionary with keys that corr...
69c4d1d190cb20ebf043c1f97e47f653cc86af52
355,215
import re def is_url(maybe_url): """ Determine whether a path is a URL. :param str maybe_url: path to investigate as URL :return bool: whether path appears to be a URL """ # from Django 1.3.x # https://github.com/django/django/blob/6726d750979a7c29e0dd866b4ea367eef7c8a420/django/core/vali...
6f56557ace9dfaa580c5f8b6723282c80e0d1949
438,536
def IC_NIS(ic_cc, ic_ca, ic_pp, ic_pa, p_nis_a, p_nis_c): """ Calculates the predicted binding affinity value based on the IC-NIS model. """ return -0.09459*ic_cc + -0.10007*ic_ca + 0.19577*ic_pp + -0.22671*ic_pa \ + 0.18681*p_nis_a + 0.13810*p_nis_c + -15.9433
8b4d549cd2eb9162c33a8f984c295a516cb88ad3
657,641
from typing import Any from typing import Dict def check_dict_str_str(data: Any) -> Dict[str, str]: """Check if data is `Dict[str, str]` and return it.""" if not isinstance(data, dict): raise TypeError(data) for key, value in data.items(): if not isinstance(key, str): raise Typ...
ca5e400809f90db60230642670c61fc64191c797
326,603
def get_form_details(form): """ This function extracts all possible useful information about an HTML `form` """ details = {} # get the form action (target url) action = form.attrs.get("action").lower() # get the form method (POST, GET, etc.) method = form.attrs.get("method", "get").lower...
3868f9edf07ea731cb2ce8e68be603dd7a9a936c
628,759
def compound_interest(principal, rate, compounds_per_year, time): """Calculates the compound interest earned over a given period of time""" principal, rate, compounds_per_year, time = float(principal), float(rate), float(compounds_per_year), float(time) return principal * ((1 + ((rate / 100) / compounds_per...
8d7e56eb89678828da4c4b42ecce35fecced9767
389,130
import pkg_resources def load_description(package: str, path: str, filename: str): """ This function loads a static description file. Parameters: package (str): Package name where file is located in path (str): Path within the package. filename (str): Name of file to load. Re...
1a4afa40366d054f8ebf491c301c5cbc2a3a694a
96,371
def convert_timedelta(td): """ Convert a timedelta object to a timespec usable by `at`. Note that `at` does not understand seconds, so extra seconds are rounded down. """ total_seconds = (td.microseconds / 1000000) + (td.days * 24 * 60 * 60) + \ td.seconds total_minutes = total_seconds // 60 ...
2ad2fa2a589c12ee5f7d9461f47f1538e93151c7
164,944
def entitydata_values_add_field(data, property_uri, dup_index, value): """ Add field to data; if duplicate then reformat appropriately. Updates and returns supplied entity value dictionary. """ if property_uri in data: suffix = "__%d"%dup_index else: suffix = "" data[propert...
6d4eb2b05a32108ad6e75215bbc87b37636e64c2
248,777
def __get_col_name(col): """ Internal helper function to get the actual name of a pandas DataFrame column from a column name that may consists of an arbitrary sequence of tuples. The function will return the last value of the innermost tuple. """ curr_val = col while isinstance(curr_val, tup...
faf9a338463b8eae0d6331d9562ea634049aaba3
204,650
def sequenceLength(sequenceFile): """Get the total # of bp from a fasta file.""" seqLength = 0 for line in open(sequenceFile): line = line.strip() if line == '' or line[0] == '>': continue seqLength += len(line) return seqLength
3cad40e95d873c4085e848c5217a89cd44b3eed7
477,618
def comp_diff_emerge(result, loc1, loc2, time, obs='sstopo'): """Compute differential glacial isostatic adjustment between locs 1 and 2. Parameters ---------- result : GiaSimOutput loc1, loc2 : tuples of (lon, lat) time : the time for comparison obs : str The type of observation, de...
69c2dd7b0396132c86d02cb72d5d1b02c545ce75
574,681
def check_nonconvex_invest_type(dct): """ Checks if flow attribute 'invest.nonconvex' is type bool, if the attribute is present. Parameters ---------- dct : dict Dictionary with all paramerters for the oemof-solph components. Returns ------- dict : Updated Dictionary is ret...
a0c5f3f4e3e3bd97be795986a9ebf7b334ad6a60
505,411
def _get_offset(cmd): """Returns the offset into the cmd based upon if it's a dictionary page or a data page""" dict_offset = cmd.dictionary_page_offset data_offset = cmd.data_page_offset if dict_offset is None or data_offset < dict_offset: return data_offset return dict_offset
ed280e089327bfa5e1d5895b7c323a589338ea84
323,357
def TruncateInSpace(labText,maxLenLab): """ This truncates a string to a given length but tries to cut at a space position instead of splitting a word. """ if len( labText ) > maxLenLab: idx = labText.find(" ",maxLenLab) # sys.stderr.write("idx=%d\n"%idx) if idx < 0: idx = maxLenLab # BEWARE: This mus...
fe30f2031970faedaf8d04b9e25d522689d281a6
457,827
def no_duplicates(route): """ This function removes duplicate nodes that may be present in a route, ensuring it can be plotted. Parameters ---------- route : list list of nodes traversed by route, in order Returns ------- route : list list of nodes traversed by route, i...
aeb97e7370c0bf1d4a25c40264d5673fcea7f162
671,082
import click def generate_mapping(mapper, molA, molB): """Utility method to extract a single mapping from a mapper. Parameters ---------- mapper : :class:`.LigandAtomMapper` the mapper to use to generate the mapping molA, molB : :class:`.SmallMoleculeComponent` molecules to map be...
cd718e40337e4165f8fe20b9264381e08fb2c152
341,767
def sort_load_list_by_size(load_list): """Given the standard load list return a list ordered by load_set size""" return sorted(load_list, key=lambda t: len(t[2]))
2ec4b799e631dfae7e7dd80e7e13da78287ba999
212,540
def utf8(obj): """ This helper function attempts to decode a string like object to utf-8 encoding. For Python2 it just works. For Python3 a string object does not have decode mehtod whilst a byte object does. """ try: value = obj.decode('utf-8') except AttributeError: value =...
bd02bf79cb1950ee1e494b8f7622a338b4825d99
452,039
def indent(code, level): """ indent code to the given level """ return code.replace("\n", "\n" + (" "*level))
71e1584165cac2ea76ac7a28c2b3368bf6ae9ef1
618,935
import socket def can_resolve(target): """Tries to look up a hostname then bind to that IP address. Args: target: a hostname or IP address as a string Returns: True if the target is resolvable to a valid IP address """ try: socket.getaddrinfo(target, None) return...
5d3394e95a94d79bfdd40e7b0ed6370bef35deb8
228,994
import time def format_time_delta(cgxtimestamp): """ Format a CloudGenix timestamp into Human Readable string. :param cgxtimestamp: Timestamp from CloudGenix API :return: """ # cgxtimestamp may be milliseconds or nanoseconds. Drop the digits after the first 10. # this should work until 226...
61685bcbaa822722b993c1eae41ccffad7177014
295,927
def get_async_result_silent(result, timeout=None): """ Calls the ``get([timeout])`` method of an `AsyncResult <https://docs.python.org/latest/library/multiprocessing.html#multiprocessing.pool.AsyncResult>`__ object *result* and returns its value. The only difference is that potentially raised exceptions...
1f06fa75db2957583f17edcd3ebb58179da5e6b1
400,830
def _run_autocommit_on(cnx, db_parameters): """Run autocommit on test. Args: cnx: The database connection context. db_parameters: Database parameters. """ def exe(cnx, sql): return cnx.cursor().execute(sql.format(name=db_parameters["name"])) exe( cnx, """ I...
636741c934bae0c7791ed7946c87e42600c2b0d2
92,027
def fix_json_fname(fname): """Add JSON suffix to file name if it's missing""" if fname.lower().endswith('.json'): return fname else: return fname + ".json"
dcf343066a36be29333eefc406997f3bed60b938
484,276
def _odd(x: int) -> bool: """Checks if integer is odd""" return x%2 == 1
eaf6d8f6ae2ac5bda2585edf740893ec69772c87
307,664