repo stringlengths 7 54 | path stringlengths 4 192 | url stringlengths 87 284 | code stringlengths 78 104k | code_tokens list | docstring stringlengths 1 46.9k | docstring_tokens list | language stringclasses 1
value | partition stringclasses 3
values |
|---|---|---|---|---|---|---|---|---|
michael-lazar/rtv | rtv/terminal.py | https://github.com/michael-lazar/rtv/blob/ccef2af042566ad384977028cf0bde01bc524dda/rtv/terminal.py#L878-L910 | def strip_textpad(text):
"""
Attempt to intelligently strip excess whitespace from the output of a
curses textpad.
"""
if text is None:
return text
# Trivial case where the textbox is only one line long.
if '\n' not in text:
return text.r... | [
"def",
"strip_textpad",
"(",
"text",
")",
":",
"if",
"text",
"is",
"None",
":",
"return",
"text",
"# Trivial case where the textbox is only one line long.",
"if",
"'\\n'",
"not",
"in",
"text",
":",
"return",
"text",
".",
"rstrip",
"(",
")",
"# Allow one space at t... | Attempt to intelligently strip excess whitespace from the output of a
curses textpad. | [
"Attempt",
"to",
"intelligently",
"strip",
"excess",
"whitespace",
"from",
"the",
"output",
"of",
"a",
"curses",
"textpad",
"."
] | python | train |
astrorafael/twisted-mqtt | examples/pubsubs.py | https://github.com/astrorafael/twisted-mqtt/blob/5b322f7c2b82a502b1e1b70703ae45f1f668d07d/examples/pubsubs.py#L72-L89 | def connectToBroker(self, protocol):
'''
Connect to MQTT broker
'''
self.protocol = protocol
self.protocol.onPublish = self.onPublish
self.protocol.onDisconnection = self.onDisconnection
self.protocol.setWindowSize(3)
self.task = task... | [
"def",
"connectToBroker",
"(",
"self",
",",
"protocol",
")",
":",
"self",
".",
"protocol",
"=",
"protocol",
"self",
".",
"protocol",
".",
"onPublish",
"=",
"self",
".",
"onPublish",
"self",
".",
"protocol",
".",
"onDisconnection",
"=",
"self",
".",
"onDisc... | Connect to MQTT broker | [
"Connect",
"to",
"MQTT",
"broker"
] | python | test |
Fantomas42/django-blog-zinnia | zinnia/xmlrpc/metaweblog.py | https://github.com/Fantomas42/django-blog-zinnia/blob/b4949304b104a8e1a7a7a0773cbfd024313c3a15/zinnia/xmlrpc/metaweblog.py#L205-L212 | def get_post(post_id, username, password):
"""
metaWeblog.getPost(post_id, username, password)
=> post structure
"""
user = authenticate(username, password)
site = Site.objects.get_current()
return post_structure(Entry.objects.get(id=post_id, authors=user), site) | [
"def",
"get_post",
"(",
"post_id",
",",
"username",
",",
"password",
")",
":",
"user",
"=",
"authenticate",
"(",
"username",
",",
"password",
")",
"site",
"=",
"Site",
".",
"objects",
".",
"get_current",
"(",
")",
"return",
"post_structure",
"(",
"Entry",
... | metaWeblog.getPost(post_id, username, password)
=> post structure | [
"metaWeblog",
".",
"getPost",
"(",
"post_id",
"username",
"password",
")",
"=",
">",
"post",
"structure"
] | python | train |
numenta/htmresearch | htmresearch/frameworks/sp_paper/sp_metrics.py | https://github.com/numenta/htmresearch/blob/70c096b09a577ea0432c3f3bfff4442d4871b7aa/htmresearch/frameworks/sp_paper/sp_metrics.py#L888-L920 | def mutualInformation(sp, activeColumnsCurrentEpoch, column_1, column_2):
"""
Computes the mutual information of the binary variables that represent
the activation probabilities of two columns. The mutual information I(X,Y)
of two random variables is given by
\[
I (X,Y) = \sum_{x,y} p(x,y) log( p(x,... | [
"def",
"mutualInformation",
"(",
"sp",
",",
"activeColumnsCurrentEpoch",
",",
"column_1",
",",
"column_2",
")",
":",
"i",
",",
"j",
"=",
"column_1",
",",
"column_2",
"batchSize",
"=",
"activeColumnsCurrentEpoch",
".",
"shape",
"[",
"0",
"]",
"# Activity Counts",... | Computes the mutual information of the binary variables that represent
the activation probabilities of two columns. The mutual information I(X,Y)
of two random variables is given by
\[
I (X,Y) = \sum_{x,y} p(x,y) log( p(x,y) / ( p(x) p(y) ) ).
\]
(https://en.wikipedia.org/wiki/Mutual_information) | [
"Computes",
"the",
"mutual",
"information",
"of",
"the",
"binary",
"variables",
"that",
"represent",
"the",
"activation",
"probabilities",
"of",
"two",
"columns",
".",
"The",
"mutual",
"information",
"I",
"(",
"X",
"Y",
")",
"of",
"two",
"random",
"variables",... | python | train |
lablup/backend.ai-client-py | src/ai/backend/client/cli/admin/images.py | https://github.com/lablup/backend.ai-client-py/blob/a063d774fea6f4350b89498c40d3c837ec3029a7/src/ai/backend/client/cli/admin/images.py#L11-L34 | def images():
'''
Show the list of registered images in this cluster.
'''
fields = [
('Name', 'name'),
('Registry', 'registry'),
('Tag', 'tag'),
('Digest', 'digest'),
('Size', 'size_bytes'),
('Aliases', 'aliases'),
]
with Session() as session:
... | [
"def",
"images",
"(",
")",
":",
"fields",
"=",
"[",
"(",
"'Name'",
",",
"'name'",
")",
",",
"(",
"'Registry'",
",",
"'registry'",
")",
",",
"(",
"'Tag'",
",",
"'tag'",
")",
",",
"(",
"'Digest'",
",",
"'digest'",
")",
",",
"(",
"'Size'",
",",
"'si... | Show the list of registered images in this cluster. | [
"Show",
"the",
"list",
"of",
"registered",
"images",
"in",
"this",
"cluster",
"."
] | python | train |
opencobra/cobrapy | cobra/core/reaction.py | https://github.com/opencobra/cobrapy/blob/9d1987cdb3a395cf4125a3439c3b002ff2be2009/cobra/core/reaction.py#L490-L504 | def functional(self):
"""All required enzymes for reaction are functional.
Returns
-------
bool
True if the gene-protein-reaction (GPR) rule is fulfilled for
this reaction, or if reaction is not associated to a model,
otherwise False.
"""
... | [
"def",
"functional",
"(",
"self",
")",
":",
"if",
"self",
".",
"_model",
":",
"tree",
",",
"_",
"=",
"parse_gpr",
"(",
"self",
".",
"gene_reaction_rule",
")",
"return",
"eval_gpr",
"(",
"tree",
",",
"{",
"gene",
".",
"id",
"for",
"gene",
"in",
"self"... | All required enzymes for reaction are functional.
Returns
-------
bool
True if the gene-protein-reaction (GPR) rule is fulfilled for
this reaction, or if reaction is not associated to a model,
otherwise False. | [
"All",
"required",
"enzymes",
"for",
"reaction",
"are",
"functional",
"."
] | python | valid |
lingthio/Flask-User | flask_user/user_mixin.py | https://github.com/lingthio/Flask-User/blob/a379fa0a281789618c484b459cb41236779b95b1/flask_user/user_mixin.py#L59-L102 | def has_roles(self, *requirements):
""" Return True if the user has all of the specified roles. Return False otherwise.
has_roles() accepts a list of requirements:
has_role(requirement1, requirement2, requirement3).
Each requirement is either a role_name, or a tuple_of_... | [
"def",
"has_roles",
"(",
"self",
",",
"*",
"requirements",
")",
":",
"# Translates a list of role objects to a list of role_names",
"user_manager",
"=",
"current_app",
".",
"user_manager",
"role_names",
"=",
"user_manager",
".",
"db_manager",
".",
"get_user_roles",
"(",
... | Return True if the user has all of the specified roles. Return False otherwise.
has_roles() accepts a list of requirements:
has_role(requirement1, requirement2, requirement3).
Each requirement is either a role_name, or a tuple_of_role_names.
role_name example: ... | [
"Return",
"True",
"if",
"the",
"user",
"has",
"all",
"of",
"the",
"specified",
"roles",
".",
"Return",
"False",
"otherwise",
"."
] | python | train |
raff/dynash | dynash2/dynash2.py | https://github.com/raff/dynash/blob/a2b4fab67dd85ceaa9c1bb7604ebc1768a7fc28e/dynash2/dynash2.py#L463-L477 | def do_refresh(self, line):
"refresh {table_name}"
table = self.get_table(line)
while True:
desc = table.describe()
status = desc['Table']['TableStatus']
if status == 'ACTIVE':
break
else:
print status, "..."
... | [
"def",
"do_refresh",
"(",
"self",
",",
"line",
")",
":",
"table",
"=",
"self",
".",
"get_table",
"(",
"line",
")",
"while",
"True",
":",
"desc",
"=",
"table",
".",
"describe",
"(",
")",
"status",
"=",
"desc",
"[",
"'Table'",
"]",
"[",
"'TableStatus'"... | refresh {table_name} | [
"refresh",
"{",
"table_name",
"}"
] | python | train |
CiscoUcs/UcsPythonSDK | src/UcsSdk/UcsBase.py | https://github.com/CiscoUcs/UcsPythonSDK/blob/bf6b07d6abeacb922c92b198352eda4eb9e4629b/src/UcsSdk/UcsBase.py#L68-L73 | def childWriteXml(self, w, option):
"""Method writes the xml representation for the object."""
ch = []
for c in self.child:
ch.append(c.WriteXml(w, option))
return ch | [
"def",
"childWriteXml",
"(",
"self",
",",
"w",
",",
"option",
")",
":",
"ch",
"=",
"[",
"]",
"for",
"c",
"in",
"self",
".",
"child",
":",
"ch",
".",
"append",
"(",
"c",
".",
"WriteXml",
"(",
"w",
",",
"option",
")",
")",
"return",
"ch"
] | Method writes the xml representation for the object. | [
"Method",
"writes",
"the",
"xml",
"representation",
"for",
"the",
"object",
"."
] | python | train |
apache/incubator-mxnet | python/mxnet/operator.py | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/operator.py#L506-L527 | def infer_type(self, in_type):
"""infer_type interface. override to create new operators
Parameters
----------
in_type : list of np.dtype
list of argument types in the same order as
declared in list_arguments.
Returns
-------
in_type : li... | [
"def",
"infer_type",
"(",
"self",
",",
"in_type",
")",
":",
"return",
"in_type",
",",
"[",
"in_type",
"[",
"0",
"]",
"]",
"*",
"len",
"(",
"self",
".",
"list_outputs",
"(",
")",
")",
",",
"[",
"in_type",
"[",
"0",
"]",
"]",
"*",
"len",
"(",
"se... | infer_type interface. override to create new operators
Parameters
----------
in_type : list of np.dtype
list of argument types in the same order as
declared in list_arguments.
Returns
-------
in_type : list
list of argument types. Can... | [
"infer_type",
"interface",
".",
"override",
"to",
"create",
"new",
"operators"
] | python | train |
mozilla/treeherder | treeherder/seta/job_priorities.py | https://github.com/mozilla/treeherder/blob/cc47bdec872e5c668d0f01df89517390a164cda3/treeherder/seta/job_priorities.py#L27-L56 | def _process(self, project, build_system, job_priorities):
'''Return list of ref_data_name for job_priorities'''
jobs = []
# we cache the reference data names in order to reduce API calls
cache_key = '{}-{}-ref_data_names_cache'.format(project, build_system)
ref_data_names_map =... | [
"def",
"_process",
"(",
"self",
",",
"project",
",",
"build_system",
",",
"job_priorities",
")",
":",
"jobs",
"=",
"[",
"]",
"# we cache the reference data names in order to reduce API calls",
"cache_key",
"=",
"'{}-{}-ref_data_names_cache'",
".",
"format",
"(",
"projec... | Return list of ref_data_name for job_priorities | [
"Return",
"list",
"of",
"ref_data_name",
"for",
"job_priorities"
] | python | train |
linode/linode_api4-python | linode_api4/objects/linode.py | https://github.com/linode/linode_api4-python/blob/1dd7318d2aed014c746d48c7957464c57af883ca/linode_api4/objects/linode.py#L643-L648 | def initiate_migration(self):
"""
Initiates a pending migration that is already scheduled for this Linode
Instance
"""
self._client.post('{}/migrate'.format(Instance.api_endpoint), model=self) | [
"def",
"initiate_migration",
"(",
"self",
")",
":",
"self",
".",
"_client",
".",
"post",
"(",
"'{}/migrate'",
".",
"format",
"(",
"Instance",
".",
"api_endpoint",
")",
",",
"model",
"=",
"self",
")"
] | Initiates a pending migration that is already scheduled for this Linode
Instance | [
"Initiates",
"a",
"pending",
"migration",
"that",
"is",
"already",
"scheduled",
"for",
"this",
"Linode",
"Instance"
] | python | train |
marcotcr/lime | lime/lime_text.py | https://github.com/marcotcr/lime/blob/08133d47df00ed918e22005e0c98f6eefd5a1d71/lime/lime_text.py#L356-L418 | def explain_instance(self,
text_instance,
classifier_fn,
labels=(1,),
top_labels=None,
num_features=10,
num_samples=5000,
distance_metric='cosine... | [
"def",
"explain_instance",
"(",
"self",
",",
"text_instance",
",",
"classifier_fn",
",",
"labels",
"=",
"(",
"1",
",",
")",
",",
"top_labels",
"=",
"None",
",",
"num_features",
"=",
"10",
",",
"num_samples",
"=",
"5000",
",",
"distance_metric",
"=",
"'cosi... | Generates explanations for a prediction.
First, we generate neighborhood data by randomly hiding features from
the instance (see __data_labels_distance_mapping). We then learn
locally weighted linear models on this neighborhood data to explain
each of the classes in an interpretable way... | [
"Generates",
"explanations",
"for",
"a",
"prediction",
"."
] | python | train |
raiden-network/raiden | raiden/network/proxies/utils.py | https://github.com/raiden-network/raiden/blob/407ba15c72074e9de88771d6b9661ff4dc36bef5/raiden/network/proxies/utils.py#L16-L42 | def compare_contract_versions(
proxy: ContractProxy,
expected_version: str,
contract_name: str,
address: Address,
) -> None:
"""Compare version strings of a contract.
If not matching raise ContractVersionMismatch. Also may raise AddressWrongContract
if the contract contains ... | [
"def",
"compare_contract_versions",
"(",
"proxy",
":",
"ContractProxy",
",",
"expected_version",
":",
"str",
",",
"contract_name",
":",
"str",
",",
"address",
":",
"Address",
",",
")",
"->",
"None",
":",
"assert",
"isinstance",
"(",
"expected_version",
",",
"s... | Compare version strings of a contract.
If not matching raise ContractVersionMismatch. Also may raise AddressWrongContract
if the contract contains no code. | [
"Compare",
"version",
"strings",
"of",
"a",
"contract",
"."
] | python | train |
wonambi-python/wonambi | wonambi/detect/spindle.py | https://github.com/wonambi-python/wonambi/blob/1d8e3d7e53df8017c199f703bcab582914676e76/wonambi/detect/spindle.py#L1728-L1751 | def remove_straddlers(events, time, s_freq, toler=0.1):
"""Reject an event if it straddles a stitch, by comparing its
duration to its timespan.
Parameters
----------
events : ndarray (dtype='int')
N x M matrix with start, ..., end samples
time : ndarray (dtype='float')
vector w... | [
"def",
"remove_straddlers",
"(",
"events",
",",
"time",
",",
"s_freq",
",",
"toler",
"=",
"0.1",
")",
":",
"dur",
"=",
"(",
"events",
"[",
":",
",",
"-",
"1",
"]",
"-",
"1",
"-",
"events",
"[",
":",
",",
"0",
"]",
")",
"/",
"s_freq",
"continuou... | Reject an event if it straddles a stitch, by comparing its
duration to its timespan.
Parameters
----------
events : ndarray (dtype='int')
N x M matrix with start, ..., end samples
time : ndarray (dtype='float')
vector with time points
s_freq : float
sampling frequency
... | [
"Reject",
"an",
"event",
"if",
"it",
"straddles",
"a",
"stitch",
"by",
"comparing",
"its",
"duration",
"to",
"its",
"timespan",
"."
] | python | train |
F5Networks/f5-common-python | f5/utils/iapp_parser.py | https://github.com/F5Networks/f5-common-python/blob/7e67d5acd757a60e3d5f8c88c534bd72208f5494/f5/utils/iapp_parser.py#L200-L230 | def _add_cli_scripts(self):
'''Add the found external sections to the templ_dict.'''
pattern = r"cli script\s+" \
r"(\/[\w\.\-]+\/)?" \
r"(?P<name>[\w\.\-]+)\s*\{"
sections = re.finditer(pattern, self.template_str)
for section in sections:
... | [
"def",
"_add_cli_scripts",
"(",
"self",
")",
":",
"pattern",
"=",
"r\"cli script\\s+\"",
"r\"(\\/[\\w\\.\\-]+\\/)?\"",
"r\"(?P<name>[\\w\\.\\-]+)\\s*\\{\"",
"sections",
"=",
"re",
".",
"finditer",
"(",
"pattern",
",",
"self",
".",
"template_str",
")",
"for",
"section"... | Add the found external sections to the templ_dict. | [
"Add",
"the",
"found",
"external",
"sections",
"to",
"the",
"templ_dict",
"."
] | python | train |
ska-sa/katcp-python | katcp/resource_client.py | https://github.com/ska-sa/katcp-python/blob/9127c826a1d030c53b84d0e95743e20e5c5ea153/katcp/resource_client.py#L549-L582 | def set_sensor_listener(self, sensor_name, listener):
"""Set a sensor listener for a sensor even if it is not yet known
The listener registration should persist across sensor disconnect/reconnect.
sensor_name : str
Name of the sensor
listener : callable
Listening... | [
"def",
"set_sensor_listener",
"(",
"self",
",",
"sensor_name",
",",
"listener",
")",
":",
"sensor_name",
"=",
"resource",
".",
"escape_name",
"(",
"sensor_name",
")",
"sensor_obj",
"=",
"dict",
".",
"get",
"(",
"self",
".",
"_sensor",
",",
"sensor_name",
")"... | Set a sensor listener for a sensor even if it is not yet known
The listener registration should persist across sensor disconnect/reconnect.
sensor_name : str
Name of the sensor
listener : callable
Listening callable that will be registered on the named sensor when it bec... | [
"Set",
"a",
"sensor",
"listener",
"for",
"a",
"sensor",
"even",
"if",
"it",
"is",
"not",
"yet",
"known",
"The",
"listener",
"registration",
"should",
"persist",
"across",
"sensor",
"disconnect",
"/",
"reconnect",
"."
] | python | train |
aiortc/pylibsrtp | pylibsrtp/__init__.py | https://github.com/aiortc/pylibsrtp/blob/31824d1f8430ff6dc217cfc101093b6ba2a307b2/pylibsrtp/__init__.py#L167-L174 | def add_stream(self, policy):
"""
Add a stream to the SRTP session, applying the given `policy`
to the stream.
:param policy: :class:`Policy`
"""
_srtp_assert(lib.srtp_add_stream(self._srtp[0], policy._policy)) | [
"def",
"add_stream",
"(",
"self",
",",
"policy",
")",
":",
"_srtp_assert",
"(",
"lib",
".",
"srtp_add_stream",
"(",
"self",
".",
"_srtp",
"[",
"0",
"]",
",",
"policy",
".",
"_policy",
")",
")"
] | Add a stream to the SRTP session, applying the given `policy`
to the stream.
:param policy: :class:`Policy` | [
"Add",
"a",
"stream",
"to",
"the",
"SRTP",
"session",
"applying",
"the",
"given",
"policy",
"to",
"the",
"stream",
"."
] | python | train |
fastai/fastai | fastai/data_block.py | https://github.com/fastai/fastai/blob/9fb84a5cdefe5a766cdb792b8f5d8971737b7e67/fastai/data_block.py#L113-L118 | def from_folder(cls, path:PathOrStr, extensions:Collection[str]=None, recurse:bool=True,
include:Optional[Collection[str]]=None, processor:PreProcessors=None, **kwargs)->'ItemList':
"""Create an `ItemList` in `path` from the filenames that have a suffix in `extensions`.
`recurse` det... | [
"def",
"from_folder",
"(",
"cls",
",",
"path",
":",
"PathOrStr",
",",
"extensions",
":",
"Collection",
"[",
"str",
"]",
"=",
"None",
",",
"recurse",
":",
"bool",
"=",
"True",
",",
"include",
":",
"Optional",
"[",
"Collection",
"[",
"str",
"]",
"]",
"... | Create an `ItemList` in `path` from the filenames that have a suffix in `extensions`.
`recurse` determines if we search subfolders. | [
"Create",
"an",
"ItemList",
"in",
"path",
"from",
"the",
"filenames",
"that",
"have",
"a",
"suffix",
"in",
"extensions",
".",
"recurse",
"determines",
"if",
"we",
"search",
"subfolders",
"."
] | python | train |
hadrianl/huobi | huobitrade/utils.py | https://github.com/hadrianl/huobi/blob/bbfa2036703ee84a76d5d8e9f89c25fc8a55f2c7/huobitrade/utils.py#L211-L241 | def http_post_request(url, params, add_to_headers=None, _async=False):
"""
from 火币demo, post方法
:param url:
:param params:
:param add_to_headers:
:return:
"""
headers = {
"Accept": "application/json",
'Content-Type': 'application/json'
}
if add_to_headers:
... | [
"def",
"http_post_request",
"(",
"url",
",",
"params",
",",
"add_to_headers",
"=",
"None",
",",
"_async",
"=",
"False",
")",
":",
"headers",
"=",
"{",
"\"Accept\"",
":",
"\"application/json\"",
",",
"'Content-Type'",
":",
"'application/json'",
"}",
"if",
"add_... | from 火币demo, post方法
:param url:
:param params:
:param add_to_headers:
:return: | [
"from",
"火币demo",
"post方法",
":",
"param",
"url",
":",
":",
"param",
"params",
":",
":",
"param",
"add_to_headers",
":",
":",
"return",
":"
] | python | train |
taizilongxu/douban.fm | doubanfm/API/api.py | https://github.com/taizilongxu/douban.fm/blob/d65126d3bd3e12d8a7109137caff8da0efc22b2f/doubanfm/API/api.py#L229-L268 | def get_lrc(self, playingsong):
"""
获取歌词
如果测试频繁会发如下信息:
{'msg': 'You API access rate limit has been exceeded.
Contact api-master@douban.com if you want higher limit. ',
'code': 1998,
'request': 'GET /j/v2/lyric'}
"""
try:
url... | [
"def",
"get_lrc",
"(",
"self",
",",
"playingsong",
")",
":",
"try",
":",
"url",
"=",
"\"https://douban.fm/j/v2/lyric\"",
"postdata",
"=",
"{",
"'sid'",
":",
"playingsong",
"[",
"'sid'",
"]",
",",
"'ssid'",
":",
"playingsong",
"[",
"'ssid'",
"]",
",",
"}",
... | 获取歌词
如果测试频繁会发如下信息:
{'msg': 'You API access rate limit has been exceeded.
Contact api-master@douban.com if you want higher limit. ',
'code': 1998,
'request': 'GET /j/v2/lyric'} | [
"获取歌词"
] | python | train |
inasafe/inasafe | safe/report/expressions/infographic.py | https://github.com/inasafe/inasafe/blob/831d60abba919f6d481dc94a8d988cc205130724/safe/report/expressions/infographic.py#L317-L323 | def additional_minimum_needs_section_header_element(feature, parent):
"""Retrieve additional minimum needs section header string
from definitions.
"""
_ = feature, parent # NOQA
header = additional_minimum_needs_section_header['string_format']
return header.capitalize() | [
"def",
"additional_minimum_needs_section_header_element",
"(",
"feature",
",",
"parent",
")",
":",
"_",
"=",
"feature",
",",
"parent",
"# NOQA",
"header",
"=",
"additional_minimum_needs_section_header",
"[",
"'string_format'",
"]",
"return",
"header",
".",
"capitalize",... | Retrieve additional minimum needs section header string
from definitions. | [
"Retrieve",
"additional",
"minimum",
"needs",
"section",
"header",
"string",
"from",
"definitions",
"."
] | python | train |
croscon/fleaker | fleaker/logging.py | https://github.com/croscon/fleaker/blob/046b026b79c9912bceebb17114bc0c5d2d02e3c7/fleaker/logging.py#L59-L70 | def format(self, record):
"""Format the log record."""
levelname = getattr(record, 'levelname', None)
record.levelcolor = ''
record.endlevelcolor = ''
if levelname:
level_color = getattr(self.TermColors, levelname, '')
record.levelcolor = level_color
... | [
"def",
"format",
"(",
"self",
",",
"record",
")",
":",
"levelname",
"=",
"getattr",
"(",
"record",
",",
"'levelname'",
",",
"None",
")",
"record",
".",
"levelcolor",
"=",
"''",
"record",
".",
"endlevelcolor",
"=",
"''",
"if",
"levelname",
":",
"level_col... | Format the log record. | [
"Format",
"the",
"log",
"record",
"."
] | python | train |
pypa/pipenv | pipenv/vendor/distlib/util.py | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/distlib/util.py#L1698-L1704 | def inc_convert(self, value):
"""Default converter for the inc:// protocol."""
if not os.path.isabs(value):
value = os.path.join(self.base, value)
with codecs.open(value, 'r', encoding='utf-8') as f:
result = json.load(f)
return result | [
"def",
"inc_convert",
"(",
"self",
",",
"value",
")",
":",
"if",
"not",
"os",
".",
"path",
".",
"isabs",
"(",
"value",
")",
":",
"value",
"=",
"os",
".",
"path",
".",
"join",
"(",
"self",
".",
"base",
",",
"value",
")",
"with",
"codecs",
".",
"... | Default converter for the inc:// protocol. | [
"Default",
"converter",
"for",
"the",
"inc",
":",
"//",
"protocol",
"."
] | python | train |
dnanexus/dx-toolkit | src/python/dxpy/bindings/search.py | https://github.com/dnanexus/dx-toolkit/blob/74befb53ad90fcf902d8983ae6d74580f402d619/src/python/dxpy/bindings/search.py#L719-L736 | def find_one_app(zero_ok=False, more_ok=True, **kwargs):
"""
:param zero_ok:
If False (default), :class:`~dxpy.exceptions.DXSearchError` is
raised if the search has 0 results; if True, returns None if the
search has 0 results
:type zero_ok: bool
:param more_ok:
If False, ... | [
"def",
"find_one_app",
"(",
"zero_ok",
"=",
"False",
",",
"more_ok",
"=",
"True",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"_find_one",
"(",
"find_apps",
",",
"zero_ok",
"=",
"zero_ok",
",",
"more_ok",
"=",
"more_ok",
",",
"*",
"*",
"kwargs",
")"
] | :param zero_ok:
If False (default), :class:`~dxpy.exceptions.DXSearchError` is
raised if the search has 0 results; if True, returns None if the
search has 0 results
:type zero_ok: bool
:param more_ok:
If False, :class:`~dxpy.exceptions.DXSearchError` is raised if
the sear... | [
":",
"param",
"zero_ok",
":",
"If",
"False",
"(",
"default",
")",
":",
"class",
":",
"~dxpy",
".",
"exceptions",
".",
"DXSearchError",
"is",
"raised",
"if",
"the",
"search",
"has",
"0",
"results",
";",
"if",
"True",
"returns",
"None",
"if",
"the",
"sea... | python | train |
openstack/quark | quark/plugin_modules/floating_ips.py | https://github.com/openstack/quark/blob/1112e6a66917d3e98e44cb7b33b107fd5a74bb2e/quark/plugin_modules/floating_ips.py#L610-L635 | def get_scalingips(context, filters=None, fields=None, sorts=['id'],
limit=None, marker=None, page_reverse=False):
"""Retrieve a list of scaling ips.
:param context: neutron api request context.
:param filters: a dictionary with keys that are valid keys for
a scaling ip as listed... | [
"def",
"get_scalingips",
"(",
"context",
",",
"filters",
"=",
"None",
",",
"fields",
"=",
"None",
",",
"sorts",
"=",
"[",
"'id'",
"]",
",",
"limit",
"=",
"None",
",",
"marker",
"=",
"None",
",",
"page_reverse",
"=",
"False",
")",
":",
"LOG",
".",
"... | Retrieve a list of scaling ips.
:param context: neutron api request context.
:param filters: a dictionary with keys that are valid keys for
a scaling ip as listed in the RESOURCE_ATTRIBUTE_MAP object
in neutron/api/v2/attributes.py. Values in this dictionary
are an iterable containing ... | [
"Retrieve",
"a",
"list",
"of",
"scaling",
"ips",
"."
] | python | valid |
mjirik/imtools | imtools/select_label_qt.py | https://github.com/mjirik/imtools/blob/eb29fa59df0e0684d8334eb3bc5ef36ea46d1d3a/imtools/select_label_qt.py#L47-L67 | def init_slab(self, slab=None, segmentation=None, voxelsize_mm=None, show_ok_button=False):
"""
Create widget with segmentation labels information used to select labels.
:param slab: dict with label name and its id
:param segmentation: 3D label ndarray
:param voxelsize_mm: size ... | [
"def",
"init_slab",
"(",
"self",
",",
"slab",
"=",
"None",
",",
"segmentation",
"=",
"None",
",",
"voxelsize_mm",
"=",
"None",
",",
"show_ok_button",
"=",
"False",
")",
":",
"self",
".",
"segmentation",
"=",
"segmentation",
"self",
".",
"voxelsize_mm",
"="... | Create widget with segmentation labels information used to select labels.
:param slab: dict with label name and its id
:param segmentation: 3D label ndarray
:param voxelsize_mm: size of voxel in mm
:return: | [
"Create",
"widget",
"with",
"segmentation",
"labels",
"information",
"used",
"to",
"select",
"labels",
"."
] | python | train |
allenai/allennlp | allennlp/semparse/contexts/atis_tables.py | https://github.com/allenai/allennlp/blob/648a36f77db7e45784c047176074f98534c76636/allennlp/semparse/contexts/atis_tables.py#L128-L170 | def get_numbers_from_utterance(utterance: str, tokenized_utterance: List[Token]) -> Dict[str, List[int]]:
"""
Given an utterance, this function finds all the numbers that are in the action space. Since we need to
keep track of linking scores, we represent the numbers as a dictionary, where the keys are the ... | [
"def",
"get_numbers_from_utterance",
"(",
"utterance",
":",
"str",
",",
"tokenized_utterance",
":",
"List",
"[",
"Token",
"]",
")",
"->",
"Dict",
"[",
"str",
",",
"List",
"[",
"int",
"]",
"]",
":",
"# When we use a regex to find numbers or strings, we need a mapping... | Given an utterance, this function finds all the numbers that are in the action space. Since we need to
keep track of linking scores, we represent the numbers as a dictionary, where the keys are the string
representation of the number and the values are lists of the token indices that triggers that number. | [
"Given",
"an",
"utterance",
"this",
"function",
"finds",
"all",
"the",
"numbers",
"that",
"are",
"in",
"the",
"action",
"space",
".",
"Since",
"we",
"need",
"to",
"keep",
"track",
"of",
"linking",
"scores",
"we",
"represent",
"the",
"numbers",
"as",
"a",
... | python | train |
bernardopires/django-tenant-schemas | tenant_schemas/postgresql_backend/base.py | https://github.com/bernardopires/django-tenant-schemas/blob/75faf00834e1fb7ed017949bfb54531f6329a8dd/tenant_schemas/postgresql_backend/base.py#L66-L72 | def set_tenant(self, tenant, include_public=True):
"""
Main API method to current database schema,
but it does not actually modify the db connection.
"""
self.set_schema(tenant.schema_name, include_public)
self.tenant = tenant | [
"def",
"set_tenant",
"(",
"self",
",",
"tenant",
",",
"include_public",
"=",
"True",
")",
":",
"self",
".",
"set_schema",
"(",
"tenant",
".",
"schema_name",
",",
"include_public",
")",
"self",
".",
"tenant",
"=",
"tenant"
] | Main API method to current database schema,
but it does not actually modify the db connection. | [
"Main",
"API",
"method",
"to",
"current",
"database",
"schema",
"but",
"it",
"does",
"not",
"actually",
"modify",
"the",
"db",
"connection",
"."
] | python | train |
tritemio/PyBroMo | pybromo/iter_chunks.py | https://github.com/tritemio/PyBroMo/blob/b75f82a4551ff37e7c7a7e6954c536451f3e6d06/pybromo/iter_chunks.py#L42-L51 | def iter_chunk_index(num_samples, chunksize):
"""Iterator used to iterate in chunks over an array of size `num_samples`.
At each iteration returns a start and stop index for a slice of size
`chunksize`. In the last iteration the slice may be smaller.
"""
i = 0
for c_size in iter_chunksize(num_s... | [
"def",
"iter_chunk_index",
"(",
"num_samples",
",",
"chunksize",
")",
":",
"i",
"=",
"0",
"for",
"c_size",
"in",
"iter_chunksize",
"(",
"num_samples",
",",
"chunksize",
")",
":",
"yield",
"i",
",",
"i",
"+",
"c_size",
"i",
"+=",
"c_size"
] | Iterator used to iterate in chunks over an array of size `num_samples`.
At each iteration returns a start and stop index for a slice of size
`chunksize`. In the last iteration the slice may be smaller. | [
"Iterator",
"used",
"to",
"iterate",
"in",
"chunks",
"over",
"an",
"array",
"of",
"size",
"num_samples",
"."
] | python | valid |
limpyd/redis-limpyd | limpyd/fields.py | https://github.com/limpyd/redis-limpyd/blob/3c745dde1390a0bd09690b77a089dcc08c6c7e43/limpyd/fields.py#L640-L647 | def _del(self, command, *args, **kwargs):
"""
Shortcut for commands that remove all values of the field.
All will be deindexed.
"""
if self.indexable:
self.deindex()
return self._traverse_command(command, *args, **kwargs) | [
"def",
"_del",
"(",
"self",
",",
"command",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"self",
".",
"indexable",
":",
"self",
".",
"deindex",
"(",
")",
"return",
"self",
".",
"_traverse_command",
"(",
"command",
",",
"*",
"args",
",... | Shortcut for commands that remove all values of the field.
All will be deindexed. | [
"Shortcut",
"for",
"commands",
"that",
"remove",
"all",
"values",
"of",
"the",
"field",
".",
"All",
"will",
"be",
"deindexed",
"."
] | python | train |
FlaskGuys/Flask-Imagine | flask_imagine/filters/thumbnail.py | https://github.com/FlaskGuys/Flask-Imagine/blob/f79c6517ecb5480b63a2b3b8554edb6e2ac8be8c/flask_imagine/filters/thumbnail.py#L96-L118 | def outbound_sizes(cls, original_width, original_height, target_width, target_height):
"""
Calculate new image sizes for outbound mode
:param original_width: int
:param original_height: int
:param target_width: int
:param target_height: int
:return: tuple(int, int... | [
"def",
"outbound_sizes",
"(",
"cls",
",",
"original_width",
",",
"original_height",
",",
"target_width",
",",
"target_height",
")",
":",
"if",
"target_width",
"<=",
"original_width",
"and",
"target_height",
"<=",
"original_height",
":",
"k",
"=",
"original_width",
... | Calculate new image sizes for outbound mode
:param original_width: int
:param original_height: int
:param target_width: int
:param target_height: int
:return: tuple(int, int) | [
"Calculate",
"new",
"image",
"sizes",
"for",
"outbound",
"mode",
":",
"param",
"original_width",
":",
"int",
":",
"param",
"original_height",
":",
"int",
":",
"param",
"target_width",
":",
"int",
":",
"param",
"target_height",
":",
"int",
":",
"return",
":",... | python | train |
SoftwareDefinedBuildings/XBOS | apps/data_analysis/XBOS_data_analytics/Import_Data.py | https://github.com/SoftwareDefinedBuildings/XBOS/blob/c12d4fb14518ea3ae98c471c28e0710fdf74dd25/apps/data_analysis/XBOS_data_analytics/Import_Data.py#L193-L318 | def get_weather_power_tstat(self, site, start, end, data_type=['weather', 'power']):
""" Get weather and power data.
Parameters
----------
site : str
Site name.
start : str
Start date.
end : str
End date.
d... | [
"def",
"get_weather_power_tstat",
"(",
"self",
",",
"site",
",",
"start",
",",
"end",
",",
"data_type",
"=",
"[",
"'weather'",
",",
"'power'",
"]",
")",
":",
"m",
"=",
"dataclient",
".",
"MDALClient",
"(",
"\"corbusier.cs.berkeley.edu:8088\"",
")",
"request",
... | Get weather and power data.
Parameters
----------
site : str
Site name.
start : str
Start date.
end : str
End date.
data_type : str
Type of data needed (all, weather, power, temperature, hsp, csp) | [
"Get",
"weather",
"and",
"power",
"data",
"."
] | python | train |
syndbg/demonoid-api | demonoid/urls.py | https://github.com/syndbg/demonoid-api/blob/518aa389ac91b5243b92fc19923103f31041a61e/demonoid/urls.py#L112-L122 | def fetch(self):
"""
Makes a request to combined url with `self._params` as parameters.
If the server at combined url responds with Client or Server error, raises an exception.
:return: the response from combined url
:rtype: requests.models.Response
"""
response ... | [
"def",
"fetch",
"(",
"self",
")",
":",
"response",
"=",
"self",
".",
"_session",
".",
"get",
"(",
"self",
".",
"url",
",",
"params",
"=",
"self",
".",
"params",
")",
"response",
".",
"raise_for_status",
"(",
")",
"return",
"response"
] | Makes a request to combined url with `self._params` as parameters.
If the server at combined url responds with Client or Server error, raises an exception.
:return: the response from combined url
:rtype: requests.models.Response | [
"Makes",
"a",
"request",
"to",
"combined",
"url",
"with",
"self",
".",
"_params",
"as",
"parameters",
".",
"If",
"the",
"server",
"at",
"combined",
"url",
"responds",
"with",
"Client",
"or",
"Server",
"error",
"raises",
"an",
"exception",
"."
] | python | train |
Esri/ArcREST | src/arcrest/manageorg/_community.py | https://github.com/Esri/ArcREST/blob/ab240fde2b0200f61d4a5f6df033516e53f2f416/src/arcrest/manageorg/_community.py#L399-L408 | def group(self, groupId):
"""
gets a group based on it's ID
"""
url = "%s/%s" % (self.root, groupId)
return Group(url=url,
securityHandler=self._securityHandler,
proxy_url=self._proxy_url,
proxy_port=self._proxy_port,... | [
"def",
"group",
"(",
"self",
",",
"groupId",
")",
":",
"url",
"=",
"\"%s/%s\"",
"%",
"(",
"self",
".",
"root",
",",
"groupId",
")",
"return",
"Group",
"(",
"url",
"=",
"url",
",",
"securityHandler",
"=",
"self",
".",
"_securityHandler",
",",
"proxy_url... | gets a group based on it's ID | [
"gets",
"a",
"group",
"based",
"on",
"it",
"s",
"ID"
] | python | train |
bodylabs/lace | lace/geometry.py | https://github.com/bodylabs/lace/blob/b68f4a60a4cac66c0607ffbae38ef9d07d37f459/lace/geometry.py#L206-L233 | def cut_across_axis(self, dim, minval=None, maxval=None):
'''
Cut the mesh by a plane, discarding vertices that lie behind that
plane. Or cut the mesh by two parallel planes, discarding vertices
that lie outside them.
The region to keep is defined by an axis of perpendicularity,... | [
"def",
"cut_across_axis",
"(",
"self",
",",
"dim",
",",
"minval",
"=",
"None",
",",
"maxval",
"=",
"None",
")",
":",
"# vertex_mask keeps track of the vertices we want to keep.",
"vertex_mask",
"=",
"np",
".",
"ones",
"(",
"(",
"len",
"(",
"self",
".",
"v",
... | Cut the mesh by a plane, discarding vertices that lie behind that
plane. Or cut the mesh by two parallel planes, discarding vertices
that lie outside them.
The region to keep is defined by an axis of perpendicularity,
specified by `dim`: 0 means x, 1 means y, 2 means z. `minval`
... | [
"Cut",
"the",
"mesh",
"by",
"a",
"plane",
"discarding",
"vertices",
"that",
"lie",
"behind",
"that",
"plane",
".",
"Or",
"cut",
"the",
"mesh",
"by",
"two",
"parallel",
"planes",
"discarding",
"vertices",
"that",
"lie",
"outside",
"them",
"."
] | python | train |
PmagPy/PmagPy | dialogs/grid_frame3.py | https://github.com/PmagPy/PmagPy/blob/c7984f8809bf40fe112e53dcc311a33293b62d0b/dialogs/grid_frame3.py#L884-L894 | def onCopySelection(self, event):
"""
Copies self.df_slice to the Clipboard if slice exists
"""
if self.df_slice is not None:
pd.DataFrame.to_clipboard(self.df_slice, header=False, index=False)
self.grid.ClearSelection()
self.df_slice = None
... | [
"def",
"onCopySelection",
"(",
"self",
",",
"event",
")",
":",
"if",
"self",
".",
"df_slice",
"is",
"not",
"None",
":",
"pd",
".",
"DataFrame",
".",
"to_clipboard",
"(",
"self",
".",
"df_slice",
",",
"header",
"=",
"False",
",",
"index",
"=",
"False",
... | Copies self.df_slice to the Clipboard if slice exists | [
"Copies",
"self",
".",
"df_slice",
"to",
"the",
"Clipboard",
"if",
"slice",
"exists"
] | python | train |
napalm-automation/napalm-logs | napalm_logs/listener_proc.py | https://github.com/napalm-automation/napalm-logs/blob/4b89100a6e4f994aa004f3ea42a06dc803a7ccb0/napalm_logs/listener_proc.py#L62-L76 | def _setup_ipc(self):
'''
Setup the listener ICP pusher.
'''
log.debug('Setting up the listener IPC pusher')
self.ctx = zmq.Context()
self.pub = self.ctx.socket(zmq.PUSH)
self.pub.connect(LST_IPC_URL)
log.debug('Setting HWM for the listener: %d', self.opts... | [
"def",
"_setup_ipc",
"(",
"self",
")",
":",
"log",
".",
"debug",
"(",
"'Setting up the listener IPC pusher'",
")",
"self",
".",
"ctx",
"=",
"zmq",
".",
"Context",
"(",
")",
"self",
".",
"pub",
"=",
"self",
".",
"ctx",
".",
"socket",
"(",
"zmq",
".",
... | Setup the listener ICP pusher. | [
"Setup",
"the",
"listener",
"ICP",
"pusher",
"."
] | python | train |
phaethon/kamene | kamene/contrib/gsm_um.py | https://github.com/phaethon/kamene/blob/11d4064844f4f68ac5d7546f5633ac7d02082914/kamene/contrib/gsm_um.py#L2485-L2490 | def authenticationAndCipheringReject():
"""AUTHENTICATION AND CIPHERING REJECT Section 9.4.11"""
a = TpPd(pd=0x3)
b = MessageType(mesType=0x14) # 00010100
packet = a / b
return packet | [
"def",
"authenticationAndCipheringReject",
"(",
")",
":",
"a",
"=",
"TpPd",
"(",
"pd",
"=",
"0x3",
")",
"b",
"=",
"MessageType",
"(",
"mesType",
"=",
"0x14",
")",
"# 00010100",
"packet",
"=",
"a",
"/",
"b",
"return",
"packet"
] | AUTHENTICATION AND CIPHERING REJECT Section 9.4.11 | [
"AUTHENTICATION",
"AND",
"CIPHERING",
"REJECT",
"Section",
"9",
".",
"4",
".",
"11"
] | python | train |
xsleonard/pystmark | pystmark.py | https://github.com/xsleonard/pystmark/blob/329ccae1a7c8d57f28fa72cd8dbbee3e39413ed6/pystmark.py#L1108-L1124 | def send(self, messages=None, api_key=None, secure=None, test=None,
**request_args):
'''Send batch request to Postmark API.
Returns result of :func:`requests.post`.
:param messages: Batch messages to send to the Postmark API.
:type messages: A list of :class:`Message`
... | [
"def",
"send",
"(",
"self",
",",
"messages",
"=",
"None",
",",
"api_key",
"=",
"None",
",",
"secure",
"=",
"None",
",",
"test",
"=",
"None",
",",
"*",
"*",
"request_args",
")",
":",
"return",
"super",
"(",
"BatchSender",
",",
"self",
")",
".",
"sen... | Send batch request to Postmark API.
Returns result of :func:`requests.post`.
:param messages: Batch messages to send to the Postmark API.
:type messages: A list of :class:`Message`
:param api_key: Your Postmark API key. Defaults to `self.api_key`.
:param test: Make a test reques... | [
"Send",
"batch",
"request",
"to",
"Postmark",
"API",
".",
"Returns",
"result",
"of",
":",
"func",
":",
"requests",
".",
"post",
"."
] | python | train |
relekang/python-semantic-release | semantic_release/cli.py | https://github.com/relekang/python-semantic-release/blob/76123f410180599a19e7c48da413880185bbea20/semantic_release/cli.py#L132-L188 | def publish(**kwargs):
"""
Runs the version task before pushing to git and uploading to pypi.
"""
current_version = get_current_version()
click.echo('Current version: {0}'.format(current_version))
retry = kwargs.get("retry")
debug('publish: retry=', retry)
if retry:
# The "new" ... | [
"def",
"publish",
"(",
"*",
"*",
"kwargs",
")",
":",
"current_version",
"=",
"get_current_version",
"(",
")",
"click",
".",
"echo",
"(",
"'Current version: {0}'",
".",
"format",
"(",
"current_version",
")",
")",
"retry",
"=",
"kwargs",
".",
"get",
"(",
"\"... | Runs the version task before pushing to git and uploading to pypi. | [
"Runs",
"the",
"version",
"task",
"before",
"pushing",
"to",
"git",
"and",
"uploading",
"to",
"pypi",
"."
] | python | train |
phoebe-project/phoebe2 | phoebe/parameters/parameters.py | https://github.com/phoebe-project/phoebe2/blob/e64b8be683977064e2d55dd1b3ac400f64c3e379/phoebe/parameters/parameters.py#L211-L224 | def update_if_client(fctn):
"""Intercept and check updates from server if bundle is in client mode."""
@functools.wraps(fctn)
def _update_if_client(self, *args, **kwargs):
b = self._bundle
if b is None or not hasattr(b, 'is_client'):
return fctn(self, *args, **kwargs)
eli... | [
"def",
"update_if_client",
"(",
"fctn",
")",
":",
"@",
"functools",
".",
"wraps",
"(",
"fctn",
")",
"def",
"_update_if_client",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"b",
"=",
"self",
".",
"_bundle",
"if",
"b",
"is",
"No... | Intercept and check updates from server if bundle is in client mode. | [
"Intercept",
"and",
"check",
"updates",
"from",
"server",
"if",
"bundle",
"is",
"in",
"client",
"mode",
"."
] | python | train |
ResidentMario/missingno | missingno/missingno.py | https://github.com/ResidentMario/missingno/blob/1d67f91fbab0695a919c6bb72c796db57024e0ca/missingno/missingno.py#L195-L263 | def bar(df, figsize=(24, 10), fontsize=16, labels=None, log=False, color='dimgray', inline=False,
filter=None, n=0, p=0, sort=None):
"""
A bar chart visualization of the nullity of the given DataFrame.
:param df: The input DataFrame.
:param log: Whether or not to display a logorithmic plot. Def... | [
"def",
"bar",
"(",
"df",
",",
"figsize",
"=",
"(",
"24",
",",
"10",
")",
",",
"fontsize",
"=",
"16",
",",
"labels",
"=",
"None",
",",
"log",
"=",
"False",
",",
"color",
"=",
"'dimgray'",
",",
"inline",
"=",
"False",
",",
"filter",
"=",
"None",
... | A bar chart visualization of the nullity of the given DataFrame.
:param df: The input DataFrame.
:param log: Whether or not to display a logorithmic plot. Defaults to False (linear).
:param filter: The filter to apply to the heatmap. Should be one of "top", "bottom", or None (default).
:param n: The ca... | [
"A",
"bar",
"chart",
"visualization",
"of",
"the",
"nullity",
"of",
"the",
"given",
"DataFrame",
"."
] | python | train |
sorgerlab/indra | indra/literature/deft_tools.py | https://github.com/sorgerlab/indra/blob/79a70415832c5702d7a820c7c9ccc8e25010124b/indra/literature/deft_tools.py#L87-L114 | def universal_extract_paragraphs(xml):
"""Extract paragraphs from xml that could be from different sources
First try to parse the xml as if it came from elsevier. if we do not
have valid elsevier xml this will throw an exception. the text extraction
function in the pmc client may not throw an exceptio... | [
"def",
"universal_extract_paragraphs",
"(",
"xml",
")",
":",
"try",
":",
"paragraphs",
"=",
"elsevier_client",
".",
"extract_paragraphs",
"(",
"xml",
")",
"except",
"Exception",
":",
"paragraphs",
"=",
"None",
"if",
"paragraphs",
"is",
"None",
":",
"try",
":",... | Extract paragraphs from xml that could be from different sources
First try to parse the xml as if it came from elsevier. if we do not
have valid elsevier xml this will throw an exception. the text extraction
function in the pmc client may not throw an exception when parsing elsevier
xml, silently proc... | [
"Extract",
"paragraphs",
"from",
"xml",
"that",
"could",
"be",
"from",
"different",
"sources"
] | python | train |
enkore/i3pystatus | i3pystatus/core/util.py | https://github.com/enkore/i3pystatus/blob/14cfde967cecf79b40e223e35a04600f4c875af7/i3pystatus/core/util.py#L673-L698 | def get_module(function):
"""Function decorator for retrieving the ``self`` argument from the stack.
Intended for use with callbacks that need access to a modules variables, for example:
.. code:: python
from i3pystatus import Status, get_module
from i3pystatus.core.command import execute... | [
"def",
"get_module",
"(",
"function",
")",
":",
"@",
"functools",
".",
"wraps",
"(",
"function",
")",
"def",
"call_wrapper",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"stack",
"=",
"inspect",
".",
"stack",
"(",
")",
"caller_frame_info",
"=",... | Function decorator for retrieving the ``self`` argument from the stack.
Intended for use with callbacks that need access to a modules variables, for example:
.. code:: python
from i3pystatus import Status, get_module
from i3pystatus.core.command import execute
status = Status(...)
... | [
"Function",
"decorator",
"for",
"retrieving",
"the",
"self",
"argument",
"from",
"the",
"stack",
"."
] | python | train |
blockstack/blockstack-core | blockstack/lib/atlas.py | https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/atlas.py#L3213-L3231 | def run(self, peer_table=None):
"""
Loop forever, pinging someone every pass.
"""
self.running = True
while self.running:
local_inv = atlas_get_zonefile_inventory()
t1 = time_now()
self.step( peer_table=peer_table, local_inv=local_inv, path=sel... | [
"def",
"run",
"(",
"self",
",",
"peer_table",
"=",
"None",
")",
":",
"self",
".",
"running",
"=",
"True",
"while",
"self",
".",
"running",
":",
"local_inv",
"=",
"atlas_get_zonefile_inventory",
"(",
")",
"t1",
"=",
"time_now",
"(",
")",
"self",
".",
"s... | Loop forever, pinging someone every pass. | [
"Loop",
"forever",
"pinging",
"someone",
"every",
"pass",
"."
] | python | train |
pantsbuild/pants | contrib/scrooge/src/python/pants/contrib/scrooge/tasks/thrift_util.py | https://github.com/pantsbuild/pants/blob/b72e650da0df685824ffdcc71988b8c282d0962d/contrib/scrooge/src/python/pants/contrib/scrooge/tasks/thrift_util.py#L15-L43 | def find_includes(basedirs, source, log=None):
"""Finds all thrift files included by the given thrift source.
:basedirs: A set of thrift source file base directories to look for includes in.
:source: The thrift source file to scan for includes.
:log: An optional logger
"""
all_basedirs = [os.path.dirname(... | [
"def",
"find_includes",
"(",
"basedirs",
",",
"source",
",",
"log",
"=",
"None",
")",
":",
"all_basedirs",
"=",
"[",
"os",
".",
"path",
".",
"dirname",
"(",
"source",
")",
"]",
"all_basedirs",
".",
"extend",
"(",
"basedirs",
")",
"includes",
"=",
"set"... | Finds all thrift files included by the given thrift source.
:basedirs: A set of thrift source file base directories to look for includes in.
:source: The thrift source file to scan for includes.
:log: An optional logger | [
"Finds",
"all",
"thrift",
"files",
"included",
"by",
"the",
"given",
"thrift",
"source",
"."
] | python | train |
sqlalchemy-redshift/sqlalchemy-redshift | sqlalchemy_redshift/dialect.py | https://github.com/sqlalchemy-redshift/sqlalchemy-redshift/blob/b1a24872da0c8151aa60da4524605b6243d8d765/sqlalchemy_redshift/dialect.py#L440-L459 | def get_pk_constraint(self, connection, table_name, schema=None, **kw):
"""
Return information about the primary key constraint on `table_name`.
Overrides interface
:meth:`~sqlalchemy.engine.interfaces.Dialect.get_pk_constraint`.
"""
constraints = self._get_redshift_cons... | [
"def",
"get_pk_constraint",
"(",
"self",
",",
"connection",
",",
"table_name",
",",
"schema",
"=",
"None",
",",
"*",
"*",
"kw",
")",
":",
"constraints",
"=",
"self",
".",
"_get_redshift_constraints",
"(",
"connection",
",",
"table_name",
",",
"schema",
",",
... | Return information about the primary key constraint on `table_name`.
Overrides interface
:meth:`~sqlalchemy.engine.interfaces.Dialect.get_pk_constraint`. | [
"Return",
"information",
"about",
"the",
"primary",
"key",
"constraint",
"on",
"table_name",
"."
] | python | train |
totalgood/pugnlp | src/pugnlp/plots.py | https://github.com/totalgood/pugnlp/blob/c43445b14afddfdeadc5f3076675c9e8fc1ee67c/src/pugnlp/plots.py#L296-L323 | def scatmat(df, category=None, colors='rgob',
num_plots=4, num_topics=100, num_columns=4,
show=False, block=False, data_path=DATA_PATH, save=False, verbose=1):
"""Scatter plot with colored markers depending on the discrete values in a "category" column
FIXME: empty plots that dont go aw... | [
"def",
"scatmat",
"(",
"df",
",",
"category",
"=",
"None",
",",
"colors",
"=",
"'rgob'",
",",
"num_plots",
"=",
"4",
",",
"num_topics",
"=",
"100",
",",
"num_columns",
"=",
"4",
",",
"show",
"=",
"False",
",",
"block",
"=",
"False",
",",
"data_path",... | Scatter plot with colored markers depending on the discrete values in a "category" column
FIXME: empty plots that dont go away, Plot and/save scatter matrix in groups of num_columns topics | [
"Scatter",
"plot",
"with",
"colored",
"markers",
"depending",
"on",
"the",
"discrete",
"values",
"in",
"a",
"category",
"column"
] | python | train |
BlueBrain/NeuroM | neurom/view/view.py | https://github.com/BlueBrain/NeuroM/blob/254bb73535b20053d175bc4725bade662177d12b/neurom/view/view.py#L233-L255 | def plot_soma3d(ax, soma, color=None, alpha=_ALPHA):
'''Generates a 3d figure of the soma.
Args:
ax(matplotlib axes): on what to plot
soma(neurom.core.Soma): plotted soma
color(str or None): Color of plotted values, None corresponds to default choice
alpha(float): Transparency o... | [
"def",
"plot_soma3d",
"(",
"ax",
",",
"soma",
",",
"color",
"=",
"None",
",",
"alpha",
"=",
"_ALPHA",
")",
":",
"color",
"=",
"_get_color",
"(",
"color",
",",
"tree_type",
"=",
"NeuriteType",
".",
"soma",
")",
"if",
"isinstance",
"(",
"soma",
",",
"S... | Generates a 3d figure of the soma.
Args:
ax(matplotlib axes): on what to plot
soma(neurom.core.Soma): plotted soma
color(str or None): Color of plotted values, None corresponds to default choice
alpha(float): Transparency of plotted values | [
"Generates",
"a",
"3d",
"figure",
"of",
"the",
"soma",
"."
] | python | train |
MisterY/gnucash-portfolio | gnucash_portfolio/scheduledtxaggregate.py | https://github.com/MisterY/gnucash-portfolio/blob/bfaad8345a5479d1cd111acee1939e25c2a638c2/gnucash_portfolio/scheduledtxaggregate.py#L262-L264 | def get_by_id(self, tx_id: str) -> ScheduledTransaction:
""" Fetches a tx by id """
return self.query.filter(ScheduledTransaction.guid == tx_id).first() | [
"def",
"get_by_id",
"(",
"self",
",",
"tx_id",
":",
"str",
")",
"->",
"ScheduledTransaction",
":",
"return",
"self",
".",
"query",
".",
"filter",
"(",
"ScheduledTransaction",
".",
"guid",
"==",
"tx_id",
")",
".",
"first",
"(",
")"
] | Fetches a tx by id | [
"Fetches",
"a",
"tx",
"by",
"id"
] | python | train |
mlperf/training | rnn_translator/pytorch/seq2seq/models/attention.py | https://github.com/mlperf/training/blob/1c6ae725a81d15437a2b2df05cac0673fde5c3a4/rnn_translator/pytorch/seq2seq/models/attention.py#L63-L81 | def set_mask(self, context_len, context):
"""
sets self.mask which is applied before softmax
ones for inactive context fields, zeros for active context fields
:param context_len: b
:param context: if batch_first: (b x t_k x n) else: (t_k x b x n)
self.mask: (b x t_k)
... | [
"def",
"set_mask",
"(",
"self",
",",
"context_len",
",",
"context",
")",
":",
"if",
"self",
".",
"batch_first",
":",
"max_len",
"=",
"context",
".",
"size",
"(",
"1",
")",
"else",
":",
"max_len",
"=",
"context",
".",
"size",
"(",
"0",
")",
"indices",... | sets self.mask which is applied before softmax
ones for inactive context fields, zeros for active context fields
:param context_len: b
:param context: if batch_first: (b x t_k x n) else: (t_k x b x n)
self.mask: (b x t_k) | [
"sets",
"self",
".",
"mask",
"which",
"is",
"applied",
"before",
"softmax",
"ones",
"for",
"inactive",
"context",
"fields",
"zeros",
"for",
"active",
"context",
"fields"
] | python | train |
onnx/onnx | onnx/backend/base.py | https://github.com/onnx/onnx/blob/2f7dc10f03a072526d94b6820cedbf2a1ec5a2c4/onnx/backend/base.py#L89-L111 | def run_node(cls,
node, # type: NodeProto
inputs, # type: Any
device='CPU', # type: Text
outputs_info=None, # type: Optional[Sequence[Tuple[numpy.dtype, Tuple[int, ...]]]]
**kwargs # type: Dict[Text, Any]
): # ty... | [
"def",
"run_node",
"(",
"cls",
",",
"node",
",",
"# type: NodeProto",
"inputs",
",",
"# type: Any",
"device",
"=",
"'CPU'",
",",
"# type: Text",
"outputs_info",
"=",
"None",
",",
"# type: Optional[Sequence[Tuple[numpy.dtype, Tuple[int, ...]]]]",
"*",
"*",
"kwargs",
"#... | Simple run one operator and return the results.
Args:
outputs_info: a list of tuples, which contains the element type and
shape of each output. First element of the tuple is the dtype, and
the second element is the shape. More use case can be found in
https://gith... | [
"Simple",
"run",
"one",
"operator",
"and",
"return",
"the",
"results",
".",
"Args",
":",
"outputs_info",
":",
"a",
"list",
"of",
"tuples",
"which",
"contains",
"the",
"element",
"type",
"and",
"shape",
"of",
"each",
"output",
".",
"First",
"element",
"of",... | python | train |
Devoxin/Lavalink.py | lavalink/PlayerManager.py | https://github.com/Devoxin/Lavalink.py/blob/63f55c3d726d24c4cfd3674d3cd6aab6f5be110d/lavalink/PlayerManager.py#L226-L230 | def remove(self, guild_id):
""" Removes a player from the current players. """
if guild_id in self._players:
self._players[guild_id].cleanup()
del self._players[guild_id] | [
"def",
"remove",
"(",
"self",
",",
"guild_id",
")",
":",
"if",
"guild_id",
"in",
"self",
".",
"_players",
":",
"self",
".",
"_players",
"[",
"guild_id",
"]",
".",
"cleanup",
"(",
")",
"del",
"self",
".",
"_players",
"[",
"guild_id",
"]"
] | Removes a player from the current players. | [
"Removes",
"a",
"player",
"from",
"the",
"current",
"players",
"."
] | python | valid |
thisfred/val | val/_val.py | https://github.com/thisfred/val/blob/ba022e0c6c47acb3b8a45e7c44c84cc0f495c41c/val/_val.py#L339-L343 | def _validated(self, data):
"""Validate data if all subschemas validate it."""
for sub in self.schemas:
data = sub(data)
return data | [
"def",
"_validated",
"(",
"self",
",",
"data",
")",
":",
"for",
"sub",
"in",
"self",
".",
"schemas",
":",
"data",
"=",
"sub",
"(",
"data",
")",
"return",
"data"
] | Validate data if all subschemas validate it. | [
"Validate",
"data",
"if",
"all",
"subschemas",
"validate",
"it",
"."
] | python | train |
erdc/RAPIDpy | RAPIDpy/postprocess/generate_return_periods.py | https://github.com/erdc/RAPIDpy/blob/50e14e130554b254a00ff23b226cd7e4c6cfe91a/RAPIDpy/postprocess/generate_return_periods.py#L20-L153 | def generate_single_return_period(args):
"""
This function calculates a single return period for a single reach
"""
qout_file, return_period_file, rivid_index_list, step, num_years, \
method, mp_lock = args
skewvals = [-3.0, -2.8, -2.6, -2.4, -2.2, -2.0, -1.8, -1.6, -1.4, -1.2,
... | [
"def",
"generate_single_return_period",
"(",
"args",
")",
":",
"qout_file",
",",
"return_period_file",
",",
"rivid_index_list",
",",
"step",
",",
"num_years",
",",
"method",
",",
"mp_lock",
"=",
"args",
"skewvals",
"=",
"[",
"-",
"3.0",
",",
"-",
"2.8",
",",... | This function calculates a single return period for a single reach | [
"This",
"function",
"calculates",
"a",
"single",
"return",
"period",
"for",
"a",
"single",
"reach"
] | python | train |
twilio/twilio-python | twilio/rest/api/v2010/account/outgoing_caller_id.py | https://github.com/twilio/twilio-python/blob/c867895f55dcc29f522e6e8b8868d0d18483132f/twilio/rest/api/v2010/account/outgoing_caller_id.py#L327-L341 | def _proxy(self):
"""
Generate an instance context for the instance, the context is capable of
performing various actions. All instance actions are proxied to the context
:returns: OutgoingCallerIdContext for this OutgoingCallerIdInstance
:rtype: twilio.rest.api.v2010.account.o... | [
"def",
"_proxy",
"(",
"self",
")",
":",
"if",
"self",
".",
"_context",
"is",
"None",
":",
"self",
".",
"_context",
"=",
"OutgoingCallerIdContext",
"(",
"self",
".",
"_version",
",",
"account_sid",
"=",
"self",
".",
"_solution",
"[",
"'account_sid'",
"]",
... | Generate an instance context for the instance, the context is capable of
performing various actions. All instance actions are proxied to the context
:returns: OutgoingCallerIdContext for this OutgoingCallerIdInstance
:rtype: twilio.rest.api.v2010.account.outgoing_caller_id.OutgoingCallerIdCont... | [
"Generate",
"an",
"instance",
"context",
"for",
"the",
"instance",
"the",
"context",
"is",
"capable",
"of",
"performing",
"various",
"actions",
".",
"All",
"instance",
"actions",
"are",
"proxied",
"to",
"the",
"context"
] | python | train |
angr/angr | angr/misc/plugins.py | https://github.com/angr/angr/blob/4e2f97d56af5419ee73bdb30482c8dd8ff5f3e40/angr/misc/plugins.py#L42-L50 | def register_preset(cls, name, preset):
"""
Register a preset instance with the class of the hub it corresponds to. This allows individual plugin objects to
automatically register themselves with a preset by using a classmethod of their own with only the name of the
preset to register wi... | [
"def",
"register_preset",
"(",
"cls",
",",
"name",
",",
"preset",
")",
":",
"if",
"cls",
".",
"_presets",
"is",
"None",
":",
"cls",
".",
"_presets",
"=",
"{",
"}",
"cls",
".",
"_presets",
"[",
"name",
"]",
"=",
"preset"
] | Register a preset instance with the class of the hub it corresponds to. This allows individual plugin objects to
automatically register themselves with a preset by using a classmethod of their own with only the name of the
preset to register with. | [
"Register",
"a",
"preset",
"instance",
"with",
"the",
"class",
"of",
"the",
"hub",
"it",
"corresponds",
"to",
".",
"This",
"allows",
"individual",
"plugin",
"objects",
"to",
"automatically",
"register",
"themselves",
"with",
"a",
"preset",
"by",
"using",
"a",
... | python | train |
riordan/py-copyfile | copyfile/copyfile.py | https://github.com/riordan/py-copyfile/blob/ea7c45de8ac8e6f3a8a9dc0deee87f8f882a8e79/copyfile/copyfile.py#L19-L45 | def copyFile(src, dest):
"""Copies a source file to a destination whose path may not yet exist.
Keyword arguments:
src -- Source path to a file (string)
dest -- Path for destination file (also a string)
"""
#Src Exists?
try:
if os.path.isfile(src):
dpath, dfile = os.path... | [
"def",
"copyFile",
"(",
"src",
",",
"dest",
")",
":",
"#Src Exists?",
"try",
":",
"if",
"os",
".",
"path",
".",
"isfile",
"(",
"src",
")",
":",
"dpath",
",",
"dfile",
"=",
"os",
".",
"path",
".",
"split",
"(",
"dest",
")",
"if",
"not",
"os",
".... | Copies a source file to a destination whose path may not yet exist.
Keyword arguments:
src -- Source path to a file (string)
dest -- Path for destination file (also a string) | [
"Copies",
"a",
"source",
"file",
"to",
"a",
"destination",
"whose",
"path",
"may",
"not",
"yet",
"exist",
"."
] | python | train |
luckydonald/pytgbot | code_generation/output/pytgbot/bot.py | https://github.com/luckydonald/pytgbot/blob/67f4b5a1510d4583d40b5477e876b1ef0eb8971b/code_generation/output/pytgbot/bot.py#L2698-L2730 | def get_sticker_set(self, name):
"""
Use this method to get a sticker set. On success, a StickerSet object is returned.
https://core.telegram.org/bots/api#getstickerset
Parameters:
:param name: Name of the sticker set
:type name: str|unicode
... | [
"def",
"get_sticker_set",
"(",
"self",
",",
"name",
")",
":",
"assert_type_or_raise",
"(",
"name",
",",
"unicode_type",
",",
"parameter_name",
"=",
"\"name\"",
")",
"result",
"=",
"self",
".",
"do",
"(",
"\"getStickerSet\"",
",",
"name",
"=",
"name",
")",
... | Use this method to get a sticker set. On success, a StickerSet object is returned.
https://core.telegram.org/bots/api#getstickerset
Parameters:
:param name: Name of the sticker set
:type name: str|unicode
Returns:
:return: On succes... | [
"Use",
"this",
"method",
"to",
"get",
"a",
"sticker",
"set",
".",
"On",
"success",
"a",
"StickerSet",
"object",
"is",
"returned",
"."
] | python | train |
delfick/harpoon | harpoon/option_spec/image_objs.py | https://github.com/delfick/harpoon/blob/a2d39311d6127b7da2e15f40468bf320d598e461/harpoon/option_spec/image_objs.py#L217-L232 | def cache_from_names(self):
"""Yield the image names to do --cache-from from"""
cache_from = self.cache_from()
if not cache_from or cache_from is NotSpecified:
return
if cache_from is True:
yield self.image_name
return
for thing in cache_fro... | [
"def",
"cache_from_names",
"(",
"self",
")",
":",
"cache_from",
"=",
"self",
".",
"cache_from",
"(",
")",
"if",
"not",
"cache_from",
"or",
"cache_from",
"is",
"NotSpecified",
":",
"return",
"if",
"cache_from",
"is",
"True",
":",
"yield",
"self",
".",
"imag... | Yield the image names to do --cache-from from | [
"Yield",
"the",
"image",
"names",
"to",
"do",
"--",
"cache",
"-",
"from",
"from"
] | python | train |
photo/openphoto-python | trovebox/api/api_tag.py | https://github.com/photo/openphoto-python/blob/209a1da27c8d8c88dbcf4ea6c6f57031ea1bc44b/trovebox/api/api_tag.py#L31-L41 | def delete(self, tag, **kwds):
"""
Endpoint: /tag/<id>/delete.json
Deletes a tag.
Returns True if successful.
Raises a TroveboxError if not.
"""
return self._client.post("/tag/%s/delete.json" %
self._quote_url(self._extract_id(tag... | [
"def",
"delete",
"(",
"self",
",",
"tag",
",",
"*",
"*",
"kwds",
")",
":",
"return",
"self",
".",
"_client",
".",
"post",
"(",
"\"/tag/%s/delete.json\"",
"%",
"self",
".",
"_quote_url",
"(",
"self",
".",
"_extract_id",
"(",
"tag",
")",
")",
",",
"*",... | Endpoint: /tag/<id>/delete.json
Deletes a tag.
Returns True if successful.
Raises a TroveboxError if not. | [
"Endpoint",
":",
"/",
"tag",
"/",
"<id",
">",
"/",
"delete",
".",
"json"
] | python | train |
linkedin/luminol | src/luminol/algorithms/anomaly_detector_algorithms/bitmap_detector.py | https://github.com/linkedin/luminol/blob/42e4ab969b774ff98f902d064cb041556017f635/src/luminol/algorithms/anomaly_detector_algorithms/bitmap_detector.py#L176-L194 | def _compute_anom_score_between_two_windows(self, i):
"""
Compute distance difference between two windows' chunk frequencies,
which is then marked as the anomaly score of the data point on the window boundary in the middle.
:param int i: index of the data point between two windows.
... | [
"def",
"_compute_anom_score_between_two_windows",
"(",
"self",
",",
"i",
")",
":",
"lag_window_chunk_dict",
"=",
"self",
".",
"lag_dicts",
"[",
"i",
"]",
"future_window_chunk_dict",
"=",
"self",
".",
"fut_dicts",
"[",
"i",
"]",
"score",
"=",
"0",
"for",
"chunk... | Compute distance difference between two windows' chunk frequencies,
which is then marked as the anomaly score of the data point on the window boundary in the middle.
:param int i: index of the data point between two windows.
:return float: the anomaly score. | [
"Compute",
"distance",
"difference",
"between",
"two",
"windows",
"chunk",
"frequencies",
"which",
"is",
"then",
"marked",
"as",
"the",
"anomaly",
"score",
"of",
"the",
"data",
"point",
"on",
"the",
"window",
"boundary",
"in",
"the",
"middle",
".",
":",
"par... | python | train |
3ll3d00d/vibe | backend/src/recorder/resources/measurements.py | https://github.com/3ll3d00d/vibe/blob/124b029f13ac746723e92cb47e9cb56edd2e54b5/backend/src/recorder/resources/measurements.py#L42-L49 | def get(self, deviceId, measurementId):
"""
details the specific measurement.
"""
record = self.measurements.get(deviceId)
if record is not None:
return record.get(measurementId)
return None | [
"def",
"get",
"(",
"self",
",",
"deviceId",
",",
"measurementId",
")",
":",
"record",
"=",
"self",
".",
"measurements",
".",
"get",
"(",
"deviceId",
")",
"if",
"record",
"is",
"not",
"None",
":",
"return",
"record",
".",
"get",
"(",
"measurementId",
")... | details the specific measurement. | [
"details",
"the",
"specific",
"measurement",
"."
] | python | train |
PmagPy/PmagPy | dialogs/magic_grid3.py | https://github.com/PmagPy/PmagPy/blob/c7984f8809bf40fe112e53dcc311a33293b62d0b/dialogs/magic_grid3.py#L160-L191 | def add_items(self, dataframe, hide_cols=()):
"""
Add items and/or update existing items in grid
"""
# replace "None" values with ""
dataframe = dataframe.fillna("")
# remove any columns that shouldn't be shown
for col in hide_cols:
if col in dataframe... | [
"def",
"add_items",
"(",
"self",
",",
"dataframe",
",",
"hide_cols",
"=",
"(",
")",
")",
":",
"# replace \"None\" values with \"\"",
"dataframe",
"=",
"dataframe",
".",
"fillna",
"(",
"\"\"",
")",
"# remove any columns that shouldn't be shown",
"for",
"col",
"in",
... | Add items and/or update existing items in grid | [
"Add",
"items",
"and",
"/",
"or",
"update",
"existing",
"items",
"in",
"grid"
] | python | train |
amirziai/flatten | util.py | https://github.com/amirziai/flatten/blob/e8e2cbbdd6fe21177bfc0ce034562463ae555799/util.py#L1-L9 | def check_if_numbers_are_consecutive(list_):
"""
Returns True if numbers in the list are consecutive
:param list_: list of integers
:return: Boolean
"""
return all((True if second - first == 1 else False
for first, second in zip(list_[:-1], list_[1:]))) | [
"def",
"check_if_numbers_are_consecutive",
"(",
"list_",
")",
":",
"return",
"all",
"(",
"(",
"True",
"if",
"second",
"-",
"first",
"==",
"1",
"else",
"False",
"for",
"first",
",",
"second",
"in",
"zip",
"(",
"list_",
"[",
":",
"-",
"1",
"]",
",",
"l... | Returns True if numbers in the list are consecutive
:param list_: list of integers
:return: Boolean | [
"Returns",
"True",
"if",
"numbers",
"in",
"the",
"list",
"are",
"consecutive"
] | python | train |
django-parler/django-parler | parler/cache.py | https://github.com/django-parler/django-parler/blob/11ae4af5e8faddb74c69c848870122df4006a54e/parler/cache.py#L112-L144 | def _get_cached_values(instance, translated_model, language_code, use_fallback=False):
"""
Fetch an cached field.
"""
if not appsettings.PARLER_ENABLE_CACHING or not instance.pk or instance._state.adding:
return None
key = get_translation_cache_key(translated_model, instance.pk, language_co... | [
"def",
"_get_cached_values",
"(",
"instance",
",",
"translated_model",
",",
"language_code",
",",
"use_fallback",
"=",
"False",
")",
":",
"if",
"not",
"appsettings",
".",
"PARLER_ENABLE_CACHING",
"or",
"not",
"instance",
".",
"pk",
"or",
"instance",
".",
"_state... | Fetch an cached field. | [
"Fetch",
"an",
"cached",
"field",
"."
] | python | train |
qualisys/qualisys_python_sdk | qtm/packet.py | https://github.com/qualisys/qualisys_python_sdk/blob/127d7eeebc2b38b5cafdfa5d1d0198437fedd274/qtm/packet.py#L397-L409 | def get_6d(self, component_info=None, data=None, component_position=None):
"""Get 6D data."""
components = []
append_components = components.append
for _ in range(component_info.body_count):
component_position, position = QRTPacket._get_exact(
RT6DBodyPosition... | [
"def",
"get_6d",
"(",
"self",
",",
"component_info",
"=",
"None",
",",
"data",
"=",
"None",
",",
"component_position",
"=",
"None",
")",
":",
"components",
"=",
"[",
"]",
"append_components",
"=",
"components",
".",
"append",
"for",
"_",
"in",
"range",
"... | Get 6D data. | [
"Get",
"6D",
"data",
"."
] | python | valid |
stratis-storage/into-dbus-python | src/into_dbus_python/_xformer.py | https://github.com/stratis-storage/into-dbus-python/blob/81366049671f79116bbb81c97bf621800a2f6315/src/into_dbus_python/_xformer.py#L78-L103 | def _handle_variant(self):
"""
Generate the correct function for a variant signature.
:returns: function that returns an appropriate value
:rtype: ((str * object) or list)-> object
"""
def the_func(a_tuple, variant=0):
"""
Function for generating... | [
"def",
"_handle_variant",
"(",
"self",
")",
":",
"def",
"the_func",
"(",
"a_tuple",
",",
"variant",
"=",
"0",
")",
":",
"\"\"\"\n Function for generating a variant value from a tuple.\n\n :param a_tuple: the parts of the variant\n :type a_tuple: (str ... | Generate the correct function for a variant signature.
:returns: function that returns an appropriate value
:rtype: ((str * object) or list)-> object | [
"Generate",
"the",
"correct",
"function",
"for",
"a",
"variant",
"signature",
"."
] | python | valid |
sprockets/sprockets-influxdb | sprockets_influxdb.py | https://github.com/sprockets/sprockets-influxdb/blob/cce73481b8f26b02e65e3f9914a9a22eceff3063/sprockets_influxdb.py#L658-L667 | def _trigger_batch_write():
"""Stop a timeout if it's running, and then write the measurements."""
global _batch_future
LOGGER.debug('Batch write triggered (%r/%r)',
_buffer_size, _trigger_size)
_maybe_stop_timeout()
_maybe_warn_about_buffer_size()
_batch_future = _write_measur... | [
"def",
"_trigger_batch_write",
"(",
")",
":",
"global",
"_batch_future",
"LOGGER",
".",
"debug",
"(",
"'Batch write triggered (%r/%r)'",
",",
"_buffer_size",
",",
"_trigger_size",
")",
"_maybe_stop_timeout",
"(",
")",
"_maybe_warn_about_buffer_size",
"(",
")",
"_batch_f... | Stop a timeout if it's running, and then write the measurements. | [
"Stop",
"a",
"timeout",
"if",
"it",
"s",
"running",
"and",
"then",
"write",
"the",
"measurements",
"."
] | python | train |
SmokinCaterpillar/pypet | pypet/storageservice.py | https://github.com/SmokinCaterpillar/pypet/blob/97ad3e80d46dbdea02deeb98ea41f05a19565826/pypet/storageservice.py#L4110-L4157 | def _prm_write_dict_as_table(self, key, data_to_store, group, fullname, **kwargs):
"""Stores a python dictionary as pytable
:param key:
Name of data item to store
:param data_to_store:
Dictionary to store
:param group:
Group node where to store d... | [
"def",
"_prm_write_dict_as_table",
"(",
"self",
",",
"key",
",",
"data_to_store",
",",
"group",
",",
"fullname",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"key",
"in",
"group",
":",
"raise",
"ValueError",
"(",
"'Dictionary `%s` already exists in `%s`. Appending is ... | Stores a python dictionary as pytable
:param key:
Name of data item to store
:param data_to_store:
Dictionary to store
:param group:
Group node where to store data in hdf5 file
:param fullname:
Full name of the `data_to_store`s orig... | [
"Stores",
"a",
"python",
"dictionary",
"as",
"pytable"
] | python | test |
bcbio/bcbio-nextgen | bcbio/bam/counts.py | https://github.com/bcbio/bcbio-nextgen/blob/6a9348c0054ccd5baffd22f1bb7d0422f6978b20/bcbio/bam/counts.py#L41-L45 | def coverage_pileup(self, space, start, end):
"""Retrieve pileup coverage across a specified region.
"""
return ((col.pos, self._normalize(col.n, self._total))
for col in self._bam.pileup(space, start, end)) | [
"def",
"coverage_pileup",
"(",
"self",
",",
"space",
",",
"start",
",",
"end",
")",
":",
"return",
"(",
"(",
"col",
".",
"pos",
",",
"self",
".",
"_normalize",
"(",
"col",
".",
"n",
",",
"self",
".",
"_total",
")",
")",
"for",
"col",
"in",
"self"... | Retrieve pileup coverage across a specified region. | [
"Retrieve",
"pileup",
"coverage",
"across",
"a",
"specified",
"region",
"."
] | python | train |
deep-compute/logagg | logagg/collector.py | https://github.com/deep-compute/logagg/blob/7863bc1b5ddf3e67c4d4b55746799304180589a0/logagg/collector.py#L356-L412 | def _scan_fpatterns(self, state):
'''
For a list of given fpatterns, this starts a thread
collecting log lines from file
>>> os.path.isfile = lambda path: path == '/path/to/log_file.log'
>>> lc = LogCollector('file=/path/to/log_file.log:formatter=logagg.formatters.basescript', 3... | [
"def",
"_scan_fpatterns",
"(",
"self",
",",
"state",
")",
":",
"for",
"f",
"in",
"self",
".",
"fpaths",
":",
"fpattern",
",",
"formatter",
"=",
"(",
"a",
".",
"split",
"(",
"'='",
")",
"[",
"1",
"]",
"for",
"a",
"in",
"f",
".",
"split",
"(",
"'... | For a list of given fpatterns, this starts a thread
collecting log lines from file
>>> os.path.isfile = lambda path: path == '/path/to/log_file.log'
>>> lc = LogCollector('file=/path/to/log_file.log:formatter=logagg.formatters.basescript', 30)
>>> print(lc.fpaths)
file=/path/to... | [
"For",
"a",
"list",
"of",
"given",
"fpatterns",
"this",
"starts",
"a",
"thread",
"collecting",
"log",
"lines",
"from",
"file"
] | python | train |
phaethon/kamene | kamene/arch/windows/__init__.py | https://github.com/phaethon/kamene/blob/11d4064844f4f68ac5d7546f5633ac7d02082914/kamene/arch/windows/__init__.py#L193-L198 | def devname_from_index(self, if_index):
"""Return interface name from interface index"""
for devname, iface in self.items():
if iface.win_index == if_index:
return iface.name
raise ValueError("Unknown network interface index %r" % if_index) | [
"def",
"devname_from_index",
"(",
"self",
",",
"if_index",
")",
":",
"for",
"devname",
",",
"iface",
"in",
"self",
".",
"items",
"(",
")",
":",
"if",
"iface",
".",
"win_index",
"==",
"if_index",
":",
"return",
"iface",
".",
"name",
"raise",
"ValueError",... | Return interface name from interface index | [
"Return",
"interface",
"name",
"from",
"interface",
"index"
] | python | train |
DataBiosphere/dsub | dsub/providers/google_base.py | https://github.com/DataBiosphere/dsub/blob/443ce31daa6023dc2fd65ef2051796e19d18d5a7/dsub/providers/google_base.py#L301-L357 | def parse_rfc3339_utc_string(rfc3339_utc_string):
"""Converts a datestamp from RFC3339 UTC to a datetime.
Args:
rfc3339_utc_string: a datetime string in RFC3339 UTC "Zulu" format
Returns:
A datetime.
"""
# The timestamp from the Google Operations are all in RFC3339 format, but
# they are sometime... | [
"def",
"parse_rfc3339_utc_string",
"(",
"rfc3339_utc_string",
")",
":",
"# The timestamp from the Google Operations are all in RFC3339 format, but",
"# they are sometimes formatted to millisconds, microseconds, sometimes",
"# nanoseconds, and sometimes only seconds:",
"# * 2016-11-14T23:05:56Z",
... | Converts a datestamp from RFC3339 UTC to a datetime.
Args:
rfc3339_utc_string: a datetime string in RFC3339 UTC "Zulu" format
Returns:
A datetime. | [
"Converts",
"a",
"datestamp",
"from",
"RFC3339",
"UTC",
"to",
"a",
"datetime",
"."
] | python | valid |
mitsei/dlkit | dlkit/json_/utilities.py | https://github.com/mitsei/dlkit/blob/445f968a175d61c8d92c0f617a3c17dc1dc7c584/dlkit/json_/utilities.py#L914-L938 | def convert_catalog_id_to_object_id_string(catalog_id):
"""When doing hierarchies, need to convert a catalogId into an
ObjectId, so convert to a string, then into a hex format.
i.e. Bank Assessment hierarchy should become
BANKASSESSME
'42414e4b4153534553534d45'
"""
if not isinst... | [
"def",
"convert_catalog_id_to_object_id_string",
"(",
"catalog_id",
")",
":",
"if",
"not",
"isinstance",
"(",
"catalog_id",
",",
"Id",
")",
":",
"raise",
"TypeError",
"(",
"'input needs to be an Id'",
")",
"seed_str",
"=",
"catalog_id",
".",
"get_identifier",
"(",
... | When doing hierarchies, need to convert a catalogId into an
ObjectId, so convert to a string, then into a hex format.
i.e. Bank Assessment hierarchy should become
BANKASSESSME
'42414e4b4153534553534d45' | [
"When",
"doing",
"hierarchies",
"need",
"to",
"convert",
"a",
"catalogId",
"into",
"an",
"ObjectId",
"so",
"convert",
"to",
"a",
"string",
"then",
"into",
"a",
"hex",
"format",
"."
] | python | train |
OpenTreeOfLife/peyotl | scripts/nexson/prune_to_clean_mapped.py | https://github.com/OpenTreeOfLife/peyotl/blob/5e4e52a0fdbd17f490aa644ad79fda6ea2eda7c0/scripts/nexson/prune_to_clean_mapped.py#L147-L159 | def prune_clade(self, node_id):
"""Prune `node_id` and the edges and nodes that are tipward of it.
Caller must delete the edge to node_id."""
to_del_nodes = [node_id]
while bool(to_del_nodes):
node_id = to_del_nodes.pop(0)
self._flag_node_as_del_and_del_in_by_targ... | [
"def",
"prune_clade",
"(",
"self",
",",
"node_id",
")",
":",
"to_del_nodes",
"=",
"[",
"node_id",
"]",
"while",
"bool",
"(",
"to_del_nodes",
")",
":",
"node_id",
"=",
"to_del_nodes",
".",
"pop",
"(",
"0",
")",
"self",
".",
"_flag_node_as_del_and_del_in_by_ta... | Prune `node_id` and the edges and nodes that are tipward of it.
Caller must delete the edge to node_id. | [
"Prune",
"node_id",
"and",
"the",
"edges",
"and",
"nodes",
"that",
"are",
"tipward",
"of",
"it",
".",
"Caller",
"must",
"delete",
"the",
"edge",
"to",
"node_id",
"."
] | python | train |
EnergieID/smappy | smappy/smappy.py | https://github.com/EnergieID/smappy/blob/1ada3abc9a51c76205c072369258f6f4f4e8fd0f/smappy/smappy.py#L139-L151 | def get_service_locations(self):
"""
Request service locations
Returns
-------
dict
"""
url = URLS['servicelocation']
headers = {"Authorization": "Bearer {}".format(self.access_token)}
r = requests.get(url, headers=headers)
r.raise_for_sta... | [
"def",
"get_service_locations",
"(",
"self",
")",
":",
"url",
"=",
"URLS",
"[",
"'servicelocation'",
"]",
"headers",
"=",
"{",
"\"Authorization\"",
":",
"\"Bearer {}\"",
".",
"format",
"(",
"self",
".",
"access_token",
")",
"}",
"r",
"=",
"requests",
".",
... | Request service locations
Returns
-------
dict | [
"Request",
"service",
"locations"
] | python | train |
sorgerlab/indra | indra/sources/sparser/processor.py | https://github.com/sorgerlab/indra/blob/79a70415832c5702d7a820c7c9ccc8e25010124b/indra/sources/sparser/processor.py#L155-L172 | def set_statements_pmid(self, pmid):
"""Set the evidence PMID of Statements that have been extracted.
Parameters
----------
pmid : str or None
The PMID to be used in the Evidence objects of the Statements
that were extracted by the processor.
"""
... | [
"def",
"set_statements_pmid",
"(",
"self",
",",
"pmid",
")",
":",
"# Replace PMID value in JSON dict first",
"for",
"stmt",
"in",
"self",
".",
"json_stmts",
":",
"evs",
"=",
"stmt",
".",
"get",
"(",
"'evidence'",
",",
"[",
"]",
")",
"for",
"ev",
"in",
"evs... | Set the evidence PMID of Statements that have been extracted.
Parameters
----------
pmid : str or None
The PMID to be used in the Evidence objects of the Statements
that were extracted by the processor. | [
"Set",
"the",
"evidence",
"PMID",
"of",
"Statements",
"that",
"have",
"been",
"extracted",
"."
] | python | train |
bcbio/bcbio-nextgen | bcbio/cwl/hpc.py | https://github.com/bcbio/bcbio-nextgen/blob/6a9348c0054ccd5baffd22f1bb7d0422f6978b20/bcbio/cwl/hpc.py#L8-L40 | def create_cromwell_config(args, work_dir, sample_file):
"""Prepare a cromwell configuration within the current working directory.
"""
docker_attrs = ["String? docker", "String? docker_user"]
cwl_attrs = ["Int? cpuMin", "Int? cpuMax", "Int? memoryMin", "Int? memoryMax", "String? outDirMin",
... | [
"def",
"create_cromwell_config",
"(",
"args",
",",
"work_dir",
",",
"sample_file",
")",
":",
"docker_attrs",
"=",
"[",
"\"String? docker\"",
",",
"\"String? docker_user\"",
"]",
"cwl_attrs",
"=",
"[",
"\"Int? cpuMin\"",
",",
"\"Int? cpuMax\"",
",",
"\"Int? memoryMin\"... | Prepare a cromwell configuration within the current working directory. | [
"Prepare",
"a",
"cromwell",
"configuration",
"within",
"the",
"current",
"working",
"directory",
"."
] | python | train |
ihgazni2/elist | elist/elist.py | https://github.com/ihgazni2/elist/blob/8c07b5029bda34ead60ce10335ceb145f209263c/elist/elist.py#L4328-L4365 | def filter(ol,test_func,*args,**kwargs):
'''
from elist.elist import *
def test_func(ele,x):
cond = (ele > x)
return(cond)
ol = [1,2,3,4]
id(ol)
new = filter(ol,test_func,3)
new
id(new)
#####
ol = [10,20,30,40]
... | [
"def",
"filter",
"(",
"ol",
",",
"test_func",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"(",
"'mode'",
"in",
"kwargs",
")",
":",
"mode",
"=",
"kwargs",
"[",
"'mode'",
"]",
"else",
":",
"mode",
"=",
"\"new\"",
"length",
"=",
"ol",... | from elist.elist import *
def test_func(ele,x):
cond = (ele > x)
return(cond)
ol = [1,2,3,4]
id(ol)
new = filter(ol,test_func,3)
new
id(new)
#####
ol = [10,20,30,40]
id(ol)
rslt = filter(ol,test_func,3,mode=... | [
"from",
"elist",
".",
"elist",
"import",
"*",
"def",
"test_func",
"(",
"ele",
"x",
")",
":",
"cond",
"=",
"(",
"ele",
">",
"x",
")",
"return",
"(",
"cond",
")",
"ol",
"=",
"[",
"1",
"2",
"3",
"4",
"]",
"id",
"(",
"ol",
")",
"new",
"=",
"fil... | python | valid |
kubernetes-client/python | kubernetes/client/apis/custom_objects_api.py | https://github.com/kubernetes-client/python/blob/5e512ff564c244c50cab780d821542ed56aa965a/kubernetes/client/apis/custom_objects_api.py#L415-L442 | def delete_namespaced_custom_object(self, group, version, namespace, plural, name, body, **kwargs):
"""
Deletes the specified namespace scoped custom object
This method makes a synchronous HTTP request by default. To make an
asynchronous HTTP request, please pass async_req=True
>... | [
"def",
"delete_namespaced_custom_object",
"(",
"self",
",",
"group",
",",
"version",
",",
"namespace",
",",
"plural",
",",
"name",
",",
"body",
",",
"*",
"*",
"kwargs",
")",
":",
"kwargs",
"[",
"'_return_http_data_only'",
"]",
"=",
"True",
"if",
"kwargs",
... | Deletes the specified namespace scoped custom object
This method makes a synchronous HTTP request by default. To make an
asynchronous HTTP request, please pass async_req=True
>>> thread = api.delete_namespaced_custom_object(group, version, namespace, plural, name, body, async_req=True)
>... | [
"Deletes",
"the",
"specified",
"namespace",
"scoped",
"custom",
"object",
"This",
"method",
"makes",
"a",
"synchronous",
"HTTP",
"request",
"by",
"default",
".",
"To",
"make",
"an",
"asynchronous",
"HTTP",
"request",
"please",
"pass",
"async_req",
"=",
"True",
... | python | train |
ssato/python-anyconfig | src/anyconfig/backend/base.py | https://github.com/ssato/python-anyconfig/blob/f2f4fb8d8e232aadea866c202e1dd7a5967e2877/src/anyconfig/backend/base.py#L362-L380 | def dump(self, cnf, ioi, **kwargs):
"""
Dump config 'cnf' to output object of which 'ioi' refering.
:param cnf: Configuration data to dump
:param ioi:
an 'anyconfig.globals.IOInfo' namedtuple object provides various
info of input object to load data from
... | [
"def",
"dump",
"(",
"self",
",",
"cnf",
",",
"ioi",
",",
"*",
"*",
"kwargs",
")",
":",
"kwargs",
"=",
"anyconfig",
".",
"utils",
".",
"filter_options",
"(",
"self",
".",
"_dump_opts",
",",
"kwargs",
")",
"if",
"anyconfig",
".",
"utils",
".",
"is_stre... | Dump config 'cnf' to output object of which 'ioi' refering.
:param cnf: Configuration data to dump
:param ioi:
an 'anyconfig.globals.IOInfo' namedtuple object provides various
info of input object to load data from
:param kwargs: optional keyword parameters to be saniti... | [
"Dump",
"config",
"cnf",
"to",
"output",
"object",
"of",
"which",
"ioi",
"refering",
"."
] | python | train |
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 |
learningequality/ricecooker | ricecooker/utils/linecook.py | https://github.com/learningequality/ricecooker/blob/2f0385282500cb77ef2894646c6f9ce11bd7a853/ricecooker/utils/linecook.py#L117-L126 | def keep_folder(raw_path):
"""
Keep only folders that don't contain patterns in `DIR_EXCLUDE_PATTERNS`.
"""
keep = True
for pattern in DIR_EXCLUDE_PATTERNS:
if pattern in raw_path:
LOGGER.debug('rejecting', raw_path)
keep = False
return keep | [
"def",
"keep_folder",
"(",
"raw_path",
")",
":",
"keep",
"=",
"True",
"for",
"pattern",
"in",
"DIR_EXCLUDE_PATTERNS",
":",
"if",
"pattern",
"in",
"raw_path",
":",
"LOGGER",
".",
"debug",
"(",
"'rejecting'",
",",
"raw_path",
")",
"keep",
"=",
"False",
"retu... | Keep only folders that don't contain patterns in `DIR_EXCLUDE_PATTERNS`. | [
"Keep",
"only",
"folders",
"that",
"don",
"t",
"contain",
"patterns",
"in",
"DIR_EXCLUDE_PATTERNS",
"."
] | python | train |
nephila/djangocms-page-tags | djangocms_page_tags/utils.py | https://github.com/nephila/djangocms-page-tags/blob/602c9d74456d689f46ddb8d67cd64d1a42747359/djangocms_page_tags/utils.py#L5-L23 | def get_cache_key(request, page, lang, site_id, title):
"""
Create the cache key for the current page and tag type
"""
from cms.cache import _get_cache_key
from cms.templatetags.cms_tags import _get_page_by_untyped_arg
from cms.models import Page
if not isinstance(page, Page):
page ... | [
"def",
"get_cache_key",
"(",
"request",
",",
"page",
",",
"lang",
",",
"site_id",
",",
"title",
")",
":",
"from",
"cms",
".",
"cache",
"import",
"_get_cache_key",
"from",
"cms",
".",
"templatetags",
".",
"cms_tags",
"import",
"_get_page_by_untyped_arg",
"from"... | Create the cache key for the current page and tag type | [
"Create",
"the",
"cache",
"key",
"for",
"the",
"current",
"page",
"and",
"tag",
"type"
] | python | train |
LonamiWebs/Telethon | telethon/events/common.py | https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon/events/common.py#L83-L94 | async def resolve(self, client):
"""Helper method to allow event builders to be resolved before usage"""
if self.resolved:
return
if not self._resolve_lock:
self._resolve_lock = asyncio.Lock(loop=client.loop)
async with self._resolve_lock:
if not sel... | [
"async",
"def",
"resolve",
"(",
"self",
",",
"client",
")",
":",
"if",
"self",
".",
"resolved",
":",
"return",
"if",
"not",
"self",
".",
"_resolve_lock",
":",
"self",
".",
"_resolve_lock",
"=",
"asyncio",
".",
"Lock",
"(",
"loop",
"=",
"client",
".",
... | Helper method to allow event builders to be resolved before usage | [
"Helper",
"method",
"to",
"allow",
"event",
"builders",
"to",
"be",
"resolved",
"before",
"usage"
] | python | train |
explosion/thinc | thinc/extra/_vendorized/keras_generic_utils.py | https://github.com/explosion/thinc/blob/90129be5f0d6c665344245a7c37dbe1b8afceea2/thinc/extra/_vendorized/keras_generic_utils.py#L53-L63 | def func_load(code, defaults=None, closure=None, globs=None):
'''Deserialize user defined function.'''
if isinstance(code, (tuple, list)): # unpack previous dump
code, defaults, closure = code
code = marshal.loads(code.encode('raw_unicode_escape'))
if globs is None:
globs = globals()
... | [
"def",
"func_load",
"(",
"code",
",",
"defaults",
"=",
"None",
",",
"closure",
"=",
"None",
",",
"globs",
"=",
"None",
")",
":",
"if",
"isinstance",
"(",
"code",
",",
"(",
"tuple",
",",
"list",
")",
")",
":",
"# unpack previous dump",
"code",
",",
"d... | Deserialize user defined function. | [
"Deserialize",
"user",
"defined",
"function",
"."
] | python | train |
cmbruns/pyopenvr | src/openvr/__init__.py | https://github.com/cmbruns/pyopenvr/blob/68395d26bb3df6ab1f0f059c38d441f962938be6/src/openvr/__init__.py#L4631-L4639 | def getOverlayErrorNameFromEnum(self, error):
"""
returns a string that corresponds with the specified overlay error. The string will be the name
of the error enum value for all valid error codes
"""
fn = self.function_table.getOverlayErrorNameFromEnum
result = fn(error... | [
"def",
"getOverlayErrorNameFromEnum",
"(",
"self",
",",
"error",
")",
":",
"fn",
"=",
"self",
".",
"function_table",
".",
"getOverlayErrorNameFromEnum",
"result",
"=",
"fn",
"(",
"error",
")",
"return",
"result"
] | returns a string that corresponds with the specified overlay error. The string will be the name
of the error enum value for all valid error codes | [
"returns",
"a",
"string",
"that",
"corresponds",
"with",
"the",
"specified",
"overlay",
"error",
".",
"The",
"string",
"will",
"be",
"the",
"name",
"of",
"the",
"error",
"enum",
"value",
"for",
"all",
"valid",
"error",
"codes"
] | python | train |
aegirhall/console-menu | consolemenu/items/submenu_item.py | https://github.com/aegirhall/console-menu/blob/1a28959d6f1dd6ac79c87b11efd8529d05532422/consolemenu/items/submenu_item.py#L42-L48 | def clean_up(self):
"""
This class overrides this method
"""
self.submenu.join()
self.menu.clear_screen()
self.menu.resume() | [
"def",
"clean_up",
"(",
"self",
")",
":",
"self",
".",
"submenu",
".",
"join",
"(",
")",
"self",
".",
"menu",
".",
"clear_screen",
"(",
")",
"self",
".",
"menu",
".",
"resume",
"(",
")"
] | This class overrides this method | [
"This",
"class",
"overrides",
"this",
"method"
] | python | train |
saltstack/salt | salt/modules/virt.py | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/virt.py#L516-L532 | def _get_migrate_command():
'''
Returns the command shared by the different migration types
'''
tunnel = __salt__['config.option']('virt.tunnel')
if tunnel:
salt.utils.versions.warn_until(
'Sodium',
'\'virt.tunnel\' has been deprecated in favor of '
'\'vir... | [
"def",
"_get_migrate_command",
"(",
")",
":",
"tunnel",
"=",
"__salt__",
"[",
"'config.option'",
"]",
"(",
"'virt.tunnel'",
")",
"if",
"tunnel",
":",
"salt",
".",
"utils",
".",
"versions",
".",
"warn_until",
"(",
"'Sodium'",
",",
"'\\'virt.tunnel\\' has been dep... | Returns the command shared by the different migration types | [
"Returns",
"the",
"command",
"shared",
"by",
"the",
"different",
"migration",
"types"
] | python | train |
ozak/georasters | georasters/georasters.py | https://github.com/ozak/georasters/blob/0612bd91bb2a2cb2f1d59ba89c1ff131dae27d70/georasters/georasters.py#L137-L155 | def create_geotiff(name, Array, driver, ndv, xsize, ysize, geot, projection, datatype, band=1):
'''
Creates new geotiff from array
'''
if isinstance(datatype, np.int) == False:
if datatype.startswith('gdal.GDT_') == False:
datatype = eval('gdal.GDT_'+datatype)
newfilename = name+... | [
"def",
"create_geotiff",
"(",
"name",
",",
"Array",
",",
"driver",
",",
"ndv",
",",
"xsize",
",",
"ysize",
",",
"geot",
",",
"projection",
",",
"datatype",
",",
"band",
"=",
"1",
")",
":",
"if",
"isinstance",
"(",
"datatype",
",",
"np",
".",
"int",
... | Creates new geotiff from array | [
"Creates",
"new",
"geotiff",
"from",
"array"
] | python | train |
django-json-api/django-rest-framework-json-api | rest_framework_json_api/parsers.py | https://github.com/django-json-api/django-rest-framework-json-api/blob/de7021f9e011615ce8b65d0cb38227c6c12721b6/rest_framework_json_api/parsers.py#L85-L153 | def parse(self, stream, media_type=None, parser_context=None):
"""
Parses the incoming bytestream as JSON and returns the resulting data
"""
result = super(JSONParser, self).parse(
stream, media_type=media_type, parser_context=parser_context
)
if not isinstan... | [
"def",
"parse",
"(",
"self",
",",
"stream",
",",
"media_type",
"=",
"None",
",",
"parser_context",
"=",
"None",
")",
":",
"result",
"=",
"super",
"(",
"JSONParser",
",",
"self",
")",
".",
"parse",
"(",
"stream",
",",
"media_type",
"=",
"media_type",
",... | Parses the incoming bytestream as JSON and returns the resulting data | [
"Parses",
"the",
"incoming",
"bytestream",
"as",
"JSON",
"and",
"returns",
"the",
"resulting",
"data"
] | python | train |
jpadilla/django-dotenv | dotenv.py | https://github.com/jpadilla/django-dotenv/blob/16489ebda8716071bdff6b6365aa64b7fa420f17/dotenv.py#L37-L65 | def read_dotenv(dotenv=None, override=False):
"""
Read a .env file into os.environ.
If not given a path to a dotenv path, does filthy magic stack backtracking
to find manage.py and then find the dotenv.
If tests rely on .env files, setting the overwrite flag to True is a safe
way to ensure tes... | [
"def",
"read_dotenv",
"(",
"dotenv",
"=",
"None",
",",
"override",
"=",
"False",
")",
":",
"if",
"dotenv",
"is",
"None",
":",
"frame_filename",
"=",
"sys",
".",
"_getframe",
"(",
")",
".",
"f_back",
".",
"f_code",
".",
"co_filename",
"dotenv",
"=",
"os... | Read a .env file into os.environ.
If not given a path to a dotenv path, does filthy magic stack backtracking
to find manage.py and then find the dotenv.
If tests rely on .env files, setting the overwrite flag to True is a safe
way to ensure tests run consistently across all environments.
:param o... | [
"Read",
"a",
".",
"env",
"file",
"into",
"os",
".",
"environ",
"."
] | python | train |
DAI-Lab/Copulas | copulas/multivariate/vine.py | https://github.com/DAI-Lab/Copulas/blob/821df61c3d36a6b81ef2883935f935c2eaaa862c/copulas/multivariate/vine.py#L127-L137 | def get_likelihood(self, uni_matrix):
"""Compute likelihood of the vine."""
num_tree = len(self.trees)
values = np.empty([1, num_tree])
for i in range(num_tree):
value, new_uni_matrix = self.trees[i].get_likelihood(uni_matrix)
uni_matrix = new_uni_matrix
... | [
"def",
"get_likelihood",
"(",
"self",
",",
"uni_matrix",
")",
":",
"num_tree",
"=",
"len",
"(",
"self",
".",
"trees",
")",
"values",
"=",
"np",
".",
"empty",
"(",
"[",
"1",
",",
"num_tree",
"]",
")",
"for",
"i",
"in",
"range",
"(",
"num_tree",
")",... | Compute likelihood of the vine. | [
"Compute",
"likelihood",
"of",
"the",
"vine",
"."
] | python | train |
lucaslamounier/USGSDownload | usgsdownload/usgs.py | https://github.com/lucaslamounier/USGSDownload/blob/0969483ea9f9648aa17b099f36d2e1010488b2a4/usgsdownload/usgs.py#L193-L215 | def connect_earthexplorer(self):
""" Connection to Earth explorer without proxy """
logger.info("Establishing connection to Earthexplorer")
print("\n Establishing connection to Earthexplorer")
try:
opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor())
... | [
"def",
"connect_earthexplorer",
"(",
"self",
")",
":",
"logger",
".",
"info",
"(",
"\"Establishing connection to Earthexplorer\"",
")",
"print",
"(",
"\"\\n Establishing connection to Earthexplorer\"",
")",
"try",
":",
"opener",
"=",
"urllib",
".",
"request",
".",
"bu... | Connection to Earth explorer without proxy | [
"Connection",
"to",
"Earth",
"explorer",
"without",
"proxy"
] | python | test |
apache/airflow | airflow/contrib/hooks/bigquery_hook.py | https://github.com/apache/airflow/blob/b69c686ad8a0c89b9136bb4b31767257eb7b2597/airflow/contrib/hooks/bigquery_hook.py#L1341-L1353 | def get_schema(self, dataset_id, table_id):
"""
Get the schema for a given datset.table.
see https://cloud.google.com/bigquery/docs/reference/v2/tables#resource
:param dataset_id: the dataset ID of the requested table
:param table_id: the table ID of the requested table
... | [
"def",
"get_schema",
"(",
"self",
",",
"dataset_id",
",",
"table_id",
")",
":",
"tables_resource",
"=",
"self",
".",
"service",
".",
"tables",
"(",
")",
".",
"get",
"(",
"projectId",
"=",
"self",
".",
"project_id",
",",
"datasetId",
"=",
"dataset_id",
",... | Get the schema for a given datset.table.
see https://cloud.google.com/bigquery/docs/reference/v2/tables#resource
:param dataset_id: the dataset ID of the requested table
:param table_id: the table ID of the requested table
:return: a table schema | [
"Get",
"the",
"schema",
"for",
"a",
"given",
"datset",
".",
"table",
".",
"see",
"https",
":",
"//",
"cloud",
".",
"google",
".",
"com",
"/",
"bigquery",
"/",
"docs",
"/",
"reference",
"/",
"v2",
"/",
"tables#resource"
] | python | test |
ctuning/ck | ck/kernel.py | https://github.com/ctuning/ck/blob/7e009814e975f8742790d3106340088a46223714/ck/kernel.py#L6100-L6202 | def update(i):
"""
Input: {
(repo_uoa) - repo UOA
module_uoa - module UOA
data_uoa - data UOA
(data_uid) - data UID (if uoa is an alias)
(data_name) - user friendly data name
... | [
"def",
"update",
"(",
"i",
")",
":",
"# Check if global writing is allowed",
"r",
"=",
"check_writing",
"(",
"{",
"}",
")",
"if",
"r",
"[",
"'return'",
"]",
">",
"0",
":",
"return",
"r",
"# Try to load entry, if doesn't exist, add entry",
"dd",
"=",
"{",
"}",
... | Input: {
(repo_uoa) - repo UOA
module_uoa - module UOA
data_uoa - data UOA
(data_uid) - data UID (if uoa is an alias)
(data_name) - user friendly data name
(dict_from_cid) ... | [
"Input",
":",
"{",
"(",
"repo_uoa",
")",
"-",
"repo",
"UOA",
"module_uoa",
"-",
"module",
"UOA",
"data_uoa",
"-",
"data",
"UOA",
"(",
"data_uid",
")",
"-",
"data",
"UID",
"(",
"if",
"uoa",
"is",
"an",
"alias",
")",
"(",
"data_name",
")",
"-",
"user... | python | train |
planetlabs/es_fluent | es_fluent/filters/geometry.py | https://github.com/planetlabs/es_fluent/blob/74f8db3a1bf9aa1d54512cf2d5e0ec58ee2f4b1c/es_fluent/filters/geometry.py#L84-L99 | def to_query(self):
"""
Returns a json-serializable representation.
"""
return {
"geo_shape": {
self.name: {
"indexed_shape": {
"index": self.index_name,
"type": self.doc_type,
... | [
"def",
"to_query",
"(",
"self",
")",
":",
"return",
"{",
"\"geo_shape\"",
":",
"{",
"self",
".",
"name",
":",
"{",
"\"indexed_shape\"",
":",
"{",
"\"index\"",
":",
"self",
".",
"index_name",
",",
"\"type\"",
":",
"self",
".",
"doc_type",
",",
"\"id\"",
... | Returns a json-serializable representation. | [
"Returns",
"a",
"json",
"-",
"serializable",
"representation",
"."
] | python | train |
callowayproject/Calloway | calloway/apps/django_ext/views.py | https://github.com/callowayproject/Calloway/blob/d22e98d41fbd298ab6393ba7bd84a75528be9f81/calloway/apps/django_ext/views.py#L6-L31 | def custom_server_error(request, template_name='500.html', admin_template_name='500A.html'):
"""
500 error handler. Displays a full trackback for superusers and the first line of the
traceback for staff members.
Templates: `500.html` or `500A.html` (admin)
Context: trace
Holds the traceback... | [
"def",
"custom_server_error",
"(",
"request",
",",
"template_name",
"=",
"'500.html'",
",",
"admin_template_name",
"=",
"'500A.html'",
")",
":",
"trace",
"=",
"None",
"if",
"request",
".",
"user",
".",
"is_authenticated",
"(",
")",
"and",
"(",
"request",
".",
... | 500 error handler. Displays a full trackback for superusers and the first line of the
traceback for staff members.
Templates: `500.html` or `500A.html` (admin)
Context: trace
Holds the traceback information for debugging. | [
"500",
"error",
"handler",
".",
"Displays",
"a",
"full",
"trackback",
"for",
"superusers",
"and",
"the",
"first",
"line",
"of",
"the",
"traceback",
"for",
"staff",
"members",
"."
] | python | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.