content
stringlengths
39
9.28k
sha1
stringlengths
40
40
id
int64
8
710k
def _get_default_annual_spacing(nyears): """ Returns a default spacing between consecutive ticks for annual data. """ if nyears < 11: (min_spacing, maj_spacing) = (1, 1) elif nyears < 20: (min_spacing, maj_spacing) = (1, 2) elif nyears < 50: (min_spacing, maj_spacing) = (...
ddc98001e9324f2486f141b86f285ac48b726dd2
48,558
import torch def get_attention(model, tokenizer, text, include_queries_and_keys=False): """Compute representation of the attention to pass to the d3 visualization Args: model: pytorch_transformers model tokenizer: pytorch_transformers tokenizer text: Input text include_queries_and_ke...
082d7f7b6f7036d1691dba120c07cf7d97443c1b
242,404
def macd(df, short_long_signals=[(12, 26, 9)]): """ Moving Average Convergence Divergence Parameters ---------- df : pandas.DataFrame, must include columns ['Close'] Dataframe where the macd is extracted from short_long_signals : list, default [(12, 26, 9)] List of periods of (short_...
890e6014c7603d3ae274411928500fd48f78085b
498,863
def replication(samples): """ Deterministically replicate samples. :param samples: A list in which each element again is a list containing the sample and the number of times the sample needs to be replicated, e.g.: samples = [(x1, 2), (x2, 0), ..., (xM, 1)] :return: list of replicated samples...
38f4bcddcfaa1e5bdba2112a9481ceaa9da51d48
410,161
from datetime import datetime def from_timestamp(timestamp: str) -> datetime: """Parses the raw timestamp given by the API into a :class:`datetime.datetime` object.""" return datetime.strptime(timestamp, "%Y%m%dT%H%M%S.000Z")
81d3c0a5297fa0053ae9a951147fac6f46907956
693,067
def read_text_from_file(path_to_text_file): """Reads the text file and returns whole content as a string. Args: path_to_text_file (str) Returns: A string that concatenates all the lines in a single line and uses '\n' as the line separator. That means if the text file includes any ...
923befb88b04eb7f36ba52bca1d010fb39d094f4
208,862
from time import mktime def toMillis(date): """Converts a Date object to its millisecond value elapsed since January 1, 1970, 00:00:00 UTC (GMT). Args: date (Date): The date object to convert. Returns: int: 8-byte integer representing the number of millisecond elapsed sin...
12d61ccc39ca38bf1155ef79185e5ba46a0e3698
469,858
def find_dict(l, key, value): """Find dict d from list l where key matches value. Return index""" for i, d in enumerate(l): if d[key] == value: return i
1f7b379c01f544cd72781959cda671ff72af252a
79,546
from datetime import datetime def date_from_timestamp(ts): """ Returns a tuple containing (date, time) strings for a given Unix timestamp. """ day = datetime.utcfromtimestamp(ts).strftime('%Y-%m-%d') tod = datetime.utcfromtimestamp(ts).strftime('%H:%M:%S') return (day, tod)
ceddfe2e1ff5d8efbf559a270f7a6aa4fb963f17
312,677
def snake_to_camel(snake_str: str, delimiter: str = '_') -> str: """ Converts snake_case to camelCase. Useful for projects where different languages like NodeJS are used and you have to transform your interchange format from snake_case into camelCase. Args: snake_str (str): The snake_case strin...
ff144a99486246cbad7e358fd715a1e743dfdaa1
401,809
import random def shuffle(coll): """ Return a random permutation of ``coll``. Not lazy. """ coll = coll[:] random.shuffle(coll) return coll
ca714cca1b45a2e71501bf796b21ad5d19a848aa
313,713
def test_dir_type(arg): """Parse a directory argument for the test command.""" if ',' in arg: arg = arg.split(',') return (arg[0], [int(i) for i in arg[1:]]) else: return (arg, [None])
e30b18800f655c2c73b0642a5e62e5a52b5125c5
224,430
def moveZeroes(nums): """ Move all zeros to the end of the given array (nums) with keeping the order of other elements. Do not return anything, modify nums in-place instead. """ # counter = 0 # for i in range(len(nums) - 1): # if nums[counter] == 0: # nums.pop(counter) #...
a0830af05d8d51ba4289279c038d7f3e09ffcda8
272,377
import re def satisfy_label_requirements(k, v): """Takes in a key and value and returns (String, String) that satisfies the label text requirements. Label text requirements include max length of 63 chars, only allowing (a-z, 0-9, -, _), key must start with a letter, and value must be a string. https://cloud....
be033ae63942508c07dcfc9045f26e3bbbb4024e
445,575
def JaccardIndex(axial_auto, axial_validation): """ Calculates the Jaccard Index / Tanimoto Index between 2 numpy ndarrays. DSC = (A and B) / (A or B) Input ndarrays must be boolean. From Jaccard's paper: Jaccard, Paul (February 1912). "THE DISTRIBUTION OF THE FLORA IN THE ALPINE ZONE.1". New Phytolog...
1037bbb09f3ae1103bc54017cf407fb2477a7d52
166,439
def _acct(v): """Convert to accounting (float) for excel, but default to original value.""" try: if v is None or v == '': return '' return float(v) except ValueError: return v
5d7985a3b5392a30a496a0a480d1109681024197
521,296
def StringFill(_string, _len, fill_front = False, fill_spaces = False): """Function to fill the string _string up to length _len with dots. If len(_string) > _len, the string is cropped. **kwargs: fill_front = True to fill in front of the input string. (Preset fill_front = False) Examples: Strin...
e09549e7f91b406151de813764e30cc3bb5301e6
284,538
from typing import OrderedDict def readUniqueHashMap(fileName, keyIndex = 1): """Read file list file and return key/value hash map. Can be used to sample name/sample file definition, or parameter options definition. Arguments: fileName {str} -- the file containing at least two columns, one is key and anoth...
de88e252525da7d04249c1eace0d759e67d20d13
319,802
import math def relatively_prime(a:int, b:int) -> bool: """ Two numbers are relatively prime if their greatest common denominator (GCD) is 1. Parameters: a (int): first number b (int): second number Returns: (bool): True if the two numbers' GCD is 1, otherwise False. """...
ec53289fc0299e7f543a896288985a5c4031b3fa
381,672
def get_string_from_bytes(byte_data, encoding="ascii"): """Decodes a string from DAT file byte data. Note that in byte form these strings are 0 terminated and this 0 is removed Args: byte_data (bytes) : the binary data to convert to a string encoding (string) : optional, the encoding type to...
c07523139e2509fcc19b2ce1d9a933fcb648abfd
2,931
def get_index_after_weight_limit(items_by_weight, weight_limit): """Given a list of (item_index, [any other fields,] item) tuples sorted by item weight, find the positional index that first exceeds the passed weight limit""" # find the item that first exceeds the weight limit; binary search code is based on b...
1efda1a7bd63d2af1ca4415a13becbc9b8189320
442,135
def on_raised(callback, *args): """Invoke callback if exception within args occurs. Reraise exception.""" def decorator(main_function): def wrapper(*wargs, **kwargs): try: return main_function(*wargs, **kwargs) except Exception as e: if len(args) =...
c58e08be9e2da68e1332e9c20c5323fc6753ebf7
444,080
def _test_success(block_id, block_dict, extra_args): """ Automatically returns success """ return True
6866b2645debbf2c5200cf85f341975143f01e08
346,089
def gate_error_to_irb_decay(irb_error: float, rb_decay: float, dim: int): """ For convenience, inversion of Eq. 4 of [IRB]_. See :func:`irb_decay_to_error`. :param irb_error: error of the interleaved gate. :param rb_decay: Observed decay parameter in standard rb experiment. :param dim: Dimensi...
4298d9d132d12929711aa2388118179649ad2fe4
324,462
def get_user(txn, email): """Gets user node.""" query = """ MATCH (a:User) WHERE a.email = "{email}" RETURN a """.format(email=email) result = txn.run(query) return result.value()
e623c22d7ddc5fddf29031e906a10e341d0e41a2
411,818
import collections def _group_by_id(objs): """Return a dictionary whose keys are MBIDs and whose values are lists of objects (Albums or Items) with that ID. """ counts = collections.defaultdict(list) for obj in objs: mbid = getattr(obj, 'mb_trackid', obj.mb_albumid) counts[mbid].ap...
714ae5ac1cbac1b7d60fddea70f43b93d32f4700
138,233
def alert2subject(alert_obj): """ Transforms an alert into a subject for mails :param alert_obj: :return: """ return '[WEBMONITOR] WEBSITE : ' + alert_obj['website'] + ' IS ' + alert_obj['status']
d582eb5c0c02ea643ba7e5ee7d323f997bff8a30
579,866
def assert_raises(c, exc): """Test whether callable c raises an exception of type exc.""" try: c() except exc: return True else: raise AssertionError("%r failed to raise exception %r" % (c, exc))
e3ed1a7734a223801e520b863e6006d6a1bdff29
266,794
import warnings def lmc(wave, tau_v=1, **kwargs): """ Pei 1992 LMC extinction curve. :param wave: The wavelengths at which optical depth estimates are desired. :param tau_v: (default: 1) The optical depth at 5500\AA, used to normalize the attenuation curve. :returns tau: ...
04c89605e8ad4188c62b631e173a9c8fe714958a
707,441
def get_available_group(car): """ Detect and, if is possible, assign a group to a car :param car: Available car that wants a group :type car: journey.Car :returns: Group assigned if is possible, None if isn't :type returns: journey.Group """ group = car.get_available_group() if gro...
8a5661db72d6c9cd505fd0962aedb632fe210a9d
360,277
from pathlib import Path def is_scene(directory: Path) -> bool: """Checks if a directory is a scene that contains instructions. To be a scene, a directory must: * Contain files. * Its name must start with `scene`. Args directory (Path): The path towards the directory to ...
32cd107183aa02cc43c506ee1e25af656ebf7628
502,501
def normalize_date(date): """Bring the date argument to a uniform format, which is YYYY-MM-DD.""" # Remove the time portion. time_pos = date.find('T') if time_pos >= 0: date = date[:time_pos] # Insert dashes. if len(date) == 8: date = date[:4] + '-' + date[4:6] + '-' + date[6:] ...
68589207d4c2c24d8f3af4afcfd6bf2c4c01fe67
361,885
def get_dbtype_from_file_exten(infp): """Determine data type from fasta filename extension. """ dbtype = None exten = infp.rsplit('.', 1)[1] if exten == 'faa': dbtype = 'prot' elif exten == 'fna': dbtype = 'nucl' assert dbtype is not None, """Could not determine data type for...
c2a9a15f7fb531bc83ac61641a7097f4a6878167
417,294
def sortedDictValues(inputDict, reverse=False): """ Returns the given dictionary as a list of keys sorted deterministically by value then key:: {"spam": 0, "eggs": 1, "ham": 1} => ["spam", "eggs", "ham"] :param dict inputDict: :param bool reverse: Reversed sorting :rtype: list """ ...
50581e6e66094795ed1a8842e2492fe8c06f19a2
86,432
from typing import List def span_labels_to_tag_labels( labels: List[str], label_encoding: str = "BIO" ) -> List[str]: """Converts a list of span labels to tag labels following `spacy.gold.biluo_tags_from_offsets` Parameters ---------- labels Span labels to convert label_encoding ...
3e706d10f7c3667c527150c1178b63938362e47f
343,320
def get_clip_index_by_media_id(clip_info, clip_list): """ For a given clip info dict, will return the index at which it is found in the list by comparing media_id If nothing is found, return None """ media_id_list = [item["media_id"] for item in clip_list] try: output = media_id_list...
7ca2466a65fcb54c7414d64726430ab0fe86789d
271,849
def issubstring(s1, s2, *args, **kwargs): """Is s1 a substring of s2""" return s2.count(s1) > 0
9a3aad1e3f46677457d78e9169c241577102200e
651,451
def getvaluelist(doclist, fieldname): """ Returns a list of values of a particualr fieldname from all Document object in a doclist """ l = [] for d in doclist: l.append(d.fields[fieldname]) return l
b85d171b537636477b00021ce717788b5e4735da
7,780
def find_neighbor(used_letters): """ This function help find the current position's neighbors that have not been used previously. :param used_letters: list, list of the indexes of used letters :return: list, list of indexes that are current position's neighbors and not have been used """ neighbo...
5058665c1e1c659192587c26e4348f7bfe2f2326
603,576
def tolist(value=None, sep=',', empty_strings=False): """Convert a string to a list. The input string is split on the separator character. The default separator is ','. An alternative separator may be passed as the 'sep' keyword. If no string value is provided a function is returned that splits a strin...
93a1d3e45736fc57a4a85f9e481bfd32c32843f7
607,859
def chunk(seq, count): """Splits given sequence to n chunks as evenly as possible. Args: seq: Sequence to split count: Number of chunks Returns: List of chunks """ avg = len(seq) / float(count) res = [] i = 0.0 while i < len(seq): res.append(seq[int(i):...
35bcd80917a3a82db40d116cc3846c1ab7493194
102,035
import torch def numpy_img_to_torch(batch): """Preprocess images Process numpy images: 1. Normalize by dividing by 255.0 2. Set datatype to be float32 3. Make sure the input dimensions are (batch size, channels, height, width) 4. Convert to torch.Tensor type Returns ------- ...
f68d0d84d12f92a717f3f192724257399acd4a8b
231,158
def const(result): """Return a function that ignores any arguments and just returns the specified result""" def constResult(*args, **kwargs): return result return constResult
ea6f0cec9f7a5d86a4d2a22b1cb02cb2176b9335
483,793
def int2hex(number): """Returns a string representation of the number as hex. """ return "%04X" % number
fe43dfa07cf955a671e0be6ca82abee42e236482
617,700
def find_shared_neurons(listA, listB): """ :param listA: list of unique neurons in A(dtype:list of int) :param listA: list of unique neurons in B(dtype:list of int) :return: shared neurons between list A and B(dtype:list of int) """ shared_neurons = set.intersection(set(listA), set(listB)) r...
25bea1aa3d51286b2b4fbaf10070cb8ee8fe7220
338,609
def flatten(tensor): """ Flatten input tensor as the shape of (nb, nf) :param tensor: input Tensor :type tensor: torch.Tensor :return: flattened tensor :rtype: torch.Tensor """ assert len(tensor.shape) >= 2 if len(tensor.shape) > 2: flattened = tensor.view(tensor.shape[0],...
d9103fd3554b8186a0c0a9840b914315d5646334
94,137
def request_value(request, key, default=None): """ Returns first found value, using this order: POST, GET, default. :param request: :param key: :param default: :return: """ value = request.POST.get(key, None) or request.GET.get(key, None) if value is not None: return value ...
28cc13be18632bee1c1ad43558470bdbaa5100ad
75,787
def makeFullName(parScope, parName): """ Create the fully-qualified name (inclues scope if used) """ # Skip scope (and leading dot) if no scope, even in cases where scope # IS used for other pars in the same task. if parScope: return parScope+'.'+parName else: return parName
0dda72bb1ed8a6f82eaa34362834d2329bae9630
629,471
import math def progressbar(cur, tot, length): """Generate a progress bar""" per = math.floor(cur * float(length) / tot) return "[{}{}]".format("#" * per, " " * (length - per))
0b8c7ebe27640d1b5f75c32756e31e6f3ba2b178
254,417
def TestToExtract(data,missing,overwrite): """ Test if need to extract the data :param float/int data: data to test :param float/int missing: missing value :param boolean overwrite: to overwrite or not :returns: boolean if condition met """ if data==missing or overwrite: retur...
96366843466c1b285faa64bccc7a45e6bce6175c
219,073
def unique_prefixes(context): """Return a dictionary with unique prefixes for modules in `context`. Keys are 'module' statements and values are prefixes, disambiguated where necessary. """ res = {} for m in context.modules.values(): if m.keyword == "submodule": continue prf = ne...
b16d472726f61d7ff3dace6761b0bf8b356356bc
317,331
def link(method): """ decorator to flag an admin method as rendering a link on client list view. :param object method: method to be flagged. :returns: method. :rtype: type """ setattr(method, 'is_link', True) return method
78da478aaa7cade53d6f7a70c214eabd00715e2f
601,297
def strplural(n, name, nonumber=False, s=''): """ Returns the plural or singular of a string Parameters ---------- n : integer The plural or singular is based on this number. name : string String for which a plural is requested. nonumber : boolean If true, don't prep...
9fb50adf94cf2ca951c4704acd18c6084bb8107f
437,125
def is_file_in_manifest(file_name, width, manifest): """Whether the given file, in its given width, is in manifest.""" return (manifest.get(file_name, '-1') == width)
11ef361d61ca1e5a6b0ac5a6b569f55751a12186
517,340
import cProfile def mpi_profile_decorator(comm, filename=None): """ Profiles execution of MPI processes and writes stats to separate files """ def prof_decorator(f): def wrap_f(*args, **kwargs): pr = cProfile.Profile() pr.enable() result = f(*args, **kw...
c6f9627aa3d8f19bb19f6de34de6c00670c347f2
551,246
def get_local_hostname() -> str: """ A function to get the information from /etc/hostname :return: string. Hostname """ hostname_path = "/etc/hostname" with open(hostname_path) as f: try: s = f.readlines() return s[0].strip() except IOError: ra...
205c748679f47e1dc331d1e1200ea7ecdc55cbc6
206,298
def average_barcodes(df, sequence_label="label", out_prefix=None): """Average RNA/DNA barcode counts for each sequence within replicates. Parameters ---------- df : pd.DataFrame Index is the barcode, one column must have the key sequence_label, the rest are assumed to be RNA/DNA counts ...
965ce9344aa749f1829534855396814e90316823
243,675
import json def _clean_output_json(output_json: str) -> str: """Make JSON output deterministic and nicer to read.""" try: output = json.loads(output_json) except json.JSONDecodeError: raise ValueError( f"Instead of JSON, output was:\n--- output start ---\n{output_json}\n--- out...
0952ed8f8cc34ca2c18aa3d09ca0c81607066332
702,040
from typing import Sequence def order_inversions( ttset: Sequence ) -> int: """ Given a transformed version of a series with order numbers, returns the number of order inversions that ocurred because of the transformation. """ orders = [x[0] for x in ttset] inv_count = 0 for i in range(l...
6d061adb0035594e0076b0d370407f8e6f6ef4e3
410,382
def print_palindromes_from_list(palindrome_list): """ Given a list with palindrome positions, lengths and sequences, print the positions and lengths separated by a whitespace, one pair per line. """ for palindrome in palindrome_list: print("%s %s" % ( palindrome[0], palindrome[1]...
475629e6ec967b2011a760993bb20b2d9b7c6967
356,634
def lr_decay(N, step, learning_rate): """ learning rate decay Args: learning_rate: base learning rate step: current iteration number N: total number of iterations over which learning rate is decayed """ min_lr = 0.00001 res = learning_rate * ((N - step) / N) ** 2 retu...
307ac7a886a463320504a6983d1941e59d76b41a
597,901
def format_title(host: str) -> str: """Format the title for config entries.""" return "Controller ({})".format(host)
99ca5c97007a8f0373184d8d9c5c55bb5d7d64b9
25,916
def add_date_end(record: dict): """ Function to make ``date_end`` ``date_start`` if ``measure_stage`` is "Lift" Parameters ---------- record : dict Input record. Returns ------- type Record with date_end changed conditionally, or original record. """ if record...
67f6ae063aabdf7a7d456ed0ce9660a75b37b6c2
11,385
def predict_model(model, X_score): """Uses a trained scikit-learn model to predict over the scoring data""" return model.predict(X_score)
9083ae727e7b1572c4f19c2adee3a80437d0b406
179,775
def post_process_sentencepiece_tokenizer_output(s): """ replaces whitespace encoded as '_' with ' ' for sentencepiece tokenizers. """ s = s.replace('▁', ' ') return s
fd14a796bdf45102584e7911e625e78ba4e5e05c
529,776
def br_to_us_number_format(numb_str: str) -> str: """ Removes dot as thousand separator and replaces comma decimal separator with dot >>> br_to_us_number_format('10.000,00') '10000.00' """ return numb_str.replace(".", "").replace(",", ".")
0c7e44918e865093f9c8d86e309a846cb5640116
197,947
def filter_year(vv, year): """Filters by year""" vvy = vv[vv['year'] >= year] return vvy
48ebca317ae29c3b3b1299794f23ea9c3ec7b914
188,402
from typing import List def get_prompt(letter_set: List[str], correct_words: List[str], incorrect_words: List[str], score: int, current_round: int, total_rounds: int) -> str: """Generate the prompt text for a single game round.""" prompt =...
916b23e87eef8d16f89b0d46b20da604c568029a
425,442
def get_ver_component(ver_list, idx): """Get version component from components list. Return 0 for components out of range as default. """ if idx < len(ver_list): return ver_list[idx] return 0
4425440a82b67e95553617a830f1ec7aa3bbc04e
438,910
def version_check(version): """Checks if OpenFlow version is compatible and returns the version if it is Parameters ---------- version: hex The OpenFlow version taken from the SDN switch 'hello' message Returns ------- The OpenFlow version if match, else 0 for unknown version ...
a0edb7f70dca6f9be64b020c13a9a02f1d65572c
640,875
def torch2numpy(img): """ Converts a torch image to numpy format """ if img.dim() == 4: img = img.permute(0, 2, 3, 1).contiguous() elif img.dim() == 3: img = img.permute(1, 2, 0).contiguous() return img.cpu().numpy()
25fee887319d6014bc480498550c6b95fb0f6ea8
684,281
def does_algorithm_implementation_have_capabilities_to_execute_parameter(parameter_kisao_id, algorithm_specs): """ Determine if an implementation of an algorithm has the capabilities to execute a model langugae Args: parameter_kisao_id (:obj:`str`): KiSAO id for an algorithm parameter algorithm...
653712ae621bd014547e04009243cefe4c9eb8e1
706,441
def format_range(low, high, width): """Format a range from low to high inclusively, with a certain width.""" if low == high: return "%0*d" % (width, low) else: return "%0*d-%0*d" % (width, low, width, high)
59fc9f38967541924e1d74799d655b07884d22fe
642,926
import base64 import pickle def ObjectToBase64EncodedString(Object): """Encode Python object into base64 encoded string. The object is pickled before encoding. Arguments: object: Python object. Returns: str : Base64 encode object string or None. """ return None if Objec...
08936ec2ea3d4bcf324a81623b4a0082f9f8fa0a
162,238
def splitTag(chunkTag, oTag = "O", raw = False): """ Split chunk tag into IOB tag and chunk type; return (iob_tag, chunk_type) """ if chunkTag == "O" or chunkTag == oTag: tag, type_ = "O", None elif raw: tag, type_ = "B", chunkTag else: try: # split on fir...
c44d923c1799cd9af921abb2207956630c25e8c0
340,441
def _get_dimension(region): """ Return dimensionality of `region` (0, 1, 2, or 3). """ if len(region) == 7: zone_name, imin, imax, jmin, jmax, kmin, kmax = region elif len(region) == 5: zone_name, imin, imax, jmin, jmax = region kmin, kmax = 0, 0 else: zone_name, imin, im...
1ee0853d131262d9c08d76205b853c7e10704231
474,442
import collections def group_fields_by_root(field_locations): """Given a list of field_locations group together those that hang from the same parent. Parameters ---------- field_locations: List[FieldLocation] Returns ------- dict Dictionary mapping PageTree node numbers to a ...
345b4c5c5f30c9806a26c3812e758341ac74fc42
106,564
def get_version(raw): """ This will parse out the version string from the given list of lines. If no version string can be found a ValueError will be raised. """ for line in raw: if line.startswith("# MODULE:"): _, version = line.split(":", 1) return version.strip() ...
cddccd1905f7a75eb1122b300cccebb71782304f
81,476
def strip_vmdk_extension(filename): """ Remove the .vmdk file extension from a string """ return filename.replace(".vmdk", "")
c4968c0e92e3948d23226224064abf78368acfbb
152,381
from typing import Any def _yamlize(value: Any) -> Any: """Converts a python value to a valid YAML representation. Args: value: the python value to convert Returns: Either a string containing ``"null"``, ``"true"`` or ``"false"`` for the special cases ``None``, ``True`` and ``Fal...
b7b202fcd0b0e91c46a8d8c9dbd27dfa35ec348b
178,047
def get_z_sample(xbar, mu, SE): """ Return the z-score of a sample, from a sampling distribution. Parameters ---------- * xbar: mean of the current sample. * mu: mean of the population from where the sample is drawn. * SE: standard error of the sampling distribution (population SD / root(po...
be1b19d6c0ff6a9f47425e3b12813b6da68938f1
668,085
def apple_url_fix(url): """ Fix Apple URL. :param url: URL to fix :return: fixed URL """ if url.startswith("webcal://"): url = url.replace('webcal://', 'http://', 1) return url
e3576984708089e5932a45675ed5af7bc622b3fa
613,295
def load_text(file_name): """ Load lines from a plain-text file and return these as a list, with trailing newlines stripped. Arguments: file_name (str or unicode): file name. Returns: list of str or unicode: lines. """ with open(file_name) as text_file: lines = text_...
11c4b0d57be2488800b11857b138b98fad689564
120,653
def in_order_traversal(tree, path=[]): """Visit left -> curr -> right""" if tree: in_order_traversal(tree.left, path) path.append(tree.value, path) in_order_traversal(tree.right, path) return path
7436f339f5eb9dfabf04b02eab5c1eab2f6023b8
210,039
def should_log_line(line): """ Filters out unhelpful lines in the stacktrace (such as type decorators) that can be left out without missing out. """ blacklist = ['google_appengine', 'typechecked_', 'add_1_monkey_patches', 'db_hooks', 'threading.py'] return all(word not in line for word in blacklist)
210c13e7e2eb51b88c122bd2d1a5710cd3611a52
394,183
def print_deps_stdout_arg(request): """Argument for printing deps to stdout""" return request.param
63d735cd08b71bf12bef624c187ca9e128621ae6
665,243
def all_different(x): """ Return True if all non-None values in x are different""" seen = set() return not any([i is not None and (i in seen or seen.add(i)) for i in x])
47296e27a261a1e2dfeaa1b67d4bc9ca142a5c99
194,191
def is_zip_archive(file_name): """test for zip file archive extension""" if file_name.lower().endswith('.zip'): return True else: return False
7e8f6b3304e05bb771d0fcce0677a4d89700829d
603,564
def get_sheet(book, sheetName=None, sheetIndex=0): """Get xlrd sheet object""" if sheetName is not None: sheet = book.sheet_by_name(sheetName) return sheet else: sheet = book.sheet_by_index(sheetIndex) return sheet
1db384417769299540e892321c029f71f9f4f10b
61,887
from typing import List def tcp_decode(message: bytes) -> List: """Decode TCP message to a list of strings.""" return message.decode().split('\r\n')[:-1]
a7445816445009a0550006ebb974fec6287ab469
265,670
def is_reference_html_file(filename): """Return true if the filename points to a reference HTML file.""" if (filename.endswith('-expected.html') or filename.endswith('-expected-mismatch.html')): return True return False
72c635528fb96d6a5c475c348df03c3b44147fbf
566,682
from functools import reduce def get_nested(dictionary: dict, keys: str, default=None): """ Get a value inside a nested dict, or return the default value otherwise. source: https://stackoverflow.com/a/46890853 :param dictionary: the dict with the value inside :param keys: a string to the path, ne...
3130209ede766a2f59e34c414964f4d908ba745b
454,766
import torch def accuracy(y_true, y_pred): """Compute classification accuracy (pytorch tensors) """ return torch.mean(y_pred.eq(y_true).float())
976c02adbf0627aa8e6a9df495c4799750fdb584
562,043
def get_num_increases(data: list[int]) -> int: """ Get the total number of times the value of the next element in the list is greater than the value of the previous element >>> get_num_increases([1, 3, 4, 2, 5]) 3 """ return sum(b > a for a, b in zip(data[:-1], data[1:]))
d57422eba4cdcee2cc16877af8aa82590a5716cc
94,571
from typing import List import ast def create_request_data(data_fields: List, args: dict) -> dict: """ This function converts the input given by the user when creating a new record to a data dict that should be passed in the http request. Args: data_fields: A list with the fields that should ...
18237aa4be661a2bc70160d6923788a70f39a94f
356,471
def get_first_list_prop(lst): """ Returns the first element in the list that starts with list_, -1 if not found. Arguments: lst {list} """ for i, e in enumerate(lst): if e.startswith("list_"): return i return -1
faa73a11e835b4ee7133b504d06cb715df00331f
95,455
def _arguments_str_from_dictionary(options): """ Convert method options passed as a dictionary to a str object having the form of the method arguments """ option_string = "" for k in options: if isinstance(options[k], str): option_string += k+"='"+str(options[k])+"'," ...
6f0cf1176f0bcada81dc8dbe17cb57e760fd4d8c
686,295
import warnings def prettywarn(msg, warntype): """Prints a suppressable warning without stack or line info.""" original = warnings.formatwarning def _pretty_fmt(message, category, filename, lineno, line=None): return "{0}: {1}\n".format(category.__name__, message) warnings.formatwarning = _pre...
c3d1ba02346a23057880c0a323cf969cc0bc00fa
189,242
import json def load_json(json_path): """ json 파일 읽어오기 :param json_path: json 파일 경로 :return: json 파일 데이터 """ with open(json_path, 'r') as f: data = json.load(f) return data
cd533be2d00c6c10075147fbab81cc3b3b8469e9
607,046
import torch def quat2mat(quat): # https://github.com/ClementPinard/SfmLearner-Pytorch/blob/master/inverse_warp.py#L112 """Convert quaternion coefficients to rotation matrix. Args: quat: first three coeff of quaternion of rotation. fourht is then computed to have a norm of 1 -- size = [B, 3] Retur...
c1badeea24e4829ac67dd8e7657960146be4cbdb
281,473