repo stringlengths 7 55 | path stringlengths 4 223 | url stringlengths 87 315 | code stringlengths 75 104k | code_tokens list | docstring stringlengths 1 46.9k | docstring_tokens list | language stringclasses 1
value | partition stringclasses 3
values | avg_line_len float64 7.91 980 |
|---|---|---|---|---|---|---|---|---|---|
edeposit/edeposit.amqp.harvester | src/edeposit/amqp/harvester/scrappers/cpress_cz.py | https://github.com/edeposit/edeposit.amqp.harvester/blob/38cb87ccdf6bf2f550a98460d0a329c4b9dc8e2e/src/edeposit/amqp/harvester/scrappers/cpress_cz.py#L205-L227 | def _parse_description(html_chunk):
"""
Parse description of the book.
Args:
html_chunk (obj): HTMLElement containing slice of the page with details.
Returns:
str/None: Description as string or None if not found.
"""
description_tag = html_chunk.match(
["div", {"class":... | [
"def",
"_parse_description",
"(",
"html_chunk",
")",
":",
"description_tag",
"=",
"html_chunk",
".",
"match",
"(",
"[",
"\"div\"",
",",
"{",
"\"class\"",
":",
"\"kniha_detail_text\"",
"}",
"]",
",",
"\"p\"",
")",
"if",
"not",
"description_tag",
":",
"return",
... | Parse description of the book.
Args:
html_chunk (obj): HTMLElement containing slice of the page with details.
Returns:
str/None: Description as string or None if not found. | [
"Parse",
"description",
"of",
"the",
"book",
"."
] | python | train | 26.304348 |
f3at/feat | src/feat/models/effect.py | https://github.com/f3at/feat/blob/15da93fc9d6ec8154f52a9172824e25821195ef8/src/feat/models/effect.py#L127-L136 | def context_value(name):
"""
Returns an effect that drops the current value, and replaces it with
the value from the context with the given name.
"""
def context_value(_value, context, **_params):
return defer.succeed(context[name])
return context_value | [
"def",
"context_value",
"(",
"name",
")",
":",
"def",
"context_value",
"(",
"_value",
",",
"context",
",",
"*",
"*",
"_params",
")",
":",
"return",
"defer",
".",
"succeed",
"(",
"context",
"[",
"name",
"]",
")",
"return",
"context_value"
] | Returns an effect that drops the current value, and replaces it with
the value from the context with the given name. | [
"Returns",
"an",
"effect",
"that",
"drops",
"the",
"current",
"value",
"and",
"replaces",
"it",
"with",
"the",
"value",
"from",
"the",
"context",
"with",
"the",
"given",
"name",
"."
] | python | train | 27.8 |
kmmbvnr/django-any | django_any/models.py | https://github.com/kmmbvnr/django-any/blob/6f64ebd05476e2149e2e71deeefbb10f8edfc412/django_any/models.py#L311-L322 | def any_slug_field(field, **kwargs):
"""
Return random value for SlugField
>>> result = any_field(models.SlugField())
>>> type(result)
<type 'str'>
>>> from django.core.validators import slug_re
>>> re.match(slug_re, result) is not None
True
"""
letters = ascii_letters ... | [
"def",
"any_slug_field",
"(",
"field",
",",
"*",
"*",
"kwargs",
")",
":",
"letters",
"=",
"ascii_letters",
"+",
"digits",
"+",
"'_-'",
"return",
"xunit",
".",
"any_string",
"(",
"letters",
"=",
"letters",
",",
"max_length",
"=",
"field",
".",
"max_length",... | Return random value for SlugField
>>> result = any_field(models.SlugField())
>>> type(result)
<type 'str'>
>>> from django.core.validators import slug_re
>>> re.match(slug_re, result) is not None
True | [
"Return",
"random",
"value",
"for",
"SlugField",
">>>",
"result",
"=",
"any_field",
"(",
"models",
".",
"SlugField",
"()",
")",
">>>",
"type",
"(",
"result",
")",
"<type",
"str",
">",
">>>",
"from",
"django",
".",
"core",
".",
"validators",
"import",
"sl... | python | test | 33.583333 |
sprockets/sprockets.mixins.amqp | sprockets/mixins/amqp/__init__.py | https://github.com/sprockets/sprockets.mixins.amqp/blob/de22b85aec1315bc01e47774637098c34525692b/sprockets/mixins/amqp/__init__.py#L390-L401 | def close(self):
"""Cleanly shutdown the connection to RabbitMQ
:raises: sprockets.mixins.amqp.ConnectionStateError
"""
if not self.closable:
LOGGER.warning('Closed called while %s', self.state_description)
raise ConnectionStateError(self.state_description)
... | [
"def",
"close",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"closable",
":",
"LOGGER",
".",
"warning",
"(",
"'Closed called while %s'",
",",
"self",
".",
"state_description",
")",
"raise",
"ConnectionStateError",
"(",
"self",
".",
"state_description",
")"... | Cleanly shutdown the connection to RabbitMQ
:raises: sprockets.mixins.amqp.ConnectionStateError | [
"Cleanly",
"shutdown",
"the",
"connection",
"to",
"RabbitMQ"
] | python | train | 35.583333 |
mrstephenneal/dirutility | dirutility/backup.py | https://github.com/mrstephenneal/dirutility/blob/339378659e2d7e09c53acfc51c5df745bb0cd517/dirutility/backup.py#L89-L93 | def _backup_pb_tqdm(self, dirs):
"""Create a backup with a tqdm progress bar."""
with ZipFile(self.zip_filename, 'w') as backup_zip:
for path in tqdm(dirs, desc='Writing Zip Files', total=len(dirs)):
backup_zip.write(path, path[len(self.source):len(path)]) | [
"def",
"_backup_pb_tqdm",
"(",
"self",
",",
"dirs",
")",
":",
"with",
"ZipFile",
"(",
"self",
".",
"zip_filename",
",",
"'w'",
")",
"as",
"backup_zip",
":",
"for",
"path",
"in",
"tqdm",
"(",
"dirs",
",",
"desc",
"=",
"'Writing Zip Files'",
",",
"total",
... | Create a backup with a tqdm progress bar. | [
"Create",
"a",
"backup",
"with",
"a",
"tqdm",
"progress",
"bar",
"."
] | python | train | 59.2 |
python-diamond/Diamond | src/collectors/netstat/netstat.py | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/collectors/netstat/netstat.py#L34-L42 | def get_default_config(self):
"""
Returns the default collector settings
"""
config = super(NetstatCollector, self).get_default_config()
config.update({
'path': 'netstat',
})
return config | [
"def",
"get_default_config",
"(",
"self",
")",
":",
"config",
"=",
"super",
"(",
"NetstatCollector",
",",
"self",
")",
".",
"get_default_config",
"(",
")",
"config",
".",
"update",
"(",
"{",
"'path'",
":",
"'netstat'",
",",
"}",
")",
"return",
"config"
] | Returns the default collector settings | [
"Returns",
"the",
"default",
"collector",
"settings"
] | python | train | 28.444444 |
andreikop/python-ws-discovery | wsdiscovery/cmdline.py | https://github.com/andreikop/python-ws-discovery/blob/a7b852cf43115c6f986e509b1870d6963e76687f/wsdiscovery/cmdline.py#L64-L74 | def discover(scope, loglevel, capture):
"Discover systems using WS-Discovery"
if loglevel:
level = getattr(logging, loglevel, None)
if not level:
print("Invalid log level '%s'" % loglevel)
return
logger.setLevel(level)
run(scope=scope, capture=capture) | [
"def",
"discover",
"(",
"scope",
",",
"loglevel",
",",
"capture",
")",
":",
"if",
"loglevel",
":",
"level",
"=",
"getattr",
"(",
"logging",
",",
"loglevel",
",",
"None",
")",
"if",
"not",
"level",
":",
"print",
"(",
"\"Invalid log level '%s'\"",
"%",
"lo... | Discover systems using WS-Discovery | [
"Discover",
"systems",
"using",
"WS",
"-",
"Discovery"
] | python | test | 27.454545 |
libyal/dtfabric | dtfabric/reader.py | https://github.com/libyal/dtfabric/blob/0d2b5719fa257f6e5c661a406737ebcf8c8db266/dtfabric/reader.py#L914-L943 | def _ReadStreamDataTypeDefinition(
self, definitions_registry, definition_values, definition_name,
is_member=False):
"""Reads a stream data type definition.
Args:
definitions_registry (DataTypeDefinitionsRegistry): data type definitions
registry.
definition_values (dict[str, o... | [
"def",
"_ReadStreamDataTypeDefinition",
"(",
"self",
",",
"definitions_registry",
",",
"definition_values",
",",
"definition_name",
",",
"is_member",
"=",
"False",
")",
":",
"if",
"is_member",
":",
"supported_definition_values",
"=",
"(",
"self",
".",
"_SUPPORTED_DEFI... | Reads a stream data type definition.
Args:
definitions_registry (DataTypeDefinitionsRegistry): data type definitions
registry.
definition_values (dict[str, object]): definition values.
definition_name (str): name of the definition.
is_member (Optional[bool]): True if the data type... | [
"Reads",
"a",
"stream",
"data",
"type",
"definition",
"."
] | python | train | 36.866667 |
not-na/peng3d | peng3d/model.py | https://github.com/not-na/peng3d/blob/1151be665b26cc8a479f6307086ba919e4d32d85/peng3d/model.py#L316-L325 | def setParent(self,parent):
"""
Sets the parent of this bone for all entities.
Note that this method must be called before many other methods to ensure internal state has been initialized.
This method also registers this bone as a child of its parent.
"""
... | [
"def",
"setParent",
"(",
"self",
",",
"parent",
")",
":",
"self",
".",
"parent",
"=",
"parent",
"self",
".",
"parent",
".",
"child_bones",
"[",
"self",
".",
"name",
"]",
"=",
"self"
] | Sets the parent of this bone for all entities.
Note that this method must be called before many other methods to ensure internal state has been initialized.
This method also registers this bone as a child of its parent. | [
"Sets",
"the",
"parent",
"of",
"this",
"bone",
"for",
"all",
"entities",
".",
"Note",
"that",
"this",
"method",
"must",
"be",
"called",
"before",
"many",
"other",
"methods",
"to",
"ensure",
"internal",
"state",
"has",
"been",
"initialized",
".",
"This",
"m... | python | test | 38.1 |
Julius2342/pyvlx | pyvlx/opening_device.py | https://github.com/Julius2342/pyvlx/blob/ee78e1324bcb1be5b8d1a9d05ab5496b72eae848/pyvlx/opening_device.py#L43-L53 | async def open(self, wait_for_completion=True):
"""Open window.
Parameters:
* wait_for_completion: If set, function will return
after device has reached target position.
"""
await self.set_position(
position=Position(position_percent=0),
... | [
"async",
"def",
"open",
"(",
"self",
",",
"wait_for_completion",
"=",
"True",
")",
":",
"await",
"self",
".",
"set_position",
"(",
"position",
"=",
"Position",
"(",
"position_percent",
"=",
"0",
")",
",",
"wait_for_completion",
"=",
"wait_for_completion",
")"
... | Open window.
Parameters:
* wait_for_completion: If set, function will return
after device has reached target position. | [
"Open",
"window",
"."
] | python | train | 32.181818 |
heitzmann/gdspy | gdspy/__init__.py | https://github.com/heitzmann/gdspy/blob/2c8d1313248c544e2066d19095b7ad7158c79bc9/gdspy/__init__.py#L3322-L3352 | def add(self, cell, overwrite_duplicate=False):
"""
Add one or more cells to the library.
Parameters
----------
cell : ``Cell`` of list of ``Cell``
Cells to be included in the library.
overwrite_duplicate : bool
If True an existing cell with the s... | [
"def",
"add",
"(",
"self",
",",
"cell",
",",
"overwrite_duplicate",
"=",
"False",
")",
":",
"if",
"isinstance",
"(",
"cell",
",",
"Cell",
")",
":",
"if",
"(",
"not",
"overwrite_duplicate",
"and",
"cell",
".",
"name",
"in",
"self",
".",
"cell_dict",
"an... | Add one or more cells to the library.
Parameters
----------
cell : ``Cell`` of list of ``Cell``
Cells to be included in the library.
overwrite_duplicate : bool
If True an existing cell with the same name in the library
will be overwritten.
Re... | [
"Add",
"one",
"or",
"more",
"cells",
"to",
"the",
"library",
"."
] | python | train | 38.290323 |
log2timeline/plaso | plaso/parsers/plist_plugins/airport.py | https://github.com/log2timeline/plaso/blob/9c564698d2da3ffbe23607a3c54c0582ea18a6cc/plaso/parsers/plist_plugins/airport.py#L25-L57 | def GetEntries(self, parser_mediator, match=None, **unused_kwargs):
"""Extracts relevant Airport entries.
Args:
parser_mediator (ParserMediator): mediates interactions between parsers
and other components, such as storage and dfvfs.
match (Optional[dict[str: object]]): keys extracted from... | [
"def",
"GetEntries",
"(",
"self",
",",
"parser_mediator",
",",
"match",
"=",
"None",
",",
"*",
"*",
"unused_kwargs",
")",
":",
"if",
"'RememberedNetworks'",
"not",
"in",
"match",
":",
"return",
"for",
"wifi",
"in",
"match",
"[",
"'RememberedNetworks'",
"]",
... | Extracts relevant Airport entries.
Args:
parser_mediator (ParserMediator): mediates interactions between parsers
and other components, such as storage and dfvfs.
match (Optional[dict[str: object]]): keys extracted from PLIST_KEYS. | [
"Extracts",
"relevant",
"Airport",
"entries",
"."
] | python | train | 38.212121 |
mikedh/trimesh | trimesh/collision.py | https://github.com/mikedh/trimesh/blob/25e059bf6d4caa74f62ffd58ce4f61a90ee4e518/trimesh/collision.py#L373-L439 | def in_collision_other(self, other_manager,
return_names=False, return_data=False):
"""
Check if any object from this manager collides with any object
from another manager.
Parameters
-------------------
other_manager : CollisionManager
... | [
"def",
"in_collision_other",
"(",
"self",
",",
"other_manager",
",",
"return_names",
"=",
"False",
",",
"return_data",
"=",
"False",
")",
":",
"cdata",
"=",
"fcl",
".",
"CollisionData",
"(",
")",
"if",
"return_names",
"or",
"return_data",
":",
"cdata",
"=",
... | Check if any object from this manager collides with any object
from another manager.
Parameters
-------------------
other_manager : CollisionManager
Another collision manager object
return_names : bool
If true, a set is returned containing the names
... | [
"Check",
"if",
"any",
"object",
"from",
"this",
"manager",
"collides",
"with",
"any",
"object",
"from",
"another",
"manager",
"."
] | python | train | 37.373134 |
miguelgrinberg/python-socketio | socketio/asyncio_namespace.py | https://github.com/miguelgrinberg/python-socketio/blob/c0c1bf8d21e3597389b18938550a0724dd9676b7/socketio/asyncio_namespace.py#L73-L83 | async def close_room(self, room, namespace=None):
"""Close a room.
The only difference with the :func:`socketio.Server.close_room` method
is that when the ``namespace`` argument is not given the namespace
associated with the class is used.
Note: this method is a coroutine.
... | [
"async",
"def",
"close_room",
"(",
"self",
",",
"room",
",",
"namespace",
"=",
"None",
")",
":",
"return",
"await",
"self",
".",
"server",
".",
"close_room",
"(",
"room",
",",
"namespace",
"=",
"namespace",
"or",
"self",
".",
"namespace",
")"
] | Close a room.
The only difference with the :func:`socketio.Server.close_room` method
is that when the ``namespace`` argument is not given the namespace
associated with the class is used.
Note: this method is a coroutine. | [
"Close",
"a",
"room",
"."
] | python | train | 38.090909 |
ralphje/imagemounter | imagemounter/volume_system.py | https://github.com/ralphje/imagemounter/blob/86213781c366cad65096447d91f522f0a3fb4b93/imagemounter/volume_system.py#L411-L482 | def detect(self, volume_system, vstype='detect'):
"""Finds and mounts all volumes based on mmls."""
try:
cmd = ['mmls']
if volume_system.parent.offset:
cmd.extend(['-o', str(volume_system.parent.offset // volume_system.disk.block_size)])
if vstype in ... | [
"def",
"detect",
"(",
"self",
",",
"volume_system",
",",
"vstype",
"=",
"'detect'",
")",
":",
"try",
":",
"cmd",
"=",
"[",
"'mmls'",
"]",
"if",
"volume_system",
".",
"parent",
".",
"offset",
":",
"cmd",
".",
"extend",
"(",
"[",
"'-o'",
",",
"str",
... | Finds and mounts all volumes based on mmls. | [
"Finds",
"and",
"mounts",
"all",
"volumes",
"based",
"on",
"mmls",
"."
] | python | train | 48.166667 |
cltk/cltk | cltk/inflection/old_norse/verbs.py | https://github.com/cltk/cltk/blob/ed9c025b7ec43c949481173251b70e05e4dffd27/cltk/inflection/old_norse/verbs.py#L855-L892 | def past_active(self):
"""
Weak verbs
I
>>> verb = WeakOldNorseVerb()
>>> verb.set_canonic_forms(["kalla", "kallaði", "kallaðinn"])
>>> verb.past_active()
['kallaða', 'kallaðir', 'kallaði', 'kölluðum', 'kölluðuð', 'kölluðu']
II
>>> verb = WeakOldN... | [
"def",
"past_active",
"(",
"self",
")",
":",
"forms",
"=",
"[",
"]",
"stem",
"=",
"self",
".",
"sfg3et",
"[",
":",
"-",
"1",
"]",
"forms",
".",
"append",
"(",
"stem",
"+",
"\"a\"",
")",
"forms",
".",
"append",
"(",
"self",
".",
"sfg3et",
"+",
"... | Weak verbs
I
>>> verb = WeakOldNorseVerb()
>>> verb.set_canonic_forms(["kalla", "kallaði", "kallaðinn"])
>>> verb.past_active()
['kallaða', 'kallaðir', 'kallaði', 'kölluðum', 'kölluðuð', 'kölluðu']
II
>>> verb = WeakOldNorseVerb()
>>> verb.set_canonic_for... | [
"Weak",
"verbs",
"I",
">>>",
"verb",
"=",
"WeakOldNorseVerb",
"()",
">>>",
"verb",
".",
"set_canonic_forms",
"(",
"[",
"kalla",
"kallaði",
"kallaðinn",
"]",
")",
">>>",
"verb",
".",
"past_active",
"()",
"[",
"kallaða",
"kallaðir",
"kallaði",
"kölluðum",
"köl... | python | train | 32.210526 |
cloudant/python-cloudant | src/cloudant/client.py | https://github.com/cloudant/python-cloudant/blob/e0ba190f6ba07fe3522a668747128214ad573c7e/src/cloudant/client.py#L145-L194 | def connect(self):
"""
Starts up an authentication session for the client using cookie
authentication if necessary.
"""
if self.r_session:
self.session_logout()
if self.admin_party:
self._use_iam = False
self.r_session = ClientSession(... | [
"def",
"connect",
"(",
"self",
")",
":",
"if",
"self",
".",
"r_session",
":",
"self",
".",
"session_logout",
"(",
")",
"if",
"self",
".",
"admin_party",
":",
"self",
".",
"_use_iam",
"=",
"False",
"self",
".",
"r_session",
"=",
"ClientSession",
"(",
"t... | Starts up an authentication session for the client using cookie
authentication if necessary. | [
"Starts",
"up",
"an",
"authentication",
"session",
"for",
"the",
"client",
"using",
"cookie",
"authentication",
"if",
"necessary",
"."
] | python | train | 34.12 |
watson-developer-cloud/python-sdk | ibm_watson/natural_language_understanding_v1.py | https://github.com/watson-developer-cloud/python-sdk/blob/4c2c9df4466fcde88975da9ecd834e6ba95eb353/ibm_watson/natural_language_understanding_v1.py#L689-L696 | def _to_dict(self):
"""Return a json dictionary representing this model."""
_dict = {}
if hasattr(self, 'limit') and self.limit is not None:
_dict['limit'] = self.limit
if hasattr(self, 'model') and self.model is not None:
_dict['model'] = self.model
retur... | [
"def",
"_to_dict",
"(",
"self",
")",
":",
"_dict",
"=",
"{",
"}",
"if",
"hasattr",
"(",
"self",
",",
"'limit'",
")",
"and",
"self",
".",
"limit",
"is",
"not",
"None",
":",
"_dict",
"[",
"'limit'",
"]",
"=",
"self",
".",
"limit",
"if",
"hasattr",
... | Return a json dictionary representing this model. | [
"Return",
"a",
"json",
"dictionary",
"representing",
"this",
"model",
"."
] | python | train | 40 |
KE-works/pykechain | pykechain/models/scope.py | https://github.com/KE-works/pykechain/blob/b0296cf34328fd41660bf6f0b9114fd0167c40c4/pykechain/models/scope.py#L199-L211 | def add_member(self, member):
"""
Add a single member to the scope.
You may only edit the list of members if the pykechain credentials allow this.
:param member: single username to be added to the scope list of members
:type member: basestring
:raises APIError: when una... | [
"def",
"add_member",
"(",
"self",
",",
"member",
")",
":",
"select_action",
"=",
"'add_member'",
"self",
".",
"_update_scope_project_team",
"(",
"select_action",
"=",
"select_action",
",",
"user",
"=",
"member",
",",
"user_type",
"=",
"'member'",
")"
] | Add a single member to the scope.
You may only edit the list of members if the pykechain credentials allow this.
:param member: single username to be added to the scope list of members
:type member: basestring
:raises APIError: when unable to update the scope member | [
"Add",
"a",
"single",
"member",
"to",
"the",
"scope",
"."
] | python | train | 37.692308 |
DinoTools/python-overpy | overpy/__init__.py | https://github.com/DinoTools/python-overpy/blob/db8f80eeb1b4d1405816bd62c16ddb3364e0c46d/overpy/__init__.py#L586-L594 | def get_ways(self, way_id=None, **kwargs):
"""
Alias for get_elements() but filter the result by Way
:param way_id: The Id of the way
:type way_id: Integer
:return: List of elements
"""
return self.get_elements(Way, elem_id=way_id, **kwargs) | [
"def",
"get_ways",
"(",
"self",
",",
"way_id",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"self",
".",
"get_elements",
"(",
"Way",
",",
"elem_id",
"=",
"way_id",
",",
"*",
"*",
"kwargs",
")"
] | Alias for get_elements() but filter the result by Way
:param way_id: The Id of the way
:type way_id: Integer
:return: List of elements | [
"Alias",
"for",
"get_elements",
"()",
"but",
"filter",
"the",
"result",
"by",
"Way"
] | python | train | 32.222222 |
wandb/client | wandb/vendor/prompt_toolkit/layout/mouse_handlers.py | https://github.com/wandb/client/blob/7d08954ed5674fee223cd85ed0d8518fe47266b2/wandb/vendor/prompt_toolkit/layout/mouse_handlers.py#L24-L29 | def set_mouse_handler_for_range(self, x_min, x_max, y_min, y_max, handler=None):
"""
Set mouse handler for a region.
"""
for x, y in product(range(x_min, x_max), range(y_min, y_max)):
self.mouse_handlers[x,y] = handler | [
"def",
"set_mouse_handler_for_range",
"(",
"self",
",",
"x_min",
",",
"x_max",
",",
"y_min",
",",
"y_max",
",",
"handler",
"=",
"None",
")",
":",
"for",
"x",
",",
"y",
"in",
"product",
"(",
"range",
"(",
"x_min",
",",
"x_max",
")",
",",
"range",
"(",... | Set mouse handler for a region. | [
"Set",
"mouse",
"handler",
"for",
"a",
"region",
"."
] | python | train | 42.833333 |
pantsbuild/pants | src/python/pants/engine/build_files.py | https://github.com/pantsbuild/pants/blob/b72e650da0df685824ffdcc71988b8c282d0962d/src/python/pants/engine/build_files.py#L80-L164 | def hydrate_struct(address_mapper, address):
"""Given an AddressMapper and an Address, resolve a Struct from a BUILD file.
Recursively collects any embedded addressables within the Struct, but will not walk into a
dependencies field, since those should be requested explicitly by rules.
"""
address_family = ... | [
"def",
"hydrate_struct",
"(",
"address_mapper",
",",
"address",
")",
":",
"address_family",
"=",
"yield",
"Get",
"(",
"AddressFamily",
",",
"Dir",
"(",
"address",
".",
"spec_path",
")",
")",
"struct",
"=",
"address_family",
".",
"addressables",
".",
"get",
"... | Given an AddressMapper and an Address, resolve a Struct from a BUILD file.
Recursively collects any embedded addressables within the Struct, but will not walk into a
dependencies field, since those should be requested explicitly by rules. | [
"Given",
"an",
"AddressMapper",
"and",
"an",
"Address",
"resolve",
"a",
"Struct",
"from",
"a",
"BUILD",
"file",
"."
] | python | train | 44.752941 |
graphql-python/graphql-core-next | graphql/utilities/schema_printer.py | https://github.com/graphql-python/graphql-core-next/blob/073dce3f002f897d40f9348ffd8f107815160540/graphql/utilities/schema_printer.py#L306-L308 | def print_value(value: Any, type_: GraphQLInputType) -> str:
"""Convenience function for printing a Python value"""
return print_ast(ast_from_value(value, type_)) | [
"def",
"print_value",
"(",
"value",
":",
"Any",
",",
"type_",
":",
"GraphQLInputType",
")",
"->",
"str",
":",
"return",
"print_ast",
"(",
"ast_from_value",
"(",
"value",
",",
"type_",
")",
")"
] | Convenience function for printing a Python value | [
"Convenience",
"function",
"for",
"printing",
"a",
"Python",
"value"
] | python | train | 56 |
guaix-ucm/numina | numina/array/wavecalib/resample.py | https://github.com/guaix-ucm/numina/blob/6c829495df8937f77c2de9383c1038ffb3e713e3/numina/array/wavecalib/resample.py#L102-L132 | def shiftx_image2d_flux(image2d_orig, xoffset):
"""Resample 2D image using a shift in the x direction (flux is preserved).
Parameters
----------
image2d_orig : numpy array
2D image to be resampled.
xoffset : float
Offset to be applied.
Returns
-------
image2d_resampled ... | [
"def",
"shiftx_image2d_flux",
"(",
"image2d_orig",
",",
"xoffset",
")",
":",
"if",
"image2d_orig",
".",
"ndim",
"==",
"1",
":",
"naxis1",
"=",
"image2d_orig",
".",
"size",
"elif",
"image2d_orig",
".",
"ndim",
"==",
"2",
":",
"naxis2",
",",
"naxis1",
"=",
... | Resample 2D image using a shift in the x direction (flux is preserved).
Parameters
----------
image2d_orig : numpy array
2D image to be resampled.
xoffset : float
Offset to be applied.
Returns
-------
image2d_resampled : numpy array
Resampled 2D image. | [
"Resample",
"2D",
"image",
"using",
"a",
"shift",
"in",
"the",
"x",
"direction",
"(",
"flux",
"is",
"preserved",
")",
"."
] | python | train | 28.806452 |
alexras/pylsdj | pylsdj/instrument.py | https://github.com/alexras/pylsdj/blob/1c45a7919dd324e941f76b315558b9647892e4d5/pylsdj/instrument.py#L79-L86 | def import_lsdinst(self, struct_data):
"""import from an lsdinst struct"""
self.name = struct_data['name']
self.automate = struct_data['data']['automate']
self.pan = struct_data['data']['pan']
if self.table is not None:
self.table.import_lsdinst(struct_data) | [
"def",
"import_lsdinst",
"(",
"self",
",",
"struct_data",
")",
":",
"self",
".",
"name",
"=",
"struct_data",
"[",
"'name'",
"]",
"self",
".",
"automate",
"=",
"struct_data",
"[",
"'data'",
"]",
"[",
"'automate'",
"]",
"self",
".",
"pan",
"=",
"struct_dat... | import from an lsdinst struct | [
"import",
"from",
"an",
"lsdinst",
"struct"
] | python | train | 38 |
edeposit/edeposit.amqp.harvester | src/edeposit/amqp/harvester/scrappers/zonerpress_cz/zonerpress_api.py | https://github.com/edeposit/edeposit.amqp.harvester/blob/38cb87ccdf6bf2f550a98460d0a329c4b9dc8e2e/src/edeposit/amqp/harvester/scrappers/zonerpress_cz/zonerpress_api.py#L115-L158 | def has_neigh(tag_name, params=None, content=None, left=True):
"""
This function generates functions, which matches all tags with neighbours
defined by parameters.
Args:
tag_name (str): Tag has to have neighbour with this tagname.
params (dict): Tag has to have neighbour with this param... | [
"def",
"has_neigh",
"(",
"tag_name",
",",
"params",
"=",
"None",
",",
"content",
"=",
"None",
",",
"left",
"=",
"True",
")",
":",
"def",
"has_neigh_closure",
"(",
"element",
")",
":",
"if",
"not",
"element",
".",
"parent",
"or",
"not",
"(",
"element",
... | This function generates functions, which matches all tags with neighbours
defined by parameters.
Args:
tag_name (str): Tag has to have neighbour with this tagname.
params (dict): Tag has to have neighbour with this parameters.
params (str): Tag has to have neighbour with this content.
... | [
"This",
"function",
"generates",
"functions",
"which",
"matches",
"all",
"tags",
"with",
"neighbours",
"defined",
"by",
"parameters",
"."
] | python | train | 32.909091 |
apache/spark | python/pyspark/streaming/dstream.py | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/streaming/dstream.py#L239-L245 | def groupByKey(self, numPartitions=None):
"""
Return a new DStream by applying groupByKey on each RDD.
"""
if numPartitions is None:
numPartitions = self._sc.defaultParallelism
return self.transform(lambda rdd: rdd.groupByKey(numPartitions)) | [
"def",
"groupByKey",
"(",
"self",
",",
"numPartitions",
"=",
"None",
")",
":",
"if",
"numPartitions",
"is",
"None",
":",
"numPartitions",
"=",
"self",
".",
"_sc",
".",
"defaultParallelism",
"return",
"self",
".",
"transform",
"(",
"lambda",
"rdd",
":",
"rd... | Return a new DStream by applying groupByKey on each RDD. | [
"Return",
"a",
"new",
"DStream",
"by",
"applying",
"groupByKey",
"on",
"each",
"RDD",
"."
] | python | train | 41 |
KxSystems/pyq | src/pyq/__init__.py | https://github.com/KxSystems/pyq/blob/ad7b807abde94615a7344aaa930bb01fb1552cc5/src/pyq/__init__.py#L485-L497 | def update(self, columns=(), by=(), where=(), **kwds):
"""update from self
>>> t = q('([]a:1 2 3; b:10 20 30)')
>>> t.update('a*2',
... where='b > 20').show() # doctest: +NORMALIZE_WHITESPACE
a b
----
1 10
2 20
6 30
"""
r... | [
"def",
"update",
"(",
"self",
",",
"columns",
"=",
"(",
")",
",",
"by",
"=",
"(",
")",
",",
"where",
"=",
"(",
")",
",",
"*",
"*",
"kwds",
")",
":",
"return",
"self",
".",
"_seu",
"(",
"'update'",
",",
"columns",
",",
"by",
",",
"where",
",",... | update from self
>>> t = q('([]a:1 2 3; b:10 20 30)')
>>> t.update('a*2',
... where='b > 20').show() # doctest: +NORMALIZE_WHITESPACE
a b
----
1 10
2 20
6 30 | [
"update",
"from",
"self"
] | python | train | 27.615385 |
skyfielders/python-skyfield | skyfield/timelib.py | https://github.com/skyfielders/python-skyfield/blob/51d9e042e06457f6b1f2415296d50a38cb3a300f/skyfield/timelib.py#L540-L557 | def _utc_year(self):
"""Return a fractional UTC year, for convenience when plotting.
An experiment, probably superseded by the ``J`` attribute below.
"""
d = self._utc_float() - 1721059.5
#d += offset
C = 365 * 100 + 24
d -= 365
d += d // C - d // (4 * C... | [
"def",
"_utc_year",
"(",
"self",
")",
":",
"d",
"=",
"self",
".",
"_utc_float",
"(",
")",
"-",
"1721059.5",
"#d += offset",
"C",
"=",
"365",
"*",
"100",
"+",
"24",
"d",
"-=",
"365",
"d",
"+=",
"d",
"//",
"C",
"-",
"d",
"//",
"(",
"4",
"*",
"C... | Return a fractional UTC year, for convenience when plotting.
An experiment, probably superseded by the ``J`` attribute below. | [
"Return",
"a",
"fractional",
"UTC",
"year",
"for",
"convenience",
"when",
"plotting",
"."
] | python | train | 26.388889 |
budacom/trading-bots | trading_bots/contrib/clients.py | https://github.com/budacom/trading-bots/blob/8cb68bb8d0b5f822108db1cc5dae336e3d3c3452/trading_bots/contrib/clients.py#L424-L426 | def fetch_open_orders(self, limit: int) -> List[Order]:
"""Fetch latest open orders, must provide a limit."""
return self._fetch_orders_limit(self._open_orders, limit) | [
"def",
"fetch_open_orders",
"(",
"self",
",",
"limit",
":",
"int",
")",
"->",
"List",
"[",
"Order",
"]",
":",
"return",
"self",
".",
"_fetch_orders_limit",
"(",
"self",
".",
"_open_orders",
",",
"limit",
")"
] | Fetch latest open orders, must provide a limit. | [
"Fetch",
"latest",
"open",
"orders",
"must",
"provide",
"a",
"limit",
"."
] | python | train | 60.333333 |
aws/aws-encryption-sdk-python | src/aws_encryption_sdk/internal/formatting/deserialize.py | https://github.com/aws/aws-encryption-sdk-python/blob/d182155d5fb1ef176d9e7d0647679737d5146495/src/aws_encryption_sdk/internal/formatting/deserialize.py#L76-L88 | def _verified_version_from_id(version_id):
# type: (int) -> SerializationVersion
"""Load a message :class:`SerializationVersion` for the specified version ID.
:param int version_id: Message format version ID
:return: Message format version
:rtype: SerializationVersion
:raises NotSupportedError:... | [
"def",
"_verified_version_from_id",
"(",
"version_id",
")",
":",
"# type: (int) -> SerializationVersion",
"try",
":",
"return",
"SerializationVersion",
"(",
"version_id",
")",
"except",
"ValueError",
"as",
"error",
":",
"raise",
"NotSupportedError",
"(",
"\"Unsupported ve... | Load a message :class:`SerializationVersion` for the specified version ID.
:param int version_id: Message format version ID
:return: Message format version
:rtype: SerializationVersion
:raises NotSupportedError: if unsupported version ID is received | [
"Load",
"a",
"message",
":",
"class",
":",
"SerializationVersion",
"for",
"the",
"specified",
"version",
"ID",
"."
] | python | train | 40.538462 |
robinandeer/puzzle | puzzle/log.py | https://github.com/robinandeer/puzzle/blob/9476f05b416d3a5135d25492cb31411fdf831c58/puzzle/log.py#L7-L31 | def configure_stream(level='WARNING'):
"""Configure root logger using a standard stream handler.
Args:
level (string, optional): lowest level to log to the console
Returns:
logging.RootLogger: root logger instance with attached handler
"""
# get the root logger
root_logger = lo... | [
"def",
"configure_stream",
"(",
"level",
"=",
"'WARNING'",
")",
":",
"# get the root logger",
"root_logger",
"=",
"logging",
".",
"getLogger",
"(",
")",
"# set the logger level to the same as will be used by the handler",
"root_logger",
".",
"setLevel",
"(",
"level",
")",... | Configure root logger using a standard stream handler.
Args:
level (string, optional): lowest level to log to the console
Returns:
logging.RootLogger: root logger instance with attached handler | [
"Configure",
"root",
"logger",
"using",
"a",
"standard",
"stream",
"handler",
"."
] | python | train | 31.44 |
coinbase/coinbase-python | coinbase/wallet/client.py | https://github.com/coinbase/coinbase-python/blob/497c28158f529e8c7d0228521b4386a890baf088/coinbase/wallet/client.py#L534-L539 | def commit_withdrawal(self, account_id, withdrawal_id, **params):
"""https://developers.coinbase.com/api/v2#commit-a-withdrawal"""
response = self._post(
'v2', 'accounts', account_id, 'withdrawals', withdrawal_id, 'commit',
data=params)
return self._make_api_object(respon... | [
"def",
"commit_withdrawal",
"(",
"self",
",",
"account_id",
",",
"withdrawal_id",
",",
"*",
"*",
"params",
")",
":",
"response",
"=",
"self",
".",
"_post",
"(",
"'v2'",
",",
"'accounts'",
",",
"account_id",
",",
"'withdrawals'",
",",
"withdrawal_id",
",",
... | https://developers.coinbase.com/api/v2#commit-a-withdrawal | [
"https",
":",
"//",
"developers",
".",
"coinbase",
".",
"com",
"/",
"api",
"/",
"v2#commit",
"-",
"a",
"-",
"withdrawal"
] | python | train | 55 |
skggm/skggm | inverse_covariance/profiling/graphs.py | https://github.com/skggm/skggm/blob/a0ed406586c4364ea3297a658f415e13b5cbdaf8/inverse_covariance/profiling/graphs.py#L5-L61 | def lattice(prng, n_features, alpha, random_sign=False, low=0.3, high=0.7):
"""Returns the adjacency matrix for a lattice network.
The resulting network is a Toeplitz matrix with random values summing
between -1 and 1 and zeros along the diagonal.
The range of the values can be controlled via the para... | [
"def",
"lattice",
"(",
"prng",
",",
"n_features",
",",
"alpha",
",",
"random_sign",
"=",
"False",
",",
"low",
"=",
"0.3",
",",
"high",
"=",
"0.7",
")",
":",
"degree",
"=",
"int",
"(",
"1",
"+",
"np",
".",
"round",
"(",
"alpha",
"*",
"n_features",
... | Returns the adjacency matrix for a lattice network.
The resulting network is a Toeplitz matrix with random values summing
between -1 and 1 and zeros along the diagonal.
The range of the values can be controlled via the parameters low and high.
If random_sign is false, all entries will be negative, oth... | [
"Returns",
"the",
"adjacency",
"matrix",
"for",
"a",
"lattice",
"network",
"."
] | python | train | 34.561404 |
miso-belica/sumy | sumy/evaluation/content_based.py | https://github.com/miso-belica/sumy/blob/099ab4938e2c1b6a011297375586bac2953641b9/sumy/evaluation/content_based.py#L36-L57 | def unit_overlap(evaluated_model, reference_model):
"""
Computes unit overlap of two text documents. Documents
has to be represented as TF models of non-empty document.
:returns float:
0 <= overlap <= 1, where 0 means no match and 1 means
exactly the same.
"""
if not (isinstance... | [
"def",
"unit_overlap",
"(",
"evaluated_model",
",",
"reference_model",
")",
":",
"if",
"not",
"(",
"isinstance",
"(",
"evaluated_model",
",",
"TfModel",
")",
"and",
"isinstance",
"(",
"reference_model",
",",
"TfModel",
")",
")",
":",
"raise",
"ValueError",
"("... | Computes unit overlap of two text documents. Documents
has to be represented as TF models of non-empty document.
:returns float:
0 <= overlap <= 1, where 0 means no match and 1 means
exactly the same. | [
"Computes",
"unit",
"overlap",
"of",
"two",
"text",
"documents",
".",
"Documents",
"has",
"to",
"be",
"represented",
"as",
"TF",
"models",
"of",
"non",
"-",
"empty",
"document",
"."
] | python | train | 37.636364 |
textbook/atmdb | atmdb/client.py | https://github.com/textbook/atmdb/blob/cab14547d2e777a1e26c2560266365c484855789/atmdb/client.py#L59-L94 | async def get_data(self, url):
"""Get data from the TMDb API via :py:func:`aiohttp.get`.
Notes:
Updates configuration (if required) on successful requests.
Arguments:
url (:py:class:`str`): The endpoint URL and params.
Returns:
:py:class:`dict`: The parse... | [
"async",
"def",
"get_data",
"(",
"self",
",",
"url",
")",
":",
"logger",
".",
"debug",
"(",
"'making request to %r'",
",",
"url",
")",
"with",
"aiohttp",
".",
"ClientSession",
"(",
")",
"as",
"session",
":",
"async",
"with",
"session",
".",
"get",
"(",
... | Get data from the TMDb API via :py:func:`aiohttp.get`.
Notes:
Updates configuration (if required) on successful requests.
Arguments:
url (:py:class:`str`): The endpoint URL and params.
Returns:
:py:class:`dict`: The parsed JSON result. | [
"Get",
"data",
"from",
"the",
"TMDb",
"API",
"via",
":",
"py",
":",
"func",
":",
"aiohttp",
".",
"get",
"."
] | python | train | 39.527778 |
libyal/libbde | setup.py | https://github.com/libyal/libbde/blob/5f59d11dbb52690b4155f2cc3fcb1ac512d076a8/setup.py#L60-L75 | def _RunCommand(self, command):
"""Runs the command."""
arguments = shlex.split(command)
process = subprocess.Popen(
arguments, stderr=subprocess.PIPE, stdout=subprocess.PIPE,
universal_newlines=True)
if not process:
raise RuntimeError("Running: {0:s} failed.".format(command))
... | [
"def",
"_RunCommand",
"(",
"self",
",",
"command",
")",
":",
"arguments",
"=",
"shlex",
".",
"split",
"(",
"command",
")",
"process",
"=",
"subprocess",
".",
"Popen",
"(",
"arguments",
",",
"stderr",
"=",
"subprocess",
".",
"PIPE",
",",
"stdout",
"=",
... | Runs the command. | [
"Runs",
"the",
"command",
"."
] | python | train | 34.125 |
assemblerflow/flowcraft | flowcraft/templates/process_viral_assembly.py | https://github.com/assemblerflow/flowcraft/blob/fc3f4bddded1efc76006600016dc71a06dd908c0/flowcraft/templates/process_viral_assembly.py#L451-L562 | def main(sample_id, assembly_file, minsize):
"""Main executor of the process_mapping template.
Parameters
----------
sample_id : str
Sample Identification string.
assembly: str
Path to the fatsa file generated by the assembler.
minsize: str
Min contig size to be consider... | [
"def",
"main",
"(",
"sample_id",
",",
"assembly_file",
",",
"minsize",
")",
":",
"logger",
".",
"info",
"(",
"\"Starting assembly file processing\"",
")",
"warnings",
"=",
"[",
"]",
"fails",
"=",
"\"\"",
"# Parse the spades assembly file and perform the first filtering.... | Main executor of the process_mapping template.
Parameters
----------
sample_id : str
Sample Identification string.
assembly: str
Path to the fatsa file generated by the assembler.
minsize: str
Min contig size to be considered a complete ORF | [
"Main",
"executor",
"of",
"the",
"process_mapping",
"template",
"."
] | python | test | 33.3125 |
mseclab/PyJFuzz | pyjfuzz/core/pjf_mutators.py | https://github.com/mseclab/PyJFuzz/blob/f777067076f62c9ab74ffea6e90fd54402b7a1b4/pyjfuzz/core/pjf_mutators.py#L133-L140 | def get_mutator(self, obj, obj_type):
"""
Get a random mutator for the given type
"""
if obj_type == unicode:
obj_type = str
obj = str(obj)
return self._get_random(obj_type)(obj) | [
"def",
"get_mutator",
"(",
"self",
",",
"obj",
",",
"obj_type",
")",
":",
"if",
"obj_type",
"==",
"unicode",
":",
"obj_type",
"=",
"str",
"obj",
"=",
"str",
"(",
"obj",
")",
"return",
"self",
".",
"_get_random",
"(",
"obj_type",
")",
"(",
"obj",
")"
... | Get a random mutator for the given type | [
"Get",
"a",
"random",
"mutator",
"for",
"the",
"given",
"type"
] | python | test | 29.375 |
fr33jc/bang | bang/providers/hpcloud/load_balancer.py | https://github.com/fr33jc/bang/blob/8f000713f88d2a9a8c1193b63ca10a6578560c16/bang/providers/hpcloud/load_balancer.py#L60-L75 | def find_lb_by_name(self, name):
"""
Look up a LBaaS instance by name (rather than id)
:attr string name: The LBaaS name assigned at creation time
:rtype :class:`dict`
"""
log.debug("Finding load balancers matching name '%s'" % name)
matching = filter(lambda l:... | [
"def",
"find_lb_by_name",
"(",
"self",
",",
"name",
")",
":",
"log",
".",
"debug",
"(",
"\"Finding load balancers matching name '%s'\"",
"%",
"name",
")",
"matching",
"=",
"filter",
"(",
"lambda",
"l",
":",
"l",
"[",
"'name'",
"]",
"==",
"name",
",",
"self... | Look up a LBaaS instance by name (rather than id)
:attr string name: The LBaaS name assigned at creation time
:rtype :class:`dict` | [
"Look",
"up",
"a",
"LBaaS",
"instance",
"by",
"name",
"(",
"rather",
"than",
"id",
")"
] | python | train | 38.1875 |
tanghaibao/goatools | goatools/associations.py | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/associations.py#L40-L47 | def dnld_annotation(assc_file, prt=sys.stdout):
"""Download gaf, gpad, or gpi from http://current.geneontology.org/annotations/"""
if not os.path.isfile(assc_file):
# assc_http = "http://geneontology.org/gene-associations/"
assc_http = "http://current.geneontology.org/annotations/"
_, as... | [
"def",
"dnld_annotation",
"(",
"assc_file",
",",
"prt",
"=",
"sys",
".",
"stdout",
")",
":",
"if",
"not",
"os",
".",
"path",
".",
"isfile",
"(",
"assc_file",
")",
":",
"# assc_http = \"http://geneontology.org/gene-associations/\"",
"assc_http",
"=",
"\"http://curr... | Download gaf, gpad, or gpi from http://current.geneontology.org/annotations/ | [
"Download",
"gaf",
"gpad",
"or",
"gpi",
"from",
"http",
":",
"//",
"current",
".",
"geneontology",
".",
"org",
"/",
"annotations",
"/"
] | python | train | 59.75 |
abe-winter/pg13-py | pg13/pg.py | https://github.com/abe-winter/pg13-py/blob/c78806f99f35541a8756987e86edca3438aa97f5/pg13/pg.py#L286-L291 | def delete(self,pool_or_cursor):
".. warning:: pgmock doesn't support delete yet, so this isn't tested"
vals=self.pkey_vals()
whereclause=' and '.join('%s=%%s'%k for k in self.PKEY.split(','))
q='delete from %s where %s'%(self.TABLE,whereclause)
commit_or_execute(pool_or_cursor,q,vals) | [
"def",
"delete",
"(",
"self",
",",
"pool_or_cursor",
")",
":",
"vals",
"=",
"self",
".",
"pkey_vals",
"(",
")",
"whereclause",
"=",
"' and '",
".",
"join",
"(",
"'%s=%%s'",
"%",
"k",
"for",
"k",
"in",
"self",
".",
"PKEY",
".",
"split",
"(",
"','",
... | .. warning:: pgmock doesn't support delete yet, so this isn't tested | [
"..",
"warning",
"::",
"pgmock",
"doesn",
"t",
"support",
"delete",
"yet",
"so",
"this",
"isn",
"t",
"tested"
] | python | train | 51 |
waleedka/hiddenlayer | demos/tf_cifar10.py | https://github.com/waleedka/hiddenlayer/blob/294f8732b271cbdd6310c55bdf5ce855cbf61c75/demos/tf_cifar10.py#L121-L169 | def model(self, inputs, mode='train'):
"""Build a simple convnet (BN before ReLU).
Args:
inputs: a tensor of size [batch_size, height, width, channels]
mode: string in ['train', 'test']
Returns:
the last op containing the predictions
Note:
... | [
"def",
"model",
"(",
"self",
",",
"inputs",
",",
"mode",
"=",
"'train'",
")",
":",
"# Extract features",
"training",
"=",
"(",
"mode",
"==",
"'train'",
")",
"with",
"tf",
".",
"variable_scope",
"(",
"'conv1'",
")",
"as",
"scope",
":",
"conv",
"=",
"tf"... | Build a simple convnet (BN before ReLU).
Args:
inputs: a tensor of size [batch_size, height, width, channels]
mode: string in ['train', 'test']
Returns:
the last op containing the predictions
Note:
Best score
Step: 7015 - Epoch: 18/20 ... | [
"Build",
"a",
"simple",
"convnet",
"(",
"BN",
"before",
"ReLU",
")",
".",
"Args",
":",
"inputs",
":",
"a",
"tensor",
"of",
"size",
"[",
"batch_size",
"height",
"width",
"channels",
"]",
"mode",
":",
"string",
"in",
"[",
"train",
"test",
"]",
"Returns",... | python | train | 52.55102 |
Miserlou/Zappa | zappa/utilities.py | https://github.com/Miserlou/Zappa/blob/3ccf7490a8d8b8fa74a61ee39bf44234f3567739/zappa/utilities.py#L442-L455 | def check_new_version_available(this_version):
"""
Checks if a newer version of Zappa is available.
Returns True is updateable, else False.
"""
import requests
pypi_url = 'https://pypi.python.org/pypi/Zappa/json'
resp = requests.get(pypi_url, timeout=1.5)
top_version = resp.json()['in... | [
"def",
"check_new_version_available",
"(",
"this_version",
")",
":",
"import",
"requests",
"pypi_url",
"=",
"'https://pypi.python.org/pypi/Zappa/json'",
"resp",
"=",
"requests",
".",
"get",
"(",
"pypi_url",
",",
"timeout",
"=",
"1.5",
")",
"top_version",
"=",
"resp"... | Checks if a newer version of Zappa is available.
Returns True is updateable, else False. | [
"Checks",
"if",
"a",
"newer",
"version",
"of",
"Zappa",
"is",
"available",
"."
] | python | train | 25.857143 |
yychen/twd97 | twd97/converter.py | https://github.com/yychen/twd97/blob/2fe05dbca335be425a1f451e0ef8f210ec864de1/twd97/converter.py#L69-L78 | def tomindec(origin):
"""
Convert [+/-]DDD.DDDDD to a tuple (degrees, minutes)
"""
origin = float(origin)
degrees = int(origin)
minutes = (origin % 1) * 60
return degrees, minutes | [
"def",
"tomindec",
"(",
"origin",
")",
":",
"origin",
"=",
"float",
"(",
"origin",
")",
"degrees",
"=",
"int",
"(",
"origin",
")",
"minutes",
"=",
"(",
"origin",
"%",
"1",
")",
"*",
"60",
"return",
"degrees",
",",
"minutes"
] | Convert [+/-]DDD.DDDDD to a tuple (degrees, minutes) | [
"Convert",
"[",
"+",
"/",
"-",
"]",
"DDD",
".",
"DDDDD",
"to",
"a",
"tuple",
"(",
"degrees",
"minutes",
")"
] | python | train | 20 |
caktus/django-timepiece | timepiece/utils/__init__.py | https://github.com/caktus/django-timepiece/blob/52515dec027664890efbc535429e1ba1ee152f40/timepiece/utils/__init__.py#L31-L42 | def get_active_entry(user, select_for_update=False):
"""Returns the user's currently-active entry, or None."""
entries = apps.get_model('entries', 'Entry').no_join
if select_for_update:
entries = entries.select_for_update()
entries = entries.filter(user=user, end_time__isnull=True)
if not e... | [
"def",
"get_active_entry",
"(",
"user",
",",
"select_for_update",
"=",
"False",
")",
":",
"entries",
"=",
"apps",
".",
"get_model",
"(",
"'entries'",
",",
"'Entry'",
")",
".",
"no_join",
"if",
"select_for_update",
":",
"entries",
"=",
"entries",
".",
"select... | Returns the user's currently-active entry, or None. | [
"Returns",
"the",
"user",
"s",
"currently",
"-",
"active",
"entry",
"or",
"None",
"."
] | python | train | 38.583333 |
zsimic/runez | src/runez/config.py | https://github.com/zsimic/runez/blob/14363b719a1aae1528859a501a22d075ce0abfcc/src/runez/config.py#L137-L152 | def get_str(self, key, default=None):
"""
Args:
key (str | unicode | None): Key to lookup
default (str | unicode | None): Default to use if key is not configured
Returns:
(str | None): Value of key, if defined
"""
if key:
for provi... | [
"def",
"get_str",
"(",
"self",
",",
"key",
",",
"default",
"=",
"None",
")",
":",
"if",
"key",
":",
"for",
"provider",
"in",
"self",
".",
"providers",
":",
"value",
"=",
"provider",
".",
"get_str",
"(",
"key",
")",
"if",
"value",
"is",
"not",
"None... | Args:
key (str | unicode | None): Key to lookup
default (str | unicode | None): Default to use if key is not configured
Returns:
(str | None): Value of key, if defined | [
"Args",
":",
"key",
"(",
"str",
"|",
"unicode",
"|",
"None",
")",
":",
"Key",
"to",
"lookup",
"default",
"(",
"str",
"|",
"unicode",
"|",
"None",
")",
":",
"Default",
"to",
"use",
"if",
"key",
"is",
"not",
"configured"
] | python | train | 29.25 |
tamasgal/km3pipe | km3pipe/hardware.py | https://github.com/tamasgal/km3pipe/blob/7a9b59ac899a28775b5bdc5d391d9a5340d08040/km3pipe/hardware.py#L351-L356 | def pmt_angles(self):
"""A list of PMT directions sorted by PMT channel, on DU-1, floor-1"""
if self._pmt_angles == []:
mask = (self.pmts.du == 1) & (self.pmts.floor == 1)
self._pmt_angles = self.pmts.dir[mask]
return self._pmt_angles | [
"def",
"pmt_angles",
"(",
"self",
")",
":",
"if",
"self",
".",
"_pmt_angles",
"==",
"[",
"]",
":",
"mask",
"=",
"(",
"self",
".",
"pmts",
".",
"du",
"==",
"1",
")",
"&",
"(",
"self",
".",
"pmts",
".",
"floor",
"==",
"1",
")",
"self",
".",
"_p... | A list of PMT directions sorted by PMT channel, on DU-1, floor-1 | [
"A",
"list",
"of",
"PMT",
"directions",
"sorted",
"by",
"PMT",
"channel",
"on",
"DU",
"-",
"1",
"floor",
"-",
"1"
] | python | train | 46.166667 |
bearyinnovative/bearychat.py | examples/rtm_loop.py | https://github.com/bearyinnovative/bearychat.py/blob/6c7af2d215c2ff7135bb5af66ca333d0ea1089fd/examples/rtm_loop.py#L152-L167 | def get_error(self, block=False, timeout=None):
"""Removes and returns an error from self._errors
Args:
block(bool): if True block until a RTMMessage is available,
else it will return None when self._inbox is empty
timeout(int): it blocks at most timeout... | [
"def",
"get_error",
"(",
"self",
",",
"block",
"=",
"False",
",",
"timeout",
"=",
"None",
")",
":",
"try",
":",
"error",
"=",
"self",
".",
"_errors",
".",
"get",
"(",
"block",
"=",
"block",
",",
"timeout",
"=",
"timeout",
")",
"return",
"error",
"e... | Removes and returns an error from self._errors
Args:
block(bool): if True block until a RTMMessage is available,
else it will return None when self._inbox is empty
timeout(int): it blocks at most timeout seconds
Returns:
error if inbox is no... | [
"Removes",
"and",
"returns",
"an",
"error",
"from",
"self",
".",
"_errors"
] | python | train | 34.3125 |
inspirehep/harvesting-kit | harvestingkit/inspire_cds_package/from_cds.py | https://github.com/inspirehep/harvesting-kit/blob/33a7f8aa9dade1d863110c6d8b27dfd955cb471f/harvestingkit/inspire_cds_package/from_cds.py#L159-L171 | def is_published(self):
"""Check fields 980 and 773 to see if the record has already been published.
:return: True is published, else False
"""
field980 = record_get_field_instances(self.record, '980')
field773 = record_get_field_instances(self.record, '773')
for f980 in... | [
"def",
"is_published",
"(",
"self",
")",
":",
"field980",
"=",
"record_get_field_instances",
"(",
"self",
".",
"record",
",",
"'980'",
")",
"field773",
"=",
"record_get_field_instances",
"(",
"self",
".",
"record",
",",
"'773'",
")",
"for",
"f980",
"in",
"fi... | Check fields 980 and 773 to see if the record has already been published.
:return: True is published, else False | [
"Check",
"fields",
"980",
"and",
"773",
"to",
"see",
"if",
"the",
"record",
"has",
"already",
"been",
"published",
"."
] | python | valid | 39.923077 |
pydata/numexpr | numexpr/utils.py | https://github.com/pydata/numexpr/blob/364bac13d84524e0e01db892301b2959d822dcff/numexpr/utils.py#L148-L168 | def detect_number_of_cores():
"""
Detects the number of cores on a system. Cribbed from pp.
"""
# Linux, Unix and MacOS:
if hasattr(os, "sysconf"):
if "SC_NPROCESSORS_ONLN" in os.sysconf_names:
# Linux & Unix:
ncpus = os.sysconf("SC_NPROCESSORS_ONLN")
if i... | [
"def",
"detect_number_of_cores",
"(",
")",
":",
"# Linux, Unix and MacOS:",
"if",
"hasattr",
"(",
"os",
",",
"\"sysconf\"",
")",
":",
"if",
"\"SC_NPROCESSORS_ONLN\"",
"in",
"os",
".",
"sysconf_names",
":",
"# Linux & Unix:",
"ncpus",
"=",
"os",
".",
"sysconf",
"... | Detects the number of cores on a system. Cribbed from pp. | [
"Detects",
"the",
"number",
"of",
"cores",
"on",
"a",
"system",
".",
"Cribbed",
"from",
"pp",
"."
] | python | train | 30.857143 |
priestc/moneywagon | moneywagon/mcaf.py | https://github.com/priestc/moneywagon/blob/00518f1f557dcca8b3031f46d3564c2baa0227a3/moneywagon/mcaf.py#L38-L52 | def gen_primes():
""" Generate an infinite sequence of prime numbers.
"""
D = {}
q = 2
while True:
if q not in D:
yield q
D[q * q] = [q]
else:
for p in D[q]:
D.setdefault(p + q, []).append(p)
del D[q]
q += 1 | [
"def",
"gen_primes",
"(",
")",
":",
"D",
"=",
"{",
"}",
"q",
"=",
"2",
"while",
"True",
":",
"if",
"q",
"not",
"in",
"D",
":",
"yield",
"q",
"D",
"[",
"q",
"*",
"q",
"]",
"=",
"[",
"q",
"]",
"else",
":",
"for",
"p",
"in",
"D",
"[",
"q",... | Generate an infinite sequence of prime numbers. | [
"Generate",
"an",
"infinite",
"sequence",
"of",
"prime",
"numbers",
"."
] | python | train | 20.133333 |
mdiener/grace | grace/py27/slimit/parser.py | https://github.com/mdiener/grace/blob/2dab13a2cf636da5da989904c5885166fc94d36d/grace/py27/slimit/parser.py#L1129-L1131 | def p_labelled_statement(self, p):
"""labelled_statement : identifier COLON statement"""
p[0] = ast.Label(identifier=p[1], statement=p[3]) | [
"def",
"p_labelled_statement",
"(",
"self",
",",
"p",
")",
":",
"p",
"[",
"0",
"]",
"=",
"ast",
".",
"Label",
"(",
"identifier",
"=",
"p",
"[",
"1",
"]",
",",
"statement",
"=",
"p",
"[",
"3",
"]",
")"
] | labelled_statement : identifier COLON statement | [
"labelled_statement",
":",
"identifier",
"COLON",
"statement"
] | python | train | 50.666667 |
scidam/cachepy | crypter.py | https://github.com/scidam/cachepy/blob/680eeb7ff04ec9bb634b71cceb0841abaf2d530e/crypter.py#L30-L42 | def padding(s, bs=AES.block_size):
"""Fills a bytes-like object with arbitrary symbols to make its length divisible by `bs`.
"""
s = to_bytes(s)
if len(s) % bs == 0:
res = s + b''.join(map(to_bytes, [random.SystemRandom().choice(string.ascii_lowercase + string.digits) for _ in range(bs - 1... | [
"def",
"padding",
"(",
"s",
",",
"bs",
"=",
"AES",
".",
"block_size",
")",
":",
"s",
"=",
"to_bytes",
"(",
"s",
")",
"if",
"len",
"(",
"s",
")",
"%",
"bs",
"==",
"0",
":",
"res",
"=",
"s",
"+",
"b''",
".",
"join",
"(",
"map",
"(",
"to_bytes... | Fills a bytes-like object with arbitrary symbols to make its length divisible by `bs`. | [
"Fills",
"a",
"bytes",
"-",
"like",
"object",
"with",
"arbitrary",
"symbols",
"to",
"make",
"its",
"length",
"divisible",
"by",
"bs",
"."
] | python | train | 59.538462 |
saltstack/salt | salt/modules/boto_rds.py | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/boto_rds.py#L780-L819 | def describe_parameter_group(name, Filters=None, MaxRecords=None, Marker=None,
region=None, key=None, keyid=None, profile=None):
'''
Returns a list of `DBParameterGroup` descriptions.
CLI example to description of parameter group::
salt myminion boto_rds.describe_parame... | [
"def",
"describe_parameter_group",
"(",
"name",
",",
"Filters",
"=",
"None",
",",
"MaxRecords",
"=",
"None",
",",
"Marker",
"=",
"None",
",",
"region",
"=",
"None",
",",
"key",
"=",
"None",
",",
"keyid",
"=",
"None",
",",
"profile",
"=",
"None",
")",
... | Returns a list of `DBParameterGroup` descriptions.
CLI example to description of parameter group::
salt myminion boto_rds.describe_parameter_group parametergroupname\
region=us-east-1 | [
"Returns",
"a",
"list",
"of",
"DBParameterGroup",
"descriptions",
".",
"CLI",
"example",
"to",
"description",
"of",
"parameter",
"group",
"::"
] | python | train | 41.525 |
kmike/django-generic-images | generic_images/models.py | https://github.com/kmike/django-generic-images/blob/4e45068ed219ac35396758eb6b6e1fe5306147df/generic_images/models.py#L164-L179 | def get_upload_path(self, filename):
''' Override this in proxy subclass to customize upload path.
Default upload path is
:file:`/media/images/<user.id>/<filename>.<ext>`
or :file:`/media/images/common/<filename>.<ext>` if user is not set.
``<filename>`` is retur... | [
"def",
"get_upload_path",
"(",
"self",
",",
"filename",
")",
":",
"user_folder",
"=",
"str",
"(",
"self",
".",
"user",
".",
"pk",
")",
"if",
"self",
".",
"user",
"else",
"'common'",
"root",
",",
"ext",
"=",
"os",
".",
"path",
".",
"splitext",
"(",
... | Override this in proxy subclass to customize upload path.
Default upload path is
:file:`/media/images/<user.id>/<filename>.<ext>`
or :file:`/media/images/common/<filename>.<ext>` if user is not set.
``<filename>`` is returned by
:meth:`~generic_images.models.... | [
"Override",
"this",
"in",
"proxy",
"subclass",
"to",
"customize",
"upload",
"path",
".",
"Default",
"upload",
"path",
"is",
":",
"file",
":",
"/",
"media",
"/",
"images",
"/",
"<user",
".",
"id",
">",
"/",
"<filename",
">",
".",
"<ext",
">",
"or",
":... | python | train | 47.8125 |
fermiPy/fermipy | fermipy/jobs/scatter_gather.py | https://github.com/fermiPy/fermipy/blob/9df5e7e3728307fd58c5bba36fd86783c39fbad4/fermipy/jobs/scatter_gather.py#L147-L177 | def _check_link_completion(self, link, fail_pending=False, fail_running=False):
"""Internal function to check the completion of all the dispatched jobs
Returns
-------
status_vect : `JobStatusVector`
Vector that summarize the number of jobs in various states.
"""
... | [
"def",
"_check_link_completion",
"(",
"self",
",",
"link",
",",
"fail_pending",
"=",
"False",
",",
"fail_running",
"=",
"False",
")",
":",
"status_vect",
"=",
"JobStatusVector",
"(",
")",
"for",
"job_key",
",",
"job_details",
"in",
"link",
".",
"jobs",
".",
... | Internal function to check the completion of all the dispatched jobs
Returns
-------
status_vect : `JobStatusVector`
Vector that summarize the number of jobs in various states. | [
"Internal",
"function",
"to",
"check",
"the",
"completion",
"of",
"all",
"the",
"dispatched",
"jobs"
] | python | train | 39.419355 |
cpburnz/python-path-specification | pathspec/util.py | https://github.com/cpburnz/python-path-specification/blob/6fc7567a58cb68ec7d72cc287e7fb97dbe22c017/pathspec/util.py#L181-L207 | def normalize_file(file, separators=None):
"""
Normalizes the file path to use the POSIX path separator (i.e., ``'/'``).
*file* (:class:`str`) is the file path.
*separators* (:class:`~collections.abc.Collection` of :class:`str`; or
:data:`None`) optionally contains the path separators to normalize.
This does no... | [
"def",
"normalize_file",
"(",
"file",
",",
"separators",
"=",
"None",
")",
":",
"# Normalize path separators.",
"if",
"separators",
"is",
"None",
":",
"separators",
"=",
"NORMALIZE_PATH_SEPS",
"norm_file",
"=",
"file",
"for",
"sep",
"in",
"separators",
":",
"nor... | Normalizes the file path to use the POSIX path separator (i.e., ``'/'``).
*file* (:class:`str`) is the file path.
*separators* (:class:`~collections.abc.Collection` of :class:`str`; or
:data:`None`) optionally contains the path separators to normalize.
This does not need to include the POSIX path separator (``'/'... | [
"Normalizes",
"the",
"file",
"path",
"to",
"use",
"the",
"POSIX",
"path",
"separator",
"(",
"i",
".",
"e",
".",
"/",
")",
"."
] | python | train | 32.925926 |
ipazc/mtcnn | mtcnn/network.py | https://github.com/ipazc/mtcnn/blob/17029fe453a435f50c472ae2fd1c493341b5ede3/mtcnn/network.py#L80-L97 | def set_weights(self, weights_values: dict, ignore_missing=False):
"""
Sets the weights values of the network.
:param weights_values: dictionary with weights for each layer
"""
network_name = self.__class__.__name__.lower()
with tf.variable_scope(network_name):
... | [
"def",
"set_weights",
"(",
"self",
",",
"weights_values",
":",
"dict",
",",
"ignore_missing",
"=",
"False",
")",
":",
"network_name",
"=",
"self",
".",
"__class__",
".",
"__name__",
".",
"lower",
"(",
")",
"with",
"tf",
".",
"variable_scope",
"(",
"network... | Sets the weights values of the network.
:param weights_values: dictionary with weights for each layer | [
"Sets",
"the",
"weights",
"values",
"of",
"the",
"network",
".",
":",
"param",
"weights_values",
":",
"dictionary",
"with",
"weights",
"for",
"each",
"layer"
] | python | train | 42.833333 |
Azure/azure-cosmos-table-python | azure-cosmosdb-table/azure/cosmosdb/table/tableservice.py | https://github.com/Azure/azure-cosmos-table-python/blob/a7b618f6bddc465c9fdf899ea2971dfe4d04fcf0/azure-cosmosdb-table/azure/cosmosdb/table/tableservice.py#L613-L635 | def get_table_acl(self, table_name, timeout=None):
'''
Returns details about any stored access policies specified on the
table that may be used with Shared Access Signatures.
:param str table_name:
The name of an existing table.
:param int timeout:
The se... | [
"def",
"get_table_acl",
"(",
"self",
",",
"table_name",
",",
"timeout",
"=",
"None",
")",
":",
"_validate_not_none",
"(",
"'table_name'",
",",
"table_name",
")",
"request",
"=",
"HTTPRequest",
"(",
")",
"request",
".",
"method",
"=",
"'GET'",
"request",
".",... | Returns details about any stored access policies specified on the
table that may be used with Shared Access Signatures.
:param str table_name:
The name of an existing table.
:param int timeout:
The server timeout, expressed in seconds.
:return: A dictionary of ac... | [
"Returns",
"details",
"about",
"any",
"stored",
"access",
"policies",
"specified",
"on",
"the",
"table",
"that",
"may",
"be",
"used",
"with",
"Shared",
"Access",
"Signatures",
"."
] | python | train | 40.391304 |
mlperf/training | image_classification/tensorflow/official/utils/logs/hooks.py | https://github.com/mlperf/training/blob/1c6ae725a81d15437a2b2df05cac0673fde5c3a4/image_classification/tensorflow/official/utils/logs/hooks.py#L69-L74 | def begin(self):
"""Called once before using the session to check global step."""
self._global_step_tensor = tf.train.get_global_step()
if self._global_step_tensor is None:
raise RuntimeError(
'Global step should be created to use StepCounterHook.') | [
"def",
"begin",
"(",
"self",
")",
":",
"self",
".",
"_global_step_tensor",
"=",
"tf",
".",
"train",
".",
"get_global_step",
"(",
")",
"if",
"self",
".",
"_global_step_tensor",
"is",
"None",
":",
"raise",
"RuntimeError",
"(",
"'Global step should be created to us... | Called once before using the session to check global step. | [
"Called",
"once",
"before",
"using",
"the",
"session",
"to",
"check",
"global",
"step",
"."
] | python | train | 45.333333 |
bykof/billomapy | billomapy/billomapy.py | https://github.com/bykof/billomapy/blob/a28ba69fd37654fa145d0411d52c200e7f8984ab/billomapy/billomapy.py#L87-L106 | def _create_put_request(self, resource, billomat_id, command=None, send_data=None):
"""
Creates a put request and return the response data
"""
assert (isinstance(resource, str))
if isinstance(billomat_id, int):
billomat_id = str(billomat_id)
if not command:
... | [
"def",
"_create_put_request",
"(",
"self",
",",
"resource",
",",
"billomat_id",
",",
"command",
"=",
"None",
",",
"send_data",
"=",
"None",
")",
":",
"assert",
"(",
"isinstance",
"(",
"resource",
",",
"str",
")",
")",
"if",
"isinstance",
"(",
"billomat_id"... | Creates a put request and return the response data | [
"Creates",
"a",
"put",
"request",
"and",
"return",
"the",
"response",
"data"
] | python | train | 29.1 |
Clinical-Genomics/trailblazer | trailblazer/mip/sacct.py | https://github.com/Clinical-Genomics/trailblazer/blob/27f3cd21043a1077bd7029e85783459a50a7b798/trailblazer/mip/sacct.py#L71-L75 | def filter_jobs(sacct_jobs, failed=True):
"""Filter jobs that have a FAILED etc. status."""
categories = FAILED_CATEGORIES if failed else NORMAL_CATEGORIES
filtered_jobs = [job for job in sacct_jobs if job['state'] in categories]
return filtered_jobs | [
"def",
"filter_jobs",
"(",
"sacct_jobs",
",",
"failed",
"=",
"True",
")",
":",
"categories",
"=",
"FAILED_CATEGORIES",
"if",
"failed",
"else",
"NORMAL_CATEGORIES",
"filtered_jobs",
"=",
"[",
"job",
"for",
"job",
"in",
"sacct_jobs",
"if",
"job",
"[",
"'state'",... | Filter jobs that have a FAILED etc. status. | [
"Filter",
"jobs",
"that",
"have",
"a",
"FAILED",
"etc",
".",
"status",
"."
] | python | train | 52.4 |
projectatomic/osbs-client | osbs/api.py | https://github.com/projectatomic/osbs-client/blob/571fe035dab3a7c02e1dccd5d65ffd75be750458/osbs/api.py#L1331-L1342 | def get_config_map(self, name):
"""
Get a ConfigMap object from the server
Raises exception on error
:param name: str, name of configMap to get from the server
:returns: ConfigMapResponse containing the ConfigMap with the requested name
"""
response = self.os.ge... | [
"def",
"get_config_map",
"(",
"self",
",",
"name",
")",
":",
"response",
"=",
"self",
".",
"os",
".",
"get_config_map",
"(",
"name",
")",
"config_map_response",
"=",
"ConfigMapResponse",
"(",
"response",
".",
"json",
"(",
")",
")",
"return",
"config_map_resp... | Get a ConfigMap object from the server
Raises exception on error
:param name: str, name of configMap to get from the server
:returns: ConfigMapResponse containing the ConfigMap with the requested name | [
"Get",
"a",
"ConfigMap",
"object",
"from",
"the",
"server"
] | python | train | 35.583333 |
MrMinimal64/timezonefinder | timezonefinder/timezonefinder.py | https://github.com/MrMinimal64/timezonefinder/blob/96cc43afb3bae57ffd002ab4cf104fe15eda2257/timezonefinder/timezonefinder.py#L423-L489 | def timezone_at(self, *, lng, lat):
"""
this function looks up in which polygons the point could be included in
to speed things up there are shortcuts being used (stored in a binary file)
especially for large polygons it is expensive to check if a point is really included,
so cer... | [
"def",
"timezone_at",
"(",
"self",
",",
"*",
",",
"lng",
",",
"lat",
")",
":",
"lng",
",",
"lat",
"=",
"rectify_coordinates",
"(",
"lng",
",",
"lat",
")",
"# x = longitude y = latitude both converted to 8byte int",
"x",
"=",
"coord2int",
"(",
"lng",
")",
"... | this function looks up in which polygons the point could be included in
to speed things up there are shortcuts being used (stored in a binary file)
especially for large polygons it is expensive to check if a point is really included,
so certain simplifications are made and even when you get a hi... | [
"this",
"function",
"looks",
"up",
"in",
"which",
"polygons",
"the",
"point",
"could",
"be",
"included",
"in",
"to",
"speed",
"things",
"up",
"there",
"are",
"shortcuts",
"being",
"used",
"(",
"stored",
"in",
"a",
"binary",
"file",
")",
"especially",
"for"... | python | train | 57.283582 |
salesking/salesking_python_sdk | salesking/collection.py | https://github.com/salesking/salesking_python_sdk/blob/0d5a95c5ee4e16a85562ceaf67bb11b55e47ee4c/salesking/collection.py#L128-L137 | def set_filters(self, filters):
"""
set and validate filters dict
"""
if not isinstance(filters, dict):
raise Exception("filters must be a dict")
self.filters = {}
for key in filters.keys():
value = filters[key]
self.add_filter(key,valu... | [
"def",
"set_filters",
"(",
"self",
",",
"filters",
")",
":",
"if",
"not",
"isinstance",
"(",
"filters",
",",
"dict",
")",
":",
"raise",
"Exception",
"(",
"\"filters must be a dict\"",
")",
"self",
".",
"filters",
"=",
"{",
"}",
"for",
"key",
"in",
"filte... | set and validate filters dict | [
"set",
"and",
"validate",
"filters",
"dict"
] | python | train | 31.3 |
molmod/molmod | molmod/io/cp2k.py | https://github.com/molmod/molmod/blob/a7b5b4364ed514ad4c465856c05b5eda1cb561e0/molmod/io/cp2k.py#L296-L300 | def set_value(self, value):
"""Set the value associated with the keyword"""
if not isinstance(value, str):
raise TypeError("A value must be a string, got %s." % value)
self.__value = value | [
"def",
"set_value",
"(",
"self",
",",
"value",
")",
":",
"if",
"not",
"isinstance",
"(",
"value",
",",
"str",
")",
":",
"raise",
"TypeError",
"(",
"\"A value must be a string, got %s.\"",
"%",
"value",
")",
"self",
".",
"__value",
"=",
"value"
] | Set the value associated with the keyword | [
"Set",
"the",
"value",
"associated",
"with",
"the",
"keyword"
] | python | train | 44 |
shmir/PyIxNetwork | ixnetwork/ixn_statistics_view.py | https://github.com/shmir/PyIxNetwork/blob/e7d7a89c08a5d3a1382b4dcfd915bbfc7eedd33f/ixnetwork/ixn_statistics_view.py#L61-L67 | def get_stats(self, stat_name):
"""
:param stat_name: requested statistics name.
:returns: all values of the requested statistic for all objects.
"""
return [self.get_stat(r, stat_name) for r in self.statistics.keys()] | [
"def",
"get_stats",
"(",
"self",
",",
"stat_name",
")",
":",
"return",
"[",
"self",
".",
"get_stat",
"(",
"r",
",",
"stat_name",
")",
"for",
"r",
"in",
"self",
".",
"statistics",
".",
"keys",
"(",
")",
"]"
] | :param stat_name: requested statistics name.
:returns: all values of the requested statistic for all objects. | [
":",
"param",
"stat_name",
":",
"requested",
"statistics",
"name",
".",
":",
"returns",
":",
"all",
"values",
"of",
"the",
"requested",
"statistic",
"for",
"all",
"objects",
"."
] | python | train | 36.142857 |
dslackw/slpkg | slpkg/config.py | https://github.com/dslackw/slpkg/blob/dd2e08a80e944d337d157b992167ba631a4343de/slpkg/config.py#L40-L77 | def view(self):
"""View slpkg config file
"""
print("") # new line at start
conf_args = [
"RELEASE",
"SLACKWARE_VERSION",
"COMP_ARCH",
"BUILD_PATH",
"PACKAGES",
"PATCHES",
"CHECKMD5",
"DEL_A... | [
"def",
"view",
"(",
"self",
")",
":",
"print",
"(",
"\"\"",
")",
"# new line at start",
"conf_args",
"=",
"[",
"\"RELEASE\"",
",",
"\"SLACKWARE_VERSION\"",
",",
"\"COMP_ARCH\"",
",",
"\"BUILD_PATH\"",
",",
"\"PACKAGES\"",
",",
"\"PATCHES\"",
",",
"\"CHECKMD5\"",
... | View slpkg config file | [
"View",
"slpkg",
"config",
"file"
] | python | train | 29.421053 |
mozilla/taar | taar/plugin.py | https://github.com/mozilla/taar/blob/4002eb395f0b7ad837f1578e92d590e2cf82bdca/taar/plugin.py#L32-L52 | def clean_promoted_guids(raw_promoted_guids):
""" Verify that the promoted GUIDs are formatted correctly,
otherwise strip it down into an empty list.
"""
valid = True
for row in raw_promoted_guids:
if len(row) != 2:
valid = False
break
if not (
(... | [
"def",
"clean_promoted_guids",
"(",
"raw_promoted_guids",
")",
":",
"valid",
"=",
"True",
"for",
"row",
"in",
"raw_promoted_guids",
":",
"if",
"len",
"(",
"row",
")",
"!=",
"2",
":",
"valid",
"=",
"False",
"break",
"if",
"not",
"(",
"(",
"isinstance",
"(... | Verify that the promoted GUIDs are formatted correctly,
otherwise strip it down into an empty list. | [
"Verify",
"that",
"the",
"promoted",
"GUIDs",
"are",
"formatted",
"correctly",
"otherwise",
"strip",
"it",
"down",
"into",
"an",
"empty",
"list",
"."
] | python | train | 26.285714 |
campbellr/smashrun-client | smashrun/client.py | https://github.com/campbellr/smashrun-client/blob/2522cb4d0545cf482a49a9533f12aac94c5aecdc/smashrun/client.py#L215-L225 | def delete_activity(self, id_num):
"""Delete an activity (run).
:param id_num: The activity ID to delete
"""
url = self._build_url('my', 'activities', id_num)
r = self.session.delete(url)
r.raise_for_status()
return r | [
"def",
"delete_activity",
"(",
"self",
",",
"id_num",
")",
":",
"url",
"=",
"self",
".",
"_build_url",
"(",
"'my'",
",",
"'activities'",
",",
"id_num",
")",
"r",
"=",
"self",
".",
"session",
".",
"delete",
"(",
"url",
")",
"r",
".",
"raise_for_status",... | Delete an activity (run).
:param id_num: The activity ID to delete | [
"Delete",
"an",
"activity",
"(",
"run",
")",
"."
] | python | train | 24.181818 |
joshspeagle/dynesty | dynesty/sampler.py | https://github.com/joshspeagle/dynesty/blob/9e482aafeb5cf84bedb896fa6f07a761d917983e/dynesty/sampler.py#L275-L308 | def _fill_queue(self, loglstar):
"""Sequentially add new live point proposals to the queue."""
# Add/zip arguments to submit to the queue.
point_queue = []
axes_queue = []
while self.nqueue < self.queue_size:
if self._beyond_unit_bound(loglstar):
# Pr... | [
"def",
"_fill_queue",
"(",
"self",
",",
"loglstar",
")",
":",
"# Add/zip arguments to submit to the queue.",
"point_queue",
"=",
"[",
"]",
"axes_queue",
"=",
"[",
"]",
"while",
"self",
".",
"nqueue",
"<",
"self",
".",
"queue_size",
":",
"if",
"self",
".",
"_... | Sequentially add new live point proposals to the queue. | [
"Sequentially",
"add",
"new",
"live",
"point",
"proposals",
"to",
"the",
"queue",
"."
] | python | train | 45.352941 |
gem/oq-engine | openquake/baselib/general.py | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/baselib/general.py#L763-L778 | def new(self, array):
"""
Convert an array of compatible length into a DictArray:
>>> d = DictArray({'PGA': [0.01, 0.02, 0.04], 'PGV': [0.1, 0.2]})
>>> d.new(numpy.arange(0, 5, 1)) # array of lenght 5 = 3 + 2
<DictArray
PGA: [0 1 2]
PGV: [3 4]>
"""
... | [
"def",
"new",
"(",
"self",
",",
"array",
")",
":",
"assert",
"len",
"(",
"self",
".",
"array",
")",
"==",
"len",
"(",
"array",
")",
"arr",
"=",
"object",
".",
"__new__",
"(",
"self",
".",
"__class__",
")",
"arr",
".",
"dt",
"=",
"self",
".",
"d... | Convert an array of compatible length into a DictArray:
>>> d = DictArray({'PGA': [0.01, 0.02, 0.04], 'PGV': [0.1, 0.2]})
>>> d.new(numpy.arange(0, 5, 1)) # array of lenght 5 = 3 + 2
<DictArray
PGA: [0 1 2]
PGV: [3 4]> | [
"Convert",
"an",
"array",
"of",
"compatible",
"length",
"into",
"a",
"DictArray",
":"
] | python | train | 31 |
bioasp/caspo | caspo/core/clamping.py | https://github.com/bioasp/caspo/blob/a68d1eace75b9b08f23633d1fb5ce6134403959e/caspo/core/clamping.py#L105-L123 | def to_csv(self, filename, stimuli=None, inhibitors=None, prepend=""):
"""
Writes the list of clampings to a CSV file
Parameters
----------
filename : str
Absolute path where to write the CSV file
stimuli : Optional[list[str]]
List of stimuli nam... | [
"def",
"to_csv",
"(",
"self",
",",
"filename",
",",
"stimuli",
"=",
"None",
",",
"inhibitors",
"=",
"None",
",",
"prepend",
"=",
"\"\"",
")",
":",
"self",
".",
"to_dataframe",
"(",
"stimuli",
",",
"inhibitors",
",",
"prepend",
")",
".",
"to_csv",
"(",
... | Writes the list of clampings to a CSV file
Parameters
----------
filename : str
Absolute path where to write the CSV file
stimuli : Optional[list[str]]
List of stimuli names. If given, stimuli are converted to {0,1} instead of {-1,1}.
inhibitors : Optio... | [
"Writes",
"the",
"list",
"of",
"clampings",
"to",
"a",
"CSV",
"file"
] | python | train | 37.526316 |
tanghaibao/jcvi | jcvi/apps/restriction.py | https://github.com/tanghaibao/jcvi/blob/d2e31a77b6ade7f41f3b321febc2b4744d1cdeca/jcvi/apps/restriction.py#L59-L69 | def extract_full(rec, sites, flank, fw):
"""
Full extraction of seq flanking the sites.
"""
for s in sites:
newid = "{0}:{1}".format(rec.name, s)
left = max(s - flank, 0)
right = min(s + flank, len(rec))
frag = rec.seq[left:right].strip("Nn")
newrec = SeqRecord(fr... | [
"def",
"extract_full",
"(",
"rec",
",",
"sites",
",",
"flank",
",",
"fw",
")",
":",
"for",
"s",
"in",
"sites",
":",
"newid",
"=",
"\"{0}:{1}\"",
".",
"format",
"(",
"rec",
".",
"name",
",",
"s",
")",
"left",
"=",
"max",
"(",
"s",
"-",
"flank",
... | Full extraction of seq flanking the sites. | [
"Full",
"extraction",
"of",
"seq",
"flanking",
"the",
"sites",
"."
] | python | train | 34.727273 |
snbuback/django_services | django_services/service/core.py | https://github.com/snbuback/django_services/blob/58cbdea878bb11197add0ed1008a9206e4d92671/django_services/service/core.py#L80-L94 | def has_perm(self, service, perm_name, obj, call_name):
"""
Raise PermissionDenied if user has no permission in object
"""
user = service.user
if not (perm_name is False):
if not user.has_perm(perm_name, obj=obj):
LOG_PERM.warn(
u'U... | [
"def",
"has_perm",
"(",
"self",
",",
"service",
",",
"perm_name",
",",
"obj",
",",
"call_name",
")",
":",
"user",
"=",
"service",
".",
"user",
"if",
"not",
"(",
"perm_name",
"is",
"False",
")",
":",
"if",
"not",
"user",
".",
"has_perm",
"(",
"perm_na... | Raise PermissionDenied if user has no permission in object | [
"Raise",
"PermissionDenied",
"if",
"user",
"has",
"no",
"permission",
"in",
"object"
] | python | train | 46.533333 |
rodluger/everest | everest/basecamp.py | https://github.com/rodluger/everest/blob/6779591f9f8b3556847e2fbf761bdfac7520eaea/everest/basecamp.py#L232-L241 | def mask(self):
'''
The array of indices to be masked. This is the union of the sets of
outliers, bad (flagged) cadences, transit cadences, and :py:obj:`NaN`
cadences.
'''
return np.array(list(set(np.concatenate([self.outmask, self.badmask,
self.... | [
"def",
"mask",
"(",
"self",
")",
":",
"return",
"np",
".",
"array",
"(",
"list",
"(",
"set",
"(",
"np",
".",
"concatenate",
"(",
"[",
"self",
".",
"outmask",
",",
"self",
".",
"badmask",
",",
"self",
".",
"transitmask",
",",
"self",
".",
"nanmask",... | The array of indices to be masked. This is the union of the sets of
outliers, bad (flagged) cadences, transit cadences, and :py:obj:`NaN`
cadences. | [
"The",
"array",
"of",
"indices",
"to",
"be",
"masked",
".",
"This",
"is",
"the",
"union",
"of",
"the",
"sets",
"of",
"outliers",
"bad",
"(",
"flagged",
")",
"cadences",
"transit",
"cadences",
"and",
":",
"py",
":",
"obj",
":",
"NaN",
"cadences",
"."
] | python | train | 35.2 |
phuijse/P4J | P4J/generator.py | https://github.com/phuijse/P4J/blob/1ec6b2ac63674ca55aeb2966b9cf40c273d7c203/P4J/generator.py#L135-L165 | def irregular_sampling(T, N, rseed=None):
"""
Generates an irregularly sampled time vector by perturbating a
linearly spaced vector and latter deleting a certain number of
points
Parameters
----------
T: float
Time span of the vector, i.e. how long it is in time
N: positiv... | [
"def",
"irregular_sampling",
"(",
"T",
",",
"N",
",",
"rseed",
"=",
"None",
")",
":",
"sampling_period",
"=",
"(",
"T",
"/",
"float",
"(",
"N",
")",
")",
"N",
"=",
"int",
"(",
"N",
")",
"np",
".",
"random",
".",
"seed",
"(",
"rseed",
")",
"t",
... | Generates an irregularly sampled time vector by perturbating a
linearly spaced vector and latter deleting a certain number of
points
Parameters
----------
T: float
Time span of the vector, i.e. how long it is in time
N: positive integer
Number of samples of the resulting t... | [
"Generates",
"an",
"irregularly",
"sampled",
"time",
"vector",
"by",
"perturbating",
"a",
"linearly",
"spaced",
"vector",
"and",
"latter",
"deleting",
"a",
"certain",
"number",
"of",
"points",
"Parameters",
"----------",
"T",
":",
"float",
"Time",
"span",
"of",
... | python | train | 28.258065 |
googleapis/oauth2client | oauth2client/client.py | https://github.com/googleapis/oauth2client/blob/50d20532a748f18e53f7d24ccbe6647132c979a9/oauth2client/client.py#L1896-L1941 | def step1_get_authorize_url(self, redirect_uri=None, state=None):
"""Returns a URI to redirect to the provider.
Args:
redirect_uri: string, Either the string 'urn:ietf:wg:oauth:2.0:oob'
for a non-web-based application, or a URI that
handle... | [
"def",
"step1_get_authorize_url",
"(",
"self",
",",
"redirect_uri",
"=",
"None",
",",
"state",
"=",
"None",
")",
":",
"if",
"redirect_uri",
"is",
"not",
"None",
":",
"logger",
".",
"warning",
"(",
"(",
"'The redirect_uri parameter for '",
"'OAuth2WebServerFlow.ste... | Returns a URI to redirect to the provider.
Args:
redirect_uri: string, Either the string 'urn:ietf:wg:oauth:2.0:oob'
for a non-web-based application, or a URI that
handles the callback from the authorization server.
This ... | [
"Returns",
"a",
"URI",
"to",
"redirect",
"to",
"the",
"provider",
"."
] | python | valid | 43.043478 |
wdecoster/nanoget | nanoget/extraction_functions.py | https://github.com/wdecoster/nanoget/blob/fb7306220e261849b96785fab02dd2f35a0e3b60/nanoget/extraction_functions.py#L93-L117 | def check_bam(bam, samtype="bam"):
"""Check if bam file is valid.
Bam file should:
- exists
- has an index (create if necessary)
- is sorted by coordinate
- has at least one mapped read
"""
ut.check_existance(bam)
samfile = pysam.AlignmentFile(bam, "rb")
if not samfile.has_index... | [
"def",
"check_bam",
"(",
"bam",
",",
"samtype",
"=",
"\"bam\"",
")",
":",
"ut",
".",
"check_existance",
"(",
"bam",
")",
"samfile",
"=",
"pysam",
".",
"AlignmentFile",
"(",
"bam",
",",
"\"rb\"",
")",
"if",
"not",
"samfile",
".",
"has_index",
"(",
")",
... | Check if bam file is valid.
Bam file should:
- exists
- has an index (create if necessary)
- is sorted by coordinate
- has at least one mapped read | [
"Check",
"if",
"bam",
"file",
"is",
"valid",
"."
] | python | train | 44.68 |
softlayer/softlayer-python | SoftLayer/managers/user.py | https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/user.py#L146-L169 | def get_logins(self, user_id, start_date=None):
"""Gets the login history for a user, default start_date is 30 days ago
:param int id: User id to get
:param string start_date: "%m/%d/%Y %H:%M:%s" formatted string.
:returns: list https://softlayer.github.io/reference/datatypes/SoftLayer_... | [
"def",
"get_logins",
"(",
"self",
",",
"user_id",
",",
"start_date",
"=",
"None",
")",
":",
"if",
"start_date",
"is",
"None",
":",
"date_object",
"=",
"datetime",
".",
"datetime",
".",
"today",
"(",
")",
"-",
"datetime",
".",
"timedelta",
"(",
"days",
... | Gets the login history for a user, default start_date is 30 days ago
:param int id: User id to get
:param string start_date: "%m/%d/%Y %H:%M:%s" formatted string.
:returns: list https://softlayer.github.io/reference/datatypes/SoftLayer_User_Customer_Access_Authentication/
Example::
... | [
"Gets",
"the",
"login",
"history",
"for",
"a",
"user",
"default",
"start_date",
"is",
"30",
"days",
"ago"
] | python | train | 39.833333 |
jobovy/galpy | galpy/orbit/OrbitTop.py | https://github.com/jobovy/galpy/blob/9c5b9fe65d58835624dffe432be282060918ee08/galpy/orbit/OrbitTop.py#L1907-L2386 | def animate(self,*args,**kwargs): #pragma: no cover
"""
NAME:
animate
PURPOSE:
animate an Orbit
INPUT:
d1= first dimension to plot ('x', 'y', 'R', 'vR', 'vT', 'z', 'vz', ...); can be list with up to three entries for three subplots
d2= second d... | [
"def",
"animate",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"#pragma: no cover",
"try",
":",
"from",
"IPython",
".",
"display",
"import",
"HTML",
"except",
"ImportError",
":",
"raise",
"ImportError",
"(",
"\"Orbit.animate requires ipyth... | NAME:
animate
PURPOSE:
animate an Orbit
INPUT:
d1= first dimension to plot ('x', 'y', 'R', 'vR', 'vT', 'z', 'vz', ...); can be list with up to three entries for three subplots
d2= second dimension to plot; can be list with up to three entries for three subplot... | [
"NAME",
":",
"animate",
"PURPOSE",
":",
"animate",
"an",
"Orbit",
"INPUT",
":",
"d1",
"=",
"first",
"dimension",
"to",
"plot",
"(",
"x",
"y",
"R",
"vR",
"vT",
"z",
"vz",
"...",
")",
";",
"can",
"be",
"list",
"with",
"up",
"to",
"three",
"entries",
... | python | train | 34.539583 |
Yubico/yubikey-manager | ykman/cli/piv.py | https://github.com/Yubico/yubikey-manager/blob/3ac27bc59ae76a59db9d09a530494add2edbbabf/ykman/cli/piv.py#L833-L857 | def read_object(ctx, pin, object_id):
"""
Read arbitrary PIV object.
Read PIV object by providing the object id.
\b
OBJECT-ID Id of PIV object in HEX.
"""
controller = ctx.obj['controller']
def do_read_object(retry=True):
try:
click.echo(controller.get_data(... | [
"def",
"read_object",
"(",
"ctx",
",",
"pin",
",",
"object_id",
")",
":",
"controller",
"=",
"ctx",
".",
"obj",
"[",
"'controller'",
"]",
"def",
"do_read_object",
"(",
"retry",
"=",
"True",
")",
":",
"try",
":",
"click",
".",
"echo",
"(",
"controller",... | Read arbitrary PIV object.
Read PIV object by providing the object id.
\b
OBJECT-ID Id of PIV object in HEX. | [
"Read",
"arbitrary",
"PIV",
"object",
"."
] | python | train | 25.44 |
shaypal5/pdutil | pdutil/iter/iter.py | https://github.com/shaypal5/pdutil/blob/231059634643af2558d22070f89767410978cf56/pdutil/iter/iter.py#L4-L32 | def sub_dfs_by_size(df, size):
"""Get a generator yielding consecutive sub-dataframes of the given size.
Arguments
---------
df : pandas.DataFrame
The dataframe for which to get sub-dataframes.
size : int
The size of each sub-dataframe.
Returns
-------
generator
... | [
"def",
"sub_dfs_by_size",
"(",
"df",
",",
"size",
")",
":",
"for",
"i",
"in",
"range",
"(",
"0",
",",
"len",
"(",
"df",
")",
",",
"size",
")",
":",
"yield",
"(",
"df",
".",
"iloc",
"[",
"i",
":",
"i",
"+",
"size",
"]",
")"
] | Get a generator yielding consecutive sub-dataframes of the given size.
Arguments
---------
df : pandas.DataFrame
The dataframe for which to get sub-dataframes.
size : int
The size of each sub-dataframe.
Returns
-------
generator
A generator yielding consecutive sub-... | [
"Get",
"a",
"generator",
"yielding",
"consecutive",
"sub",
"-",
"dataframes",
"of",
"the",
"given",
"size",
"."
] | python | train | 26.586207 |
facelessuser/backrefs | backrefs/uniprops/__init__.py | https://github.com/facelessuser/backrefs/blob/3b3d60f5d57b02044f880aa29c9c5add0e31a34f/backrefs/uniprops/__init__.py#L154-L165 | def get_hangul_syllable_type_property(value, is_bytes=False):
"""Get `HANGUL SYLLABLE TYPE` property."""
obj = unidata.ascii_hangul_syllable_type if is_bytes else unidata.unicode_hangul_syllable_type
if value.startswith('^'):
negated = value[1:]
value = '^' + unidata.unicode_alias['hanguls... | [
"def",
"get_hangul_syllable_type_property",
"(",
"value",
",",
"is_bytes",
"=",
"False",
")",
":",
"obj",
"=",
"unidata",
".",
"ascii_hangul_syllable_type",
"if",
"is_bytes",
"else",
"unidata",
".",
"unicode_hangul_syllable_type",
"if",
"value",
".",
"startswith",
"... | Get `HANGUL SYLLABLE TYPE` property. | [
"Get",
"HANGUL",
"SYLLABLE",
"TYPE",
"property",
"."
] | python | train | 37.916667 |
jtpaasch/simplygithub | simplygithub/internals/api.py | https://github.com/jtpaasch/simplygithub/blob/b77506275ec276ce90879bf1ea9299a79448b903/simplygithub/internals/api.py#L119-L144 | def post_request(profile, resource, payload):
"""Do a POST request to Github's API.
Args:
profile
A profile generated from ``simplygithub.authentication.profile``.
Such profiles tell this module (i) the ``repo`` to connect to,
and (ii) the ``token`` to connect with.... | [
"def",
"post_request",
"(",
"profile",
",",
"resource",
",",
"payload",
")",
":",
"url",
"=",
"get_url",
"(",
"profile",
",",
"resource",
")",
"headers",
"=",
"get_headers",
"(",
"profile",
")",
"response",
"=",
"requests",
".",
"post",
"(",
"url",
",",
... | Do a POST request to Github's API.
Args:
profile
A profile generated from ``simplygithub.authentication.profile``.
Such profiles tell this module (i) the ``repo`` to connect to,
and (ii) the ``token`` to connect with.
resource
The part of a Github A... | [
"Do",
"a",
"POST",
"request",
"to",
"Github",
"s",
"API",
"."
] | python | train | 33.076923 |
codelv/enaml-native | src/enamlnative/android/android_list_view.py | https://github.com/codelv/enaml-native/blob/c33986e9eda468c508806e0a3e73c771401e5718/src/enamlnative/android/android_list_view.py#L268-L290 | def _on_items_changed(self, change):
""" Observe container events on the items list and update the
adapter appropriately.
"""
if change['type'] != 'container':
return
op = change['operation']
if op == 'append':
i = len(change['value'])-1
... | [
"def",
"_on_items_changed",
"(",
"self",
",",
"change",
")",
":",
"if",
"change",
"[",
"'type'",
"]",
"!=",
"'container'",
":",
"return",
"op",
"=",
"change",
"[",
"'operation'",
"]",
"if",
"op",
"==",
"'append'",
":",
"i",
"=",
"len",
"(",
"change",
... | Observe container events on the items list and update the
adapter appropriately. | [
"Observe",
"container",
"events",
"on",
"the",
"items",
"list",
"and",
"update",
"the",
"adapter",
"appropriately",
"."
] | python | train | 40.043478 |
apache/incubator-mxnet | python/mxnet/optimizer/optimizer.py | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/optimizer/optimizer.py#L266-L291 | def update_multi_precision(self, index, weight, grad, state):
"""Updates the given parameter using the corresponding gradient and state.
Mixed precision version.
Parameters
----------
index : int
The unique index of the parameter into the individual learning
... | [
"def",
"update_multi_precision",
"(",
"self",
",",
"index",
",",
"weight",
",",
"grad",
",",
"state",
")",
":",
"if",
"self",
".",
"multi_precision",
"and",
"weight",
".",
"dtype",
"==",
"numpy",
".",
"float16",
":",
"# Wrapper for mixed precision",
"weight_ma... | Updates the given parameter using the corresponding gradient and state.
Mixed precision version.
Parameters
----------
index : int
The unique index of the parameter into the individual learning
rates and weight decays. Learning rates and weight decay
... | [
"Updates",
"the",
"given",
"parameter",
"using",
"the",
"corresponding",
"gradient",
"and",
"state",
".",
"Mixed",
"precision",
"version",
"."
] | python | train | 43.5 |
ClericPy/torequests | torequests/crawlers.py | https://github.com/ClericPy/torequests/blob/1793261688d7a47e1c3a0830d83f8552f5e3e5d9/torequests/crawlers.py#L282-L323 | def reset_new_request(self):
"""Remove the non-sense args from the self.ignore, return self.new_request"""
raw_url = self.new_request['url']
parsed_url = urlparse(raw_url)
qsl = parse_qsl(parsed_url.query)
new_url = self._join_url(
parsed_url, [i for i in qsl if i not... | [
"def",
"reset_new_request",
"(",
"self",
")",
":",
"raw_url",
"=",
"self",
".",
"new_request",
"[",
"'url'",
"]",
"parsed_url",
"=",
"urlparse",
"(",
"raw_url",
")",
"qsl",
"=",
"parse_qsl",
"(",
"parsed_url",
".",
"query",
")",
"new_url",
"=",
"self",
"... | Remove the non-sense args from the self.ignore, return self.new_request | [
"Remove",
"the",
"non",
"-",
"sense",
"args",
"from",
"the",
"self",
".",
"ignore",
"return",
"self",
".",
"new_request"
] | python | train | 46.619048 |
pgmpy/pgmpy | ez_setup.py | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/ez_setup.py#L335-L354 | def _parse_args():
"""
Parse the command line for options
"""
parser = optparse.OptionParser()
parser.add_option(
'--user', dest='user_install', action='store_true', default=False,
help='install in user site package (requires Python 2.6 or later)')
parser.add_option(
'--d... | [
"def",
"_parse_args",
"(",
")",
":",
"parser",
"=",
"optparse",
".",
"OptionParser",
"(",
")",
"parser",
".",
"add_option",
"(",
"'--user'",
",",
"dest",
"=",
"'user_install'",
",",
"action",
"=",
"'store_true'",
",",
"default",
"=",
"False",
",",
"help",
... | Parse the command line for options | [
"Parse",
"the",
"command",
"line",
"for",
"options"
] | python | train | 39.35 |
s-m-i-t-a/railroad | railroad/actions.py | https://github.com/s-m-i-t-a/railroad/blob/ddb4afa018b8523b5d8c3a86e55388d1ea0ab37c/railroad/actions.py#L8-L32 | def actions(acts, done):
'''
Prepare actions pipeline.
:param tuple acts: called functions
:param function done: get result from actions
:returns function: function that starts executio
'''
def _intermediate(acc, action):
result = action(acc['state'])
values = concatv(acc['... | [
"def",
"actions",
"(",
"acts",
",",
"done",
")",
":",
"def",
"_intermediate",
"(",
"acc",
",",
"action",
")",
":",
"result",
"=",
"action",
"(",
"acc",
"[",
"'state'",
"]",
")",
"values",
"=",
"concatv",
"(",
"acc",
"[",
"'values'",
"]",
",",
"[",
... | Prepare actions pipeline.
:param tuple acts: called functions
:param function done: get result from actions
:returns function: function that starts executio | [
"Prepare",
"actions",
"pipeline",
"."
] | python | train | 25.4 |
tkem/cachetools | cachetools/keys.py | https://github.com/tkem/cachetools/blob/1b67cddadccb89993e9d2567bac22e57e2b2b373/cachetools/keys.py#L28-L34 | def hashkey(*args, **kwargs):
"""Return a cache key for the specified hashable arguments."""
if kwargs:
return _HashedTuple(args + sum(sorted(kwargs.items()), _kwmark))
else:
return _HashedTuple(args) | [
"def",
"hashkey",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"kwargs",
":",
"return",
"_HashedTuple",
"(",
"args",
"+",
"sum",
"(",
"sorted",
"(",
"kwargs",
".",
"items",
"(",
")",
")",
",",
"_kwmark",
")",
")",
"else",
":",
"retu... | Return a cache key for the specified hashable arguments. | [
"Return",
"a",
"cache",
"key",
"for",
"the",
"specified",
"hashable",
"arguments",
"."
] | python | train | 31.857143 |
trailofbits/manticore | manticore/utils/helpers.py | https://github.com/trailofbits/manticore/blob/54c5a15b1119c523ae54c09972413e8b97f11629/manticore/utils/helpers.py#L44-L60 | def get_taints(arg, taint=None):
"""
Helper to list an object taints.
:param arg: a value or Expression
:param taint: a regular expression matching a taint value (eg. 'IMPORTANT.*'). If None, this function checks for any taint value.
"""
if not issymbolic(arg):
return
for arg_taint ... | [
"def",
"get_taints",
"(",
"arg",
",",
"taint",
"=",
"None",
")",
":",
"if",
"not",
"issymbolic",
"(",
"arg",
")",
":",
"return",
"for",
"arg_taint",
"in",
"arg",
".",
"taint",
":",
"if",
"taint",
"is",
"not",
"None",
":",
"m",
"=",
"re",
".",
"ma... | Helper to list an object taints.
:param arg: a value or Expression
:param taint: a regular expression matching a taint value (eg. 'IMPORTANT.*'). If None, this function checks for any taint value. | [
"Helper",
"to",
"list",
"an",
"object",
"taints",
".",
":",
"param",
"arg",
":",
"a",
"value",
"or",
"Expression",
":",
"param",
"taint",
":",
"a",
"regular",
"expression",
"matching",
"a",
"taint",
"value",
"(",
"eg",
".",
"IMPORTANT",
".",
"*",
")",
... | python | valid | 30.588235 |
pmacosta/pmisc | pmisc/compat3.py | https://github.com/pmacosta/pmisc/blob/dd2bb32e59eee872f1ef2db2d9921a396ab9f50b/pmisc/compat3.py#L30-L38 | def _readlines(fname, fpointer1=open, fpointer2=open): # pragma: no cover
"""Read all lines from file."""
# fpointer1, fpointer2 arguments to ease testing
try:
with fpointer1(fname, "r") as fobj:
return fobj.readlines()
except UnicodeDecodeError: # pragma: no cover
with fpo... | [
"def",
"_readlines",
"(",
"fname",
",",
"fpointer1",
"=",
"open",
",",
"fpointer2",
"=",
"open",
")",
":",
"# pragma: no cover",
"# fpointer1, fpointer2 arguments to ease testing",
"try",
":",
"with",
"fpointer1",
"(",
"fname",
",",
"\"r\"",
")",
"as",
"fobj",
"... | Read all lines from file. | [
"Read",
"all",
"lines",
"from",
"file",
"."
] | python | train | 43.666667 |
hsolbrig/PyShEx | pyshex/utils/schema_utils.py | https://github.com/hsolbrig/PyShEx/blob/9d659cc36e808afd66d4a6d60e8ea21cb12eb744/pyshex/utils/schema_utils.py#L26-L36 | def triple_reference_of(label: ShExJ.tripleExprLabel, cntxt: Context) -> Optional[ShExJ.tripleExpr]:
""" Search for the label in a Schema """
te: Optional[ShExJ.tripleExpr] = None
if cntxt.schema.start is not None:
te = triple_in_shape(cntxt.schema.start, label, cntxt)
if te is None:
for... | [
"def",
"triple_reference_of",
"(",
"label",
":",
"ShExJ",
".",
"tripleExprLabel",
",",
"cntxt",
":",
"Context",
")",
"->",
"Optional",
"[",
"ShExJ",
".",
"tripleExpr",
"]",
":",
"te",
":",
"Optional",
"[",
"ShExJ",
".",
"tripleExpr",
"]",
"=",
"None",
"i... | Search for the label in a Schema | [
"Search",
"for",
"the",
"label",
"in",
"a",
"Schema"
] | python | train | 41.545455 |
saltstack/salt | salt/states/virt.py | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/states/virt.py#L148-L184 | def _virt_call(domain, function, section, comment,
connection=None, username=None, password=None, **kwargs):
'''
Helper to call the virt functions. Wildcards supported.
:param domain:
:param function:
:param section:
:param comment:
:return:
'''
ret = {'name': domain,... | [
"def",
"_virt_call",
"(",
"domain",
",",
"function",
",",
"section",
",",
"comment",
",",
"connection",
"=",
"None",
",",
"username",
"=",
"None",
",",
"password",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"ret",
"=",
"{",
"'name'",
":",
"domai... | Helper to call the virt functions. Wildcards supported.
:param domain:
:param function:
:param section:
:param comment:
:return: | [
"Helper",
"to",
"call",
"the",
"virt",
"functions",
".",
"Wildcards",
"supported",
"."
] | python | train | 41.405405 |
ultradns/python_rest_api_client | ultra_rest_client/ultra_rest_client.py | https://github.com/ultradns/python_rest_api_client/blob/e4095f28f5cb5e258b768c06ef7cf8b1915aa5ec/ultra_rest_client/ultra_rest_client.py#L311-L330 | def create_rrset(self, zone_name, rtype, owner_name, ttl, rdata):
"""Creates a new RRSet in the specified zone.
Arguments:
zone_name -- The zone that will contain the new RRSet. The trailing dot is optional.
rtype -- The type of the RRSet. This can be numeric (1) or
i... | [
"def",
"create_rrset",
"(",
"self",
",",
"zone_name",
",",
"rtype",
",",
"owner_name",
",",
"ttl",
",",
"rdata",
")",
":",
"if",
"type",
"(",
"rdata",
")",
"is",
"not",
"list",
":",
"rdata",
"=",
"[",
"rdata",
"]",
"rrset",
"=",
"{",
"\"ttl\"",
":"... | Creates a new RRSet in the specified zone.
Arguments:
zone_name -- The zone that will contain the new RRSet. The trailing dot is optional.
rtype -- The type of the RRSet. This can be numeric (1) or
if a well-known name is defined for the type (A), you can use it instead.
... | [
"Creates",
"a",
"new",
"RRSet",
"in",
"the",
"specified",
"zone",
"."
] | python | train | 59.85 |
kentik/kentikapi-py | kentikapi/v5/tagging.py | https://github.com/kentik/kentikapi-py/blob/aa94c0b7eaf88409818b97967d7293e309e11bab/kentikapi/v5/tagging.py#L431-L446 | def submit_populator_batch(self, column_name, batch):
"""Submit a populator batch
Submit a populator batch as a series of HTTP requests in small chunks,
returning the batch GUID, or raising exception on error."""
if not set(column_name).issubset(_allowedCustomDimensionChars):
... | [
"def",
"submit_populator_batch",
"(",
"self",
",",
"column_name",
",",
"batch",
")",
":",
"if",
"not",
"set",
"(",
"column_name",
")",
".",
"issubset",
"(",
"_allowedCustomDimensionChars",
")",
":",
"raise",
"ValueError",
"(",
"'Invalid custom dimension name \"%s\":... | Submit a populator batch
Submit a populator batch as a series of HTTP requests in small chunks,
returning the batch GUID, or raising exception on error. | [
"Submit",
"a",
"populator",
"batch"
] | python | train | 57.25 |
kwikteam/phy | phy/plot/utils.py | https://github.com/kwikteam/phy/blob/7e9313dc364304b7d2bd03b92938347343703003/phy/plot/utils.py#L122-L147 | def _get_texture(arr, default, n_items, from_bounds):
"""Prepare data to be uploaded as a texture.
The from_bounds must be specified.
"""
if not hasattr(default, '__len__'): # pragma: no cover
default = [default]
n_cols = len(default)
if arr is None: # pragma: no cover
arr = ... | [
"def",
"_get_texture",
"(",
"arr",
",",
"default",
",",
"n_items",
",",
"from_bounds",
")",
":",
"if",
"not",
"hasattr",
"(",
"default",
",",
"'__len__'",
")",
":",
"# pragma: no cover",
"default",
"=",
"[",
"default",
"]",
"n_cols",
"=",
"len",
"(",
"de... | Prepare data to be uploaded as a texture.
The from_bounds must be specified. | [
"Prepare",
"data",
"to",
"be",
"uploaded",
"as",
"a",
"texture",
"."
] | python | train | 33.5 |
angr/angr | angr/analyses/vfg.py | https://github.com/angr/angr/blob/4e2f97d56af5419ee73bdb30482c8dd8ff5f3e40/angr/analyses/vfg.py#L1815-L1835 | def _ordered_node_addrs(self, function_address):
"""
For a given function, return all nodes in an optimal traversal order. If the function does not exist, return an
empty list.
:param int function_address: Address of the function.
:return: A ordered list of the nodes.
:r... | [
"def",
"_ordered_node_addrs",
"(",
"self",
",",
"function_address",
")",
":",
"try",
":",
"function",
"=",
"self",
".",
"kb",
".",
"functions",
"[",
"function_address",
"]",
"except",
"KeyError",
":",
"# the function does not exist",
"return",
"[",
"]",
"if",
... | For a given function, return all nodes in an optimal traversal order. If the function does not exist, return an
empty list.
:param int function_address: Address of the function.
:return: A ordered list of the nodes.
:rtype: list | [
"For",
"a",
"given",
"function",
"return",
"all",
"nodes",
"in",
"an",
"optimal",
"traversal",
"order",
".",
"If",
"the",
"function",
"does",
"not",
"exist",
"return",
"an",
"empty",
"list",
"."
] | python | train | 37.142857 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.