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 |
|---|---|---|---|---|---|---|---|---|---|
fprimex/zdesk | zdesk/zdesk_api.py | https://github.com/fprimex/zdesk/blob/851611c13b4d530e9df31390b3ec709baf0a0188/zdesk/zdesk_api.py#L4399-L4402 | def views_preview_count(self, data, **kwargs):
"https://developer.zendesk.com/rest_api/docs/core/views#preview-count"
api_path = "/api/v2/views/preview/count.json"
return self.call(api_path, method="POST", data=data, **kwargs) | [
"def",
"views_preview_count",
"(",
"self",
",",
"data",
",",
"*",
"*",
"kwargs",
")",
":",
"api_path",
"=",
"\"/api/v2/views/preview/count.json\"",
"return",
"self",
".",
"call",
"(",
"api_path",
",",
"method",
"=",
"\"POST\"",
",",
"data",
"=",
"data",
",",... | https://developer.zendesk.com/rest_api/docs/core/views#preview-count | [
"https",
":",
"//",
"developer",
".",
"zendesk",
".",
"com",
"/",
"rest_api",
"/",
"docs",
"/",
"core",
"/",
"views#preview",
"-",
"count"
] | python | train | 61.75 |
tdryer/hangups | hangups/conversation.py | https://github.com/tdryer/hangups/blob/85c0bf0a57698d077461283895707260f9dbf931/hangups/conversation.py#L836-L872 | async def _on_state_update(self, state_update):
"""Receive a StateUpdate and fan out to Conversations.
Args:
state_update: hangouts_pb2.StateUpdate instance
"""
# The state update will include some type of notification:
notification_type = state_update.WhichOneof('st... | [
"async",
"def",
"_on_state_update",
"(",
"self",
",",
"state_update",
")",
":",
"# The state update will include some type of notification:",
"notification_type",
"=",
"state_update",
".",
"WhichOneof",
"(",
"'state_update'",
")",
"# If conversation fields have been updated, the ... | Receive a StateUpdate and fan out to Conversations.
Args:
state_update: hangouts_pb2.StateUpdate instance | [
"Receive",
"a",
"StateUpdate",
"and",
"fan",
"out",
"to",
"Conversations",
"."
] | python | valid | 40.567568 |
ebu/PlugIt | plugit_proxy/views.py | https://github.com/ebu/PlugIt/blob/de5f1e870f67caaef7a4a58e4bb1ed54d9c5dc53/plugit_proxy/views.py#L36-L59 | def getPlugItObject(hproPk):
"""Return the plugit object and the baseURI to use if not in standalone mode"""
from hprojects.models import HostedProject
try:
hproject = HostedProject.objects.get(pk=hproPk)
except (HostedProject.DoesNotExist, ValueError):
try:
hproject = Host... | [
"def",
"getPlugItObject",
"(",
"hproPk",
")",
":",
"from",
"hprojects",
".",
"models",
"import",
"HostedProject",
"try",
":",
"hproject",
"=",
"HostedProject",
".",
"objects",
".",
"get",
"(",
"pk",
"=",
"hproPk",
")",
"except",
"(",
"HostedProject",
".",
... | Return the plugit object and the baseURI to use if not in standalone mode | [
"Return",
"the",
"plugit",
"object",
"and",
"the",
"baseURI",
"to",
"use",
"if",
"not",
"in",
"standalone",
"mode"
] | python | train | 35.916667 |
saltstack/salt | salt/modules/boto_apigateway.py | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/boto_apigateway.py#L1642-L1664 | def attach_usage_plan_to_apis(plan_id, apis, region=None, key=None, keyid=None, profile=None):
'''
Attaches given usage plan to each of the apis provided in a list of apiId and stage values
.. versionadded:: 2017.7.0
apis
a list of dictionaries, where each dictionary contains the following:
... | [
"def",
"attach_usage_plan_to_apis",
"(",
"plan_id",
",",
"apis",
",",
"region",
"=",
"None",
",",
"key",
"=",
"None",
",",
"keyid",
"=",
"None",
",",
"profile",
"=",
"None",
")",
":",
"return",
"_update_usage_plan_apis",
"(",
"plan_id",
",",
"apis",
",",
... | Attaches given usage plan to each of the apis provided in a list of apiId and stage values
.. versionadded:: 2017.7.0
apis
a list of dictionaries, where each dictionary contains the following:
apiId
a string, which is the id of the created API in AWS ApiGateway
stage
... | [
"Attaches",
"given",
"usage",
"plan",
"to",
"each",
"of",
"the",
"apis",
"provided",
"in",
"a",
"list",
"of",
"apiId",
"and",
"stage",
"values"
] | python | train | 34.26087 |
hotdoc/hotdoc | hotdoc/core/config.py | https://github.com/hotdoc/hotdoc/blob/1067cdc8482b585b364a38fb52ca5d904e486280/hotdoc/core/config.py#L31-L52 | def load_config_json(conf_file):
"""Banana?"""
try:
with open(conf_file) as _:
try:
json_conf = json.load(_)
except ValueError as ze_error:
error('invalid-config',
'The provided configuration file %s is not valid json.\n'
... | [
"def",
"load_config_json",
"(",
"conf_file",
")",
":",
"try",
":",
"with",
"open",
"(",
"conf_file",
")",
"as",
"_",
":",
"try",
":",
"json_conf",
"=",
"json",
".",
"load",
"(",
"_",
")",
"except",
"ValueError",
"as",
"ze_error",
":",
"error",
"(",
"... | Banana? | [
"Banana?"
] | python | train | 35.363636 |
glue-viz/glue-vispy-viewers | glue_vispy_viewers/extern/vispy/util/config.py | https://github.com/glue-viz/glue-vispy-viewers/blob/54a4351d98c1f90dfb1a557d1b447c1f57470eea/glue_vispy_viewers/extern/vispy/util/config.py#L188-L224 | def _get_vispy_app_dir():
"""Helper to get the default directory for storing vispy data"""
# Define default user directory
user_dir = os.path.expanduser('~')
# Get system app data dir
path = None
if sys.platform.startswith('win'):
path1, path2 = os.getenv('LOCALAPPDATA'), os.getenv('APP... | [
"def",
"_get_vispy_app_dir",
"(",
")",
":",
"# Define default user directory",
"user_dir",
"=",
"os",
".",
"path",
".",
"expanduser",
"(",
"'~'",
")",
"# Get system app data dir",
"path",
"=",
"None",
"if",
"sys",
".",
"platform",
".",
"startswith",
"(",
"'win'"... | Helper to get the default directory for storing vispy data | [
"Helper",
"to",
"get",
"the",
"default",
"directory",
"for",
"storing",
"vispy",
"data"
] | python | train | 39.27027 |
inveniosoftware/invenio-search | invenio_search/cli.py | https://github.com/inveniosoftware/invenio-search/blob/19c073d608d4c811f1c5aecb6622402d39715228/invenio_search/cli.py#L68-L81 | def init(force):
"""Initialize registered aliases and mappings."""
click.secho('Creating indexes...', fg='green', bold=True, file=sys.stderr)
with click.progressbar(
current_search.create(ignore=[400] if force else None),
length=current_search.number_of_indexes) as bar:
for n... | [
"def",
"init",
"(",
"force",
")",
":",
"click",
".",
"secho",
"(",
"'Creating indexes...'",
",",
"fg",
"=",
"'green'",
",",
"bold",
"=",
"True",
",",
"file",
"=",
"sys",
".",
"stderr",
")",
"with",
"click",
".",
"progressbar",
"(",
"current_search",
".... | Initialize registered aliases and mappings. | [
"Initialize",
"registered",
"aliases",
"and",
"mappings",
"."
] | python | train | 47.642857 |
inveniosoftware-contrib/invenio-workflows | invenio_workflows/models.py | https://github.com/inveniosoftware-contrib/invenio-workflows/blob/9c09fd29509a3db975ac2aba337e6760d8cfd3c2/invenio_workflows/models.py#L96-L99 | def delete(cls, uuid):
"""Delete a workflow."""
to_delete = Workflow.query.get(uuid)
db.session.delete(to_delete) | [
"def",
"delete",
"(",
"cls",
",",
"uuid",
")",
":",
"to_delete",
"=",
"Workflow",
".",
"query",
".",
"get",
"(",
"uuid",
")",
"db",
".",
"session",
".",
"delete",
"(",
"to_delete",
")"
] | Delete a workflow. | [
"Delete",
"a",
"workflow",
"."
] | python | train | 33.5 |
pymc-devs/pymc | pymc/examples/disaster_model_gof.py | https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/examples/disaster_model_gof.py#L50-L55 | def disasters_sim(early_mean=early_mean,
late_mean=late_mean,
switchpoint=switchpoint):
"""Coal mining disasters sampled from the posterior predictive distribution"""
return concatenate((pm.rpoisson(early_mean, size=switchpoint), pm.rpoisson(
late_mean, size=n - switc... | [
"def",
"disasters_sim",
"(",
"early_mean",
"=",
"early_mean",
",",
"late_mean",
"=",
"late_mean",
",",
"switchpoint",
"=",
"switchpoint",
")",
":",
"return",
"concatenate",
"(",
"(",
"pm",
".",
"rpoisson",
"(",
"early_mean",
",",
"size",
"=",
"switchpoint",
... | Coal mining disasters sampled from the posterior predictive distribution | [
"Coal",
"mining",
"disasters",
"sampled",
"from",
"the",
"posterior",
"predictive",
"distribution"
] | python | train | 54 |
coreGreenberet/homematicip-rest-api | homematicip/home.py | https://github.com/coreGreenberet/homematicip-rest-api/blob/d4c8df53281577e01709f75cacb78b1a5a1d00db/homematicip/home.py#L559-L578 | def set_pin(self, newPin: str, oldPin: str = None) -> dict:
""" sets a new pin for the home
Args:
newPin(str): the new pin
oldPin(str): optional, if there is currently a pin active it must be given here.
Otherwise it will not be possible to set the ... | [
"def",
"set_pin",
"(",
"self",
",",
"newPin",
":",
"str",
",",
"oldPin",
":",
"str",
"=",
"None",
")",
"->",
"dict",
":",
"if",
"newPin",
"==",
"None",
":",
"newPin",
"=",
"\"\"",
"data",
"=",
"{",
"\"pin\"",
":",
"newPin",
"}",
"if",
"oldPin",
"... | sets a new pin for the home
Args:
newPin(str): the new pin
oldPin(str): optional, if there is currently a pin active it must be given here.
Otherwise it will not be possible to set the new pin
Returns:
the result of the call | [
"sets",
"a",
"new",
"pin",
"for",
"the",
"home",
"Args",
":",
"newPin",
"(",
"str",
")",
":",
"the",
"new",
"pin",
"oldPin",
"(",
"str",
")",
":",
"optional",
"if",
"there",
"is",
"currently",
"a",
"pin",
"active",
"it",
"must",
"be",
"given",
"her... | python | train | 35.2 |
astropy/photutils | photutils/psf/models.py | https://github.com/astropy/photutils/blob/cc9bb4534ab76bac98cb5f374a348a2573d10401/photutils/psf/models.py#L708-L742 | def evaluate(self, x, y, flux, x_0, y_0):
"""
Evaluate the `GriddedPSFModel` for the input parameters.
"""
# NOTE: this is needed because the PSF photometry routines input
# length-1 values instead of scalars. TODO: fix the photometry
# routines.
if not np.issca... | [
"def",
"evaluate",
"(",
"self",
",",
"x",
",",
"y",
",",
"flux",
",",
"x_0",
",",
"y_0",
")",
":",
"# NOTE: this is needed because the PSF photometry routines input",
"# length-1 values instead of scalars. TODO: fix the photometry",
"# routines.",
"if",
"not",
"np",
".",... | Evaluate the `GriddedPSFModel` for the input parameters. | [
"Evaluate",
"the",
"GriddedPSFModel",
"for",
"the",
"input",
"parameters",
"."
] | python | train | 41.771429 |
RudolfCardinal/pythonlib | cardinal_pythonlib/rnc_db.py | https://github.com/RudolfCardinal/pythonlib/blob/0b84cb35f38bd7d8723958dae51b480a829b7227/cardinal_pythonlib/rnc_db.py#L907-L920 | def get_sql_select_all_fields_by_key(
table: str,
fieldlist: Sequence[str],
keyname: str,
delims: Tuple[str, str] = ("", "")) -> str:
"""Returns SQL:
SELECT [all fields in the fieldlist] WHERE [keyname] = ?
"""
return (
"SELECT " +
",".join([delimit(x,... | [
"def",
"get_sql_select_all_fields_by_key",
"(",
"table",
":",
"str",
",",
"fieldlist",
":",
"Sequence",
"[",
"str",
"]",
",",
"keyname",
":",
"str",
",",
"delims",
":",
"Tuple",
"[",
"str",
",",
"str",
"]",
"=",
"(",
"\"\"",
",",
"\"\"",
")",
")",
"-... | Returns SQL:
SELECT [all fields in the fieldlist] WHERE [keyname] = ? | [
"Returns",
"SQL",
":",
"SELECT",
"[",
"all",
"fields",
"in",
"the",
"fieldlist",
"]",
"WHERE",
"[",
"keyname",
"]",
"=",
"?"
] | python | train | 31.428571 |
bwohlberg/sporco | sporco/cnvrep.py | https://github.com/bwohlberg/sporco/blob/8946a04331106f4e39904fbdf2dc7351900baa04/sporco/cnvrep.py#L655-L677 | def normalise(v, dimN=2):
r"""Normalise vectors, corresponding to slices along specified number
of initial spatial dimensions of an array, to have unit
:math:`\ell_2` norm. The remaining axes enumerate the distinct
vectors to be normalised.
Parameters
----------
v : array_like
Array w... | [
"def",
"normalise",
"(",
"v",
",",
"dimN",
"=",
"2",
")",
":",
"axisN",
"=",
"tuple",
"(",
"range",
"(",
"0",
",",
"dimN",
")",
")",
"vn",
"=",
"np",
".",
"sqrt",
"(",
"np",
".",
"sum",
"(",
"v",
"**",
"2",
",",
"axisN",
",",
"keepdims",
"=... | r"""Normalise vectors, corresponding to slices along specified number
of initial spatial dimensions of an array, to have unit
:math:`\ell_2` norm. The remaining axes enumerate the distinct
vectors to be normalised.
Parameters
----------
v : array_like
Array with components to be normalise... | [
"r",
"Normalise",
"vectors",
"corresponding",
"to",
"slices",
"along",
"specified",
"number",
"of",
"initial",
"spatial",
"dimensions",
"of",
"an",
"array",
"to",
"have",
"unit",
":",
"math",
":",
"\\",
"ell_2",
"norm",
".",
"The",
"remaining",
"axes",
"enum... | python | train | 28.956522 |
SylvanasSun/FishFishJump | fish_core/simhash.py | https://github.com/SylvanasSun/FishFishJump/blob/696212d242d8d572f3f1b43925f3d8ab8acc6a2d/fish_core/simhash.py#L103-L119 | def simhash(self, content):
"""
Select policies for simhash on the different types of content.
"""
if content is None:
self.hash = -1
return
if isinstance(content, str):
features = self.tokenizer_func(content, self.keyword_weight_pari)
... | [
"def",
"simhash",
"(",
"self",
",",
"content",
")",
":",
"if",
"content",
"is",
"None",
":",
"self",
".",
"hash",
"=",
"-",
"1",
"return",
"if",
"isinstance",
"(",
"content",
",",
"str",
")",
":",
"features",
"=",
"self",
".",
"tokenizer_func",
"(",
... | Select policies for simhash on the different types of content. | [
"Select",
"policies",
"for",
"simhash",
"on",
"the",
"different",
"types",
"of",
"content",
"."
] | python | train | 37.117647 |
CalebBell/thermo | thermo/safety.py | https://github.com/CalebBell/thermo/blob/3857ed023a3e64fd3039a32d53576c24990ef1c3/thermo/safety.py#L1179-L1229 | def Crowl_Louvar_UFL(atoms):
r'''Calculates upper flammability limit, using the Crowl-Louvar [1]_
correlation. Uses molecular formula only.
The upper flammability limit of a gas is air is:
.. math::
C_mH_xO_y + zO_2 \to mCO_2 + \frac{x}{2}H_2O
\text{UFL} = \frac{3.5}{4.76m + 1.19x - 2... | [
"def",
"Crowl_Louvar_UFL",
"(",
"atoms",
")",
":",
"nC",
",",
"nH",
",",
"nO",
"=",
"0",
",",
"0",
",",
"0",
"if",
"'C'",
"in",
"atoms",
"and",
"atoms",
"[",
"'C'",
"]",
":",
"nC",
"=",
"atoms",
"[",
"'C'",
"]",
"else",
":",
"return",
"None",
... | r'''Calculates upper flammability limit, using the Crowl-Louvar [1]_
correlation. Uses molecular formula only.
The upper flammability limit of a gas is air is:
.. math::
C_mH_xO_y + zO_2 \to mCO_2 + \frac{x}{2}H_2O
\text{UFL} = \frac{3.5}{4.76m + 1.19x - 2.38y + 1}
Parameters
---... | [
"r",
"Calculates",
"upper",
"flammability",
"limit",
"using",
"the",
"Crowl",
"-",
"Louvar",
"[",
"1",
"]",
"_",
"correlation",
".",
"Uses",
"molecular",
"formula",
"only",
"."
] | python | valid | 26.058824 |
uw-it-aca/uw-restclients-graderoster | uw_sws_graderoster/__init__.py | https://github.com/uw-it-aca/uw-restclients-graderoster/blob/1e41553eb7363765af60e87223ca9d22cf6c9187/uw_sws_graderoster/__init__.py#L34-L56 | def update_graderoster(graderoster, requestor):
"""
Updates the graderoster resource for the passed restclients.GradeRoster
model. A new restclients.GradeRoster is returned, representing the
document returned from the update request.
"""
label = graderoster.graderoster_label()
url = "{}/{}".... | [
"def",
"update_graderoster",
"(",
"graderoster",
",",
"requestor",
")",
":",
"label",
"=",
"graderoster",
".",
"graderoster_label",
"(",
")",
"url",
"=",
"\"{}/{}\"",
".",
"format",
"(",
"graderoster_url",
",",
"encode_section_label",
"(",
"label",
")",
")",
"... | Updates the graderoster resource for the passed restclients.GradeRoster
model. A new restclients.GradeRoster is returned, representing the
document returned from the update request. | [
"Updates",
"the",
"graderoster",
"resource",
"for",
"the",
"passed",
"restclients",
".",
"GradeRoster",
"model",
".",
"A",
"new",
"restclients",
".",
"GradeRoster",
"is",
"returned",
"representing",
"the",
"document",
"returned",
"from",
"the",
"update",
"request"... | python | train | 43 |
google/budou | budou/nlapisegmenter.py | https://github.com/google/budou/blob/101224e6523186851f38ee57a6b2e7bdbd826de2/budou/nlapisegmenter.py#L203-L221 | def _group_chunks_by_entities(self, chunks, entities):
"""Groups chunks by entities retrieved from NL API Entity Analysis.
Args:
chunks (:obj:`budou.chunk.ChunkList`): List of chunks to be processed.
entities (:obj:`list` of :obj:`dict`): List of entities.
Returns:
A chunk list. (:obj:`b... | [
"def",
"_group_chunks_by_entities",
"(",
"self",
",",
"chunks",
",",
"entities",
")",
":",
"for",
"entity",
"in",
"entities",
":",
"chunks_to_concat",
"=",
"chunks",
".",
"get_overlaps",
"(",
"entity",
"[",
"'beginOffset'",
"]",
",",
"len",
"(",
"entity",
"[... | Groups chunks by entities retrieved from NL API Entity Analysis.
Args:
chunks (:obj:`budou.chunk.ChunkList`): List of chunks to be processed.
entities (:obj:`list` of :obj:`dict`): List of entities.
Returns:
A chunk list. (:obj:`budou.chunk.ChunkList`) | [
"Groups",
"chunks",
"by",
"entities",
"retrieved",
"from",
"NL",
"API",
"Entity",
"Analysis",
"."
] | python | train | 36.421053 |
bjmorgan/vasppy | vasppy/procar.py | https://github.com/bjmorgan/vasppy/blob/cc2d1449697b17ee1c43715a02cddcb1139a6834/vasppy/procar.py#L38-L56 | def points_are_in_a_straight_line( points, tolerance=1e-7 ):
"""
Check whether a set of points fall on a straight line.
Calculates the areas of triangles formed by triplets of the points.
Returns False is any of these areas are larger than the tolerance.
Args:
points (list(np.array)): list ... | [
"def",
"points_are_in_a_straight_line",
"(",
"points",
",",
"tolerance",
"=",
"1e-7",
")",
":",
"a",
"=",
"points",
"[",
"0",
"]",
"b",
"=",
"points",
"[",
"1",
"]",
"for",
"c",
"in",
"points",
"[",
"2",
":",
"]",
":",
"if",
"area_of_a_triangle_in_cart... | Check whether a set of points fall on a straight line.
Calculates the areas of triangles formed by triplets of the points.
Returns False is any of these areas are larger than the tolerance.
Args:
points (list(np.array)): list of Cartesian coordinates for each point.
tolerance (optional:floa... | [
"Check",
"whether",
"a",
"set",
"of",
"points",
"fall",
"on",
"a",
"straight",
"line",
".",
"Calculates",
"the",
"areas",
"of",
"triangles",
"formed",
"by",
"triplets",
"of",
"the",
"points",
".",
"Returns",
"False",
"is",
"any",
"of",
"these",
"areas",
... | python | train | 39.631579 |
shaypal5/strct | strct/dicts/_dict.py | https://github.com/shaypal5/strct/blob/f3a301692d052ddb79331230b3c00625db1d83fc/strct/dicts/_dict.py#L609-L643 | def sum_num_dicts(dicts, normalize=False):
"""Sums the given dicts into a single dict mapping each key to the sum
of its mappings in all given dicts.
Parameters
----------
dicts : list
A list of dict objects mapping each key to an numeric value.
normalize : bool, default False
I... | [
"def",
"sum_num_dicts",
"(",
"dicts",
",",
"normalize",
"=",
"False",
")",
":",
"sum_dict",
"=",
"{",
"}",
"for",
"dicti",
"in",
"dicts",
":",
"for",
"key",
"in",
"dicti",
":",
"sum_dict",
"[",
"key",
"]",
"=",
"sum_dict",
".",
"get",
"(",
"key",
"... | Sums the given dicts into a single dict mapping each key to the sum
of its mappings in all given dicts.
Parameters
----------
dicts : list
A list of dict objects mapping each key to an numeric value.
normalize : bool, default False
Indicated whether to normalize all values by value ... | [
"Sums",
"the",
"given",
"dicts",
"into",
"a",
"single",
"dict",
"mapping",
"each",
"key",
"to",
"the",
"sum",
"of",
"its",
"mappings",
"in",
"all",
"given",
"dicts",
"."
] | python | train | 29.628571 |
andreikop/qutepart | qutepart/indenter/scheme.py | https://github.com/andreikop/qutepart/blob/109d76b239751318bcef06f39b2fbbf18687a40b/qutepart/indenter/scheme.py#L25-L34 | def _lastWord(self, text):
"""Move backward to the start of the word at the end of a string.
Return the word
"""
for index, char in enumerate(text[::-1]):
if char.isspace() or \
char in ('(', ')'):
return text[len(text) - index :]
else:
... | [
"def",
"_lastWord",
"(",
"self",
",",
"text",
")",
":",
"for",
"index",
",",
"char",
"in",
"enumerate",
"(",
"text",
"[",
":",
":",
"-",
"1",
"]",
")",
":",
"if",
"char",
".",
"isspace",
"(",
")",
"or",
"char",
"in",
"(",
"'('",
",",
"')'",
"... | Move backward to the start of the word at the end of a string.
Return the word | [
"Move",
"backward",
"to",
"the",
"start",
"of",
"the",
"word",
"at",
"the",
"end",
"of",
"a",
"string",
".",
"Return",
"the",
"word"
] | python | train | 33.4 |
samgiles/slumber | slumber/utils.py | https://github.com/samgiles/slumber/blob/af0f9ef7bd8df8bde6b47088630786c737869bce/slumber/utils.py#L9-L16 | def url_join(base, *args):
"""
Helper function to join an arbitrary number of url segments together.
"""
scheme, netloc, path, query, fragment = urlsplit(base)
path = path if len(path) else "/"
path = posixpath.join(path, *[('%s' % x) for x in args])
return urlunsplit([scheme, netloc, path, ... | [
"def",
"url_join",
"(",
"base",
",",
"*",
"args",
")",
":",
"scheme",
",",
"netloc",
",",
"path",
",",
"query",
",",
"fragment",
"=",
"urlsplit",
"(",
"base",
")",
"path",
"=",
"path",
"if",
"len",
"(",
"path",
")",
"else",
"\"/\"",
"path",
"=",
... | Helper function to join an arbitrary number of url segments together. | [
"Helper",
"function",
"to",
"join",
"an",
"arbitrary",
"number",
"of",
"url",
"segments",
"together",
"."
] | python | train | 41.25 |
ligyxy/DictMySQL | dictmysql.py | https://github.com/ligyxy/DictMySQL/blob/f40d649193ccf58d1c7933189be1042b37afbe31/dictmysql.py#L355-L372 | def select_page(self, limit, offset=0, **kwargs):
"""
:type limit: int
:param limit: The max row number for each page
:type offset: int
:param offset: The starting position of the page
:return:
"""
start = offset
while True:
result = se... | [
"def",
"select_page",
"(",
"self",
",",
"limit",
",",
"offset",
"=",
"0",
",",
"*",
"*",
"kwargs",
")",
":",
"start",
"=",
"offset",
"while",
"True",
":",
"result",
"=",
"self",
".",
"select",
"(",
"limit",
"=",
"[",
"start",
",",
"limit",
"]",
"... | :type limit: int
:param limit: The max row number for each page
:type offset: int
:param offset: The starting position of the page
:return: | [
":",
"type",
"limit",
":",
"int",
":",
"param",
"limit",
":",
"The",
"max",
"row",
"number",
"for",
"each",
"page",
":",
"type",
"offset",
":",
"int",
":",
"param",
"offset",
":",
"The",
"starting",
"position",
"of",
"the",
"page",
":",
"return",
":"... | python | train | 28.444444 |
nephila/djangocms-apphook-setup | djangocms_apphook_setup/base.py | https://github.com/nephila/djangocms-apphook-setup/blob/e82c0afdf966f859fe13dc80fcd417b44080f460/djangocms_apphook_setup/base.py#L22-L57 | def _create_page(cls, page, lang, auto_title, cms_app=None, parent=None, namespace=None,
site=None, set_home=False):
"""
Create a single page or titles
:param page: Page instance
:param lang: language code
:param auto_title: title text for the newly created ... | [
"def",
"_create_page",
"(",
"cls",
",",
"page",
",",
"lang",
",",
"auto_title",
",",
"cms_app",
"=",
"None",
",",
"parent",
"=",
"None",
",",
"namespace",
"=",
"None",
",",
"site",
"=",
"None",
",",
"set_home",
"=",
"False",
")",
":",
"from",
"cms",
... | Create a single page or titles
:param page: Page instance
:param lang: language code
:param auto_title: title text for the newly created title
:param cms_app: Apphook Class to be attached to the page
:param parent: parent page (None when creating the home page)
:param na... | [
"Create",
"a",
"single",
"page",
"or",
"titles"
] | python | train | 39.833333 |
log2timeline/plaso | plaso/parsers/chrome_preferences.py | https://github.com/log2timeline/plaso/blob/9c564698d2da3ffbe23607a3c54c0582ea18a6cc/plaso/parsers/chrome_preferences.py#L156-L189 | def _ExtractContentSettingsExceptions(self, exceptions_dict, parser_mediator):
"""Extracts site specific events.
Args:
exceptions_dict (dict): Permission exceptions data from Preferences file.
parser_mediator (ParserMediator): mediates interactions between parsers
and other components, su... | [
"def",
"_ExtractContentSettingsExceptions",
"(",
"self",
",",
"exceptions_dict",
",",
"parser_mediator",
")",
":",
"for",
"permission",
"in",
"exceptions_dict",
":",
"if",
"permission",
"not",
"in",
"self",
".",
"_EXCEPTIONS_KEYS",
":",
"continue",
"exception_dict",
... | Extracts site specific events.
Args:
exceptions_dict (dict): Permission exceptions data from Preferences file.
parser_mediator (ParserMediator): mediates interactions between parsers
and other components, such as storage and dfvfs. | [
"Extracts",
"site",
"specific",
"events",
"."
] | python | train | 42.323529 |
rameshg87/pyremotevbox | pyremotevbox/ZSI/parse.py | https://github.com/rameshg87/pyremotevbox/blob/123dffff27da57c8faa3ac1dd4c68b1cf4558b1a/pyremotevbox/ZSI/parse.py#L328-L333 | def WhatMustIUnderstand(self):
'''Return a list of (uri,localname) tuples for all elements in the
header that have mustUnderstand set.
'''
return [ ( E.namespaceURI, E.localName )
for E in self.header_elements if _find_mu(E) == "1" ] | [
"def",
"WhatMustIUnderstand",
"(",
"self",
")",
":",
"return",
"[",
"(",
"E",
".",
"namespaceURI",
",",
"E",
".",
"localName",
")",
"for",
"E",
"in",
"self",
".",
"header_elements",
"if",
"_find_mu",
"(",
"E",
")",
"==",
"\"1\"",
"]"
] | Return a list of (uri,localname) tuples for all elements in the
header that have mustUnderstand set. | [
"Return",
"a",
"list",
"of",
"(",
"uri",
"localname",
")",
"tuples",
"for",
"all",
"elements",
"in",
"the",
"header",
"that",
"have",
"mustUnderstand",
"set",
"."
] | python | train | 46 |
pytroll/trollsift | trollsift/parser.py | https://github.com/pytroll/trollsift/blob/d0e5b6006e248974d806d0dd8e20cc6641d778fb/trollsift/parser.py#L354-L362 | def get_convert_dict(fmt):
"""Retrieve parse definition from the format string `fmt`."""
convdef = {}
for literal_text, field_name, format_spec, conversion in formatter.parse(fmt):
if field_name is None:
continue
# XXX: Do I need to include 'conversion'?
convdef[field_nam... | [
"def",
"get_convert_dict",
"(",
"fmt",
")",
":",
"convdef",
"=",
"{",
"}",
"for",
"literal_text",
",",
"field_name",
",",
"format_spec",
",",
"conversion",
"in",
"formatter",
".",
"parse",
"(",
"fmt",
")",
":",
"if",
"field_name",
"is",
"None",
":",
"con... | Retrieve parse definition from the format string `fmt`. | [
"Retrieve",
"parse",
"definition",
"from",
"the",
"format",
"string",
"fmt",
"."
] | python | train | 38.555556 |
ChristianTremblay/BAC0 | BAC0/core/devices/Points.py | https://github.com/ChristianTremblay/BAC0/blob/8d95b065ea068524a08f5b0c34322ebeeba95d06/BAC0/core/devices/Points.py#L902-L912 | def value(self):
"""
Take last known value as the value
"""
try:
value = self.lastValue
except IndexError:
value = "NaN"
except ValueError:
value = "NaN"
return value | [
"def",
"value",
"(",
"self",
")",
":",
"try",
":",
"value",
"=",
"self",
".",
"lastValue",
"except",
"IndexError",
":",
"value",
"=",
"\"NaN\"",
"except",
"ValueError",
":",
"value",
"=",
"\"NaN\"",
"return",
"value"
] | Take last known value as the value | [
"Take",
"last",
"known",
"value",
"as",
"the",
"value"
] | python | train | 22.545455 |
linkedin/luminol | src/luminol/correlator.py | https://github.com/linkedin/luminol/blob/42e4ab969b774ff98f902d064cb041556017f635/src/luminol/correlator.py#L113-L118 | def is_correlated(self, threshold=0):
"""
Compare with a threshold to determine whether two timeseries correlate to each other.
:return: a CorrelationResult object if two time series correlate otherwise false.
"""
return self.correlation_result if self.correlation_result.coeffici... | [
"def",
"is_correlated",
"(",
"self",
",",
"threshold",
"=",
"0",
")",
":",
"return",
"self",
".",
"correlation_result",
"if",
"self",
".",
"correlation_result",
".",
"coefficient",
">=",
"threshold",
"else",
"False"
] | Compare with a threshold to determine whether two timeseries correlate to each other.
:return: a CorrelationResult object if two time series correlate otherwise false. | [
"Compare",
"with",
"a",
"threshold",
"to",
"determine",
"whether",
"two",
"timeseries",
"correlate",
"to",
"each",
"other",
".",
":",
"return",
":",
"a",
"CorrelationResult",
"object",
"if",
"two",
"time",
"series",
"correlate",
"otherwise",
"false",
"."
] | python | train | 57 |
google/openhtf | openhtf/util/console_output.py | https://github.com/google/openhtf/blob/655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09/openhtf/util/console_output.py#L78-L109 | def banner_print(msg, color='', width=60, file=sys.stdout, logger=_LOG):
"""Print the message as a banner with a fixed width.
Also logs the message (un-bannered) to the given logger at the debug level.
Args:
msg: The message to print.
color: Optional colorama color string to be applied to the message. Y... | [
"def",
"banner_print",
"(",
"msg",
",",
"color",
"=",
"''",
",",
"width",
"=",
"60",
",",
"file",
"=",
"sys",
".",
"stdout",
",",
"logger",
"=",
"_LOG",
")",
":",
"if",
"logger",
":",
"logger",
".",
"debug",
"(",
"ANSI_ESC_RE",
".",
"sub",
"(",
"... | Print the message as a banner with a fixed width.
Also logs the message (un-bannered) to the given logger at the debug level.
Args:
msg: The message to print.
color: Optional colorama color string to be applied to the message. You can
concatenate colorama color strings together in order to get any... | [
"Print",
"the",
"message",
"as",
"a",
"banner",
"with",
"a",
"fixed",
"width",
"."
] | python | train | 37.25 |
wright-group/WrightTools | WrightTools/data/_data.py | https://github.com/wright-group/WrightTools/blob/80d3ddd5074d8d5c1bc03fd5a0e0f10d4b424aeb/WrightTools/data/_data.py#L211-L229 | def _on_axes_updated(self):
"""Method to run when axes are changed in any way.
Propagates updated axes properly.
"""
# update attrs
self.attrs["axes"] = [a.identity.encode() for a in self._axes]
# remove old attributes
while len(self._current_axis_identities_in_n... | [
"def",
"_on_axes_updated",
"(",
"self",
")",
":",
"# update attrs",
"self",
".",
"attrs",
"[",
"\"axes\"",
"]",
"=",
"[",
"a",
".",
"identity",
".",
"encode",
"(",
")",
"for",
"a",
"in",
"self",
".",
"_axes",
"]",
"# remove old attributes",
"while",
"len... | Method to run when axes are changed in any way.
Propagates updated axes properly. | [
"Method",
"to",
"run",
"when",
"axes",
"are",
"changed",
"in",
"any",
"way",
"."
] | python | train | 38.368421 |
ToucanToco/toucan-data-sdk | toucan_data_sdk/utils/decorators.py | https://github.com/ToucanToco/toucan-data-sdk/blob/c3ca874e1b64f4bdcc2edda750a72d45d1561d8a/toucan_data_sdk/utils/decorators.py#L185-L213 | def domain(domain_name):
"""
Allow to apply a function f(df: DataFrame) -> DataFrame) on dfs by specifying the key
E.g instead of writing:
def process_domain1(dfs):
df = dfs['domain1']
# actual process
dfs['domain1'] = df
return dfs
You can write:... | [
"def",
"domain",
"(",
"domain_name",
")",
":",
"def",
"decorator",
"(",
"func",
")",
":",
"@",
"wraps",
"(",
"func",
")",
"def",
"wrapper",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"dfs",
",",
"",
"*",
"args",
"=",
"args",
"if",
"no... | Allow to apply a function f(df: DataFrame) -> DataFrame) on dfs by specifying the key
E.g instead of writing:
def process_domain1(dfs):
df = dfs['domain1']
# actual process
dfs['domain1'] = df
return dfs
You can write:
@domain('domain1')
d... | [
"Allow",
"to",
"apply",
"a",
"function",
"f",
"(",
"df",
":",
"DataFrame",
")",
"-",
">",
"DataFrame",
")",
"on",
"dfs",
"by",
"specifying",
"the",
"key",
"E",
".",
"g",
"instead",
"of",
"writing",
":",
"def",
"process_domain1",
"(",
"dfs",
")",
":",... | python | test | 27.344828 |
bapakode/OmMongo | ommongo/fields/fields.py | https://github.com/bapakode/OmMongo/blob/52b5a5420516dc709f2d2eb065818c7973991ce3/ommongo/fields/fields.py#L366-L375 | def unwrap(self, value, session=None):
''' Unwrap value using the unwrap function from ``EnumField.item_type``.
Since unwrap validation could not happen in is_valid_wrap, it
happens in this function.'''
self.validate_unwrap(value)
value = self.item_type.unwrap(value, sess... | [
"def",
"unwrap",
"(",
"self",
",",
"value",
",",
"session",
"=",
"None",
")",
":",
"self",
".",
"validate_unwrap",
"(",
"value",
")",
"value",
"=",
"self",
".",
"item_type",
".",
"unwrap",
"(",
"value",
",",
"session",
"=",
"session",
")",
"for",
"va... | Unwrap value using the unwrap function from ``EnumField.item_type``.
Since unwrap validation could not happen in is_valid_wrap, it
happens in this function. | [
"Unwrap",
"value",
"using",
"the",
"unwrap",
"function",
"from",
"EnumField",
".",
"item_type",
".",
"Since",
"unwrap",
"validation",
"could",
"not",
"happen",
"in",
"is_valid_wrap",
"it",
"happens",
"in",
"this",
"function",
"."
] | python | train | 48.4 |
bakwc/PySyncObj | pysyncobj/batteries.py | https://github.com/bakwc/PySyncObj/blob/be3b0aaa932d5156f5df140c23c962430f51b7b8/pysyncobj/batteries.py#L496-L509 | def tryAcquire(self, lockID, callback=None, sync=False, timeout=None):
"""Attempt to acquire lock.
:param lockID: unique lock identifier.
:type lockID: str
:param sync: True - to wait until lock is acquired or failed to acquire.
:type sync: bool
:param callback: if sync ... | [
"def",
"tryAcquire",
"(",
"self",
",",
"lockID",
",",
"callback",
"=",
"None",
",",
"sync",
"=",
"False",
",",
"timeout",
"=",
"None",
")",
":",
"return",
"self",
".",
"__lockImpl",
".",
"acquire",
"(",
"lockID",
",",
"self",
".",
"__selfID",
",",
"t... | Attempt to acquire lock.
:param lockID: unique lock identifier.
:type lockID: str
:param sync: True - to wait until lock is acquired or failed to acquire.
:type sync: bool
:param callback: if sync is False - callback will be called with operation result.
:type callback: ... | [
"Attempt",
"to",
"acquire",
"lock",
"."
] | python | test | 51.142857 |
ska-sa/montblanc | montblanc/util/parsing.py | https://github.com/ska-sa/montblanc/blob/8a2e742e7500bcc6196489b735f87b233075dd2d/montblanc/util/parsing.py#L12-L122 | def parse_python_assigns(assign_str):
"""
Parses a string, containing assign statements
into a dictionary.
.. code-block:: python
h5 = katdal.open('123456789.h5')
kwargs = parse_python_assigns("spw=3; scans=[1,2];"
"targets='bpcal,radec';"
... | [
"def",
"parse_python_assigns",
"(",
"assign_str",
")",
":",
"if",
"not",
"assign_str",
":",
"return",
"{",
"}",
"def",
"_eval_value",
"(",
"stmt_value",
")",
":",
"# If the statement value is a call to a builtin, try evaluate it",
"if",
"isinstance",
"(",
"stmt_value",
... | Parses a string, containing assign statements
into a dictionary.
.. code-block:: python
h5 = katdal.open('123456789.h5')
kwargs = parse_python_assigns("spw=3; scans=[1,2];"
"targets='bpcal,radec';"
"channels=slice(0,20... | [
"Parses",
"a",
"string",
"containing",
"assign",
"statements",
"into",
"a",
"dictionary",
"."
] | python | train | 36.504505 |
jaijuneja/PyTLDR | pytldr/nlp/tokenizer.py | https://github.com/jaijuneja/PyTLDR/blob/4ba2ab88dbbb1318a86bf4483264ab213e166b6b/pytldr/nlp/tokenizer.py#L61-L66 | def stem(self, word):
"""Perform stemming on an input word."""
if self.stemmer:
return unicode_to_ascii(self._stemmer.stem(word))
else:
return word | [
"def",
"stem",
"(",
"self",
",",
"word",
")",
":",
"if",
"self",
".",
"stemmer",
":",
"return",
"unicode_to_ascii",
"(",
"self",
".",
"_stemmer",
".",
"stem",
"(",
"word",
")",
")",
"else",
":",
"return",
"word"
] | Perform stemming on an input word. | [
"Perform",
"stemming",
"on",
"an",
"input",
"word",
"."
] | python | train | 31.666667 |
kislyuk/aegea | aegea/packages/github3/users.py | https://github.com/kislyuk/aegea/blob/94957e9dba036eae3052e2662c208b259c08399a/aegea/packages/github3/users.py#L395-L418 | def update(self, name=None, email=None, blog=None, company=None,
location=None, hireable=False, bio=None):
"""If authenticated as this user, update the information with
the information provided in the parameters.
:param str name: e.g., 'John Smith', not login name
:param ... | [
"def",
"update",
"(",
"self",
",",
"name",
"=",
"None",
",",
"email",
"=",
"None",
",",
"blog",
"=",
"None",
",",
"company",
"=",
"None",
",",
"location",
"=",
"None",
",",
"hireable",
"=",
"False",
",",
"bio",
"=",
"None",
")",
":",
"user",
"=",... | If authenticated as this user, update the information with
the information provided in the parameters.
:param str name: e.g., 'John Smith', not login name
:param str email: e.g., 'john.smith@example.com'
:param str blog: e.g., 'http://www.example.com/jsmith/blog'
:param str comp... | [
"If",
"authenticated",
"as",
"this",
"user",
"update",
"the",
"information",
"with",
"the",
"information",
"provided",
"in",
"the",
"parameters",
"."
] | python | train | 41.416667 |
QUANTAXIS/QUANTAXIS | QUANTAXIS/QAIndicator/hurst.py | https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QAIndicator/hurst.py#L55-L65 | def deviation(self, series, start, limit, mean):
'''
:type start: int
:type limit: int
:type mean: int
:rtype: list()
'''
d = []
for x in range(start, limit):
d.append(float(series[x] - mean))
return d | [
"def",
"deviation",
"(",
"self",
",",
"series",
",",
"start",
",",
"limit",
",",
"mean",
")",
":",
"d",
"=",
"[",
"]",
"for",
"x",
"in",
"range",
"(",
"start",
",",
"limit",
")",
":",
"d",
".",
"append",
"(",
"float",
"(",
"series",
"[",
"x",
... | :type start: int
:type limit: int
:type mean: int
:rtype: list() | [
":",
"type",
"start",
":",
"int",
":",
"type",
"limit",
":",
"int",
":",
"type",
"mean",
":",
"int",
":",
"rtype",
":",
"list",
"()"
] | python | train | 25 |
theonion/django-bulbs | bulbs/content/models.py | https://github.com/theonion/django-bulbs/blob/0c0e6e3127a7dc487b96677fab95cacd2b3806da/bulbs/content/models.py#L278-L291 | def first_image(self):
"""Ready-only attribute that provides the value of the first non-none image that's
not the thumbnail override field.
"""
# loop through image fields and grab the first non-none one
for model_field in self._meta.fields:
if isinstance(model_field,... | [
"def",
"first_image",
"(",
"self",
")",
":",
"# loop through image fields and grab the first non-none one",
"for",
"model_field",
"in",
"self",
".",
"_meta",
".",
"fields",
":",
"if",
"isinstance",
"(",
"model_field",
",",
"ImageField",
")",
":",
"if",
"model_field"... | Ready-only attribute that provides the value of the first non-none image that's
not the thumbnail override field. | [
"Ready",
"-",
"only",
"attribute",
"that",
"provides",
"the",
"value",
"of",
"the",
"first",
"non",
"-",
"none",
"image",
"that",
"s",
"not",
"the",
"thumbnail",
"override",
"field",
"."
] | python | train | 43.428571 |
sixty-north/cosmic-ray | src/cosmic_ray/work_db.py | https://github.com/sixty-north/cosmic-ray/blob/c654e074afbb7b7fcbc23359083c1287c0d3e991/src/cosmic_ray/work_db.py#L128-L133 | def results(self):
"An iterable of all `(job-id, WorkResult)`s."
cur = self._conn.cursor()
rows = cur.execute("SELECT * FROM results")
for row in rows:
yield (row['job_id'], _row_to_work_result(row)) | [
"def",
"results",
"(",
"self",
")",
":",
"cur",
"=",
"self",
".",
"_conn",
".",
"cursor",
"(",
")",
"rows",
"=",
"cur",
".",
"execute",
"(",
"\"SELECT * FROM results\"",
")",
"for",
"row",
"in",
"rows",
":",
"yield",
"(",
"row",
"[",
"'job_id'",
"]",... | An iterable of all `(job-id, WorkResult)`s. | [
"An",
"iterable",
"of",
"all",
"(",
"job",
"-",
"id",
"WorkResult",
")",
"s",
"."
] | python | train | 39.666667 |
jmgilman/Neolib | neolib/pyamf/remoting/gateway/twisted.py | https://github.com/jmgilman/Neolib/blob/228fafeaed0f3195676137732384a14820ae285c/neolib/pyamf/remoting/gateway/twisted.py#L238-L281 | def render_POST(self, request):
"""
Read remoting request from the client.
@type request: The HTTP Request.
@param request: C{twisted.web.http.Request}
"""
def handleDecodeError(failure):
"""
Return HTTP 400 Bad Request.
"""
... | [
"def",
"render_POST",
"(",
"self",
",",
"request",
")",
":",
"def",
"handleDecodeError",
"(",
"failure",
")",
":",
"\"\"\"\n Return HTTP 400 Bad Request.\n \"\"\"",
"errMesg",
"=",
"\"%s: %s\"",
"%",
"(",
"failure",
".",
"type",
",",
"failure",
... | Read remoting request from the client.
@type request: The HTTP Request.
@param request: C{twisted.web.http.Request} | [
"Read",
"remoting",
"request",
"from",
"the",
"client",
"."
] | python | train | 31.045455 |
saltstack/salt | salt/minion.py | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/minion.py#L2681-L2698 | def _fallback_cleanups(self):
'''
Fallback cleanup routines, attempting to fix leaked processes, threads, etc.
'''
# Add an extra fallback in case a forked process leaks through
multiprocessing.active_children()
# Cleanup Windows threads
if not salt.utils.platfor... | [
"def",
"_fallback_cleanups",
"(",
"self",
")",
":",
"# Add an extra fallback in case a forked process leaks through",
"multiprocessing",
".",
"active_children",
"(",
")",
"# Cleanup Windows threads",
"if",
"not",
"salt",
".",
"utils",
".",
"platform",
".",
"is_windows",
"... | Fallback cleanup routines, attempting to fix leaked processes, threads, etc. | [
"Fallback",
"cleanup",
"routines",
"attempting",
"to",
"fix",
"leaked",
"processes",
"threads",
"etc",
"."
] | python | train | 34.222222 |
saulpw/visidata | visidata/vdtui.py | https://github.com/saulpw/visidata/blob/32771e0cea6c24fc7902683d14558391395c591f/visidata/vdtui.py#L1537-L1543 | def unselect(self, rows, status=True, progress=True):
"Unselect given rows. Don't show progress if progress=False; don't show status if status=False."
before = len(self._selectedRows)
for r in (Progress(rows, 'unselecting') if progress else rows):
self.unselectRow(r)
if statu... | [
"def",
"unselect",
"(",
"self",
",",
"rows",
",",
"status",
"=",
"True",
",",
"progress",
"=",
"True",
")",
":",
"before",
"=",
"len",
"(",
"self",
".",
"_selectedRows",
")",
"for",
"r",
"in",
"(",
"Progress",
"(",
"rows",
",",
"'unselecting'",
")",
... | Unselect given rows. Don't show progress if progress=False; don't show status if status=False. | [
"Unselect",
"given",
"rows",
".",
"Don",
"t",
"show",
"progress",
"if",
"progress",
"=",
"False",
";",
"don",
"t",
"show",
"status",
"if",
"status",
"=",
"False",
"."
] | python | train | 60 |
seomoz/qless-py | qless/workers/forking.py | https://github.com/seomoz/qless-py/blob/3eda4ffcd4c0016c9a7e44f780d6155e1a354dda/qless/workers/forking.py#L112-L116 | def handler(self, signum, frame): # pragma: no cover
'''Signal handler for this process'''
if signum in (signal.SIGTERM, signal.SIGINT, signal.SIGQUIT):
self.stop(signum)
os._exit(0) | [
"def",
"handler",
"(",
"self",
",",
"signum",
",",
"frame",
")",
":",
"# pragma: no cover",
"if",
"signum",
"in",
"(",
"signal",
".",
"SIGTERM",
",",
"signal",
".",
"SIGINT",
",",
"signal",
".",
"SIGQUIT",
")",
":",
"self",
".",
"stop",
"(",
"signum",
... | Signal handler for this process | [
"Signal",
"handler",
"for",
"this",
"process"
] | python | train | 43.8 |
rigetti/pyquil | pyquil/gate_matrices.py | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/gate_matrices.py#L225-L231 | def relaxation_operators(p):
"""
Return the amplitude damping Kraus operators
"""
k0 = np.array([[1.0, 0.0], [0.0, np.sqrt(1 - p)]])
k1 = np.array([[0.0, np.sqrt(p)], [0.0, 0.0]])
return k0, k1 | [
"def",
"relaxation_operators",
"(",
"p",
")",
":",
"k0",
"=",
"np",
".",
"array",
"(",
"[",
"[",
"1.0",
",",
"0.0",
"]",
",",
"[",
"0.0",
",",
"np",
".",
"sqrt",
"(",
"1",
"-",
"p",
")",
"]",
"]",
")",
"k1",
"=",
"np",
".",
"array",
"(",
... | Return the amplitude damping Kraus operators | [
"Return",
"the",
"amplitude",
"damping",
"Kraus",
"operators"
] | python | train | 30.142857 |
nicolargo/glances | glances/outputs/glances_curses.py | https://github.com/nicolargo/glances/blob/5bd4d587a736e0d2b03170b56926841d2a3eb7ee/glances/outputs/glances_curses.py#L769-L845 | def display_popup(self, message,
size_x=None, size_y=None,
duration=3,
is_input=False,
input_size=30,
input_value=None):
"""
Display a centered popup.
If is_input is False:
Dis... | [
"def",
"display_popup",
"(",
"self",
",",
"message",
",",
"size_x",
"=",
"None",
",",
"size_y",
"=",
"None",
",",
"duration",
"=",
"3",
",",
"is_input",
"=",
"False",
",",
"input_size",
"=",
"30",
",",
"input_value",
"=",
"None",
")",
":",
"# Center th... | Display a centered popup.
If is_input is False:
Display a centered popup with the given message during duration seconds
If size_x and size_y: set the popup size
else set it automatically
Return True if the popup could be displayed
If is_input is True:
Displ... | [
"Display",
"a",
"centered",
"popup",
"."
] | python | train | 36.350649 |
SuperCowPowers/workbench | workbench/workers/pcap_http_graph.py | https://github.com/SuperCowPowers/workbench/blob/710232756dd717f734253315e3d0b33c9628dafb/workbench/workers/pcap_http_graph.py#L68-L86 | def http_log_graph(self, stream):
''' Build up a graph (nodes and edges from a Bro http.log) '''
print 'Entering http_log_graph...'
for row in list(stream):
# Skip '-' hosts
if (row['id.orig_h'] == '-'):
continue
# Add the originating host
... | [
"def",
"http_log_graph",
"(",
"self",
",",
"stream",
")",
":",
"print",
"'Entering http_log_graph...'",
"for",
"row",
"in",
"list",
"(",
"stream",
")",
":",
"# Skip '-' hosts",
"if",
"(",
"row",
"[",
"'id.orig_h'",
"]",
"==",
"'-'",
")",
":",
"continue",
"... | Build up a graph (nodes and edges from a Bro http.log) | [
"Build",
"up",
"a",
"graph",
"(",
"nodes",
"and",
"edges",
"from",
"a",
"Bro",
"http",
".",
"log",
")"
] | python | train | 39.473684 |
Metatab/metapack | metapack/index.py | https://github.com/Metatab/metapack/blob/8365f221fbeaa3c0be9091f2eaf3447fd8e2e8d6/metapack/index.py#L140-L148 | def update(self,o):
"""Update from another index or index dict"""
self.open()
try:
self._db.update(o._db)
except AttributeError:
self._db.update(o) | [
"def",
"update",
"(",
"self",
",",
"o",
")",
":",
"self",
".",
"open",
"(",
")",
"try",
":",
"self",
".",
"_db",
".",
"update",
"(",
"o",
".",
"_db",
")",
"except",
"AttributeError",
":",
"self",
".",
"_db",
".",
"update",
"(",
"o",
")"
] | Update from another index or index dict | [
"Update",
"from",
"another",
"index",
"or",
"index",
"dict"
] | python | train | 21.888889 |
santoshphilip/eppy | eppy/EPlusInterfaceFunctions/mylib2.py | https://github.com/santoshphilip/eppy/blob/55410ff7c11722f35bc4331ff5e00a0b86f787e1/eppy/EPlusInterfaceFunctions/mylib2.py#L307-L310 | def fsliceafter(astr, sub):
"""Return the slice after at sub in string astr"""
findex = astr.find(sub)
return astr[findex + len(sub):] | [
"def",
"fsliceafter",
"(",
"astr",
",",
"sub",
")",
":",
"findex",
"=",
"astr",
".",
"find",
"(",
"sub",
")",
"return",
"astr",
"[",
"findex",
"+",
"len",
"(",
"sub",
")",
":",
"]"
] | Return the slice after at sub in string astr | [
"Return",
"the",
"slice",
"after",
"at",
"sub",
"in",
"string",
"astr"
] | python | train | 35.75 |
a1ezzz/wasp-general | wasp_general/task/dependency.py | https://github.com/a1ezzz/wasp-general/blob/1029839d33eb663f8dec76c1c46754d53c1de4a9/wasp_general/task/dependency.py#L122-L151 | def dependency_check(self, task_cls, skip_unresolved=False):
""" Check dependency of task for irresolvable conflicts (like task to task mutual dependency)
:param task_cls: task to check
:param skip_unresolved: flag controls this method behaviour for tasks that could not be found. \
When False, method will rais... | [
"def",
"dependency_check",
"(",
"self",
",",
"task_cls",
",",
"skip_unresolved",
"=",
"False",
")",
":",
"def",
"check",
"(",
"check_task_cls",
",",
"global_dependencies",
")",
":",
"if",
"check_task_cls",
".",
"__registry_tag__",
"in",
"global_dependencies",
":",... | Check dependency of task for irresolvable conflicts (like task to task mutual dependency)
:param task_cls: task to check
:param skip_unresolved: flag controls this method behaviour for tasks that could not be found. \
When False, method will raise an exception if task tag was set in dependency and the related ta... | [
"Check",
"dependency",
"of",
"task",
"for",
"irresolvable",
"conflicts",
"(",
"like",
"task",
"to",
"task",
"mutual",
"dependency",
")"
] | python | train | 38.333333 |
Phyks/libbmc | libbmc/tools.py | https://github.com/Phyks/libbmc/blob/9ef1a29d2514157d1edd6c13ecbd61b07ae9315e/libbmc/tools.py#L39-L54 | def map_or_apply(function, param):
"""
Map the function on ``param``, or apply it, depending whether ``param`` \
is a list or an item.
:param function: The function to apply.
:param param: The parameter to feed the function with (list or item).
:returns: The computed value or ``None``.
... | [
"def",
"map_or_apply",
"(",
"function",
",",
"param",
")",
":",
"try",
":",
"if",
"isinstance",
"(",
"param",
",",
"list",
")",
":",
"return",
"[",
"next",
"(",
"iter",
"(",
"function",
"(",
"i",
")",
")",
")",
"for",
"i",
"in",
"param",
"]",
"el... | Map the function on ``param``, or apply it, depending whether ``param`` \
is a list or an item.
:param function: The function to apply.
:param param: The parameter to feed the function with (list or item).
:returns: The computed value or ``None``. | [
"Map",
"the",
"function",
"on",
"param",
"or",
"apply",
"it",
"depending",
"whether",
"param",
"\\",
"is",
"a",
"list",
"or",
"an",
"item",
"."
] | python | train | 32.75 |
Azure/azure-sdk-for-python | azure-mgmt-storage/azure/mgmt/storage/storage_management_client.py | https://github.com/Azure/azure-sdk-for-python/blob/d7306fde32f60a293a7567678692bdad31e4b667/azure-mgmt-storage/azure/mgmt/storage/storage_management_client.py#L108-L144 | def models(cls, api_version=DEFAULT_API_VERSION):
"""Module depends on the API version:
* 2015-06-15: :mod:`v2015_06_15.models<azure.mgmt.storage.v2015_06_15.models>`
* 2016-01-01: :mod:`v2016_01_01.models<azure.mgmt.storage.v2016_01_01.models>`
* 2016-12-01: :mod:`v2016_12_01.... | [
"def",
"models",
"(",
"cls",
",",
"api_version",
"=",
"DEFAULT_API_VERSION",
")",
":",
"if",
"api_version",
"==",
"'2015-06-15'",
":",
"from",
".",
"v2015_06_15",
"import",
"models",
"return",
"models",
"elif",
"api_version",
"==",
"'2016-01-01'",
":",
"from",
... | Module depends on the API version:
* 2015-06-15: :mod:`v2015_06_15.models<azure.mgmt.storage.v2015_06_15.models>`
* 2016-01-01: :mod:`v2016_01_01.models<azure.mgmt.storage.v2016_01_01.models>`
* 2016-12-01: :mod:`v2016_12_01.models<azure.mgmt.storage.v2016_12_01.models>`
* 2... | [
"Module",
"depends",
"on",
"the",
"API",
"version",
":"
] | python | test | 49.027027 |
GetmeUK/MongoFrames | mongoframes/frames.py | https://github.com/GetmeUK/MongoFrames/blob/7d2bd792235dfa77a9deecab5366f5f73480823d/mongoframes/frames.py#L305-L328 | def insert_many(cls, documents):
"""Insert a list of documents"""
from mongoframes.queries import to_refs
# Ensure all documents have been converted to frames
frames = cls._ensure_frames(documents)
# Send insert signal
signal('insert').send(cls, frames=frames)
... | [
"def",
"insert_many",
"(",
"cls",
",",
"documents",
")",
":",
"from",
"mongoframes",
".",
"queries",
"import",
"to_refs",
"# Ensure all documents have been converted to frames",
"frames",
"=",
"cls",
".",
"_ensure_frames",
"(",
"documents",
")",
"# Send insert signal",
... | Insert a list of documents | [
"Insert",
"a",
"list",
"of",
"documents"
] | python | train | 29.25 |
Clinical-Genomics/scout | scout/commands/load/variants.py | https://github.com/Clinical-Genomics/scout/blob/90a551e2e1653a319e654c2405c2866f93d0ebb9/scout/commands/load/variants.py#L27-L104 | def variants(context, case_id, institute, force, cancer, cancer_research, sv,
sv_research, snv, snv_research, str_clinical, chrom, start, end, hgnc_id,
hgnc_symbol, rank_treshold):
"""Upload variants to a case
Note that the files has to be linked with the case,
if they ... | [
"def",
"variants",
"(",
"context",
",",
"case_id",
",",
"institute",
",",
"force",
",",
"cancer",
",",
"cancer_research",
",",
"sv",
",",
"sv_research",
",",
"snv",
",",
"snv_research",
",",
"str_clinical",
",",
"chrom",
",",
"start",
",",
"end",
",",
"h... | Upload variants to a case
Note that the files has to be linked with the case,
if they are not use 'scout update case'. | [
"Upload",
"variants",
"to",
"a",
"case"
] | python | test | 38.487179 |
gears/gears | gears/environment.py | https://github.com/gears/gears/blob/5729c2525a8c04c185e998bd9a86233708972921/gears/environment.py#L99-L102 | def register(self, mimetype, processor):
"""Register passed `processor` for passed `mimetype`."""
if mimetype not in self or processor not in self[mimetype]:
self.setdefault(mimetype, []).append(processor) | [
"def",
"register",
"(",
"self",
",",
"mimetype",
",",
"processor",
")",
":",
"if",
"mimetype",
"not",
"in",
"self",
"or",
"processor",
"not",
"in",
"self",
"[",
"mimetype",
"]",
":",
"self",
".",
"setdefault",
"(",
"mimetype",
",",
"[",
"]",
")",
"."... | Register passed `processor` for passed `mimetype`. | [
"Register",
"passed",
"processor",
"for",
"passed",
"mimetype",
"."
] | python | test | 57.5 |
TheHive-Project/Cortex-Analyzers | analyzers/MaxMind/ipaddr.py | https://github.com/TheHive-Project/Cortex-Analyzers/blob/8dae6a8c4cf9af5554ae8c844985c4b44d4bd4bf/analyzers/MaxMind/ipaddr.py#L1462-L1483 | def _parse_hextet(self, hextet_str):
"""Convert an IPv6 hextet string into an integer.
Args:
hextet_str: A string, the number to parse.
Returns:
The hextet as an integer.
Raises:
ValueError: if the input isn't strictly a hex number from [0..FFFF].
... | [
"def",
"_parse_hextet",
"(",
"self",
",",
"hextet_str",
")",
":",
"# Whitelist the characters, since int() allows a lot of bizarre stuff.",
"if",
"not",
"self",
".",
"_HEX_DIGITS",
".",
"issuperset",
"(",
"hextet_str",
")",
":",
"raise",
"ValueError",
"if",
"len",
"("... | Convert an IPv6 hextet string into an integer.
Args:
hextet_str: A string, the number to parse.
Returns:
The hextet as an integer.
Raises:
ValueError: if the input isn't strictly a hex number from [0..FFFF]. | [
"Convert",
"an",
"IPv6",
"hextet",
"string",
"into",
"an",
"integer",
"."
] | python | train | 30.045455 |
tjcsl/cslbot | cslbot/commands/help.py | https://github.com/tjcsl/cslbot/blob/aebe07be47141f61d7c180706bddfb707f19b2b5/cslbot/commands/help.py#L23-L48 | def cmd(send, msg, args):
"""Gives help.
Syntax: {command} [command]
"""
cmdchar = args['config']['core']['cmdchar']
if msg:
if msg.startswith(cmdchar):
msg = msg[len(cmdchar):]
if len(msg.split()) > 1:
send("One argument only")
elif not command_regi... | [
"def",
"cmd",
"(",
"send",
",",
"msg",
",",
"args",
")",
":",
"cmdchar",
"=",
"args",
"[",
"'config'",
"]",
"[",
"'core'",
"]",
"[",
"'cmdchar'",
"]",
"if",
"msg",
":",
"if",
"msg",
".",
"startswith",
"(",
"cmdchar",
")",
":",
"msg",
"=",
"msg",
... | Gives help.
Syntax: {command} [command] | [
"Gives",
"help",
"."
] | python | train | 37 |
bukun/TorCMS | torcms/model/evaluation_model.py | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/evaluation_model.py#L38-L54 | def add_or_update(user_id, app_id, value):
'''
Editing evaluation.
'''
rec = MEvaluation.get_by_signature(user_id, app_id)
if rec:
entry = TabEvaluation.update(
value=value,
).where(TabEvaluation.uid == rec.uid)
entry.execute()
... | [
"def",
"add_or_update",
"(",
"user_id",
",",
"app_id",
",",
"value",
")",
":",
"rec",
"=",
"MEvaluation",
".",
"get_by_signature",
"(",
"user_id",
",",
"app_id",
")",
"if",
"rec",
":",
"entry",
"=",
"TabEvaluation",
".",
"update",
"(",
"value",
"=",
"val... | Editing evaluation. | [
"Editing",
"evaluation",
"."
] | python | train | 29.235294 |
capitalone/giraffez | giraffez/export.py | https://github.com/capitalone/giraffez/blob/6b4d27eb1a1eaf188c6885c7364ef27e92b1b957/giraffez/export.py#L204-L219 | def to_str(self, delimiter='|', null='NULL'):
"""
Sets the current encoder output to Python `str` and returns
a row iterator.
:param str null: The string representation of null values
:param str delimiter: The string delimiting values in the output
string
:r... | [
"def",
"to_str",
"(",
"self",
",",
"delimiter",
"=",
"'|'",
",",
"null",
"=",
"'NULL'",
")",
":",
"self",
".",
"export",
".",
"set_null",
"(",
"null",
")",
"self",
".",
"export",
".",
"set_delimiter",
"(",
"delimiter",
")",
"self",
".",
"options",
"(... | Sets the current encoder output to Python `str` and returns
a row iterator.
:param str null: The string representation of null values
:param str delimiter: The string delimiting values in the output
string
:rtype: iterator (yields ``str``) | [
"Sets",
"the",
"current",
"encoder",
"output",
"to",
"Python",
"str",
"and",
"returns",
"a",
"row",
"iterator",
"."
] | python | test | 37.8125 |
paperhive/ansible-ec2-inventory | ansible_ec2_inventory/ec2inventory.py | https://github.com/paperhive/ansible-ec2-inventory/blob/6a13f9de61c089a7b13bce494adceb7507971059/ansible_ec2_inventory/ec2inventory.py#L810-L895 | def add_elasticache_node(self, node, cluster, region):
''' Adds an ElastiCache node to the inventory and index, as long as
it is addressable '''
# Only want available nodes unless all_elasticache_nodes is True
if not self.all_elasticache_nodes and node['CacheNodeStatus'] != 'available':... | [
"def",
"add_elasticache_node",
"(",
"self",
",",
"node",
",",
"cluster",
",",
"region",
")",
":",
"# Only want available nodes unless all_elasticache_nodes is True",
"if",
"not",
"self",
".",
"all_elasticache_nodes",
"and",
"node",
"[",
"'CacheNodeStatus'",
"]",
"!=",
... | Adds an ElastiCache node to the inventory and index, as long as
it is addressable | [
"Adds",
"an",
"ElastiCache",
"node",
"to",
"the",
"inventory",
"and",
"index",
"as",
"long",
"as",
"it",
"is",
"addressable"
] | python | train | 43.755814 |
sentinel-hub/sentinelhub-py | sentinelhub/opensearch.py | https://github.com/sentinel-hub/sentinelhub-py/blob/08a83b7f1e289187159a643336995d8369860fea/sentinelhub/opensearch.py#L97-L113 | def get_area_dates(bbox, date_interval, maxcc=None):
""" Get list of times of existing images from specified area and time range
:param bbox: bounding box of requested area
:type bbox: geometry.BBox
:param date_interval: a pair of time strings in ISO8601 format
:type date_interval: tuple(str)
:... | [
"def",
"get_area_dates",
"(",
"bbox",
",",
"date_interval",
",",
"maxcc",
"=",
"None",
")",
":",
"area_info",
"=",
"get_area_info",
"(",
"bbox",
",",
"date_interval",
",",
"maxcc",
"=",
"maxcc",
")",
"return",
"sorted",
"(",
"{",
"datetime",
".",
"datetime... | Get list of times of existing images from specified area and time range
:param bbox: bounding box of requested area
:type bbox: geometry.BBox
:param date_interval: a pair of time strings in ISO8601 format
:type date_interval: tuple(str)
:param maxcc: filter images by maximum percentage of cloud cov... | [
"Get",
"list",
"of",
"times",
"of",
"existing",
"images",
"from",
"specified",
"area",
"and",
"time",
"range"
] | python | train | 46.352941 |
StellarCN/py-stellar-base | stellar_base/horizon.py | https://github.com/StellarCN/py-stellar-base/blob/cce2e782064fb3955c85e1696e630d67b1010848/stellar_base/horizon.py#L352-L376 | def assets(self, asset_code=None, asset_issuer=None, cursor=None, order='asc', limit=10):
"""This endpoint represents all assets. It will give you all the assets
in the system along with various statistics about each.
See the documentation below for details on query parameters that are
... | [
"def",
"assets",
"(",
"self",
",",
"asset_code",
"=",
"None",
",",
"asset_issuer",
"=",
"None",
",",
"cursor",
"=",
"None",
",",
"order",
"=",
"'asc'",
",",
"limit",
"=",
"10",
")",
":",
"endpoint",
"=",
"'/assets'",
"params",
"=",
"self",
".",
"__qu... | This endpoint represents all assets. It will give you all the assets
in the system along with various statistics about each.
See the documentation below for details on query parameters that are
available.
`GET /assets{?asset_code,asset_issuer,cursor,limit,order}
<https://www.st... | [
"This",
"endpoint",
"represents",
"all",
"assets",
".",
"It",
"will",
"give",
"you",
"all",
"the",
"assets",
"in",
"the",
"system",
"along",
"with",
"various",
"statistics",
"about",
"each",
"."
] | python | train | 48.56 |
horazont/aioxmpp | aioxmpp/stream.py | https://github.com/horazont/aioxmpp/blob/22a68e5e1d23f2a4dee470092adbd4672f9ef061/aioxmpp/stream.py#L2733-L2765 | def message_handler(stream, type_, from_, cb):
"""
Context manager to temporarily register a callback to handle messages on a
:class:`StanzaStream`.
:param stream: Stanza stream to register the coroutine at
:type stream: :class:`StanzaStream`
:param type_: Message type to listen for, or :data:`... | [
"def",
"message_handler",
"(",
"stream",
",",
"type_",
",",
"from_",
",",
"cb",
")",
":",
"stream",
".",
"register_message_callback",
"(",
"type_",
",",
"from_",
",",
"cb",
",",
")",
"try",
":",
"yield",
"finally",
":",
"stream",
".",
"unregister_message_c... | Context manager to temporarily register a callback to handle messages on a
:class:`StanzaStream`.
:param stream: Stanza stream to register the coroutine at
:type stream: :class:`StanzaStream`
:param type_: Message type to listen for, or :data:`None` for a wildcard
match.
:type typ... | [
"Context",
"manager",
"to",
"temporarily",
"register",
"a",
"callback",
"to",
"handle",
"messages",
"on",
"a",
":",
"class",
":",
"StanzaStream",
"."
] | python | train | 28.454545 |
richardkiss/pycoin | pycoin/key/electrum.py | https://github.com/richardkiss/pycoin/blob/1e8d0d9fe20ce0347b97847bb529cd1bd84c7442/pycoin/key/electrum.py#L11-L20 | def initial_key_to_master_key(initial_key):
"""
initial_key:
a hex string of length 32
"""
b = initial_key.encode("utf8")
orig_input = b
for i in range(100000):
b = hashlib.sha256(b + orig_input).digest()
return from_bytes_32(b) | [
"def",
"initial_key_to_master_key",
"(",
"initial_key",
")",
":",
"b",
"=",
"initial_key",
".",
"encode",
"(",
"\"utf8\"",
")",
"orig_input",
"=",
"b",
"for",
"i",
"in",
"range",
"(",
"100000",
")",
":",
"b",
"=",
"hashlib",
".",
"sha256",
"(",
"b",
"+... | initial_key:
a hex string of length 32 | [
"initial_key",
":",
"a",
"hex",
"string",
"of",
"length",
"32"
] | python | train | 26.3 |
boriel/zxbasic | zxblex.py | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxblex.py#L274-L281 | def t_string_NGRAPH(t):
r"\\[ '.:][ '.:]"
global __STRING
P = {' ': 0, "'": 2, '.': 8, ':': 10}
N = {' ': 0, "'": 1, '.': 4, ':': 5}
__STRING += chr(128 + P[t.value[1]] + N[t.value[2]]) | [
"def",
"t_string_NGRAPH",
"(",
"t",
")",
":",
"global",
"__STRING",
"P",
"=",
"{",
"' '",
":",
"0",
",",
"\"'\"",
":",
"2",
",",
"'.'",
":",
"8",
",",
"':'",
":",
"10",
"}",
"N",
"=",
"{",
"' '",
":",
"0",
",",
"\"'\"",
":",
"1",
",",
"'.'"... | r"\\[ '.:][ '.:] | [
"r",
"\\\\",
"[",
".",
":",
"]",
"[",
".",
":",
"]"
] | python | train | 25 |
cidles/pressagio | src/pressagio/dbconnector.py | https://github.com/cidles/pressagio/blob/2b3b89ae82316b929244e4c63e393682b2a57e57/src/pressagio/dbconnector.py#L488-L522 | def create_index(self, cardinality):
"""
Create an index for the table with the given cardinality.
Parameters
----------
cardinality : int
The cardinality to create a index for.
"""
DatabaseConnector.create_index(self, cardinality)
query = "C... | [
"def",
"create_index",
"(",
"self",
",",
"cardinality",
")",
":",
"DatabaseConnector",
".",
"create_index",
"(",
"self",
",",
"cardinality",
")",
"query",
"=",
"\"CREATE INDEX idx_{0}_gram_varchar ON _{0}_gram(word varchar_pattern_ops);\"",
".",
"format",
"(",
"cardinalit... | Create an index for the table with the given cardinality.
Parameters
----------
cardinality : int
The cardinality to create a index for. | [
"Create",
"an",
"index",
"for",
"the",
"table",
"with",
"the",
"given",
"cardinality",
"."
] | python | train | 37.371429 |
Open-ET/openet-core-beta | openet/core/interp.py | https://github.com/Open-ET/openet-core-beta/blob/f2b81ccf87bf7e7fe1b9f3dd1d4081d0ec7852db/openet/core/interp.py#L161-L227 | def aggregate_daily(image_coll, start_date=None, end_date=None,
agg_type='mean'):
"""Aggregate images by day without using joins
The primary purpose of this function is to join separate Landsat images
from the same path into a single daily image.
Parameters
----------
image... | [
"def",
"aggregate_daily",
"(",
"image_coll",
",",
"start_date",
"=",
"None",
",",
"end_date",
"=",
"None",
",",
"agg_type",
"=",
"'mean'",
")",
":",
"if",
"start_date",
"and",
"end_date",
":",
"test_coll",
"=",
"image_coll",
".",
"filterDate",
"(",
"ee",
"... | Aggregate images by day without using joins
The primary purpose of this function is to join separate Landsat images
from the same path into a single daily image.
Parameters
----------
image_coll : ee.ImageCollection
Input image collection.
start_date : date, number, string, optional
... | [
"Aggregate",
"images",
"by",
"day",
"without",
"using",
"joins"
] | python | train | 34.985075 |
andrenarchy/krypy | krypy/recycling/factories.py | https://github.com/andrenarchy/krypy/blob/4883ec9a61d64ea56489e15c35cc40f0633ab2f1/krypy/recycling/factories.py#L53-L136 | def _get_best_subset(self, ritz):
'''Return candidate set with smallest goal functional.'''
# (c,\omega(c)) for all considered subsets c
overall_evaluations = {}
def evaluate(_subset, _evaluations):
try:
_evaluations[_subset] = \
self.sub... | [
"def",
"_get_best_subset",
"(",
"self",
",",
"ritz",
")",
":",
"# (c,\\omega(c)) for all considered subsets c",
"overall_evaluations",
"=",
"{",
"}",
"def",
"evaluate",
"(",
"_subset",
",",
"_evaluations",
")",
":",
"try",
":",
"_evaluations",
"[",
"_subset",
"]",... | Return candidate set with smallest goal functional. | [
"Return",
"candidate",
"set",
"with",
"smallest",
"goal",
"functional",
"."
] | python | train | 39.52381 |
github/octodns | octodns/manager.py | https://github.com/github/octodns/blob/65ee60491e22e6bb0a2aa08f7069c6ecf6c3fee6/octodns/manager.py#L360-L387 | def dump(self, zone, output_dir, lenient, split, source, *sources):
'''
Dump zone data from the specified source
'''
self.log.info('dump: zone=%s, sources=%s', zone, sources)
# We broke out source to force at least one to be passed, add it to any
# others we got.
... | [
"def",
"dump",
"(",
"self",
",",
"zone",
",",
"output_dir",
",",
"lenient",
",",
"split",
",",
"source",
",",
"*",
"sources",
")",
":",
"self",
".",
"log",
".",
"info",
"(",
"'dump: zone=%s, sources=%s'",
",",
"zone",
",",
"sources",
")",
"# We broke out... | Dump zone data from the specified source | [
"Dump",
"zone",
"data",
"from",
"the",
"specified",
"source"
] | python | train | 32.035714 |
jobovy/galpy | galpy/actionAngle/actionAngleStaeckel.py | https://github.com/jobovy/galpy/blob/9c5b9fe65d58835624dffe432be282060918ee08/galpy/actionAngle/actionAngleStaeckel.py#L609-L651 | def JR(self,**kwargs):
"""
NAME:
JR
PURPOSE:
Calculate the radial action
INPUT:
fixed_quad= (False) if True, use n=10 fixed_quad
+scipy.integrate.quad keywords
OUTPUT:
J_R(R,vT,vT)/ro/vc + estimate of the error (nan for fixed... | [
"def",
"JR",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"hasattr",
"(",
"self",
",",
"'_JR'",
")",
":",
"#pragma: no cover",
"return",
"self",
".",
"_JR",
"umin",
",",
"umax",
"=",
"self",
".",
"calcUminUmax",
"(",
")",
"#print self._ux, sel... | NAME:
JR
PURPOSE:
Calculate the radial action
INPUT:
fixed_quad= (False) if True, use n=10 fixed_quad
+scipy.integrate.quad keywords
OUTPUT:
J_R(R,vT,vT)/ro/vc + estimate of the error (nan for fixed_quad)
HISTORY:
2012-11-... | [
"NAME",
":",
"JR",
"PURPOSE",
":",
"Calculate",
"the",
"radial",
"action",
"INPUT",
":",
"fixed_quad",
"=",
"(",
"False",
")",
"if",
"True",
"use",
"n",
"=",
"10",
"fixed_quad",
"+",
"scipy",
".",
"integrate",
".",
"quad",
"keywords",
"OUTPUT",
":",
"J... | python | train | 43.651163 |
log2timeline/dftimewolf | dftimewolf/lib/collectors/grr_hunt.py | https://github.com/log2timeline/dftimewolf/blob/45f898476a288d73c4256ae8e3836a2a4848c0d7/dftimewolf/lib/collectors/grr_hunt.py#L145-L160 | def process(self):
"""Construct and start a new File hunt.
Returns:
The newly created GRR hunt object.
Raises:
RuntimeError: if no items specified for collection.
"""
print('Hunt to collect {0:d} items'.format(len(self.file_path_list)))
print('Files to be collected: {0!s}'.format(s... | [
"def",
"process",
"(",
"self",
")",
":",
"print",
"(",
"'Hunt to collect {0:d} items'",
".",
"format",
"(",
"len",
"(",
"self",
".",
"file_path_list",
")",
")",
")",
"print",
"(",
"'Files to be collected: {0!s}'",
".",
"format",
"(",
"self",
".",
"file_path_li... | Construct and start a new File hunt.
Returns:
The newly created GRR hunt object.
Raises:
RuntimeError: if no items specified for collection. | [
"Construct",
"and",
"start",
"a",
"new",
"File",
"hunt",
"."
] | python | train | 36.1875 |
tensorflow/tensorboard | tensorboard/plugins/image/images_plugin.py | https://github.com/tensorflow/tensorboard/blob/8e5f497b48e40f2a774f85416b8a35ac0693c35e/tensorboard/plugins/image/images_plugin.py#L266-L318 | def _get_individual_image(self, run, tag, index, sample):
"""
Returns the actual image bytes for a given image.
Args:
run: The name of the run the image belongs to.
tag: The name of the tag the images belongs to.
index: The index of the image in the current reservoir.
sample: The ze... | [
"def",
"_get_individual_image",
"(",
"self",
",",
"run",
",",
"tag",
",",
"index",
",",
"sample",
")",
":",
"if",
"self",
".",
"_db_connection_provider",
":",
"db",
"=",
"self",
".",
"_db_connection_provider",
"(",
")",
"cursor",
"=",
"db",
".",
"execute",... | Returns the actual image bytes for a given image.
Args:
run: The name of the run the image belongs to.
tag: The name of the tag the images belongs to.
index: The index of the image in the current reservoir.
sample: The zero-indexed sample of the image to retrieve (for example,
setti... | [
"Returns",
"the",
"actual",
"image",
"bytes",
"for",
"a",
"given",
"image",
"."
] | python | train | 34.603774 |
treycucco/pyebnf | pyebnf/primitive.py | https://github.com/treycucco/pyebnf/blob/3634ddabbe5d73508bcc20f4a591f86a46634e1d/pyebnf/primitive.py#L140-L160 | def trimmed(self, pred=trimmed_pred_default):
"""Trim a ParseTree.
A node is trimmed if pred(node) returns True.
"""
new_children = []
for child in self.children:
if isinstance(child, ParseNode):
new_child = child.trimmed(pred)
else:
new_child = child
if not pred... | [
"def",
"trimmed",
"(",
"self",
",",
"pred",
"=",
"trimmed_pred_default",
")",
":",
"new_children",
"=",
"[",
"]",
"for",
"child",
"in",
"self",
".",
"children",
":",
"if",
"isinstance",
"(",
"child",
",",
"ParseNode",
")",
":",
"new_child",
"=",
"child",... | Trim a ParseTree.
A node is trimmed if pred(node) returns True. | [
"Trim",
"a",
"ParseTree",
"."
] | python | test | 27.238095 |
manns/pyspread | pyspread/src/gui/_grid_cell_editor.py | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/gui/_grid_cell_editor.py#L264-L288 | def StartingKey(self, evt):
"""
If the editor is enabled by pressing keys on the grid, this will be
called to let the editor do something about that first key if desired.
"""
key = evt.GetKeyCode()
ch = None
if key in [
wx.WXK_NUMPAD0, wx.WXK_NUMP... | [
"def",
"StartingKey",
"(",
"self",
",",
"evt",
")",
":",
"key",
"=",
"evt",
".",
"GetKeyCode",
"(",
")",
"ch",
"=",
"None",
"if",
"key",
"in",
"[",
"wx",
".",
"WXK_NUMPAD0",
",",
"wx",
".",
"WXK_NUMPAD1",
",",
"wx",
".",
"WXK_NUMPAD2",
",",
"wx",
... | If the editor is enabled by pressing keys on the grid, this will be
called to let the editor do something about that first key if desired. | [
"If",
"the",
"editor",
"is",
"enabled",
"by",
"pressing",
"keys",
"on",
"the",
"grid",
"this",
"will",
"be",
"called",
"to",
"let",
"the",
"editor",
"do",
"something",
"about",
"that",
"first",
"key",
"if",
"desired",
"."
] | python | train | 36.12 |
calmjs/calmjs.parse | src/calmjs/parse/parsers/es5.py | https://github.com/calmjs/calmjs.parse/blob/369f0ee346c5a84c4d5c35a7733a0e63b02eac59/src/calmjs/parse/parsers/es5.py#L1241-L1250 | def p_iteration_statement_6(self, p):
"""
iteration_statement \
: FOR LPAREN VAR identifier initializer_noin IN expr RPAREN statement
"""
vardecl = self.asttypes.VarDeclNoIn(
identifier=p[4], initializer=p[5])
vardecl.setpos(p, 3)
p[0] = self.asttype... | [
"def",
"p_iteration_statement_6",
"(",
"self",
",",
"p",
")",
":",
"vardecl",
"=",
"self",
".",
"asttypes",
".",
"VarDeclNoIn",
"(",
"identifier",
"=",
"p",
"[",
"4",
"]",
",",
"initializer",
"=",
"p",
"[",
"5",
"]",
")",
"vardecl",
".",
"setpos",
"(... | iteration_statement \
: FOR LPAREN VAR identifier initializer_noin IN expr RPAREN statement | [
"iteration_statement",
"\\",
":",
"FOR",
"LPAREN",
"VAR",
"identifier",
"initializer_noin",
"IN",
"expr",
"RPAREN",
"statement"
] | python | train | 38.6 |
loli/medpy | medpy/metric/binary.py | https://github.com/loli/medpy/blob/95216b9e22e7ce301f0edf953ee2a2f1b6c6aee5/medpy/metric/binary.py#L456-L563 | def asd(result, reference, voxelspacing=None, connectivity=1):
"""
Average surface distance metric.
Computes the average surface distance (ASD) between the binary objects in two images.
Parameters
----------
result : array_like
Input data containing objects. Can be any type but... | [
"def",
"asd",
"(",
"result",
",",
"reference",
",",
"voxelspacing",
"=",
"None",
",",
"connectivity",
"=",
"1",
")",
":",
"sds",
"=",
"__surface_distances",
"(",
"result",
",",
"reference",
",",
"voxelspacing",
",",
"connectivity",
")",
"asd",
"=",
"sds",
... | Average surface distance metric.
Computes the average surface distance (ASD) between the binary objects in two images.
Parameters
----------
result : array_like
Input data containing objects. Can be any type but will be converted
into binary: background where 0, object everywhe... | [
"Average",
"surface",
"distance",
"metric",
".",
"Computes",
"the",
"average",
"surface",
"distance",
"(",
"ASD",
")",
"between",
"the",
"binary",
"objects",
"in",
"two",
"images",
".",
"Parameters",
"----------",
"result",
":",
"array_like",
"Input",
"data",
... | python | train | 33.398148 |
python-openxml/python-docx | docx/opc/phys_pkg.py | https://github.com/python-openxml/python-docx/blob/6756f6cd145511d3eb6d1d188beea391b1ddfd53/docx/opc/phys_pkg.py#L150-L155 | def write(self, pack_uri, blob):
"""
Write *blob* to this zip package with the membername corresponding to
*pack_uri*.
"""
self._zipf.writestr(pack_uri.membername, blob) | [
"def",
"write",
"(",
"self",
",",
"pack_uri",
",",
"blob",
")",
":",
"self",
".",
"_zipf",
".",
"writestr",
"(",
"pack_uri",
".",
"membername",
",",
"blob",
")"
] | Write *blob* to this zip package with the membername corresponding to
*pack_uri*. | [
"Write",
"*",
"blob",
"*",
"to",
"this",
"zip",
"package",
"with",
"the",
"membername",
"corresponding",
"to",
"*",
"pack_uri",
"*",
"."
] | python | train | 34 |
freelancer/freelancer-sdk-python | freelancersdk/resources/projects/projects.py | https://github.com/freelancer/freelancer-sdk-python/blob/e09034936d6f13b3909a9464ee329c81c1834941/freelancersdk/resources/projects/projects.py#L230-L252 | def place_project_bid(session, project_id, bidder_id, description, amount,
period, milestone_percentage):
"""
Place a bid on a project
"""
bid_data = {
'project_id': project_id,
'bidder_id': bidder_id,
'description': description,
'amount': amount,
... | [
"def",
"place_project_bid",
"(",
"session",
",",
"project_id",
",",
"bidder_id",
",",
"description",
",",
"amount",
",",
"period",
",",
"milestone_percentage",
")",
":",
"bid_data",
"=",
"{",
"'project_id'",
":",
"project_id",
",",
"'bidder_id'",
":",
"bidder_id... | Place a bid on a project | [
"Place",
"a",
"bid",
"on",
"a",
"project"
] | python | valid | 36.608696 |
koalalorenzo/python-digitalocean | digitalocean/Image.py | https://github.com/koalalorenzo/python-digitalocean/blob/d0221b57856fb1e131cafecf99d826f7b07a947c/digitalocean/Image.py#L141-L149 | def transfer(self, new_region_slug):
"""
Transfer the image
"""
return self.get_data(
"images/%s/actions/" % self.id,
type=POST,
params={"type": "transfer", "region": new_region_slug}
) | [
"def",
"transfer",
"(",
"self",
",",
"new_region_slug",
")",
":",
"return",
"self",
".",
"get_data",
"(",
"\"images/%s/actions/\"",
"%",
"self",
".",
"id",
",",
"type",
"=",
"POST",
",",
"params",
"=",
"{",
"\"type\"",
":",
"\"transfer\"",
",",
"\"region\"... | Transfer the image | [
"Transfer",
"the",
"image"
] | python | valid | 28.555556 |
biocommons/hgvs | hgvs/projector.py | https://github.com/biocommons/hgvs/blob/4d16efb475e1802b2531a2f1c373e8819d8e533b/hgvs/projector.py#L64-L77 | def project_variant_forward(self, c_variant):
"""
project c_variant on the source transcript onto the destination transcript
:param c_variant: an :class:`hgvs.sequencevariant.SequenceVariant` object on the source transcript
:returns: c_variant: an :class:`hgvs.sequencevariant.SequenceVa... | [
"def",
"project_variant_forward",
"(",
"self",
",",
"c_variant",
")",
":",
"if",
"c_variant",
".",
"ac",
"!=",
"self",
".",
"src_tm",
".",
"tx_ac",
":",
"raise",
"RuntimeError",
"(",
"\"variant accession does not match that used to initialize \"",
"+",
"__name__",
"... | project c_variant on the source transcript onto the destination transcript
:param c_variant: an :class:`hgvs.sequencevariant.SequenceVariant` object on the source transcript
:returns: c_variant: an :class:`hgvs.sequencevariant.SequenceVariant` object on the destination transcript | [
"project",
"c_variant",
"on",
"the",
"source",
"transcript",
"onto",
"the",
"destination",
"transcript"
] | python | train | 53.857143 |
push-things/django-th | django_th/services/services.py | https://github.com/push-things/django-th/blob/86c999d16bcf30b6224206e5b40824309834ac8c/django_th/services/services.py#L131-L152 | def save_data(self, trigger_id, **data):
"""
used to save data to the service
but first of all
make some work about the data to find
and the data to convert
:param trigger_id: trigger ID from which to save data
:param data: the data to chec... | [
"def",
"save_data",
"(",
"self",
",",
"trigger_id",
",",
"*",
"*",
"data",
")",
":",
"title",
"=",
"self",
".",
"set_title",
"(",
"data",
")",
"title",
"=",
"HtmlEntities",
"(",
"title",
")",
".",
"html_entity_decode",
"content",
"=",
"self",
".",
"set... | used to save data to the service
but first of all
make some work about the data to find
and the data to convert
:param trigger_id: trigger ID from which to save data
:param data: the data to check to be used and save
:type trigger_id: int
... | [
"used",
"to",
"save",
"data",
"to",
"the",
"service",
"but",
"first",
"of",
"all",
"make",
"some",
"work",
"about",
"the",
"data",
"to",
"find",
"and",
"the",
"data",
"to",
"convert",
":",
"param",
"trigger_id",
":",
"trigger",
"ID",
"from",
"which",
"... | python | train | 40.863636 |
linkedin/naarad | src/naarad/__init__.py | https://github.com/linkedin/naarad/blob/261e2c0760fd6a6b0ee59064180bd8e3674311fe/src/naarad/__init__.py#L74-L81 | def create_analysis(self, config):
"""
Create Analysis and save in Naarad from config
:param config:
:return:
"""
self._default_test_id += 1
self._analyses[self._default_test_id] = _Analysis(ts_start=None, config=config, test_id=self._default_test_id) | [
"def",
"create_analysis",
"(",
"self",
",",
"config",
")",
":",
"self",
".",
"_default_test_id",
"+=",
"1",
"self",
".",
"_analyses",
"[",
"self",
".",
"_default_test_id",
"]",
"=",
"_Analysis",
"(",
"ts_start",
"=",
"None",
",",
"config",
"=",
"config",
... | Create Analysis and save in Naarad from config
:param config:
:return: | [
"Create",
"Analysis",
"and",
"save",
"in",
"Naarad",
"from",
"config",
":",
"param",
"config",
":",
":",
"return",
":"
] | python | valid | 34 |
Britefury/batchup | batchup/datasets/dataset.py | https://github.com/Britefury/batchup/blob/3fc2304e629f813c05f9e7a85a18acef3581a536/batchup/datasets/dataset.py#L124-L135 | def acquire(self, **kwargs):
"""
Download the file and return its path
Returns
-------
str or None
The path of the file in BatchUp's temporary directory or None if
the download failed.
"""
return config.download_data(self.temp_filename, se... | [
"def",
"acquire",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"config",
".",
"download_data",
"(",
"self",
".",
"temp_filename",
",",
"self",
".",
"url",
",",
"self",
".",
"sha256",
")"
] | Download the file and return its path
Returns
-------
str or None
The path of the file in BatchUp's temporary directory or None if
the download failed. | [
"Download",
"the",
"file",
"and",
"return",
"its",
"path"
] | python | train | 30.416667 |
materialsproject/pymatgen | pymatgen/ext/matproj.py | https://github.com/materialsproject/pymatgen/blob/4ca558cf72f8d5f8a1f21dfdfc0181a971c186da/pymatgen/ext/matproj.py#L1064-L1087 | def get_cohesive_energy(self, material_id, per_atom=False):
"""
Gets the cohesive for a material (eV per formula unit). Cohesive energy
is defined as the difference between the bulk energy and the sum of
total DFT energy of isolated atoms for atom elements in the bulk.
Ar... | [
"def",
"get_cohesive_energy",
"(",
"self",
",",
"material_id",
",",
"per_atom",
"=",
"False",
")",
":",
"entry",
"=",
"self",
".",
"get_entry_by_material_id",
"(",
"material_id",
")",
"ebulk",
"=",
"entry",
".",
"energy",
"/",
"entry",
".",
"composition",
".... | Gets the cohesive for a material (eV per formula unit). Cohesive energy
is defined as the difference between the bulk energy and the sum of
total DFT energy of isolated atoms for atom elements in the bulk.
Args:
material_id (str): Materials Project material_id, e.g. 'mp-123'.... | [
"Gets",
"the",
"cohesive",
"for",
"a",
"material",
"(",
"eV",
"per",
"formula",
"unit",
")",
".",
"Cohesive",
"energy",
"is",
"defined",
"as",
"the",
"difference",
"between",
"the",
"bulk",
"energy",
"and",
"the",
"sum",
"of",
"total",
"DFT",
"energy",
"... | python | train | 49.5 |
chrisspen/weka | weka/arff.py | https://github.com/chrisspen/weka/blob/c86fc4b8eef1afd56f89ec28283bdf9e2fdc453b/weka/arff.py#L592-L601 | def define_attribute(self, name, atype, data=None):
"""
Define a new attribute. atype has to be one of 'integer', 'real', 'numeric', 'string', 'date' or 'nominal'.
For nominal attributes, pass the possible values as data.
For date attributes, pass the format as data.
"""
... | [
"def",
"define_attribute",
"(",
"self",
",",
"name",
",",
"atype",
",",
"data",
"=",
"None",
")",
":",
"self",
".",
"attributes",
".",
"append",
"(",
"name",
")",
"assert",
"atype",
"in",
"TYPES",
",",
"\"Unknown type '%s'. Must be one of: %s\"",
"%",
"(",
... | Define a new attribute. atype has to be one of 'integer', 'real', 'numeric', 'string', 'date' or 'nominal'.
For nominal attributes, pass the possible values as data.
For date attributes, pass the format as data. | [
"Define",
"a",
"new",
"attribute",
".",
"atype",
"has",
"to",
"be",
"one",
"of",
"integer",
"real",
"numeric",
"string",
"date",
"or",
"nominal",
".",
"For",
"nominal",
"attributes",
"pass",
"the",
"possible",
"values",
"as",
"data",
".",
"For",
"date",
... | python | train | 52.3 |
thusoy/headsup | headsup.py | https://github.com/thusoy/headsup/blob/165a63cc6c987f664f2efd901d483ca07b7bc898/headsup.py#L83-L90 | def get_default_net_device():
""" Find the device where the default route is. """
with open('/proc/net/route') as fh:
for line in fh:
iface, dest, _ = line.split(None, 2)
if dest == '00000000':
return iface
return None | [
"def",
"get_default_net_device",
"(",
")",
":",
"with",
"open",
"(",
"'/proc/net/route'",
")",
"as",
"fh",
":",
"for",
"line",
"in",
"fh",
":",
"iface",
",",
"dest",
",",
"_",
"=",
"line",
".",
"split",
"(",
"None",
",",
"2",
")",
"if",
"dest",
"==... | Find the device where the default route is. | [
"Find",
"the",
"device",
"where",
"the",
"default",
"route",
"is",
"."
] | python | train | 33.875 |
criteo/gourde | gourde/gourde.py | https://github.com/criteo/gourde/blob/9a274e534a2af5d2b2a5e99f10c59010adb94863/gourde/gourde.py#L251-L264 | def threads_bt(self):
"""Display thread backtraces."""
import threading
import traceback
threads = {}
for thread in threading.enumerate():
frames = sys._current_frames().get(thread.ident)
if frames:
stack = traceback.format_stack(frames)
... | [
"def",
"threads_bt",
"(",
"self",
")",
":",
"import",
"threading",
"import",
"traceback",
"threads",
"=",
"{",
"}",
"for",
"thread",
"in",
"threading",
".",
"enumerate",
"(",
")",
":",
"frames",
"=",
"sys",
".",
"_current_frames",
"(",
")",
".",
"get",
... | Display thread backtraces. | [
"Display",
"thread",
"backtraces",
"."
] | python | train | 33.714286 |
dpgaspar/Flask-AppBuilder | flask_appbuilder/console.py | https://github.com/dpgaspar/Flask-AppBuilder/blob/c293734c1b86e176a3ba57ee2deab6676d125576/flask_appbuilder/console.py#L156-L168 | def create_user(app, appbuilder, role, username, firstname, lastname, email, password):
"""
Create a user
"""
_appbuilder = import_application(app, appbuilder)
role_object = _appbuilder.sm.find_role(role)
user = _appbuilder.sm.add_user(
username, firstname, lastname, email, role_obje... | [
"def",
"create_user",
"(",
"app",
",",
"appbuilder",
",",
"role",
",",
"username",
",",
"firstname",
",",
"lastname",
",",
"email",
",",
"password",
")",
":",
"_appbuilder",
"=",
"import_application",
"(",
"app",
",",
"appbuilder",
")",
"role_object",
"=",
... | Create a user | [
"Create",
"a",
"user"
] | python | train | 38.384615 |
Azure/azure-multiapi-storage-python | azure/multiapi/storage/v2015_04_05/table/tableservice.py | https://github.com/Azure/azure-multiapi-storage-python/blob/bd5482547f993c6eb56fd09070e15c2e9616e440/azure/multiapi/storage/v2015_04_05/table/tableservice.py#L804-L836 | def insert_entity(self, table_name, entity, timeout=None):
'''
Inserts a new entity into the table. Throws if an entity with the same
PartitionKey and RowKey already exists.
When inserting an entity into a table, you must specify values for the
PartitionKey and RowKey system p... | [
"def",
"insert_entity",
"(",
"self",
",",
"table_name",
",",
"entity",
",",
"timeout",
"=",
"None",
")",
":",
"_validate_not_none",
"(",
"'table_name'",
",",
"table_name",
")",
"request",
"=",
"_insert_entity",
"(",
"entity",
")",
"request",
".",
"host",
"="... | Inserts a new entity into the table. Throws if an entity with the same
PartitionKey and RowKey already exists.
When inserting an entity into a table, you must specify values for the
PartitionKey and RowKey system properties. Together, these properties
form the primary key and must be... | [
"Inserts",
"a",
"new",
"entity",
"into",
"the",
"table",
".",
"Throws",
"if",
"an",
"entity",
"with",
"the",
"same",
"PartitionKey",
"and",
"RowKey",
"already",
"exists",
"."
] | python | train | 48.060606 |
agoragames/kairos | kairos/cassandra_backend.py | https://github.com/agoragames/kairos/blob/0b062d543b0f4a46df460fa0eb6ec281232ab179/kairos/cassandra_backend.py#L188-L196 | def _insert_data(self, connection, name, value, timestamp, interval, config):
'''Helper to insert data into cql.'''
cursor = connection.cursor()
try:
stmt = self._insert_stmt(name, value, timestamp, interval, config)
if stmt:
cursor.execute(stmt)
finally:
cursor.close() | [
"def",
"_insert_data",
"(",
"self",
",",
"connection",
",",
"name",
",",
"value",
",",
"timestamp",
",",
"interval",
",",
"config",
")",
":",
"cursor",
"=",
"connection",
".",
"cursor",
"(",
")",
"try",
":",
"stmt",
"=",
"self",
".",
"_insert_stmt",
"(... | Helper to insert data into cql. | [
"Helper",
"to",
"insert",
"data",
"into",
"cql",
"."
] | python | train | 33.777778 |
Kozea/cairocffi | cairocffi/matrix.py | https://github.com/Kozea/cairocffi/blob/450853add7e32eea20985b6aa5f54d9cb3cd04fe/cairocffi/matrix.py#L106-L123 | def translate(self, tx, ty):
"""Applies a translation by :obj:`tx`, :obj:`ty`
to the transformation in this matrix.
The effect of the new transformation is to
first translate the coordinates by :obj:`tx` and :obj:`ty`,
then apply the original transformation to the coordinates.
... | [
"def",
"translate",
"(",
"self",
",",
"tx",
",",
"ty",
")",
":",
"cairo",
".",
"cairo_matrix_translate",
"(",
"self",
".",
"_pointer",
",",
"tx",
",",
"ty",
")"
] | Applies a translation by :obj:`tx`, :obj:`ty`
to the transformation in this matrix.
The effect of the new transformation is to
first translate the coordinates by :obj:`tx` and :obj:`ty`,
then apply the original transformation to the coordinates.
.. note::
This chang... | [
"Applies",
"a",
"translation",
"by",
":",
"obj",
":",
"tx",
":",
"obj",
":",
"ty",
"to",
"the",
"transformation",
"in",
"this",
"matrix",
"."
] | python | train | 33.666667 |
kennethreitz/records | records.py | https://github.com/kennethreitz/records/blob/ecd857266c5e7830d657cbe0196816314790563b/records.py#L207-L226 | def first(self, default=None, as_dict=False, as_ordereddict=False):
"""Returns a single record for the RecordCollection, or `default`. If
`default` is an instance or subclass of Exception, then raise it
instead of returning it."""
# Try to get a record, or return/raise default.
... | [
"def",
"first",
"(",
"self",
",",
"default",
"=",
"None",
",",
"as_dict",
"=",
"False",
",",
"as_ordereddict",
"=",
"False",
")",
":",
"# Try to get a record, or return/raise default.",
"try",
":",
"record",
"=",
"self",
"[",
"0",
"]",
"except",
"IndexError",
... | Returns a single record for the RecordCollection, or `default`. If
`default` is an instance or subclass of Exception, then raise it
instead of returning it. | [
"Returns",
"a",
"single",
"record",
"for",
"the",
"RecordCollection",
"or",
"default",
".",
"If",
"default",
"is",
"an",
"instance",
"or",
"subclass",
"of",
"Exception",
"then",
"raise",
"it",
"instead",
"of",
"returning",
"it",
"."
] | python | train | 32.8 |
awickert/gFlex | gflex/f2d.py | https://github.com/awickert/gFlex/blob/3ac32249375b0f8d342a142585d86ea4d905a5a0/gflex/f2d.py#L184-L196 | def elasprep(self):
"""
dx4, dy4, dx2dy2, D = elasprep(dx,dy,Te,E=1E11,nu=0.25)
Defines the variables that are required to create the 2D finite
difference solution coefficient matrix
"""
if self.Method != 'SAS_NG':
self.dx4 = self.dx**4
self.dy4 = self.dy**4
self.dx2... | [
"def",
"elasprep",
"(",
"self",
")",
":",
"if",
"self",
".",
"Method",
"!=",
"'SAS_NG'",
":",
"self",
".",
"dx4",
"=",
"self",
".",
"dx",
"**",
"4",
"self",
".",
"dy4",
"=",
"self",
".",
"dy",
"**",
"4",
"self",
".",
"dx2dy2",
"=",
"self",
".",... | dx4, dy4, dx2dy2, D = elasprep(dx,dy,Te,E=1E11,nu=0.25)
Defines the variables that are required to create the 2D finite
difference solution coefficient matrix | [
"dx4",
"dy4",
"dx2dy2",
"D",
"=",
"elasprep",
"(",
"dx",
"dy",
"Te",
"E",
"=",
"1E11",
"nu",
"=",
"0",
".",
"25",
")",
"Defines",
"the",
"variables",
"that",
"are",
"required",
"to",
"create",
"the",
"2D",
"finite",
"difference",
"solution",
"coefficie... | python | train | 29.846154 |
LEMS/pylems | lems/model/dynamics.py | https://github.com/LEMS/pylems/blob/4eeb719d2f23650fe16c38626663b69b5c83818b/lems/model/dynamics.py#L104-L116 | def toxml(self):
"""
Exports this object into a LEMS XML object
"""
return '<DerivedVariable name="{0}"'.format(self.name) +\
(' dimension="{0}"'.format(self.dimension) if self.dimension else '') +\
(' exposure="{0}"'.format(self.exposure) if self.exposure else '') +... | [
"def",
"toxml",
"(",
"self",
")",
":",
"return",
"'<DerivedVariable name=\"{0}\"'",
".",
"format",
"(",
"self",
".",
"name",
")",
"+",
"(",
"' dimension=\"{0}\"'",
".",
"format",
"(",
"self",
".",
"dimension",
")",
"if",
"self",
".",
"dimension",
"else",
"... | Exports this object into a LEMS XML object | [
"Exports",
"this",
"object",
"into",
"a",
"LEMS",
"XML",
"object"
] | python | train | 47.923077 |
ontio/ontology-python-sdk | ontology/smart_contract/neo_contract/oep4.py | https://github.com/ontio/ontology-python-sdk/blob/ac88bdda941896c5d2ced08422a9c5179d3f9b19/ontology/smart_contract/neo_contract/oep4.py#L123-L150 | def transfer(self, from_acct: Account, b58_to_address: str, value: int, payer_acct: Account, gas_limit: int,
gas_price: int) -> str:
"""
This interface is used to call the Transfer method in ope4
that transfer an amount of tokens from one account to another account.
:pa... | [
"def",
"transfer",
"(",
"self",
",",
"from_acct",
":",
"Account",
",",
"b58_to_address",
":",
"str",
",",
"value",
":",
"int",
",",
"payer_acct",
":",
"Account",
",",
"gas_limit",
":",
"int",
",",
"gas_price",
":",
"int",
")",
"->",
"str",
":",
"func",... | This interface is used to call the Transfer method in ope4
that transfer an amount of tokens from one account to another account.
:param from_acct: an Account class that send the oep4 token.
:param b58_to_address: a base58 encode address that receive the oep4 token.
:param value: an int... | [
"This",
"interface",
"is",
"used",
"to",
"call",
"the",
"Transfer",
"method",
"in",
"ope4",
"that",
"transfer",
"an",
"amount",
"of",
"tokens",
"from",
"one",
"account",
"to",
"another",
"account",
"."
] | python | train | 62.857143 |
CxAalto/gtfspy | gtfspy/mapviz.py | https://github.com/CxAalto/gtfspy/blob/bddba4b74faae6c1b91202f19184811e326547e5/gtfspy/mapviz.py#L262-L305 | def _expand_spatial_bounds_to_fit_axes(bounds, ax_width, ax_height):
"""
Parameters
----------
bounds: dict
ax_width: float
ax_height: float
Returns
-------
spatial_bounds
"""
b = bounds
height_meters = util.wgs84_distance(b['lat_min'], b['lon_min'], b['lat_max'], b['lon... | [
"def",
"_expand_spatial_bounds_to_fit_axes",
"(",
"bounds",
",",
"ax_width",
",",
"ax_height",
")",
":",
"b",
"=",
"bounds",
"height_meters",
"=",
"util",
".",
"wgs84_distance",
"(",
"b",
"[",
"'lat_min'",
"]",
",",
"b",
"[",
"'lon_min'",
"]",
",",
"b",
"[... | Parameters
----------
bounds: dict
ax_width: float
ax_height: float
Returns
-------
spatial_bounds | [
"Parameters",
"----------",
"bounds",
":",
"dict",
"ax_width",
":",
"float",
"ax_height",
":",
"float"
] | python | valid | 37.272727 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/tools/magfit.py | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/tools/magfit.py#L51-L58 | def radius_cmp(a, b, offsets):
'''return +1 or -1 for for sorting'''
diff = radius(a, offsets) - radius(b, offsets)
if diff > 0:
return 1
if diff < 0:
return -1
return 0 | [
"def",
"radius_cmp",
"(",
"a",
",",
"b",
",",
"offsets",
")",
":",
"diff",
"=",
"radius",
"(",
"a",
",",
"offsets",
")",
"-",
"radius",
"(",
"b",
",",
"offsets",
")",
"if",
"diff",
">",
"0",
":",
"return",
"1",
"if",
"diff",
"<",
"0",
":",
"r... | return +1 or -1 for for sorting | [
"return",
"+",
"1",
"or",
"-",
"1",
"for",
"for",
"sorting"
] | python | train | 24.75 |
gtaylor/django-athumb | athumb/management/commands/athumb_regen_field.py | https://github.com/gtaylor/django-athumb/blob/69261ace0dff81e33156a54440874456a7b38dfb/athumb/management/commands/athumb_regen_field.py#L43-L119 | def regenerate_thumbs(self):
"""
Handle re-generating the thumbnails. All this involves is reading the
original file, then saving the same exact thing. Kind of annoying, but
it's simple.
"""
Model = self.model
instances = Model.objects.all()
num_instances ... | [
"def",
"regenerate_thumbs",
"(",
"self",
")",
":",
"Model",
"=",
"self",
".",
"model",
"instances",
"=",
"Model",
".",
"objects",
".",
"all",
"(",
")",
"num_instances",
"=",
"instances",
".",
"count",
"(",
")",
"# Filenames are keys in here, to help avoid re-gen... | Handle re-generating the thumbnails. All this involves is reading the
original file, then saving the same exact thing. Kind of annoying, but
it's simple. | [
"Handle",
"re",
"-",
"generating",
"the",
"thumbnails",
".",
"All",
"this",
"involves",
"is",
"reading",
"the",
"original",
"file",
"then",
"saving",
"the",
"same",
"exact",
"thing",
".",
"Kind",
"of",
"annoying",
"but",
"it",
"s",
"simple",
"."
] | python | train | 40.103896 |
ladybug-tools/ladybug | ladybug/futil.py | https://github.com/ladybug-tools/ladybug/blob/c08b7308077a48d5612f644943f92d5b5dade583/ladybug/futil.py#L295-L305 | def csv_to_num_matrix(csv_file_path):
"""Load a CSV file consisting only of numbers into a Python matrix of floats.
Args:
csv_file_path: Full path to a valid CSV file (e.g. c:/ladybug/test.csv)
"""
mtx = []
with open(csv_file_path) as csv_data_file:
for row in csv_data_file:
... | [
"def",
"csv_to_num_matrix",
"(",
"csv_file_path",
")",
":",
"mtx",
"=",
"[",
"]",
"with",
"open",
"(",
"csv_file_path",
")",
"as",
"csv_data_file",
":",
"for",
"row",
"in",
"csv_data_file",
":",
"mtx",
".",
"append",
"(",
"[",
"float",
"(",
"val",
")",
... | Load a CSV file consisting only of numbers into a Python matrix of floats.
Args:
csv_file_path: Full path to a valid CSV file (e.g. c:/ladybug/test.csv) | [
"Load",
"a",
"CSV",
"file",
"consisting",
"only",
"of",
"numbers",
"into",
"a",
"Python",
"matrix",
"of",
"floats",
"."
] | python | train | 34.545455 |
DiamondLightSource/python-workflows | workflows/transport/common_transport.py | https://github.com/DiamondLightSource/python-workflows/blob/7ef47b457655b96f4d2ef7ee9863cf1b6d20e023/workflows/transport/common_transport.py#L260-L285 | def nack(self, message, subscription_id=None, **kwargs):
"""Reject receipt of a message. This only makes sense when the
'acknowledgement' flag was set for the relevant subscription.
:param message: ID of the message to be rejected, OR a dictionary
containing a field 'mess... | [
"def",
"nack",
"(",
"self",
",",
"message",
",",
"subscription_id",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"isinstance",
"(",
"message",
",",
"dict",
")",
":",
"message_id",
"=",
"message",
".",
"get",
"(",
"\"message-id\"",
")",
"if",
... | Reject receipt of a message. This only makes sense when the
'acknowledgement' flag was set for the relevant subscription.
:param message: ID of the message to be rejected, OR a dictionary
containing a field 'message-id'.
:param subscription_id: ID of the associated subscr... | [
"Reject",
"receipt",
"of",
"a",
"message",
".",
"This",
"only",
"makes",
"sense",
"when",
"the",
"acknowledgement",
"flag",
"was",
"set",
"for",
"the",
"relevant",
"subscription",
".",
":",
"param",
"message",
":",
"ID",
"of",
"the",
"message",
"to",
"be",... | python | train | 53.423077 |
scot-dev/scot | scot/external/infomax_.py | https://github.com/scot-dev/scot/blob/48598b79d4400dad893b134cd2194715511facda/scot/external/infomax_.py#L22-L281 | def infomax(data, weights=None, l_rate=None, block=None, w_change=1e-12,
anneal_deg=60., anneal_step=0.9, extended=False, n_subgauss=1,
kurt_size=6000, ext_blocks=1, max_iter=200,
random_state=None, verbose=None):
"""Run the (extended) Infomax ICA decomposition on raw data
b... | [
"def",
"infomax",
"(",
"data",
",",
"weights",
"=",
"None",
",",
"l_rate",
"=",
"None",
",",
"block",
"=",
"None",
",",
"w_change",
"=",
"1e-12",
",",
"anneal_deg",
"=",
"60.",
",",
"anneal_step",
"=",
"0.9",
",",
"extended",
"=",
"False",
",",
"n_su... | Run the (extended) Infomax ICA decomposition on raw data
based on the publications of Bell & Sejnowski 1995 (Infomax)
and Lee, Girolami & Sejnowski, 1999 (extended Infomax)
Parameters
----------
data : np.ndarray, shape (n_samples, n_features)
The data to unmix.
w_init : np.ndarray, sh... | [
"Run",
"the",
"(",
"extended",
")",
"Infomax",
"ICA",
"decomposition",
"on",
"raw",
"data"
] | python | train | 36.307692 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.