text stringlengths 75 104k | code_tokens list | avg_line_len float64 7.91 980 | score float64 0 0.18 |
|---|---|---|---|
def save_group(self, group):
""" Group was saved. """
# If group already exists, take over existing group rather then error.
try:
lgroup = self._get_group(group.name)
changes = changeset(lgroup, {})
except ObjectDoesNotExist:
lgroup = self._group_class... | [
"def",
"save_group",
"(",
"self",
",",
"group",
")",
":",
"# If group already exists, take over existing group rather then error.",
"try",
":",
"lgroup",
"=",
"self",
".",
"_get_group",
"(",
"group",
".",
"name",
")",
"changes",
"=",
"changeset",
"(",
"lgroup",
",... | 33.5 | 0.00363 |
def get(self):
"""Gets the next item from the queue.
Returns a Future that resolves to the next item once it is available.
"""
io_loop = IOLoop.current()
new_get = Future()
with self._lock:
get, self._get = self._get, new_get
answer = Future()
... | [
"def",
"get",
"(",
"self",
")",
":",
"io_loop",
"=",
"IOLoop",
".",
"current",
"(",
")",
"new_get",
"=",
"Future",
"(",
")",
"with",
"self",
".",
"_lock",
":",
"get",
",",
"self",
".",
"_get",
"=",
"self",
".",
"_get",
",",
"new_get",
"answer",
"... | 29.75 | 0.002035 |
def structure(self, obj, cl):
# type: (Any, Type[T]) -> T
"""Convert unstructured Python data structures to structured data."""
return self._structure_func.dispatch(cl)(obj, cl) | [
"def",
"structure",
"(",
"self",
",",
"obj",
",",
"cl",
")",
":",
"# type: (Any, Type[T]) -> T",
"return",
"self",
".",
"_structure_func",
".",
"dispatch",
"(",
"cl",
")",
"(",
"obj",
",",
"cl",
")"
] | 39.6 | 0.014851 |
def file_to_str(fname):
"""
Read a file into a string
PRE: fname is a small file (to avoid hogging memory and its discontents)
"""
data = None
# rU = read with Universal line terminator
with open(fname, 'rU') as fd:
data = fd.read()
return data | [
"def",
"file_to_str",
"(",
"fname",
")",
":",
"data",
"=",
"None",
"# rU = read with Universal line terminator",
"with",
"open",
"(",
"fname",
",",
"'rU'",
")",
"as",
"fd",
":",
"data",
"=",
"fd",
".",
"read",
"(",
")",
"return",
"data"
] | 27.5 | 0.003521 |
def round_to_x_digits(number, digits):
"""
Returns 'number' rounded to 'digits' digits.
"""
return round(number * math.pow(10, digits)) / math.pow(10, digits) | [
"def",
"round_to_x_digits",
"(",
"number",
",",
"digits",
")",
":",
"return",
"round",
"(",
"number",
"*",
"math",
".",
"pow",
"(",
"10",
",",
"digits",
")",
")",
"/",
"math",
".",
"pow",
"(",
"10",
",",
"digits",
")"
] | 34 | 0.005747 |
def get_sdc_by_name(self, name):
"""
Get ScaleIO SDC object by its name
:param name: Name of SDC
:return: ScaleIO SDC object
:raise KeyError: No SDC with specified name found
:rtype: SDC object
"""
for sdc in self.sdc:
if sdc.name == name:
... | [
"def",
"get_sdc_by_name",
"(",
"self",
",",
"name",
")",
":",
"for",
"sdc",
"in",
"self",
".",
"sdc",
":",
"if",
"sdc",
".",
"name",
"==",
"name",
":",
"return",
"sdc",
"raise",
"KeyError",
"(",
"\"SDC of that name not found\"",
")"
] | 32 | 0.005063 |
def _parse_impute2_line(self, line):
"""Parses the current IMPUTE2 line (a single variant).
Args:
line (str): An IMPUTE2 line.
Returns:
Genotypes: The genotype in dosage format.
Warning
=======
By default, the genotypes object has multiallel... | [
"def",
"_parse_impute2_line",
"(",
"self",
",",
"line",
")",
":",
"# Splitting",
"row",
"=",
"line",
".",
"rstrip",
"(",
"\"\\r\\n\"",
")",
".",
"split",
"(",
"\" \"",
")",
"# Constructing the probabilities",
"prob",
"=",
"np",
".",
"array",
"(",
"row",
"[... | 27.970588 | 0.002033 |
def _seed(self, seed=-1):
"""
Initialize the random seed
"""
if seed != -1:
self.random = NupicRandom(seed)
else:
self.random = NupicRandom() | [
"def",
"_seed",
"(",
"self",
",",
"seed",
"=",
"-",
"1",
")",
":",
"if",
"seed",
"!=",
"-",
"1",
":",
"self",
".",
"random",
"=",
"NupicRandom",
"(",
"seed",
")",
"else",
":",
"self",
".",
"random",
"=",
"NupicRandom",
"(",
")"
] | 20.75 | 0.017341 |
def fail(self, tup):
"""Indicate that processing of a Tuple has failed.
:param tup: the Tuple to fail (its ``id`` if ``str``).
:type tup: :class:`str` or :class:`pystorm.component.Tuple`
"""
tup_id = tup.id if isinstance(tup, Tuple) else tup
self.send_message({"command":... | [
"def",
"fail",
"(",
"self",
",",
"tup",
")",
":",
"tup_id",
"=",
"tup",
".",
"id",
"if",
"isinstance",
"(",
"tup",
",",
"Tuple",
")",
"else",
"tup",
"self",
".",
"send_message",
"(",
"{",
"\"command\"",
":",
"\"fail\"",
",",
"\"id\"",
":",
"tup_id",
... | 42 | 0.005831 |
def _oct_to_dec(ip, check=True):
"""Octal to decimal conversion."""
if check and not is_oct(ip):
raise ValueError('_oct_to_dec: invalid IP: "%s"' % ip)
if isinstance(ip, int):
ip = oct(ip)
return int(str(ip), 8) | [
"def",
"_oct_to_dec",
"(",
"ip",
",",
"check",
"=",
"True",
")",
":",
"if",
"check",
"and",
"not",
"is_oct",
"(",
"ip",
")",
":",
"raise",
"ValueError",
"(",
"'_oct_to_dec: invalid IP: \"%s\"'",
"%",
"ip",
")",
"if",
"isinstance",
"(",
"ip",
",",
"int",
... | 33.857143 | 0.004115 |
def resizeEvent(self, event):
"""
Handles a resize event for this overlay, centering the central widget if
one is found.
:param event | <QtCore.QEvent>
"""
super(XOverlayWidget, self).resizeEvent(event)
self.adjustSize() | [
"def",
"resizeEvent",
"(",
"self",
",",
"event",
")",
":",
"super",
"(",
"XOverlayWidget",
",",
"self",
")",
".",
"resizeEvent",
"(",
"event",
")",
"self",
".",
"adjustSize",
"(",
")"
] | 30.444444 | 0.010638 |
def _get_layout_as_etree(layout_dict):
"""
Convert something that looks like this:
{
'color' : ['red'],
'shapefile' : ['blah.shp']
}
Into something that looks like this:
<layout>
<item>
<name>color</name>
<value>red</value>
</item>
... | [
"def",
"_get_layout_as_etree",
"(",
"layout_dict",
")",
":",
"if",
"layout_dict",
"is",
"None",
":",
"return",
"None",
"layout",
"=",
"etree",
".",
"Element",
"(",
"\"layout\"",
")",
"layout_dict",
"=",
"eval",
"(",
"layout_dict",
")",
"for",
"k",
",",
"v"... | 23.454545 | 0.001241 |
def init(self):
"""
Adds custom calculations to orbit simulation.
This routine is run once, and only once, upon instantiation.
Adds quasi-dipole coordiantes, velocity calculation in ECEF coords,
adds the attitude vectors of spacecraft assuming x is ram pointing and
z is generally nadir, add... | [
"def",
"init",
"(",
"self",
")",
":",
"self",
".",
"custom",
".",
"add",
"(",
"add_quasi_dipole_coordinates",
",",
"'modify'",
")",
"self",
".",
"custom",
".",
"add",
"(",
"add_aacgm_coordinates",
",",
"'modify'",
")",
"self",
".",
"custom",
".",
"add",
... | 46.333333 | 0.005766 |
def active_language(self):
"""
Returns active language.
"""
# Current instance language (if user uses activate_language() method)
if self._language is not None:
return self._language
# Current site language (translation.get_language())
current = utils... | [
"def",
"active_language",
"(",
"self",
")",
":",
"# Current instance language (if user uses activate_language() method)",
"if",
"self",
".",
"_language",
"is",
"not",
"None",
":",
"return",
"self",
".",
"_language",
"# Current site language (translation.get_language())",
"cur... | 31.466667 | 0.004115 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.