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 |
|---|---|---|---|---|---|---|---|---|---|
pandeylab/pythomics | pythomics/genomics/structures.py | https://github.com/pandeylab/pythomics/blob/ab0a5651a2e02a25def4d277b35fa09d1631bfcb/pythomics/genomics/structures.py#L63-L70 | def parse_entry(self, row):
"""Parse an individual VCF entry and return a VCFEntry which contains information about
the call (such as alternative allele, zygosity, etc.)
"""
var_call = VCFEntry(self.individuals)
var_call.parse_entry(row)
return var_call | [
"def",
"parse_entry",
"(",
"self",
",",
"row",
")",
":",
"var_call",
"=",
"VCFEntry",
"(",
"self",
".",
"individuals",
")",
"var_call",
".",
"parse_entry",
"(",
"row",
")",
"return",
"var_call"
] | Parse an individual VCF entry and return a VCFEntry which contains information about
the call (such as alternative allele, zygosity, etc.) | [
"Parse",
"an",
"individual",
"VCF",
"entry",
"and",
"return",
"a",
"VCFEntry",
"which",
"contains",
"information",
"about",
"the",
"call",
"(",
"such",
"as",
"alternative",
"allele",
"zygosity",
"etc",
".",
")"
] | python | train | 36.875 |
coldfix/udiskie | udiskie/mount.py | https://github.com/coldfix/udiskie/blob/804c9d27df6f7361fec3097c432398f2d702f911/udiskie/mount.py#L691-L700 | def get_all_handleable_roots(self):
"""
Get list of all handleable devices, return only those that represent
root nodes within the filtered device tree.
"""
nodes = self.get_device_tree()
return [node.device
for node in sorted(nodes.values(), key=DevNode._... | [
"def",
"get_all_handleable_roots",
"(",
"self",
")",
":",
"nodes",
"=",
"self",
".",
"get_device_tree",
"(",
")",
"return",
"[",
"node",
".",
"device",
"for",
"node",
"in",
"sorted",
"(",
"nodes",
".",
"values",
"(",
")",
",",
"key",
"=",
"DevNode",
".... | Get list of all handleable devices, return only those that represent
root nodes within the filtered device tree. | [
"Get",
"list",
"of",
"all",
"handleable",
"devices",
"return",
"only",
"those",
"that",
"represent",
"root",
"nodes",
"within",
"the",
"filtered",
"device",
"tree",
"."
] | python | train | 44 |
fabioz/PyDev.Debugger | pydevd_attach_to_process/winappdbg/sql.py | https://github.com/fabioz/PyDev.Debugger/blob/ed9c4307662a5593b8a7f1f3389ecd0e79b8c503/pydevd_attach_to_process/winappdbg/sql.py#L314-L320 | def Transactional(fn, self, *argv, **argd):
"""
Decorator that wraps DAO methods to handle transactions automatically.
It may only work with subclasses of L{BaseDAO}.
"""
return self._transactional(fn, *argv, **argd) | [
"def",
"Transactional",
"(",
"fn",
",",
"self",
",",
"*",
"argv",
",",
"*",
"*",
"argd",
")",
":",
"return",
"self",
".",
"_transactional",
"(",
"fn",
",",
"*",
"argv",
",",
"*",
"*",
"argd",
")"
] | Decorator that wraps DAO methods to handle transactions automatically.
It may only work with subclasses of L{BaseDAO}. | [
"Decorator",
"that",
"wraps",
"DAO",
"methods",
"to",
"handle",
"transactions",
"automatically",
"."
] | python | train | 33 |
ianmiell/shutit | shutit_pexpect.py | https://github.com/ianmiell/shutit/blob/19cd64cdfb23515b106b40213dccff4101617076/shutit_pexpect.py#L1884-L1904 | def get_env_pass(self,user=None,msg=None,note=None):
"""Gets a password from the user if one is not already recorded for this environment.
@param user: username we are getting password for
@param msg: message to put out there
"""
shutit = self.shutit
shutit.handle_note(note)
user = user or self.wh... | [
"def",
"get_env_pass",
"(",
"self",
",",
"user",
"=",
"None",
",",
"msg",
"=",
"None",
",",
"note",
"=",
"None",
")",
":",
"shutit",
"=",
"self",
".",
"shutit",
"shutit",
".",
"handle_note",
"(",
"note",
")",
"user",
"=",
"user",
"or",
"self",
".",... | Gets a password from the user if one is not already recorded for this environment.
@param user: username we are getting password for
@param msg: message to put out there | [
"Gets",
"a",
"password",
"from",
"the",
"user",
"if",
"one",
"is",
"not",
"already",
"recorded",
"for",
"this",
"environment",
"."
] | python | train | 40.619048 |
ml4ai/delphi | delphi/AnalysisGraph.py | https://github.com/ml4ai/delphi/blob/6d03d8aafeab99610387c51b89c99738ff2abbe3/delphi/AnalysisGraph.py#L151-L157 | def from_uncharted_json_file(cls, file):
""" Construct an AnalysisGraph object from a file containing INDRA
statements serialized exported by Uncharted's CauseMos webapp.
"""
with open(file, "r") as f:
_dict = json.load(f)
return cls.from_uncharted_json_serialized_dic... | [
"def",
"from_uncharted_json_file",
"(",
"cls",
",",
"file",
")",
":",
"with",
"open",
"(",
"file",
",",
"\"r\"",
")",
"as",
"f",
":",
"_dict",
"=",
"json",
".",
"load",
"(",
"f",
")",
"return",
"cls",
".",
"from_uncharted_json_serialized_dict",
"(",
"_di... | Construct an AnalysisGraph object from a file containing INDRA
statements serialized exported by Uncharted's CauseMos webapp. | [
"Construct",
"an",
"AnalysisGraph",
"object",
"from",
"a",
"file",
"containing",
"INDRA",
"statements",
"serialized",
"exported",
"by",
"Uncharted",
"s",
"CauseMos",
"webapp",
"."
] | python | train | 46 |
aleju/imgaug | imgaug/augmentables/segmaps.py | https://github.com/aleju/imgaug/blob/786be74aa855513840113ea523c5df495dc6a8af/imgaug/augmentables/segmaps.py#L424-L455 | def resize(self, sizes, interpolation="cubic"):
"""
Resize the segmentation map array to the provided size given the provided interpolation.
Parameters
----------
sizes : float or iterable of int or iterable of float
New size of the array in ``(height, width)``.
... | [
"def",
"resize",
"(",
"self",
",",
"sizes",
",",
"interpolation",
"=",
"\"cubic\"",
")",
":",
"arr_resized",
"=",
"ia",
".",
"imresize_single_image",
"(",
"self",
".",
"arr",
",",
"sizes",
",",
"interpolation",
"=",
"interpolation",
")",
"# cubic interpolation... | Resize the segmentation map array to the provided size given the provided interpolation.
Parameters
----------
sizes : float or iterable of int or iterable of float
New size of the array in ``(height, width)``.
See :func:`imgaug.imgaug.imresize_single_image` for details.... | [
"Resize",
"the",
"segmentation",
"map",
"array",
"to",
"the",
"provided",
"size",
"given",
"the",
"provided",
"interpolation",
"."
] | python | valid | 41.84375 |
cuihantao/andes | andes/system.py | https://github.com/cuihantao/andes/blob/7067898d4f26ce7534e968b8486c4aa8fe3a511a/andes/system.py#L466-L494 | def dump_config(self, file_path):
"""
Dump system and routine configurations to an rc-formatted file.
Parameters
----------
file_path : str
path to the configuration file. The user will be prompted if the
file already exists.
Returns
----... | [
"def",
"dump_config",
"(",
"self",
",",
"file_path",
")",
":",
"if",
"os",
".",
"path",
".",
"isfile",
"(",
"file_path",
")",
":",
"logger",
".",
"debug",
"(",
"'File {} alreay exist. Overwrite? [y/N]'",
".",
"format",
"(",
"file_path",
")",
")",
"choice",
... | Dump system and routine configurations to an rc-formatted file.
Parameters
----------
file_path : str
path to the configuration file. The user will be prompted if the
file already exists.
Returns
-------
None | [
"Dump",
"system",
"and",
"routine",
"configurations",
"to",
"an",
"rc",
"-",
"formatted",
"file",
"."
] | python | train | 32.37931 |
mitsei/dlkit | dlkit/services/relationship.py | https://github.com/mitsei/dlkit/blob/445f968a175d61c8d92c0f617a3c17dc1dc7c584/dlkit/services/relationship.py#L1107-L1115 | def get_relationship_form(self, *args, **kwargs):
"""Pass through to provider RelationshipAdminSession.get_relationship_form_for_update"""
# Implemented from kitosid template for -
# osid.resource.ResourceAdminSession.get_resource_form_for_update
# This method might be a bit sketchy. Tim... | [
"def",
"get_relationship_form",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"# Implemented from kitosid template for -",
"# osid.resource.ResourceAdminSession.get_resource_form_for_update",
"# This method might be a bit sketchy. Time will tell.",
"if",
"isinst... | Pass through to provider RelationshipAdminSession.get_relationship_form_for_update | [
"Pass",
"through",
"to",
"provider",
"RelationshipAdminSession",
".",
"get_relationship_form_for_update"
] | python | train | 62.888889 |
Tivix/django-common | django_common/decorators.py | https://github.com/Tivix/django-common/blob/407d208121011a8425139e541629554114d96c18/django_common/decorators.py#L47-L59 | def anonymous_required(view, redirect_to=None):
"""
Only allow if user is NOT authenticated.
"""
if redirect_to is None:
redirect_to = settings.LOGIN_REDIRECT_URL
@wraps(view)
def wrapper(request, *a, **k):
if request.user and request.user.is_authenticated():
return ... | [
"def",
"anonymous_required",
"(",
"view",
",",
"redirect_to",
"=",
"None",
")",
":",
"if",
"redirect_to",
"is",
"None",
":",
"redirect_to",
"=",
"settings",
".",
"LOGIN_REDIRECT_URL",
"@",
"wraps",
"(",
"view",
")",
"def",
"wrapper",
"(",
"request",
",",
"... | Only allow if user is NOT authenticated. | [
"Only",
"allow",
"if",
"user",
"is",
"NOT",
"authenticated",
"."
] | python | train | 30.615385 |
aws/aws-dynamodb-encryption-python | src/dynamodb_encryption_sdk/transform.py | https://github.com/aws/aws-dynamodb-encryption-python/blob/8de3bbe13df39c59b21bf431010f7acfcf629a2f/src/dynamodb_encryption_sdk/transform.py#L25-L35 | def dict_to_ddb(item):
# type: (Dict[str, Any]) -> Dict[str, Any]
# TODO: narrow these types down
"""Converts a native Python dictionary to a raw DynamoDB item.
:param dict item: Native item
:returns: DynamoDB item
:rtype: dict
"""
serializer = TypeSerializer()
return {key: serializ... | [
"def",
"dict_to_ddb",
"(",
"item",
")",
":",
"# type: (Dict[str, Any]) -> Dict[str, Any]",
"# TODO: narrow these types down",
"serializer",
"=",
"TypeSerializer",
"(",
")",
"return",
"{",
"key",
":",
"serializer",
".",
"serialize",
"(",
"value",
")",
"for",
"key",
"... | Converts a native Python dictionary to a raw DynamoDB item.
:param dict item: Native item
:returns: DynamoDB item
:rtype: dict | [
"Converts",
"a",
"native",
"Python",
"dictionary",
"to",
"a",
"raw",
"DynamoDB",
"item",
"."
] | python | train | 32.818182 |
pmacosta/ptrie | ptrie/ptrie.py | https://github.com/pmacosta/ptrie/blob/c176d3ee810b7b5243c7ff2bbf2f1af0b0fff2a8/ptrie/ptrie.py#L1030-L1075 | def make_root(self, name): # noqa: D302
r"""
Make a sub-node the root node of the tree.
All nodes not belonging to the sub-tree are deleted
:param name: New root node name
:type name: :ref:`NodeName`
:raises:
* RuntimeError (Argument \`name\` is not valid)
... | [
"def",
"make_root",
"(",
"self",
",",
"name",
")",
":",
"# noqa: D302",
"if",
"self",
".",
"_validate_node_name",
"(",
"name",
")",
":",
"raise",
"RuntimeError",
"(",
"\"Argument `name` is not valid\"",
")",
"if",
"(",
"name",
"!=",
"self",
".",
"root_name",
... | r"""
Make a sub-node the root node of the tree.
All nodes not belonging to the sub-tree are deleted
:param name: New root node name
:type name: :ref:`NodeName`
:raises:
* RuntimeError (Argument \`name\` is not valid)
* RuntimeError (Node *[name]* not in tre... | [
"r",
"Make",
"a",
"sub",
"-",
"node",
"the",
"root",
"node",
"of",
"the",
"tree",
"."
] | python | train | 31.695652 |
clld/pycdstar | src/pycdstar/media.py | https://github.com/clld/pycdstar/blob/1a225b472c4e6bf9b8078fa3198f939395c53d22/src/pycdstar/media.py#L85-L106 | def create_object(self, api, metadata=None):
"""
Create an object using the CDSTAR API, with the file content as bitstream.
:param api:
:return:
"""
metadata = {k: v for k, v in (metadata or {}).items()}
metadata.setdefault('creator', '{0.__name__} {0.__version__... | [
"def",
"create_object",
"(",
"self",
",",
"api",
",",
"metadata",
"=",
"None",
")",
":",
"metadata",
"=",
"{",
"k",
":",
"v",
"for",
"k",
",",
"v",
"in",
"(",
"metadata",
"or",
"{",
"}",
")",
".",
"items",
"(",
")",
"}",
"metadata",
".",
"setde... | Create an object using the CDSTAR API, with the file content as bitstream.
:param api:
:return: | [
"Create",
"an",
"object",
"using",
"the",
"CDSTAR",
"API",
"with",
"the",
"file",
"content",
"as",
"bitstream",
"."
] | python | train | 36.045455 |
notifiers/notifiers | notifiers/utils/helpers.py | https://github.com/notifiers/notifiers/blob/6dd8aafff86935dbb4763db9c56f9cdd7fc08b65/notifiers/utils/helpers.py#L9-L18 | def text_to_bool(value: str) -> bool:
"""
Tries to convert a text value to a bool. If unsuccessful returns if value is None or not
:param value: Value to check
"""
try:
return bool(strtobool(value))
except (ValueError, AttributeError):
return value is not None | [
"def",
"text_to_bool",
"(",
"value",
":",
"str",
")",
"->",
"bool",
":",
"try",
":",
"return",
"bool",
"(",
"strtobool",
"(",
"value",
")",
")",
"except",
"(",
"ValueError",
",",
"AttributeError",
")",
":",
"return",
"value",
"is",
"not",
"None"
] | Tries to convert a text value to a bool. If unsuccessful returns if value is None or not
:param value: Value to check | [
"Tries",
"to",
"convert",
"a",
"text",
"value",
"to",
"a",
"bool",
".",
"If",
"unsuccessful",
"returns",
"if",
"value",
"is",
"None",
"or",
"not"
] | python | train | 29.2 |
CalebBell/ht | ht/conduction.py | https://github.com/CalebBell/ht/blob/3097ef9524c4cf0068ad453c17b10ec9ce551eee/ht/conduction.py#L493-L538 | def S_isothermal_pipe_to_two_planes(D, Z, L=1.):
r'''Returns the Shape factor `S` of a pipe of constant outer temperature
and of outer diameter `D` which is `Z` distance from two infinite
isothermal planes of equal temperatures, parallel to each other and
enclosing the pipe. Length `L` must be provided,... | [
"def",
"S_isothermal_pipe_to_two_planes",
"(",
"D",
",",
"Z",
",",
"L",
"=",
"1.",
")",
":",
"return",
"2.",
"*",
"pi",
"*",
"L",
"/",
"log",
"(",
"8.",
"*",
"Z",
"/",
"(",
"pi",
"*",
"D",
")",
")"
] | r'''Returns the Shape factor `S` of a pipe of constant outer temperature
and of outer diameter `D` which is `Z` distance from two infinite
isothermal planes of equal temperatures, parallel to each other and
enclosing the pipe. Length `L` must be provided, but can be set to
1 to obtain a dimensionless sh... | [
"r",
"Returns",
"the",
"Shape",
"factor",
"S",
"of",
"a",
"pipe",
"of",
"constant",
"outer",
"temperature",
"and",
"of",
"outer",
"diameter",
"D",
"which",
"is",
"Z",
"distance",
"from",
"two",
"infinite",
"isothermal",
"planes",
"of",
"equal",
"temperatures... | python | train | 30.826087 |
tmr232/Sark | sark/qt.py | https://github.com/tmr232/Sark/blob/bee62879c2aea553a3924d887e2b30f2a6008581/sark/qt.py#L56-L66 | def get_window():
"""Get IDA's top level window."""
tform = idaapi.get_current_tform()
# Required sometimes when closing IDBs and not IDA.
if not tform:
tform = idaapi.find_tform("Output window")
widget = form_to_widget(tform)
window = widget.window()
return window | [
"def",
"get_window",
"(",
")",
":",
"tform",
"=",
"idaapi",
".",
"get_current_tform",
"(",
")",
"# Required sometimes when closing IDBs and not IDA.",
"if",
"not",
"tform",
":",
"tform",
"=",
"idaapi",
".",
"find_tform",
"(",
"\"Output window\"",
")",
"widget",
"=... | Get IDA's top level window. | [
"Get",
"IDA",
"s",
"top",
"level",
"window",
"."
] | python | train | 26.636364 |
watson-developer-cloud/python-sdk | ibm_watson/compare_comply_v1.py | https://github.com/watson-developer-cloud/python-sdk/blob/4c2c9df4466fcde88975da9ecd834e6ba95eb353/ibm_watson/compare_comply_v1.py#L3453-L3460 | def _to_dict(self):
"""Return a json dictionary representing this model."""
_dict = {}
if hasattr(self, 'key') and self.key is not None:
_dict['key'] = self.key._to_dict()
if hasattr(self, 'value') and self.value is not None:
_dict['value'] = self.value._to_dict()... | [
"def",
"_to_dict",
"(",
"self",
")",
":",
"_dict",
"=",
"{",
"}",
"if",
"hasattr",
"(",
"self",
",",
"'key'",
")",
"and",
"self",
".",
"key",
"is",
"not",
"None",
":",
"_dict",
"[",
"'key'",
"]",
"=",
"self",
".",
"key",
".",
"_to_dict",
"(",
"... | Return a json dictionary representing this model. | [
"Return",
"a",
"json",
"dictionary",
"representing",
"this",
"model",
"."
] | python | train | 41.75 |
lsbardel/python-stdnet | stdnet/odm/query.py | https://github.com/lsbardel/python-stdnet/blob/78db5320bdedc3f28c5e4f38cda13a4469e35db7/stdnet/odm/query.py#L445-L456 | def union(self, *queries):
'''Return a new :class:`Query` obtained form the union of this
:class:`Query` with one or more *queries*.
For example, lets say we want to have the union
of two queries obtained from the :meth:`filter` method::
query = session.query(MyModel)
qs = query.filter(field1 = ... | [
"def",
"union",
"(",
"self",
",",
"*",
"queries",
")",
":",
"q",
"=",
"self",
".",
"_clone",
"(",
")",
"q",
".",
"unions",
"+=",
"queries",
"return",
"q"
] | Return a new :class:`Query` obtained form the union of this
:class:`Query` with one or more *queries*.
For example, lets say we want to have the union
of two queries obtained from the :meth:`filter` method::
query = session.query(MyModel)
qs = query.filter(field1 = 'bla').union(query.filter(field2 = 'foo... | [
"Return",
"a",
"new",
":",
"class",
":",
"Query",
"obtained",
"form",
"the",
"union",
"of",
"this",
":",
"class",
":",
"Query",
"with",
"one",
"or",
"more",
"*",
"queries",
"*",
".",
"For",
"example",
"lets",
"say",
"we",
"want",
"to",
"have",
"the",... | python | train | 35.833333 |
UCBerkeleySETI/blimpy | blimpy/waterfall.py | https://github.com/UCBerkeleySETI/blimpy/blob/b8822d3e3e911944370d84371a91fa0c29e9772e/blimpy/waterfall.py#L473-L496 | def __get_chunk_dimensions(self):
""" Sets the chunking dimmentions depending on the file type.
"""
#Usually '.0000.' is in self.filename
if np.abs(self.header[b'foff']) < 1e-5:
logger.info('Detecting high frequency resolution data.')
chunk_dim = (1,1,1048576) #1... | [
"def",
"__get_chunk_dimensions",
"(",
"self",
")",
":",
"#Usually '.0000.' is in self.filename",
"if",
"np",
".",
"abs",
"(",
"self",
".",
"header",
"[",
"b'foff'",
"]",
")",
"<",
"1e-5",
":",
"logger",
".",
"info",
"(",
"'Detecting high frequency resolution data.... | Sets the chunking dimmentions depending on the file type. | [
"Sets",
"the",
"chunking",
"dimmentions",
"depending",
"on",
"the",
"file",
"type",
"."
] | python | test | 51.583333 |
ianclegg/ntlmlib | ntlmlib/security.py | https://github.com/ianclegg/ntlmlib/blob/49eadfe4701bcce84a4ca9cbab5b6d5d72eaad05/ntlmlib/security.py#L260-L288 | def sign(self, message):
"""
Generates a signature for the supplied message using NTLM2 Session Security
Note: [MS-NLMP] Section 3.4.4
The message signature for NTLM with extended session security is a 16-byte value that contains the following
components, as described by the NTLM... | [
"def",
"sign",
"(",
"self",
",",
"message",
")",
":",
"hmac_context",
"=",
"hmac",
".",
"new",
"(",
"self",
".",
"outgoing_signing_key",
")",
"hmac_context",
".",
"update",
"(",
"struct",
".",
"pack",
"(",
"'<i'",
",",
"self",
".",
"outgoing_sequence",
"... | Generates a signature for the supplied message using NTLM2 Session Security
Note: [MS-NLMP] Section 3.4.4
The message signature for NTLM with extended session security is a 16-byte value that contains the following
components, as described by the NTLMSSP_MESSAGE_SIGNATURE structure:
- A... | [
"Generates",
"a",
"signature",
"for",
"the",
"supplied",
"message",
"using",
"NTLM2",
"Session",
"Security",
"Note",
":",
"[",
"MS",
"-",
"NLMP",
"]",
"Section",
"3",
".",
"4",
".",
"4",
"The",
"message",
"signature",
"for",
"NTLM",
"with",
"extended",
"... | python | train | 47.310345 |
deeplearning4j/pydl4j | pydl4j/downloader.py | https://github.com/deeplearning4j/pydl4j/blob/63f8a1cae2afb4b08dbfe28ef8e08de741f0d3cd/pydl4j/downloader.py#L23-L82 | def download(url, file_name):
r = requests.get(url, stream=True)
file_size = int(r.headers['Content-length'])
'''
if py3:
file_size = int(u.getheader("Content-Length")[0])
else:
file_size = int(u.info().getheaders("Content-Length")[0])
'''
file_exists = False
if... | [
"def",
"download",
"(",
"url",
",",
"file_name",
")",
":",
"r",
"=",
"requests",
".",
"get",
"(",
"url",
",",
"stream",
"=",
"True",
")",
"file_size",
"=",
"int",
"(",
"r",
".",
"headers",
"[",
"'Content-length'",
"]",
")",
"file_exists",
"=",
"False... | if py3:
file_size = int(u.getheader("Content-Length")[0])
else:
file_size = int(u.info().getheaders("Content-Length")[0]) | [
"if",
"py3",
":",
"file_size",
"=",
"int",
"(",
"u",
".",
"getheader",
"(",
"Content",
"-",
"Length",
")",
"[",
"0",
"]",
")",
"else",
":",
"file_size",
"=",
"int",
"(",
"u",
".",
"info",
"()",
".",
"getheaders",
"(",
"Content",
"-",
"Length",
")... | python | train | 37.816667 |
libtcod/python-tcod | tcod/image.py | https://github.com/libtcod/python-tcod/blob/8ba10c5cfb813eaf3e834de971ba2d6acb7838e4/tcod/image.py#L59-L66 | def clear(self, color: Tuple[int, int, int]) -> None:
"""Fill this entire Image with color.
Args:
color (Union[Tuple[int, int, int], Sequence[int]]):
An (r, g, b) sequence or Color instance.
"""
lib.TCOD_image_clear(self.image_c, color) | [
"def",
"clear",
"(",
"self",
",",
"color",
":",
"Tuple",
"[",
"int",
",",
"int",
",",
"int",
"]",
")",
"->",
"None",
":",
"lib",
".",
"TCOD_image_clear",
"(",
"self",
".",
"image_c",
",",
"color",
")"
] | Fill this entire Image with color.
Args:
color (Union[Tuple[int, int, int], Sequence[int]]):
An (r, g, b) sequence or Color instance. | [
"Fill",
"this",
"entire",
"Image",
"with",
"color",
"."
] | python | train | 36.25 |
has2k1/plotnine | plotnine/guides/guide_colorbar.py | https://github.com/has2k1/plotnine/blob/566e579af705367e584fb27a74e6c5199624ca89/plotnine/guides/guide_colorbar.py#L295-L321 | def add_segmented_colorbar(da, colors, direction):
"""
Add 'non-rastered' colorbar to DrawingArea
"""
nbreak = len(colors)
if direction == 'vertical':
linewidth = da.height/nbreak
verts = [None] * nbreak
x1, x2 = 0, da.width
for i, color in enumerate(colors):
... | [
"def",
"add_segmented_colorbar",
"(",
"da",
",",
"colors",
",",
"direction",
")",
":",
"nbreak",
"=",
"len",
"(",
"colors",
")",
"if",
"direction",
"==",
"'vertical'",
":",
"linewidth",
"=",
"da",
".",
"height",
"/",
"nbreak",
"verts",
"=",
"[",
"None",
... | Add 'non-rastered' colorbar to DrawingArea | [
"Add",
"non",
"-",
"rastered",
"colorbar",
"to",
"DrawingArea"
] | python | train | 33.37037 |
genialis/resolwe | resolwe/flow/models/entity.py | https://github.com/genialis/resolwe/blob/f7bb54932c81ec0cfc5b5e80d238fceaeaa48d86/resolwe/flow/models/entity.py#L34-L37 | def move_to_collection(self, source_collection, destination_collection):
"""Move entities from source to destination collection."""
for entity in self:
entity.move_to_collection(source_collection, destination_collection) | [
"def",
"move_to_collection",
"(",
"self",
",",
"source_collection",
",",
"destination_collection",
")",
":",
"for",
"entity",
"in",
"self",
":",
"entity",
".",
"move_to_collection",
"(",
"source_collection",
",",
"destination_collection",
")"
] | Move entities from source to destination collection. | [
"Move",
"entities",
"from",
"source",
"to",
"destination",
"collection",
"."
] | python | train | 61.25 |
elifesciences/elife-tools | elifetools/parseJATS.py | https://github.com/elifesciences/elife-tools/blob/4b9e38cbe485c61a4ed7cbd8970c6b318334fd86/elifetools/parseJATS.py#L298-L308 | def subject_area(soup):
"""
Find the subject areas from article-categories subject tags
"""
subject_area = []
tags = raw_parser.subject_area(soup)
for tag in tags:
subject_area.append(node_text(tag))
return subject_area | [
"def",
"subject_area",
"(",
"soup",
")",
":",
"subject_area",
"=",
"[",
"]",
"tags",
"=",
"raw_parser",
".",
"subject_area",
"(",
"soup",
")",
"for",
"tag",
"in",
"tags",
":",
"subject_area",
".",
"append",
"(",
"node_text",
"(",
"tag",
")",
")",
"retu... | Find the subject areas from article-categories subject tags | [
"Find",
"the",
"subject",
"areas",
"from",
"article",
"-",
"categories",
"subject",
"tags"
] | python | train | 22.454545 |
saltstack/salt | salt/loader.py | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/loader.py#L515-L528 | def roster(opts, runner=None, utils=None, whitelist=None):
'''
Returns the roster modules
'''
return LazyLoader(
_module_dirs(opts, 'roster'),
opts,
tag='roster',
whitelist=whitelist,
pack={
'__runner__': runner,
'__utils__': utils,
... | [
"def",
"roster",
"(",
"opts",
",",
"runner",
"=",
"None",
",",
"utils",
"=",
"None",
",",
"whitelist",
"=",
"None",
")",
":",
"return",
"LazyLoader",
"(",
"_module_dirs",
"(",
"opts",
",",
"'roster'",
")",
",",
"opts",
",",
"tag",
"=",
"'roster'",
",... | Returns the roster modules | [
"Returns",
"the",
"roster",
"modules"
] | python | train | 22.571429 |
nuclio/nuclio-sdk-py | nuclio_sdk/event.py | https://github.com/nuclio/nuclio-sdk-py/blob/5af9ffc19a0d96255ff430bc358be9cd7a57f424/nuclio_sdk/event.py#L74-L99 | def from_json(data):
"""Decode event encoded as JSON by processor"""
parsed_data = json.loads(data)
trigger = TriggerInfo(
parsed_data['trigger']['class'],
parsed_data['trigger']['kind'],
)
# extract content type, needed to decode body
content_ty... | [
"def",
"from_json",
"(",
"data",
")",
":",
"parsed_data",
"=",
"json",
".",
"loads",
"(",
"data",
")",
"trigger",
"=",
"TriggerInfo",
"(",
"parsed_data",
"[",
"'trigger'",
"]",
"[",
"'class'",
"]",
",",
"parsed_data",
"[",
"'trigger'",
"]",
"[",
"'kind'"... | Decode event encoded as JSON by processor | [
"Decode",
"event",
"encoded",
"as",
"JSON",
"by",
"processor"
] | python | train | 42.192308 |
tensorflow/tensor2tensor | tensor2tensor/data_generators/text_encoder.py | https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/data_generators/text_encoder.py#L750-L866 | def build_from_token_counts(self,
token_counts,
min_count,
num_iterations=4,
reserved_tokens=None,
max_subtoken_length=None):
"""Train a SubwordTextEncoder based on a... | [
"def",
"build_from_token_counts",
"(",
"self",
",",
"token_counts",
",",
"min_count",
",",
"num_iterations",
"=",
"4",
",",
"reserved_tokens",
"=",
"None",
",",
"max_subtoken_length",
"=",
"None",
")",
":",
"if",
"reserved_tokens",
"is",
"None",
":",
"reserved_t... | Train a SubwordTextEncoder based on a dictionary of word counts.
Args:
token_counts: a dictionary of Unicode strings to int.
min_count: an integer - discard subtokens with lower counts.
num_iterations: an integer. how many iterations of refinement.
reserved_tokens: List of reserved tokens.... | [
"Train",
"a",
"SubwordTextEncoder",
"based",
"on",
"a",
"dictionary",
"of",
"word",
"counts",
"."
] | python | train | 46.393162 |
Alignak-monitoring/alignak | alignak/external_command.py | https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/external_command.py#L1014-L1048 | def add_svc_comment(self, service, author, comment):
"""Add a service comment
Format of the line that triggers function call::
ADD_SVC_COMMENT;<host_name>;<service_description>;<persistent:obsolete>;<author>;<comment>
:param service: service to add the comment
:type service: al... | [
"def",
"add_svc_comment",
"(",
"self",
",",
"service",
",",
"author",
",",
"comment",
")",
":",
"data",
"=",
"{",
"'author'",
":",
"author",
",",
"'comment'",
":",
"comment",
",",
"'comment_type'",
":",
"2",
",",
"'entry_type'",
":",
"1",
",",
"'source'"... | Add a service comment
Format of the line that triggers function call::
ADD_SVC_COMMENT;<host_name>;<service_description>;<persistent:obsolete>;<author>;<comment>
:param service: service to add the comment
:type service: alignak.objects.service.Service
:param author: author name... | [
"Add",
"a",
"service",
"comment",
"Format",
"of",
"the",
"line",
"that",
"triggers",
"function",
"call",
"::"
] | python | train | 43.371429 |
observermedia/django-wordpress-rest | wordpress/loading.py | https://github.com/observermedia/django-wordpress-rest/blob/f0d96891d8ac5a69c8ba90e044876e756fad1bfe/wordpress/loading.py#L463-L498 | def load_posts(self, post_type=None, max_pages=200, status=None):
"""
Load all WordPress posts of a given post_type from a site.
:param post_type: post, page, attachment, or any custom post type set up in the WP API
:param max_pages: kill counter to avoid infinite looping
:param... | [
"def",
"load_posts",
"(",
"self",
",",
"post_type",
"=",
"None",
",",
"max_pages",
"=",
"200",
",",
"status",
"=",
"None",
")",
":",
"logger",
".",
"info",
"(",
"\"loading posts with post_type=%s\"",
",",
"post_type",
")",
"# clear them all out so we don't get dup... | Load all WordPress posts of a given post_type from a site.
:param post_type: post, page, attachment, or any custom post type set up in the WP API
:param max_pages: kill counter to avoid infinite looping
:param status: load posts with the given status,
including any of: "publish", "p... | [
"Load",
"all",
"WordPress",
"posts",
"of",
"a",
"given",
"post_type",
"from",
"a",
"site",
"."
] | python | train | 43.277778 |
ANTsX/ANTsPy | ants/registration/apply_transforms.py | https://github.com/ANTsX/ANTsPy/blob/638020af2cdfc5ff4bdb9809ffe67aa505727a3b/ants/registration/apply_transforms.py#L196-L311 | def apply_transforms_to_points( dim, points, transformlist,
whichtoinvert=None, verbose=False ):
"""
Apply a transform list to map a pointset from one domain to
another. In registration, one computes mappings between pairs of
domains. These transforms are often a sequence of incr... | [
"def",
"apply_transforms_to_points",
"(",
"dim",
",",
"points",
",",
"transformlist",
",",
"whichtoinvert",
"=",
"None",
",",
"verbose",
"=",
"False",
")",
":",
"if",
"not",
"isinstance",
"(",
"transformlist",
",",
"(",
"tuple",
",",
"list",
")",
")",
"and... | Apply a transform list to map a pointset from one domain to
another. In registration, one computes mappings between pairs of
domains. These transforms are often a sequence of increasingly
complex maps, e.g. from translation, to rigid, to affine to
deformation. The list of such transforms is passed ... | [
"Apply",
"a",
"transform",
"list",
"to",
"map",
"a",
"pointset",
"from",
"one",
"domain",
"to",
"another",
".",
"In",
"registration",
"one",
"computes",
"mappings",
"between",
"pairs",
"of",
"domains",
".",
"These",
"transforms",
"are",
"often",
"a",
"sequen... | python | train | 37.491379 |
Microsoft/azure-devops-python-api | azure-devops/azure/devops/v5_0/work/work_client.py | https://github.com/Microsoft/azure-devops-python-api/blob/4777ffda2f5052fabbaddb2abe9cb434e0cf1aa8/azure-devops/azure/devops/v5_0/work/work_client.py#L448-L481 | def replace_capacities(self, capacities, team_context, iteration_id):
"""ReplaceCapacities.
Replace a team's capacity
:param [TeamMemberCapacity] capacities: Team capacity to replace
:param :class:`<TeamContext> <azure.devops.v5_0.work.models.TeamContext>` team_context: The team context ... | [
"def",
"replace_capacities",
"(",
"self",
",",
"capacities",
",",
"team_context",
",",
"iteration_id",
")",
":",
"project",
"=",
"None",
"team",
"=",
"None",
"if",
"team_context",
"is",
"not",
"None",
":",
"if",
"team_context",
".",
"project_id",
":",
"proje... | ReplaceCapacities.
Replace a team's capacity
:param [TeamMemberCapacity] capacities: Team capacity to replace
:param :class:`<TeamContext> <azure.devops.v5_0.work.models.TeamContext>` team_context: The team context for the operation
:param str iteration_id: ID of the iteration
:r... | [
"ReplaceCapacities",
".",
"Replace",
"a",
"team",
"s",
"capacity",
":",
"param",
"[",
"TeamMemberCapacity",
"]",
"capacities",
":",
"Team",
"capacity",
"to",
"replace",
":",
"param",
":",
"class",
":",
"<TeamContext",
">",
"<azure",
".",
"devops",
".",
"v5_0... | python | train | 47.617647 |
hannorein/rebound | rebound/simulation.py | https://github.com/hannorein/rebound/blob/bb0f814c98e629401acaab657cae2304b0e003f7/rebound/simulation.py#L1154-L1188 | def remove(self, index=None, hash=None, keepSorted=True):
"""
Removes a particle from the simulation.
Parameters
----------
index : int, optional
Specify particle to remove by index.
hash : c_uint32 or string, optional
Specifiy particle to remove... | [
"def",
"remove",
"(",
"self",
",",
"index",
"=",
"None",
",",
"hash",
"=",
"None",
",",
"keepSorted",
"=",
"True",
")",
":",
"if",
"index",
"is",
"not",
"None",
":",
"clibrebound",
".",
"reb_remove",
"(",
"byref",
"(",
"self",
")",
",",
"index",
",... | Removes a particle from the simulation.
Parameters
----------
index : int, optional
Specify particle to remove by index.
hash : c_uint32 or string, optional
Specifiy particle to remove by hash (if a string is passed, the corresponding hash is calculated).
... | [
"Removes",
"a",
"particle",
"from",
"the",
"simulation",
"."
] | python | train | 43.342857 |
saltstack/salt | salt/utils/files.py | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/utils/files.py#L714-L726 | def list_files(directory):
'''
Return a list of all files found under directory (and its subdirectories)
'''
ret = set()
ret.add(directory)
for root, dirs, files in safe_walk(directory):
for name in files:
ret.add(os.path.join(root, name))
for name in dirs:
... | [
"def",
"list_files",
"(",
"directory",
")",
":",
"ret",
"=",
"set",
"(",
")",
"ret",
".",
"add",
"(",
"directory",
")",
"for",
"root",
",",
"dirs",
",",
"files",
"in",
"safe_walk",
"(",
"directory",
")",
":",
"for",
"name",
"in",
"files",
":",
"ret... | Return a list of all files found under directory (and its subdirectories) | [
"Return",
"a",
"list",
"of",
"all",
"files",
"found",
"under",
"directory",
"(",
"and",
"its",
"subdirectories",
")"
] | python | train | 28.076923 |
Microsoft/knack | knack/cli.py | https://github.com/Microsoft/knack/blob/5f1a480a33f103e2688c46eef59fb2d9eaf2baad/knack/cli.py#L164-L170 | def exception_handler(self, ex): # pylint: disable=no-self-use
""" The default exception handler """
if isinstance(ex, CLIError):
logger.error(ex)
else:
logger.exception(ex)
return 1 | [
"def",
"exception_handler",
"(",
"self",
",",
"ex",
")",
":",
"# pylint: disable=no-self-use",
"if",
"isinstance",
"(",
"ex",
",",
"CLIError",
")",
":",
"logger",
".",
"error",
"(",
"ex",
")",
"else",
":",
"logger",
".",
"exception",
"(",
"ex",
")",
"ret... | The default exception handler | [
"The",
"default",
"exception",
"handler"
] | python | train | 33.285714 |
hsolbrig/PyShEx | pyshex/utils/schema_loader.py | https://github.com/hsolbrig/PyShEx/blob/9d659cc36e808afd66d4a6d60e8ea21cb12eb744/pyshex/utils/schema_loader.py#L47-L58 | def loads(self, schema_txt: str) -> ShExJ.Schema:
""" Parse and return schema as a ShExJ Schema
:param schema_txt: ShExC or ShExJ representation of a ShEx Schema
:return: ShEx Schema representation of schema
"""
self.schema_text = schema_txt
if schema_txt.strip()[0] == '... | [
"def",
"loads",
"(",
"self",
",",
"schema_txt",
":",
"str",
")",
"->",
"ShExJ",
".",
"Schema",
":",
"self",
".",
"schema_text",
"=",
"schema_txt",
"if",
"schema_txt",
".",
"strip",
"(",
")",
"[",
"0",
"]",
"==",
"'{'",
":",
"# TODO: figure out how to pro... | Parse and return schema as a ShExJ Schema
:param schema_txt: ShExC or ShExJ representation of a ShEx Schema
:return: ShEx Schema representation of schema | [
"Parse",
"and",
"return",
"schema",
"as",
"a",
"ShExJ",
"Schema"
] | python | train | 45.416667 |
WZBSocialScienceCenter/tmtoolkit | tmtoolkit/preprocess.py | https://github.com/WZBSocialScienceCenter/tmtoolkit/blob/ca8b9d072e37ccc82b533f47d48bd9755722305b/tmtoolkit/preprocess.py#L476-L532 | def apply_custom_filter(self, filter_func, to_ngrams=False):
"""
Apply a custom filter function `filter_func` to all tokens or ngrams (if `to_ngrams` is True).
`filter_func` must accept a single parameter: a dictionary of structure `{<doc_label>: <tokens list>}`. It
must return a diction... | [
"def",
"apply_custom_filter",
"(",
"self",
",",
"filter_func",
",",
"to_ngrams",
"=",
"False",
")",
":",
"# Because it is not possible to send a function to the workers, all tokens must be fetched from the workers",
"# first and then the custom function is called and run in a single proces... | Apply a custom filter function `filter_func` to all tokens or ngrams (if `to_ngrams` is True).
`filter_func` must accept a single parameter: a dictionary of structure `{<doc_label>: <tokens list>}`. It
must return a dictionary with the same structure.
This function can only be run on a single p... | [
"Apply",
"a",
"custom",
"filter",
"function",
"filter_func",
"to",
"all",
"tokens",
"or",
"ngrams",
"(",
"if",
"to_ngrams",
"is",
"True",
")",
".",
"filter_func",
"must",
"accept",
"a",
"single",
"parameter",
":",
"a",
"dictionary",
"of",
"structure",
"{",
... | python | train | 39.438596 |
Arello-Mobile/swagger2rst | swg2rst/utils/exampilators.py | https://github.com/Arello-Mobile/swagger2rst/blob/e519f70701477dcc9f0bb237ee5b8e08e848701b/swg2rst/utils/exampilators.py#L204-L253 | def get_property_example(cls, property_, nested=None, **kw):
""" Get example for property
:param dict property_:
:param set nested:
:return: example value
"""
paths = kw.get('paths', [])
name = kw.get('name', '')
result = None
if name and paths:
... | [
"def",
"get_property_example",
"(",
"cls",
",",
"property_",
",",
"nested",
"=",
"None",
",",
"*",
"*",
"kw",
")",
":",
"paths",
"=",
"kw",
".",
"get",
"(",
"'paths'",
",",
"[",
"]",
")",
"name",
"=",
"kw",
".",
"get",
"(",
"'name'",
",",
"''",
... | Get example for property
:param dict property_:
:param set nested:
:return: example value | [
"Get",
"example",
"for",
"property"
] | python | train | 44.32 |
shi-cong/PYSTUDY | PYSTUDY/encryptlib.py | https://github.com/shi-cong/PYSTUDY/blob/c8da7128ea18ecaa5849f2066d321e70d6f97f70/PYSTUDY/encryptlib.py#L44-L57 | def reverse_cipher(message):
"""
反转加密法
:param message: 待加密字符串
:return: 被加密字符串
"""
translated = ''
i = len(message) - 1
while i >= 0:
translated = translated + message[i]
i = i - 1
return translated | [
"def",
"reverse_cipher",
"(",
"message",
")",
":",
"translated",
"=",
"''",
"i",
"=",
"len",
"(",
"message",
")",
"-",
"1",
"while",
"i",
">=",
"0",
":",
"translated",
"=",
"translated",
"+",
"message",
"[",
"i",
"]",
"i",
"=",
"i",
"-",
"1",
"re... | 反转加密法
:param message: 待加密字符串
:return: 被加密字符串 | [
"反转加密法",
":",
"param",
"message",
":",
"待加密字符串",
":",
"return",
":",
"被加密字符串"
] | python | train | 17 |
nickmckay/LiPD-utilities | Python/lipd/lpd_noaa.py | https://github.com/nickmckay/LiPD-utilities/blob/5dab6bbeffc5effd68e3a6beaca6b76aa928e860/Python/lipd/lpd_noaa.py#L638-L655 | def __put_year_col_first(d):
"""
Always write year column first. Reorder dictionary so that year is first
:param dict d: data
:return dict: Reordered data
"""
if "year" in d:
D = OrderedDict()
# store the year column first
D["year"] = d... | [
"def",
"__put_year_col_first",
"(",
"d",
")",
":",
"if",
"\"year\"",
"in",
"d",
":",
"D",
"=",
"OrderedDict",
"(",
")",
"# store the year column first",
"D",
"[",
"\"year\"",
"]",
"=",
"d",
"[",
"\"year\"",
"]",
"for",
"k",
",",
"v",
"in",
"d",
".",
... | Always write year column first. Reorder dictionary so that year is first
:param dict d: data
:return dict: Reordered data | [
"Always",
"write",
"year",
"column",
"first",
".",
"Reorder",
"dictionary",
"so",
"that",
"year",
"is",
"first",
":",
"param",
"dict",
"d",
":",
"data",
":",
"return",
"dict",
":",
"Reordered",
"data"
] | python | train | 31.055556 |
thomasdelaet/python-velbus | velbus/module.py | https://github.com/thomasdelaet/python-velbus/blob/af2f8af43f1a24bf854eff9f3126fd7b5c41b3dd/velbus/module.py#L147-L158 | def _name_messages_complete(self):
"""
Check if all name messages have been received
"""
for channel in range(1, self.number_of_channels() + 1):
try:
for name_index in range(1, 4):
if not isinstance(self._name_data[channel][name_index], str... | [
"def",
"_name_messages_complete",
"(",
"self",
")",
":",
"for",
"channel",
"in",
"range",
"(",
"1",
",",
"self",
".",
"number_of_channels",
"(",
")",
"+",
"1",
")",
":",
"try",
":",
"for",
"name_index",
"in",
"range",
"(",
"1",
",",
"4",
")",
":",
... | Check if all name messages have been received | [
"Check",
"if",
"all",
"name",
"messages",
"have",
"been",
"received"
] | python | train | 35.583333 |
push-things/django-th | th_evernote/evernote_mgr.py | https://github.com/push-things/django-th/blob/86c999d16bcf30b6224206e5b40824309834ac8c/th_evernote/evernote_mgr.py#L161-L175 | def set_note_footer(data, trigger):
"""
handle the footer of the note
"""
footer = ''
if data.get('link'):
provided_by = _('Provided by')
provided_from = _('from')
footer_from = "<br/><br/>{} <em>{}</em> {} <a href='{}'>{}</a>"
... | [
"def",
"set_note_footer",
"(",
"data",
",",
"trigger",
")",
":",
"footer",
"=",
"''",
"if",
"data",
".",
"get",
"(",
"'link'",
")",
":",
"provided_by",
"=",
"_",
"(",
"'Provided by'",
")",
"provided_from",
"=",
"_",
"(",
"'from'",
")",
"footer_from",
"... | handle the footer of the note | [
"handle",
"the",
"footer",
"of",
"the",
"note"
] | python | train | 32.2 |
gmr/rejected | rejected/mcp.py | https://github.com/gmr/rejected/blob/610a3e1401122ecb98d891b6795cca0255e5b044/rejected/mcp.py#L443-L469 | def poll(self):
"""Start the poll process by invoking the get_stats method of the
consumers. If we hit this after another interval without fully
processing, note it with a warning.
"""
self.set_state(self.STATE_ACTIVE)
# If we don't have any active consumers, spawn new ... | [
"def",
"poll",
"(",
"self",
")",
":",
"self",
".",
"set_state",
"(",
"self",
".",
"STATE_ACTIVE",
")",
"# If we don't have any active consumers, spawn new ones",
"if",
"not",
"self",
".",
"total_process_count",
":",
"LOGGER",
".",
"debug",
"(",
"'Did not find any ac... | Start the poll process by invoking the get_stats method of the
consumers. If we hit this after another interval without fully
processing, note it with a warning. | [
"Start",
"the",
"poll",
"process",
"by",
"invoking",
"the",
"get_stats",
"method",
"of",
"the",
"consumers",
".",
"If",
"we",
"hit",
"this",
"after",
"another",
"interval",
"without",
"fully",
"processing",
"note",
"it",
"with",
"a",
"warning",
"."
] | python | train | 36.62963 |
python/performance | performance/benchmarks/bm_nqueens.py | https://github.com/python/performance/blob/2a9524c0a5714e85106671bc61d750e800fe17db/performance/benchmarks/bm_nqueens.py#L9-L30 | def permutations(iterable, r=None):
"""permutations(range(3), 2) --> (0,1) (0,2) (1,0) (1,2) (2,0) (2,1)"""
pool = tuple(iterable)
n = len(pool)
if r is None:
r = n
indices = list(range(n))
cycles = list(range(n - r + 1, n + 1))[::-1]
yield tuple(pool[i] for i in indices[:r])
whi... | [
"def",
"permutations",
"(",
"iterable",
",",
"r",
"=",
"None",
")",
":",
"pool",
"=",
"tuple",
"(",
"iterable",
")",
"n",
"=",
"len",
"(",
"pool",
")",
"if",
"r",
"is",
"None",
":",
"r",
"=",
"n",
"indices",
"=",
"list",
"(",
"range",
"(",
"n",... | permutations(range(3), 2) --> (0,1) (0,2) (1,0) (1,2) (2,0) (2,1) | [
"permutations",
"(",
"range",
"(",
"3",
")",
"2",
")",
"--",
">",
"(",
"0",
"1",
")",
"(",
"0",
"2",
")",
"(",
"1",
"0",
")",
"(",
"1",
"2",
")",
"(",
"2",
"0",
")",
"(",
"2",
"1",
")"
] | python | test | 32.954545 |
andrenarchy/krypy | krypy/utils.py | https://github.com/andrenarchy/krypy/blob/4883ec9a61d64ea56489e15c35cc40f0633ab2f1/krypy/utils.py#L612-L621 | def operator(self):
"""Get a ``LinearOperator`` corresponding to apply().
:return: a LinearOperator that calls apply().
"""
# is projection the zero operator?
if self.V.shape[1] == 0:
N = self.V.shape[0]
return ZeroLinearOperator((N, N))
return se... | [
"def",
"operator",
"(",
"self",
")",
":",
"# is projection the zero operator?",
"if",
"self",
".",
"V",
".",
"shape",
"[",
"1",
"]",
"==",
"0",
":",
"N",
"=",
"self",
".",
"V",
".",
"shape",
"[",
"0",
"]",
"return",
"ZeroLinearOperator",
"(",
"(",
"N... | Get a ``LinearOperator`` corresponding to apply().
:return: a LinearOperator that calls apply(). | [
"Get",
"a",
"LinearOperator",
"corresponding",
"to",
"apply",
"()",
"."
] | python | train | 35.5 |
chrislit/abydos | abydos/phonetic/_beider_morse.py | https://github.com/chrislit/abydos/blob/165466b3ff6afd8024a4c8660421b0c4e7773db9/abydos/phonetic/_beider_morse.py#L936-L1025 | def bmpm(
word,
language_arg=0,
name_mode='gen',
match_mode='approx',
concat=False,
filter_langs=False,
):
"""Return the Beider-Morse Phonetic Matching encoding(s) of a term.
This is a wrapper for :py:meth:`BeiderMorse.encode`.
Parameters
----------
word : str
The w... | [
"def",
"bmpm",
"(",
"word",
",",
"language_arg",
"=",
"0",
",",
"name_mode",
"=",
"'gen'",
",",
"match_mode",
"=",
"'approx'",
",",
"concat",
"=",
"False",
",",
"filter_langs",
"=",
"False",
",",
")",
":",
"return",
"BeiderMorse",
"(",
")",
".",
"encod... | Return the Beider-Morse Phonetic Matching encoding(s) of a term.
This is a wrapper for :py:meth:`BeiderMorse.encode`.
Parameters
----------
word : str
The word to transform
language_arg : str
The language of the term; supported values include:
- ``any``
- `... | [
"Return",
"the",
"Beider",
"-",
"Morse",
"Phonetic",
"Matching",
"encoding",
"(",
"s",
")",
"of",
"a",
"term",
"."
] | python | valid | 26.411111 |
johnbywater/eventsourcing | eventsourcing/contrib/paxos/composable.py | https://github.com/johnbywater/eventsourcing/blob/de2c22c653fdccf2f5ee96faea74453ff1847e42/eventsourcing/contrib/paxos/composable.py#L360-L408 | def receive_accepted(self, msg):
'''
Called when an Accepted message is received from an acceptor. Once the final value
is determined, the return value of this method will be a Resolution message containing
the consentual value. Subsequent calls after the resolution is chosen will contin... | [
"def",
"receive_accepted",
"(",
"self",
",",
"msg",
")",
":",
"if",
"self",
".",
"final_value",
"is",
"not",
"None",
":",
"if",
"msg",
".",
"proposal_id",
">=",
"self",
".",
"final_proposal_id",
"and",
"msg",
".",
"proposal_value",
"==",
"self",
".",
"fi... | Called when an Accepted message is received from an acceptor. Once the final value
is determined, the return value of this method will be a Resolution message containing
the consentual value. Subsequent calls after the resolution is chosen will continue to add
new Acceptors to the final_acceptor... | [
"Called",
"when",
"an",
"Accepted",
"message",
"is",
"received",
"from",
"an",
"acceptor",
".",
"Once",
"the",
"final",
"value",
"is",
"determined",
"the",
"return",
"value",
"of",
"this",
"method",
"will",
"be",
"a",
"Resolution",
"message",
"containing",
"... | python | train | 40.387755 |
cloud9ers/gurumate | environment/lib/python2.7/site-packages/IPython/parallel/client/client.py | https://github.com/cloud9ers/gurumate/blob/075dc74d1ee62a8c6b7a8bf2b271364f01629d1e/environment/lib/python2.7/site-packages/IPython/parallel/client/client.py#L797-L810 | def _flush_notifications(self):
"""Flush notifications of engine registrations waiting
in ZMQ queue."""
idents,msg = self.session.recv(self._notification_socket, mode=zmq.NOBLOCK)
while msg is not None:
if self.debug:
pprint(msg)
msg_type = msg['he... | [
"def",
"_flush_notifications",
"(",
"self",
")",
":",
"idents",
",",
"msg",
"=",
"self",
".",
"session",
".",
"recv",
"(",
"self",
".",
"_notification_socket",
",",
"mode",
"=",
"zmq",
".",
"NOBLOCK",
")",
"while",
"msg",
"is",
"not",
"None",
":",
"if"... | Flush notifications of engine registrations waiting
in ZMQ queue. | [
"Flush",
"notifications",
"of",
"engine",
"registrations",
"waiting",
"in",
"ZMQ",
"queue",
"."
] | python | test | 45.5 |
nornir-automation/nornir | nornir/core/task.py | https://github.com/nornir-automation/nornir/blob/3425c47fd870db896cb80f619bae23bd98d50c74/nornir/core/task.py#L216-L218 | def failed_hosts(self):
"""Hosts that failed during the execution of the task."""
return {h: r for h, r in self.items() if r.failed} | [
"def",
"failed_hosts",
"(",
"self",
")",
":",
"return",
"{",
"h",
":",
"r",
"for",
"h",
",",
"r",
"in",
"self",
".",
"items",
"(",
")",
"if",
"r",
".",
"failed",
"}"
] | Hosts that failed during the execution of the task. | [
"Hosts",
"that",
"failed",
"during",
"the",
"execution",
"of",
"the",
"task",
"."
] | python | train | 48.666667 |
royi1000/py-libhdate | hdate/date.py | https://github.com/royi1000/py-libhdate/blob/12af759fb69f1d6403abed3762beaf5ace16a34b/hdate/date.py#L130-L134 | def _jdn(self):
"""Return the Julian date number for the given date."""
if self._last_updated == "gdate":
return conv.gdate_to_jdn(self.gdate)
return conv.hdate_to_jdn(self.hdate) | [
"def",
"_jdn",
"(",
"self",
")",
":",
"if",
"self",
".",
"_last_updated",
"==",
"\"gdate\"",
":",
"return",
"conv",
".",
"gdate_to_jdn",
"(",
"self",
".",
"gdate",
")",
"return",
"conv",
".",
"hdate_to_jdn",
"(",
"self",
".",
"hdate",
")"
] | Return the Julian date number for the given date. | [
"Return",
"the",
"Julian",
"date",
"number",
"for",
"the",
"given",
"date",
"."
] | python | train | 42.2 |
sckott/pygbif | pygbif/occurrences/download.py | https://github.com/sckott/pygbif/blob/bf54f2920bc46d97d7e2e1b0c8059e5878f3c5ab/pygbif/occurrences/download.py#L18-L29 | def _check_environ(variable, value):
"""check if a variable is present in the environmental variables"""
if is_not_none(value):
return value
else:
value = os.environ.get(variable)
if is_none(value):
stop(''.join([variable,
""" not supplied and no... | [
"def",
"_check_environ",
"(",
"variable",
",",
"value",
")",
":",
"if",
"is_not_none",
"(",
"value",
")",
":",
"return",
"value",
"else",
":",
"value",
"=",
"os",
".",
"environ",
".",
"get",
"(",
"variable",
")",
"if",
"is_none",
"(",
"value",
")",
"... | check if a variable is present in the environmental variables | [
"check",
"if",
"a",
"variable",
"is",
"present",
"in",
"the",
"environmental",
"variables"
] | python | train | 34.5 |
kevinconway/iface | iface/checks.py | https://github.com/kevinconway/iface/blob/2687f7965eed155b9594a298ffa260a2f9f821f9/iface/checks.py#L9-L25 | def _ensure_ifaces_tuple(ifaces):
"""Convert to a tuple of interfaces and raise if not interfaces."""
try:
ifaces = tuple(ifaces)
except TypeError:
ifaces = (ifaces,)
for iface in ifaces:
if not _issubclass(iface, ibc.Iface):
raise TypeError('Can only compare ag... | [
"def",
"_ensure_ifaces_tuple",
"(",
"ifaces",
")",
":",
"try",
":",
"ifaces",
"=",
"tuple",
"(",
"ifaces",
")",
"except",
"TypeError",
":",
"ifaces",
"=",
"(",
"ifaces",
",",
")",
"for",
"iface",
"in",
"ifaces",
":",
"if",
"not",
"_issubclass",
"(",
"i... | Convert to a tuple of interfaces and raise if not interfaces. | [
"Convert",
"to",
"a",
"tuple",
"of",
"interfaces",
"and",
"raise",
"if",
"not",
"interfaces",
"."
] | python | train | 20.117647 |
PredixDev/predixpy | predix/security/uaa.py | https://github.com/PredixDev/predixpy/blob/a0cb34cf40f716229351bb6d90d6ecace958c81f/predix/security/uaa.py#L226-L239 | def logout(self):
"""
Log currently authenticated user out, invalidating any existing tokens.
"""
# Remove token from local cache
# MAINT: need to expire token on server
data = self._read_uaa_cache()
if self.uri in data:
for client in data[self.uri]:
... | [
"def",
"logout",
"(",
"self",
")",
":",
"# Remove token from local cache",
"# MAINT: need to expire token on server",
"data",
"=",
"self",
".",
"_read_uaa_cache",
"(",
")",
"if",
"self",
".",
"uri",
"in",
"data",
":",
"for",
"client",
"in",
"data",
"[",
"self",
... | Log currently authenticated user out, invalidating any existing tokens. | [
"Log",
"currently",
"authenticated",
"user",
"out",
"invalidating",
"any",
"existing",
"tokens",
"."
] | python | train | 37.928571 |
manns/pyspread | pyspread/src/lib/xrect.py | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/lib/xrect.py#L47-L57 | def is_bbox_not_intersecting(self, other):
"""Returns False iif bounding boxed of self and other intersect"""
self_x_min, self_x_max, self_y_min, self_y_max = self.get_bbox()
other_x_min, other_x_max, other_y_min, other_y_max = other.get_bbox()
return \
self_x_min > other_x... | [
"def",
"is_bbox_not_intersecting",
"(",
"self",
",",
"other",
")",
":",
"self_x_min",
",",
"self_x_max",
",",
"self_y_min",
",",
"self_y_max",
"=",
"self",
".",
"get_bbox",
"(",
")",
"other_x_min",
",",
"other_x_max",
",",
"other_y_min",
",",
"other_y_max",
"=... | Returns False iif bounding boxed of self and other intersect | [
"Returns",
"False",
"iif",
"bounding",
"boxed",
"of",
"self",
"and",
"other",
"intersect"
] | python | train | 40 |
dvdotsenko/jsonrpc.py | jsonrpcparts/serializers.py | https://github.com/dvdotsenko/jsonrpc.py/blob/19673edd77a9518ac5655bd407f6b93ffbb2cafc/jsonrpcparts/serializers.py#L440-L467 | def parse_request(cls, request_string):
"""JSONRPC allows for **batch** requests to be communicated
as array of dicts. This method parses out each individual
element in the batch and returns a list of tuples, each
tuple a result of parsing of each item in the batch.
:Returns: ... | [
"def",
"parse_request",
"(",
"cls",
",",
"request_string",
")",
":",
"try",
":",
"batch",
"=",
"cls",
".",
"json_loads",
"(",
"request_string",
")",
"except",
"ValueError",
"as",
"err",
":",
"raise",
"errors",
".",
"RPCParseError",
"(",
"\"No valid JSON. (%s)\... | JSONRPC allows for **batch** requests to be communicated
as array of dicts. This method parses out each individual
element in the batch and returns a list of tuples, each
tuple a result of parsing of each item in the batch.
:Returns: | tuple of (results, is_batch_mode_flag)
... | [
"JSONRPC",
"allows",
"for",
"**",
"batch",
"**",
"requests",
"to",
"be",
"communicated",
"as",
"array",
"of",
"dicts",
".",
"This",
"method",
"parses",
"out",
"each",
"individual",
"element",
"in",
"the",
"batch",
"and",
"returns",
"a",
"list",
"of",
"tupl... | python | train | 48.357143 |
hozn/coilmq | coilmq/auth/simple.py | https://github.com/hozn/coilmq/blob/76b7fcf347144b3a5746423a228bed121dc564b5/coilmq/auth/simple.py#L29-L42 | def make_simple():
"""
Create a L{SimpleAuthenticator} instance using values read from coilmq configuration.
@return: The configured L{SimpleAuthenticator}
@rtype: L{SimpleAuthenticator}
@raise ConfigError: If there is a configuration error.
"""
authfile = config.get('coilmq', 'auth.simple.... | [
"def",
"make_simple",
"(",
")",
":",
"authfile",
"=",
"config",
".",
"get",
"(",
"'coilmq'",
",",
"'auth.simple.file'",
")",
"if",
"not",
"authfile",
":",
"raise",
"ConfigError",
"(",
"'Missing configuration parameter: auth.simple.file'",
")",
"sa",
"=",
"SimpleAu... | Create a L{SimpleAuthenticator} instance using values read from coilmq configuration.
@return: The configured L{SimpleAuthenticator}
@rtype: L{SimpleAuthenticator}
@raise ConfigError: If there is a configuration error. | [
"Create",
"a",
"L",
"{",
"SimpleAuthenticator",
"}",
"instance",
"using",
"values",
"read",
"from",
"coilmq",
"configuration",
"."
] | python | train | 35.071429 |
WhyNotHugo/django-renderpdf | django_renderpdf/views.py | https://github.com/WhyNotHugo/django-renderpdf/blob/56de11326e61d317b5eb08c340790ef9955778e3/django_renderpdf/views.py#L88-L108 | def render(self, request, template, context):
"""
Returns a response. By default, this will contain the rendered PDF, but
if both ``allow_force_html`` is ``True`` and the querystring
``html=true`` was set it will return a plain HTML.
"""
if self.allow_force_html and self.... | [
"def",
"render",
"(",
"self",
",",
"request",
",",
"template",
",",
"context",
")",
":",
"if",
"self",
".",
"allow_force_html",
"and",
"self",
".",
"request",
".",
"GET",
".",
"get",
"(",
"'html'",
",",
"False",
")",
":",
"html",
"=",
"get_template",
... | Returns a response. By default, this will contain the rendered PDF, but
if both ``allow_force_html`` is ``True`` and the querystring
``html=true`` was set it will return a plain HTML. | [
"Returns",
"a",
"response",
".",
"By",
"default",
"this",
"will",
"contain",
"the",
"rendered",
"PDF",
"but",
"if",
"both",
"allow_force_html",
"is",
"True",
"and",
"the",
"querystring",
"html",
"=",
"true",
"was",
"set",
"it",
"will",
"return",
"a",
"plai... | python | train | 42.857143 |
spyder-ide/spyder | spyder/app/mainwindow.py | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/app/mainwindow.py#L2741-L2755 | def open_file(self, fname, external=False):
"""
Open filename with the appropriate application
Redirect to the right widget (txt -> editor, spydata -> workspace, ...)
or open file outside Spyder (if extension is not supported)
"""
fname = to_text_string(fname)
... | [
"def",
"open_file",
"(",
"self",
",",
"fname",
",",
"external",
"=",
"False",
")",
":",
"fname",
"=",
"to_text_string",
"(",
"fname",
")",
"ext",
"=",
"osp",
".",
"splitext",
"(",
"fname",
")",
"[",
"1",
"]",
"if",
"encoding",
".",
"is_text_file",
"(... | Open filename with the appropriate application
Redirect to the right widget (txt -> editor, spydata -> workspace, ...)
or open file outside Spyder (if extension is not supported) | [
"Open",
"filename",
"with",
"the",
"appropriate",
"application",
"Redirect",
"to",
"the",
"right",
"widget",
"(",
"txt",
"-",
">",
"editor",
"spydata",
"-",
">",
"workspace",
"...",
")",
"or",
"open",
"file",
"outside",
"Spyder",
"(",
"if",
"extension",
"i... | python | train | 43.133333 |
ladybug-tools/ladybug | ladybug/designday.py | https://github.com/ladybug-tools/ladybug/blob/c08b7308077a48d5612f644943f92d5b5dade583/ladybug/designday.py#L194-L199 | def to_json(self):
"""Convert the Design Day to a dictionary."""
return {
'location': self.location.to_json(),
'design_days': [des_d.to_json() for des_d in self.design_days]
} | [
"def",
"to_json",
"(",
"self",
")",
":",
"return",
"{",
"'location'",
":",
"self",
".",
"location",
".",
"to_json",
"(",
")",
",",
"'design_days'",
":",
"[",
"des_d",
".",
"to_json",
"(",
")",
"for",
"des_d",
"in",
"self",
".",
"design_days",
"]",
"}... | Convert the Design Day to a dictionary. | [
"Convert",
"the",
"Design",
"Day",
"to",
"a",
"dictionary",
"."
] | python | train | 36.333333 |
psss/did | did/plugins/trello.py | https://github.com/psss/did/blob/04e4ee6f1aa14c0cae3ba9f9803871f3f98279cb/did/plugins/trello.py#L114-L125 | def board_links_to_ids(self):
""" Convert board links to ids """
resp = self.stats.session.open(
"{0}/members/{1}/boards?{2}".format(
self.stats.url, self.username, urllib.urlencode({
"key": self.key,
"token": self.token,
... | [
"def",
"board_links_to_ids",
"(",
"self",
")",
":",
"resp",
"=",
"self",
".",
"stats",
".",
"session",
".",
"open",
"(",
"\"{0}/members/{1}/boards?{2}\"",
".",
"format",
"(",
"self",
".",
"stats",
".",
"url",
",",
"self",
".",
"username",
",",
"urllib",
... | Convert board links to ids | [
"Convert",
"board",
"links",
"to",
"ids"
] | python | train | 43.083333 |
brocade/pynos | pynos/versions/ver_6/ver_6_0_1/yang/brocade_policer.py | https://github.com/brocade/pynos/blob/bd8a34e98f322de3fc06750827d8bbc3a0c00380/pynos/versions/ver_6/ver_6_0_1/yang/brocade_policer.py#L149-L161 | def police_priority_map_exceed_map_pri1_exceed(self, **kwargs):
"""Auto Generated Code
"""
config = ET.Element("config")
police_priority_map = ET.SubElement(config, "police-priority-map", xmlns="urn:brocade.com:mgmt:brocade-policer")
name_key = ET.SubElement(police_priority_map, ... | [
"def",
"police_priority_map_exceed_map_pri1_exceed",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"config",
"=",
"ET",
".",
"Element",
"(",
"\"config\"",
")",
"police_priority_map",
"=",
"ET",
".",
"SubElement",
"(",
"config",
",",
"\"police-priority-map\"",
... | Auto Generated Code | [
"Auto",
"Generated",
"Code"
] | python | train | 49.153846 |
rstoneback/pysatMagVect | pysatMagVect/satellite.py | https://github.com/rstoneback/pysatMagVect/blob/3fdc87ffbe05be58123f80f880d1237c2f34c7be/pysatMagVect/satellite.py#L171-L342 | def add_mag_drift_unit_vectors(inst, max_steps=40000, step_size=10.):
"""Add unit vectors expressing the ion drift coordinate system
organized by the geomagnetic field. Unit vectors are expressed
in S/C coordinates.
Interally, routine calls add_mag_drift_unit_vectors_ecef.
See function for inp... | [
"def",
"add_mag_drift_unit_vectors",
"(",
"inst",
",",
"max_steps",
"=",
"40000",
",",
"step_size",
"=",
"10.",
")",
":",
"# vectors are returned in geo/ecef coordinate system",
"add_mag_drift_unit_vectors_ecef",
"(",
"inst",
",",
"max_steps",
"=",
"max_steps",
",",
"st... | Add unit vectors expressing the ion drift coordinate system
organized by the geomagnetic field. Unit vectors are expressed
in S/C coordinates.
Interally, routine calls add_mag_drift_unit_vectors_ecef.
See function for input parameter description.
Requires the orientation of the S/C basis vecto... | [
"Add",
"unit",
"vectors",
"expressing",
"the",
"ion",
"drift",
"coordinate",
"system",
"organized",
"by",
"the",
"geomagnetic",
"field",
".",
"Unit",
"vectors",
"are",
"expressed",
"in",
"S",
"/",
"C",
"coordinates",
".",
"Interally",
"routine",
"calls",
"add_... | python | train | 77.936047 |
samluescher/django-media-tree | media_tree/contrib/views/mixin_base.py | https://github.com/samluescher/django-media-tree/blob/3eb6345faaf57e2fbe35ca431d4d133f950f2b5f/media_tree/contrib/views/mixin_base.py#L24-L52 | def get_view(self, request, view_class, opts=None):
"""
Instantiates and returns the view class that will generate the
actual context for this plugin.
"""
kwargs = {}
if opts:
if not isinstance(opts, dict):
opts = opts.__dict__
else:
... | [
"def",
"get_view",
"(",
"self",
",",
"request",
",",
"view_class",
",",
"opts",
"=",
"None",
")",
":",
"kwargs",
"=",
"{",
"}",
"if",
"opts",
":",
"if",
"not",
"isinstance",
"(",
"opts",
",",
"dict",
")",
":",
"opts",
"=",
"opts",
".",
"__dict__",
... | Instantiates and returns the view class that will generate the
actual context for this plugin. | [
"Instantiates",
"and",
"returns",
"the",
"view",
"class",
"that",
"will",
"generate",
"the",
"actual",
"context",
"for",
"this",
"plugin",
"."
] | python | train | 32.172414 |
markokr/rarfile | rarfile.py | https://github.com/markokr/rarfile/blob/2704344e8d7a1658c96c8ed8f449d7ba01bedea3/rarfile.py#L685-L695 | def setpassword(self, password):
"""Sets the password to use when extracting.
"""
self._password = password
if self._file_parser:
if self._file_parser.has_header_encryption():
self._file_parser = None
if not self._file_parser:
self._parse()... | [
"def",
"setpassword",
"(",
"self",
",",
"password",
")",
":",
"self",
".",
"_password",
"=",
"password",
"if",
"self",
".",
"_file_parser",
":",
"if",
"self",
".",
"_file_parser",
".",
"has_header_encryption",
"(",
")",
":",
"self",
".",
"_file_parser",
"=... | Sets the password to use when extracting. | [
"Sets",
"the",
"password",
"to",
"use",
"when",
"extracting",
"."
] | python | train | 34.727273 |
StackStorm/pybind | pybind/nos/v6_0_2f/brocade_nameserver_rpc/__init__.py | https://github.com/StackStorm/pybind/blob/44c467e71b2b425be63867aba6e6fa28b2cfe7fb/pybind/nos/v6_0_2f/brocade_nameserver_rpc/__init__.py#L189-L213 | def _set_get_nameserver_detail(self, v, load=False):
"""
Setter method for get_nameserver_detail, mapped from YANG variable /brocade_nameserver_rpc/get_nameserver_detail (rpc)
If this variable is read-only (config: false) in the
source YANG file, then _set_get_nameserver_detail is considered as a privat... | [
"def",
"_set_get_nameserver_detail",
"(",
"self",
",",
"v",
",",
"load",
"=",
"False",
")",
":",
"if",
"hasattr",
"(",
"v",
",",
"\"_utype\"",
")",
":",
"v",
"=",
"v",
".",
"_utype",
"(",
"v",
")",
"try",
":",
"t",
"=",
"YANGDynClass",
"(",
"v",
... | Setter method for get_nameserver_detail, mapped from YANG variable /brocade_nameserver_rpc/get_nameserver_detail (rpc)
If this variable is read-only (config: false) in the
source YANG file, then _set_get_nameserver_detail is considered as a private
method. Backends looking to populate this variable should
... | [
"Setter",
"method",
"for",
"get_nameserver_detail",
"mapped",
"from",
"YANG",
"variable",
"/",
"brocade_nameserver_rpc",
"/",
"get_nameserver_detail",
"(",
"rpc",
")",
"If",
"this",
"variable",
"is",
"read",
"-",
"only",
"(",
"config",
":",
"false",
")",
"in",
... | python | train | 78.16 |
wiheto/teneto | teneto/temporalcommunity/integration.py | https://github.com/wiheto/teneto/blob/80d7a83a9adc1714589b020627c45bd5b66248ab/teneto/temporalcommunity/integration.py#L5-L45 | def integration(temporalcommunities, staticcommunities):
"""
Calculates the integration coefficient for each node. Measures the average probability
that a node is in the same community as nodes from other systems.
Parameters:
------------
temporalcommunities : array
temporal co... | [
"def",
"integration",
"(",
"temporalcommunities",
",",
"staticcommunities",
")",
":",
"# make sure the static and temporal communities have the same number of nodes",
"if",
"staticcommunities",
".",
"shape",
"[",
"0",
"]",
"!=",
"temporalcommunities",
".",
"shape",
"[",
"0"... | Calculates the integration coefficient for each node. Measures the average probability
that a node is in the same community as nodes from other systems.
Parameters:
------------
temporalcommunities : array
temporal communities vector (node,time)
staticcommunities : array
... | [
"Calculates",
"the",
"integration",
"coefficient",
"for",
"each",
"node",
".",
"Measures",
"the",
"average",
"probability",
"that",
"a",
"node",
"is",
"in",
"the",
"same",
"community",
"as",
"nodes",
"from",
"other",
"systems",
"."
] | python | train | 34.195122 |
StackStorm/pybind | pybind/slxos/v17s_1_02/routing_system/router/isis/router_isis_cmds_holder/router_isis_attributes/set_overload_bit/on_startup/__init__.py | https://github.com/StackStorm/pybind/blob/44c467e71b2b425be63867aba6e6fa28b2cfe7fb/pybind/slxos/v17s_1_02/routing_system/router/isis/router_isis_cmds_holder/router_isis_attributes/set_overload_bit/on_startup/__init__.py#L126-L147 | def _set_wait_for_bgp(self, v, load=False):
"""
Setter method for wait_for_bgp, mapped from YANG variable /routing_system/router/isis/router_isis_cmds_holder/router_isis_attributes/set_overload_bit/on_startup/wait_for_bgp (container)
If this variable is read-only (config: false) in the
source YANG file,... | [
"def",
"_set_wait_for_bgp",
"(",
"self",
",",
"v",
",",
"load",
"=",
"False",
")",
":",
"if",
"hasattr",
"(",
"v",
",",
"\"_utype\"",
")",
":",
"v",
"=",
"v",
".",
"_utype",
"(",
"v",
")",
"try",
":",
"t",
"=",
"YANGDynClass",
"(",
"v",
",",
"b... | Setter method for wait_for_bgp, mapped from YANG variable /routing_system/router/isis/router_isis_cmds_holder/router_isis_attributes/set_overload_bit/on_startup/wait_for_bgp (container)
If this variable is read-only (config: false) in the
source YANG file, then _set_wait_for_bgp is considered as a private
m... | [
"Setter",
"method",
"for",
"wait_for_bgp",
"mapped",
"from",
"YANG",
"variable",
"/",
"routing_system",
"/",
"router",
"/",
"isis",
"/",
"router_isis_cmds_holder",
"/",
"router_isis_attributes",
"/",
"set_overload_bit",
"/",
"on_startup",
"/",
"wait_for_bgp",
"(",
"... | python | train | 77.272727 |
Element-34/py.saunter | saunter/matchers.py | https://github.com/Element-34/py.saunter/blob/bdc8480b1453e082872c80d3382d42565b8ed9c0/saunter/matchers.py#L100-L114 | def verify_false(self, expr, msg=None):
"""
Soft assert for whether the condition is false
:params expr: the statement to evaluate
:params msg: (Optional) msg explaining the difference
"""
try:
self.assert_false(expr, msg)
except AssertionError, e:
... | [
"def",
"verify_false",
"(",
"self",
",",
"expr",
",",
"msg",
"=",
"None",
")",
":",
"try",
":",
"self",
".",
"assert_false",
"(",
"expr",
",",
"msg",
")",
"except",
"AssertionError",
",",
"e",
":",
"if",
"msg",
":",
"m",
"=",
"\"%s:\\n%s\"",
"%",
"... | Soft assert for whether the condition is false
:params expr: the statement to evaluate
:params msg: (Optional) msg explaining the difference | [
"Soft",
"assert",
"for",
"whether",
"the",
"condition",
"is",
"false"
] | python | train | 30.733333 |
liampauling/betfair | betfairlightweight/streaming/cache.py | https://github.com/liampauling/betfair/blob/8479392eb4849c525d78d43497c32c0bb108e977/betfairlightweight/streaming/cache.py#L223-L253 | def serialise(self):
"""Creates standard market book json response,
will error if EX_MARKET_DEF not incl.
"""
return {
'marketId': self.market_id,
'totalAvailable': None,
'isMarketDataDelayed': None,
'lastMatchTime': None,
'betD... | [
"def",
"serialise",
"(",
"self",
")",
":",
"return",
"{",
"'marketId'",
":",
"self",
".",
"market_id",
",",
"'totalAvailable'",
":",
"None",
",",
"'isMarketDataDelayed'",
":",
"None",
",",
"'lastMatchTime'",
":",
"None",
",",
"'betDelay'",
":",
"self",
".",
... | Creates standard market book json response,
will error if EX_MARKET_DEF not incl. | [
"Creates",
"standard",
"market",
"book",
"json",
"response",
"will",
"error",
"if",
"EX_MARKET_DEF",
"not",
"incl",
"."
] | python | train | 52.290323 |
user-cont/conu | conu/backend/k8s/utils.py | https://github.com/user-cont/conu/blob/08caae7bb6bdd265b55bb106c3da6a7946a5a352/conu/backend/k8s/utils.py#L23-L38 | def k8s_ports_to_metadata_ports(k8s_ports):
"""
:param k8s_ports: list of V1ServicePort
:return: list of str, list of exposed ports, example:
- ['1234/tcp', '8080/udp']
"""
ports = []
for k8s_port in k8s_ports:
if k8s_port.protocol is not None:
ports.append("%s/... | [
"def",
"k8s_ports_to_metadata_ports",
"(",
"k8s_ports",
")",
":",
"ports",
"=",
"[",
"]",
"for",
"k8s_port",
"in",
"k8s_ports",
":",
"if",
"k8s_port",
".",
"protocol",
"is",
"not",
"None",
":",
"ports",
".",
"append",
"(",
"\"%s/%s\"",
"%",
"(",
"k8s_port"... | :param k8s_ports: list of V1ServicePort
:return: list of str, list of exposed ports, example:
- ['1234/tcp', '8080/udp'] | [
":",
"param",
"k8s_ports",
":",
"list",
"of",
"V1ServicePort",
":",
"return",
":",
"list",
"of",
"str",
"list",
"of",
"exposed",
"ports",
"example",
":",
"-",
"[",
"1234",
"/",
"tcp",
"8080",
"/",
"udp",
"]"
] | python | train | 26.9375 |
biolink/ontobio | ontobio/sim/api/semsearch.py | https://github.com/biolink/ontobio/blob/4e512a7831cfe6bc1b32f2c3be2ba41bc5cf7345/ontobio/sim/api/semsearch.py#L204-L212 | def compare(self,
query_classes: Set,
reference_classes: Set,
method: Optional) -> SimResult:
"""
Given two lists of entites (classes, individual)
return their similarity
"""
raise NotImplementedError | [
"def",
"compare",
"(",
"self",
",",
"query_classes",
":",
"Set",
",",
"reference_classes",
":",
"Set",
",",
"method",
":",
"Optional",
")",
"->",
"SimResult",
":",
"raise",
"NotImplementedError"
] | Given two lists of entites (classes, individual)
return their similarity | [
"Given",
"two",
"lists",
"of",
"entites",
"(",
"classes",
"individual",
")",
"return",
"their",
"similarity"
] | python | train | 31.111111 |
larsyencken/csvdiff | csvdiff/__init__.py | https://github.com/larsyencken/csvdiff/blob/163dd9da676a8e5f926a935803726340261f03ae/csvdiff/__init__.py#L81-L84 | def _nice_fieldnames(all_columns, index_columns):
"Indexes on the left, other fields in alphabetical order on the right."
non_index_columns = set(all_columns).difference(index_columns)
return index_columns + sorted(non_index_columns) | [
"def",
"_nice_fieldnames",
"(",
"all_columns",
",",
"index_columns",
")",
":",
"non_index_columns",
"=",
"set",
"(",
"all_columns",
")",
".",
"difference",
"(",
"index_columns",
")",
"return",
"index_columns",
"+",
"sorted",
"(",
"non_index_columns",
")"
] | Indexes on the left, other fields in alphabetical order on the right. | [
"Indexes",
"on",
"the",
"left",
"other",
"fields",
"in",
"alphabetical",
"order",
"on",
"the",
"right",
"."
] | python | train | 60.5 |
Erotemic/utool | utool/util_dev.py | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_dev.py#L2499-L2509 | def execstr_funckw(func):
"""
for doctests kwargs
SeeAlso:
ut.exec_func_src
ut.argparse_funckw
"""
import utool as ut
funckw = ut.get_func_kwargs(func)
return ut.execstr_dict(funckw, explicit=True) | [
"def",
"execstr_funckw",
"(",
"func",
")",
":",
"import",
"utool",
"as",
"ut",
"funckw",
"=",
"ut",
".",
"get_func_kwargs",
"(",
"func",
")",
"return",
"ut",
".",
"execstr_dict",
"(",
"funckw",
",",
"explicit",
"=",
"True",
")"
] | for doctests kwargs
SeeAlso:
ut.exec_func_src
ut.argparse_funckw | [
"for",
"doctests",
"kwargs"
] | python | train | 21.090909 |
geertj/gruvi | lib/gruvi/dbus.py | https://github.com/geertj/gruvi/blob/1d77ca439600b6ea7a19aa1ee85dca0f3be3f3f8/lib/gruvi/dbus.py#L188-L203 | def parse_dbus_header(header):
"""Parse a D-BUS header. Return the message size."""
if six.indexbytes(header, 0) == ord('l'):
endian = '<'
elif six.indexbytes(header, 0) == ord('B'):
endian = '>'
else:
raise ValueError('illegal endianness')
if not 1 <= six.indexbytes(header, ... | [
"def",
"parse_dbus_header",
"(",
"header",
")",
":",
"if",
"six",
".",
"indexbytes",
"(",
"header",
",",
"0",
")",
"==",
"ord",
"(",
"'l'",
")",
":",
"endian",
"=",
"'<'",
"elif",
"six",
".",
"indexbytes",
"(",
"header",
",",
"0",
")",
"==",
"ord",... | Parse a D-BUS header. Return the message size. | [
"Parse",
"a",
"D",
"-",
"BUS",
"header",
".",
"Return",
"the",
"message",
"size",
"."
] | python | train | 41.375 |
myaooo/pysbrl | pysbrl/rule_list.py | https://github.com/myaooo/pysbrl/blob/74bba8c6913a7f82e32313108f8c3e025b89d9c7/pysbrl/rule_list.py#L227-L242 | def from_raw(self, rule_ids, outputs, raw_rules):
"""
A helper function that converts the results returned from C function
:param rule_ids:
:param outputs:
:param raw_rules:
:return:
"""
self._rule_pool = [([], [])] + raw_rules
self._rule_list = []... | [
"def",
"from_raw",
"(",
"self",
",",
"rule_ids",
",",
"outputs",
",",
"raw_rules",
")",
":",
"self",
".",
"_rule_pool",
"=",
"[",
"(",
"[",
"]",
",",
"[",
"]",
")",
"]",
"+",
"raw_rules",
"self",
".",
"_rule_list",
"=",
"[",
"]",
"for",
"i",
",",... | A helper function that converts the results returned from C function
:param rule_ids:
:param outputs:
:param raw_rules:
:return: | [
"A",
"helper",
"function",
"that",
"converts",
"the",
"results",
"returned",
"from",
"C",
"function",
":",
"param",
"rule_ids",
":",
":",
"param",
"outputs",
":",
":",
"param",
"raw_rules",
":",
":",
"return",
":"
] | python | train | 39.1875 |
ssato/python-anyconfig | src/anyconfig/utils.py | https://github.com/ssato/python-anyconfig/blob/f2f4fb8d8e232aadea866c202e1dd7a5967e2877/src/anyconfig/utils.py#L157-L176 | def is_ioinfo(obj, keys=None):
"""
:return: True if given 'obj' is a 'IOInfo' namedtuple object.
>>> assert not is_ioinfo(1)
>>> assert not is_ioinfo("aaa")
>>> assert not is_ioinfo({})
>>> assert not is_ioinfo(('a', 1, {}))
>>> inp = anyconfig.globals.IOInfo("/etc/hosts", "path", "/etc/ho... | [
"def",
"is_ioinfo",
"(",
"obj",
",",
"keys",
"=",
"None",
")",
":",
"if",
"keys",
"is",
"None",
":",
"keys",
"=",
"anyconfig",
".",
"globals",
".",
"IOI_KEYS",
"if",
"isinstance",
"(",
"obj",
",",
"tuple",
")",
"and",
"getattr",
"(",
"obj",
",",
"\... | :return: True if given 'obj' is a 'IOInfo' namedtuple object.
>>> assert not is_ioinfo(1)
>>> assert not is_ioinfo("aaa")
>>> assert not is_ioinfo({})
>>> assert not is_ioinfo(('a', 1, {}))
>>> inp = anyconfig.globals.IOInfo("/etc/hosts", "path", "/etc/hosts",
... ... | [
":",
"return",
":",
"True",
"if",
"given",
"obj",
"is",
"a",
"IOInfo",
"namedtuple",
"object",
"."
] | python | train | 29.8 |
flyingrub/scdl | scdl/scdl.py | https://github.com/flyingrub/scdl/blob/e833a22dd6676311b72fadd8a1c80f4a06acfad9/scdl/scdl.py#L323-L362 | def download(user, dl_type, name):
"""
Download user items of dl_type (ie. all, playlists, liked, commented, etc.)
"""
username = user['username']
user_id = user['id']
logger.info(
'Retrieving all {0} of user {1}...'.format(name, username)
)
dl_url = url[dl_type].format(user_id)
... | [
"def",
"download",
"(",
"user",
",",
"dl_type",
",",
"name",
")",
":",
"username",
"=",
"user",
"[",
"'username'",
"]",
"user_id",
"=",
"user",
"[",
"'id'",
"]",
"logger",
".",
"info",
"(",
"'Retrieving all {0} of user {1}...'",
".",
"format",
"(",
"name",... | Download user items of dl_type (ie. all, playlists, liked, commented, etc.) | [
"Download",
"user",
"items",
"of",
"dl_type",
"(",
"ie",
".",
"all",
"playlists",
"liked",
"commented",
"etc",
".",
")"
] | python | train | 35.85 |
SavinaRoja/OpenAccess_EPUB | src/openaccess_epub/utils/epub.py | https://github.com/SavinaRoja/OpenAccess_EPUB/blob/6b77ba30b7394fd003920e7a7957bca963a90656/src/openaccess_epub/utils/epub.py#L163-L191 | def epub_zip(outdirect):
"""
Zips up the input file directory into an EPUB file.
"""
def recursive_zip(zipf, directory, folder=None):
if folder is None:
folder = ''
for item in os.listdir(directory):
if os.path.isfile(os.path.join(directory, item)):
... | [
"def",
"epub_zip",
"(",
"outdirect",
")",
":",
"def",
"recursive_zip",
"(",
"zipf",
",",
"directory",
",",
"folder",
"=",
"None",
")",
":",
"if",
"folder",
"is",
"None",
":",
"folder",
"=",
"''",
"for",
"item",
"in",
"os",
".",
"listdir",
"(",
"direc... | Zips up the input file directory into an EPUB file. | [
"Zips",
"up",
"the",
"input",
"file",
"directory",
"into",
"an",
"EPUB",
"file",
"."
] | python | train | 35.517241 |
Rapptz/discord.py | discord/client.py | https://github.com/Rapptz/discord.py/blob/05d4f7f9620ef33635d6ac965b26528e09cdaf5b/discord/client.py#L502-L511 | async def start(self, *args, **kwargs):
"""|coro|
A shorthand coroutine for :meth:`login` + :meth:`connect`.
"""
bot = kwargs.pop('bot', True)
reconnect = kwargs.pop('reconnect', True)
await self.login(*args, bot=bot)
await self.connect(reconnect=reconnect) | [
"async",
"def",
"start",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"bot",
"=",
"kwargs",
".",
"pop",
"(",
"'bot'",
",",
"True",
")",
"reconnect",
"=",
"kwargs",
".",
"pop",
"(",
"'reconnect'",
",",
"True",
")",
"await",
"s... | |coro|
A shorthand coroutine for :meth:`login` + :meth:`connect`. | [
"|coro|"
] | python | train | 30.6 |
github/octodns | octodns/provider/azuredns.py | https://github.com/github/octodns/blob/65ee60491e22e6bb0a2aa08f7069c6ecf6c3fee6/octodns/provider/azuredns.py#L450-L467 | def _apply_Create(self, change):
'''A record from change must be created.
:param change: a change object
:type change: octodns.record.Change
:type return: void
'''
ar = _AzureRecord(self._resource_group, change.new)
create = self._dns_client.record_... | [
"def",
"_apply_Create",
"(",
"self",
",",
"change",
")",
":",
"ar",
"=",
"_AzureRecord",
"(",
"self",
".",
"_resource_group",
",",
"change",
".",
"new",
")",
"create",
"=",
"self",
".",
"_dns_client",
".",
"record_sets",
".",
"create_or_update",
"create",
... | A record from change must be created.
:param change: a change object
:type change: octodns.record.Change
:type return: void | [
"A",
"record",
"from",
"change",
"must",
"be",
"created",
"."
] | python | train | 35.222222 |
numenta/nupic | examples/opf/tools/sp_plotter.py | https://github.com/numenta/nupic/blob/5922fafffdccc8812e72b3324965ad2f7d4bbdad/examples/opf/tools/sp_plotter.py#L166-L190 | def modifyBits(inputVal, maxChanges):
""" Modifies up to maxChanges number of bits in the inputVal
"""
changes = np.random.random_integers(0, maxChanges, 1)[0]
if changes == 0:
return inputVal
inputWidth = len(inputVal)
whatToChange = np.random.random_integers(0, 41, changes)
runningIndex = -1
n... | [
"def",
"modifyBits",
"(",
"inputVal",
",",
"maxChanges",
")",
":",
"changes",
"=",
"np",
".",
"random",
".",
"random_integers",
"(",
"0",
",",
"maxChanges",
",",
"1",
")",
"[",
"0",
"]",
"if",
"changes",
"==",
"0",
":",
"return",
"inputVal",
"inputWidt... | Modifies up to maxChanges number of bits in the inputVal | [
"Modifies",
"up",
"to",
"maxChanges",
"number",
"of",
"bits",
"in",
"the",
"inputVal"
] | python | valid | 23.48 |
buildbot/buildbot | master/setup.py | https://github.com/buildbot/buildbot/blob/5df3cfae6d760557d99156633c32b1822a1e130c/master/setup.py#L42-L48 | def include(d, e):
"""Generate a pair of (directory, file-list) for installation.
'd' -- A directory
'e' -- A glob pattern"""
return (d, [f for f in glob.glob('%s/%s' % (d, e)) if os.path.isfile(f)]) | [
"def",
"include",
"(",
"d",
",",
"e",
")",
":",
"return",
"(",
"d",
",",
"[",
"f",
"for",
"f",
"in",
"glob",
".",
"glob",
"(",
"'%s/%s'",
"%",
"(",
"d",
",",
"e",
")",
")",
"if",
"os",
".",
"path",
".",
"isfile",
"(",
"f",
")",
"]",
")"
] | Generate a pair of (directory, file-list) for installation.
'd' -- A directory
'e' -- A glob pattern | [
"Generate",
"a",
"pair",
"of",
"(",
"directory",
"file",
"-",
"list",
")",
"for",
"installation",
"."
] | python | train | 30.142857 |
sunlightlabs/django-locksmith | locksmith/hub/models.py | https://github.com/sunlightlabs/django-locksmith/blob/eef5b7c25404560aaad50b6e622594f89239b74b/locksmith/hub/models.py#L82-L87 | def mark_for_update(self):
'''
Note that a change has been made so all Statuses need update
'''
self.pub_statuses.exclude(status=UNPUBLISHED).update(status=NEEDS_UPDATE)
push_key.delay(self) | [
"def",
"mark_for_update",
"(",
"self",
")",
":",
"self",
".",
"pub_statuses",
".",
"exclude",
"(",
"status",
"=",
"UNPUBLISHED",
")",
".",
"update",
"(",
"status",
"=",
"NEEDS_UPDATE",
")",
"push_key",
".",
"delay",
"(",
"self",
")"
] | Note that a change has been made so all Statuses need update | [
"Note",
"that",
"a",
"change",
"has",
"been",
"made",
"so",
"all",
"Statuses",
"need",
"update"
] | python | train | 38.166667 |
cnt-dev/cnt.rulebase | cnt/rulebase/rules/sentence_segmentation/sentence_segmenter.py | https://github.com/cnt-dev/cnt.rulebase/blob/d1c767c356d8ee05b23ec5b04aaac84784ee547c/cnt/rulebase/rules/sentence_segmentation/sentence_segmenter.py#L108-L170 | def result(self) -> workflow.IntervalGeneratorType:
"""
Generate intervals indicating the valid sentences.
"""
config = cast(SentenceSegementationConfig, self.config)
index = -1
labels = None
while True:
# 1. Find the start of the sentence.
... | [
"def",
"result",
"(",
"self",
")",
"->",
"workflow",
".",
"IntervalGeneratorType",
":",
"config",
"=",
"cast",
"(",
"SentenceSegementationConfig",
",",
"self",
".",
"config",
")",
"index",
"=",
"-",
"1",
"labels",
"=",
"None",
"while",
"True",
":",
"# 1. F... | Generate intervals indicating the valid sentences. | [
"Generate",
"intervals",
"indicating",
"the",
"valid",
"sentences",
"."
] | python | train | 37.206349 |
treycucco/bidon | bidon/db/access/model_access.py | https://github.com/treycucco/bidon/blob/d9f24596841d0e69e8ac70a1d1a1deecea95e340/bidon/db/access/model_access.py#L29-L34 | def find_models(self, constructor, constraints=None, *, columns=None, order_by=None,
limiting=None, table_name=None):
"""Specialization of DataAccess.find_all that returns models instead of cursor objects."""
return self._find_models(
constructor, table_name or constructor.table_name, co... | [
"def",
"find_models",
"(",
"self",
",",
"constructor",
",",
"constraints",
"=",
"None",
",",
"*",
",",
"columns",
"=",
"None",
",",
"order_by",
"=",
"None",
",",
"limiting",
"=",
"None",
",",
"table_name",
"=",
"None",
")",
":",
"return",
"self",
".",
... | Specialization of DataAccess.find_all that returns models instead of cursor objects. | [
"Specialization",
"of",
"DataAccess",
".",
"find_all",
"that",
"returns",
"models",
"instead",
"of",
"cursor",
"objects",
"."
] | python | train | 64.333333 |
hasgeek/coaster | coaster/utils/misc.py | https://github.com/hasgeek/coaster/blob/07f7eb5d5f516e22fa14fdf4dc70e0ae13ee398d/coaster/utils/misc.py#L401-L437 | def format_currency(value, decimals=2):
"""
Return a number suitably formatted for display as currency, with
thousands separated by commas and up to two decimal points.
>>> format_currency(1000)
'1,000'
>>> format_currency(100)
'100'
>>> format_currency(999.95)
'999.95'
>>> form... | [
"def",
"format_currency",
"(",
"value",
",",
"decimals",
"=",
"2",
")",
":",
"number",
",",
"decimal",
"=",
"(",
"(",
"u'%%.%df'",
"%",
"decimals",
")",
"%",
"value",
")",
".",
"split",
"(",
"u'.'",
")",
"parts",
"=",
"[",
"]",
"while",
"len",
"(",... | Return a number suitably formatted for display as currency, with
thousands separated by commas and up to two decimal points.
>>> format_currency(1000)
'1,000'
>>> format_currency(100)
'100'
>>> format_currency(999.95)
'999.95'
>>> format_currency(99.95)
'99.95'
>>> format_curren... | [
"Return",
"a",
"number",
"suitably",
"formatted",
"for",
"display",
"as",
"currency",
"with",
"thousands",
"separated",
"by",
"commas",
"and",
"up",
"to",
"two",
"decimal",
"points",
"."
] | python | train | 26.567568 |
datosgobar/pydatajson | pydatajson/search.py | https://github.com/datosgobar/pydatajson/blob/3141082ffbaa295e2deaf6ffbbc5a59f5859960e/pydatajson/search.py#L101-L180 | def get_distributions(catalog, filter_in=None, filter_out=None,
meta_field=None, exclude_meta_fields=None,
only_time_series=False):
"""Devuelve lista de distribuciones del catálogo o de uno de sus metadatos.
Args:
catalog (dict, str or DataJson): Representaci... | [
"def",
"get_distributions",
"(",
"catalog",
",",
"filter_in",
"=",
"None",
",",
"filter_out",
"=",
"None",
",",
"meta_field",
"=",
"None",
",",
"exclude_meta_fields",
"=",
"None",
",",
"only_time_series",
"=",
"False",
")",
":",
"filter_in",
"=",
"filter_in",
... | Devuelve lista de distribuciones del catálogo o de uno de sus metadatos.
Args:
catalog (dict, str or DataJson): Representación externa/interna de un
catálogo. Una representación _externa_ es un path local o una
URL remota a un archivo con la metadata de un catálogo, en
f... | [
"Devuelve",
"lista",
"de",
"distribuciones",
"del",
"catálogo",
"o",
"de",
"uno",
"de",
"sus",
"metadatos",
"."
] | python | train | 44.4625 |
shoebot/shoebot | lib/sbaudio/__init__.py | https://github.com/shoebot/shoebot/blob/d554c1765c1899fa25727c9fc6805d221585562b/lib/sbaudio/__init__.py#L55-L63 | def scaled_fft(fft, scale=1.0):
"""
Produces a nicer graph, I'm not sure if this is correct
"""
data = np.zeros(len(fft))
for i, v in enumerate(fft):
data[i] = scale * (i * v) / NUM_SAMPLES
return data | [
"def",
"scaled_fft",
"(",
"fft",
",",
"scale",
"=",
"1.0",
")",
":",
"data",
"=",
"np",
".",
"zeros",
"(",
"len",
"(",
"fft",
")",
")",
"for",
"i",
",",
"v",
"in",
"enumerate",
"(",
"fft",
")",
":",
"data",
"[",
"i",
"]",
"=",
"scale",
"*",
... | Produces a nicer graph, I'm not sure if this is correct | [
"Produces",
"a",
"nicer",
"graph",
"I",
"m",
"not",
"sure",
"if",
"this",
"is",
"correct"
] | python | valid | 25.111111 |
tensorpack/tensorpack | tensorpack/dataflow/format.py | https://github.com/tensorpack/tensorpack/blob/d7a13cb74c9066bc791d7aafc3b744b60ee79a9f/tensorpack/dataflow/format.py#L167-L202 | def CaffeLMDB(lmdb_path, shuffle=True, keys=None):
"""
Read a Caffe LMDB file where each value contains a ``caffe.Datum`` protobuf.
Produces datapoints of the format: [HWC image, label].
Note that Caffe LMDB format is not efficient: it stores serialized raw
arrays rather than JPEG images.
Args... | [
"def",
"CaffeLMDB",
"(",
"lmdb_path",
",",
"shuffle",
"=",
"True",
",",
"keys",
"=",
"None",
")",
":",
"cpb",
"=",
"get_caffe_pb",
"(",
")",
"lmdb_data",
"=",
"LMDBData",
"(",
"lmdb_path",
",",
"shuffle",
",",
"keys",
")",
"def",
"decoder",
"(",
"k",
... | Read a Caffe LMDB file where each value contains a ``caffe.Datum`` protobuf.
Produces datapoints of the format: [HWC image, label].
Note that Caffe LMDB format is not efficient: it stores serialized raw
arrays rather than JPEG images.
Args:
lmdb_path, shuffle, keys: same as :class:`LMDBData`.
... | [
"Read",
"a",
"Caffe",
"LMDB",
"file",
"where",
"each",
"value",
"contains",
"a",
"caffe",
".",
"Datum",
"protobuf",
".",
"Produces",
"datapoints",
"of",
"the",
"format",
":",
"[",
"HWC",
"image",
"label",
"]",
"."
] | python | train | 33 |
jmgilman/Neolib | neolib/pyamf/util/pure.py | https://github.com/jmgilman/Neolib/blob/228fafeaed0f3195676137732384a14820ae285c/neolib/pyamf/util/pure.py#L116-L123 | def write(self, s, size=None):
"""
Writes the content of the specified C{s} into this buffer.
@param s: Raw bytes
"""
self._buffer.write(s)
self._len_changed = True | [
"def",
"write",
"(",
"self",
",",
"s",
",",
"size",
"=",
"None",
")",
":",
"self",
".",
"_buffer",
".",
"write",
"(",
"s",
")",
"self",
".",
"_len_changed",
"=",
"True"
] | Writes the content of the specified C{s} into this buffer.
@param s: Raw bytes | [
"Writes",
"the",
"content",
"of",
"the",
"specified",
"C",
"{",
"s",
"}",
"into",
"this",
"buffer",
"."
] | python | train | 25.75 |
astrocatalogs/astrocats | astrocats/catalog/gitter.py | https://github.com/astrocatalogs/astrocats/blob/11abc3131c6366ecd23964369e55ff264add7805/astrocats/catalog/gitter.py#L30-L56 | def get_sha(path=None, log=None, short=False, timeout=None):
"""Use `git rev-parse HEAD <REPO>` to get current SHA.
"""
# git_command = "git rev-parse HEAD {}".format(repo_name).split()
# git_command = "git rev-parse HEAD".split()
git_command = ["git", "rev-parse"]
if short:
git_command.... | [
"def",
"get_sha",
"(",
"path",
"=",
"None",
",",
"log",
"=",
"None",
",",
"short",
"=",
"False",
",",
"timeout",
"=",
"None",
")",
":",
"# git_command = \"git rev-parse HEAD {}\".format(repo_name).split()",
"# git_command = \"git rev-parse HEAD\".split()",
"git_command",
... | Use `git rev-parse HEAD <REPO>` to get current SHA. | [
"Use",
"git",
"rev",
"-",
"parse",
"HEAD",
"<REPO",
">",
"to",
"get",
"current",
"SHA",
"."
] | python | train | 29.111111 |
gwastro/pycbc | pycbc/transforms.py | https://github.com/gwastro/pycbc/blob/7a64cdd104d263f1b6ea0b01e6841837d05a4cb3/pycbc/transforms.py#L107-L161 | def from_config(cls, cp, section, outputs, skip_opts=None,
additional_opts=None):
"""Initializes a transform from the given section.
Parameters
----------
cp : pycbc.workflow.WorkflowConfigParser
A parsed configuration file that contains the transform opt... | [
"def",
"from_config",
"(",
"cls",
",",
"cp",
",",
"section",
",",
"outputs",
",",
"skip_opts",
"=",
"None",
",",
"additional_opts",
"=",
"None",
")",
":",
"tag",
"=",
"outputs",
"if",
"skip_opts",
"is",
"None",
":",
"skip_opts",
"=",
"[",
"]",
"if",
... | Initializes a transform from the given section.
Parameters
----------
cp : pycbc.workflow.WorkflowConfigParser
A parsed configuration file that contains the transform options.
section : str
Name of the section in the configuration file.
outputs : str
... | [
"Initializes",
"a",
"transform",
"from",
"the",
"given",
"section",
"."
] | python | train | 38.818182 |
twidi/py-dataql | dataql/parsers/generic.py | https://github.com/twidi/py-dataql/blob/5841a3fd559829193ed709c255166085bdde1c52/dataql/parsers/generic.py#L373-L399 | def visit_field(self, _, children):
"""A simple field.
Arguments
---------
_ (node) : parsimonious.nodes.Node.
children : list
- 0: for ``FILTERS``: list of instances of ``.resources.Field``.
Returns
-------
.resources.Field
An in... | [
"def",
"visit_field",
"(",
"self",
",",
"_",
",",
"children",
")",
":",
"filters",
"=",
"children",
"[",
"0",
"]",
"return",
"self",
".",
"Field",
"(",
"getattr",
"(",
"filters",
"[",
"0",
"]",
",",
"'name'",
",",
"None",
")",
",",
"filters",
"=",
... | A simple field.
Arguments
---------
_ (node) : parsimonious.nodes.Node.
children : list
- 0: for ``FILTERS``: list of instances of ``.resources.Field``.
Returns
-------
.resources.Field
An instance of ``.resources.Field`` with the correct... | [
"A",
"simple",
"field",
"."
] | python | train | 28.851852 |
petebachant/PXL | pxl/timeseries.py | https://github.com/petebachant/PXL/blob/d7d06cb74422e1ac0154741351fbecea080cfcc0/pxl/timeseries.py#L91-L96 | def average_over_area(q, x, y):
"""Averages a quantity `q` over a rectangular area given a 2D array and
the x and y vectors for sample locations, using the trapezoidal rule"""
area = (np.max(x) - np.min(x))*(np.max(y) - np.min(y))
integral = np.trapz(np.trapz(q, y, axis=0), x)
return integral/a... | [
"def",
"average_over_area",
"(",
"q",
",",
"x",
",",
"y",
")",
":",
"area",
"=",
"(",
"np",
".",
"max",
"(",
"x",
")",
"-",
"np",
".",
"min",
"(",
"x",
")",
")",
"*",
"(",
"np",
".",
"max",
"(",
"y",
")",
"-",
"np",
".",
"min",
"(",
"y"... | Averages a quantity `q` over a rectangular area given a 2D array and
the x and y vectors for sample locations, using the trapezoidal rule | [
"Averages",
"a",
"quantity",
"q",
"over",
"a",
"rectangular",
"area",
"given",
"a",
"2D",
"array",
"and",
"the",
"x",
"and",
"y",
"vectors",
"for",
"sample",
"locations",
"using",
"the",
"trapezoidal",
"rule"
] | python | train | 53 |
Stufinite/djangoApiDec | djangoApiDec/djangoApiDec.py | https://github.com/Stufinite/djangoApiDec/blob/8b2d5776b3413b1b850df12a92f30526c05c0a46/djangoApiDec/djangoApiDec.py#L38-L54 | def queryString_required(strList):
""" An decorator checking whether queryString key is valid or not
Args:
str: allowed queryString key
Returns:
if contains invalid queryString key, it will raise exception.
"""
def _dec(function):
@wraps(function)
def _wrap(request, *args, **kwargs):
for i in strList:
... | [
"def",
"queryString_required",
"(",
"strList",
")",
":",
"def",
"_dec",
"(",
"function",
")",
":",
"@",
"wraps",
"(",
"function",
")",
"def",
"_wrap",
"(",
"request",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"for",
"i",
"in",
"strList",
... | An decorator checking whether queryString key is valid or not
Args:
str: allowed queryString key
Returns:
if contains invalid queryString key, it will raise exception. | [
"An",
"decorator",
"checking",
"whether",
"queryString",
"key",
"is",
"valid",
"or",
"not",
"Args",
":",
"str",
":",
"allowed",
"queryString",
"key"
] | python | valid | 26.235294 |
aiogram/aiogram | aiogram/utils/payload.py | https://github.com/aiogram/aiogram/blob/2af930149ce2482547721e2c8755c10307295e48/aiogram/utils/payload.py#L30-L43 | def _normalize(obj):
"""
Normalize dicts and lists
:param obj:
:return: normalized object
"""
if isinstance(obj, list):
return [_normalize(item) for item in obj]
elif isinstance(obj, dict):
return {k: _normalize(v) for k, v in obj.items() if v is not None}
elif hasattr(o... | [
"def",
"_normalize",
"(",
"obj",
")",
":",
"if",
"isinstance",
"(",
"obj",
",",
"list",
")",
":",
"return",
"[",
"_normalize",
"(",
"item",
")",
"for",
"item",
"in",
"obj",
"]",
"elif",
"isinstance",
"(",
"obj",
",",
"dict",
")",
":",
"return",
"{"... | Normalize dicts and lists
:param obj:
:return: normalized object | [
"Normalize",
"dicts",
"and",
"lists"
] | python | train | 26.428571 |
guysv/txkernel | txkernel/connection.py | https://github.com/guysv/txkernel/blob/a0aa1591df347732264f594bb13bc10d8aaf0f23/txkernel/connection.py#L42-L50 | def generate(cls, partial_props=None):
"""
Generate new connection file props from
defaults
"""
partial_props = partial_props or {}
props = partial_props.copy()
props.update(cls.DEFAULT_PROPERTIES)
return cls(props) | [
"def",
"generate",
"(",
"cls",
",",
"partial_props",
"=",
"None",
")",
":",
"partial_props",
"=",
"partial_props",
"or",
"{",
"}",
"props",
"=",
"partial_props",
".",
"copy",
"(",
")",
"props",
".",
"update",
"(",
"cls",
".",
"DEFAULT_PROPERTIES",
")",
"... | Generate new connection file props from
defaults | [
"Generate",
"new",
"connection",
"file",
"props",
"from",
"defaults"
] | python | train | 30.111111 |
pschmitt/pykeepass | pykeepass/kdbx_parsing/common.py | https://github.com/pschmitt/pykeepass/blob/85da3630d6e410b2a10d3e711cd69308b51d401d/pykeepass/kdbx_parsing/common.py#L101-L144 | def compute_key_composite(password=None, keyfile=None):
"""Compute composite key.
Used in header verification and payload decryption."""
# hash the password
if password:
password_composite = hashlib.sha256(password.encode('utf-8')).digest()
else:
password_composite = b''
# hash ... | [
"def",
"compute_key_composite",
"(",
"password",
"=",
"None",
",",
"keyfile",
"=",
"None",
")",
":",
"# hash the password",
"if",
"password",
":",
"password_composite",
"=",
"hashlib",
".",
"sha256",
"(",
"password",
".",
"encode",
"(",
"'utf-8'",
")",
")",
... | Compute composite key.
Used in header verification and payload decryption. | [
"Compute",
"composite",
"key",
".",
"Used",
"in",
"header",
"verification",
"and",
"payload",
"decryption",
"."
] | python | train | 38.568182 |
tomduck/pandoc-tablenos | pandoc_tablenos.py | https://github.com/tomduck/pandoc-tablenos/blob/b3c7b6a259eec5fb7c8420033d05b32640f1f266/pandoc_tablenos.py#L89-L107 | def attach_attrs_table(key, value, fmt, meta):
"""Extracts attributes and attaches them to element."""
# We can't use attach_attrs_factory() because Table is a block-level element
if key in ['Table']:
assert len(value) == 5
caption = value[0] # caption, align, x, head, body
# Set ... | [
"def",
"attach_attrs_table",
"(",
"key",
",",
"value",
",",
"fmt",
",",
"meta",
")",
":",
"# We can't use attach_attrs_factory() because Table is a block-level element",
"if",
"key",
"in",
"[",
"'Table'",
"]",
":",
"assert",
"len",
"(",
"value",
")",
"==",
"5",
... | Extracts attributes and attaches them to element. | [
"Extracts",
"attributes",
"and",
"attaches",
"them",
"to",
"element",
"."
] | python | train | 33.894737 |
wbond/vat_moss-python | vat_moss/exchange_rates.py | https://github.com/wbond/vat_moss-python/blob/5089dcf036eb2e9abc58e78186fd46b522a50620/vat_moss/exchange_rates.py#L26-L158 | def fetch():
"""
Fetches the latest exchange rate info from the European Central Bank. These
rates need to be used for displaying invoices since some countries require
local currency be quoted. Also useful to store the GBP rate of the VAT
collected at time of purchase to prevent fluctuations in exch... | [
"def",
"fetch",
"(",
")",
":",
"response",
"=",
"urlopen",
"(",
"'https://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml'",
")",
"_",
",",
"params",
"=",
"cgi",
".",
"parse_header",
"(",
"response",
".",
"headers",
"[",
"'Content-Type'",
"]",
")",
"if",
"... | Fetches the latest exchange rate info from the European Central Bank. These
rates need to be used for displaying invoices since some countries require
local currency be quoted. Also useful to store the GBP rate of the VAT
collected at time of purchase to prevent fluctuations in exchange rates from
signi... | [
"Fetches",
"the",
"latest",
"exchange",
"rate",
"info",
"from",
"the",
"European",
"Central",
"Bank",
".",
"These",
"rates",
"need",
"to",
"be",
"used",
"for",
"displaying",
"invoices",
"since",
"some",
"countries",
"require",
"local",
"currency",
"be",
"quote... | python | train | 36.849624 |
SKA-ScienceDataProcessor/integration-prototype | sip/tango_control/tango_processing_block/app/delete_devices.py | https://github.com/SKA-ScienceDataProcessor/integration-prototype/blob/8c8006de6ad71dcd44114b0338780738079c87d4/sip/tango_control/tango_processing_block/app/delete_devices.py#L11-L24 | def delete_pb_devices():
"""Delete PBs devices from the Tango database."""
parser = argparse.ArgumentParser(description='Register PB devices.')
parser.add_argument('num_pb', type=int,
help='Number of PBs devices to register.')
args = parser.parse_args()
log = logging.getLogg... | [
"def",
"delete_pb_devices",
"(",
")",
":",
"parser",
"=",
"argparse",
".",
"ArgumentParser",
"(",
"description",
"=",
"'Register PB devices.'",
")",
"parser",
".",
"add_argument",
"(",
"'num_pb'",
",",
"type",
"=",
"int",
",",
"help",
"=",
"'Number of PBs device... | Delete PBs devices from the Tango database. | [
"Delete",
"PBs",
"devices",
"from",
"the",
"Tango",
"database",
"."
] | python | train | 39.714286 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.