text stringlengths 75 104k | code_tokens list | avg_line_len float64 7.91 980 | score float64 0 0.18 |
|---|---|---|---|
def perform_iteration(self):
"""Get any changes to the log files and push updates to Redis."""
stats = self.get_all_stats()
self.redis_client.publish(
self.redis_key,
jsonify_asdict(stats),
) | [
"def",
"perform_iteration",
"(",
"self",
")",
":",
"stats",
"=",
"self",
".",
"get_all_stats",
"(",
")",
"self",
".",
"redis_client",
".",
"publish",
"(",
"self",
".",
"redis_key",
",",
"jsonify_asdict",
"(",
"stats",
")",
",",
")"
] | 30.125 | 0.008065 |
def get(args):
"""Retrieve records.
Argument:
args: arguments object
"""
password = get_password(args)
token = connect.get_token(args.username, password, args.server)
if args.__dict__.get('search'):
# When using '--search' option
keyword = args.search
else:
... | [
"def",
"get",
"(",
"args",
")",
":",
"password",
"=",
"get_password",
"(",
"args",
")",
"token",
"=",
"connect",
".",
"get_token",
"(",
"args",
".",
"username",
",",
"password",
",",
"args",
".",
"server",
")",
"if",
"args",
".",
"__dict__",
".",
"ge... | 22.6875 | 0.001321 |
def extension(self, value):
"""
Setter for **self.__extension** attribute.
:param value: Attribute value.
:type value: unicode
"""
if value is not None:
assert type(value) is unicode, "'{0}' attribute: '{1}' type is not 'unicode'!".format(
"e... | [
"def",
"extension",
"(",
"self",
",",
"value",
")",
":",
"if",
"value",
"is",
"not",
"None",
":",
"assert",
"type",
"(",
"value",
")",
"is",
"unicode",
",",
"\"'{0}' attribute: '{1}' type is not 'unicode'!\"",
".",
"format",
"(",
"\"extension\"",
",",
"value",... | 29.916667 | 0.008108 |
def add_note(self, note):
"""Add a note to the selected tracks.
Everything container.Track supports in __add__ is accepted.
"""
for n in self.selected_tracks:
self.tracks[n] + note | [
"def",
"add_note",
"(",
"self",
",",
"note",
")",
":",
"for",
"n",
"in",
"self",
".",
"selected_tracks",
":",
"self",
".",
"tracks",
"[",
"n",
"]",
"+",
"note"
] | 31.285714 | 0.008889 |
def _bits_to_geohash(value):
"""Convert a list of GeoHash bits to a GeoHash."""
ret = []
# Get 5 bits at a time
for i in (value[i:i+5] for i in xrange(0, len(value), 5)):
# Convert binary to integer
# Note: reverse here, the slice above doesn't work quite right in reverse.
total = sum([(bit*2**count... | [
"def",
"_bits_to_geohash",
"(",
"value",
")",
":",
"ret",
"=",
"[",
"]",
"# Get 5 bits at a time",
"for",
"i",
"in",
"(",
"value",
"[",
"i",
":",
"i",
"+",
"5",
"]",
"for",
"i",
"in",
"xrange",
"(",
"0",
",",
"len",
"(",
"value",
")",
",",
"5",
... | 39.636364 | 0.017937 |
def facet_search(cls, *facets):
'''
Build a FacetSearch for a given list of facets
Elasticsearch DSL doesn't allow to list facets
once and for all and then later select them.
They are always all requested
As we don't use them every time and facet computation
can... | [
"def",
"facet_search",
"(",
"cls",
",",
"*",
"facets",
")",
":",
"f",
"=",
"dict",
"(",
"(",
"k",
",",
"v",
")",
"for",
"k",
",",
"v",
"in",
"cls",
".",
"facets",
".",
"items",
"(",
")",
"if",
"k",
"in",
"facets",
")",
"class",
"TempSearch",
... | 31.384615 | 0.002378 |
def _tp_cache(func):
"""Internal wrapper caching __getitem__ of generic types with a fallback to
original function for non-hashable arguments.
"""
cached = functools.lru_cache()(func)
_cleanups.append(cached.cache_clear)
@functools.wraps(func)
def inner(*args, **kwds):
try:
... | [
"def",
"_tp_cache",
"(",
"func",
")",
":",
"cached",
"=",
"functools",
".",
"lru_cache",
"(",
")",
"(",
"func",
")",
"_cleanups",
".",
"append",
"(",
"cached",
".",
"cache_clear",
")",
"@",
"functools",
".",
"wraps",
"(",
"func",
")",
"def",
"inner",
... | 28.941176 | 0.001969 |
def redirect(where: Optional[str] = None,
default: Optional[str] = None,
override: Optional[str] = None,
_anchor: Optional[str] = None,
_cls: Optional[Union[object, type]] = None,
_external: Optional[bool] = False,
_external_host: Optional[st... | [
"def",
"redirect",
"(",
"where",
":",
"Optional",
"[",
"str",
"]",
"=",
"None",
",",
"default",
":",
"Optional",
"[",
"str",
"]",
"=",
"None",
",",
"override",
":",
"Optional",
"[",
"str",
"]",
"=",
"None",
",",
"_anchor",
":",
"Optional",
"[",
"st... | 50.207547 | 0.000369 |
async def apply_json(self, data):
"""Apply a JSON data object for a service
"""
if not isinstance(data, list):
data = [data]
result = []
for entry in data:
if not isinstance(entry, dict):
raise KongError('dictionary required')
e... | [
"async",
"def",
"apply_json",
"(",
"self",
",",
"data",
")",
":",
"if",
"not",
"isinstance",
"(",
"data",
",",
"list",
")",
":",
"data",
"=",
"[",
"data",
"]",
"result",
"=",
"[",
"]",
"for",
"entry",
"in",
"data",
":",
"if",
"not",
"isinstance",
... | 40.088235 | 0.001433 |
def synchronize_task(self, func, *args, **kwargs):
"""Run callable in the rpc thread and wait for it to finish.
The callable ``func`` will be passed into the EmulationLoop and run
there. This method will block until ``func`` is finished and
return/raise whatever that callable returns/r... | [
"def",
"synchronize_task",
"(",
"self",
",",
"func",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"async",
"def",
"_runner",
"(",
")",
":",
"return",
"func",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
"return",
"self",
".",
"emulator",... | 40.142857 | 0.001738 |
def expand(self):
"""Expand out all operator expressions within S, L and H
Return a new :class:`SLH` object with these expanded expressions.
"""
return SLH(self.S.expand(), self.L.expand(), self.H.expand()) | [
"def",
"expand",
"(",
"self",
")",
":",
"return",
"SLH",
"(",
"self",
".",
"S",
".",
"expand",
"(",
")",
",",
"self",
".",
"L",
".",
"expand",
"(",
")",
",",
"self",
".",
"H",
".",
"expand",
"(",
")",
")"
] | 39 | 0.008368 |
def unirange(a, b):
"""Returns a regular expression string to match the given non-BMP range."""
if b < a:
raise ValueError("Bad character range")
if a < 0x10000 or b < 0x10000:
raise ValueError("unirange is only defined for non-BMP ranges")
if sys.maxunicode > 0xffff:
# wide bui... | [
"def",
"unirange",
"(",
"a",
",",
"b",
")",
":",
"if",
"b",
"<",
"a",
":",
"raise",
"ValueError",
"(",
"\"Bad character range\"",
")",
"if",
"a",
"<",
"0x10000",
"or",
"b",
"<",
"0x10000",
":",
"raise",
"ValueError",
"(",
"\"unirange is only defined for no... | 42.783784 | 0.001235 |
def connection_key(self):
"""
Return an index key used to cache the sampler connection.
"""
return "{host}:{namespace}:{username}".format(host=self.host, namespace=self.namespace, username=self.username) | [
"def",
"connection_key",
"(",
"self",
")",
":",
"return",
"\"{host}:{namespace}:{username}\"",
".",
"format",
"(",
"host",
"=",
"self",
".",
"host",
",",
"namespace",
"=",
"self",
".",
"namespace",
",",
"username",
"=",
"self",
".",
"username",
")"
] | 46.2 | 0.012766 |
def update_options(self, kwargs_model, kwargs_constraints, kwargs_likelihood):
"""
updates the options by overwriting the kwargs with the new ones being added/changed
WARNING: some updates may not be valid depending on the model options. Use carefully!
:param kwargs_model:
:para... | [
"def",
"update_options",
"(",
"self",
",",
"kwargs_model",
",",
"kwargs_constraints",
",",
"kwargs_likelihood",
")",
":",
"kwargs_model_updated",
"=",
"self",
".",
"kwargs_model",
".",
"update",
"(",
"kwargs_model",
")",
"kwargs_constraints_updated",
"=",
"self",
".... | 51.785714 | 0.009485 |
def stop(self):
""" Stop logging with this logger.
"""
if not self.active:
return
self.removeHandler(self.handlers[-1])
self.active = False
return | [
"def",
"stop",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"active",
":",
"return",
"self",
".",
"removeHandler",
"(",
"self",
".",
"handlers",
"[",
"-",
"1",
"]",
")",
"self",
".",
"active",
"=",
"False",
"return"
] | 22.111111 | 0.009662 |
def replacebranch(idf, loop, branch,
listofcomponents, fluid=None,
debugsave=False,
testing=None):
"""It will replace the components in the branch with components in
listofcomponents"""
if fluid is None:
fluid = ''
# -------- testing --------... | [
"def",
"replacebranch",
"(",
"idf",
",",
"loop",
",",
"branch",
",",
"listofcomponents",
",",
"fluid",
"=",
"None",
",",
"debugsave",
"=",
"False",
",",
"testing",
"=",
"None",
")",
":",
"if",
"fluid",
"is",
"None",
":",
"fluid",
"=",
"''",
"# --------... | 36.137931 | 0.001703 |
def debug_contents(self, indent=1, file=sys.stdout, _ids=None):
"""Print out interesting things about the object."""
klasses = list(self.__class__.__mro__)
klasses.reverse()
# print special attributes "bottom up"
previous_attrs = ()
for c in klasses:
attrs = ... | [
"def",
"debug_contents",
"(",
"self",
",",
"indent",
"=",
"1",
",",
"file",
"=",
"sys",
".",
"stdout",
",",
"_ids",
"=",
"None",
")",
":",
"klasses",
"=",
"list",
"(",
"self",
".",
"__class__",
".",
"__mro__",
")",
"klasses",
".",
"reverse",
"(",
"... | 39.25 | 0.002486 |
def get_as_array(self, key):
"""
Converts map element into an AnyValueMap or returns empty AnyValueMap if conversion is not possible.
:param key: an index of element to get.
:return: AnyValueMap value of the element or empty AnyValueMap if conversion is not supported.
"""
... | [
"def",
"get_as_array",
"(",
"self",
",",
"key",
")",
":",
"value",
"=",
"self",
".",
"get",
"(",
"key",
")",
"return",
"AnyValueMap",
".",
"from_value",
"(",
"value",
")"
] | 38 | 0.010283 |
def send_point_data(events, additional):
"""creates data point payloads and sends them to influxdb
"""
bodies = {}
for (site, content_id), count in events.items():
if not len(site) or not len(content_id):
continue
# influxdb will take an array of arrays of values, cutting do... | [
"def",
"send_point_data",
"(",
"events",
",",
"additional",
")",
":",
"bodies",
"=",
"{",
"}",
"for",
"(",
"site",
",",
"content_id",
")",
",",
"count",
"in",
"events",
".",
"items",
"(",
")",
":",
"if",
"not",
"len",
"(",
"site",
")",
"or",
"not",... | 33.275862 | 0.002014 |
def enqueue(self, obj, *args, **kwargs):
"""Enqueue a function call or :doc:`job` instance.
:param func: Function or :doc:`job <job>`. Must be serializable and
importable by :doc:`worker <worker>` processes.
:type func: callable | :doc:`kq.Job <job>`
:param args: Positional ... | [
"def",
"enqueue",
"(",
"self",
",",
"obj",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"timestamp",
"=",
"int",
"(",
"time",
".",
"time",
"(",
")",
"*",
"1000",
")",
"if",
"isinstance",
"(",
"obj",
",",
"Job",
")",
":",
"job_id",
"=",
... | 39.590164 | 0.000808 |
def comment_stream(reddit_session, subreddit, limit=None, verbosity=1):
"""Indefinitely yield new comments from the provided subreddit.
Comments are yielded from oldest to newest.
:param reddit_session: The reddit_session to make requests from. In all the
examples this is assigned to the variable ... | [
"def",
"comment_stream",
"(",
"reddit_session",
",",
"subreddit",
",",
"limit",
"=",
"None",
",",
"verbosity",
"=",
"1",
")",
":",
"get_function",
"=",
"partial",
"(",
"reddit_session",
".",
"get_comments",
",",
"six",
".",
"text_type",
"(",
"subreddit",
")"... | 54.12 | 0.000726 |
def get_base_level(text, upper_is_rtl=False):
"""Get the paragraph base embedding level. Returns 0 for LTR,
1 for RTL.
`text` a unicode object.
Set `upper_is_rtl` to True to treat upper case chars as strong 'R'
for debugging (default: False).
"""
base_level = None
prev_surrogate = F... | [
"def",
"get_base_level",
"(",
"text",
",",
"upper_is_rtl",
"=",
"False",
")",
":",
"base_level",
"=",
"None",
"prev_surrogate",
"=",
"False",
"# P2",
"for",
"_ch",
"in",
"text",
":",
"# surrogate in case of ucs2",
"if",
"_IS_UCS2",
"and",
"(",
"_SURROGATE_MIN",
... | 22.25 | 0.000978 |
def get_colors(n):
"""get colors for freqpoly graph"""
cb_palette = ["#E69F00", "#56B4E9", "#009E73", "#F0E442", "#0072B2", "#D55E00",
"#CC79A7","#001F3F", "#0074D9", "#7FDBFF", "#39CCCC", "#3D9970", "#2ECC40",
"#01FF70", "#FFDC00", "#FF851B", "#FF4136", "#F0... | [
"def",
"get_colors",
"(",
"n",
")",
":",
"cb_palette",
"=",
"[",
"\"#E69F00\"",
",",
"\"#56B4E9\"",
",",
"\"#009E73\"",
",",
"\"#F0E442\"",
",",
"\"#0072B2\"",
",",
"\"#D55E00\"",
",",
"\"#CC79A7\"",
",",
"\"#001F3F\"",
",",
"\"#0074D9\"",
",",
"\"#7FDBFF\"",
... | 42.692308 | 0.012346 |
def ensure_row_dep_constraint(
self, M_c, T, X_L, X_D, row1, row2, dependent=True, wrt=None,
max_iter=100, force=False):
"""Ensures dependencey or indepdendency between rows with respect to
columns."""
X_L_list, X_D_list, was_multistate = su.ensure_multistate(X_L, X_D)
... | [
"def",
"ensure_row_dep_constraint",
"(",
"self",
",",
"M_c",
",",
"T",
",",
"X_L",
",",
"X_D",
",",
"row1",
",",
"row2",
",",
"dependent",
"=",
"True",
",",
"wrt",
"=",
"None",
",",
"max_iter",
"=",
"100",
",",
"force",
"=",
"False",
")",
":",
"X_L... | 37 | 0.001386 |
def _parse_ret(func, variables, annotations=None):
"""Parse func's return annotation and return either None, a variable,
or a tuple of variables.
NOTE:
* _parse_ret() also notifies variables about will-writes.
* A variable can be written multiple times per return annotation.
"""
anno = ... | [
"def",
"_parse_ret",
"(",
"func",
",",
"variables",
",",
"annotations",
"=",
"None",
")",
":",
"anno",
"=",
"(",
"annotations",
"or",
"func",
".",
"__annotations__",
")",
".",
"get",
"(",
"'return'",
")",
"if",
"anno",
"is",
"None",
":",
"return",
"Non... | 37.416667 | 0.001086 |
def _configMailer(self):
""" Config Mailer Class """
self._MAILER = Mailer(self.MAILER_HOST, self.MAILER_PORT)
self._MAILER.login(self.MAILER_USER, self.MAILER_PWD) | [
"def",
"_configMailer",
"(",
"self",
")",
":",
"self",
".",
"_MAILER",
"=",
"Mailer",
"(",
"self",
".",
"MAILER_HOST",
",",
"self",
".",
"MAILER_PORT",
")",
"self",
".",
"_MAILER",
".",
"login",
"(",
"self",
".",
"MAILER_USER",
",",
"self",
".",
"MAILE... | 46.25 | 0.010638 |
def staff_products_form_factory(user):
''' Creates a StaffProductsForm that restricts the available products to
those that are available to a user. '''
products = inventory.Product.objects.all()
products = ProductController.available_products(user, products=products)
product_ids = [product.id for ... | [
"def",
"staff_products_form_factory",
"(",
"user",
")",
":",
"products",
"=",
"inventory",
".",
"Product",
".",
"objects",
".",
"all",
"(",
")",
"products",
"=",
"ProductController",
".",
"available_products",
"(",
"user",
",",
"products",
"=",
"products",
")"... | 31.695652 | 0.001332 |
def format_unspents(unspents):
"""
Used for testing only!
"""
assert BLOCKSTACK_TEST, 'format_unspents can only be used in test mode!'
return [{
"transaction_hash": s["txid"],
"outpoint": {
'hash': s['txid'],
'index': s["vout"],
},
"value": int... | [
"def",
"format_unspents",
"(",
"unspents",
")",
":",
"assert",
"BLOCKSTACK_TEST",
",",
"'format_unspents can only be used in test mode!'",
"return",
"[",
"{",
"\"transaction_hash\"",
":",
"s",
"[",
"\"txid\"",
"]",
",",
"\"outpoint\"",
":",
"{",
"'hash'",
":",
"s",
... | 27.764706 | 0.002049 |
def deinit(self):
"""Blank out the NeoPixels and release the pin."""
for i in range(len(self.buf)):
self.buf[i] = 0
neopixel_write(self.pin, self.buf)
self.pin.deinit() | [
"def",
"deinit",
"(",
"self",
")",
":",
"for",
"i",
"in",
"range",
"(",
"len",
"(",
"self",
".",
"buf",
")",
")",
":",
"self",
".",
"buf",
"[",
"i",
"]",
"=",
"0",
"neopixel_write",
"(",
"self",
".",
"pin",
",",
"self",
".",
"buf",
")",
"self... | 34.5 | 0.009434 |
def reset():
"""
Clear global data and remove the handlers.
CAUSION! This method sets as a signal handlers the ones which it has
noticed on initialization time. If there has been another handler installed
on top of us it will get removed by this method call.
"""
global _handlers, python_sign... | [
"def",
"reset",
"(",
")",
":",
"global",
"_handlers",
",",
"python_signal",
"for",
"sig",
",",
"(",
"previous",
",",
"_",
")",
"in",
"_handlers",
".",
"iteritems",
"(",
")",
":",
"if",
"not",
"previous",
":",
"previous",
"=",
"SIG_DFL",
"python_signal",
... | 37.384615 | 0.002008 |
def xlink_href_target(self, node, group=None):
"""
Return either:
- a tuple (renderer, node) when the the xlink:href attribute targets
a vector file or node
- the path to an image file for any raster image targets
- None if any problem occurs
"""... | [
"def",
"xlink_href_target",
"(",
"self",
",",
"node",
",",
"group",
"=",
"None",
")",
":",
"xlink_href",
"=",
"node",
".",
"attrib",
".",
"get",
"(",
"'{http://www.w3.org/1999/xlink}href'",
")",
"if",
"not",
"xlink_href",
":",
"return",
"None",
"# First handle... | 41.772152 | 0.002072 |
def _get_node_dir(node):
"""Return the absolute path of the directory of a filesystem node."""
path = os.path.abspath(node)
return path if os.path.isdir(path) else os.path.dirname(path) | [
"def",
"_get_node_dir",
"(",
"node",
")",
":",
"path",
"=",
"os",
".",
"path",
".",
"abspath",
"(",
"node",
")",
"return",
"path",
"if",
"os",
".",
"path",
".",
"isdir",
"(",
"path",
")",
"else",
"os",
".",
"path",
".",
"dirname",
"(",
"path",
")... | 51.5 | 0.009569 |
def gui_getFile():
"""
Launch an ABF file selection file dialog.
This is smart, and remembers (through reboots) where you last were.
"""
import tkinter as tk
from tkinter import filedialog
root = tk.Tk() # this is natively supported by python
root.withdraw() # hide main window
root.w... | [
"def",
"gui_getFile",
"(",
")",
":",
"import",
"tkinter",
"as",
"tk",
"from",
"tkinter",
"import",
"filedialog",
"root",
"=",
"tk",
".",
"Tk",
"(",
")",
"# this is natively supported by python",
"root",
".",
"withdraw",
"(",
")",
"# hide main window",
"root",
... | 37.842105 | 0.009498 |
def attribute_circle(self, EdgeAttribute=None, network=None, \
NodeAttribute=None, nodeList=None, singlePartition=None,\
spacing=None, verbose=False):
"""
Execute the Attribute Circle Layout on a network.
:param EdgeAttribute (string, optional): The name of the edge column
containing numeric values that wil... | [
"def",
"attribute_circle",
"(",
"self",
",",
"EdgeAttribute",
"=",
"None",
",",
"network",
"=",
"None",
",",
"NodeAttribute",
"=",
"None",
",",
"nodeList",
"=",
"None",
",",
"singlePartition",
"=",
"None",
",",
"spacing",
"=",
"None",
",",
"verbose",
"=",
... | 55.606061 | 0.029459 |
def _load_modules(self):
"""
Load modules-related configuration listened in modules section
Before loading:
"modules": {
"mal": "myanimelist.json",
"ann": "animenewsnetwork.json"
}
After loading:
"modules": {
"mal": {
....
},
"ann": {
... | [
"def",
"_load_modules",
"(",
"self",
")",
":",
"if",
"self",
".",
"exists",
"(",
"\"modules\"",
")",
":",
"for",
"item",
"in",
"self",
".",
"_json",
"[",
"\"modules\"",
"]",
":",
"try",
":",
"json_data",
"=",
"json",
".",
"loads",
"(",
"self",
".",
... | 28.8 | 0.009409 |
def ensure(assertion, message=None):
"""
Checks an assertion argument for truth-ness. Will return ``True`` or
explicitly raise ``AssertionError``. This is to deal with environments
using ``python -O` or ``PYTHONOPTIMIZE=``.
:param assertion: some value to evaluate for truth-ness
:param message:... | [
"def",
"ensure",
"(",
"assertion",
",",
"message",
"=",
"None",
")",
":",
"message",
"=",
"message",
"or",
"assertion",
"if",
"not",
"assertion",
":",
"raise",
"AssertionError",
"(",
"message",
")",
"return",
"True"
] | 31.733333 | 0.002041 |
def unhexlify(blob):
"""
Takes a hexlified script and turns it back into a string of Python code.
"""
lines = blob.split('\n')[1:]
output = []
for line in lines:
# Discard the address, length etc. and reverse the hexlification
output.append(binascii.unhexlify(line[9:-2]))
# C... | [
"def",
"unhexlify",
"(",
"blob",
")",
":",
"lines",
"=",
"blob",
".",
"split",
"(",
"'\\n'",
")",
"[",
"1",
":",
"]",
"output",
"=",
"[",
"]",
"for",
"line",
"in",
"lines",
":",
"# Discard the address, length etc. and reverse the hexlification",
"output",
".... | 36.36 | 0.001072 |
def upload(self, bug: Bug) -> bool:
"""
Attempts to upload the Docker image for a given bug to
`DockerHub <https://hub.docker.com>`_.
"""
return self.__installation.build.upload(bug.image) | [
"def",
"upload",
"(",
"self",
",",
"bug",
":",
"Bug",
")",
"->",
"bool",
":",
"return",
"self",
".",
"__installation",
".",
"build",
".",
"upload",
"(",
"bug",
".",
"image",
")"
] | 37.166667 | 0.008772 |
def _match_datetime_pattern(self, tokens):
"""
Match the datetime pattern at the beginning of the token list.
There are several formats that this method needs to understand
and distinguish between (see MongoDB's SERVER-7965):
ctime-pre2.4 Wed Dec 31 19:00:00
ctime ... | [
"def",
"_match_datetime_pattern",
"(",
"self",
",",
"tokens",
")",
":",
"# first check: less than 4 tokens can't be ctime",
"assume_iso8601_format",
"=",
"len",
"(",
"tokens",
")",
"<",
"4",
"# check for ctime-pre-2.4 or ctime format",
"if",
"not",
"assume_iso8601_format",
... | 38.596154 | 0.000972 |
def estimate_cp_pval(ts, method="mean"):
""" Estimate changepoints in a time series by using R. """
"""
ts: time series
method: look for a single changepoint in 'mean' , 'var', 'mean and var'
Returns: returns index of the changepoint, and pvalue. Here pvalue = 1
means ... | [
"def",
"estimate_cp_pval",
"(",
"ts",
",",
"method",
"=",
"\"mean\"",
")",
":",
"\"\"\" \n ts: time series\n method: look for a single changepoint in 'mean' , 'var', 'mean and var'\n Returns: returns index of the changepoint, and pvalue. Here pvalue = 1\n mea... | 34.565217 | 0.002448 |
def setSortedBy( self, sortedBy ):
"""
Sets the sorting information for this widget to the inputed sorting
options. This can be either a list of terms, or a comma deliminated
string.
:param sortedBy | <str> || [(<str> column, <str> direction), ..]
""... | [
"def",
"setSortedBy",
"(",
"self",
",",
"sortedBy",
")",
":",
"if",
"(",
"type",
"(",
"groupBy",
")",
"in",
"(",
"list",
",",
"tuple",
")",
")",
":",
"sortedBy",
"=",
"','",
".",
"join",
"(",
"map",
"(",
"lambda",
"x",
":",
"'%s|%s'",
"%",
"x",
... | 40.333333 | 0.016162 |
def decode(input, fallback_encoding, errors='replace'):
"""
Decode a single string.
:param input: A byte string
:param fallback_encoding:
An :class:`Encoding` object or a label string.
The encoding to use if :obj:`input` does note have a BOM.
:param errors: Type of error handling. S... | [
"def",
"decode",
"(",
"input",
",",
"fallback_encoding",
",",
"errors",
"=",
"'replace'",
")",
":",
"# Fail early if `encoding` is an invalid label.",
"fallback_encoding",
"=",
"_get_encoding",
"(",
"fallback_encoding",
")",
"bom_encoding",
",",
"input",
"=",
"_detect_b... | 39.3 | 0.001242 |
def read(self, input_stream, kmip_version=enums.KMIPVersion.KMIP_2_0):
"""
Read the data stream and decode the Attributes structure into its
parts.
Args:
input_stream (stream): A data stream containing encoded object
data, supporting a read method.
... | [
"def",
"read",
"(",
"self",
",",
"input_stream",
",",
"kmip_version",
"=",
"enums",
".",
"KMIPVersion",
".",
"KMIP_2_0",
")",
":",
"if",
"kmip_version",
"<",
"enums",
".",
"KMIPVersion",
".",
"KMIP_2_0",
":",
"raise",
"exceptions",
".",
"VersionNotSupported",
... | 41.520833 | 0.00098 |
def pubsub_pop_message(self, deadline=None):
"""Pops a message for a subscribed client.
Args:
deadline (int): max number of seconds to wait (None => no timeout)
Returns:
Future with the popped message as result (or None if timeout
or ConnectionError obje... | [
"def",
"pubsub_pop_message",
"(",
"self",
",",
"deadline",
"=",
"None",
")",
":",
"if",
"not",
"self",
".",
"subscribed",
":",
"excep",
"=",
"ClientError",
"(",
"\"you must subscribe before using \"",
"\"pubsub_pop_message\"",
")",
"raise",
"tornado",
".",
"gen",
... | 35.032258 | 0.001792 |
def fit_candidates(AggOp, B, tol=1e-10):
"""Fit near-nullspace candidates to form the tentative prolongator.
Parameters
----------
AggOp : csr_matrix
Describes the sparsity pattern of the tentative prolongator.
Has dimension (#blocks, #aggregates)
B : array
The near-nullspac... | [
"def",
"fit_candidates",
"(",
"AggOp",
",",
"B",
",",
"tol",
"=",
"1e-10",
")",
":",
"if",
"not",
"isspmatrix_csr",
"(",
"AggOp",
")",
":",
"raise",
"TypeError",
"(",
"'expected csr_matrix for argument AggOp'",
")",
"B",
"=",
"np",
".",
"asarray",
"(",
"B"... | 34.479167 | 0.000196 |
def boot(self, width=None, height=None,
only_if_needed=True, check_booted=True, **boot_kwargs):
"""Boot a SpiNNaker machine.
The system will be booted from the Ethernet connected chip whose
hostname was given as the argument to the MachineController. With the
default argume... | [
"def",
"boot",
"(",
"self",
",",
"width",
"=",
"None",
",",
"height",
"=",
"None",
",",
"only_if_needed",
"=",
"True",
",",
"check_booted",
"=",
"True",
",",
"*",
"*",
"boot_kwargs",
")",
":",
"# Report deprecated width/height arguments",
"if",
"width",
"is"... | 44.682171 | 0.000509 |
def spline(x, y, n, yp1, ypn, y2):
'''
/* CALCULATE 2ND DERIVATIVES OF CUBIC SPLINE INTERP FUNCTION
* ADAPTED FROM NUMERICAL RECIPES BY PRESS ET AL
* X,Y: ARRAYS OF TABULATED FUNCTION IN ASCENDING ORDER BY X
* N: SIZE OF ARRAYS X,Y
* YP1,YPN: SPECIFIED DERIVATIVES AT X[0] AND X[N-1... | [
"def",
"spline",
"(",
"x",
",",
"y",
",",
"n",
",",
"yp1",
",",
"ypn",
",",
"y2",
")",
":",
"u",
"=",
"[",
"0.0",
"]",
"*",
"n",
"#I think this is the same as malloc",
"#no need for the out of memory",
"if",
"(",
"yp1",
">",
"0.99E30",
")",
":",
"# pra... | 31.510638 | 0.013752 |
def get_kwargs_index(target) -> int:
"""
Returns the index of the "**kwargs" parameter if such a parameter exists in
the function arguments or -1 otherwise.
:param target:
The target function for which the kwargs index should be determined
:return:
The keyword arguments index if it ... | [
"def",
"get_kwargs_index",
"(",
"target",
")",
"->",
"int",
":",
"code",
"=",
"target",
".",
"__code__",
"if",
"not",
"bool",
"(",
"code",
".",
"co_flags",
"&",
"inspect",
".",
"CO_VARKEYWORDS",
")",
":",
"return",
"-",
"1",
"return",
"(",
"code",
".",... | 27.047619 | 0.001701 |
def make_scores(
ic50_y,
ic50_y_pred,
sample_weight=None,
threshold_nm=500,
max_ic50=50000):
"""
Calculate AUC, F1, and Kendall Tau scores.
Parameters
-----------
ic50_y : float list
true IC50s (i.e. affinities)
ic50_y_pred : float list
p... | [
"def",
"make_scores",
"(",
"ic50_y",
",",
"ic50_y_pred",
",",
"sample_weight",
"=",
"None",
",",
"threshold_nm",
"=",
"500",
",",
"max_ic50",
"=",
"50000",
")",
":",
"y_pred",
"=",
"from_ic50",
"(",
"ic50_y_pred",
",",
"max_ic50",
")",
"try",
":",
"auc",
... | 21.963636 | 0.000792 |
def delete_message(self, queue, message):
"""
Delete a message from a queue.
:type queue: A :class:`boto.sqs.queue.Queue` object
:param queue: The Queue from which messages are read.
:type message: A :class:`boto.sqs.message.Message` object
:param message: The M... | [
"def",
"delete_message",
"(",
"self",
",",
"queue",
",",
"message",
")",
":",
"params",
"=",
"{",
"'ReceiptHandle'",
":",
"message",
".",
"receipt_handle",
"}",
"return",
"self",
".",
"get_status",
"(",
"'DeleteMessage'",
",",
"params",
",",
"queue",
".",
... | 36.533333 | 0.008897 |
def _replace_docstring_header(paragraph):
"""Process NumPy-like function docstrings."""
# Replace Markdown headers in docstrings with light headers in bold.
paragraph = re.sub(_docstring_header_pattern,
r'*\1*',
paragraph,
)
paragrap... | [
"def",
"_replace_docstring_header",
"(",
"paragraph",
")",
":",
"# Replace Markdown headers in docstrings with light headers in bold.",
"paragraph",
"=",
"re",
".",
"sub",
"(",
"_docstring_header_pattern",
",",
"r'*\\1*'",
",",
"paragraph",
",",
")",
"paragraph",
"=",
"re... | 31.4 | 0.002062 |
def can_reach(self, node, traversable=lambda node, edge: True):
""" Returns True if given node can be reached over traversable edges.
To enforce edge direction, use a node==edge.node1 traversable.
"""
if isinstance(node, str):
node = self.graph[node]
... | [
"def",
"can_reach",
"(",
"self",
",",
"node",
",",
"traversable",
"=",
"lambda",
"node",
",",
"edge",
":",
"True",
")",
":",
"if",
"isinstance",
"(",
"node",
",",
"str",
")",
":",
"node",
"=",
"self",
".",
"graph",
"[",
"node",
"]",
"for",
"n",
"... | 36 | 0.01354 |
def move(self, auth, resource, destinationresource, options={"aliases": True}, defer=False):
""" Moves a resource from one parent client to another.
Args:
auth: <cik>
resource: Identifed resource to be moved.
destinationresource: resource of client resource is being ... | [
"def",
"move",
"(",
"self",
",",
"auth",
",",
"resource",
",",
"destinationresource",
",",
"options",
"=",
"{",
"\"aliases\"",
":",
"True",
"}",
",",
"defer",
"=",
"False",
")",
":",
"return",
"self",
".",
"_call",
"(",
"'move'",
",",
"auth",
",",
"[... | 46.888889 | 0.009302 |
def get_proxy(self, input):
"""Gets a proxy.
:param input: a proxy condition
:type input: ``osid.proxy.ProxyCondition``
:return: a proxy
:rtype: ``osid.proxy.Proxy``
:raise: ``NullArgument`` -- ``input`` is ``null``
:raise: ``OperationFailed`` -- unable to comple... | [
"def",
"get_proxy",
"(",
"self",
",",
"input",
")",
":",
"from",
".",
".",
"authentication_process",
".",
"objects",
"import",
"Authentication",
"agent_id",
"=",
"input",
".",
"user",
".",
"username",
"host",
"=",
"settings",
".",
"HOST",
"url_path",
"=",
... | 41.086957 | 0.002068 |
def _top(self):
""" g """
# Goto top of the list
self.top.body.focus_position = 2 if self.compact is False else 0
self.top.keypress(self.size, "") | [
"def",
"_top",
"(",
"self",
")",
":",
"# Goto top of the list",
"self",
".",
"top",
".",
"body",
".",
"focus_position",
"=",
"2",
"if",
"self",
".",
"compact",
"is",
"False",
"else",
"0",
"self",
".",
"top",
".",
"keypress",
"(",
"self",
".",
"size",
... | 34.8 | 0.011236 |
def _build_table_options(self, row):
""" Setup the mostly-non-schema table options, like caching settings """
return dict((o, row.get(o)) for o in self.recognized_table_options if o in row) | [
"def",
"_build_table_options",
"(",
"self",
",",
"row",
")",
":",
"return",
"dict",
"(",
"(",
"o",
",",
"row",
".",
"get",
"(",
"o",
")",
")",
"for",
"o",
"in",
"self",
".",
"recognized_table_options",
"if",
"o",
"in",
"row",
")"
] | 67.666667 | 0.019512 |
def add_to_products(self, products=None, all_products=False):
"""
Add user group to some product license configuration groups (PLCs), or all of them.
:param products: list of product names the user should be added to
:param all_products: a boolean meaning add to all (don't specify produc... | [
"def",
"add_to_products",
"(",
"self",
",",
"products",
"=",
"None",
",",
"all_products",
"=",
"False",
")",
":",
"if",
"all_products",
":",
"if",
"products",
":",
"raise",
"ArgumentError",
"(",
"\"When adding to all products, do not specify specific products\"",
")",... | 54.375 | 0.00904 |
def average_values(self, *args, **kwargs) -> float:
"""Average the actual values of the |Variable| object.
For 0-dimensional |Variable| objects, the result of method
|Variable.average_values| equals |Variable.value|. The
following example shows this for the sloppily defined class
... | [
"def",
"average_values",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
"->",
"float",
":",
"try",
":",
"if",
"not",
"self",
".",
"NDIM",
":",
"return",
"self",
".",
"value",
"mask",
"=",
"self",
".",
"get_submask",
"(",
"*",
"args",
... | 39.94186 | 0.000284 |
def summary(self, fmt=None, initial=True, default=''):
"""
Given a format string, return a summary description of a component.
Args:
component (dict): A component dictionary.
fmt (str): Describes the format with a string. If no format is
given, you will j... | [
"def",
"summary",
"(",
"self",
",",
"fmt",
"=",
"None",
",",
"initial",
"=",
"True",
",",
"default",
"=",
"''",
")",
":",
"if",
"default",
"and",
"not",
"self",
".",
"__dict__",
":",
"return",
"default",
"if",
"fmt",
"==",
"''",
":",
"return",
"def... | 33.244444 | 0.001299 |
def scaled(self, scale):
"""
Return a copy of the current scene, with meshes and scene
transforms scaled to the requested factor.
Parameters
-----------
scale : float
Factor to scale meshes and transforms
Returns
-----------
scaled : tr... | [
"def",
"scaled",
"(",
"self",
",",
"scale",
")",
":",
"scale",
"=",
"float",
"(",
"scale",
")",
"# matrix for 2D scaling",
"scale_2D",
"=",
"np",
".",
"eye",
"(",
"3",
")",
"*",
"scale",
"# matrix for 3D scaling",
"scale_3D",
"=",
"np",
".",
"eye",
"(",
... | 35.33871 | 0.000888 |
def adapter(self, adapter):
"""Sets the adapter instance under the "_adapter" property in use by this class.
Also sets the adapter property for all implemented classes under this category.
:param adapter: New adapter instance to set for this class and all implemented classes under this categor... | [
"def",
"adapter",
"(",
"self",
",",
"adapter",
")",
":",
"self",
".",
"_adapter",
"=",
"adapter",
"for",
"implemented_class",
"in",
"self",
".",
"implemented_classes",
":",
"class_name",
"=",
"implemented_class",
".",
"__name__",
".",
"lower",
"(",
")",
"get... | 50.25 | 0.009772 |
def build_parser():
"""
_build_parser_
Set up CLI parser options, parse the
CLI options an return the parsed results
"""
parser = argparse.ArgumentParser(
description='dockerstache templating util'
)
parser.add_argument(
'--output', '-o',
help='Working directory... | [
"def",
"build_parser",
"(",
")",
":",
"parser",
"=",
"argparse",
".",
"ArgumentParser",
"(",
"description",
"=",
"'dockerstache templating util'",
")",
"parser",
".",
"add_argument",
"(",
"'--output'",
",",
"'-o'",
",",
"help",
"=",
"'Working directory to render doc... | 26.44898 | 0.002232 |
def _buckets_nearly_equal(a_dist, b_dist):
"""Determines whether two `Distributions` are nearly equal.
Args:
a_dist (:class:`Distribution`): an instance
b_dist (:class:`Distribution`): another instance
Return:
boolean: `True` if the two instances are approximately equal, otherwise
... | [
"def",
"_buckets_nearly_equal",
"(",
"a_dist",
",",
"b_dist",
")",
":",
"a_type",
",",
"a_buckets",
"=",
"_detect_bucket_option",
"(",
"a_dist",
")",
"b_type",
",",
"b_buckets",
"=",
"_detect_bucket_option",
"(",
"b_dist",
")",
"if",
"a_type",
"!=",
"b_type",
... | 34.208333 | 0.001185 |
def set_proxy(self, proxy_server, proxy_port, proxy_username,
proxy_password):
""" Sets a proxy on the Session
:param str proxy_server: the proxy server
:param int proxy_port: the proxy port, defaults to 8080
:param str proxy_username: the proxy username
:param... | [
"def",
"set_proxy",
"(",
"self",
",",
"proxy_server",
",",
"proxy_port",
",",
"proxy_username",
",",
"proxy_password",
")",
":",
"if",
"proxy_server",
"and",
"proxy_port",
":",
"if",
"proxy_username",
"and",
"proxy_password",
":",
"self",
".",
"proxy",
"=",
"{... | 49.307692 | 0.002295 |
def bk_blue(cls):
"Make the text background color blue."
wAttributes = cls._get_text_attributes()
wAttributes &= ~win32.BACKGROUND_MASK
wAttributes |= win32.BACKGROUND_BLUE
cls._set_text_attributes(wAttributes) | [
"def",
"bk_blue",
"(",
"cls",
")",
":",
"wAttributes",
"=",
"cls",
".",
"_get_text_attributes",
"(",
")",
"wAttributes",
"&=",
"~",
"win32",
".",
"BACKGROUND_MASK",
"wAttributes",
"|=",
"win32",
".",
"BACKGROUND_BLUE",
"cls",
".",
"_set_text_attributes",
"(",
... | 41 | 0.011952 |
def drawRect(self, rect):
"""Draw a rectangle.
"""
r = Rect(rect)
self.draw_cont += "%g %g %g %g re\n" % JM_TUPLE(list(r.bl * self.ipctm) + \
[r.width, r.height])
self.updateRect(r)
self.lastPoint = r.tl
return self.l... | [
"def",
"drawRect",
"(",
"self",
",",
"rect",
")",
":",
"r",
"=",
"Rect",
"(",
"rect",
")",
"self",
".",
"draw_cont",
"+=",
"\"%g %g %g %g re\\n\"",
"%",
"JM_TUPLE",
"(",
"list",
"(",
"r",
".",
"bl",
"*",
"self",
".",
"ipctm",
")",
"+",
"[",
"r",
... | 35.555556 | 0.015244 |
def get_network_interface_id(name, region=None, key=None, keyid=None,
profile=None):
'''
Get an Elastic Network Interface id from its name tag.
.. versionadded:: 2016.3.0
CLI Example:
.. code-block:: bash
salt myminion boto_ec2.get_network_interface_id name=m... | [
"def",
"get_network_interface_id",
"(",
"name",
",",
"region",
"=",
"None",
",",
"key",
"=",
"None",
",",
"keyid",
"=",
"None",
",",
"profile",
"=",
"None",
")",
":",
"conn",
"=",
"_get_conn",
"(",
"region",
"=",
"region",
",",
"key",
"=",
"key",
","... | 31.518519 | 0.002281 |
def do_POST(self):
"""
Based on the original, available at https://github.com/python/cpython/blob/2.7/Lib/SimpleXMLRPCServer.py
Only difference is that it denies requests bigger than a certain size.
Handles the HTTP POST request.
Attempts to interpret all HTTP POST requests as ... | [
"def",
"do_POST",
"(",
"self",
")",
":",
"# Check that the path is legal",
"if",
"not",
"self",
".",
"is_rpc_path_valid",
"(",
")",
":",
"self",
".",
"report_404",
"(",
")",
"return",
"# reject gzip, so size-caps will work",
"encoding",
"=",
"self",
".",
"headers"... | 39.534884 | 0.002009 |
def convert(self, request, response, data):
"""
Performs the desired Conversion.
:param request: The webob Request object describing the
request.
:param response: The webob Response object describing the
response.
:param data: The... | [
"def",
"convert",
"(",
"self",
",",
"request",
",",
"response",
",",
"data",
")",
":",
"if",
"self",
".",
"modifier",
".",
"param",
"is",
"None",
"or",
"self",
".",
"modifier",
".",
"param",
"==",
"'pid'",
":",
"return",
"str",
"(",
"os",
".",
"get... | 36.227273 | 0.002445 |
def unit_tangent(self, t=None):
"""returns the unit tangent of the segment at t."""
assert self.end != self.start
dseg = self.end - self.start
return dseg/abs(dseg) | [
"def",
"unit_tangent",
"(",
"self",
",",
"t",
"=",
"None",
")",
":",
"assert",
"self",
".",
"end",
"!=",
"self",
".",
"start",
"dseg",
"=",
"self",
".",
"end",
"-",
"self",
".",
"start",
"return",
"dseg",
"/",
"abs",
"(",
"dseg",
")"
] | 38.4 | 0.010204 |
def trigger_update(self, params, values):
""" Notify parent of a parameter change """
if self._parent:
self._parent.trigger_update(params, values)
else:
self.update(params, values) | [
"def",
"trigger_update",
"(",
"self",
",",
"params",
",",
"values",
")",
":",
"if",
"self",
".",
"_parent",
":",
"self",
".",
"_parent",
".",
"trigger_update",
"(",
"params",
",",
"values",
")",
"else",
":",
"self",
".",
"update",
"(",
"params",
",",
... | 37.166667 | 0.008772 |
def search_artist(self, artist_name, max_songs=None,
sort='popularity', per_page=20, get_full_info=True):
"""Search Genius.com for songs by the specified artist.
Returns an Artist object containing artist's songs.
:param artist_name: Name of the artist to search for
... | [
"def",
"search_artist",
"(",
"self",
",",
"artist_name",
",",
"max_songs",
"=",
"None",
",",
"sort",
"=",
"'popularity'",
",",
"per_page",
"=",
"20",
",",
"get_full_info",
"=",
"True",
")",
":",
"if",
"self",
".",
"verbose",
":",
"print",
"(",
"'Searchin... | 44.081395 | 0.001806 |
def _json_safe_float(number):
"""
JSON serialization for infinity can be problematic.
See https://docs.python.org/2/library/json.html#basic-usage
This function returns None if `number` is infinity or negative infinity.
If the `number` cannot be converted to float, this will raise an exception.
... | [
"def",
"_json_safe_float",
"(",
"number",
")",
":",
"if",
"number",
"is",
"None",
":",
"return",
"None",
"if",
"isinstance",
"(",
"number",
",",
"float",
")",
":",
"return",
"None",
"if",
"np",
".",
"isinf",
"(",
"number",
")",
"or",
"np",
".",
"isna... | 33.1875 | 0.001832 |
def send_error(self, status_code: int = 500, **kwargs: Any) -> None:
"""Sends the given HTTP error code to the browser.
If `flush()` has already been called, it is not possible to send
an error, so this method will simply terminate the response.
If output has been written but not yet fl... | [
"def",
"send_error",
"(",
"self",
",",
"status_code",
":",
"int",
"=",
"500",
",",
"*",
"*",
"kwargs",
":",
"Any",
")",
"->",
"None",
":",
"if",
"self",
".",
"_headers_written",
":",
"gen_log",
".",
"error",
"(",
"\"Cannot send error response after headers w... | 43.864865 | 0.001808 |
def get_coordinates(self):
"""Retrieves coordinates (latitudes/longitudes) from the output
JSON/XML response
Returns:
coordinates (namedtuple): List of named tuples of coordinates
(latitudes and longitudes)
"""
resource_list = self.get_resource()
... | [
"def",
"get_coordinates",
"(",
"self",
")",
":",
"resource_list",
"=",
"self",
".",
"get_resource",
"(",
")",
"coordinates",
"=",
"namedtuple",
"(",
"'coordinates'",
",",
"[",
"'latitude'",
",",
"'longitude'",
"]",
")",
"try",
":",
"return",
"[",
"coordinate... | 41.909091 | 0.002121 |
def patch(module, external=(), internal=()):
"""
Temporarily monkey-patch dependencies which can be external to, or internal
to the supplied module.
:param module: Module object
:param external: External dependencies to patch (full paths as strings)
:param internal: Internal dependencies to pat... | [
"def",
"patch",
"(",
"module",
",",
"external",
"=",
"(",
")",
",",
"internal",
"=",
"(",
")",
")",
":",
"external",
"=",
"tuple",
"(",
"external",
")",
"internal",
"=",
"tuple",
"(",
"internal",
")",
"def",
"decorator",
"(",
"fn",
")",
":",
"@",
... | 38.895833 | 0.000522 |
def _private_notes(self, key, value):
"""Populate the ``_private_notes`` key.
Also populates the ``_export_to`` key through side effects.
"""
def _is_for_cds(value):
normalized_c_values = [el.upper() for el in force_list(value.get('c'))]
return 'CDS' in normalized_c_values
def _is_... | [
"def",
"_private_notes",
"(",
"self",
",",
"key",
",",
"value",
")",
":",
"def",
"_is_for_cds",
"(",
"value",
")",
":",
"normalized_c_values",
"=",
"[",
"el",
".",
"upper",
"(",
")",
"for",
"el",
"in",
"force_list",
"(",
"value",
".",
"get",
"(",
"'c... | 32.342105 | 0.00079 |
def extrude(
self,
input_entity,
translation_axis=None,
rotation_axis=None,
point_on_axis=None,
angle=None,
num_layers=None,
recombine=False,
):
"""Extrusion (translation + rotation) of any entity along a given
translation_axis, around ... | [
"def",
"extrude",
"(",
"self",
",",
"input_entity",
",",
"translation_axis",
"=",
"None",
",",
"rotation_axis",
"=",
"None",
",",
"point_on_axis",
"=",
"None",
",",
"angle",
"=",
"None",
",",
"num_layers",
"=",
"None",
",",
"recombine",
"=",
"False",
",",
... | 39.220183 | 0.001597 |
def generate_tap_reports(self):
"""Generate TAP reports.
The results are either combined into a single output file or
the output file name is generated from the test case.
"""
# We're streaming but set_plan wasn't called, so we can only
# know the plan now (at the end).
... | [
"def",
"generate_tap_reports",
"(",
"self",
")",
":",
"# We're streaming but set_plan wasn't called, so we can only",
"# know the plan now (at the end).",
"if",
"self",
".",
"streaming",
"and",
"not",
"self",
".",
"_plan_written",
":",
"print",
"(",
"\"1..{0}\"",
".",
"fo... | 46.5 | 0.001975 |
def ns(self, value):
"""The ns property.
Args:
value (string). the property value.
"""
if value == self._defaults['ns'] and 'ns' in self._values:
del self._values['ns']
else:
self._values['ns'] = value | [
"def",
"ns",
"(",
"self",
",",
"value",
")",
":",
"if",
"value",
"==",
"self",
".",
"_defaults",
"[",
"'ns'",
"]",
"and",
"'ns'",
"in",
"self",
".",
"_values",
":",
"del",
"self",
".",
"_values",
"[",
"'ns'",
"]",
"else",
":",
"self",
".",
"_valu... | 27.7 | 0.01049 |
def save(self, fname):
""" Saves the dictionary in json format
:param fname: file to save to
"""
with open(fname, 'wb') as f:
json.dump(self, f) | [
"def",
"save",
"(",
"self",
",",
"fname",
")",
":",
"with",
"open",
"(",
"fname",
",",
"'wb'",
")",
"as",
"f",
":",
"json",
".",
"dump",
"(",
"self",
",",
"f",
")"
] | 30.5 | 0.010638 |
def createEditor(self, parent, option, index):
"""
Creates a new editor for the given index parented to the inputed widget.
:param parent | <QWidget>
option | <QStyleOption>
index | <QModelIndex>
:return <QWidget... | [
"def",
"createEditor",
"(",
"self",
",",
"parent",
",",
"option",
",",
"index",
")",
":",
"if",
"index",
".",
"column",
"(",
")",
"in",
"self",
".",
"_disabledEditingColumns",
":",
"return",
"None",
"editor",
"=",
"super",
"(",
"XTreeWidgetDelegate",
",",
... | 36.714286 | 0.010114 |
def _zip(self) -> ObjectValue:
"""Zip the receiver into an object and return it."""
res = ObjectValue(self.siblings.copy(), self.timestamp)
res[self.name] = self.value
return res | [
"def",
"_zip",
"(",
"self",
")",
"->",
"ObjectValue",
":",
"res",
"=",
"ObjectValue",
"(",
"self",
".",
"siblings",
".",
"copy",
"(",
")",
",",
"self",
".",
"timestamp",
")",
"res",
"[",
"self",
".",
"name",
"]",
"=",
"self",
".",
"value",
"return"... | 41.2 | 0.009524 |
def add_param_annotations(
logic: Callable, params: List[RequestParamAnnotation]) -> Callable:
"""Adds parameter annotations to a logic function.
This adds additional required and/or optional parameters to the logic
function that are not part of it's signature. It's intended to be used
by deco... | [
"def",
"add_param_annotations",
"(",
"logic",
":",
"Callable",
",",
"params",
":",
"List",
"[",
"RequestParamAnnotation",
"]",
")",
"->",
"Callable",
":",
"# If we've already added param annotations to this function get the",
"# values from the logic, otherwise we need to inspect... | 42.851064 | 0.000971 |
def add_intspin(self, setting):
'''add a spin control'''
tab = self.panel(setting.tab)
default = setting.value
(minv, maxv) = setting.range
ctrl = wx.SpinCtrl(tab, -1,
initial = default,
min = minv,
... | [
"def",
"add_intspin",
"(",
"self",
",",
"setting",
")",
":",
"tab",
"=",
"self",
".",
"panel",
"(",
"setting",
".",
"tab",
")",
"default",
"=",
"setting",
".",
"value",
"(",
"minv",
",",
"maxv",
")",
"=",
"setting",
".",
"range",
"ctrl",
"=",
"wx",... | 37.6 | 0.020779 |
def text_filter(regex_base, value):
"""
Helper method to regex replace images with captions in different markups
"""
regex = regex_base % {
're_cap': r'[a-zA-Z0-9\.\,:;/_ \(\)\-\!\?"]+',
're_img': r'[a-zA-Z0-9\.:/_\-\% ]+'
}
images = re.findall(regex, value)
for i in images:... | [
"def",
"text_filter",
"(",
"regex_base",
",",
"value",
")",
":",
"regex",
"=",
"regex_base",
"%",
"{",
"'re_cap'",
":",
"r'[a-zA-Z0-9\\.\\,:;/_ \\(\\)\\-\\!\\?\"]+'",
",",
"'re_img'",
":",
"r'[a-zA-Z0-9\\.:/_\\-\\% ]+'",
"}",
"images",
"=",
"re",
".",
"findall",
"... | 29.684211 | 0.001718 |
def _draw_background(self, divisions=10):
"""
Draws the background of the dial
:param divisions: the number of divisions
between 'ticks' shown on the dial
:return: None
"""
self.canvas.create_arc(2, 2, self.size-2, self.size-2,
styl... | [
"def",
"_draw_background",
"(",
"self",
",",
"divisions",
"=",
"10",
")",
":",
"self",
".",
"canvas",
".",
"create_arc",
"(",
"2",
",",
"2",
",",
"self",
".",
"size",
"-",
"2",
",",
"self",
".",
"size",
"-",
"2",
",",
"style",
"=",
"tk",
".",
"... | 43.454545 | 0.001364 |
def expand_kids_by_index(self, *indices):
"Expand (inline) children at the given indices"
for i in sorted(indices, reverse=True): # reverse so that changing tail won't affect indices
kid = self.children[i]
self.children[i:i+1] = kid.children | [
"def",
"expand_kids_by_index",
"(",
"self",
",",
"*",
"indices",
")",
":",
"for",
"i",
"in",
"sorted",
"(",
"indices",
",",
"reverse",
"=",
"True",
")",
":",
"# reverse so that changing tail won't affect indices",
"kid",
"=",
"self",
".",
"children",
"[",
"i",... | 55.4 | 0.014235 |
def get_calltip(project, source_code, offset, resource=None,
maxfixes=1, ignore_unknown=False, remove_self=False):
"""Get the calltip of a function
The format of the returned string is
``module_name.holding_scope_names.function_name(arguments)``. For
classes `__init__()` and for normal... | [
"def",
"get_calltip",
"(",
"project",
",",
"source_code",
",",
"offset",
",",
"resource",
"=",
"None",
",",
"maxfixes",
"=",
"1",
",",
"ignore_unknown",
"=",
"False",
",",
"remove_self",
"=",
"False",
")",
":",
"fixer",
"=",
"fixsyntax",
".",
"FixSyntax",
... | 40.903226 | 0.00077 |
def interface_errors(self):
""" Parse 'show interfaces extensive' and return interfaces with errors.
Purpose: This function is called for the -e flag. It will let the user
| know if there are any interfaces with errors, and what those
| interfaces are.
@returns: T... | [
"def",
"interface_errors",
"(",
"self",
")",
":",
"output",
"=",
"[",
"]",
"# used to store the list of interfaces with errors.",
"# get a string of each physical and logical interface element",
"dev_response",
"=",
"self",
".",
"_session",
".",
"command",
"(",
"'sh interface... | 49.555556 | 0.001649 |
def __write_filter_tmpl(html_tpl):
'''
doing for directory.
'''
out_dir = os.path.join(os.getcwd(), CRUD_PATH, 'list')
if os.path.exists(out_dir):
pass
else:
os.mkdir(out_dir)
# for var_name in VAR_NAMES:
for var_name, bl_val in SWITCH_DICS.items():
if var_name.st... | [
"def",
"__write_filter_tmpl",
"(",
"html_tpl",
")",
":",
"out_dir",
"=",
"os",
".",
"path",
".",
"join",
"(",
"os",
".",
"getcwd",
"(",
")",
",",
"CRUD_PATH",
",",
"'list'",
")",
"if",
"os",
".",
"path",
".",
"exists",
"(",
"out_dir",
")",
":",
"pa... | 35.8 | 0.002039 |
def wrap_application(application, before_run, on_start, shutdown):
"""
Wrap a tornado application in a callback-aware wrapper.
:param tornado.web.Application application: application to wrap.
:param list|NoneType before_run: optional list of callbacks
to invoke before the IOLoop is started.
... | [
"def",
"wrap_application",
"(",
"application",
",",
"before_run",
",",
"on_start",
",",
"shutdown",
")",
":",
"before_run",
"=",
"[",
"]",
"if",
"before_run",
"is",
"None",
"else",
"before_run",
"on_start",
"=",
"[",
"]",
"if",
"on_start",
"is",
"None",
"e... | 37 | 0.000908 |
def update(self):
"""Update |C1| based on :math:`c_1 = \\frac{Damp}{1+Damp}`.
Examples:
The first examples show the calculated value of |C1| for
the lowest possible value of |Lag|, the lowest possible value,
and an intermediate value:
>>> from hydpy.mod... | [
"def",
"update",
"(",
"self",
")",
":",
"damp",
"=",
"self",
".",
"subpars",
".",
"pars",
".",
"control",
".",
"damp",
"self",
"(",
"numpy",
".",
"clip",
"(",
"damp",
"/",
"(",
"1.",
"+",
"damp",
")",
",",
"0.",
",",
".5",
")",
")"
] | 30.138889 | 0.001786 |
def update_data(self, data_np, metadata=None, astype=None):
"""DO NOT USE: this method will be deprecated!
"""
self.set_data(data_np.copy(), metadata=metadata,
astype=astype) | [
"def",
"update_data",
"(",
"self",
",",
"data_np",
",",
"metadata",
"=",
"None",
",",
"astype",
"=",
"None",
")",
":",
"self",
".",
"set_data",
"(",
"data_np",
".",
"copy",
"(",
")",
",",
"metadata",
"=",
"metadata",
",",
"astype",
"=",
"astype",
")"... | 43.2 | 0.009091 |
def sort_labeled_intervals(intervals, labels=None):
'''Sort intervals, and optionally, their corresponding labels
according to start time.
Parameters
----------
intervals : np.ndarray, shape=(n, 2)
The input intervals
labels : list, optional
Labels for each interval
Return... | [
"def",
"sort_labeled_intervals",
"(",
"intervals",
",",
"labels",
"=",
"None",
")",
":",
"idx",
"=",
"np",
".",
"argsort",
"(",
"intervals",
"[",
":",
",",
"0",
"]",
")",
"intervals_sorted",
"=",
"intervals",
"[",
"idx",
"]",
"if",
"labels",
"is",
"Non... | 24.230769 | 0.001527 |
def scale_flow(flow, to_unit=True):
"Scale the coords in `flow` to -1/1 or the image size depending on `to_unit`."
s = tensor([flow.size[0]/2,flow.size[1]/2])[None]
if to_unit: flow.flow = flow.flow/s-1
else: flow.flow = (flow.flow+1)*s
return flow | [
"def",
"scale_flow",
"(",
"flow",
",",
"to_unit",
"=",
"True",
")",
":",
"s",
"=",
"tensor",
"(",
"[",
"flow",
".",
"size",
"[",
"0",
"]",
"/",
"2",
",",
"flow",
".",
"size",
"[",
"1",
"]",
"/",
"2",
"]",
")",
"[",
"None",
"]",
"if",
"to_un... | 44.833333 | 0.018248 |
def get_user_loc(self, master_or_instance):
"""Get the user location of a Glyphs master or instance.
Masters in Glyphs can have a user location in the "Axis Location"
custom parameter.
The user location is what the user sees on the slider in his
variable-font-enabled UI. For wei... | [
"def",
"get_user_loc",
"(",
"self",
",",
"master_or_instance",
")",
":",
"user_loc",
"=",
"self",
".",
"default_user_loc",
"if",
"self",
".",
"tag",
"!=",
"\"wght\"",
":",
"# The user location is by default the same as the design location.",
"user_loc",
"=",
"self",
"... | 46.392857 | 0.000754 |
def _link_package_versions(self, link, search):
"""Return an InstallationCandidate or None"""
platform = get_platform()
version = None
if link.egg_fragment:
egg_info = link.egg_fragment
ext = link.ext
else:
egg_info, ext = link.splitext()
... | [
"def",
"_link_package_versions",
"(",
"self",
",",
"link",
",",
"search",
")",
":",
"platform",
"=",
"get_platform",
"(",
")",
"version",
"=",
"None",
"if",
"link",
".",
"egg_fragment",
":",
"egg_info",
"=",
"link",
".",
"egg_fragment",
"ext",
"=",
"link",... | 43.598214 | 0.0004 |
def vcs_nodes(self):
"""dict: vcs node details
"""
urn = "{urn:brocade.com:mgmt:brocade-vcs}"
namespace = 'urn:brocade.com:mgmt:brocade-vcs'
show_vcs = ET.Element('show-vcs', xmlns=namespace)
results = self._callback(show_vcs, handler='get')
result = []
fo... | [
"def",
"vcs_nodes",
"(",
"self",
")",
":",
"urn",
"=",
"\"{urn:brocade.com:mgmt:brocade-vcs}\"",
"namespace",
"=",
"'urn:brocade.com:mgmt:brocade-vcs'",
"show_vcs",
"=",
"ET",
".",
"Element",
"(",
"'show-vcs'",
",",
"xmlns",
"=",
"namespace",
")",
"results",
"=",
... | 51 | 0.00104 |
def where(self, where: str) -> 'SASdata':
"""
This method returns a clone of the SASdata object, with the where attribute set. The original SASdata object is not affected.
:param where: the where clause to apply
:return: SAS data object
"""
sd = SASdata(self.sas, self.li... | [
"def",
"where",
"(",
"self",
",",
"where",
":",
"str",
")",
"->",
"'SASdata'",
":",
"sd",
"=",
"SASdata",
"(",
"self",
".",
"sas",
",",
"self",
".",
"libref",
",",
"self",
".",
"table",
",",
"dsopts",
"=",
"dict",
"(",
"self",
".",
"dsopts",
")",... | 39.454545 | 0.009009 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.