text stringlengths 75 104k | code_tokens list | avg_line_len float64 7.91 980 | score float64 0 0.18 |
|---|---|---|---|
def dataset_generator(filepath,
dataset,
chunk_size=1,
start_idx=None,
end_idx=None):
"""Generate example dicts."""
encoder = dna_encoder.DNAEncoder(chunk_size=chunk_size)
with h5py.File(filepath, "r") as h5_file:
# Get in... | [
"def",
"dataset_generator",
"(",
"filepath",
",",
"dataset",
",",
"chunk_size",
"=",
"1",
",",
"start_idx",
"=",
"None",
",",
"end_idx",
"=",
"None",
")",
":",
"encoder",
"=",
"dna_encoder",
".",
"DNAEncoder",
"(",
"chunk_size",
"=",
"chunk_size",
")",
"wi... | 40.413793 | 0.010833 |
def get_password_data(
name=None,
kwargs=None,
instance_id=None,
call=None,
):
'''
Return password data for a Windows instance.
By default only the encrypted password data will be returned. However, if a
key_file is passed in, then a decrypted password will also be r... | [
"def",
"get_password_data",
"(",
"name",
"=",
"None",
",",
"kwargs",
"=",
"None",
",",
"instance_id",
"=",
"None",
",",
"call",
"=",
"None",
",",
")",
":",
"if",
"call",
"!=",
"'action'",
":",
"raise",
"SaltCloudSystemExit",
"(",
"'The get_password_data acti... | 32.292683 | 0.000733 |
def add_package(self, package):
"""
Add a package to this project
"""
self._data.setdefault('packages', {})
self._data['packages'][package.name] = package.source
for package in package.deploy_packages:
self.add_package(package)
self._save() | [
"def",
"add_package",
"(",
"self",
",",
"package",
")",
":",
"self",
".",
"_data",
".",
"setdefault",
"(",
"'packages'",
",",
"{",
"}",
")",
"self",
".",
"_data",
"[",
"'packages'",
"]",
"[",
"package",
".",
"name",
"]",
"=",
"package",
".",
"source"... | 25.666667 | 0.009404 |
def update_state(self, state):
"""
Set the state of the current checklist item. Returns a new ChecklistItem object.
"""
checklistitem_json = self.fetch_json(
uri_path = self.base_uri + '/state',
http_method = 'PUT',
query_params = {'value': 'complete' ... | [
"def",
"update_state",
"(",
"self",
",",
"state",
")",
":",
"checklistitem_json",
"=",
"self",
".",
"fetch_json",
"(",
"uri_path",
"=",
"self",
".",
"base_uri",
"+",
"'/state'",
",",
"http_method",
"=",
"'PUT'",
",",
"query_params",
"=",
"{",
"'value'",
":... | 40.090909 | 0.022173 |
def _to_dict(self):
"""Return a json dictionary representing this model."""
_dict = {}
if hasattr(self, 'document_retrieval_strategy'
) and self.document_retrieval_strategy is not None:
_dict[
'document_retrieval_strategy'] = self.document_retrieval_... | [
"def",
"_to_dict",
"(",
"self",
")",
":",
"_dict",
"=",
"{",
"}",
"if",
"hasattr",
"(",
"self",
",",
"'document_retrieval_strategy'",
")",
"and",
"self",
".",
"document_retrieval_strategy",
"is",
"not",
"None",
":",
"_dict",
"[",
"'document_retrieval_strategy'",... | 42.75 | 0.011461 |
def value_present(name, xpath, value, **kwargs):
'''
.. versionadded:: Neon
Manages a given XML file
name : string
The location of the XML file to manage, as an absolute path.
xpath : string
xpath location to manage
value : string
value to ensure present
.. code-... | [
"def",
"value_present",
"(",
"name",
",",
"xpath",
",",
"value",
",",
"*",
"*",
"kwargs",
")",
":",
"ret",
"=",
"{",
"'name'",
":",
"name",
",",
"'changes'",
":",
"{",
"}",
",",
"'result'",
":",
"True",
",",
"'comment'",
":",
"''",
"}",
"if",
"'t... | 28.156863 | 0.000673 |
def topil(self):
"""Returns a PIL.Image version of this Pix"""
from PIL import Image
# Leptonica manages data in words, so it implicitly does an endian
# swap. Tell Pillow about this when it reads the data.
pix = self
if sys.byteorder == 'little':
if self.mo... | [
"def",
"topil",
"(",
"self",
")",
":",
"from",
"PIL",
"import",
"Image",
"# Leptonica manages data in words, so it implicitly does an endian",
"# swap. Tell Pillow about this when it reads the data.",
"pix",
"=",
"self",
"if",
"sys",
".",
"byteorder",
"==",
"'little'",
":"... | 35.137931 | 0.00191 |
def request(
self,
url: str,
method: str,
raise_for_status: bool = True,
path_to_errors: tuple = None,
*args,
**kwargs
) -> tuple:
"""
A wrapper method for :meth:`~requests.Session.request``, which adds some defaults and logging
:param... | [
"def",
"request",
"(",
"self",
",",
"url",
":",
"str",
",",
"method",
":",
"str",
",",
"raise_for_status",
":",
"bool",
"=",
"True",
",",
"path_to_errors",
":",
"tuple",
"=",
"None",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
"->",
"tuple",
":... | 37.527273 | 0.002361 |
def run_container(image,
name=None,
skip_translate=None,
ignore_collisions=False,
validate_ip_addrs=True,
client_timeout=salt.utils.docker.CLIENT_TIMEOUT,
bg=False,
replace=False,
... | [
"def",
"run_container",
"(",
"image",
",",
"name",
"=",
"None",
",",
"skip_translate",
"=",
"None",
",",
"ignore_collisions",
"=",
"False",
",",
"validate_ip_addrs",
"=",
"True",
",",
"client_timeout",
"=",
"salt",
".",
"utils",
".",
"docker",
".",
"CLIENT_T... | 41.372385 | 0.00079 |
def parse_authn_request_response(self, xmlstr, binding, outstanding=None,
outstanding_certs=None, conv_info=None):
""" Deal with an AuthnResponse
:param xmlstr: The reply as a xml string
:param binding: Which binding that was used for the transport
:... | [
"def",
"parse_authn_request_response",
"(",
"self",
",",
"xmlstr",
",",
"binding",
",",
"outstanding",
"=",
"None",
",",
"outstanding_certs",
"=",
"None",
",",
"conv_info",
"=",
"None",
")",
":",
"if",
"not",
"getattr",
"(",
"self",
".",
"config",
",",
"'e... | 40.491525 | 0.001635 |
def patch(make_pool=_default_make_pool):
"""Monkey-patches httplib2.Http to be httplib2shim.Http.
This effectively makes all clients of httplib2 use urlilb3. It's preferable
to specify httplib2shim.Http explicitly where you can, but this can be
useful in situations where you do not control the construc... | [
"def",
"patch",
"(",
"make_pool",
"=",
"_default_make_pool",
")",
":",
"setattr",
"(",
"httplib2",
",",
"'_HttpOriginal'",
",",
"httplib2",
".",
"Http",
")",
"httplib2",
".",
"Http",
"=",
"Http",
"Http",
".",
"_make_pool",
"=",
"make_pool"
] | 44.823529 | 0.001285 |
def parse_data_slots(value):
"""Parse data-slots value into slots used to wrap node, prepend to node or
append to node.
>>> parse_data_slots('')
([], [], [])
>>> parse_data_slots('foo bar')
(['foo', 'bar'], [], [])
>>> parse_data_slots('foo bar > foobar')
(['foo', 'b... | [
"def",
"parse_data_slots",
"(",
"value",
")",
":",
"value",
"=",
"unquote",
"(",
"value",
")",
"if",
"'>'",
"in",
"value",
":",
"wrappers",
",",
"children",
"=",
"value",
".",
"split",
"(",
"'>'",
",",
"1",
")",
"else",
":",
"wrappers",
"=",
"value",... | 27.046512 | 0.00083 |
def qwarp_epi(dset,align_subbrick=5,suffix='_qwal',prefix=None):
'''aligns an EPI time-series using 3dQwarp
Very expensive and not efficient at all, but it can produce pretty impressive alignment for EPI time-series with significant
distortions due to motion'''
info = nl.dset_info(dset)
if info==No... | [
"def",
"qwarp_epi",
"(",
"dset",
",",
"align_subbrick",
"=",
"5",
",",
"suffix",
"=",
"'_qwal'",
",",
"prefix",
"=",
"None",
")",
":",
"info",
"=",
"nl",
".",
"dset_info",
"(",
"dset",
")",
"if",
"info",
"==",
"None",
":",
"nl",
".",
"notify",
"(",... | 41.785714 | 0.019488 |
async def wait_and_quit(loop):
"""Wait until all task are executed."""
from pylp.lib.tasks import running
if running:
await asyncio.wait(map(lambda runner: runner.future, running)) | [
"async",
"def",
"wait_and_quit",
"(",
"loop",
")",
":",
"from",
"pylp",
".",
"lib",
".",
"tasks",
"import",
"running",
"if",
"running",
":",
"await",
"asyncio",
".",
"wait",
"(",
"map",
"(",
"lambda",
"runner",
":",
"runner",
".",
"future",
",",
"runni... | 36.2 | 0.027027 |
def load(language_dir, filename, encoding):
''' Open and return the supplied json file '''
global _DICTIONARY
try:
json_file = filename + '.json'
with io.open(os.path.join(language_dir, json_file), 'r', encoding=encoding) as f:
_DICTIONARY = json.load(f)
except IOError:
raise IOError('... | [
"def",
"load",
"(",
"language_dir",
",",
"filename",
",",
"encoding",
")",
":",
"global",
"_DICTIONARY",
"try",
":",
"json_file",
"=",
"filename",
"+",
"'.json'",
"with",
"io",
".",
"open",
"(",
"os",
".",
"path",
".",
"join",
"(",
"language_dir",
",",
... | 46.545455 | 0.015326 |
def sum(self, selector=identity):
'''Return the arithmetic sum of the values in the sequence..
All of the source sequence will be consumed.
Note: This method uses immediate execution.
Args:
selector: An optional single argument function which will be used
t... | [
"def",
"sum",
"(",
"self",
",",
"selector",
"=",
"identity",
")",
":",
"if",
"self",
".",
"closed",
"(",
")",
":",
"raise",
"ValueError",
"(",
"\"Attempt to call sum() on a closed Queryable.\"",
")",
"if",
"not",
"is_callable",
"(",
"selector",
")",
":",
"ra... | 32.5 | 0.002134 |
def _log_P(self, X , Z, k):
"""
Log of the probability of transition from z to x with k steps
log ( P_k (x, z) )
Inputs :
X :
state to be proposed to
Z :
state to be proposed from
k :
number of recursions, depth
"""
r... | [
"def",
"_log_P",
"(",
"self",
",",
"X",
",",
"Z",
",",
"k",
")",
":",
"r_",
"=",
"self",
".",
"_r_",
"Z_",
"=",
"self",
".",
"_Z_",
"# zero case",
"if",
"k",
"==",
"0",
":",
"log_P",
"=",
"Z",
"[",
"'log_p'",
"]",
"+",
"log_K",
"(",
"X",
",... | 28.892857 | 0.021531 |
def load(self, verbose=False):
"""
Load the list of songs.
Note that this only loads a list of songs that this artist was the main
artist of. If they were only featured in the song, that song won't be
listed here. There is a list on the artist page for that, I just
hav... | [
"def",
"load",
"(",
"self",
",",
"verbose",
"=",
"False",
")",
":",
"self",
".",
"_songs",
"=",
"[",
"]",
"page_num",
"=",
"1",
"total_pages",
"=",
"1",
"while",
"page_num",
"<=",
"total_pages",
":",
"if",
"verbose",
":",
"print",
"(",
"'retrieving pag... | 40.6875 | 0.0015 |
def install_mesos_single_box_mode(distribution):
""" install mesos (all of it) on a single node"""
if 'ubuntu' in distribution:
log_green('adding mesosphere apt-key')
apt_add_key(keyid='E56151BF')
os = lsb_release()
apt_string = 'deb http://repos.mesosphere.io/%s %s main' % (
... | [
"def",
"install_mesos_single_box_mode",
"(",
"distribution",
")",
":",
"if",
"'ubuntu'",
"in",
"distribution",
":",
"log_green",
"(",
"'adding mesosphere apt-key'",
")",
"apt_add_key",
"(",
"keyid",
"=",
"'E56151BF'",
")",
"os",
"=",
"lsb_release",
"(",
")",
"apt_... | 38.12963 | 0.001894 |
def dbRestore(self, db_value, context=None):
"""
Converts a stored database value to Python.
:param typ: <str>
:param py_value: <variant>
:param context: <orb.Context>
:return: <variant>
"""
# restore translatable column
if self.testFlag(self.Fla... | [
"def",
"dbRestore",
"(",
"self",
",",
"db_value",
",",
"context",
"=",
"None",
")",
":",
"# restore translatable column",
"if",
"self",
".",
"testFlag",
"(",
"self",
".",
"Flags",
".",
"I18n",
")",
":",
"if",
"isinstance",
"(",
"db_value",
",",
"(",
"str... | 30.307692 | 0.00246 |
def add_param(self, param_key, param_val):
"""
adds parameters as key value pairs
"""
self.params.append([param_key, param_val])
if param_key == '__success_test':
self.success = param_val | [
"def",
"add_param",
"(",
"self",
",",
"param_key",
",",
"param_val",
")",
":",
"self",
".",
"params",
".",
"append",
"(",
"[",
"param_key",
",",
"param_val",
"]",
")",
"if",
"param_key",
"==",
"'__success_test'",
":",
"self",
".",
"success",
"=",
"param_... | 33.285714 | 0.008368 |
def w16_circuit() -> qf.Circuit:
"""
Return a circuit that prepares the the 16-qubit W state using\
sqrt(iswaps) and local gates, respecting linear topology
"""
gates = [
qf.X(7),
qf.ISWAP(7, 8) ** 0.5,
qf.S(8),
qf.Z(8),
qf.SWAP(7, 6),
qf.SWAP(6, 5)... | [
"def",
"w16_circuit",
"(",
")",
"->",
"qf",
".",
"Circuit",
":",
"gates",
"=",
"[",
"qf",
".",
"X",
"(",
"7",
")",
",",
"qf",
".",
"ISWAP",
"(",
"7",
",",
"8",
")",
"**",
"0.5",
",",
"qf",
".",
"S",
"(",
"8",
")",
",",
"qf",
".",
"Z",
"... | 16.261364 | 0.000659 |
def MakeSimpleProtoClass(fields, full_name=None, pool=None):
"""Create a Protobuf class whose fields are basic types.
Note: this doesn't validate field names!
Args:
fields: dict of {name: field_type} mappings for each field in the proto. If
this is an OrderedDict the order will be maintained, otherw... | [
"def",
"MakeSimpleProtoClass",
"(",
"fields",
",",
"full_name",
"=",
"None",
",",
"pool",
"=",
"None",
")",
":",
"factory",
"=",
"message_factory",
".",
"MessageFactory",
"(",
"pool",
"=",
"pool",
")",
"if",
"full_name",
"is",
"not",
"None",
":",
"try",
... | 37.555556 | 0.012975 |
def find_tags(self, tokens, **kwargs):
""" Annotates the given list of tokens with part-of-speech tags.
Returns a list of tokens, where each token is now a [word, tag]-list.
"""
# ["The", "cat", "purs"] => [["The", "DT"], ["cat", "NN"], ["purs", "VB"]]
return find_tags(tokens... | [
"def",
"find_tags",
"(",
"self",
",",
"tokens",
",",
"*",
"*",
"kwargs",
")",
":",
"# [\"The\", \"cat\", \"purs\"] => [[\"The\", \"DT\"], [\"cat\", \"NN\"], [\"purs\", \"VB\"]]",
"return",
"find_tags",
"(",
"tokens",
",",
"lexicon",
"=",
"kwargs",
".",
"get",
"(",
"\"... | 62.071429 | 0.039683 |
def check_image_format(fformat):
"""Check that *fformat* is valid
"""
cases = {"jpg": "jpeg",
"jpeg": "jpeg",
"tif": "tiff",
"tiff": "tif",
"pgm": "ppm",
"pbm": "ppm",
"ppm": "ppm",
"bmp": "bmp",
"dib": "... | [
"def",
"check_image_format",
"(",
"fformat",
")",
":",
"cases",
"=",
"{",
"\"jpg\"",
":",
"\"jpeg\"",
",",
"\"jpeg\"",
":",
"\"jpeg\"",
",",
"\"tif\"",
":",
"\"tiff\"",
",",
"\"tiff\"",
":",
"\"tif\"",
",",
"\"pgm\"",
":",
"\"ppm\"",
",",
"\"pbm\"",
":",
... | 26.423077 | 0.001404 |
def as_part(func):
"""
Converts a function to a :class:`Part <cqparts.Part>` instance.
So the conventionally defined *part*::
import cadquery
from cqparts import Part
from cqparts.params import Float
class Box(Part):
x = Float(1)
y = Float(2)
... | [
"def",
"as_part",
"(",
"func",
")",
":",
"from",
".",
".",
"import",
"Part",
"def",
"inner",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"part_class",
"=",
"type",
"(",
"func",
".",
"__name__",
",",
"(",
"Part",
",",
")",
",",
"{",
"'m... | 25.146341 | 0.001867 |
def replace_macros(string, spec=None):
"""Replace all macros in given string with corresponding values.
For example: a string '%{name}-%{version}.tar.gz' will be transformed to 'foo-2.0.tar.gz'.
:param string A string containing macros that you want to be replaced
:param spec An optional spec file. If... | [
"def",
"replace_macros",
"(",
"string",
",",
"spec",
"=",
"None",
")",
":",
"if",
"spec",
":",
"assert",
"isinstance",
"(",
"spec",
",",
"Spec",
")",
"def",
"_is_conditional",
"(",
"macro",
":",
"str",
")",
"->",
"bool",
":",
"return",
"macro",
".",
... | 31.967742 | 0.001958 |
def bands(self):
"""
Bandpasses for which StarPopulation has magnitude data
"""
bands = []
for c in self.stars.columns:
if re.search('_mag',c):
bands.append(c)
return bands | [
"def",
"bands",
"(",
"self",
")",
":",
"bands",
"=",
"[",
"]",
"for",
"c",
"in",
"self",
".",
"stars",
".",
"columns",
":",
"if",
"re",
".",
"search",
"(",
"'_mag'",
",",
"c",
")",
":",
"bands",
".",
"append",
"(",
"c",
")",
"return",
"bands"
] | 26.666667 | 0.012097 |
def isuncertainties(arg_list):
"""
check if the input list contains any elements with uncertainties class
:param arg_list: list of arguments
:return: True/False
"""
for arg in arg_list:
if isinstance(arg, (list, tuple)) and isinstance(arg[0], uct.UFloat):
return True
... | [
"def",
"isuncertainties",
"(",
"arg_list",
")",
":",
"for",
"arg",
"in",
"arg_list",
":",
"if",
"isinstance",
"(",
"arg",
",",
"(",
"list",
",",
"tuple",
")",
")",
"and",
"isinstance",
"(",
"arg",
"[",
"0",
"]",
",",
"uct",
".",
"UFloat",
")",
":",... | 33.588235 | 0.001704 |
def update(self, permission):
"""In-place update of permissions."""
self.needs.update(permission.needs)
self.excludes.update(permission.excludes) | [
"def",
"update",
"(",
"self",
",",
"permission",
")",
":",
"self",
".",
"needs",
".",
"update",
"(",
"permission",
".",
"needs",
")",
"self",
".",
"excludes",
".",
"update",
"(",
"permission",
".",
"excludes",
")"
] | 41.5 | 0.011834 |
def trace_grid_stack_to_next_plane(self):
"""Trace this plane's grid_stacks to the next plane, using its deflection angles."""
def minus(grid, deflections):
return grid - deflections
return self.grid_stack.map_function(minus, self.deflection_stack) | [
"def",
"trace_grid_stack_to_next_plane",
"(",
"self",
")",
":",
"def",
"minus",
"(",
"grid",
",",
"deflections",
")",
":",
"return",
"grid",
"-",
"deflections",
"return",
"self",
".",
"grid_stack",
".",
"map_function",
"(",
"minus",
",",
"self",
".",
"deflec... | 40 | 0.01049 |
def _L(self, parm):
""" Creates cholesky decomposition of covariance matrix
Parameters
----------
parm : np.array
Contains transformed latent variables
Returns
----------
The cholesky decomposition (L) of K
"""
return np.linalg.chol... | [
"def",
"_L",
"(",
"self",
",",
"parm",
")",
":",
"return",
"np",
".",
"linalg",
".",
"cholesky",
"(",
"self",
".",
"kernel",
".",
"K",
"(",
"parm",
")",
"+",
"np",
".",
"identity",
"(",
"self",
".",
"X",
"(",
")",
".",
"shape",
"[",
"1",
"]",... | 26.642857 | 0.010363 |
def items_lower(self):
'''
Returns a generator iterating over keys and values, with the keys all
being lowercase.
'''
return ((key, val[1]) for key, val in six.iteritems(self._data)) | [
"def",
"items_lower",
"(",
"self",
")",
":",
"return",
"(",
"(",
"key",
",",
"val",
"[",
"1",
"]",
")",
"for",
"key",
",",
"val",
"in",
"six",
".",
"iteritems",
"(",
"self",
".",
"_data",
")",
")"
] | 36.166667 | 0.009009 |
def load_3DXML(file_obj, *args, **kwargs):
"""
Load a 3DXML scene into kwargs.
Parameters
------------
file_obj : file object
Open and containing 3DXML data
Returns
-----------
kwargs : dict
Can be passed to trimesh.exchange.load.load_kwargs
"""
archive = util.decom... | [
"def",
"load_3DXML",
"(",
"file_obj",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"archive",
"=",
"util",
".",
"decompress",
"(",
"file_obj",
",",
"file_type",
"=",
"'zip'",
")",
"# a dictionary of file name : lxml etree",
"as_etree",
"=",
"{",
"}",... | 39.627306 | 0.000091 |
def connect(self):
"""Logs into the specified ftp server and returns connector."""
for tried_connection_count in range(CFG_FTP_CONNECTION_ATTEMPTS):
try:
self.ftp = FtpHandler(self.config.OXFORD.URL,
self.config.OXFORD.LOGIN,
... | [
"def",
"connect",
"(",
"self",
")",
":",
"for",
"tried_connection_count",
"in",
"range",
"(",
"CFG_FTP_CONNECTION_ATTEMPTS",
")",
":",
"try",
":",
"self",
".",
"ftp",
"=",
"FtpHandler",
"(",
"self",
".",
"config",
".",
"OXFORD",
".",
"URL",
",",
"self",
... | 52.73913 | 0.001619 |
def process_directive(self, directive):
"""
Process a directive which either adds some files from ``allfiles`` to
``files``, or removes some files from ``files``.
:param directive: The directive to process. This should be in a format
compatible with distutils ``MANI... | [
"def",
"process_directive",
"(",
"self",
",",
"directive",
")",
":",
"# Parse the line: split it up, make sure the right number of words",
"# is there, and return the relevant words. 'action' is always",
"# defined: it's the first word of the line. Which of the other",
"# three are defined d... | 46.959459 | 0.001409 |
def set_geo_area(self, area):
'''Sets the geo area for the map.
* africa
* asia
* europe
* middle_east
* south_america
* usa
* world
'''
if area in self.__areas:
self.geo_area = area
else:
raise Unk... | [
"def",
"set_geo_area",
"(",
"self",
",",
"area",
")",
":",
"if",
"area",
"in",
"self",
".",
"__areas",
":",
"self",
".",
"geo_area",
"=",
"area",
"else",
":",
"raise",
"UnknownChartType",
"(",
"'Unknown chart type for maps: %s'",
"%",
"area",
")"
] | 22.4375 | 0.010695 |
def _readLoop(self):
""" Read thread main loop
Reads lines from the connected device
"""
try:
readTermSeq = list(self.RX_EOL_SEQ)
readTermLen = len(readTermSeq)
rxBuffer = []
while self.alive:
data = self.serial.rea... | [
"def",
"_readLoop",
"(",
"self",
")",
":",
"try",
":",
"readTermSeq",
"=",
"list",
"(",
"self",
".",
"RX_EOL_SEQ",
")",
"readTermLen",
"=",
"len",
"(",
"readTermSeq",
")",
"rxBuffer",
"=",
"[",
"]",
"while",
"self",
".",
"alive",
":",
"data",
"=",
"s... | 45.611111 | 0.010733 |
def augknt(knots,order):
"""Augment knot sequence such that some boundary conditions
are met."""
a = []
[a.append(knots[0]) for t in range(0,order)]
[a.append(k) for k in knots]
[a.append(knots[-1]) for t in range(0,order)]
return np.array(a) | [
"def",
"augknt",
"(",
"knots",
",",
"order",
")",
":",
"a",
"=",
"[",
"]",
"[",
"a",
".",
"append",
"(",
"knots",
"[",
"0",
"]",
")",
"for",
"t",
"in",
"range",
"(",
"0",
",",
"order",
")",
"]",
"[",
"a",
".",
"append",
"(",
"k",
")",
"fo... | 33 | 0.01845 |
def _wait_for_and_process_task(self, task):
"""Wait for a task to be ready and process the task.
Args:
task: The task to execute.
"""
function_descriptor = FunctionDescriptor.from_bytes_list(
task.function_descriptor_list())
driver_id = task.driver_id()
... | [
"def",
"_wait_for_and_process_task",
"(",
"self",
",",
"task",
")",
":",
"function_descriptor",
"=",
"FunctionDescriptor",
".",
"from_bytes_list",
"(",
"task",
".",
"function_descriptor_list",
"(",
")",
")",
"driver_id",
"=",
"task",
".",
"driver_id",
"(",
")",
... | 46.328571 | 0.000604 |
def remove_vcf_info(keyword, variant_line=None, variant_dict=None):
"""Remove the information of a info field of a vcf variant line or a
variant dict.
Arguments:
variant_line (str): A vcf formatted variant line
variant_dict (dict): A variant dictionary
keyword (str): The in... | [
"def",
"remove_vcf_info",
"(",
"keyword",
",",
"variant_line",
"=",
"None",
",",
"variant_dict",
"=",
"None",
")",
":",
"logger",
".",
"debug",
"(",
"\"Removing variant information {0}\"",
".",
"format",
"(",
"keyword",
")",
")",
"fixed_variant",
"=",
"None",
... | 31.982456 | 0.00958 |
def rep1(parser: Union[Parser, Sequence[Input]]) -> RepeatedOnceParser:
"""Match a parser one or more times repeatedly.
This matches ``parser`` multiple times in a row. If it matches as least
once, it returns a list of values from each time ``parser`` matched. If it
does not match ``parser`` at all, it... | [
"def",
"rep1",
"(",
"parser",
":",
"Union",
"[",
"Parser",
",",
"Sequence",
"[",
"Input",
"]",
"]",
")",
"->",
"RepeatedOnceParser",
":",
"if",
"isinstance",
"(",
"parser",
",",
"str",
")",
":",
"parser",
"=",
"lit",
"(",
"parser",
")",
"return",
"Re... | 35.923077 | 0.002088 |
def array_from_pair_dictionary(
pair_dict,
array_fn,
dtype="float32",
square_result=False):
"""
Convert a dictionary whose keys are pairs (k1, k2) into a sparse
or incomplete array.
Parameters
----------
pair_dict : dict
Dictionary from pairs of keys to v... | [
"def",
"array_from_pair_dictionary",
"(",
"pair_dict",
",",
"array_fn",
",",
"dtype",
"=",
"\"float32\"",
",",
"square_result",
"=",
"False",
")",
":",
"row_key_set",
",",
"column_key_set",
"=",
"pair_dict_key_sets",
"(",
"pair_dict",
")",
"if",
"square_result",
"... | 31.5625 | 0.00064 |
def search(request, spec, operator='and'):
"""
Search the package database using the indicated search spec.
The spec may include any of the keywords described in the above list
(except 'stable_version' and 'classifiers'),
for example: {'description': 'spam'} will search description fields.
With... | [
"def",
"search",
"(",
"request",
",",
"spec",
",",
"operator",
"=",
"'and'",
")",
":",
"api",
"=",
"pypi",
".",
"proxy",
"rv",
"=",
"[",
"]",
"# search in proxy",
"for",
"k",
",",
"v",
"in",
"spec",
".",
"items",
"(",
")",
":",
"rv",
"+=",
"api",... | 32.916667 | 0.001844 |
def search_news(q, start=1, count=10, wait=10, asynchronous=False, cached=False):
""" Returns a Yahoo news query formatted as a YahooSearch list object.
"""
service = YAHOO_NEWS
return YahooSearch(q, start, count, service, None, wait, asynchronous, cached) | [
"def",
"search_news",
"(",
"q",
",",
"start",
"=",
"1",
",",
"count",
"=",
"10",
",",
"wait",
"=",
"10",
",",
"asynchronous",
"=",
"False",
",",
"cached",
"=",
"False",
")",
":",
"service",
"=",
"YAHOO_NEWS",
"return",
"YahooSearch",
"(",
"q",
",",
... | 39.428571 | 0.01773 |
def repository_contributors(self, **kwargs):
"""Return a list of contributors for the project.
Args:
all (bool): If True, return all the items, without pagination
per_page (int): Number of items to retrieve per request
page (int): ID of the page to return (starts wit... | [
"def",
"repository_contributors",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"path",
"=",
"'/projects/%s/repository/contributors'",
"%",
"self",
".",
"get_id",
"(",
")",
"return",
"self",
".",
"manager",
".",
"gitlab",
".",
"http_list",
"(",
"path",
","... | 43.55 | 0.002247 |
def get_object(cls, api_token, volume_id):
"""
Class method that will return an Volume object by ID.
"""
volume = cls(token=api_token, id=volume_id)
volume.load()
return volume | [
"def",
"get_object",
"(",
"cls",
",",
"api_token",
",",
"volume_id",
")",
":",
"volume",
"=",
"cls",
"(",
"token",
"=",
"api_token",
",",
"id",
"=",
"volume_id",
")",
"volume",
".",
"load",
"(",
")",
"return",
"volume"
] | 31.142857 | 0.008929 |
def pipe_truncate(context=None, _INPUT=None, conf=None, **kwargs):
"""An operator that returns a specified number of items from the top of a
feed. Not loopable.
Parameters
----------
context : pipe2py.Context object
_INPUT : pipe2py.modules pipe like object (iterable of items)
kwargs -- ter... | [
"def",
"pipe_truncate",
"(",
"context",
"=",
"None",
",",
"_INPUT",
"=",
"None",
",",
"conf",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"funcs",
"=",
"get_splits",
"(",
"None",
",",
"conf",
",",
"*",
"*",
"cdicts",
"(",
"opts",
",",
"kwargs",... | 27.606061 | 0.00106 |
def binary_n(total_N, min_n=50):
"""
Creates a list of values by successively halving the total length total_N
until the resulting value is less than min_n.
Non-integer results are rounded down.
Args:
total_N (int):
total length
Kwargs:
min_n (int):
minimal length after division
Ret... | [
"def",
"binary_n",
"(",
"total_N",
",",
"min_n",
"=",
"50",
")",
":",
"max_exp",
"=",
"np",
".",
"log2",
"(",
"1.0",
"*",
"total_N",
"/",
"min_n",
")",
"max_exp",
"=",
"int",
"(",
"np",
".",
"floor",
"(",
"max_exp",
")",
")",
"return",
"[",
"int"... | 26.666667 | 0.008621 |
def GetCredential(self, path_spec, identifier):
"""Retrieves a specific credential from the key chain.
Args:
path_spec (PathSpec): path specification.
identifier (str): credential identifier.
Returns:
object: credential or None if the credential for the path specification
is no... | [
"def",
"GetCredential",
"(",
"self",
",",
"path_spec",
",",
"identifier",
")",
":",
"credentials",
"=",
"self",
".",
"_credentials_per_path_spec",
".",
"get",
"(",
"path_spec",
".",
"comparable",
",",
"{",
"}",
")",
"return",
"credentials",
".",
"get",
"(",
... | 34.384615 | 0.002179 |
def write_configuration_file(filepath=_give_default_file_path(),
overwrite=False):
"""Create a configuration file.
Writes the current state of settings into a configuration file.
.. note:: Since a file is permamently written, this function
is strictly speaking not side... | [
"def",
"write_configuration_file",
"(",
"filepath",
"=",
"_give_default_file_path",
"(",
")",
",",
"overwrite",
"=",
"False",
")",
":",
"config",
"=",
"configparser",
".",
"ConfigParser",
"(",
")",
"config",
".",
"read_dict",
"(",
"settings",
")",
"if",
"os",
... | 31.785714 | 0.001091 |
def spawnProcess(processProtocol, executable, args=(), env={},
path=None, uid=None, gid=None, usePTY=0,
packages=()):
"""Launch a process with a particular Python environment.
All arguments as to reactor.spawnProcess(), except for the
addition of an optional packages itera... | [
"def",
"spawnProcess",
"(",
"processProtocol",
",",
"executable",
",",
"args",
"=",
"(",
")",
",",
"env",
"=",
"{",
"}",
",",
"path",
"=",
"None",
",",
"uid",
"=",
"None",
",",
"gid",
"=",
"None",
",",
"usePTY",
"=",
"0",
",",
"packages",
"=",
"(... | 36.64 | 0.001064 |
def FieldDefinitionProtosFromTuples(field_def_tuples):
"""Converts (field-name, type) tuples to MetricFieldDefinition protos."""
# TODO: This needs fixing for Python 3.
field_def_protos = []
for field_name, field_type in field_def_tuples:
if field_type in (int, long):
field_type = rdf_stats.MetricFiel... | [
"def",
"FieldDefinitionProtosFromTuples",
"(",
"field_def_tuples",
")",
":",
"# TODO: This needs fixing for Python 3.",
"field_def_protos",
"=",
"[",
"]",
"for",
"field_name",
",",
"field_type",
"in",
"field_def_tuples",
":",
"if",
"field_type",
"in",
"(",
"int",
",",
... | 44.133333 | 0.013314 |
def bokeh_tree(name, rawtext, text, lineno, inliner, options=None, content=None):
''' Link to a URL in the Bokeh GitHub tree, pointing to appropriate tags
for releases, or to master otherwise.
The link text is simply the URL path supplied, so typical usage might
look like:
.. code-block:: none
... | [
"def",
"bokeh_tree",
"(",
"name",
",",
"rawtext",
",",
"text",
",",
"lineno",
",",
"inliner",
",",
"options",
"=",
"None",
",",
"content",
"=",
"None",
")",
":",
"app",
"=",
"inliner",
".",
"document",
".",
"settings",
".",
"env",
".",
"app",
"tag",
... | 31.357143 | 0.00221 |
def upload_and_update(path, token, cleanup):
"""
The egg that the provided path points to will be uploaded to Databricks.
All jobs which use the same major version of the library will be updated
to use the new version, and all version of this library in the production
folder with the same major v... | [
"def",
"upload_and_update",
"(",
"path",
",",
"token",
",",
"cleanup",
")",
":",
"config",
"=",
"_load_config",
"(",
"CFG_FILE",
")",
"token",
"=",
"_resolve_input",
"(",
"token",
",",
"'token'",
",",
"'token'",
",",
"config",
")",
"folder",
"=",
"_resolve... | 36.857143 | 0.000944 |
def main(_):
"""Create or load configuration and launch the trainer."""
utility.set_up_logging()
if not FLAGS.config:
raise KeyError('You must specify a configuration.')
logdir = FLAGS.logdir and os.path.expanduser(os.path.join(
FLAGS.logdir, '{}-{}'.format(FLAGS.timestamp, FLAGS.config)))
try:
... | [
"def",
"main",
"(",
"_",
")",
":",
"utility",
".",
"set_up_logging",
"(",
")",
"if",
"not",
"FLAGS",
".",
"config",
":",
"raise",
"KeyError",
"(",
"'You must specify a configuration.'",
")",
"logdir",
"=",
"FLAGS",
".",
"logdir",
"and",
"os",
".",
"path",
... | 40.714286 | 0.013722 |
def recurrence(self, recurrence):
"""See `recurrence`."""
if not is_valid_recurrence(recurrence):
raise KeyError("'%s' is not a valid recurrence value" % recurrence)
self._recurrence = recurrence | [
"def",
"recurrence",
"(",
"self",
",",
"recurrence",
")",
":",
"if",
"not",
"is_valid_recurrence",
"(",
"recurrence",
")",
":",
"raise",
"KeyError",
"(",
"\"'%s' is not a valid recurrence value\"",
"%",
"recurrence",
")",
"self",
".",
"_recurrence",
"=",
"recurren... | 37.833333 | 0.008621 |
def functions(self):
"""
A list of functions declared or defined in this module.
"""
return [v for v in self.globals.values()
if isinstance(v, values.Function)] | [
"def",
"functions",
"(",
"self",
")",
":",
"return",
"[",
"v",
"for",
"v",
"in",
"self",
".",
"globals",
".",
"values",
"(",
")",
"if",
"isinstance",
"(",
"v",
",",
"values",
".",
"Function",
")",
"]"
] | 33.833333 | 0.009615 |
def egg_info_matches(
egg_info, search_name, link,
_egg_info_re=re.compile(r'([a-z0-9_.]+)-([a-z0-9_.!+-]+)', re.I)):
"""Pull the version part out of a string.
:param egg_info: The string to parse. E.g. foo-2.1
:param search_name: The name of the package this belongs to. None to
inf... | [
"def",
"egg_info_matches",
"(",
"egg_info",
",",
"search_name",
",",
"link",
",",
"_egg_info_re",
"=",
"re",
".",
"compile",
"(",
"r'([a-z0-9_.]+)-([a-z0-9_.!+-]+)'",
",",
"re",
".",
"I",
")",
")",
":",
"match",
"=",
"_egg_info_re",
".",
"search",
"(",
"egg_... | 40.481481 | 0.001787 |
def save_session(fname=None, session=None, pickleProto=-1):
"""Save current Scapy session to the file specified in the fname arg.
params:
- fname: file to save the scapy session in
- session: scapy session to use. If None, the console one will be used
- pickleProto: pickle proto version (default... | [
"def",
"save_session",
"(",
"fname",
"=",
"None",
",",
"session",
"=",
"None",
",",
"pickleProto",
"=",
"-",
"1",
")",
":",
"from",
"scapy",
"import",
"utils",
"if",
"fname",
"is",
"None",
":",
"fname",
"=",
"conf",
".",
"session",
"if",
"not",
"fnam... | 34.090909 | 0.000648 |
def recover(self, data, redis=None):
''' Retrieve this field's value from the database '''
value = data.get(self.name)
if value is None or value == 'None':
return None
return str(value) | [
"def",
"recover",
"(",
"self",
",",
"data",
",",
"redis",
"=",
"None",
")",
":",
"value",
"=",
"data",
".",
"get",
"(",
"self",
".",
"name",
")",
"if",
"value",
"is",
"None",
"or",
"value",
"==",
"'None'",
":",
"return",
"None",
"return",
"str",
... | 28 | 0.008658 |
def updateWritingTone(user, writingTone, maintainHistory):
"""
updateWritingTone updates the user with the writing tones interpreted based
on the specified thresholds
@param: user a json object representing user information (tone) to be used
in conversing with the Conversation Service
@param: wr... | [
"def",
"updateWritingTone",
"(",
"user",
",",
"writingTone",
",",
"maintainHistory",
")",
":",
"currentWriting",
"=",
"[",
"]",
"currentWritingObject",
"=",
"[",
"]",
"# Process each writing tone and determine if it is high or low",
"for",
"tone",
"in",
"writingTone",
"... | 41.025 | 0.000595 |
def dechunk(stream):
"""De-chunk HTTP body stream.
:param file stream: readable file-like object.
:rtype: __generator[bytes]
:raise: DechunkError
"""
# TODO(vovan): Add support for chunk extensions:
# TODO(vovan): http://tools.ietf.org/html/rfc2616#section-3.6.1
while True:
c... | [
"def",
"dechunk",
"(",
"stream",
")",
":",
"# TODO(vovan): Add support for chunk extensions:",
"# TODO(vovan): http://tools.ietf.org/html/rfc2616#section-3.6.1",
"while",
"True",
":",
"chunk_len",
"=",
"read_until",
"(",
"stream",
",",
"b'\\r\\n'",
")",
"if",
"chunk_len",
"... | 27.540541 | 0.000948 |
def create_shepherd_tour(self, name=None, theme=None):
""" Creates a Shepherd JS website tour.
@Params
name - If creating multiple tours at the same time,
use this to select the tour you wish to add steps to.
theme - Sets the default theme for the tour.
... | [
"def",
"create_shepherd_tour",
"(",
"self",
",",
"name",
"=",
"None",
",",
"theme",
"=",
"None",
")",
":",
"shepherd_theme",
"=",
"\"shepherd-theme-arrows\"",
"if",
"theme",
":",
"if",
"theme",
".",
"lower",
"(",
")",
"==",
"\"default\"",
":",
"shepherd_them... | 37.616667 | 0.000864 |
def measure_topology(fbasename=None, log=None, ml_version=ml_version):
"""Measures mesh topology
Args:
fbasename (str): input filename.
log (str): filename to log output
Returns:
dict: dictionary with the following keys:
vert_num (int): number of vertices
ed... | [
"def",
"measure_topology",
"(",
"fbasename",
"=",
"None",
",",
"log",
"=",
"None",
",",
"ml_version",
"=",
"ml_version",
")",
":",
"ml_script1_file",
"=",
"'TEMP3D_measure_topology.mlx'",
"ml_script1",
"=",
"mlx",
".",
"FilterScript",
"(",
"file_in",
"=",
"fbase... | 44.419355 | 0.000711 |
def all(self):
""" Returns a list of all :class:`~plexapi.settings.Setting` objects available. """
return list(v for id, v in sorted(self._settings.items())) | [
"def",
"all",
"(",
"self",
")",
":",
"return",
"list",
"(",
"v",
"for",
"id",
",",
"v",
"in",
"sorted",
"(",
"self",
".",
"_settings",
".",
"items",
"(",
")",
")",
")"
] | 57 | 0.017341 |
def median_grouped(name, num, minimum=0, maximum=0, ref=None):
'''
Calculates the grouped mean of the ``num`` most recent values. Requires a
list.
USAGE:
.. code-block:: yaml
foo:
calc.median_grouped:
- name: myregentry
- num: 5
'''
return calc(
... | [
"def",
"median_grouped",
"(",
"name",
",",
"num",
",",
"minimum",
"=",
"0",
",",
"maximum",
"=",
"0",
",",
"ref",
"=",
"None",
")",
":",
"return",
"calc",
"(",
"name",
"=",
"name",
",",
"num",
"=",
"num",
",",
"oper",
"=",
"'median_grouped'",
",",
... | 19.818182 | 0.002188 |
def unlock(self):
"""Unlock this Workspace."""
r = fapi.unlock_workspace(self.namespace, self.name, self.api_url)
fapi._check_response_code(r, 204)
self.data['workspace']['isLocked'] = False
return self | [
"def",
"unlock",
"(",
"self",
")",
":",
"r",
"=",
"fapi",
".",
"unlock_workspace",
"(",
"self",
".",
"namespace",
",",
"self",
".",
"name",
",",
"self",
".",
"api_url",
")",
"fapi",
".",
"_check_response_code",
"(",
"r",
",",
"204",
")",
"self",
".",... | 39.5 | 0.008264 |
def update_watch(self, wd, mask=None, proc_fun=None, rec=False,
auto_add=False, quiet=True):
"""
Update existing watch descriptors |wd|. The |mask| value, the
processing object |proc_fun|, the recursive param |rec| and the
|auto_add| and |quiet| flags can all be upda... | [
"def",
"update_watch",
"(",
"self",
",",
"wd",
",",
"mask",
"=",
"None",
",",
"proc_fun",
"=",
"None",
",",
"rec",
"=",
"False",
",",
"auto_add",
"=",
"False",
",",
"quiet",
"=",
"True",
")",
":",
"lwd",
"=",
"self",
".",
"__format_param",
"(",
"wd... | 40.394366 | 0.001702 |
def _load(stream, container, sep=_SEP, dkey=DEFAULTSECT, **kwargs):
"""
:param stream: File or file-like object provides ini-style conf
:param container: any callable to make container
:param sep: Seprator string
:param dkey: Default section name
:return: Dict or dict-like object represents con... | [
"def",
"_load",
"(",
"stream",
",",
"container",
",",
"sep",
"=",
"_SEP",
",",
"dkey",
"=",
"DEFAULTSECT",
",",
"*",
"*",
"kwargs",
")",
":",
"(",
"kwargs_1",
",",
"psr",
")",
"=",
"_make_parser",
"(",
"*",
"*",
"kwargs",
")",
"if",
"IS_PYTHON_3",
... | 29.269231 | 0.001272 |
def list_operations(self, name, filter_, page_size=0, options=None):
"""
Lists operations that match the specified filter in the request. If the
server doesn't support this method, it returns ``UNIMPLEMENTED``.
NOTE: the ``name`` binding below allows API services to override the binding
... | [
"def",
"list_operations",
"(",
"self",
",",
"name",
",",
"filter_",
",",
"page_size",
"=",
"0",
",",
"options",
"=",
"None",
")",
":",
"# Create the request object.",
"request",
"=",
"operations_pb2",
".",
"ListOperationsRequest",
"(",
"name",
"=",
"name",
","... | 47.06 | 0.002082 |
def prepare(self):
"""No percolator XML for protein tables"""
self.target = self.fn
self.targetheader = reader.get_tsv_header(self.target)
self.decoyheader = reader.get_tsv_header(self.decoyfn) | [
"def",
"prepare",
"(",
"self",
")",
":",
"self",
".",
"target",
"=",
"self",
".",
"fn",
"self",
".",
"targetheader",
"=",
"reader",
".",
"get_tsv_header",
"(",
"self",
".",
"target",
")",
"self",
".",
"decoyheader",
"=",
"reader",
".",
"get_tsv_header",
... | 44.2 | 0.008889 |
def batch(iterable, n, fillvalue=None):
"""Batches the elements of given iterable.
Resulting iterable will yield tuples containing at most ``n`` elements
(might be less if ``fillvalue`` isn't specified).
:param n: Number of items in every batch
:param fillvalue: Value to fill the last batch with. ... | [
"def",
"batch",
"(",
"iterable",
",",
"n",
",",
"fillvalue",
"=",
"None",
")",
":",
"ensure_iterable",
"(",
"iterable",
")",
"if",
"not",
"isinstance",
"(",
"n",
",",
"Integral",
")",
":",
"raise",
"TypeError",
"(",
"\"invalid number of elements in a batch\"",... | 35.314286 | 0.001575 |
def UpdateArpeggiates(self, type="start"):
'''
method which searches for all arpeggiates and updates the top one of each chord to be a start,
and the bottom one to be a stop ready for lilypond output
:param type:
:return:
'''
result = self.item.Search(Arpeggiate)
... | [
"def",
"UpdateArpeggiates",
"(",
"self",
",",
"type",
"=",
"\"start\"",
")",
":",
"result",
"=",
"self",
".",
"item",
".",
"Search",
"(",
"Arpeggiate",
")",
"if",
"result",
"is",
"not",
"None",
":",
"if",
"type",
"==",
"\"start\"",
":",
"result",
".",
... | 41.513514 | 0.001908 |
def _pseudodepths_wenner(configs, spacing=1, grid=None):
"""Given distances between electrodes, compute Wenner pseudo
depths for the provided configuration
The pseudodepth is computed after Roy & Apparao, 1971, as 0.11 times
the distance between the two outermost electrodes. It's not really
clear w... | [
"def",
"_pseudodepths_wenner",
"(",
"configs",
",",
"spacing",
"=",
"1",
",",
"grid",
"=",
"None",
")",
":",
"if",
"grid",
"is",
"None",
":",
"xpositions",
"=",
"(",
"configs",
"-",
"1",
")",
"*",
"spacing",
"else",
":",
"xpositions",
"=",
"grid",
".... | 40.105263 | 0.001282 |
def ring(surf, xy, r, width, color):
"""Draws a ring"""
r2 = r - width
x0, y0 = xy
x = r2
y = 0
err = 0
# collect points of the inner circle
right = {}
while x >= y:
right[x] = y
right[y] = x
right[-x] = y
right[-y] = x
y += 1
if er... | [
"def",
"ring",
"(",
"surf",
",",
"xy",
",",
"r",
",",
"width",
",",
"color",
")",
":",
"r2",
"=",
"r",
"-",
"width",
"x0",
",",
"y0",
"=",
"xy",
"x",
"=",
"r2",
"y",
"=",
"0",
"err",
"=",
"0",
"# collect points of the inner circle",
"right",
"=",... | 23.173077 | 0.002389 |
def HKY85(mu=1.0, pi=None, kappa=0.1, **kwargs):
"""
Hasegawa, Kishino and Yano 1985 model. Allows different concentrations of the
nucleotides (as in F81) + distinguishes between transition/transversionsubstitutions
(similar to K80). Link:
Hasegawa, Kishino, Yano (1985), J. Mol. Evol. 22 (2): 160–17... | [
"def",
"HKY85",
"(",
"mu",
"=",
"1.0",
",",
"pi",
"=",
"None",
",",
"kappa",
"=",
"0.1",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"pi",
"is",
"None",
":",
"pi",
"=",
"0.25",
"*",
"np",
".",
"ones",
"(",
"4",
",",
"dtype",
"=",
"float",
")",... | 31.513514 | 0.008319 |
def resolve_variables(self, provided_variables):
"""Resolve the values of the blueprint variables.
This will resolve the values of the template parameters with values
from the env file, the config, and any lookups resolved. The
resolution is run twice, in case the blueprint is jinja2 te... | [
"def",
"resolve_variables",
"(",
"self",
",",
"provided_variables",
")",
":",
"# Pass 1 to set resolved_variables to provided variables",
"self",
".",
"resolved_variables",
"=",
"{",
"}",
"variable_dict",
"=",
"dict",
"(",
"(",
"var",
".",
"name",
",",
"var",
")",
... | 41.722222 | 0.001301 |
def merge_multipartobject(upload_id, version_id=None):
"""Merge multipart object.
:param upload_id: The :class:`invenio_files_rest.models.MultipartObject`
upload ID.
:param version_id: Optionally you can define which file version.
(Default: ``None``)
:returns: The :class:`invenio_files_... | [
"def",
"merge_multipartobject",
"(",
"upload_id",
",",
"version_id",
"=",
"None",
")",
":",
"mp",
"=",
"MultipartObject",
".",
"query",
".",
"filter_by",
"(",
"upload_id",
"=",
"upload_id",
")",
".",
"one_or_none",
"(",
")",
"if",
"not",
"mp",
":",
"raise"... | 32.576923 | 0.001147 |
def get_configs(args, command_args, ansible_args=()):
"""
Glob the current directory for Molecule config files, instantiate config
objects, and returns a list.
:param args: A dict of options, arguments and commands from the CLI.
:param command_args: A dict of options passed to the subcommand from
... | [
"def",
"get_configs",
"(",
"args",
",",
"command_args",
",",
"ansible_args",
"=",
"(",
")",
")",
":",
"configs",
"=",
"[",
"config",
".",
"Config",
"(",
"molecule_file",
"=",
"util",
".",
"abs_path",
"(",
"c",
")",
",",
"args",
"=",
"args",
",",
"com... | 31.478261 | 0.00134 |
def filter_transcription_factor(stmts_in, **kwargs):
"""Filter out RegulateAmounts where subject is not a transcription factor.
Parameters
----------
stmts_in : list[indra.statements.Statement]
A list of statements to filter.
save : Optional[str]
The name of a pickle file to save th... | [
"def",
"filter_transcription_factor",
"(",
"stmts_in",
",",
"*",
"*",
"kwargs",
")",
":",
"logger",
".",
"info",
"(",
"'Filtering %d statements to remove '",
"%",
"len",
"(",
"stmts_in",
")",
"+",
"'amount regulations by non-transcription-factors...'",
")",
"path",
"=... | 35.823529 | 0.000799 |
def create_iam(self):
"""Create IAM resources."""
utils.banner("Creating IAM")
iam.create_iam_resources(env=self.env, app=self.app) | [
"def",
"create_iam",
"(",
"self",
")",
":",
"utils",
".",
"banner",
"(",
"\"Creating IAM\"",
")",
"iam",
".",
"create_iam_resources",
"(",
"env",
"=",
"self",
".",
"env",
",",
"app",
"=",
"self",
".",
"app",
")"
] | 38 | 0.012903 |
def create(vm_):
'''
Create a single VM from a data dict
'''
try:
# Check for required profile parameters before sending any API calls.
if vm_['profile'] and config.is_profile_configured(__opts__,
__active_provider_name__ or 'clo... | [
"def",
"create",
"(",
"vm_",
")",
":",
"try",
":",
"# Check for required profile parameters before sending any API calls.",
"if",
"vm_",
"[",
"'profile'",
"]",
"and",
"config",
".",
"is_profile_configured",
"(",
"__opts__",
",",
"__active_provider_name__",
"or",
"'cloud... | 36.391566 | 0.00145 |
def getRectArea(*args):
"""Calculate area of rectangle.\nparameter is one of 'px' (default), 'in', 'cm', or 'mm'."""
rect = args[0]
if len(args) > 1:
unit = args[1]
else:
unit = "px"
u = {"px": (1,1), "in": (1.,72.), "cm": (2.54, 72.), "mm": (25.4, 72.)}
f = (u[unit][0] / u[u... | [
"def",
"getRectArea",
"(",
"*",
"args",
")",
":",
"rect",
"=",
"args",
"[",
"0",
"]",
"if",
"len",
"(",
"args",
")",
">",
"1",
":",
"unit",
"=",
"args",
"[",
"1",
"]",
"else",
":",
"unit",
"=",
"\"px\"",
"u",
"=",
"{",
"\"px\"",
":",
"(",
"... | 36.2 | 0.013477 |
def estimategaps(args):
"""
%prog estimategaps JM-4 chr1 JMMale-1
Illustrate ALLMAPS gap estimation algorithm.
"""
p = OptionParser(estimategaps.__doc__)
opts, args, iopts = p.set_image_options(args, figsize="6x6", dpi=300)
if len(args) != 3:
sys.exit(not p.print_help())
pf, s... | [
"def",
"estimategaps",
"(",
"args",
")",
":",
"p",
"=",
"OptionParser",
"(",
"estimategaps",
".",
"__doc__",
")",
"opts",
",",
"args",
",",
"iopts",
"=",
"p",
".",
"set_image_options",
"(",
"args",
",",
"figsize",
"=",
"\"6x6\"",
",",
"dpi",
"=",
"300"... | 34.982609 | 0.002175 |
def get_value(value_proto):
"""Gets the python object equivalent for the given value proto.
Args:
value_proto: datastore.Value proto message.
Returns:
the corresponding python object value. timestamps are converted to
datetime, and datastore.Value is returned for blob_key_value.
"""
field = valu... | [
"def",
"get_value",
"(",
"value_proto",
")",
":",
"field",
"=",
"value_proto",
".",
"WhichOneof",
"(",
"'value_type'",
")",
"if",
"field",
"in",
"__native_value_types",
":",
"return",
"getattr",
"(",
"value_proto",
",",
"field",
")",
"if",
"field",
"==",
"'t... | 33.473684 | 0.012232 |
def copy(self, graph):
""" Returns a copy of the event handler, remembering the last node clicked.
"""
e = events(graph, self._ctx)
e.clicked = self.clicked
return e | [
"def",
"copy",
"(",
"self",
",",
"graph",
")",
":",
"e",
"=",
"events",
"(",
"graph",
",",
"self",
".",
"_ctx",
")",
"e",
".",
"clicked",
"=",
"self",
".",
"clicked",
"return",
"e"
] | 26 | 0.023256 |
def get(self, cpfile):
'''This handles a GET request to run a specified LC tool.
Parameters
----------
cpfile : str
This is the checkplot file to run the tool on.
Returns
-------
str
Returns a JSON response.
Notes
-----... | [
"def",
"get",
"(",
"self",
",",
"cpfile",
")",
":",
"if",
"cpfile",
":",
"self",
".",
"cpfile",
"=",
"(",
"xhtml_escape",
"(",
"base64",
".",
"b64decode",
"(",
"url_unescape",
"(",
"cpfile",
")",
")",
")",
")",
"# see if this plot is in the current project",... | 39.720436 | 0.002481 |
def get_client_profile(self, client_id):
"""This fetches a single client record out of DynamoDB
"""
try:
response = self._table.get_item(Key={'client_id': client_id})
compressed_bytes = response['Item']['json_payload'].value
json_byte_data = zlib.decompress(co... | [
"def",
"get_client_profile",
"(",
"self",
",",
"client_id",
")",
":",
"try",
":",
"response",
"=",
"self",
".",
"_table",
".",
"get_item",
"(",
"Key",
"=",
"{",
"'client_id'",
":",
"client_id",
"}",
")",
"compressed_bytes",
"=",
"response",
"[",
"'Item'",
... | 45.111111 | 0.002413 |
def recorddiff(a, b, buffersize=None, tempdir=None, cache=True, strict=False):
"""
Find the difference between records in two tables. E.g.::
>>> import petl as etl
>>> a = [['foo', 'bar', 'baz'],
... ['A', 1, True],
... ['C', 7, False],
... ['B', 2, False]... | [
"def",
"recorddiff",
"(",
"a",
",",
"b",
",",
"buffersize",
"=",
"None",
",",
"tempdir",
"=",
"None",
",",
"cache",
"=",
"True",
",",
"strict",
"=",
"False",
")",
":",
"added",
"=",
"recordcomplement",
"(",
"b",
",",
"a",
",",
"buffersize",
"=",
"b... | 32.538462 | 0.000574 |
async def make_request(self, service: str, method: str, path: str,
body: bytes=None, query: str=None,
headers: dict=None, correlation_id: str=None,
content_type: str=None,
timeout:int = 30,
... | [
"async",
"def",
"make_request",
"(",
"self",
",",
"service",
":",
"str",
",",
"method",
":",
"str",
",",
"path",
":",
"str",
",",
"body",
":",
"bytes",
"=",
"None",
",",
"query",
":",
"str",
"=",
"None",
",",
"headers",
":",
"dict",
"=",
"None",
... | 49.125 | 0.015807 |
def _determine_host(data, omit=''):
'''
Determine what the most resource free host is based on the given data
'''
# This is just checking for the host with the most free ram, this needs
# to be much more complicated.
host = ''
bestmem = 0
for hv_, comps in six.iteritems(data):
if... | [
"def",
"_determine_host",
"(",
"data",
",",
"omit",
"=",
"''",
")",
":",
"# This is just checking for the host with the most free ram, this needs",
"# to be much more complicated.",
"host",
"=",
"''",
"bestmem",
"=",
"0",
"for",
"hv_",
",",
"comps",
"in",
"six",
".",
... | 30.764706 | 0.001855 |
def load_mod(module, package):
""" Load a module named ``module`` from given search``path``
The module path prefix is set according to the ``prefix`` argument.
By defualt the module is loaded as if it comes from a global
'db_migrations' package. As such, it may conflict with any 'db_migration'
pac... | [
"def",
"load_mod",
"(",
"module",
",",
"package",
")",
":",
"name",
"=",
"'%s.%s'",
"%",
"(",
"package",
".",
"__name__",
",",
"module",
")",
"if",
"name",
"in",
"sys",
".",
"modules",
":",
"return",
"sys",
".",
"modules",
"[",
"name",
"]",
"return",... | 43.619048 | 0.001068 |
def getMySavedQueries(self, projectarea_id=None, projectarea_name=None,
saved_query_name=None):
"""Get all saved queries created by me in a certain project
area (optional, either `projectarea_id` or `projectarea_name` is
needed if specified)
Note: only if mysel... | [
"def",
"getMySavedQueries",
"(",
"self",
",",
"projectarea_id",
"=",
"None",
",",
"projectarea_name",
"=",
"None",
",",
"saved_query_name",
"=",
"None",
")",
":",
"self",
".",
"log",
".",
"info",
"(",
"\"Start to fetch my saved queries\"",
")",
"return",
"self",... | 48.214286 | 0.002179 |
def _bits_to_float(bits, lower=-90.0, middle=0.0, upper=90.0):
"""Convert GeoHash bits to a float."""
for i in bits:
if i:
lower = middle
else:
upper = middle
middle = (upper + lower) / 2
return middle | [
"def",
"_bits_to_float",
"(",
"bits",
",",
"lower",
"=",
"-",
"90.0",
",",
"middle",
"=",
"0.0",
",",
"upper",
"=",
"90.0",
")",
":",
"for",
"i",
"in",
"bits",
":",
"if",
"i",
":",
"lower",
"=",
"middle",
"else",
":",
"upper",
"=",
"middle",
"mid... | 24.777778 | 0.025974 |
def rewrite_properties(self, properties):
"""Set the properties and write to disk."""
with self.__library_storage_lock:
self.__library_storage = properties
self.__write_properties(None) | [
"def",
"rewrite_properties",
"(",
"self",
",",
"properties",
")",
":",
"with",
"self",
".",
"__library_storage_lock",
":",
"self",
".",
"__library_storage",
"=",
"properties",
"self",
".",
"__write_properties",
"(",
"None",
")"
] | 43.4 | 0.00905 |
def GetUserInfo(knowledge_base, user):
# TODO: This docstring cannot be a raw literal because there are
# issues with raw unicode literals on Python 2. Once support for Python 2 is
# dropped, it can be made raw again.
# pylint: disable=g-docstring-has-escape
"""Get a User protobuf for a specific user.
Args... | [
"def",
"GetUserInfo",
"(",
"knowledge_base",
",",
"user",
")",
":",
"# TODO: This docstring cannot be a raw literal because there are",
"# issues with raw unicode literals on Python 2. Once support for Python 2 is",
"# dropped, it can be made raw again.",
"# pylint: disable=g-docstring-has-esc... | 29.035714 | 0.013095 |
def _find_resp(station, channel, network, time, delta, directory):
"""
Helper function to find the response information.
Works for a given station and channel at a given time and return a
dictionary of poles and zeros, gain and sensitivity.
:type station: str
:param station: Station name (as i... | [
"def",
"_find_resp",
"(",
"station",
",",
"channel",
",",
"network",
",",
"time",
",",
"delta",
",",
"directory",
")",
":",
"possible_respfiles",
"=",
"glob",
".",
"glob",
"(",
"directory",
"+",
"os",
".",
"path",
".",
"sep",
"+",
"'RESP.'",
"+",
"netw... | 43.395062 | 0.000556 |
def restart_with_reloader(self):
"""Spawn a new Python interpreter with the same arguments as this one,
but running the reloader thread.
"""
while 1:
_log("info", " * Restarting with %s" % self.name)
args = _get_args_for_reloading()
# a weird bug on w... | [
"def",
"restart_with_reloader",
"(",
"self",
")",
":",
"while",
"1",
":",
"_log",
"(",
"\"info\"",
",",
"\" * Restarting with %s\"",
"%",
"self",
".",
"name",
")",
"args",
"=",
"_get_args_for_reloading",
"(",
")",
"# a weird bug on windows. sometimes unicode strings e... | 42.923077 | 0.001753 |
def swapoff(name):
'''
Deactivate a named swap mount
.. versionchanged:: 2016.3.2
CLI Example:
.. code-block:: bash
salt '*' mount.swapoff /root/swapfile
'''
on_ = swaps()
if name in on_:
if __grains__['kernel'] == 'SunOS':
if __grains__['virtual'] != 'zon... | [
"def",
"swapoff",
"(",
"name",
")",
":",
"on_",
"=",
"swaps",
"(",
")",
"if",
"name",
"in",
"on_",
":",
"if",
"__grains__",
"[",
"'kernel'",
"]",
"==",
"'SunOS'",
":",
"if",
"__grains__",
"[",
"'virtual'",
"]",
"!=",
"'zone'",
":",
"__salt__",
"[",
... | 27.103448 | 0.002457 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.