content stringlengths 35 416k | sha1 stringlengths 40 40 | id int64 0 710k |
|---|---|---|
def quintil_rent(x,p,d):
"""Funcion para obtener la division por quintiles de la rentabilidad"""
if x <= d[p][0.20]:
return 'Q1'
elif x <= d[p][0.4]:
return 'Q2'
elif x <= d[p][0.6]:
return 'Q3'
elif x <= d[p][0.8]:
return 'Q4'
else:
return 'Q... | c510d469a23a8fbb4f87d2ea52ad835e57f023fc | 33,582 |
import json
def from_json(text):
"""Parse text as json.
"""
# If `text` is a byte string, decode it as utf-8.
if isinstance(text, bytes):
text = text.decode('utf-8')
return json.loads(text) | 3374c29a5e36dd096f4cb1c3d6692bb9af242386 | 33,583 |
def visual_bounds(EBC, std_lon=False):
"""
Returns the latitude and longitude bounds for plotting a decently
large swatch of the EBC.
Parameters
----------
EBC : str
Identifier for the EBC.
'CalCS': California Current
'HumCS': Humboldt Current
'CanCS': Canary Curr... | a1f787ad911b16cdad6486ef94bf1595bc8fb833 | 33,584 |
def update(event_handler):
"""post processing updating artist objects"""
def event_handler_decorated(self, *args, **kwargs):
event_handler(self, *args, **kwargs)
# self.ax.imshow(self.bgimg)
self.ax.set_xlim(0, self.bgimg.shape[1])
self.ax.set_ylim(0, self.bgimg.shape[0])
... | cdc65e1f937b0cfc6423b9a4142460202e5565bb | 33,585 |
import os
import random
def random_text(random_file=None):
"""Random selective quotes from file"""
if random_file is None:
random_file = os.path.join(
os.path.dirname(os.path.dirname(__file__)), "data", "random.txt"
)
with open(random_file) as file_used:
return random.c... | 541c21924704d1d9f8843c29ed7b66598b3a1f4e | 33,587 |
import json
def load(path):
"""
本函数从一个文件中载入数据并转化为 dict 或者 list
path 是保存文件的路径
"""
with open(path, 'r', encoding='utf-8') as f:
s = f.read()
# log('load', s)
# loads: 相反,字符串 --> 列表 --> 对象。
# loads的参数是字符串的格式,所以loads负责字符串 --> 列表这一段,而 列表 --> 对象由ms = [cls.new(m) for m in ... | 2e95625d505b9d983f9c2094c2fe0300a0f19456 | 33,588 |
def is_success(code):
"""List of status codes considered to be successful."""
okay = [200, 202]
return code in okay | 442ac0b94a14afe31be26cee454f7a4e69e46d7c | 33,589 |
def exponential_smoothing(series, alpha):
"""
:define: Exponential smoothing weights all of the observations, while exponentially decreasing the weights as we move further back in time.
:define2: Exponentiality is hidden in the resuriveness of the function: y-hat = a * y-not + (1-a) * (previous y-not)
:... | 0d62b329daea56355ba81e0bff5cac9b65858877 | 33,590 |
def RGB(image):
"""
input: array with YCbCr values between 16 and 235(Y) or 240(Cb, Cr)
output: array with RGB values between 0 and 255
"""
x = image.copy()
Y = image[:, :, 0]
Cb = image[:, :, 1]
Cr = image[:, :, 2]
x[:, :, 0] = (255.0/219.0)*(Y - 16.0) + (0.0/112.0) *(Cb - 128.0)+... | 351614248bc6c3ea3b99b777f327c52f8c775944 | 33,591 |
import os
def get_abs_path_url(path):
""" Returns the absolute url for a given local path.
"""
return "file://%s" % os.path.abspath(path) | 36680eb29fd3e69334f76f7704b65e3c938ccbf0 | 33,592 |
def _iterate_over_nested_obj(obj, key):
"""It iterates over the nested dict object.
It iterates over two types of data
* list
* dict
for the rest data type it returns the value
Args:
obj (any type): object to process
key (str, int): key to find in object
"""
if isinsta... | 7b6352d6f24a8753b700c2c6491455460d5a4274 | 33,593 |
import os
def cwd_relative(path, args):
"""Translate prefix-relative path to current working directory-relative."""
return os.path.relpath(os.path.join(args.root, path), args.initial_working_dir) | 8de4cf30740222064eab2aacbf7f078e04ff7d85 | 33,594 |
def target_distribution(targets):
"""Get the target distributions.
Arguments:
targets (pd.Series): Target data
Returns:
pd.Series: Target data and their frequency distribution as percentages.
"""
distribution = targets.value_counts() / len(targets)
return distribution.mul(100).... | 93148f804130c33d18a9e33a3bf8d6fb12f6e3df | 33,595 |
import numpy
def threshold_op(base_array, threshold_val, base_nodata, target_nodata):
"""Threshold base to 1 where val >= threshold_val."""
result = numpy.empty(base_array.shape, dtype=numpy.uint8)
result[:] = target_nodata
valid_mask = ~numpy.isclose(base_array, base_nodata) & (
~numpy.isclos... | e8b4a07483ad7a6beef798708a8d6a615a8c35f6 | 33,597 |
def ExperimentTemplate() -> str:
"""A template with Markdown syntax.
:return: str with Markdown template
"""
return """
Experiment
==========
Any [markdown code](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet) can be used to describe this experiment.
For instance, you can find the au... | 302d41a33dc9bfebfdca53980a87c8c77e8f475a | 33,600 |
import pip
import os
import sys
def get_pip_program(exe=None):
"""
Gets :epkg:`pip` executable and
fixes an issue with :epkg:`Pandoc`.
@param exe path to python executable
@return pip executable
.. faqref::
:title: How can I check the dependencies... | e26f89d48506f1af66a2e1315b52cc8142a5852d | 33,601 |
def bubbleSort(l):
"""
Needs to be implemented
"""
for i in range(1, len(l)-1):
for j in range(1, len(l)-i):
if l[j] > l[j+1]:
l[j], l[j+1] = l[j+1], l[j]
return l | 55b486dda1f7efdd994903ef68482fc7e22444b5 | 33,602 |
def encode_bool(value: bool) -> bytes:
"""Encodes a boolean.
"""
return bytes([int(value)]) | fdfc695dcede9df5e79df8789837cd30a1deb0f8 | 33,603 |
from subprocess import Popen, PIPE, STDOUT
def run_cmd(cmd, shell=False, input=None):
"""Run the supplied command and return a dict of its outputs."""
p = Popen(cmd, stdout=PIPE, stdin=PIPE, stderr=STDOUT, shell=shell,
universal_newlines=True)
stdout, stderr = p.communicate(input=input)
... | c5d91da12d9b34341cf20a3e167be326d8060d35 | 33,604 |
import subprocess
import sys
def pip_import(module, pypi_name=None):
"""
Return None if we can't import or install it.
"""
try:
return __import__(module)
except ImportError:
pass
subprocess.call([sys.executable, "-m", "pip",
"install", pypi_name or module]... | fdae11df335a13662467407834774ea3efe55163 | 33,605 |
def filterProj4String(p4string):
"""
Removes the '+units' flag and value from a Proj4 string, and the
'+ellps' flag and value if there is a '+datum' flag and value,
since those seems to trip pyproj up. Seems kludgy. Argh.
"""
def should_keep_flag(flag, should_remove_ellps):
"""
... | 73d8c5f3255620c9cfe79311a6541c87ed17f4a2 | 33,606 |
import argparse
def create_argument_parser():
"""Create argument parser for the evaluate script."""
parser = argparse.ArgumentParser(
description='evaluates a dialogue model')
parser.add_argument(
'-s', '--stories',
type=str,
required=True,
help=... | 5c26c56721f476b81149f9389474f56d86f7a5bc | 33,607 |
import torch
def remove_init_unsafe_from_d(data, initials, unsafes):
"""
:param data:
:param initials:
:param unsafes:
:return:
"""
center_init = torch.tensor(initials[0])
center_unsafe = torch.tensor(unsafes[0])
new_data = []
for idx in range(len(data)):
# if data belo... | e443aa75f9483108f2fa81b603ad5f06cb4ad329 | 33,609 |
def flatten_globals(sequence_globals, evaluated=False):
"""Flattens the data structure of the globals. If evaluated=False,
saves only the value expression string of the global, not the
units or expansion."""
flattened_sequence_globals = {}
for globals_group in sequence_globals.values():
for ... | 110e4b9e5af2981c50dd4b8295f542cfaf4c2d83 | 33,610 |
def reversed_iterator(iter):
"""
Returns a reversed list of the elements of an Iterator.
"""
return reversed(list(iter)) | 0f0a012573948002777d0706024f207a98d09022 | 33,612 |
import argparse
def get_args():
"""Get command line arguments"""
parser = argparse.ArgumentParser(description='Python cli boilerplate', formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('-n', '--num', help='A number', metavar='int', type=int, default=10)
args = parser.parse_a... | 4e8ca0c0ac418a6b9ae4e697d1c38143f5f43734 | 33,613 |
def std_label(value):
"""Given Crystal specific uppercase species names, returns the capitalized
versions.
"""
labels = []
for label in value:
labels.append(label.lower().capitalize())
return labels | ffad92d9ed272bf9fabcc650e2e9b1e967d00246 | 33,614 |
def is_value(field: str, field_name: str, value: str) -> bool:
""" """
return field == value | 56d600056c1e3b8fac81112a50fadf09dcbef299 | 33,615 |
def same_module(left, right):
"""
Returns true if l is same module as r, which is when module name is equal
and modules defined in one file, in same cabal-dev sandbox or in cabal
"""
same_cabal = left.cabal and right.cabal and (left.cabal == right.cabal)
same_filename = left.location and right.l... | 2ca767afd576497b2313e2963c6411f7f595a033 | 33,617 |
import hashlib
def compute_hash(filepath: str) -> str:
"""Compute an MD5 hash for a filepath string."""
h = hashlib.md5()
h.update(filepath.encode())
return h.hexdigest() | ac311fd236a5250402231e506387a2a42073af3e | 33,618 |
def add_pem_headfoot(public_key):
"""
Return string, representing PEM text for a public key
Keyword Parameters:
public_key -- String, representing the public key text
>>> add_pem_headfoot('foo')
'-----BEGIN PUBLIC KEY-----\\nfoo\\n-----END PUBLIC KEY-----'
"""
preamble = "-----BEGIN P... | dcb093f942d47f6a11bd2dc82441ba6e82f55b01 | 33,619 |
import functools
import operator
def prod(it):
"""Product of an iterable.
"""
return functools.reduce(operator.mul, it) | e20df189d56656f680782579759c5080e6cb75c8 | 33,620 |
def many_parents_edges():
"""Node 62 has 18 parents and no children."""
edges = [('96', '62'), ('80', '62'), ('98', '62'),
('100', '62'), ('86', '62'), ('102', '62'), ('104', '62'),
('64', '62'), ('106', '62'), ('108', '62'), ('110', '62'),
('112', '62'), ('114', '62'), ('... | 7eb0509ce26e210fbf457ee59db504e73668ed97 | 33,621 |
def extract_dict_key(dataframe, column, key, new_column=None, separator='.'):
"""
Extract values of ``key`` into ``new_column``. If key is missing, ``None`` is added to
the column.
.. code-block:: python
>>> df = DataFrame({
... 'trial_num': [1, 2, 1, 2],
... | 5567a3e8e837e45b851779942e2c9729d4fe856c | 33,622 |
def compression(path):
"""
Based on filename, is compression being used?
"""
compress = None
ext = path.suffix
if ext == ".gz":
compress = True
elif ext == ".dil":
compress = False
else:
raise Exception(f"invalid file extension [{ext}], must be .dil or .dil.gz")
... | 37d556c149bf15876b352979e00f12033c40b796 | 33,623 |
def ros_unadvertise_service_cmd(service):
"""
create a rosbridge unadvertise_service command object
:param service: name of the service
"""
command = {
"op": "unadvertise_service",
"service": service
}
return command | ef78ba4ffbb6fc8b0f13ccaebdfb13651294a330 | 33,625 |
def mk_struct(name, label, resn=None, chain=None,
color='white', style='cartoon',
transparency=None):
"""Generate the PyMol code to display a structure."""
return """
create %(label)s, %(name)s %(chain)s %(resn)s
show %(style)s, %(label)s
color %(color)s, %(label)s
%(transparency)s
... | 329ec5c8cf2a4d1d54436471a2757d257fb53cca | 33,627 |
def values_exist(expected: set, actual: set) -> bool:
"""
Check the expected worksheets exist.
:return:
"""
return expected <= actual | 54dd7a070b0488efa0d1cda3ba78cd8238f55c6e | 33,628 |
def loopback_ip():
"""Return an IP address for localhost."""
return "127.0.0.1" | 1ddba8f7935b528fbac2f1db1f06f22ce616007b | 33,629 |
import os
def different_args(args, this_config_file, logger):
""" Returns empty list if no args differ
"""
diff_args = []
args_to_write = ["maxdist", "subassembler", "maxcov"]
old_config_dict = {}
this_config_dict = vars(args)
if not os.path.exists(this_config_file):
raise ValueErr... | 09305de32e385df3d5e130a66a343c73558eabf1 | 33,632 |
import torch
def physical_violation(bdb_layout, bdb_3d):
"""
compute the loss of physical violation
:param bdb_layout: 1 x 8 x 3 tensor
:param bdb_3d: b x 8 x 3 tensor
:return:
"""
b = bdb_3d.size(0)
layout_max = torch.max(bdb_layout, dim=1)[0].expand(b, -1) # bx3
layout_min = tor... | 6352591534822467d35ac0c72fbfcc1800ad8862 | 33,633 |
def clear_stop_word(file_name, sentence_list):
"""Clear a stop word from list of word in sentence
Parameter : file name that contain stop words and sentence as list
Return : Sentence as list that already clear a stop words
"""
duplicate_list = []
stopwords = []
# Open stopword file
stopw... | a20f35c232371e55f3f1d7b52e139f916f4bc6a5 | 33,635 |
import re
def string2lines(astring, tab_width=8, convert_whitespace=False,
whitespace=re.compile('[\v\f]')):
"""
Return a list of one-line strings with tabs expanded, no newlines, and
trailing whitespace stripped.
Each tab is expanded with between 1 and `tab_width` spaces, so that th... | add99c9a5844cc8b7a2c9cc63dc18a42ee4e9f10 | 33,636 |
def add_default(name, **kwargs):
"""Add validator to the plugin class default meta.
Validator will be added to all subclasses by default
:param name: str, name of the validator plugin
:param kwargs: dict, arguments used to initialize validator class
instance
"""
def wrapper(plugin):
... | 96f1bd3faadb636e500a16cd867445714ffe4a52 | 33,637 |
def make_progress(row):
"""return string for progress bar"""
if row is None:
return ""
hits = row["hits"] / float(row["tot"]) * 100.0
dots = row["dots"] / float(row["tot"]) * 100.0
# other = row['other'] / float(row['tot']) * 100.0
nulls = row["nulls"] / float(row["tot"]) * 100.0
ret... | 05e4d2e58611bef0c2e753891686bf7aaf9ec8c2 | 33,639 |
def _lookup_elements(adm, idRefs):
"""Lookup multiple ID references"""
return [adm.lookup_element(key) for key in idRefs] | a6bcecd31142009b202386dd9b5d573163722d0d | 33,640 |
def setup_ca(reference_fname,indexing=1,skip_resis=[]):
"""
most of the code in my_md_analysis assumes 1-based indexing
for this, but make_plot wants 0-based indexing. in the end,
i should switch everything over to 0-based, but i'll leave
this in as a hack for now.
"""
master_residue_list =... | 9478deea22b51417bbf38ccc8c71e16898ef3e48 | 33,641 |
def enumeration(env, node):
"""
'Enumeration' statement class for AST.
interpret - runtime function for Evaluator (empty function).
"""
return node.elements | 94d9aab5ef2f562ebaaaade063c1f09516d07d29 | 33,642 |
def LIX_getter(doc):
"""
extract LIX score
Example:
Doc.set_extension("LIX", getter=LIX_getter)
fetch result:
doc._.LIX
"""
O = len(doc)
P = len(list(doc.sents))
L = len([t for t in doc if len(t) > 6])
LIX = O / P + L * 100 / O
return LIX | 4cd7a33ba05ce8303d30345b32d350e0fd67feea | 33,646 |
def generate_stopwords():
"""
return set because membership access is much faster than using lists (lists are faster at iterating
@return {set}
"""
stopwords = set()
f = open("data/stopwords.txt")
for line in f.readlines():
stopwords.add( line.strip("\n") )
f.close()
return... | aab067bc1d1ac98235590270ef3239ff2cfcfdb6 | 33,647 |
def integrand_x(x, alpha, beta, l, i):
"""Integrand in the reparametrized q^l_i expression."""
return (
x ** (alpha - 1)
* (1 - x) ** (l + beta - i / 2 - 1)
* (1 + x) ** (i / 2)
) | 4eea4308976868ab715951b3e1c64750b2c87a2f | 33,649 |
def depth_to_location(depth: float):
"""
Convert depth (of polyp) to location in colon
based on https://training.seer.cancer.gov/colorectal/anatomy/figure/figure1.html
:param depth:
:return:
"""
locations = []
if depth <= 4:
locations.append('anus')
if 4 <= depth <= 17:
... | 1481bdc4e83d55668d98d19218a6b842c64bb21c | 33,650 |
from datetime import datetime
def GrADStime_to_datetime(gradsTime):
"""
Convert GrADS time string e.g., 00:00z01Jan2000 to datetime
Parameters
----------
gradsTime : str
Grads time in str format e.g., 00:00z01Jan2000.
Returns
----------
re : datetime
"""
l... | df21ac4532510e883245be67ba354f4048761800 | 33,651 |
def add_decoy_tag(peptides):
"""
Adds a '_decoy' tag to a list of peptides
"""
return [peptide + "_decoy" for peptide in peptides] | cc9825c4eb7b6b1bb8b7857b2522bc90fb0e4c01 | 33,652 |
def rejection_sample(fn, condition):
"""
Sample from fn until we get a value that satisfies
condition, then return it.
"""
while True:
value = fn()
if condition(value):
return value | 28674cecc21c6ef30bf1777dd3f4e595c2db1007 | 33,653 |
def fetch_base_path(dir_path: str) -> str:
"""Module to fetch base path of a given path.
Parameters
----------
dir_path*: string variable representing the actual path variable (absolute/relative)
(* - Required parameters)
Returns
-------
base path as string
"""
# Return the fil... | 3c50a107884335cbbd64e44541fc7deecfc188b6 | 33,654 |
def mock_time(value):
"""Mock out the time value."""
def _mock():
return value
return _mock | fe4bca50a3593557a74c413980160b812baf6e27 | 33,655 |
def subtile(img, w, h, cx, cy):
"""
Gets a tile-indexed w by h subsurface from the tilemap "img".
"""
return img.subsurface((cx*w, cy*h, w, h)) | c5d996922b58e53775b46b88906e7844cda2d11c | 33,657 |
def qrel_entry(quest_id, answ_id, rel_grade):
"""Produces one QREL entry
:param quest_id: question ID
:param answ_id: answer ID
:param rel_grade: relevance grade
:return: QREL entry
"""
return f'{quest_id}\t0\t{answ_id}\t{rel_grade}' | dcd349ea183ed2ee5c508890f08118dae3844802 | 33,658 |
import os
import errno
def get_user_config_path():
"""
Returns the path to the user configuration directory and creates it if it does not exist already.
:return: Path to the configuration directory of leapp.
"""
leapp_conf = os.path.join(os.path.expanduser('~'), '.config', 'leapp')
try:
... | c38d16f0f09fb11d3b1da628e0c70ac68e7fcf25 | 33,659 |
def find_in_sorted_arr(value, array, after=False):
"""Return position of element in a sorted array.
Returns:
int: the maximum position i such as array[i] <= value. If after is
True, it returns the min i such as value <= array[i] (or 0 if such
an indices does not exist).
"""... | 0a724ca72fdb2abe4feaea3a2b0d971f803479c9 | 33,660 |
def get_animation_curve_types():
"""
Returns a list with all animation curve types available in Maya
:return: list(str)
"""
anim_curve_types = ['TA', 'TL', 'TT', 'TU', 'UA', 'UL', 'UT', 'UU']
return ['animCurve{}'.format(curve_type) for curve_type in anim_curve_types] | 1b5571add93c48496d09007fc96b329b1f839d85 | 33,661 |
import sys
import platform
def _use_appnope():
"""Should we use appnope for dealing with OS X app nap?
Checks if we are on OS X 10.9 or greater.
"""
return sys.platform == 'darwin' and V(platform.mac_ver()[0]) >= V('10.9') | f7479fd77a160dafada6e77346bab4a43c7e43d0 | 33,662 |
def dequeue(interp, queuename):
"""
DEQUEUE queuename
outputs the least recently QUEUEd member of the queue that is the
value of the variable whose name is ``queuename`` and removes that
member from the queue.
"""
var = interp.get_variable(queuename)
return var.pop(0) | cb5141b3779eeedb5ac09d8d14da7403bcdb37c3 | 33,664 |
import textwrap
import argparse
def parse_args():
"""
Parses and returns script's arguments
"""
description = textwrap.dedent(
"""
Download and extract a symbiflow benchmark release into a
VTR-style directory structure.
If a previous matching symbiflow rel... | d5b96cb54da6cbc759d3f1c1c0f8240574d2fb4d | 33,665 |
def r_local(denis, alt):
"""Local recombination from Sultan eq 21 alpha*n_mol
Risbeth & Garriott '69: Dissociative recombination is the principal
E and F region loss mechansim.
Huba '96: RTI not damped by recombination in F region
n_mol is the concentration of molecular ions
alpha... | 89fe0f6bfb0558125f1283d5836940c2937f2c68 | 33,666 |
def LinearizedRockPhysicsModel(Phi, Clay, Sw, R):
"""
LINEARIZED ROCK PHYSICS MODEL
Linear rock physics model based on multilinear regression.
Written by Dario Grana (August 2020)
Parameters
----------
Phi : float or array_like
Porosity (unitless).
Clay : float
Clay volu... | 62287e8d312c020c443663c33f0bf558ad66aa7b | 33,667 |
def _get_loop_decoys(args):
"""Wrapper for Fread.automodel_loop(), to be used with map().
args[0] is a the MultiFread object, args[1] are the sequential
arguments for Fread.automodel_loop(), args[2] are the keyword
arguments for Fread.automodel_loop().
Returns a MultiFread object that is a... | 71e9cf5bd1be078cab862c783dd709bae1b69f61 | 33,669 |
def betti(H):
"""Compute the dimensions of each homology space output by the homology() function"""
return [basis.shape[1] for basis in H] | 470fefdfcfea577d2a11b6fdc304f85a84eaf8f9 | 33,670 |
import subprocess
def run_command(command):
"""
Run a system command
Args:
command (str): Command to be executed
Returns:
int, str, str: Return return code, output and error
"""
stderr = subprocess.PIPE
stdout = subprocess.PIPE
command_list = command.split(' ')
t... | eccc56a5da8d4260c204df79e6aca309c4c36f71 | 33,675 |
def getAllUserPresets():
"""
getAllUserPresets() -> None
gets a list of all current user presets
@return: a list of tuples containing all nodename/presetname pairs.
"""
return None | dcca90a2eb9b9574d1c39f470b6ee2be5dfa6960 | 33,677 |
def parse_line(line):
"""Returns a list of ints and a minuend integer.
The line needs to be in the form '1,2,3,...;5' as described in the module
docstring
"""
num_list, minuend = line.split(';')
num_list = [int(num) for num in num_list.split(',')]
minuend = int(minuend)
return num_list,... | 905222663ae3c7b7c3ef9df5d6d7ab783fb28807 | 33,679 |
def time2str(t, fmt='%Y-%m-%d %H:%M:%S', microsec=False):
""" Convert a pandas Timestamp to a string
See https://docs.python.org/2/library/datetime.html#strftime-strptime-behavior for conversion
"""
fmt = fmt + '.%f' if microsec is True else fmt
return t.strftime(fmt)
#return t.strftime(fmt... | a0aecef7b052af4b1c291d6d2a4e54467f319af2 | 33,680 |
def _try_list_if_string(input_str):
"""
Attempt to convert string to list if it is a string
"""
if not isinstance(input_str, str):
return input_str
val_split = input_str.split(",")
if len(val_split) > 1:
return [float(sval.strip()) for sval in val_split]
return input_str | c1c66dcad87dd4be041f6705e2b6252b8889dcd2 | 33,683 |
import re
def is_valid_email(field):
"""
From SO
"""
return (
re.match(
r'(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$',
field,
)
is not None
) | cbce0cc067cca9edbbf7258209bbd9ab8594977e | 33,685 |
def extract_log_size(raw_log_info):
"""提取日志大小"""
log_size = raw_log_info.strip().split('\t')[0]
return log_size | 7b98fd94b068f830fe7add7b03264f2936e218b4 | 33,686 |
from datetime import datetime
def _timehdr(ln: str) -> datetime:
"""
handles malformed header dates
NOTE: must do second=int(float()) due to non-conforming files that don't line up decimal point.
"""
try:
second = int(float(ln[30:36]))
except ValueError:
second = 0
if not... | bffa7c4d1c047d33f9b2f27e672d4cf1aa901b4b | 33,687 |
from datetime import datetime
def year_gen(min_val, target):
"""generate entries in the dropdown menus for number of years. Set to
generate values from current year to the provided minimum value"""
tup = ()
for i in range (min_val, int("{:%Y}".format(datetime.now())) + 1):
tup += (target.add_i... | 389ed945bc4662352419a1c8915e1876183cf86a | 33,688 |
def RemoveServiceAccountFromDatasetPolicy(dataset_policy, member, role):
"""Deauthorize Account for Dataset."""
for entry in dataset_policy.access:
if entry.role == role and member in entry.userByEmail:
dataset_policy.access.remove(entry)
return True
return False | b06e6f8a52ba077001ba6faf832994c5cd128df1 | 33,689 |
import requests
def get_data_from_url(url):
"""
网络请求(自动重试3次)
:argument
url: 请求地质
"""
return requests.get(url, timeout=30).text | 8db57b86acbd4ccaea989ea0f10d31cae2431fe9 | 33,690 |
import os
import sys
def identify_toplevel_dir(path):
"""
:param path:
:return:
"""
src = path
while not path.endswith('/creepiest'):
if path == '/':
raise EnvironmentError('Could not identify library path starting from {}'.format(src))
path, _ = os.path.split(path)... | 36c19cb2287bcf3d9497ca88ca7e8bed0ad70a2a | 33,693 |
import subprocess
def cmd_exists(cmd):
"""Check whether cmd exists on system."""
# https://stackoverflow.com/questions/377017/test-if-executable-exists-in-python
return subprocess.call(['type ' + cmd], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) == 0 | 02922a72abc71c00b9d72f56be06f550e3f402d0 | 33,694 |
import os
def make_file_dir_names(model_name, nt=0):
"""
Export file and directory names which contain model_name.
Indices of exported files/directories:
0 - model_name_big
1 - model_dir
2 - input_file
3 - enkf_input_file
4 - true_input_file
5 - true_sgsim_file
6 - sgs... | b5206072b671ece901f6e30d890c9b874223c5aa | 33,696 |
def receive(socket):
""" Receives a message from a socket.
It detects the end of the message when it receives 0 bytes (EOF).
Parameters
----------
socket : socket
the socket describing a connection, created by connect(url,port)
Returns
-------
response : string
HTT... | d00788654d771b16bd86496020ef1a50043c107d | 33,697 |
from typing import List
def _out_of_range(matrix: List[List[int]], row: int, col: int) -> bool:
"""Check if the row/col is out of range."""
return row < 0 or col < 0 or row >= len(matrix) or col >= len(matrix[0]) | 5385b19fd349051a4f869f4669ee16a2861e1e50 | 33,698 |
import re
def encodePythonIdentifierToC(value):
"""Encode an identifier from a given Python string."""
# Python identifiers allow almost of characters except a very
# few, much more than C identifiers support. This attempts to
# be bi-directional, so we can reverse it.
def r(match):
c = ... | 07b52b5d9dcf83de361cd48f2e710a71f16269de | 33,699 |
import math
def dryness_formula(days: int, num_storys: int) -> int:
"""
Dryness(0~1000)
>>> assert dryness_formula(30, 255) == 0, '255 storys per month'
>>> assert dryness_formula(30, 127) == 125, '127 storys per month'
>>> assert dryness_formula(30, 63) == 250, '63 storys per month'
>>> asse... | 0cb6721cb3ea52a926ba43d8fbf81d5343e24172 | 33,700 |
def substitute(line, charges, current_residuum):
"""
Look up the charge for an atom, and write into a string.
Args:
line: String containing an atom name, residuum name, and original charge.
charges: DataFrame containing atom name, residuum names, new charges.
Returns:
line: the original line, with the charge u... | 755db68832818d1c294e79ab535418d56bea06d7 | 33,701 |
def process_video(self, url):
"""Background task that runs a long function with progress reports."""
def progress_cb(done, total):
self.update_state(state='PROGRESS',
meta={'current': done, 'total': total})
#tag.tag_and_upload(url, progress_cb)
return {'current': 100, '... | da41cda5377a9e97dc3c5a4ac8df7663f36cccd1 | 33,704 |
def form_bowtie_build_cmd_list(bowtie_build_fp, input_contigs_fasta, output_index_fp):
""" format arguments received to generate list used for bowtie_build subprocess call
Args:
bowtie_build_fp(str): the string representing the path to the bowtie program
input_contigs_fasta(list): list of files... | 28af32e6a7626d8bd5647fa12194f0afddb31fbc | 33,705 |
from os.path import basename
import tempfile
import tarfile
def unpack_tarball(archive, tmpdir_prefix='tmp_'):
"""
Open an archive in a temporary directory
Args:
archive (str): the path of th archive to open
tmpdir_prefix (str): prefix of the temporary directory to untar the
... | 314d095d423878c6483835b926f4ec595b742628 | 33,707 |
import math
def test3(x, sin=math.sin):
"""
>>> %timeit test3(123456)
1000000 loops, best of 3: 306 ns per loop
"""
return sin(x) | 42ab8ee27fef2d964652d61dbd45ddad883dfd8b | 33,708 |
def check_datasets_compatible(dataset1, dataset2):
"""
Used for cross-corpus datasets that are combined
from two datasets.
Checks if two datasets have the same class names
and original shape.
The first entry of the original shape is ignored,
since the number of samples does not matter.
... | 5cecca002ebcba6b6733acf8b0b521e61e9937db | 33,709 |
import numbers
def human_bytes(size):
"""
Given a human-readable byte string (e.g. 2G, 10GB, 30MB, 20KB),
return the number of bytes. Will return 0 if the argument has
unexpected form.
Notes
-----
Based on: https://gist.github.com/beugley/ccd69945346759eb6142272a6d69b4e0
"""
if i... | 198b9e0a1179c2f992cb4f1cb4a85980982a756a | 33,710 |
def largest_palindrome_number(lo, hi):
"""largest palindromic product within a given range (using strings)"""
result = 0
for i in reversed(range(lo, hi)):
for j in reversed(range(lo, hi)):
val = list(str(i*j))
# print(i, j, val)
is_palindrome = True
fo... | 232a8d31413e352a601d4474b80141f1e80b3a6e | 33,714 |
def _find_framework_name(package_name, options):
"""
:param package_name: the name of the package
:type package_name: str
:param options: the options object
:type options: dict
:returns: the name of framework if found; None otherwise
:rtype: str
"""
return options.get(package_name, ... | 3b345a5ccbed309ad7a706dce621a8fd405dd9e4 | 33,717 |
import operator
def finalize_tsv(entries):
""" Recalculate and sort TSV data """
ret_entries = list()
# Summate counts
total_count = 0
for entry in entries:
total_count += entries[entry][0]
# Sort
entries_sorted = sorted(entries.items(), key=operator.itemgetter(1), reverse=True)
... | 4ea3915ec42b17896a732cd54d92b02063a9084e | 33,718 |
def make_number_formatter(decimal_places):
"""
Given a number of decimal places creates a formatting string that will
display numbers with that precision.
"""
fraction = '0' * decimal_places
return ''.join(['#,##0.', fraction, ';-#,##0.', fraction]) | 9d8cfbfb56d01a170f6754925f26f1433a9627e1 | 33,719 |
def index():
"""Return today's news"""
return 'koowa2' | acf48e5ff5d94c4d5b42b9598d0d767bbab5b118 | 33,720 |
def convert_node(graph, tree_node):
"""
Add a tree node to a graph.
Parameters
----------
graph : Graph
The graph where the node should be added.
tree_node : Node
The node to be added.
Returns
-------
node_id : int or tuple
The identifier of the added no... | 468b0e87a78e1f289f583f657b04e03132aa123d | 33,722 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.