content
stringlengths
39
14.9k
sha1
stringlengths
40
40
id
int64
0
710k
def get_X_train(data, index_name): """ Import the pandas-data and select and sliced it according the column-index-list Parameters ---------- data: ndarray Pandas data-stream index_name: str-list Columns-Names for removing columns out the data-stream Returns ---------- ...
0fe32aa2f1e2c28097ba67887774b656a92f23b3
78,808
def extract_feature_target(df, target, todf=True, exclusions=None): """ Separate feature set and target as ndarrays Parameters ---------- df: data frame target: column name in string Returns ------- X: All columns except target y: target col...
abac6e0495cde1d3ebc2d02c61e43a081afaf1bf
78,809
def normalize_hu(image): """Rescale an image such that tissue with Houndsfield units between air and bone is scaled to between 0 and 1. Tissue that is not that dense is clipped accordingly. Args: image: numpy.array Returns: numpy.array """ MIN_BOUND = -1000.0 # Air MAX_BOUND = 40...
78a582b5ab866f77303bdbb4155cb66563255e78
78,813
def select_points_in_box(xy, dim): """Only return the points within the limits of the box. Parameters ---------- xy : ndarray Locations of each point. dim : tuple or float Dimension of the box (x0, y0, dx, dy) or just a float indicating a box jutting out from the origin. ...
40a03bc7da810ec857732e5e5ac71105632b293e
78,815
def exponential_growth(level, constant=1): """ The number of samples in an exponentially growing 1D quadrature rule of a given level. Parameters ---------- level : integer The level of the quadrature rule Return ------ num_samples_1d : integer The number of samples ...
0ca35e51b3397cfce25272f7447ba2b88f96964c
78,818
def create_mpls_interface_desc(router_name, line_id, role): """ pattern for interfaces with MPLS router connected: - <MPLS_PROVIDER><ROLE><MPLS><ROUTER_NAME><LINE_ID> """ if role.lower() == "main": result = f'<MPLS_PROVIDER><MAIN><MPLS><{router_name}><{line_id}>' return result el...
4c43f530721ade7238e55136c37bccde17d503e3
78,821
def command(table): """Returns a function object to be used as a decorator for making commands. This function receives a command table as its argument. The table should be a dict. The returned function can be used as a decorator for adding commands to that command table. This function accepts mult...
e50aaac7c4546bd575786fb8639fe7e546664913
78,822
import random def TallestPareto(iters=2, n=10000, xmin=100, alpha=1.7): """Find the tallest person in Pareto World. iters: how many samples to generate n: how many in each sample xmin: parameter of the Pareto distribution alpha: parameter of the Pareto distribution """ tallest = 0 for...
01b5927e3e34f4a94344eb370c304af6ba2f2594
78,831
import random def random_disjoint_interval(start, end, avoid_start, avoid_end): """ Sample a value in [start, avoid_start] U [avoid_end, end] with uniform probability """ val = random.uniform(start, end - (avoid_end - avoid_start)) if val > avoid_start: val += (avoid_end - avoid_start) ...
895b2c9e6d757cb0d0cce69e32650d62233d044c
78,832
def numPositionsInRing(ring): """Number of positions in ring (starting at 1) of a hex lattice.""" return (ring - 1) * 6 if ring != 1 else 1
5f5dfedf7f5ae43f239afa195beeb80bea8a75a7
78,836
def is_task_terminal(task): """Return whether a given mesos task is terminal. Terminal states are documented in http://mesos.apache.org/api/latest/java/org/apache/mesos/Protos.TaskState.html :param task: the task to be inspected :returns: a boolean indicating if the task is considered to be in a t...
4e6bc8b98a9a0db71917e79f138f4b76c06d546a
78,839
def _partition(iterable, n): """Partition an iterable into tuples.""" it = iter(iterable) z = (it,) * n return zip(*z)
507472578b68f7933ddf0f654c98adc73918cfc6
78,847
def is_loopback(host): """Return True of the IP or the host is a loopback Return False if not. """ loopbacks = ['127', '::1'] for item in loopbacks: if host.startswith(item): return True return False
236ee11c738aff00e1a1531dcb1360a4d2c378a0
78,851
def string_to_boolean(string: str) -> bool: """Convert string representations of TRUE/FALSE to a boolean value. :param string: the string to convert. :return: _result :rtype: bool """ _string = str(string) return _string.lower() in ["true", "yes", "t", "y"]
4961a9541160f2ebfc02a4d3b8a42c2699600719
78,852
def apply_perm(omega,fbn): """ omega contains a list which will be permuted (scrambled) based on fbm. fbm is a list which represents a factorial base number. This function just translates the pseudo code in the Rosetta Code task. """ for m in range(len(fbn)): ...
b1d10b4777b1416ba4030564e15c3af9efabbd58
78,853
import re def _empty_readability_check(summary: str) -> bool: """Check if the readability summary is actually an empty entry or not.""" # It must be smaller than 1k chars, and contain a body tag, which should # not be there as summary should strip it. return (len(summary) > 1000 or not bool(re.match...
e07fb4c9a203e987761e5909f1bae3bbcc0807fa
78,860
def get_scorer_bodyparts(tracking): """ Given the tracking data hierarchical df from DLC, return the scorer and bodyparts names """ first_frame = tracking.iloc[0] try: bodyparts = first_frame.index.levels[1] scorer = first_frame.index.levels[0] except: raise N...
b5449d3f18ef89f1902a8c0e0fbcf19ca294f2f3
78,863
def center_coordinates(coords, size, binning=1): """ Given an XYZ tuple of particle coordinates and the reconstruction they came from, shift the coordinates so that the origin is at the center of the tomogram Args: coords: the (x, y, z) coordinates for the particle size: the reconst...
f989595d5cfaf4cf9d391e316dee20dfa155e508
78,865
def get_child_attr(obj, hier_attr_name): """Recursively traverses `par_obj`; returns the sub-child attribute. Args par_obj: hier_attr_name (str): e.g., attr_1.attr_2.attr_3 Return: hierarchical child attribute value. """ if "." not in hier_attr_name: return getattr(...
9cb0d56d6606c9e6f4fe7b3b8fc81d54120564c9
78,870
def get_all_tokens_in_dataset(X_train_tokenized, X_test_tokenized): """returns a list including all unique tokens in train and test set Arguments: X_train_tokenized {DataFrame} -- train set X_test_tokenized {DataFrame} -- test set Returns: list -- list of unique tokens ...
8216205654f5102476d88f3158b8365919fca3ab
78,872
import re def _FindAllMatches(regex, s): """Generates all matches of regex in string s.""" r = re.compile(regex) return r.finditer(s)
ea2e8be1684fbb935c7ccad9f3020d31f943ebe4
78,876
def cartes(seq0, seq1, modus='pair'): """ Return the Cartesian product of two sequences >>> from sympy.utilities.iterables import cartes >>> cartes([1,2], [3,4]) [[1, 3], [1, 4], [2, 3], [2, 4]] """ if modus == 'pair': return [[item0, item1] for item0 in seq0 for item1 in seq1] ...
4e555da9ad8b674ca4fbc4f14fd44ccde8fa5da8
78,877
import torch def gen_cycles(num_cycles, batch_size, cycle_length=2): """Generates cycles for alignment. Generates a batch of indices to cycle over. For example setting num_cycles=2, batch_size=5, cycle_length=3 might return something like this: cycles = [[0, 3, 4, 0], [1, 2, 0, 3]]. This means we have...
189c38733fba27b7cc4187491a457d89808871c6
78,879
def contains_names(texnode, names): """ Returns True if `texnode` (env or BraceGroup) contains one of the `names`. """ verdict = False for name in names: if texnode.find(name): verdict = True break return verdict
b6f9310e4de5ae6384b1cdc4e24521aa6b3006b2
78,880
import logging def get_csv_files_from_index(index_file): """ Read the csv filenames from an index file. Returns a list of pairs of filename and tablename. """ results = [] try: fh = open(index_file, 'r') except Exception as e: logging.info("Failed to open index file '%s':...
6207516b205438ec9a3ad3c1d900abe33df49272
78,882
def unpack(iterable): """ Helper function to unpack an iterable """ unpacked = [] for tt in iterable: for t in tt: unpacked.append(t) return unpacked
8233aa4f07c6d6f59a739c827e645ee4afe9db74
78,886
def create_statistics_from_ids(ids): """Create a statistics dictionary from a dict of ids/details for items added, modified and already_there""" return { "added": len(ids["added"]), "modified": len([item for item in ids["modified"] if item["data_changed"]]), "already_there": len(ids["alr...
8bf5ade7eb727bcc600d4fcd08d68e60410e19b9
78,889
def get_model_to_author_dict(model_name_tuples, lower=True): """ Get a dictionary of model names mapped to author names. Args: model_name_tuples (list or set): An iterable of ModelNames tuples of (model_name, author_name). Each name will be lower-case only. lower (bool, optional...
b489d9d0c0c518dfe9d993552eee052b066f8c8f
78,892
from typing import Optional from typing import Tuple import inspect from pathlib import Path def get_call_site(frames_back: int) -> Optional[Tuple[str, int]]: """ Returns path of the call site file, and line number :param frames_back: number of frames to look back in the call stack for the ...
a219328748365115fada865bcc466751916a913e
78,894
def decode_text(text): """Decode a given text string to an Unicode string. If `text` can't be decoded to a common encoding, it will be decoded to UTF-8 passing the "replace" options. """ for enc in ('utf-8', 'iso-8859-15', 'iso-8859-1', 'ascii'): try: return text.decode(enc) ...
e83f68ed817c59b2a8fdd0af01c75a80066402ae
78,899
import math import collections def _GetNestingMap(large_k, small_k): """Given two group sizes, computes a "nesting map" between groups. This function will produce a bipartite map between two sets of "group nodes" that will be used downstream to partition nodes in a bigger graph. The map encodes which groups ...
d98fa2d8af8aef3bc290183baaafe67932874808
78,900
def naka_rushton_no_b(c, a, c50, n): """ Naka-Rushton equation for modeling contrast-response functions. Do not fit baseline firing rate (b). Typical for pyramidal cells. Where: c = contrast a = Rmax (max firing rate) c50 = contrast response at 50% n = exponent ...
e218dc2613ad7f48bfc3407f5099ed65c6bd49c6
78,910
def remove_thousands_separator(lines): """Remove thousands separator. e.g. 1,000,00 becomes 1000000 """ return map(lambda s: s.replace(',', '').rstrip(), lines)
22d934bf4e601e6238278ee988fcab4c3ea7d330
78,912
def get_station_mic_output_pair_ui_name(pair): """Gets the UI name of one (station, microphone output) pair.""" station, mic_output = pair mic_output_name = mic_output.name if mic_output_name.endswith(' Output'): mic_output_name = mic_output_name[:-len(' Output')] return station.na...
930445541ee173e27d329d8e6a810540e2276b75
78,913
def _format(self, json_body=False, **format_args): """Get endpoint format values. It caches the format values of endpoints and returns the same object. json_body -- boolean, if set to True all the parameters will be sent as JSON, otherwise the parameters will be sent as query string. format_args --...
53dd66bbf4936e6c2639a60294fb0217595ff395
78,916
def meeting(members: str) -> str: """Sort members by last name. Args: members: <str> a list of members separated by ';' Returns: <str> sorted list of members Examples: >>> s = "Fred:Corwill;Wilfred:Corwill;Barney:Tornbull;Betty:Tornbull;Bjon:Tornbull;Raphael:Corwill;Alfred:Corwill" ...
4e250a98ac71773ea78c870b47a723b615487f73
78,919
from typing import List def helper_get_subsequences(s: str) -> List[str]: """Helper function to get subsequences from a string.""" sequence = s.split() if len(sequence) <= 2: return [] answer = [] for left in range(len(sequence) + 1): for right in range(left + 1, len(sequence) + 1)...
65e5102f25b6a6ebb9d3741d3447a9a2b2d52063
78,923
def get_unique_user_lexeme(data_dict): """Get all unique (user, lexeme) pairs.""" pairs = set() for u_id in data_dict.keys(): pairs.update([(u_id, x) for x in data_dict[u_id].keys()]) return sorted(pairs)
296157bf1724b30781b18444d56d53a722bc59d5
78,924
def whichMatched(matches, data, show_duplicates = True): """ Simple function to convert output of Matches to DataFrame of all matched observations Parameters ---------- matches : Match Match class object with matches already fit data : DataFrame Dataframe with unique rows,...
4d91643073333f3072a2fe3c85811b78b1afa88b
78,926
def build_base_url(host, port, protocol): """ Build the base URL for the given parameters and do not explicitly put the standard HTTP(s) ports into the URL. """ base_url = "%s://%s" % (protocol, host) if protocol.lower() == "http" and int(port) != 80: base_url += ":%d" % int(port) e...
5c3d916201f4706b1c8ff36a39eeee6280d60580
78,934
import random import re def sometimes_replace_1x_with_x(expr, var_name): """ Half of the time converts "1x" to "x". "31x", "461x", "4.1x", etc will always remain the same. """ if random.choice([0, 1]): expr = re.sub(r'(?<![0-9.])1{}'.format(var_name), r'{}'.format(var_name), expr) retu...
b5d3d2bd023e0803d504a5a19bc3ad4e40bdb133
78,935
def _get_attr(pyroute2_obj, attr_name): """Get an attribute in a pyroute object pyroute2 object attributes are stored under a key called 'attrs'. This key contains a tuple of tuples. E.g.: pyroute2_obj = {'attrs': (('TCA_KIND': 'htb'), ('TCA_OPTIONS': {...}))} :pa...
3d1c4419f9612c6842456ead521da542a1e77e9d
78,939
def _version_supports_flavor(python_version, flavor): """ Whether a `python_version` is compatible with a flavor """ return python_version.flavor.endswith(flavor)
99e030b3264df9fd9ae8c109ac8b874b034a0505
78,946
def normalize_line(groups): """ Takes match groups and uppercases them if they're not None. """ result = [] for g in groups: if g is None: result.append(None) else: result.append(g.upper()) return result
1e61d65dc44d9bc48d2b482335bf968cc86fb3c5
78,949
def ArcAngle(arc) -> float: """Converts the angle returned by pcbnew arc.GetAngle() to degrees. for some reason the returned value from pcbnew is the angle * 10 Args: arc (pcbnew.DRAWSEGMENT): the arc to operate on Returns: float: angle in degrees """ return arc.GetAngle() / 10...
cf72200dd54e2da19cabde9e54a1473ce942ab9f
78,950
def path_contains_data(bucket, root_path, min_file_size=0, file_extension=None): """Checks if there are any files under this path that contain files of size greater than 0 Args: bucket (boto.s3.bucket.Bucket): bucket within which to check. root_path (str): Should be the path relative to the buc...
0d917ede77a7a0959516ee1ab3519858c65c885d
78,953
def get_runs_for_order_and_machine(session, ts, order_id, machine_id): """Collect all the runs for a particular order/machine combo.""" runs = session.query(ts.Run) \ .filter(ts.Run.machine_id == machine_id) \ .filter(ts.Run.order_id == order_id) \ .all() return runs
2dd677afef4da00c8952ff3901cabfa6bc8a03ad
78,954
import torch def log1p(input_): """Wrapper of `torch.log1p`. Parameters ---------- input_ : DTensor Input tensor. """ return torch.log1p(input_._data)
f7552f4d2e672878159987b238852be540e23f62
78,956
def indent(instruction, cmd, line_suffix=' \\'): """Add Docker instruction and indent command. Parameters ---------- instruction : str Docker instruction for `cmd` (e.g., "RUN"). cmd : str The command (lines separated by newline character). line_suffix : str The suffix t...
5432ecd582142b8f3acc6cbb90c4e5b830aa6d91
78,958
import signal def name2signal(string): """Converts a signal name to canonical form. Signal names are recognized without regard for case: >>> name2signal('sighup') 'SIGHUP' >>> name2signal('SigHup') 'SIGHUP' >>> name2signal('SIGHUP') 'SIGHUP' The leading 'SIG' is not ...
f30fbc4536177857596d85a93784db9732b1d916
78,963
def _flatten_tools_info(tools_info): """ Flatten the dict containing info about what tools to install. The tool definition YAML file allows multiple revisions to be listed for the same tool. To enable simple, iterattive processing of the info in this script, flatten the `tools_info` list to include...
a70a8d0eda786a87da928b3b44561d19de9c1ec7
78,965
def to_vintagestory_axis(ax): """Convert blender space to VS space: X -> Z Y -> X Z -> Y """ if "X" in ax: return "Z" elif "Y" in ax: return "X" elif "Z" in ax: return "Y"
ce585cf95d9663f566ae65d3baa46a2e793bf301
78,967
def resolve_origin(node, symbols): """Resolve the address of the origin.""" return symbols.resolve_expression(node)
1977e516f0b09cc44654974e50cfcd50accde702
78,970
def getReportPeriod(request): """ Return: {string} 'filterReportPeriod' param value based on hierarchy: URL param value -> session (last used) -> none. """ filterVal = request.GET.get('reportperiod', None) filterByLastUsed = request.session.get('filterReportPeriod', 'last90') if not filterVal and filterByLastUsed...
b96bb4bc82e962d8f94cb2327356384b2dd63458
78,971
def scramble_mutation(random, candidate, args): """Return the mutants created by scramble mutation on the candidates. This function performs scramble mutation. It randomly chooses two locations along the candidate and scrambles the values within that slice. .. Arguments: random -- the rand...
d0aec67f2ed8a691f80e64d51e1f738a4c88fdc8
78,977
def is_supported_header(key): """Returns true if a standard supported header.""" # Supported headers for object. supported_headers = [ "cache-control", "content-encoding", "content-type", "content-disposition", "content-language", "x-amz-website-redirect-loca...
78c5a4b43de2cee6e44f7450ce0d252fdb4a299d
78,978
def score_seq(motif, seq): """ Given: motif: list of dictionaries of nucleotide --> probability seq: str of part of read sequence must be same length as motif Return: score: float of probability that it would be sampled from motif """ score= 1 for x in range(len(motif)): #no ...
dc11e2a16c0e93706162d75a6f16bf110147a549
78,980
def time_transformation(obj_dt_time, time_interval): # transform the datetime.time object to time period """ :param obj_dt_time: datetime.time object :param time_interval: in minute, e.g. 15 minutes :return: time period in minutes index from the mid-night, e.g. 5:15 is 5*60 + 15 = 315 """ to...
520d15c987593a3391bb4ac3d02bc8028390d4e9
78,981
def fi_format(p_gene1, p_gene2): """Set predefined format FUSION1--FUSION2 Args: p_gene1 (string): left gene of the fusion p_gene2 (string): right gene of the fusion """ return '{}--{}\n'.format(p_gene1, p_gene2)
a59cb581a147cf6c1265e48eed3b49419b86049a
78,984
import re def match(regex, line): """Match *entire* line to regex converting all spaces into '\s+' and allowing trailing spaces.""" regex = regex.replace(" ", r"\s+") regex += r"\s*\Z" return re.match(regex, line)
2ba01ee264ac1c20eb5923743655db487d7f76fc
78,987
def get_alphabetical_value(string: str) -> int: """Get alphabetical value of a given string `string`. Example: 'COLIN' -> 53 = 3 + 15 + 12 + 9 + 14 """ return sum([(ord(char) - ord('a') + 1) for char in string.lower()])
ec3f7dc1ef129b8edcb7c9fbbf95b5dd93c3a28d
78,990
def sort_by_list(lst, ref_lst, include_missing=True): """ Order the elements of the list by using the priorities given by some reference lst. if include_missing: a=[q, a, e, x, f, t], ref=[x, a, q, e] -> sort_a=[x, a, q, e, f, t] if not include_missing: a=[q, a, e, x, f], re...
434e737f685d8b919bbee105854c9f6c58cefc52
78,991
def format_size(size, threshold=1536): """Return file size as string from byte size. >>> format_size(1234) '1234 B' >>> format_size(12345678901) '11.50 GiB' """ if size < threshold: return "%i B" % size for unit in ('KiB', 'MiB', 'GiB', 'TiB', 'PiB'): size /= 1024.0 ...
cd214c645bfcfb815090f956b3f1e35d1df90a13
78,992
def compare_dicts(src, dst): """Checks if all keys in src matches the values in dst""" for k, v in src.items(): if k not in dst or v != dst[k]: return False return True
0a8eebf6731d65d37e4db7e147edeb281827ac52
78,993
import math def polar(x): """ Convert a complex from rectangular coordinates to polar coordinates. The function returns a tuple with the two elements r and phi. r is the distance from 0 and phi the phase angle. """ phi = math.atan2(x.imag, x.real) r = math.sqrt(x.re...
86237133d532c0c07bd5802e8c106aff680ba951
78,999
from typing import Union def _collate_assayedmolecule_metadata(molecule, key, assay: Union[None, str] = None): """ Batches metadata from AssayedMolecule. Parameters ---------- molecule : malt.Molecule assay : Union[None, str] Filter metadata using assay key. key : str Attribut...
514c6afb5f3e9d15b5d4cd8bc4485095ef3d1723
79,000
import math def corrected_ttr(n_terms, n_words): """ Corrected TTR (CTTR) computed as t/sqrt(2 * w), where t is the number of unique terms/vocab, and w is the total number of words. (Carrol 1964) """ if n_words == 0: return 0 return n_terms / math.sqrt(2 * n_words)
78dcbbd7149ddac62ded37c2a4746e6aa9f8398d
79,002
def get_napari_visual(viewer, layer): """Get the visual class for a given layer Parameters ---------- viewer The napari viewer object layer The napari layer object for which to find the visual. Returns ------- visual The napari visual class for the layer. ""...
02e543271f16b27047b0eb5b954017251c561e20
79,003
def is_digit(s: str) -> bool: """Alternative to s.isdigit() that handles negative integers Args: s (str): A string Returns: bool: Flag indicating if the input string is a signed int """ try: int(s) return True except: return False
e7e014a9a1e9de79d14dd86de06782239fb0a774
79,005
import re def dashify(string, dash='–'): """Replace dashes with unicode dash.""" try: try: return re.sub(r'-+', dash, string) except TypeError: return re.sub(r'-+', dash, string.content) except AttributeError: return re.sub(r'-+', dash, string.astext())
00d69e75ed1163a3702aa798b444da4ef6570401
79,006
def add_suffix_to_fp(file_path, suffix, path_separator='/'): """ Add a suffix to a file name (not a new file type; e.g. 'file' becomes 'file_name'). Return new filepath. """ new_file_path = '' new_file_path = file_path.split(path_separator) file_name = new_file_path[-1].split('.') f...
ffb1e2b9a7009f2627bd71c5c2b63d74c83a798e
79,007
def get_first(s): """Get the first item in a Pandas Series""" return s.iloc[0]
5291072ab8cf32ed46a55c7bd0a7adc5ccfcb8d8
79,010
def abmag_to_image(abmag): """ Convert AB magnitude into HSC image flux unit. """ return 10.0 ** ((27.0 - abmag) / 2.5)
d21e9b3668298de37072a9fe505a948ce87ed87f
79,013
def evaluate_parens(paren_string: str) -> bool: """ Evaluate an expression consisting of ( and ), and ensure that they are balanced. :param paren_string: A string representing the expression :return: True if the ( and ) parentheses are balanced, and False otherwise. >>> evaluate_parens('') True...
27855a31f279a7a7c2a82f8d86630ba979723873
79,017
def calculate_overshoot(cigar): """ The calculate overshoot function calculates the number of basepairs that have not been mapped but are part of the read. :param cigar: a list containing tuples representing the cigar string. :return overshoot: an integer indicating the number of basepairs in the read ...
687ce44bef05376339fbe7892b1c07b84981710f
79,018
def xvar(self, n="", **kwargs): """Specifies the X variable to be displayed. APDL Command: XVAR Parameters ---------- n X variable number: 0 or 1 - Display PLVAR values vs. time (or frequency). n - Display PLVAR values vs. variable n (2 to NV [NUMVAR]). 1 - Inter...
2d38b36f497b50a4ba4a65cea9fecab1152f8959
79,020
def get_pip_package_key(candidate): """Get package key for the provided string. The string may be a name and version. """ return str(candidate).split()[0].split('==')[0]
323deeee59e5b454e7291c944477471b2ca61aa0
79,023
def create_expected_repr(instance, fields): """ Create the expected string representation of an instance. Args: instance: The instance to create the expected repr of. fields: An array of field names that should be in the repr. Returns: The expected outpu...
d95c5e2d1bf9dd7cd58d9802fa04a14b3bb5c794
79,025
def decode_signed_byte(value: str) -> int: """ Convert a hex byte to a signed int. Copied from GE's hextodec method. """ val = int(value, 16) if val > 128: return val - 256 return val
d05eeb9cd32f969b3a531b0351cbbd801fd64c60
79,029
def get_child_nodes_osd_tree(node_id, osd_tree): """ This function finds the children of a node from the 'ceph osd tree' and returns them as list Args: node_id (int): the id of the node for which the children to be retrieved osd_tree (dict): dictionary containing the output of 'ceph osd tre...
3f0f146a3449974930f80195da033d56e97b56be
79,037
import re def camel_case_to_underscore(name): """ Converts a camelCase string to a name_with_underscores. """ return re.sub("[A-Z]+", lambda m: "_" + m.group(0).lower(), name, 0)
0c89ce1aa903e917b3ed6bedc85a0e8aae822ae1
79,041
from typing import Dict from typing import Any def get_contexts_for_widgets(response) -> Dict[str, Dict[str, Any]]: """ Searches through the response's context for subcontexts of widgets, and returns a dictionary with the widgets' `id` attribute as key and the widget's context dictionary as value. ...
a1055a8e3b4d97007acbdb266b2fd08d59177227
79,053
import re def remove_non_printable_characters(text): """Removes non-printable characters from the given text""" return re.sub(r'[^\x00-\x7F]+', '', text)
e5ee9aae2f61ef5772609dadd2252b6ce7029b8e
79,057
def generate_dns_record_parameters(domain_name=None, record_type=None, host='', record=None, ttl=None, validate_record_as='valid', **kwargs): """Generates parameters for a generic DNS record. :param domain_name: string, (required) the domain...
5749f52d17a74e300db9aae4ac972de749ee264e
79,058
def c_to_f(temp): """ Convert Celsius to Fahrenheit Args: temp (int, float, numpy.ndarray, list, tuple): Temperature in Celsius Returns: (int, float, numpy.ndarray, list, tuple): Temperature in Fahrenheit """ if type(temp) is list or type(temp) is tuple: return [c * 1.8 + ...
540c633430118de3f24e358adc6adbf561ff4653
79,060
def chunk_string(input_str, length): """ Splits a string in to smaller chunks. NOTE: http://stackoverflow.com/questions/18854620/ :param input_str: The input string to chunk. :type input_str: str :param length: The length of each chunk. :type length: int :return: A list of the input str...
9ae8661c5bc53437ce28b9340fd7b6bf822e9d2d
79,066
def usd(value): """Formats value as USD.""" return "${:,.2f}".format(value)
20c54a9286e3e9ead932d584f5df9885b965bfdd
79,067
def validate_geometry(screen_geometry): """Raise ValueError if 'screen_geometry' does not conform to <integer>x<integer> format""" columns, rows = [int(value) for value in screen_geometry.lower().split('x')] if columns <= 0 or rows <= 0: raise ValueError('Invalid value for screen-geometry option: "{...
c0c6a10cdc93c2461bf593ca530cadb9538537b8
79,071
import pathlib def build_filename(working_directory, # type: str tag_name, # type: str extension='.in', # type: str prefix='src', # type: str ): # type: (...) -> pathlib.Path """Constructs a path to a tagged requir...
c9799e638415531bff1f9c87eff8644357a5ddae
79,073
def quote(arg: object) -> object: """ Puts quotes around a string (so it appears as a string in output). Otherwise returns argument unchanged. :param arg: argument to transform. :return: argument quoted if a string, otherwise unchanged. """ if isinstance(arg,str): return f"'{arg}'" ...
746989bea154ca58309bed24b97765fc1ef86427
79,075
def FormatIso8601(t): """ Convert a time expressed in seconds to ISO 8601 time format string :type t: ``int`` :param t: Time expressed in seconds (required) :return: An ISO 8601 time format string :rtype: ``str`` """ return t.strftime("%Y-%m-%dT%H:%M:%S")
d24e62a419d90d398543cc082f470a8df4a1b68c
79,083
from typing import List def findMedianSortedArrays(self, nums1: List[int], nums2: List[int]) -> float: """ Finds the median of 2 sorted arrays First extends the nums1 array with nums2 array. This can be done with nums1 + nums2 Sort the newly formed array & determine the mid points, mid1 & mid2 I...
b6826b93f788c74ee8ca98947b7136295f290af0
79,086
import requests def get_str_from_url(url, encoding=None): # pragma: no cover """Read a string from the URL. Args: url: some URL encoding: override the encoding that would have determined automatically (Default value = None) Returns: the string """ req = requests.get(url) ...
ede6658f8419212e12d997f34d247be05721fd7f
79,089
import re def extract_version_tag_from_url(url): """Extract a DataONE API version tag from a MN or CN service endpoint URL. Args: url : str Service endpoint URL. E.g.: ``https://mn.example.org/path/v2/object/pid``. Returns: str : Valid version tags are currently ``v1`` or ``v2``. ...
b3ef81a3cf71bd7e2b155191431c5e3c878014c6
79,095
def sum_of_digits_compact(n: int) -> int: """ Find the sum of digits of a number >>> sum_of_digits_compact(12345) 15 >>> sum_of_digits_compact(123) 6 >>> sum_of_digits_compact(-123) 6 >>> sum_of_digits_compact(0) 0 """ return sum(int(c) for c in str(abs(n)))
14bdfc4c711c1cb6cae5c9631a3debd7628f0e4c
79,096
def make_initial_state(supporters): """ Creates a string of alternating Tottenham(T) and Arsenal(A) supporters of length 'supporters' with two blank seats represented by two underscores at the end of the string. make_initial_state(int) -> str """ return "TA"*supporters + "__"
ca44f347b922e2f4e24b8962463a3aac22fbb9f7
79,097
def circular_shift_sample_indices(indices, n_samples_shift, n_samples_total): """Shifts sample index values circularly by speficied amount :param numpy.ndarray indices: shape (N,) in dtype int :param int n_samples_shift: number of samples to shift, can be positive or negative :param int n_samples_total...
5974b7397dc048bb71fa013e95ad1be9aa4c4e66
79,099
def d2s(date): """ 日期转为字符串 >>> d2s(datetime.date(2016, 8, 16)) '2016-08-16' :param date: :return: """ return date.strftime("%Y-%m-%d")
a70eaa2eec84f87db97243f20007600295c5b4cf
79,108
def stop_screencast() -> dict: """Stops sending each frame in the `screencastFrame`. **Experimental** """ return {"method": "Page.stopScreencast", "params": {}}
743f604f9e4278633647e65f3e5693eb92882976
79,109
def is_bottom(module_index): """Returns True if module is in the bottom cap""" return ( (module_index>=600)&(module_index<696) )
88b778141776190fecaaa813e6ffcfd418abfd5f
79,117