repo stringlengths 7 55 | path stringlengths 4 223 | url stringlengths 87 315 | code stringlengths 75 104k | code_tokens list | docstring stringlengths 1 46.9k | docstring_tokens list | language stringclasses 1
value | partition stringclasses 3
values | avg_line_len float64 7.91 980 |
|---|---|---|---|---|---|---|---|---|---|
jaredLunde/vital-tools | vital/security/__init__.py | https://github.com/jaredLunde/vital-tools/blob/ea924c9bbb6ec22aa66f8095f018b1ee0099ac04/vital/security/__init__.py#L405-L430 | def randkey(bits, keyspace=string.ascii_letters + string.digits + '#/.',
rng=None):
""" Returns a cryptographically secure random key of desired @bits of
entropy within @keyspace using :class:random.SystemRandom
@bits: (#int) minimum bits of entropy
@keyspace: (#str) or iterable... | [
"def",
"randkey",
"(",
"bits",
",",
"keyspace",
"=",
"string",
".",
"ascii_letters",
"+",
"string",
".",
"digits",
"+",
"'#/.'",
",",
"rng",
"=",
"None",
")",
":",
"return",
"\"\"",
".",
"join",
"(",
"char",
"for",
"char",
"in",
"iter_random_chars",
"(... | Returns a cryptographically secure random key of desired @bits of
entropy within @keyspace using :class:random.SystemRandom
@bits: (#int) minimum bits of entropy
@keyspace: (#str) or iterable allowed output chars
@rng: the random number generator to use. Defaults to
:class:r... | [
"Returns",
"a",
"cryptographically",
"secure",
"random",
"key",
"of",
"desired",
"@bits",
"of",
"entropy",
"within",
"@keyspace",
"using",
":",
"class",
":",
"random",
".",
"SystemRandom"
] | python | train | 34.615385 |
flowersteam/explauto | explauto/sensorimotor_model/inverse/cma.py | https://github.com/flowersteam/explauto/blob/cf0f81ecb9f6412f7276a95bd27359000e1e26b6/explauto/sensorimotor_model/inverse/cma.py#L1504-L1512 | def idx_infeasible(self, solution_genotype):
"""return indices of "infeasible" variables, that is,
variables that do not directly map into the feasible domain such that
``tf.inverse(tf(x)) == x``.
"""
res = [i for i, x in enumerate(solution_genotype)
... | [
"def",
"idx_infeasible",
"(",
"self",
",",
"solution_genotype",
")",
":",
"res",
"=",
"[",
"i",
"for",
"i",
",",
"x",
"in",
"enumerate",
"(",
"solution_genotype",
")",
"if",
"not",
"self",
".",
"is_feasible_i",
"(",
"x",
",",
"i",
")",
"]",
"return",
... | return indices of "infeasible" variables, that is,
variables that do not directly map into the feasible domain such that
``tf.inverse(tf(x)) == x``. | [
"return",
"indices",
"of",
"infeasible",
"variables",
"that",
"is",
"variables",
"that",
"do",
"not",
"directly",
"map",
"into",
"the",
"feasible",
"domain",
"such",
"that",
"tf",
".",
"inverse",
"(",
"tf",
"(",
"x",
"))",
"==",
"x",
"."
] | python | train | 40.777778 |
rflamary/POT | ot/smooth.py | https://github.com/rflamary/POT/blob/c5108efc7b6702e1af3928bef1032e6b37734d1c/ot/smooth.py#L510-L600 | def smooth_ot_semi_dual(a, b, M, reg, reg_type='l2', method="L-BFGS-B", stopThr=1e-9,
numItermax=500, verbose=False, log=False):
r"""
Solve the regularized OT problem in the semi-dual and return the OT matrix
The function solves the smooth relaxed dual formulation (10) in [17]_ :
... | [
"def",
"smooth_ot_semi_dual",
"(",
"a",
",",
"b",
",",
"M",
",",
"reg",
",",
"reg_type",
"=",
"'l2'",
",",
"method",
"=",
"\"L-BFGS-B\"",
",",
"stopThr",
"=",
"1e-9",
",",
"numItermax",
"=",
"500",
",",
"verbose",
"=",
"False",
",",
"log",
"=",
"Fals... | r"""
Solve the regularized OT problem in the semi-dual and return the OT matrix
The function solves the smooth relaxed dual formulation (10) in [17]_ :
.. math::
\max_{\alpha}\quad a^T\alpha-OT_\Omega^*(\alpha,b)
where :
.. math::
OT_\Omega^*(\alpha,b)=\sum_j b_j
- :math:`\m... | [
"r",
"Solve",
"the",
"regularized",
"OT",
"problem",
"in",
"the",
"semi",
"-",
"dual",
"and",
"return",
"the",
"OT",
"matrix"
] | python | train | 32.604396 |
zencoder/zencoder-py | zencoder/core.py | https://github.com/zencoder/zencoder-py/blob/9d762e33e2bb2edadb0e5da0bb80a61e27636426/zencoder/core.py#L103-L110 | def post(self, url, body=None):
""" Executes an HTTP POST request for the given URL. """
response = self.http.post(url,
headers=self.headers,
data=body,
**self.requests_params)
return self.proc... | [
"def",
"post",
"(",
"self",
",",
"url",
",",
"body",
"=",
"None",
")",
":",
"response",
"=",
"self",
".",
"http",
".",
"post",
"(",
"url",
",",
"headers",
"=",
"self",
".",
"headers",
",",
"data",
"=",
"body",
",",
"*",
"*",
"self",
".",
"reque... | Executes an HTTP POST request for the given URL. | [
"Executes",
"an",
"HTTP",
"POST",
"request",
"for",
"the",
"given",
"URL",
"."
] | python | train | 40.75 |
CZ-NIC/yangson | yangson/datamodel.py | https://github.com/CZ-NIC/yangson/blob/a4b9464041fa8b28f6020a420ababf18fddf5d4a/yangson/datamodel.py#L169-L177 | def schema_digest(self) -> str:
"""Generate schema digest (to be used primarily by clients).
Returns:
Condensed information about the schema in JSON format.
"""
res = self.schema._node_digest()
res["config"] = True
return json.dumps(res) | [
"def",
"schema_digest",
"(",
"self",
")",
"->",
"str",
":",
"res",
"=",
"self",
".",
"schema",
".",
"_node_digest",
"(",
")",
"res",
"[",
"\"config\"",
"]",
"=",
"True",
"return",
"json",
".",
"dumps",
"(",
"res",
")"
] | Generate schema digest (to be used primarily by clients).
Returns:
Condensed information about the schema in JSON format. | [
"Generate",
"schema",
"digest",
"(",
"to",
"be",
"used",
"primarily",
"by",
"clients",
")",
"."
] | python | train | 32.222222 |
tensorpack/tensorpack | examples/basics/export-model.py | https://github.com/tensorpack/tensorpack/blob/d7a13cb74c9066bc791d7aafc3b744b60ee79a9f/examples/basics/export-model.py#L106-L113 | def export_serving(model_path):
"""Export trained model to use it in TensorFlow Serving or cloudML. """
pred_config = PredictConfig(
session_init=get_model_loader(model_path),
model=InferenceOnlyModel(),
input_names=['input_img_bytes'],
output_names=['prediction_img_bytes'])
... | [
"def",
"export_serving",
"(",
"model_path",
")",
":",
"pred_config",
"=",
"PredictConfig",
"(",
"session_init",
"=",
"get_model_loader",
"(",
"model_path",
")",
",",
"model",
"=",
"InferenceOnlyModel",
"(",
")",
",",
"input_names",
"=",
"[",
"'input_img_bytes'",
... | Export trained model to use it in TensorFlow Serving or cloudML. | [
"Export",
"trained",
"model",
"to",
"use",
"it",
"in",
"TensorFlow",
"Serving",
"or",
"cloudML",
"."
] | python | train | 46.375 |
singularityhub/sregistry-cli | sregistry/main/google_build/push.py | https://github.com/singularityhub/sregistry-cli/blob/abc96140a1d15b5e96d83432e1e0e1f4f8f36331/sregistry/main/google_build/push.py#L26-L58 | def push(self, path, name, tag=None):
'''push an image to Google Cloud Storage, meaning uploading it
path: should correspond to an absolte image path (or derive it)
name: should be the complete uri that the user has requested to push.
tag: should correspond with an image tag. This is provided to mi... | [
"def",
"push",
"(",
"self",
",",
"path",
",",
"name",
",",
"tag",
"=",
"None",
")",
":",
"path",
"=",
"os",
".",
"path",
".",
"abspath",
"(",
"path",
")",
"bot",
".",
"debug",
"(",
"\"PUSH %s\"",
"%",
"path",
")",
"if",
"not",
"os",
".",
"path"... | push an image to Google Cloud Storage, meaning uploading it
path: should correspond to an absolte image path (or derive it)
name: should be the complete uri that the user has requested to push.
tag: should correspond with an image tag. This is provided to mirror Docker | [
"push",
"an",
"image",
"to",
"Google",
"Cloud",
"Storage",
"meaning",
"uploading",
"it",
"path",
":",
"should",
"correspond",
"to",
"an",
"absolte",
"image",
"path",
"(",
"or",
"derive",
"it",
")",
"name",
":",
"should",
"be",
"the",
"complete",
"uri",
"... | python | test | 33.878788 |
Parsely/birding | src/birding/config.py | https://github.com/Parsely/birding/blob/c7f6eee56424234e361b1a455595de202e744dac/src/birding/config.py#L231-L261 | def import_name(name, default_ns=None):
"""Import an object based on the dotted string.
>>> import_name('textwrap') # doctest: +ELLIPSIS
<module 'textwrap' from '...'>
>>> import_name('birding.config') # doctest: +ELLIPSIS
<module 'birding.config' from '...'>
>>> import_name('birding.config.get... | [
"def",
"import_name",
"(",
"name",
",",
"default_ns",
"=",
"None",
")",
":",
"if",
"'.'",
"not",
"in",
"name",
":",
"if",
"default_ns",
"is",
"None",
":",
"return",
"importlib",
".",
"import_module",
"(",
"name",
")",
"else",
":",
"name",
"=",
"default... | Import an object based on the dotted string.
>>> import_name('textwrap') # doctest: +ELLIPSIS
<module 'textwrap' from '...'>
>>> import_name('birding.config') # doctest: +ELLIPSIS
<module 'birding.config' from '...'>
>>> import_name('birding.config.get_config') # doctest: +ELLIPSIS
<function ge... | [
"Import",
"an",
"object",
"based",
"on",
"the",
"dotted",
"string",
"."
] | python | train | 33.83871 |
ARMmbed/mbed-cloud-sdk-python | src/mbed_cloud/account_management/account_management.py | https://github.com/ARMmbed/mbed-cloud-sdk-python/blob/c0af86fb2cdd4dc7ed26f236139241067d293509/src/mbed_cloud/account_management/account_management.py#L257-L268 | def list_groups(self, **kwargs):
"""List all groups in organisation.
:param int limit: The number of groups to retrieve
:param str order: The ordering direction, ascending (asc) or descending (desc)
:param str after: Get groups after/starting at given group ID
:returns: a list o... | [
"def",
"list_groups",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"kwargs",
"=",
"self",
".",
"_verify_sort_options",
"(",
"kwargs",
")",
"api",
"=",
"self",
".",
"_get_api",
"(",
"iam",
".",
"DeveloperApi",
")",
"return",
"PaginatedResponse",
"(",
"... | List all groups in organisation.
:param int limit: The number of groups to retrieve
:param str order: The ordering direction, ascending (asc) or descending (desc)
:param str after: Get groups after/starting at given group ID
:returns: a list of :py:class:`Group` objects.
:rtype:... | [
"List",
"all",
"groups",
"in",
"organisation",
"."
] | python | train | 46.75 |
zvolsky/wfpdf | wfpdf.py | https://github.com/zvolsky/wfpdf/blob/d3625a6420ae1fb6722d81cddf0636af496c42bb/wfpdf.py#L116-L127 | def header(self, item0, *items):
"""print string item0 to the current position and next strings to defined positions
example: .header("Name", 75, "Quantity", 100, "Unit")
"""
self.txt(item0)
at_x = None
for item in items:
if at_x is None:
at_x ... | [
"def",
"header",
"(",
"self",
",",
"item0",
",",
"*",
"items",
")",
":",
"self",
".",
"txt",
"(",
"item0",
")",
"at_x",
"=",
"None",
"for",
"item",
"in",
"items",
":",
"if",
"at_x",
"is",
"None",
":",
"at_x",
"=",
"item",
"else",
":",
"self",
"... | print string item0 to the current position and next strings to defined positions
example: .header("Name", 75, "Quantity", 100, "Unit") | [
"print",
"string",
"item0",
"to",
"the",
"current",
"position",
"and",
"next",
"strings",
"to",
"defined",
"positions",
"example",
":",
".",
"header",
"(",
"Name",
"75",
"Quantity",
"100",
"Unit",
")"
] | python | train | 33.583333 |
Clinical-Genomics/scout | scout/adapter/mongo/user.py | https://github.com/Clinical-Genomics/scout/blob/90a551e2e1653a319e654c2405c2866f93d0ebb9/scout/adapter/mongo/user.py#L72-L84 | def user(self, email):
"""Fetch a user from the database.
Args:
email(str)
Returns:
user_obj(dict)
"""
LOG.info("Fetching user %s", email)
user_obj = self.user_collection.find_one({'_id': email})
return us... | [
"def",
"user",
"(",
"self",
",",
"email",
")",
":",
"LOG",
".",
"info",
"(",
"\"Fetching user %s\"",
",",
"email",
")",
"user_obj",
"=",
"self",
".",
"user_collection",
".",
"find_one",
"(",
"{",
"'_id'",
":",
"email",
"}",
")",
"return",
"user_obj"
] | Fetch a user from the database.
Args:
email(str)
Returns:
user_obj(dict) | [
"Fetch",
"a",
"user",
"from",
"the",
"database",
".",
"Args",
":",
"email",
"(",
"str",
")",
"Returns",
":",
"user_obj",
"(",
"dict",
")"
] | python | test | 24.153846 |
openego/eDisGo | edisgo/tools/edisgo_run.py | https://github.com/openego/eDisGo/blob/e6245bdaf236f9c49dbda5a18c1c458290f41e2b/edisgo/tools/edisgo_run.py#L168-L215 | def run_edisgo_twice(run_args):
"""
Run grid analysis twice on same grid: once w/ and once w/o new generators
First run without connection of new generators approves sufficient grid
hosting capacity. Otherwise, grid is reinforced.
Second run assessment grid extension needs in terms of RES integrati... | [
"def",
"run_edisgo_twice",
"(",
"run_args",
")",
":",
"# base case with no generator import",
"edisgo_grid",
",",
"costs_before_geno_import",
",",
"grid_issues_before_geno_import",
"=",
"run_edisgo_basic",
"(",
"*",
"run_args",
")",
"if",
"edisgo_grid",
":",
"# clear the py... | Run grid analysis twice on same grid: once w/ and once w/o new generators
First run without connection of new generators approves sufficient grid
hosting capacity. Otherwise, grid is reinforced.
Second run assessment grid extension needs in terms of RES integration
Parameters
----------
run_ar... | [
"Run",
"grid",
"analysis",
"twice",
"on",
"same",
"grid",
":",
"once",
"w",
"/",
"and",
"once",
"w",
"/",
"o",
"new",
"generators"
] | python | train | 35.791667 |
svetlyak40wt/python-repr | src/magic_repr/__init__.py | https://github.com/svetlyak40wt/python-repr/blob/49e358e77b97d74f29f4977ea009ab2d64c254e8/src/magic_repr/__init__.py#L125-L177 | def format_value(value):
"""This function should return unicode representation of the value
"""
value_id = id(value)
if value_id in recursion_breaker.processed:
return u'<recursion>'
recursion_breaker.processed.add(value_id)
try:
if isinstance(value, six.binary_type):
... | [
"def",
"format_value",
"(",
"value",
")",
":",
"value_id",
"=",
"id",
"(",
"value",
")",
"if",
"value_id",
"in",
"recursion_breaker",
".",
"processed",
":",
"return",
"u'<recursion>'",
"recursion_breaker",
".",
"processed",
".",
"add",
"(",
"value_id",
")",
... | This function should return unicode representation of the value | [
"This",
"function",
"should",
"return",
"unicode",
"representation",
"of",
"the",
"value"
] | python | valid | 33.018868 |
noxdafox/vminspect | vminspect/comparator.py | https://github.com/noxdafox/vminspect/blob/e685282564877e2d1950f1e09b292f4f4db1dbcd/vminspect/comparator.py#L367-L374 | def files_type(fs0, fs1, files):
"""Inspects the file type of the given files."""
for file_meta in files['deleted_files']:
file_meta['type'] = fs0.file(file_meta['path'])
for file_meta in files['created_files'] + files['modified_files']:
file_meta['type'] = fs1.file(file_meta['path'])
r... | [
"def",
"files_type",
"(",
"fs0",
",",
"fs1",
",",
"files",
")",
":",
"for",
"file_meta",
"in",
"files",
"[",
"'deleted_files'",
"]",
":",
"file_meta",
"[",
"'type'",
"]",
"=",
"fs0",
".",
"file",
"(",
"file_meta",
"[",
"'path'",
"]",
")",
"for",
"fil... | Inspects the file type of the given files. | [
"Inspects",
"the",
"file",
"type",
"of",
"the",
"given",
"files",
"."
] | python | train | 40.5 |
tango-controls/pytango | tango/utils.py | https://github.com/tango-controls/pytango/blob/9cf78c517c9cdc1081ff6d080a9646a740cc1d36/tango/utils.py#L635-L652 | def is_float(tg_type, inc_array=False):
"""Tells if the given tango type is float
:param tg_type: tango type
:type tg_type: :class:`tango.CmdArgType`
:param inc_array: (optional, default is False) determines if include array
in the list of checked types
:type inc_array: :py:ob... | [
"def",
"is_float",
"(",
"tg_type",
",",
"inc_array",
"=",
"False",
")",
":",
"global",
"_scalar_float_types",
",",
"_array_float_types",
"if",
"tg_type",
"in",
"_scalar_float_types",
":",
"return",
"True",
"if",
"not",
"inc_array",
":",
"return",
"False",
"retur... | Tells if the given tango type is float
:param tg_type: tango type
:type tg_type: :class:`tango.CmdArgType`
:param inc_array: (optional, default is False) determines if include array
in the list of checked types
:type inc_array: :py:obj:`bool`
:return: True if the given tango ... | [
"Tells",
"if",
"the",
"given",
"tango",
"type",
"is",
"float"
] | python | train | 33.944444 |
SiLab-Bonn/pyBAR | pybar/scans/analyze_timewalk.py | https://github.com/SiLab-Bonn/pyBAR/blob/5ad95bbcd41cd358825823fb78f396cfce23593e/pybar/scans/analyze_timewalk.py#L36-L41 | def get_charge_calibration(calibation_file, max_tdc):
''' Open the hit or calibration file and return the calibration per pixel'''
with tb.open_file(calibation_file, mode="r") as in_file_calibration_h5:
tdc_calibration = in_file_calibration_h5.root.HitOrCalibration[:, :, :, 1]
tdc_calibration_va... | [
"def",
"get_charge_calibration",
"(",
"calibation_file",
",",
"max_tdc",
")",
":",
"with",
"tb",
".",
"open_file",
"(",
"calibation_file",
",",
"mode",
"=",
"\"r\"",
")",
"as",
"in_file_calibration_h5",
":",
"tdc_calibration",
"=",
"in_file_calibration_h5",
".",
"... | Open the hit or calibration file and return the calibration per pixel | [
"Open",
"the",
"hit",
"or",
"calibration",
"file",
"and",
"return",
"the",
"calibration",
"per",
"pixel"
] | python | train | 78.166667 |
svenevs/exhale | exhale/graph.py | https://github.com/svenevs/exhale/blob/fe7644829057af622e467bb529db6c03a830da99/exhale/graph.py#L498-L557 | def toConsole(self, level, fmt_spec, printChildren=True):
'''
Debugging tool for printing hierarchies / ownership to the console. Recursively
calls children ``toConsole`` if this node is not a directory or a file, and
``printChildren == True``.
.. todo:: fmt_spec docs needed. k... | [
"def",
"toConsole",
"(",
"self",
",",
"level",
",",
"fmt_spec",
",",
"printChildren",
"=",
"True",
")",
":",
"indent",
"=",
"\" \"",
"*",
"level",
"utils",
".",
"verbose_log",
"(",
"\"{indent}- [{kind}]: {name}\"",
".",
"format",
"(",
"indent",
"=",
"indent... | Debugging tool for printing hierarchies / ownership to the console. Recursively
calls children ``toConsole`` if this node is not a directory or a file, and
``printChildren == True``.
.. todo:: fmt_spec docs needed. keys are ``kind`` and values are color spec
:Parameters:
`... | [
"Debugging",
"tool",
"for",
"printing",
"hierarchies",
"/",
"ownership",
"to",
"the",
"console",
".",
"Recursively",
"calls",
"children",
"toConsole",
"if",
"this",
"node",
"is",
"not",
"a",
"directory",
"or",
"a",
"file",
"and",
"printChildren",
"==",
"True",... | python | train | 45.483333 |
firecat53/urlscan | urlscan/urlchoose.py | https://github.com/firecat53/urlscan/blob/2d10807d01167873733da3b478c784f8fa21bbc0/urlscan/urlchoose.py#L547-L586 | def _search(self):
""" Search - search URLs and text.
"""
text = "Search: {}".format(self.search_string)
footerwid = urwid.AttrMap(urwid.Text(text), 'footer')
self.top.footer = footerwid
search_items = []
for grp in self.items_org:
done = False
... | [
"def",
"_search",
"(",
"self",
")",
":",
"text",
"=",
"\"Search: {}\"",
".",
"format",
"(",
"self",
".",
"search_string",
")",
"footerwid",
"=",
"urwid",
".",
"AttrMap",
"(",
"urwid",
".",
"Text",
"(",
"text",
")",
",",
"'footer'",
")",
"self",
".",
... | Search - search URLs and text. | [
"Search",
"-",
"search",
"URLs",
"and",
"text",
"."
] | python | train | 51.975 |
Jajcus/pyxmpp2 | pyxmpp2/sasl/digest_md5.py | https://github.com/Jajcus/pyxmpp2/blob/14a40a3950910a9cd008b55f0d8905aa0186ce18/pyxmpp2/sasl/digest_md5.py#L61-L76 | def _quote(data):
"""Prepare a string for quoting for DIGEST-MD5 challenge or response.
Don't add the quotes, only escape '"' and "\\" with backslashes.
:Parameters:
- `data`: a raw string.
:Types:
- `data`: `bytes`
:return: `data` with '"' and "\\" escaped using "\\".
:return... | [
"def",
"_quote",
"(",
"data",
")",
":",
"data",
"=",
"data",
".",
"replace",
"(",
"b'\\\\'",
",",
"b'\\\\\\\\'",
")",
"data",
"=",
"data",
".",
"replace",
"(",
"b'\"'",
",",
"b'\\\\\"'",
")",
"return",
"data"
] | Prepare a string for quoting for DIGEST-MD5 challenge or response.
Don't add the quotes, only escape '"' and "\\" with backslashes.
:Parameters:
- `data`: a raw string.
:Types:
- `data`: `bytes`
:return: `data` with '"' and "\\" escaped using "\\".
:returntype: `bytes` | [
"Prepare",
"a",
"string",
"for",
"quoting",
"for",
"DIGEST",
"-",
"MD5",
"challenge",
"or",
"response",
"."
] | python | valid | 26.25 |
mandiant/ioc_writer | ioc_writer/ioc_common.py | https://github.com/mandiant/ioc_writer/blob/712247f3a10bdc2584fa18ac909fc763f71df21a/ioc_writer/ioc_common.py#L951-L963 | def make_serviceitem_servicedllmd5sum(servicedll_md5, condition='is', negate=False):
"""
Create a node for ServiceItem/serviceDLLmd5sum
:return: A IndicatorItem represented as an Element node
"""
document = 'ServiceItem'
search = 'ServiceItem/serviceDLLmd5sum'
content_type = 'md5'
c... | [
"def",
"make_serviceitem_servicedllmd5sum",
"(",
"servicedll_md5",
",",
"condition",
"=",
"'is'",
",",
"negate",
"=",
"False",
")",
":",
"document",
"=",
"'ServiceItem'",
"search",
"=",
"'ServiceItem/serviceDLLmd5sum'",
"content_type",
"=",
"'md5'",
"content",
"=",
... | Create a node for ServiceItem/serviceDLLmd5sum
:return: A IndicatorItem represented as an Element node | [
"Create",
"a",
"node",
"for",
"ServiceItem",
"/",
"serviceDLLmd5sum",
":",
"return",
":",
"A",
"IndicatorItem",
"represented",
"as",
"an",
"Element",
"node"
] | python | train | 39.153846 |
spotify/luigi | luigi/notifications.py | https://github.com/spotify/luigi/blob/c5eca1c3c3ee2a7eb612486192a0da146710a1e9/luigi/notifications.py#L264-L288 | def send_email_sns(sender, subject, message, topic_ARN, image_png):
"""
Sends notification through AWS SNS. Takes Topic ARN from recipients.
Does not handle access keys. Use either
1/ configuration file
2/ EC2 instance profile
See also https://boto3.readthedocs.io/en/latest/guide/configur... | [
"def",
"send_email_sns",
"(",
"sender",
",",
"subject",
",",
"message",
",",
"topic_ARN",
",",
"image_png",
")",
":",
"from",
"boto3",
"import",
"resource",
"as",
"boto3_resource",
"sns",
"=",
"boto3_resource",
"(",
"'sns'",
")",
"topic",
"=",
"sns",
".",
... | Sends notification through AWS SNS. Takes Topic ARN from recipients.
Does not handle access keys. Use either
1/ configuration file
2/ EC2 instance profile
See also https://boto3.readthedocs.io/en/latest/guide/configuration.html. | [
"Sends",
"notification",
"through",
"AWS",
"SNS",
".",
"Takes",
"Topic",
"ARN",
"from",
"recipients",
"."
] | python | train | 37.76 |
flowersteam/explauto | explauto/sensorimotor_model/inverse/cma.py | https://github.com/flowersteam/explauto/blob/cf0f81ecb9f6412f7276a95bd27359000e1e26b6/explauto/sensorimotor_model/inverse/cma.py#L7038-L7064 | def reeval(self, X, fit, func, ask, args=()):
"""store two fitness lists, `fit` and ``fitre`` reevaluating some
solutions in `X`.
``self.evaluations`` evaluations are done for each reevaluated
fitness value.
See `__call__()`, where `reeval()` is called.
"""
self.... | [
"def",
"reeval",
"(",
"self",
",",
"X",
",",
"fit",
",",
"func",
",",
"ask",
",",
"args",
"=",
"(",
")",
")",
":",
"self",
".",
"fit",
"=",
"list",
"(",
"fit",
")",
"self",
".",
"fitre",
"=",
"list",
"(",
"fit",
")",
"self",
".",
"idx",
"="... | store two fitness lists, `fit` and ``fitre`` reevaluating some
solutions in `X`.
``self.evaluations`` evaluations are done for each reevaluated
fitness value.
See `__call__()`, where `reeval()` is called. | [
"store",
"two",
"fitness",
"lists",
"fit",
"and",
"fitre",
"reevaluating",
"some",
"solutions",
"in",
"X",
".",
"self",
".",
"evaluations",
"evaluations",
"are",
"done",
"for",
"each",
"reevaluated",
"fitness",
"value",
".",
"See",
"__call__",
"()",
"where",
... | python | train | 42.703704 |
niolabs/python-xbee | xbee/frame.py | https://github.com/niolabs/python-xbee/blob/b91be3d0ee7ccaa1990120b5b5490999d8e6cbc7/xbee/frame.py#L124-L140 | def fill(self, byte):
"""
fill: byte -> None
Adds the given raw byte to this APIFrame. If this APIFrame is marked
as escaped and this byte is an escape byte, the next byte in a call
to fill() will be unescaped.
"""
if self._unescape_next_byte:
byte =... | [
"def",
"fill",
"(",
"self",
",",
"byte",
")",
":",
"if",
"self",
".",
"_unescape_next_byte",
":",
"byte",
"=",
"intToByte",
"(",
"byteToInt",
"(",
"byte",
")",
"^",
"0x20",
")",
"self",
".",
"_unescape_next_byte",
"=",
"False",
"elif",
"self",
".",
"es... | fill: byte -> None
Adds the given raw byte to this APIFrame. If this APIFrame is marked
as escaped and this byte is an escape byte, the next byte in a call
to fill() will be unescaped. | [
"fill",
":",
"byte",
"-",
">",
"None"
] | python | train | 32.882353 |
bitshares/uptick | uptick/callorders.py | https://github.com/bitshares/uptick/blob/66c102200fdbf96cef4fd55cc69d00e690f62001/uptick/callorders.py#L20-L57 | def calls(ctx, obj, limit):
""" List call/short positions of an account or an asset
"""
if obj.upper() == obj:
# Asset
from bitshares.asset import Asset
asset = Asset(obj, full=True)
calls = asset.get_call_orders(limit)
t = [["acount", "debt", "collateral", "call pri... | [
"def",
"calls",
"(",
"ctx",
",",
"obj",
",",
"limit",
")",
":",
"if",
"obj",
".",
"upper",
"(",
")",
"==",
"obj",
":",
"# Asset",
"from",
"bitshares",
".",
"asset",
"import",
"Asset",
"asset",
"=",
"Asset",
"(",
"obj",
",",
"full",
"=",
"True",
"... | List call/short positions of an account or an asset | [
"List",
"call",
"/",
"short",
"positions",
"of",
"an",
"account",
"or",
"an",
"asset"
] | python | train | 31.868421 |
NoviceLive/intellicoder | intellicoder/intellisense/database.py | https://github.com/NoviceLive/intellicoder/blob/6cac5ebfce65c370dbebe47756a1789b120ef982/intellicoder/intellisense/database.py#L267-L285 | def make_export(self, exports):
"""Populate library exported function data."""
sql = 'drop table if exists export'
logging.debug(sql)
self.cursor.execute(sql)
sql = 'create table if not exists export ' \
'(func text unique, module text)'
logging.debug(sql)
... | [
"def",
"make_export",
"(",
"self",
",",
"exports",
")",
":",
"sql",
"=",
"'drop table if exists export'",
"logging",
".",
"debug",
"(",
"sql",
")",
"self",
".",
"cursor",
".",
"execute",
"(",
"sql",
")",
"sql",
"=",
"'create table if not exists export '",
"'(f... | Populate library exported function data. | [
"Populate",
"library",
"exported",
"function",
"data",
"."
] | python | train | 39.157895 |
romanz/trezor-agent | libagent/gpg/agent.py | https://github.com/romanz/trezor-agent/blob/513b1259c4d7aca5f88cd958edc11828d0712f1b/libagent/gpg/agent.py#L24-L28 | def sig_encode(r, s):
"""Serialize ECDSA signature data into GPG S-expression."""
r = util.assuan_serialize(util.num2bytes(r, 32))
s = util.assuan_serialize(util.num2bytes(s, 32))
return b'(7:sig-val(5:ecdsa(1:r32:' + r + b')(1:s32:' + s + b')))' | [
"def",
"sig_encode",
"(",
"r",
",",
"s",
")",
":",
"r",
"=",
"util",
".",
"assuan_serialize",
"(",
"util",
".",
"num2bytes",
"(",
"r",
",",
"32",
")",
")",
"s",
"=",
"util",
".",
"assuan_serialize",
"(",
"util",
".",
"num2bytes",
"(",
"s",
",",
"... | Serialize ECDSA signature data into GPG S-expression. | [
"Serialize",
"ECDSA",
"signature",
"data",
"into",
"GPG",
"S",
"-",
"expression",
"."
] | python | train | 51.6 |
gorakhargosh/pepe | pepe/__init__.py | https://github.com/gorakhargosh/pepe/blob/1e40853378d515c99f03b3f59efa9b943d26eb62/pepe/__init__.py#L210-L454 | def preprocess(input_file,
output_file,
defines=None,
options=None,
content_types_db=None,
_preprocessed_files=None,
_depth=0):
"""
Preprocesses the specified file.
:param input_filename:
The input path.
:... | [
"def",
"preprocess",
"(",
"input_file",
",",
"output_file",
",",
"defines",
"=",
"None",
",",
"options",
"=",
"None",
",",
"content_types_db",
"=",
"None",
",",
"_preprocessed_files",
"=",
"None",
",",
"_depth",
"=",
"0",
")",
":",
"# Options that can later be... | Preprocesses the specified file.
:param input_filename:
The input path.
:param output_filename:
The output file (NOT path).
:param defines:
a dictionary of defined variables that will be
understood in preprocessor statements. Keys must be strings and,
currently, only... | [
"Preprocesses",
"the",
"specified",
"file",
"."
] | python | train | 45.457143 |
albahnsen/CostSensitiveClassification | costcla/datasets/base.py | https://github.com/albahnsen/CostSensitiveClassification/blob/75778ae32c70671c0cdde6c4651277b6a8b58871/costcla/datasets/base.py#L183-L249 | def load_creditscoring1(cost_mat_parameters=None):
"""Load and return the credit scoring Kaggle Credit competition dataset (classification).
The credit scoring is a easily transformable example-dependent cost-sensitive classification dataset.
Parameters
----------
cost_mat_parameters : Dictionary-... | [
"def",
"load_creditscoring1",
"(",
"cost_mat_parameters",
"=",
"None",
")",
":",
"module_path",
"=",
"dirname",
"(",
"__file__",
")",
"raw_data",
"=",
"pd",
".",
"read_csv",
"(",
"join",
"(",
"module_path",
",",
"'data'",
",",
"'creditscoring1.csv.gz'",
")",
"... | Load and return the credit scoring Kaggle Credit competition dataset (classification).
The credit scoring is a easily transformable example-dependent cost-sensitive classification dataset.
Parameters
----------
cost_mat_parameters : Dictionary-like object, optional (default=None)
If not None, ... | [
"Load",
"and",
"return",
"the",
"credit",
"scoring",
"Kaggle",
"Credit",
"competition",
"dataset",
"(",
"classification",
")",
"."
] | python | train | 42.41791 |
xflr6/bitsets | bitsets/bases.py | https://github.com/xflr6/bitsets/blob/ddcfe17e7c7a11f71f1c6764b2cecf7db05d9cdf/bitsets/bases.py#L60-L64 | def members(self, as_set=False):
"""Return the set members tuple/frozenset."""
if as_set:
return frozenset(map(self._members.__getitem__, self._indexes()))
return tuple(map(self._members.__getitem__, self._indexes())) | [
"def",
"members",
"(",
"self",
",",
"as_set",
"=",
"False",
")",
":",
"if",
"as_set",
":",
"return",
"frozenset",
"(",
"map",
"(",
"self",
".",
"_members",
".",
"__getitem__",
",",
"self",
".",
"_indexes",
"(",
")",
")",
")",
"return",
"tuple",
"(",
... | Return the set members tuple/frozenset. | [
"Return",
"the",
"set",
"members",
"tuple",
"/",
"frozenset",
"."
] | python | train | 49.8 |
brmscheiner/ideogram | ideogram/converter.py | https://github.com/brmscheiner/ideogram/blob/422bf566c51fd56f7bbb6e75b16d18d52b4c7568/ideogram/converter.py#L104-L111 | def formatBodyNode(root,path):
'''Format the root node for use as the body node.'''
body = root
body.name = "body"
body.weight = calcFnWeight(body)
body.path = path
body.pclass = None
return body | [
"def",
"formatBodyNode",
"(",
"root",
",",
"path",
")",
":",
"body",
"=",
"root",
"body",
".",
"name",
"=",
"\"body\"",
"body",
".",
"weight",
"=",
"calcFnWeight",
"(",
"body",
")",
"body",
".",
"path",
"=",
"path",
"body",
".",
"pclass",
"=",
"None"... | Format the root node for use as the body node. | [
"Format",
"the",
"root",
"node",
"for",
"use",
"as",
"the",
"body",
"node",
"."
] | python | train | 28.375 |
pytroll/satpy | satpy/readers/utils.py | https://github.com/pytroll/satpy/blob/1f21d20ac686b745fb0da9b4030d139893e066dd/satpy/readers/utils.py#L178-L193 | def get_sub_area(area, xslice, yslice):
"""Apply slices to the area_extent and size of the area."""
new_area_extent = ((area.pixel_upper_left[0] +
(xslice.start - 0.5) * area.pixel_size_x),
(area.pixel_upper_left[1] -
(yslice.stop - 0.5) * a... | [
"def",
"get_sub_area",
"(",
"area",
",",
"xslice",
",",
"yslice",
")",
":",
"new_area_extent",
"=",
"(",
"(",
"area",
".",
"pixel_upper_left",
"[",
"0",
"]",
"+",
"(",
"xslice",
".",
"start",
"-",
"0.5",
")",
"*",
"area",
".",
"pixel_size_x",
")",
",... | Apply slices to the area_extent and size of the area. | [
"Apply",
"slices",
"to",
"the",
"area_extent",
"and",
"size",
"of",
"the",
"area",
"."
] | python | train | 51.0625 |
NiklasRosenstein-Python/nr-deprecated | nr/py/context.py | https://github.com/NiklasRosenstein-Python/nr-deprecated/blob/f9f8b89ea1b084841a8ab65784eaf68852686b2a/nr/py/context.py#L61-L77 | def skip(stackframe=1):
"""
Must be called from within `__enter__()`. Performs some magic to have a
#ContextSkipped exception be raised the moment the with context is entered.
The #ContextSkipped must then be handled in `__exit__()` to suppress the
propagation of the exception.
> Important: This function d... | [
"def",
"skip",
"(",
"stackframe",
"=",
"1",
")",
":",
"def",
"trace",
"(",
"frame",
",",
"event",
",",
"args",
")",
":",
"raise",
"ContextSkipped",
"sys",
".",
"settrace",
"(",
"lambda",
"*",
"args",
",",
"*",
"*",
"kwargs",
":",
"None",
")",
"fram... | Must be called from within `__enter__()`. Performs some magic to have a
#ContextSkipped exception be raised the moment the with context is entered.
The #ContextSkipped must then be handled in `__exit__()` to suppress the
propagation of the exception.
> Important: This function does not raise an exception by it... | [
"Must",
"be",
"called",
"from",
"within",
"__enter__",
"()",
".",
"Performs",
"some",
"magic",
"to",
"have",
"a",
"#ContextSkipped",
"exception",
"be",
"raised",
"the",
"moment",
"the",
"with",
"context",
"is",
"entered",
".",
"The",
"#ContextSkipped",
"must",... | python | train | 35.411765 |
jrief/django-websocket-redis | ws4redis/websocket.py | https://github.com/jrief/django-websocket-redis/blob/abcddaad2f579d71dbf375e5e34bc35eef795a81/ws4redis/websocket.py#L157-L207 | def read_message(self):
"""
Return the next text or binary message from the socket.
This is an internal method as calling this will not cleanup correctly
if an exception is called. Use `receive` instead.
"""
opcode = None
message = None
while True:
... | [
"def",
"read_message",
"(",
"self",
")",
":",
"opcode",
"=",
"None",
"message",
"=",
"None",
"while",
"True",
":",
"header",
",",
"payload",
"=",
"self",
".",
"read_frame",
"(",
")",
"f_opcode",
"=",
"header",
".",
"opcode",
"if",
"f_opcode",
"in",
"("... | Return the next text or binary message from the socket.
This is an internal method as calling this will not cleanup correctly
if an exception is called. Use `receive` instead. | [
"Return",
"the",
"next",
"text",
"or",
"binary",
"message",
"from",
"the",
"socket",
"."
] | python | train | 40.215686 |
googleapis/google-cloud-python | storage/google/cloud/storage/notification.py | https://github.com/googleapis/google-cloud-python/blob/85e80125a59cb10f8cb105f25ecc099e4b940b50/storage/google/cloud/storage/notification.py#L291-L321 | def reload(self, client=None):
"""Update this notification from the server configuration.
See:
https://cloud.google.com/storage/docs/json_api/v1/notifications/get
If :attr:`user_project` is set on the bucket, bills the API request
to that project.
:type client: :class:... | [
"def",
"reload",
"(",
"self",
",",
"client",
"=",
"None",
")",
":",
"if",
"self",
".",
"notification_id",
"is",
"None",
":",
"raise",
"ValueError",
"(",
"\"Notification not intialized by server\"",
")",
"client",
"=",
"self",
".",
"_require_client",
"(",
"clie... | Update this notification from the server configuration.
See:
https://cloud.google.com/storage/docs/json_api/v1/notifications/get
If :attr:`user_project` is set on the bucket, bills the API request
to that project.
:type client: :class:`~google.cloud.storage.client.Client` or
... | [
"Update",
"this",
"notification",
"from",
"the",
"server",
"configuration",
"."
] | python | train | 36.83871 |
Karaage-Cluster/karaage | karaage/plugins/kgusage/tasks.py | https://github.com/Karaage-Cluster/karaage/blob/2f4c8b4e2d728b3fcbb151160c49000f1c04f5c9/karaage/plugins/kgusage/tasks.py#L365-L477 | def _gen_project_trend_graph(project, start, end, force_overwrite=False):
"""Generates a bar graph for a project
Keyword arguments:
project -- Project
start -- start date
end -- end date
"""
filename = graphs.get_project_trend_graph_filename(project, start, end)
csv_filename = os.path.... | [
"def",
"_gen_project_trend_graph",
"(",
"project",
",",
"start",
",",
"end",
",",
"force_overwrite",
"=",
"False",
")",
":",
"filename",
"=",
"graphs",
".",
"get_project_trend_graph_filename",
"(",
"project",
",",
"start",
",",
"end",
")",
"csv_filename",
"=",
... | Generates a bar graph for a project
Keyword arguments:
project -- Project
start -- start date
end -- end date | [
"Generates",
"a",
"bar",
"graph",
"for",
"a",
"project"
] | python | train | 27.415929 |
aws/sagemaker-python-sdk | src/sagemaker/amazon/common.py | https://github.com/aws/sagemaker-python-sdk/blob/a9e724c7d3f5572b68c3903548c792a59d99799a/src/sagemaker/amazon/common.py#L113-L150 | def write_spmatrix_to_sparse_tensor(file, array, labels=None):
"""Writes a scipy sparse matrix to a sparse tensor"""
if not issparse(array):
raise TypeError("Array must be sparse")
# Validate shape of array and labels, resolve array and label types
if not len(array.shape) == 2:
raise V... | [
"def",
"write_spmatrix_to_sparse_tensor",
"(",
"file",
",",
"array",
",",
"labels",
"=",
"None",
")",
":",
"if",
"not",
"issparse",
"(",
"array",
")",
":",
"raise",
"TypeError",
"(",
"\"Array must be sparse\"",
")",
"# Validate shape of array and labels, resolve array... | Writes a scipy sparse matrix to a sparse tensor | [
"Writes",
"a",
"scipy",
"sparse",
"matrix",
"to",
"a",
"sparse",
"tensor"
] | python | train | 36.342105 |
Guake/guake | guake/prefs.py | https://github.com/Guake/guake/blob/4153ef38f9044cbed6494075fce80acd5809df2b/guake/prefs.py#L907-L916 | def on_palette_name_changed(self, combo):
"""Changes the value of palette in dconf
"""
palette_name = combo.get_active_text()
if palette_name not in PALETTES:
return
self.settings.styleFont.set_string('palette', PALETTES[palette_name])
self.settings.styleFont.... | [
"def",
"on_palette_name_changed",
"(",
"self",
",",
"combo",
")",
":",
"palette_name",
"=",
"combo",
".",
"get_active_text",
"(",
")",
"if",
"palette_name",
"not",
"in",
"PALETTES",
":",
"return",
"self",
".",
"settings",
".",
"styleFont",
".",
"set_string",
... | Changes the value of palette in dconf | [
"Changes",
"the",
"value",
"of",
"palette",
"in",
"dconf"
] | python | train | 46.4 |
django-treebeard/django-treebeard | treebeard/mp_tree.py | https://github.com/django-treebeard/django-treebeard/blob/8042ee939cb45394909237da447f8925e3cc6aa3/treebeard/mp_tree.py#L1039-L1042 | def get_root(self):
""":returns: the root node for the current node object."""
return get_result_class(self.__class__).objects.get(
path=self.path[0:self.steplen]) | [
"def",
"get_root",
"(",
"self",
")",
":",
"return",
"get_result_class",
"(",
"self",
".",
"__class__",
")",
".",
"objects",
".",
"get",
"(",
"path",
"=",
"self",
".",
"path",
"[",
"0",
":",
"self",
".",
"steplen",
"]",
")"
] | :returns: the root node for the current node object. | [
":",
"returns",
":",
"the",
"root",
"node",
"for",
"the",
"current",
"node",
"object",
"."
] | python | train | 47 |
Cog-Creators/Red-Lavalink | lavalink/utils.py | https://github.com/Cog-Creators/Red-Lavalink/blob/5b3fc6eb31ee5db8bd2b633a523cf69749957111/lavalink/utils.py#L1-L6 | def format_time(time):
""" Formats the given time into HH:MM:SS """
h, r = divmod(time / 1000, 3600)
m, s = divmod(r, 60)
return "%02d:%02d:%02d" % (h, m, s) | [
"def",
"format_time",
"(",
"time",
")",
":",
"h",
",",
"r",
"=",
"divmod",
"(",
"time",
"/",
"1000",
",",
"3600",
")",
"m",
",",
"s",
"=",
"divmod",
"(",
"r",
",",
"60",
")",
"return",
"\"%02d:%02d:%02d\"",
"%",
"(",
"h",
",",
"m",
",",
"s",
... | Formats the given time into HH:MM:SS | [
"Formats",
"the",
"given",
"time",
"into",
"HH",
":",
"MM",
":",
"SS"
] | python | train | 28.166667 |
BerkeleyAutomation/perception | perception/image.py | https://github.com/BerkeleyAutomation/perception/blob/03d9b37dd6b66896cdfe173905c9413c8c3c5df6/perception/image.py#L3351-L3379 | def resize(self, size, interp='nearest'):
"""Resize the image.
Parameters
----------
size : int, float, or tuple
* int - Percentage of current size.
* float - Fraction of current size.
* tuple - Size of the output image.
interp : :obj:`str`... | [
"def",
"resize",
"(",
"self",
",",
"size",
",",
"interp",
"=",
"'nearest'",
")",
":",
"resized_data_0",
"=",
"sm",
".",
"imresize",
"(",
"self",
".",
"_data",
"[",
":",
",",
":",
",",
"0",
"]",
",",
"size",
",",
"interp",
"=",
"interp",
",",
"mod... | Resize the image.
Parameters
----------
size : int, float, or tuple
* int - Percentage of current size.
* float - Fraction of current size.
* tuple - Size of the output image.
interp : :obj:`str`, optional
Interpolation to use for re-si... | [
"Resize",
"the",
"image",
"."
] | python | train | 39.482759 |
jleclanche/fireplace | fireplace/dsl/evaluator.py | https://github.com/jleclanche/fireplace/blob/d0fc0e97e185c0210de86631be20638659c0609e/fireplace/dsl/evaluator.py#L52-L60 | def trigger(self, source):
"""
Triggers all actions meant to trigger on the board state from `source`.
"""
actions = self.evaluate(source)
if actions:
if not hasattr(actions, "__iter__"):
actions = (actions, )
source.game.trigger_actions(source, actions) | [
"def",
"trigger",
"(",
"self",
",",
"source",
")",
":",
"actions",
"=",
"self",
".",
"evaluate",
"(",
"source",
")",
"if",
"actions",
":",
"if",
"not",
"hasattr",
"(",
"actions",
",",
"\"__iter__\"",
")",
":",
"actions",
"=",
"(",
"actions",
",",
")"... | Triggers all actions meant to trigger on the board state from `source`. | [
"Triggers",
"all",
"actions",
"meant",
"to",
"trigger",
"on",
"the",
"board",
"state",
"from",
"source",
"."
] | python | train | 29.555556 |
adobe-apiplatform/umapi-client.py | umapi_client/connection.py | https://github.com/adobe-apiplatform/umapi-client.py/blob/1c446d79643cc8615adaa23e12dce3ac5782cf76/umapi_client/connection.py#L386-L412 | def _execute_batch(self, actions):
"""
Execute a single batch of Actions.
For each action that has a problem, we annotate the action with the
error information for that action, and we return the number of
successful actions in the batch.
:param actions: the list of Action... | [
"def",
"_execute_batch",
"(",
"self",
",",
"actions",
")",
":",
"wire_form",
"=",
"[",
"a",
".",
"wire_dict",
"(",
")",
"for",
"a",
"in",
"actions",
"]",
"if",
"self",
".",
"test_mode",
":",
"result",
"=",
"self",
".",
"make_call",
"(",
"\"/action/%s?t... | Execute a single batch of Actions.
For each action that has a problem, we annotate the action with the
error information for that action, and we return the number of
successful actions in the batch.
:param actions: the list of Action objects to be executed
:return: count of succe... | [
"Execute",
"a",
"single",
"batch",
"of",
"Actions",
".",
"For",
"each",
"action",
"that",
"has",
"a",
"problem",
"we",
"annotate",
"the",
"action",
"with",
"the",
"error",
"information",
"for",
"that",
"action",
"and",
"we",
"return",
"the",
"number",
"of"... | python | train | 47.777778 |
saltstack/salt | salt/modules/boto_iam.py | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/boto_iam.py#L160-L175 | def role_exists(name, region=None, key=None, keyid=None, profile=None):
'''
Check to see if an IAM role exists.
CLI Example:
.. code-block:: bash
salt myminion boto_iam.role_exists myirole
'''
conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)
try:
conn... | [
"def",
"role_exists",
"(",
"name",
",",
"region",
"=",
"None",
",",
"key",
"=",
"None",
",",
"keyid",
"=",
"None",
",",
"profile",
"=",
"None",
")",
":",
"conn",
"=",
"_get_conn",
"(",
"region",
"=",
"region",
",",
"key",
"=",
"key",
",",
"keyid",
... | Check to see if an IAM role exists.
CLI Example:
.. code-block:: bash
salt myminion boto_iam.role_exists myirole | [
"Check",
"to",
"see",
"if",
"an",
"IAM",
"role",
"exists",
"."
] | python | train | 25.25 |
Alignak-monitoring/alignak | alignak/scheduler.py | https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/scheduler.py#L503-L520 | def add_notification(self, notification):
"""Add a notification into actions list
:param notification: notification to add
:type notification: alignak.notification.Notification
:return: None
"""
if notification.uuid in self.actions:
logger.warning("Already ex... | [
"def",
"add_notification",
"(",
"self",
",",
"notification",
")",
":",
"if",
"notification",
".",
"uuid",
"in",
"self",
".",
"actions",
":",
"logger",
".",
"warning",
"(",
"\"Already existing notification: %s\"",
",",
"notification",
")",
"return",
"logger",
"."... | Add a notification into actions list
:param notification: notification to add
:type notification: alignak.notification.Notification
:return: None | [
"Add",
"a",
"notification",
"into",
"actions",
"list"
] | python | train | 38.333333 |
ibis-project/ibis | ibis/expr/api.py | https://github.com/ibis-project/ibis/blob/1e39a5fd9ef088b45c155e8a5f541767ee8ef2e7/ibis/expr/api.py#L1642-L1656 | def geo_perimeter(arg, use_spheroid=None):
"""
Compute perimeter of a geo spatial data
Parameters
----------
arg : geometry or geography
use_spheroid : default None
Returns
-------
perimeter : double scalar
"""
op = ops.GeoPerimeter(arg, use_spheroid)
return op.to_expr(... | [
"def",
"geo_perimeter",
"(",
"arg",
",",
"use_spheroid",
"=",
"None",
")",
":",
"op",
"=",
"ops",
".",
"GeoPerimeter",
"(",
"arg",
",",
"use_spheroid",
")",
"return",
"op",
".",
"to_expr",
"(",
")"
] | Compute perimeter of a geo spatial data
Parameters
----------
arg : geometry or geography
use_spheroid : default None
Returns
-------
perimeter : double scalar | [
"Compute",
"perimeter",
"of",
"a",
"geo",
"spatial",
"data"
] | python | train | 20.466667 |
Ceasar/staticjinja | staticjinja/staticjinja.py | https://github.com/Ceasar/staticjinja/blob/57b8cac81da7fee3387510af4843e1bd1fd3ba28/staticjinja/staticjinja.py#L321-L338 | def is_template(self, filename):
"""Check if a file is a template.
A file is a considered a template if it is neither a partial nor
ignored.
:param filename: the name of the file to check
"""
if self.is_partial(filename):
return False
if self.is_ign... | [
"def",
"is_template",
"(",
"self",
",",
"filename",
")",
":",
"if",
"self",
".",
"is_partial",
"(",
"filename",
")",
":",
"return",
"False",
"if",
"self",
".",
"is_ignored",
"(",
"filename",
")",
":",
"return",
"False",
"if",
"self",
".",
"is_static",
... | Check if a file is a template.
A file is a considered a template if it is neither a partial nor
ignored.
:param filename: the name of the file to check | [
"Check",
"if",
"a",
"file",
"is",
"a",
"template",
"."
] | python | train | 23.722222 |
saltstack/salt | salt/modules/mdata.py | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/mdata.py#L158-L183 | def delete_(*keyname):
'''
Delete metadata
prop : string
name of property
CLI Example:
.. code-block:: bash
salt '*' mdata.get salt:role
salt '*' mdata.get user-script salt:role
'''
mdata = _check_mdata_delete()
valid_keynames = list_()
ret = {}
for k... | [
"def",
"delete_",
"(",
"*",
"keyname",
")",
":",
"mdata",
"=",
"_check_mdata_delete",
"(",
")",
"valid_keynames",
"=",
"list_",
"(",
")",
"ret",
"=",
"{",
"}",
"for",
"k",
"in",
"keyname",
":",
"if",
"mdata",
"and",
"k",
"in",
"valid_keynames",
":",
... | Delete metadata
prop : string
name of property
CLI Example:
.. code-block:: bash
salt '*' mdata.get salt:role
salt '*' mdata.get user-script salt:role | [
"Delete",
"metadata"
] | python | train | 20.653846 |
prompt-toolkit/pyvim | pyvim/commands/commands.py | https://github.com/prompt-toolkit/pyvim/blob/5928b53b9d700863c1a06d2181a034a955f94594/pyvim/commands/commands.py#L229-L241 | def _buffer(editor, variables, force=False):
"""
Go to one of the open buffers.
"""
eb = editor.window_arrangement.active_editor_buffer
force = bool(variables['force'])
buffer_name = variables.get('buffer_name')
if buffer_name:
if not force and eb.has_unsaved_changes:
ed... | [
"def",
"_buffer",
"(",
"editor",
",",
"variables",
",",
"force",
"=",
"False",
")",
":",
"eb",
"=",
"editor",
".",
"window_arrangement",
".",
"active_editor_buffer",
"force",
"=",
"bool",
"(",
"variables",
"[",
"'force'",
"]",
")",
"buffer_name",
"=",
"var... | Go to one of the open buffers. | [
"Go",
"to",
"one",
"of",
"the",
"open",
"buffers",
"."
] | python | train | 33.615385 |
waqasbhatti/astrobase | astrobase/magnitudes.py | https://github.com/waqasbhatti/astrobase/blob/2922a14619d183fb28005fa7d02027ac436f2265/astrobase/magnitudes.py#L296-L316 | def jhk_to_sdssg(jmag,hmag,kmag):
'''Converts given J, H, Ks mags to an SDSS g magnitude value.
Parameters
----------
jmag,hmag,kmag : float
2MASS J, H, Ks mags of the object.
Returns
-------
float
The converted SDSS g band magnitude.
'''
return convert_constant... | [
"def",
"jhk_to_sdssg",
"(",
"jmag",
",",
"hmag",
",",
"kmag",
")",
":",
"return",
"convert_constants",
"(",
"jmag",
",",
"hmag",
",",
"kmag",
",",
"SDSSG_JHK",
",",
"SDSSG_JH",
",",
"SDSSG_JK",
",",
"SDSSG_HK",
",",
"SDSSG_J",
",",
"SDSSG_H",
",",
"SDSSG... | Converts given J, H, Ks mags to an SDSS g magnitude value.
Parameters
----------
jmag,hmag,kmag : float
2MASS J, H, Ks mags of the object.
Returns
-------
float
The converted SDSS g band magnitude. | [
"Converts",
"given",
"J",
"H",
"Ks",
"mags",
"to",
"an",
"SDSS",
"g",
"magnitude",
"value",
"."
] | python | valid | 22.47619 |
pandas-dev/pandas | pandas/core/internals/blocks.py | https://github.com/pandas-dev/pandas/blob/9feb3ad92cc0397a04b665803a49299ee7aa1037/pandas/core/internals/blocks.py#L1952-L1979 | def to_native_types(self, slicer=None, na_rep='', float_format=None,
decimal='.', quoting=None, **kwargs):
""" convert to our native types format, slicing if desired """
values = self.values
if slicer is not None:
values = values[:, slicer]
# see gh-... | [
"def",
"to_native_types",
"(",
"self",
",",
"slicer",
"=",
"None",
",",
"na_rep",
"=",
"''",
",",
"float_format",
"=",
"None",
",",
"decimal",
"=",
"'.'",
",",
"quoting",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"values",
"=",
"self",
".",
"... | convert to our native types format, slicing if desired | [
"convert",
"to",
"our",
"native",
"types",
"format",
"slicing",
"if",
"desired"
] | python | train | 40.535714 |
resonai/ybt | yabt/docker.py | https://github.com/resonai/ybt/blob/5b40df0922ef3383eb85f2b04a26a2db4b81b3fd/yabt/docker.py#L152-L181 | def handle_build_cache(
conf: Config, name: str, tag: str, icb: ImageCachingBehavior):
"""Handle Docker image build cache.
Return image ID if image is cached, and there's no need to redo the build.
Return None if need to build the image (whether cached locally or not).
Raise RuntimeError if not... | [
"def",
"handle_build_cache",
"(",
"conf",
":",
"Config",
",",
"name",
":",
"str",
",",
"tag",
":",
"str",
",",
"icb",
":",
"ImageCachingBehavior",
")",
":",
"if",
"icb",
".",
"pull_if_cached",
"or",
"(",
"icb",
".",
"pull_if_not_cached",
"and",
"get_cached... | Handle Docker image build cache.
Return image ID if image is cached, and there's no need to redo the build.
Return None if need to build the image (whether cached locally or not).
Raise RuntimeError if not allowed to build the image because of state of
local cache.
TODO(itamar): figure out a bette... | [
"Handle",
"Docker",
"image",
"build",
"cache",
"."
] | python | train | 45.533333 |
jobovy/galpy | galpy/util/bovy_coords.py | https://github.com/jobovy/galpy/blob/9c5b9fe65d58835624dffe432be282060918ee08/galpy/util/bovy_coords.py#L871-L903 | def cov_dvrpmllbb_to_vxyz_single(d,e_d,e_vr,pmll,pmbb,cov_pmllbb,l,b):
"""
NAME:
cov_dvrpmllbb_to_vxyz
PURPOSE:
propagate distance, radial velocity, and proper motion uncertainties to
Galactic coordinates for scalar inputs
INPUT:
d - distance [kpc, as/mas for plx]
e_d ... | [
"def",
"cov_dvrpmllbb_to_vxyz_single",
"(",
"d",
",",
"e_d",
",",
"e_vr",
",",
"pmll",
",",
"pmbb",
",",
"cov_pmllbb",
",",
"l",
",",
"b",
")",
":",
"M",
"=",
"_K",
"*",
"sc",
".",
"array",
"(",
"[",
"[",
"pmll",
",",
"d",
",",
"0.",
"]",
",",
... | NAME:
cov_dvrpmllbb_to_vxyz
PURPOSE:
propagate distance, radial velocity, and proper motion uncertainties to
Galactic coordinates for scalar inputs
INPUT:
d - distance [kpc, as/mas for plx]
e_d - distance uncertainty [kpc, [as/mas] for plx]
e_vr - low velocity uncertai... | [
"NAME",
":",
"cov_dvrpmllbb_to_vxyz",
"PURPOSE",
":",
"propagate",
"distance",
"radial",
"velocity",
"and",
"proper",
"motion",
"uncertainties",
"to",
"Galactic",
"coordinates",
"for",
"scalar",
"inputs",
"INPUT",
":",
"d",
"-",
"distance",
"[",
"kpc",
"as",
"/"... | python | train | 37.424242 |
Clinical-Genomics/scout | scout/parse/ensembl.py | https://github.com/Clinical-Genomics/scout/blob/90a551e2e1653a319e654c2405c2866f93d0ebb9/scout/parse/ensembl.py#L340-L395 | def parse_ensembl_exon_request(result):
"""Parse a dataframe with ensembl exon information
Args:
res(pandas.DataFrame)
Yields:
gene_info(dict)
"""
keys = [
'chrom',
'gene',
'transcript',
'exon_id',
'exon_chrom_start',
'exon_chrom_end'... | [
"def",
"parse_ensembl_exon_request",
"(",
"result",
")",
":",
"keys",
"=",
"[",
"'chrom'",
",",
"'gene'",
",",
"'transcript'",
",",
"'exon_id'",
",",
"'exon_chrom_start'",
",",
"'exon_chrom_end'",
",",
"'5_utr_start'",
",",
"'5_utr_end'",
",",
"'3_utr_start'",
","... | Parse a dataframe with ensembl exon information
Args:
res(pandas.DataFrame)
Yields:
gene_info(dict) | [
"Parse",
"a",
"dataframe",
"with",
"ensembl",
"exon",
"information"
] | python | test | 35.767857 |
edx/edx-django-utils | edx_django_utils/monitoring/middleware.py | https://github.com/edx/edx-django-utils/blob/16cb4ac617e53c572bf68ccd19d24afeff1ca769/edx_django_utils/monitoring/middleware.py#L145-L154 | def _log_prefix(self, prefix, request):
"""
Returns a formatted prefix for logging for the given request.
"""
# After a celery task runs, the request cache is cleared. So if celery
# tasks are running synchronously (CELERY_ALWAYS _EAGER), "guid_key"
# will no longer be in... | [
"def",
"_log_prefix",
"(",
"self",
",",
"prefix",
",",
"request",
")",
":",
"# After a celery task runs, the request cache is cleared. So if celery",
"# tasks are running synchronously (CELERY_ALWAYS _EAGER), \"guid_key\"",
"# will no longer be in the request cache when process_response exec... | Returns a formatted prefix for logging for the given request. | [
"Returns",
"a",
"formatted",
"prefix",
"for",
"logging",
"for",
"the",
"given",
"request",
"."
] | python | train | 61.8 |
buildbot/buildbot | master/buildbot/www/service.py | https://github.com/buildbot/buildbot/blob/5df3cfae6d760557d99156633c32b1822a1e130c/master/buildbot/www/service.py#L91-L108 | def updateSession(self, request):
"""
Update the cookie after session object was modified
@param request: the request object which should get a new cookie
"""
# we actually need to copy some hardcoded constants from twisted :-(
# Make sure we aren't creating a secure ses... | [
"def",
"updateSession",
"(",
"self",
",",
"request",
")",
":",
"# we actually need to copy some hardcoded constants from twisted :-(",
"# Make sure we aren't creating a secure session on a non-secure page",
"secure",
"=",
"request",
".",
"isSecure",
"(",
")",
"if",
"not",
"secu... | Update the cookie after session object was modified
@param request: the request object which should get a new cookie | [
"Update",
"the",
"cookie",
"after",
"session",
"object",
"was",
"modified"
] | python | train | 37.111111 |
odlgroup/odl | odl/util/ufuncs.py | https://github.com/odlgroup/odl/blob/b8443f6aca90e191ba36c91d32253c5a36249a6c/odl/util/ufuncs.py#L164-L174 | def max(self, axis=None, dtype=None, out=None, keepdims=False):
"""Return the maximum of ``self``.
See Also
--------
numpy.amax
min
"""
return self.elem.__array_ufunc__(
np.maximum, 'reduce', self.elem,
axis=axis, dtype=dtype, out=(out,), ... | [
"def",
"max",
"(",
"self",
",",
"axis",
"=",
"None",
",",
"dtype",
"=",
"None",
",",
"out",
"=",
"None",
",",
"keepdims",
"=",
"False",
")",
":",
"return",
"self",
".",
"elem",
".",
"__array_ufunc__",
"(",
"np",
".",
"maximum",
",",
"'reduce'",
","... | Return the maximum of ``self``.
See Also
--------
numpy.amax
min | [
"Return",
"the",
"maximum",
"of",
"self",
"."
] | python | train | 29.818182 |
viralogic/py-enumerable | py_linq/py_linq.py | https://github.com/viralogic/py-enumerable/blob/63363649bccef223379e1e87056747240c83aa9d/py_linq/py_linq.py#L428-L437 | def any(self, predicate):
"""
Returns true if any elements that satisfy predicate are found
:param predicate: condition to satisfy as lambda expression
:return: boolean True or False
"""
if predicate is None:
raise NullArgumentError(
u"predicat... | [
"def",
"any",
"(",
"self",
",",
"predicate",
")",
":",
"if",
"predicate",
"is",
"None",
":",
"raise",
"NullArgumentError",
"(",
"u\"predicate lambda expression is necessary\"",
")",
"return",
"self",
".",
"where",
"(",
"predicate",
")",
".",
"count",
"(",
")",... | Returns true if any elements that satisfy predicate are found
:param predicate: condition to satisfy as lambda expression
:return: boolean True or False | [
"Returns",
"true",
"if",
"any",
"elements",
"that",
"satisfy",
"predicate",
"are",
"found",
":",
"param",
"predicate",
":",
"condition",
"to",
"satisfy",
"as",
"lambda",
"expression",
":",
"return",
":",
"boolean",
"True",
"or",
"False"
] | python | train | 39.4 |
tensorflow/tensor2tensor | tensor2tensor/data_generators/text_problems.py | https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/data_generators/text_problems.py#L607-L611 | def txt_line_iterator(txt_path):
"""Iterate through lines of file."""
with tf.gfile.Open(txt_path) as f:
for line in f:
yield line.strip() | [
"def",
"txt_line_iterator",
"(",
"txt_path",
")",
":",
"with",
"tf",
".",
"gfile",
".",
"Open",
"(",
"txt_path",
")",
"as",
"f",
":",
"for",
"line",
"in",
"f",
":",
"yield",
"line",
".",
"strip",
"(",
")"
] | Iterate through lines of file. | [
"Iterate",
"through",
"lines",
"of",
"file",
"."
] | python | train | 29.6 |
ChrisTimperley/Kaskara | python/kaskara/functions.py | https://github.com/ChrisTimperley/Kaskara/blob/3d182d95b2938508e5990eddd30321be15e2f2ef/python/kaskara/functions.py#L97-L106 | def encloses(self,
location: FileLocation
) -> Optional[FunctionDesc]:
"""
Returns the function, if any, that encloses a given location.
"""
for func in self.in_file(location.filename):
if location in func.location:
return fun... | [
"def",
"encloses",
"(",
"self",
",",
"location",
":",
"FileLocation",
")",
"->",
"Optional",
"[",
"FunctionDesc",
"]",
":",
"for",
"func",
"in",
"self",
".",
"in_file",
"(",
"location",
".",
"filename",
")",
":",
"if",
"location",
"in",
"func",
".",
"l... | Returns the function, if any, that encloses a given location. | [
"Returns",
"the",
"function",
"if",
"any",
"that",
"encloses",
"a",
"given",
"location",
"."
] | python | train | 33.2 |
QualiSystems/vCenterShell | package/cloudshell/cp/vcenter/common/vcenter/vmomi_service.py | https://github.com/QualiSystems/vCenterShell/blob/e2e24cd938a92a68f4a8e6a860810d3ef72aae6d/package/cloudshell/cp/vcenter/common/vcenter/vmomi_service.py#L160-L168 | def find_datastore_by_name(self, si, path, name):
"""
Finds datastore in the vCenter or returns "None"
:param si: pyvmomi 'ServiceInstance'
:param path: the path to find the object ('dc' or 'dc/folder' or 'dc/folder/folder/etc...')
:param name: the datastore ... | [
"def",
"find_datastore_by_name",
"(",
"self",
",",
"si",
",",
"path",
",",
"name",
")",
":",
"return",
"self",
".",
"find_obj_by_path",
"(",
"si",
",",
"path",
",",
"name",
",",
"self",
".",
"Datastore",
")"
] | Finds datastore in the vCenter or returns "None"
:param si: pyvmomi 'ServiceInstance'
:param path: the path to find the object ('dc' or 'dc/folder' or 'dc/folder/folder/etc...')
:param name: the datastore name to return | [
"Finds",
"datastore",
"in",
"the",
"vCenter",
"or",
"returns",
"None"
] | python | train | 45.222222 |
rdeits/meshcat-python | src/meshcat/animation.py | https://github.com/rdeits/meshcat-python/blob/aa3865143120f5ace8e62aab71d825e33674d277/src/meshcat/animation.py#L132-L165 | def convert_frames_to_video(tar_file_path, output_path="output.mp4", framerate=60, overwrite=False):
"""
Try to convert a tar file containing a sequence of frames saved by the
meshcat viewer into a single video file.
This relies on having `ffmpeg` installed on your system.
"""
output_path = os.... | [
"def",
"convert_frames_to_video",
"(",
"tar_file_path",
",",
"output_path",
"=",
"\"output.mp4\"",
",",
"framerate",
"=",
"60",
",",
"overwrite",
"=",
"False",
")",
":",
"output_path",
"=",
"os",
".",
"path",
".",
"abspath",
"(",
"output_path",
")",
"if",
"o... | Try to convert a tar file containing a sequence of frames saved by the
meshcat viewer into a single video file.
This relies on having `ffmpeg` installed on your system. | [
"Try",
"to",
"convert",
"a",
"tar",
"file",
"containing",
"a",
"sequence",
"of",
"frames",
"saved",
"by",
"the",
"meshcat",
"viewer",
"into",
"a",
"single",
"video",
"file",
"."
] | python | valid | 43.735294 |
google/tangent | tangent/optimization.py | https://github.com/google/tangent/blob/6533e83af09de7345d1b438512679992f080dcc9/tangent/optimization.py#L62-L88 | def dead_code_elimination(node):
"""Perform a simple form of dead code elimination on a Python AST.
This method performs reaching definitions analysis on all function
definitions. It then looks for the definition of variables that are not used
elsewhere and removes those definitions.
This function takes int... | [
"def",
"dead_code_elimination",
"(",
"node",
")",
":",
"to_remove",
"=",
"set",
"(",
"def_",
"[",
"1",
"]",
"for",
"def_",
"in",
"annotate",
".",
"unused",
"(",
"node",
")",
"if",
"not",
"isinstance",
"(",
"def_",
"[",
"1",
"]",
",",
"(",
"gast",
"... | Perform a simple form of dead code elimination on a Python AST.
This method performs reaching definitions analysis on all function
definitions. It then looks for the definition of variables that are not used
elsewhere and removes those definitions.
This function takes into consideration push and pop statement... | [
"Perform",
"a",
"simple",
"form",
"of",
"dead",
"code",
"elimination",
"on",
"a",
"Python",
"AST",
"."
] | python | train | 36.518519 |
aiortc/aiortc | aiortc/rtcdtlstransport.py | https://github.com/aiortc/aiortc/blob/60ed036abf4575bd63985724b4493d569e6da29b/aiortc/rtcdtlstransport.py#L378-L459 | async def start(self, remoteParameters):
"""
Start DTLS transport negotiation with the parameters of the remote
DTLS transport.
:param: remoteParameters: An :class:`RTCDtlsParameters`.
"""
assert self._state == State.NEW
assert len(remoteParameters.fingerprints)
... | [
"async",
"def",
"start",
"(",
"self",
",",
"remoteParameters",
")",
":",
"assert",
"self",
".",
"_state",
"==",
"State",
".",
"NEW",
"assert",
"len",
"(",
"remoteParameters",
".",
"fingerprints",
")",
"if",
"self",
".",
"transport",
".",
"role",
"==",
"'... | Start DTLS transport negotiation with the parameters of the remote
DTLS transport.
:param: remoteParameters: An :class:`RTCDtlsParameters`. | [
"Start",
"DTLS",
"transport",
"negotiation",
"with",
"the",
"parameters",
"of",
"the",
"remote",
"DTLS",
"transport",
"."
] | python | train | 38.073171 |
romanvm/django-tinymce4-lite | tinymce/settings.py | https://github.com/romanvm/django-tinymce4-lite/blob/3b9221db5f0327e1e08c79b7b8cdbdcb1848a390/tinymce/settings.py#L12-L23 | def is_managed():
"""
Check if a Django project is being managed with ``manage.py`` or
``django-admin`` scripts
:return: Check result
:rtype: bool
"""
for item in sys.argv:
if re.search(r'manage.py|django-admin|django', item) is not None:
return True
return False | [
"def",
"is_managed",
"(",
")",
":",
"for",
"item",
"in",
"sys",
".",
"argv",
":",
"if",
"re",
".",
"search",
"(",
"r'manage.py|django-admin|django'",
",",
"item",
")",
"is",
"not",
"None",
":",
"return",
"True",
"return",
"False"
] | Check if a Django project is being managed with ``manage.py`` or
``django-admin`` scripts
:return: Check result
:rtype: bool | [
"Check",
"if",
"a",
"Django",
"project",
"is",
"being",
"managed",
"with",
"manage",
".",
"py",
"or",
"django",
"-",
"admin",
"scripts"
] | python | train | 25.416667 |
wandb/client | wandb/vendor/prompt_toolkit/cache.py | https://github.com/wandb/client/blob/7d08954ed5674fee223cd85ed0d8518fe47266b2/wandb/vendor/prompt_toolkit/cache.py#L96-L111 | def memoized(maxsize=1024):
"""
Momoization decorator for immutable classes and pure functions.
"""
cache = SimpleCache(maxsize=maxsize)
def decorator(obj):
@wraps(obj)
def new_callable(*a, **kw):
def create_new():
return obj(*a, **kw)
key = ... | [
"def",
"memoized",
"(",
"maxsize",
"=",
"1024",
")",
":",
"cache",
"=",
"SimpleCache",
"(",
"maxsize",
"=",
"maxsize",
")",
"def",
"decorator",
"(",
"obj",
")",
":",
"@",
"wraps",
"(",
"obj",
")",
"def",
"new_callable",
"(",
"*",
"a",
",",
"*",
"*"... | Momoization decorator for immutable classes and pure functions. | [
"Momoization",
"decorator",
"for",
"immutable",
"classes",
"and",
"pure",
"functions",
"."
] | python | train | 26.375 |
ncrocfer/similar | similar/similar.py | https://github.com/ncrocfer/similar/blob/94adde7d6f4fa924a6fc3e6be2dee62e48d0f608/similar/similar.py#L24-L37 | def results(self):
"""
Returns a list of tuple, ordered by similarity.
"""
d = dict()
words = [word.strip() for word in self.haystack]
if not words:
raise NoResultException('No similar word found.')
for w in words:
d[w] = Levenshtein.rati... | [
"def",
"results",
"(",
"self",
")",
":",
"d",
"=",
"dict",
"(",
")",
"words",
"=",
"[",
"word",
".",
"strip",
"(",
")",
"for",
"word",
"in",
"self",
".",
"haystack",
"]",
"if",
"not",
"words",
":",
"raise",
"NoResultException",
"(",
"'No similar word... | Returns a list of tuple, ordered by similarity. | [
"Returns",
"a",
"list",
"of",
"tuple",
"ordered",
"by",
"similarity",
"."
] | python | train | 28.571429 |
azraq27/neural | neural/general.py | https://github.com/azraq27/neural/blob/fe91bfeecbf73ad99708cf5dca66cb61fcd529f5/neural/general.py#L24-L30 | def voxel_loop(self):
'''iterator that loops through each voxel and yields the coords and time series as a tuple'''
# Prob not the most efficient, but the best I can do for now:
for x in xrange(len(self.data)):
for y in xrange(len(self.data[x])):
for z in xrange(len(s... | [
"def",
"voxel_loop",
"(",
"self",
")",
":",
"# Prob not the most efficient, but the best I can do for now:",
"for",
"x",
"in",
"xrange",
"(",
"len",
"(",
"self",
".",
"data",
")",
")",
":",
"for",
"y",
"in",
"xrange",
"(",
"len",
"(",
"self",
".",
"data",
... | iterator that loops through each voxel and yields the coords and time series as a tuple | [
"iterator",
"that",
"loops",
"through",
"each",
"voxel",
"and",
"yields",
"the",
"coords",
"and",
"time",
"series",
"as",
"a",
"tuple"
] | python | train | 55.142857 |
Kozea/cairocffi | cairocffi/context.py | https://github.com/Kozea/cairocffi/blob/450853add7e32eea20985b6aa5f54d9cb3cd04fe/cairocffi/context.py#L1839-L1850 | def get_font_options(self):
"""Retrieves font rendering options set via :meth:`set_font_options`.
Note that the returned options do not include any options
derived from the underlying surface;
they are literally the options passed to :meth:`set_font_options`.
:return: A new :cla... | [
"def",
"get_font_options",
"(",
"self",
")",
":",
"font_options",
"=",
"FontOptions",
"(",
")",
"cairo",
".",
"cairo_get_font_options",
"(",
"self",
".",
"_pointer",
",",
"font_options",
".",
"_pointer",
")",
"return",
"font_options"
] | Retrieves font rendering options set via :meth:`set_font_options`.
Note that the returned options do not include any options
derived from the underlying surface;
they are literally the options passed to :meth:`set_font_options`.
:return: A new :class:`FontOptions` object. | [
"Retrieves",
"font",
"rendering",
"options",
"set",
"via",
":",
"meth",
":",
"set_font_options",
".",
"Note",
"that",
"the",
"returned",
"options",
"do",
"not",
"include",
"any",
"options",
"derived",
"from",
"the",
"underlying",
"surface",
";",
"they",
"are",... | python | train | 40.5 |
mitsei/dlkit | dlkit/json_/learning/sessions.py | https://github.com/mitsei/dlkit/blob/445f968a175d61c8d92c0f617a3c17dc1dc7c584/dlkit/json_/learning/sessions.py#L6241-L6262 | def is_child_of_objective_bank(self, id_, objective_bank_id):
"""Tests if an objective bank is a direct child of another.
arg: id (osid.id.Id): an ``Id``
arg: objective_bank_id (osid.id.Id): the ``Id`` of an
objective bank
return: (boolean) - ``true`` if the ``id``... | [
"def",
"is_child_of_objective_bank",
"(",
"self",
",",
"id_",
",",
"objective_bank_id",
")",
":",
"# Implemented from template for",
"# osid.resource.BinHierarchySession.is_child_of_bin",
"if",
"self",
".",
"_catalog_session",
"is",
"not",
"None",
":",
"return",
"self",
"... | Tests if an objective bank is a direct child of another.
arg: id (osid.id.Id): an ``Id``
arg: objective_bank_id (osid.id.Id): the ``Id`` of an
objective bank
return: (boolean) - ``true`` if the ``id`` is a child of
``objective_bank_id,`` ``false`` otherwis... | [
"Tests",
"if",
"an",
"objective",
"bank",
"is",
"a",
"direct",
"child",
"of",
"another",
"."
] | python | train | 51.181818 |
toumorokoshi/sprinter | sprinter/formula/perforce.py | https://github.com/toumorokoshi/sprinter/blob/846697a7a087e69c61d075232e754d6975a64152/sprinter/formula/perforce.py#L144-L164 | def __install_perforce(self, config):
""" install perforce binary """
if not system.is_64_bit():
self.logger.warn("Perforce formula is only designed for 64 bit systems! Not install executables...")
return False
version = config.get('version', 'r13.2')
key = 'osx' ... | [
"def",
"__install_perforce",
"(",
"self",
",",
"config",
")",
":",
"if",
"not",
"system",
".",
"is_64_bit",
"(",
")",
":",
"self",
".",
"logger",
".",
"warn",
"(",
"\"Perforce formula is only designed for 64 bit systems! Not install executables...\"",
")",
"return",
... | install perforce binary | [
"install",
"perforce",
"binary"
] | python | train | 51.571429 |
edx/i18n-tools | i18n/dummy.py | https://github.com/edx/i18n-tools/blob/99b20c17d1a0ca07a8839f33e0e9068248a581e5/i18n/dummy.py#L217-L221 | def new_filename(original_filename, new_locale):
"""Returns a filename derived from original_filename, using new_locale as the locale"""
orig_file = Path(original_filename)
new_file = orig_file.parent.parent.parent / new_locale / orig_file.parent.name / orig_file.name
return new_file.abspath() | [
"def",
"new_filename",
"(",
"original_filename",
",",
"new_locale",
")",
":",
"orig_file",
"=",
"Path",
"(",
"original_filename",
")",
"new_file",
"=",
"orig_file",
".",
"parent",
".",
"parent",
".",
"parent",
"/",
"new_locale",
"/",
"orig_file",
".",
"parent"... | Returns a filename derived from original_filename, using new_locale as the locale | [
"Returns",
"a",
"filename",
"derived",
"from",
"original_filename",
"using",
"new_locale",
"as",
"the",
"locale"
] | python | train | 61.2 |
blockstack-packages/keychain-manager-py | keychain/utils.py | https://github.com/blockstack-packages/keychain-manager-py/blob/c15c4ed8f3ed155f71ccac7c13ee08f081d38c06/keychain/utils.py#L41-L55 | def bip32_deserialize(data):
"""
Derived from code from pybitcointools (https://github.com/vbuterin/pybitcointools)
by Vitalik Buterin
"""
dbin = changebase(data, 58, 256)
if bin_dbl_sha256(dbin[:-4])[:4] != dbin[-4:]:
raise Exception("Invalid checksum")
vbytes = dbin[0:4]
depth ... | [
"def",
"bip32_deserialize",
"(",
"data",
")",
":",
"dbin",
"=",
"changebase",
"(",
"data",
",",
"58",
",",
"256",
")",
"if",
"bin_dbl_sha256",
"(",
"dbin",
"[",
":",
"-",
"4",
"]",
")",
"[",
":",
"4",
"]",
"!=",
"dbin",
"[",
"-",
"4",
":",
"]",... | Derived from code from pybitcointools (https://github.com/vbuterin/pybitcointools)
by Vitalik Buterin | [
"Derived",
"from",
"code",
"from",
"pybitcointools",
"(",
"https",
":",
"//",
"github",
".",
"com",
"/",
"vbuterin",
"/",
"pybitcointools",
")",
"by",
"Vitalik",
"Buterin"
] | python | test | 36.533333 |
googleapis/google-cloud-python | logging/google/cloud/logging/_http.py | https://github.com/googleapis/google-cloud-python/blob/85e80125a59cb10f8cb105f25ecc099e4b940b50/logging/google/cloud/logging/_http.py#L354-L391 | def list_metrics(self, project, page_size=None, page_token=None):
"""List metrics for the project associated with this client.
See
https://cloud.google.com/logging/docs/reference/v2/rest/v2/projects.metrics/list
:type project: str
:param project: ID of the project whose metrics... | [
"def",
"list_metrics",
"(",
"self",
",",
"project",
",",
"page_size",
"=",
"None",
",",
"page_token",
"=",
"None",
")",
":",
"extra_params",
"=",
"{",
"}",
"if",
"page_size",
"is",
"not",
"None",
":",
"extra_params",
"[",
"\"pageSize\"",
"]",
"=",
"page_... | List metrics for the project associated with this client.
See
https://cloud.google.com/logging/docs/reference/v2/rest/v2/projects.metrics/list
:type project: str
:param project: ID of the project whose metrics are to be listed.
:type page_size: int
:param page_size: ma... | [
"List",
"metrics",
"for",
"the",
"project",
"associated",
"with",
"this",
"client",
"."
] | python | train | 36.684211 |
cltk/cltk | cltk/prosody/greek/scanner.py | https://github.com/cltk/cltk/blob/ed9c025b7ec43c949481173251b70e05e4dffd27/cltk/prosody/greek/scanner.py#L46-L62 | def _clean_text(self, text):
"""Clean the text of extraneous punction.
By default, ':', ';', and '.' are defined as stops.
:param text: raw text
:return: clean text
:rtype : string
"""
clean = []
for char in text:
if char in self.punc_stops:
... | [
"def",
"_clean_text",
"(",
"self",
",",
"text",
")",
":",
"clean",
"=",
"[",
"]",
"for",
"char",
"in",
"text",
":",
"if",
"char",
"in",
"self",
".",
"punc_stops",
":",
"clean",
"+=",
"'.'",
"elif",
"char",
"not",
"in",
"self",
".",
"punc",
":",
"... | Clean the text of extraneous punction.
By default, ':', ';', and '.' are defined as stops.
:param text: raw text
:return: clean text
:rtype : string | [
"Clean",
"the",
"text",
"of",
"extraneous",
"punction",
"."
] | python | train | 28.235294 |
msikma/kanaconv | kanaconv/converter.py | https://github.com/msikma/kanaconv/blob/194f142e616ab5dd6d13a687b96b9f8abd1b4ea8/kanaconv/converter.py#L722-L730 | def _add_punctuation_spacing(self, input):
'''
Adds additional spacing to punctuation characters. For example,
this puts an extra space after a fullwidth full stop.
'''
for replacement in punct_spacing:
input = re.sub(replacement[0], replacement[1], input)
re... | [
"def",
"_add_punctuation_spacing",
"(",
"self",
",",
"input",
")",
":",
"for",
"replacement",
"in",
"punct_spacing",
":",
"input",
"=",
"re",
".",
"sub",
"(",
"replacement",
"[",
"0",
"]",
",",
"replacement",
"[",
"1",
"]",
",",
"input",
")",
"return",
... | Adds additional spacing to punctuation characters. For example,
this puts an extra space after a fullwidth full stop. | [
"Adds",
"additional",
"spacing",
"to",
"punctuation",
"characters",
".",
"For",
"example",
"this",
"puts",
"an",
"extra",
"space",
"after",
"a",
"fullwidth",
"full",
"stop",
"."
] | python | train | 35.777778 |
saltstack/salt | salt/crypt.py | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/crypt.py#L1428-L1464 | def decrypt(self, data):
'''
verify HMAC-SHA256 signature and decrypt data with AES-CBC
'''
aes_key, hmac_key = self.keys
sig = data[-self.SIG_SIZE:]
data = data[:-self.SIG_SIZE]
if six.PY3 and not isinstance(data, bytes):
data = salt.utils.stringutils... | [
"def",
"decrypt",
"(",
"self",
",",
"data",
")",
":",
"aes_key",
",",
"hmac_key",
"=",
"self",
".",
"keys",
"sig",
"=",
"data",
"[",
"-",
"self",
".",
"SIG_SIZE",
":",
"]",
"data",
"=",
"data",
"[",
":",
"-",
"self",
".",
"SIG_SIZE",
"]",
"if",
... | verify HMAC-SHA256 signature and decrypt data with AES-CBC | [
"verify",
"HMAC",
"-",
"SHA256",
"signature",
"and",
"decrypt",
"data",
"with",
"AES",
"-",
"CBC"
] | python | train | 39.783784 |
google/grr | grr/server/grr_response_server/databases/mysql_utils.py | https://github.com/google/grr/blob/5cef4e8e2f0d5df43ea4877e9c798e0bf60bfe74/grr/server/grr_response_server/databases/mysql_utils.py#L141-L161 | def ComponentsToPath(components):
"""Converts a list of path components to a canonical path representation.
Args:
components: A sequence of path components.
Returns:
A canonical MySQL path representation.
"""
precondition.AssertIterableType(components, Text)
for component in components:
if not... | [
"def",
"ComponentsToPath",
"(",
"components",
")",
":",
"precondition",
".",
"AssertIterableType",
"(",
"components",
",",
"Text",
")",
"for",
"component",
"in",
"components",
":",
"if",
"not",
"component",
":",
"raise",
"ValueError",
"(",
"\"Empty path component ... | Converts a list of path components to a canonical path representation.
Args:
components: A sequence of path components.
Returns:
A canonical MySQL path representation. | [
"Converts",
"a",
"list",
"of",
"path",
"components",
"to",
"a",
"canonical",
"path",
"representation",
"."
] | python | train | 26.857143 |
jorgenkg/python-neural-network | nimblenet/cost_functions.py | https://github.com/jorgenkg/python-neural-network/blob/617b9940fa157d54d7831c42c0f7ba6857239b9a/nimblenet/cost_functions.py#L41-L50 | def softmax_categorical_cross_entropy_cost( outputs, targets, derivative=False, epsilon=1e-11 ):
"""
The output signals should be in the range [0, 1]
"""
outputs = np.clip(outputs, epsilon, 1 - epsilon)
if derivative:
return outputs - targets
else:
return np.mean(-np.sum(tar... | [
"def",
"softmax_categorical_cross_entropy_cost",
"(",
"outputs",
",",
"targets",
",",
"derivative",
"=",
"False",
",",
"epsilon",
"=",
"1e-11",
")",
":",
"outputs",
"=",
"np",
".",
"clip",
"(",
"outputs",
",",
"epsilon",
",",
"1",
"-",
"epsilon",
")",
"if"... | The output signals should be in the range [0, 1] | [
"The",
"output",
"signals",
"should",
"be",
"in",
"the",
"range",
"[",
"0",
"1",
"]"
] | python | train | 34.5 |
deschler/django-modeltranslation | modeltranslation/manager.py | https://github.com/deschler/django-modeltranslation/blob/18fec04a5105cbd83fc3759f4fda20135b3a848c/modeltranslation/manager.py#L79-L87 | def append_translated(model, fields):
"If translated field is encountered, add also all its translation fields."
fields = set(fields)
from modeltranslation.translator import translator
opts = translator.get_options_for_model(model)
for key, translated in opts.fields.items():
if key in fields... | [
"def",
"append_translated",
"(",
"model",
",",
"fields",
")",
":",
"fields",
"=",
"set",
"(",
"fields",
")",
"from",
"modeltranslation",
".",
"translator",
"import",
"translator",
"opts",
"=",
"translator",
".",
"get_options_for_model",
"(",
"model",
")",
"for... | If translated field is encountered, add also all its translation fields. | [
"If",
"translated",
"field",
"is",
"encountered",
"add",
"also",
"all",
"its",
"translation",
"fields",
"."
] | python | train | 43.666667 |
django-import-export/django-import-export | import_export/resources.py | https://github.com/django-import-export/django-import-export/blob/127f00d03fd0ad282615b064b7f444a639e6ff0c/import_export/resources.py#L910-L924 | def after_import(self, dataset, result, using_transactions, dry_run, **kwargs):
"""
Reset the SQL sequences after new objects are imported
"""
# Adapted from django's loaddata
if not dry_run and any(r.import_type == RowResult.IMPORT_TYPE_NEW for r in result.rows):
con... | [
"def",
"after_import",
"(",
"self",
",",
"dataset",
",",
"result",
",",
"using_transactions",
",",
"dry_run",
",",
"*",
"*",
"kwargs",
")",
":",
"# Adapted from django's loaddata",
"if",
"not",
"dry_run",
"and",
"any",
"(",
"r",
".",
"import_type",
"==",
"Ro... | Reset the SQL sequences after new objects are imported | [
"Reset",
"the",
"SQL",
"sequences",
"after",
"new",
"objects",
"are",
"imported"
] | python | train | 45.6 |
Nekroze/librarian | librarian/deck.py | https://github.com/Nekroze/librarian/blob/5d3da2980d91a637f80ad7164fbf204a2dd2bd58/librarian/deck.py#L22-L45 | def get_card(self, index=-1, cache=True, remove=True):
"""
Retrieve a card any number of cards from the top. Returns a
``Card`` object loaded from a library if one is specified otherwise
just it will simply return its code.
If `index` is not set then the top card will be retrie... | [
"def",
"get_card",
"(",
"self",
",",
"index",
"=",
"-",
"1",
",",
"cache",
"=",
"True",
",",
"remove",
"=",
"True",
")",
":",
"if",
"len",
"(",
"self",
".",
"cards",
")",
"<",
"index",
":",
"return",
"None",
"retriever",
"=",
"self",
".",
"cards"... | Retrieve a card any number of cards from the top. Returns a
``Card`` object loaded from a library if one is specified otherwise
just it will simply return its code.
If `index` is not set then the top card will be retrieved.
If cache is set to True (the default) it will tell the librar... | [
"Retrieve",
"a",
"card",
"any",
"number",
"of",
"cards",
"from",
"the",
"top",
".",
"Returns",
"a",
"Card",
"object",
"loaded",
"from",
"a",
"library",
"if",
"one",
"is",
"specified",
"otherwise",
"just",
"it",
"will",
"simply",
"return",
"its",
"code",
... | python | train | 35 |
Diaoul/subliminal | subliminal/subtitle.py | https://github.com/Diaoul/subliminal/blob/a952dfb2032eb0fd6eb1eb89f04080923c11c4cf/subliminal/subtitle.py#L185-L244 | def guess_matches(video, guess, partial=False):
"""Get matches between a `video` and a `guess`.
If a guess is `partial`, the absence information won't be counted as a match.
:param video: the video.
:type video: :class:`~subliminal.video.Video`
:param guess: the guess.
:type guess: dict
:p... | [
"def",
"guess_matches",
"(",
"video",
",",
"guess",
",",
"partial",
"=",
"False",
")",
":",
"matches",
"=",
"set",
"(",
")",
"if",
"isinstance",
"(",
"video",
",",
"Episode",
")",
":",
"# series",
"if",
"video",
".",
"series",
"and",
"'title'",
"in",
... | Get matches between a `video` and a `guess`.
If a guess is `partial`, the absence information won't be counted as a match.
:param video: the video.
:type video: :class:`~subliminal.video.Video`
:param guess: the guess.
:type guess: dict
:param bool partial: whether or not the guess is partial.... | [
"Get",
"matches",
"between",
"a",
"video",
"and",
"a",
"guess",
"."
] | python | train | 41.666667 |
singnet/snet-cli | snet_cli/mpe_channel_command.py | https://github.com/singnet/snet-cli/blob/1b5ac98cb9a64211c861ead9fcfe6208f2749032/snet_cli/mpe_channel_command.py#L21-L25 | def _get_persistent_mpe_dir(self):
""" get persistent storage for mpe """
mpe_address = self.get_mpe_address().lower()
registry_address = self.get_registry_address().lower()
return Path.home().joinpath(".snet", "mpe_client", "%s_%s"%(mpe_address, registry_address)) | [
"def",
"_get_persistent_mpe_dir",
"(",
"self",
")",
":",
"mpe_address",
"=",
"self",
".",
"get_mpe_address",
"(",
")",
".",
"lower",
"(",
")",
"registry_address",
"=",
"self",
".",
"get_registry_address",
"(",
")",
".",
"lower",
"(",
")",
"return",
"Path",
... | get persistent storage for mpe | [
"get",
"persistent",
"storage",
"for",
"mpe"
] | python | train | 59.6 |
bcbio/bcbio-nextgen | bcbio/variation/validateplot.py | https://github.com/bcbio/bcbio-nextgen/blob/6a9348c0054ccd5baffd22f1bb7d0422f6978b20/bcbio/variation/validateplot.py#L22-L33 | def classifyplot_from_plotfiles(plot_files, out_csv, outtype="png", title=None, size=None):
"""Create a plot from individual summary csv files with classification metrics.
"""
dfs = [pd.read_csv(x) for x in plot_files]
samples = []
for df in dfs:
for sample in df["sample"].unique():
... | [
"def",
"classifyplot_from_plotfiles",
"(",
"plot_files",
",",
"out_csv",
",",
"outtype",
"=",
"\"png\"",
",",
"title",
"=",
"None",
",",
"size",
"=",
"None",
")",
":",
"dfs",
"=",
"[",
"pd",
".",
"read_csv",
"(",
"x",
")",
"for",
"x",
"in",
"plot_files... | Create a plot from individual summary csv files with classification metrics. | [
"Create",
"a",
"plot",
"from",
"individual",
"summary",
"csv",
"files",
"with",
"classification",
"metrics",
"."
] | python | train | 42.833333 |
bcbio/bcbio-nextgen | bcbio/variation/vardict.py | https://github.com/bcbio/bcbio-nextgen/blob/6a9348c0054ccd5baffd22f1bb7d0422f6978b20/bcbio/variation/vardict.py#L129-L138 | def _get_jvm_opts(data, out_file):
"""Retrieve JVM options when running the Java version of VarDict.
"""
if get_vardict_command(data) == "vardict-java":
resources = config_utils.get_resources("vardict", data["config"])
jvm_opts = resources.get("jvm_opts", ["-Xms750m", "-Xmx4g"])
jvm_... | [
"def",
"_get_jvm_opts",
"(",
"data",
",",
"out_file",
")",
":",
"if",
"get_vardict_command",
"(",
"data",
")",
"==",
"\"vardict-java\"",
":",
"resources",
"=",
"config_utils",
".",
"get_resources",
"(",
"\"vardict\"",
",",
"data",
"[",
"\"config\"",
"]",
")",
... | Retrieve JVM options when running the Java version of VarDict. | [
"Retrieve",
"JVM",
"options",
"when",
"running",
"the",
"Java",
"version",
"of",
"VarDict",
"."
] | python | train | 46.8 |
selik/xport | xport/v56.py | https://github.com/selik/xport/blob/fafd15a24ccd102fc92d0c0123b9877a0c752182/xport/v56.py#L292-L309 | def header_match(cls, header):
'''
Parse the 4-line (320-byte) library member header.
'''
mo = cls.header_re.match(header)
if mo is None:
msg = f'Expected {cls.header_re.pattern!r}, got {header!r}'
raise ValueError(msg)
return {
'name':... | [
"def",
"header_match",
"(",
"cls",
",",
"header",
")",
":",
"mo",
"=",
"cls",
".",
"header_re",
".",
"match",
"(",
"header",
")",
"if",
"mo",
"is",
"None",
":",
"msg",
"=",
"f'Expected {cls.header_re.pattern!r}, got {header!r}'",
"raise",
"ValueError",
"(",
... | Parse the 4-line (320-byte) library member header. | [
"Parse",
"the",
"4",
"-",
"line",
"(",
"320",
"-",
"byte",
")",
"library",
"member",
"header",
"."
] | python | train | 38.5 |
tensorflow/probability | experimental/neutra/neutra_kernel.py | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/experimental/neutra/neutra_kernel.py#L350-L381 | def one_step(self, current_state, previous_kernel_results):
"""Runs one iteration of NeuTra.
Args:
current_state: `Tensor` or Python `list` of `Tensor`s representing the
current state(s) of the Markov chain(s). The first `r` dimensions index
independent chains, `r = tf.rank(target_log_pro... | [
"def",
"one_step",
"(",
"self",
",",
"current_state",
",",
"previous_kernel_results",
")",
":",
"@",
"tfp",
".",
"mcmc",
".",
"internal",
".",
"util",
".",
"make_innermost_setter",
"def",
"set_num_leapfrog_steps",
"(",
"kernel_results",
",",
"num_leapfrog_steps",
... | Runs one iteration of NeuTra.
Args:
current_state: `Tensor` or Python `list` of `Tensor`s representing the
current state(s) of the Markov chain(s). The first `r` dimensions index
independent chains, `r = tf.rank(target_log_prob_fn(*current_state))`.
previous_kernel_results: `collections... | [
"Runs",
"one",
"iteration",
"of",
"NeuTra",
"."
] | python | test | 46 |
tdryer/hangups | hangups/client.py | https://github.com/tdryer/hangups/blob/85c0bf0a57698d077461283895707260f9dbf931/hangups/client.py#L114-L148 | async def connect(self):
"""Establish a connection to the chat server.
Returns when an error has occurred, or :func:`disconnect` has been
called.
"""
proxy = os.environ.get('HTTP_PROXY')
self._session = http_utils.Session(self._cookies, proxy=proxy)
try:
... | [
"async",
"def",
"connect",
"(",
"self",
")",
":",
"proxy",
"=",
"os",
".",
"environ",
".",
"get",
"(",
"'HTTP_PROXY'",
")",
"self",
".",
"_session",
"=",
"http_utils",
".",
"Session",
"(",
"self",
".",
"_cookies",
",",
"proxy",
"=",
"proxy",
")",
"tr... | Establish a connection to the chat server.
Returns when an error has occurred, or :func:`disconnect` has been
called. | [
"Establish",
"a",
"connection",
"to",
"the",
"chat",
"server",
"."
] | python | valid | 44.028571 |
balloob/pychromecast | pychromecast/socket_client.py | https://github.com/balloob/pychromecast/blob/831b09c4fed185a7bffe0ea330b7849d5f4e36b6/pychromecast/socket_client.py#L586-L608 | def _cleanup(self):
""" Cleanup open channels and handlers """
for channel in self._open_channels:
try:
self.disconnect_channel(channel)
except Exception: # pylint: disable=broad-except
pass
for handler in self._handlers.values():
... | [
"def",
"_cleanup",
"(",
"self",
")",
":",
"for",
"channel",
"in",
"self",
".",
"_open_channels",
":",
"try",
":",
"self",
".",
"disconnect_channel",
"(",
"channel",
")",
"except",
"Exception",
":",
"# pylint: disable=broad-except",
"pass",
"for",
"handler",
"i... | Cleanup open channels and handlers | [
"Cleanup",
"open",
"channels",
"and",
"handlers"
] | python | train | 36.26087 |
pypa/pipenv | pipenv/vendor/pipdeptree.py | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/pipdeptree.py#L460-L476 | def conflicting_deps(tree):
"""Returns dependencies which are not present or conflict with the
requirements of other packages.
e.g. will warn if pkg1 requires pkg2==2.0 and pkg2==1.0 is installed
:param tree: the requirements tree (dict)
:returns: dict of DistPackage -> list of unsatisfied/unknown... | [
"def",
"conflicting_deps",
"(",
"tree",
")",
":",
"conflicting",
"=",
"defaultdict",
"(",
"list",
")",
"for",
"p",
",",
"rs",
"in",
"tree",
".",
"items",
"(",
")",
":",
"for",
"req",
"in",
"rs",
":",
"if",
"req",
".",
"is_conflicting",
"(",
")",
":... | Returns dependencies which are not present or conflict with the
requirements of other packages.
e.g. will warn if pkg1 requires pkg2==2.0 and pkg2==1.0 is installed
:param tree: the requirements tree (dict)
:returns: dict of DistPackage -> list of unsatisfied/unknown ReqPackage
:rtype: dict | [
"Returns",
"dependencies",
"which",
"are",
"not",
"present",
"or",
"conflict",
"with",
"the",
"requirements",
"of",
"other",
"packages",
"."
] | python | train | 31.411765 |
saltstack/salt | salt/modules/napalm_network.py | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/napalm_network.py#L2166-L2193 | def config_changed(inherit_napalm_device=None, **kwargs): # pylint: disable=unused-argument
'''
Will prompt if the configuration has been changed.
:return: A tuple with a boolean that specifies if the config was changed on the device.\
And a string that provides more details of the reason why the con... | [
"def",
"config_changed",
"(",
"inherit_napalm_device",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"# pylint: disable=unused-argument",
"is_config_changed",
"=",
"False",
"reason",
"=",
"''",
"try_compare",
"=",
"compare_config",
"(",
"inherit_napalm_device",
"=",... | Will prompt if the configuration has been changed.
:return: A tuple with a boolean that specifies if the config was changed on the device.\
And a string that provides more details of the reason why the configuration was not changed.
CLI Example:
.. code-block:: bash
salt '*' net.config_chang... | [
"Will",
"prompt",
"if",
"the",
"configuration",
"has",
"been",
"changed",
"."
] | python | train | 30.178571 |
fboender/ansible-cmdb | src/ansiblecmdb/ansible.py | https://github.com/fboender/ansible-cmdb/blob/ebd960ac10684e8c9ec2b12751bba2c4c9504ab7/src/ansiblecmdb/ansible.py#L348-L361 | def hosts_in_group(self, groupname):
"""
Return a list of hostnames that are in a group.
"""
result = []
for hostname, hostinfo in self.hosts.items():
if groupname == 'all':
result.append(hostname)
elif 'groups' in hostinfo:
... | [
"def",
"hosts_in_group",
"(",
"self",
",",
"groupname",
")",
":",
"result",
"=",
"[",
"]",
"for",
"hostname",
",",
"hostinfo",
"in",
"self",
".",
"hosts",
".",
"items",
"(",
")",
":",
"if",
"groupname",
"==",
"'all'",
":",
"result",
".",
"append",
"(... | Return a list of hostnames that are in a group. | [
"Return",
"a",
"list",
"of",
"hostnames",
"that",
"are",
"in",
"a",
"group",
"."
] | python | train | 34 |
portfors-lab/sparkle | sparkle/gui/plotting/calibration_explore_display.py | https://github.com/portfors-lab/sparkle/blob/5fad1cf2bec58ec6b15d91da20f6236a74826110/sparkle/gui/plotting/calibration_explore_display.py#L136-L143 | def setXlimits(self, lims):
"""Sets the X axis limits of the signal plots
:param lims: (min, max) of x axis, in same units as data
:type lims: (float, float)
"""
self.responseSignalPlot.setXlim(lims)
self.stimSignalPlot.setXlim(lims) | [
"def",
"setXlimits",
"(",
"self",
",",
"lims",
")",
":",
"self",
".",
"responseSignalPlot",
".",
"setXlim",
"(",
"lims",
")",
"self",
".",
"stimSignalPlot",
".",
"setXlim",
"(",
"lims",
")"
] | Sets the X axis limits of the signal plots
:param lims: (min, max) of x axis, in same units as data
:type lims: (float, float) | [
"Sets",
"the",
"X",
"axis",
"limits",
"of",
"the",
"signal",
"plots"
] | python | train | 34.375 |
mitsei/dlkit | dlkit/json_/repository/objects.py | https://github.com/mitsei/dlkit/blob/445f968a175d61c8d92c0f617a3c17dc1dc7c584/dlkit/json_/repository/objects.py#L1049-L1061 | def clear_provider_links(self):
"""Removes the provider chain.
raise: NoAccess - ``Metadata.isRequired()`` is ``true`` or
``Metadata.isReadOnly()`` is ``true``
*compliance: mandatory -- This method must be implemented.*
"""
# Implemented from template for osid.... | [
"def",
"clear_provider_links",
"(",
"self",
")",
":",
"# Implemented from template for osid.learning.ActivityForm.clear_assets_template",
"if",
"(",
"self",
".",
"get_provider_links_metadata",
"(",
")",
".",
"is_read_only",
"(",
")",
"or",
"self",
".",
"get_provider_links_m... | Removes the provider chain.
raise: NoAccess - ``Metadata.isRequired()`` is ``true`` or
``Metadata.isReadOnly()`` is ``true``
*compliance: mandatory -- This method must be implemented.* | [
"Removes",
"the",
"provider",
"chain",
"."
] | python | train | 45.384615 |
JoelBender/bacpypes | py25/bacpypes/bvll.py | https://github.com/JoelBender/bacpypes/blob/4111b8604a16fa2b7f80d8104a43b9f3e28dfc78/py25/bacpypes/bvll.py#L89-L103 | def bvlci_contents(self, use_dict=None, as_class=dict):
"""Return the contents of an object as a dict."""
if _debug: BVLCI._debug("bvlci_contents use_dict=%r as_class=%r", use_dict, as_class)
# make/extend the dictionary of content
if use_dict is None:
use_dict = as_class()
... | [
"def",
"bvlci_contents",
"(",
"self",
",",
"use_dict",
"=",
"None",
",",
"as_class",
"=",
"dict",
")",
":",
"if",
"_debug",
":",
"BVLCI",
".",
"_debug",
"(",
"\"bvlci_contents use_dict=%r as_class=%r\"",
",",
"use_dict",
",",
"as_class",
")",
"# make/extend the ... | Return the contents of an object as a dict. | [
"Return",
"the",
"contents",
"of",
"an",
"object",
"as",
"a",
"dict",
"."
] | python | train | 38.2 |
CZ-NIC/yangson | yangson/schpattern.py | https://github.com/CZ-NIC/yangson/blob/a4b9464041fa8b28f6020a420ababf18fddf5d4a/yangson/schpattern.py#L138-L140 | def nullable(self, ctype: ContentType) -> bool:
"""Override the superclass method."""
return (not self.check_when() or self.pattern.nullable(ctype)) | [
"def",
"nullable",
"(",
"self",
",",
"ctype",
":",
"ContentType",
")",
"->",
"bool",
":",
"return",
"(",
"not",
"self",
".",
"check_when",
"(",
")",
"or",
"self",
".",
"pattern",
".",
"nullable",
"(",
"ctype",
")",
")"
] | Override the superclass method. | [
"Override",
"the",
"superclass",
"method",
"."
] | python | train | 54 |
pantsbuild/pants | src/python/pants/java/nailgun_executor.py | https://github.com/pantsbuild/pants/blob/b72e650da0df685824ffdcc71988b8c282d0962d/src/python/pants/java/nailgun_executor.py#L113-L128 | def _fingerprint(jvm_options, classpath, java_version):
"""Compute a fingerprint for this invocation of a Java task.
:param list jvm_options: JVM options passed to the java invocation
:param list classpath: The -cp arguments passed to the java invocation
:param Revision java_version: return va... | [
"def",
"_fingerprint",
"(",
"jvm_options",
",",
"classpath",
",",
"java_version",
")",
":",
"digest",
"=",
"hashlib",
".",
"sha1",
"(",
")",
"# TODO(John Sirois): hash classpath contents?",
"encoded_jvm_options",
"=",
"[",
"option",
".",
"encode",
"(",
"'utf-8'",
... | Compute a fingerprint for this invocation of a Java task.
:param list jvm_options: JVM options passed to the java invocation
:param list classpath: The -cp arguments passed to the java invocation
:param Revision java_version: return value from Distribution.version()
:return: a hexstring rep... | [
"Compute",
"a",
"fingerprint",
"for",
"this",
"invocation",
"of",
"a",
"Java",
"task",
"."
] | python | train | 57.75 |
msmbuilder/msmbuilder | msmbuilder/msm/ratematrix.py | https://github.com/msmbuilder/msmbuilder/blob/556a93a170782f47be53f4a1e9d740fb1c8272b3/msmbuilder/msm/ratematrix.py#L271-L293 | def _initial_guess(self, countsmat):
"""Generate an initial guess for \theta.
"""
if self.theta_ is not None:
return self.theta_
if self.guess == 'log':
transmat, pi = _transmat_mle_prinz(countsmat)
K = np.real(scipy.linalg.logm(transmat)) / self.lag... | [
"def",
"_initial_guess",
"(",
"self",
",",
"countsmat",
")",
":",
"if",
"self",
".",
"theta_",
"is",
"not",
"None",
":",
"return",
"self",
".",
"theta_",
"if",
"self",
".",
"guess",
"==",
"'log'",
":",
"transmat",
",",
"pi",
"=",
"_transmat_mle_prinz",
... | Generate an initial guess for \theta. | [
"Generate",
"an",
"initial",
"guess",
"for",
"\\",
"theta",
"."
] | python | train | 35.304348 |
josuebrunel/myql | myql/utils.py | https://github.com/josuebrunel/myql/blob/891bad29cc83a81b3f5ebc4d0401d6f2c22f119e/myql/utils.py#L12-L16 | def pretty_xml(data):
"""Return a pretty formated xml
"""
parsed_string = minidom.parseString(data.decode('utf-8'))
return parsed_string.toprettyxml(indent='\t', encoding='utf-8') | [
"def",
"pretty_xml",
"(",
"data",
")",
":",
"parsed_string",
"=",
"minidom",
".",
"parseString",
"(",
"data",
".",
"decode",
"(",
"'utf-8'",
")",
")",
"return",
"parsed_string",
".",
"toprettyxml",
"(",
"indent",
"=",
"'\\t'",
",",
"encoding",
"=",
"'utf-8... | Return a pretty formated xml | [
"Return",
"a",
"pretty",
"formated",
"xml"
] | python | train | 38.2 |
iotile/coretools | iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Tool/PharLapCommon.py | https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Tool/PharLapCommon.py#L68-L86 | def getPharLapVersion():
"""Returns the version of the installed ETS Tool Suite as a
decimal number. This version comes from the ETS_VER #define in
the embkern.h header. For example, '#define ETS_VER 1010' (which
is what Phar Lap 10.1 defines) would cause this method to return
1010. Phar Lap 9.1 d... | [
"def",
"getPharLapVersion",
"(",
")",
":",
"include_path",
"=",
"os",
".",
"path",
".",
"join",
"(",
"getPharLapPath",
"(",
")",
",",
"os",
".",
"path",
".",
"normpath",
"(",
"\"include/embkern.h\"",
")",
")",
"if",
"not",
"os",
".",
"path",
".",
"exis... | Returns the version of the installed ETS Tool Suite as a
decimal number. This version comes from the ETS_VER #define in
the embkern.h header. For example, '#define ETS_VER 1010' (which
is what Phar Lap 10.1 defines) would cause this method to return
1010. Phar Lap 9.1 does not have such a #define, but... | [
"Returns",
"the",
"version",
"of",
"the",
"installed",
"ETS",
"Tool",
"Suite",
"as",
"a",
"decimal",
"number",
".",
"This",
"version",
"comes",
"from",
"the",
"ETS_VER",
"#define",
"in",
"the",
"embkern",
".",
"h",
"header",
".",
"For",
"example",
"#define... | python | train | 45.947368 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.