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 |
|---|---|---|---|---|---|---|---|---|---|
gwastro/pycbc-glue | pycbc_glue/ligolw/lsctables.py | https://github.com/gwastro/pycbc-glue/blob/a3e906bae59fbfd707c3ff82e5d008d939ec5e24/pycbc_glue/ligolw/lsctables.py#L2121-L2128 | def get_slide_number(self):
"""
Return the slide-number for this trigger
"""
a, slide_number, b = self.get_id_parts()
if slide_number > 5000:
slide_number = 5000 - slide_number
return slide_number | [
"def",
"get_slide_number",
"(",
"self",
")",
":",
"a",
",",
"slide_number",
",",
"b",
"=",
"self",
".",
"get_id_parts",
"(",
")",
"if",
"slide_number",
">",
"5000",
":",
"slide_number",
"=",
"5000",
"-",
"slide_number",
"return",
"slide_number"
] | Return the slide-number for this trigger | [
"Return",
"the",
"slide",
"-",
"number",
"for",
"this",
"trigger"
] | python | train | 25.5 |
saltstack/salt | salt/modules/freebsdkmod.py | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/freebsdkmod.py#L83-L91 | def _set_persistent_module(mod):
'''
Add a module to loader.conf to make it persistent.
'''
if not mod or mod in mod_list(True) or mod not in \
available():
return set()
__salt__['file.append'](_LOADER_CONF, _LOAD_MODULE.format(mod))
return set([mod]) | [
"def",
"_set_persistent_module",
"(",
"mod",
")",
":",
"if",
"not",
"mod",
"or",
"mod",
"in",
"mod_list",
"(",
"True",
")",
"or",
"mod",
"not",
"in",
"available",
"(",
")",
":",
"return",
"set",
"(",
")",
"__salt__",
"[",
"'file.append'",
"]",
"(",
"... | Add a module to loader.conf to make it persistent. | [
"Add",
"a",
"module",
"to",
"loader",
".",
"conf",
"to",
"make",
"it",
"persistent",
"."
] | python | train | 31.888889 |
AdvancedClimateSystems/uModbus | umodbus/utils.py | https://github.com/AdvancedClimateSystems/uModbus/blob/0560a42308003f4072d988f28042b8d55b694ad4/umodbus/utils.py#L10-L23 | def log_to_stream(stream=sys.stderr, level=logging.NOTSET,
fmt=logging.BASIC_FORMAT):
""" Add :class:`logging.StreamHandler` to logger which logs to a stream.
:param stream. Stream to log to, default STDERR.
:param level: Log level, default NOTSET.
:param fmt: String with log format, ... | [
"def",
"log_to_stream",
"(",
"stream",
"=",
"sys",
".",
"stderr",
",",
"level",
"=",
"logging",
".",
"NOTSET",
",",
"fmt",
"=",
"logging",
".",
"BASIC_FORMAT",
")",
":",
"fmt",
"=",
"Formatter",
"(",
"fmt",
")",
"handler",
"=",
"StreamHandler",
"(",
")... | Add :class:`logging.StreamHandler` to logger which logs to a stream.
:param stream. Stream to log to, default STDERR.
:param level: Log level, default NOTSET.
:param fmt: String with log format, default is BASIC_FORMAT. | [
"Add",
":",
"class",
":",
"logging",
".",
"StreamHandler",
"to",
"logger",
"which",
"logs",
"to",
"a",
"stream",
"."
] | python | train | 34.357143 |
GNS3/gns3-server | gns3server/utils/images.py | https://github.com/GNS3/gns3-server/blob/a221678448fb5d24e977ef562f81d56aacc89ab1/gns3server/utils/images.py#L188-L195 | def remove_checksum(path):
"""
Remove the checksum of an image from cache if exists
"""
path = '{}.md5sum'.format(path)
if os.path.exists(path):
os.remove(path) | [
"def",
"remove_checksum",
"(",
"path",
")",
":",
"path",
"=",
"'{}.md5sum'",
".",
"format",
"(",
"path",
")",
"if",
"os",
".",
"path",
".",
"exists",
"(",
"path",
")",
":",
"os",
".",
"remove",
"(",
"path",
")"
] | Remove the checksum of an image from cache if exists | [
"Remove",
"the",
"checksum",
"of",
"an",
"image",
"from",
"cache",
"if",
"exists"
] | python | train | 22.75 |
EventRegistry/event-registry-python | eventregistry/TopicPage.py | https://github.com/EventRegistry/event-registry-python/blob/534d20b616de02f5e1cd73665a02d189645dbeb6/eventregistry/TopicPage.py#L264-L271 | def addSourceGroup(self, sourceGroupUri, weight):
"""
add a list of relevant sources by specifying a whole source group to the topic page
@param sourceGroupUri: uri of the source group to add
@param weight: importance of the provided list of sources (typically in range 1 - 50)
""... | [
"def",
"addSourceGroup",
"(",
"self",
",",
"sourceGroupUri",
",",
"weight",
")",
":",
"assert",
"isinstance",
"(",
"weight",
",",
"(",
"float",
",",
"int",
")",
")",
",",
"\"weight value has to be a positive or negative integer\"",
"self",
".",
"topicPage",
"[",
... | add a list of relevant sources by specifying a whole source group to the topic page
@param sourceGroupUri: uri of the source group to add
@param weight: importance of the provided list of sources (typically in range 1 - 50) | [
"add",
"a",
"list",
"of",
"relevant",
"sources",
"by",
"specifying",
"a",
"whole",
"source",
"group",
"to",
"the",
"topic",
"page"
] | python | train | 63.125 |
valohai/valohai-yaml | valohai_yaml/objs/step.py | https://github.com/valohai/valohai-yaml/blob/3d2e92381633d84cdba039f6905df34c9633a2e1/valohai_yaml/objs/step.py#L92-L118 | def build_command(self, parameter_values, command=None):
"""
Build the command for this step using the given parameter values.
Even if the original configuration only declared a single `command`,
this function will return a list of shell commands. It is the caller's
responsibil... | [
"def",
"build_command",
"(",
"self",
",",
"parameter_values",
",",
"command",
"=",
"None",
")",
":",
"command",
"=",
"(",
"command",
"or",
"self",
".",
"command",
")",
"# merge defaults with passed values",
"# ignore flag default values as they are special",
"# undefine... | Build the command for this step using the given parameter values.
Even if the original configuration only declared a single `command`,
this function will return a list of shell commands. It is the caller's
responsibility to concatenate them, likely using the semicolon or
double ampersa... | [
"Build",
"the",
"command",
"for",
"this",
"step",
"using",
"the",
"given",
"parameter",
"values",
"."
] | python | train | 44.481481 |
ckoepp/TwitterSearch | TwitterSearch/TwitterSearch.py | https://github.com/ckoepp/TwitterSearch/blob/627b9f519d49faf6b83859717f9082b3b2622aaf/TwitterSearch/TwitterSearch.py#L151-L170 | def authenticate(self, verify=True):
""" Creates an authenticated and internal oauth2 handler needed for \
queries to Twitter and verifies credentials if needed. If ``verify`` \
is true, it also checks if the user credentials are valid. \
The **default** value is *True*
:param... | [
"def",
"authenticate",
"(",
"self",
",",
"verify",
"=",
"True",
")",
":",
"self",
".",
"__oauth",
"=",
"OAuth1",
"(",
"self",
".",
"__consumer_key",
",",
"client_secret",
"=",
"self",
".",
"__consumer_secret",
",",
"resource_owner_key",
"=",
"self",
".",
"... | Creates an authenticated and internal oauth2 handler needed for \
queries to Twitter and verifies credentials if needed. If ``verify`` \
is true, it also checks if the user credentials are valid. \
The **default** value is *True*
:param verify: boolean variable to \
directly c... | [
"Creates",
"an",
"authenticated",
"and",
"internal",
"oauth2",
"handler",
"needed",
"for",
"\\",
"queries",
"to",
"Twitter",
"and",
"verifies",
"credentials",
"if",
"needed",
".",
"If",
"verify",
"\\",
"is",
"true",
"it",
"also",
"checks",
"if",
"the",
"user... | python | train | 45.35 |
tensorflow/tensor2tensor | tensor2tensor/layers/common_layers.py | https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_layers.py#L2322-L2386 | def sru(x,
num_layers=2,
activation=None,
initial_state=None,
name=None,
reuse=None):
"""SRU cell as in https://arxiv.org/abs/1709.02755.
As defined in the paper:
(1) x'_t = W x_t
(2) f_t = sigmoid(Wf x_t + bf)
(3) r_t = sigmoid(Wr x_t + br)
(4) c_t = f_t * c_{t-1} +... | [
"def",
"sru",
"(",
"x",
",",
"num_layers",
"=",
"2",
",",
"activation",
"=",
"None",
",",
"initial_state",
"=",
"None",
",",
"name",
"=",
"None",
",",
"reuse",
"=",
"None",
")",
":",
"if",
"num_layers",
"<",
"1",
":",
"raise",
"ValueError",
"(",
"\... | SRU cell as in https://arxiv.org/abs/1709.02755.
As defined in the paper:
(1) x'_t = W x_t
(2) f_t = sigmoid(Wf x_t + bf)
(3) r_t = sigmoid(Wr x_t + br)
(4) c_t = f_t * c_{t-1} + (1 - f_t) * x'_t
(5) h_t = r_t * activation(c_t) + (1 - r_t) * x_t
This version uses functional ops to be faster on GPUs with... | [
"SRU",
"cell",
"as",
"in",
"https",
":",
"//",
"arxiv",
".",
"org",
"/",
"abs",
"/",
"1709",
".",
"02755",
"."
] | python | train | 38.384615 |
learningequality/morango | morango/signals.py | https://github.com/learningequality/morango/blob/c3ec2554b026f65ac5f0fc5c9d439277fbac14f9/morango/signals.py#L8-L14 | def add_to_deleted_models(sender, instance=None, *args, **kwargs):
"""
Whenever a model is deleted, we record its ID in a separate model for tracking purposes. During serialization, we will mark
the model as deleted in the store.
"""
if issubclass(sender, SyncableModel):
instance._update_del... | [
"def",
"add_to_deleted_models",
"(",
"sender",
",",
"instance",
"=",
"None",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"issubclass",
"(",
"sender",
",",
"SyncableModel",
")",
":",
"instance",
".",
"_update_deleted_models",
"(",
")"
] | Whenever a model is deleted, we record its ID in a separate model for tracking purposes. During serialization, we will mark
the model as deleted in the store. | [
"Whenever",
"a",
"model",
"is",
"deleted",
"we",
"record",
"its",
"ID",
"in",
"a",
"separate",
"model",
"for",
"tracking",
"purposes",
".",
"During",
"serialization",
"we",
"will",
"mark",
"the",
"model",
"as",
"deleted",
"in",
"the",
"store",
"."
] | python | valid | 46.714286 |
inveniosoftware/invenio-access | invenio_access/ext.py | https://github.com/inveniosoftware/invenio-access/blob/3b033a4bdc110eb2f7e9f08f0744a780884bfc80/invenio_access/ext.py#L82-L93 | def delete_action_cache(self, action_key):
"""Delete action needs and excludes from cache.
.. note:: It returns the action if a cache system is defined.
:param action_key: The unique action name.
"""
if self.cache:
self.cache.delete(
self.app.config[... | [
"def",
"delete_action_cache",
"(",
"self",
",",
"action_key",
")",
":",
"if",
"self",
".",
"cache",
":",
"self",
".",
"cache",
".",
"delete",
"(",
"self",
".",
"app",
".",
"config",
"[",
"'ACCESS_ACTION_CACHE_PREFIX'",
"]",
"+",
"action_key",
")"
] | Delete action needs and excludes from cache.
.. note:: It returns the action if a cache system is defined.
:param action_key: The unique action name. | [
"Delete",
"action",
"needs",
"and",
"excludes",
"from",
"cache",
"."
] | python | train | 31.75 |
saltstack/salt | salt/modules/zookeeper.py | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/zookeeper.py#L428-L474 | def set_acls(path, acls, version=-1, profile=None, hosts=None, scheme=None,
username=None, password=None, default_acl=None):
'''
Set acls on a znode
path
path to znode
acls
list of acl dictionaries to set on the znode
version
only set acls if version matches (... | [
"def",
"set_acls",
"(",
"path",
",",
"acls",
",",
"version",
"=",
"-",
"1",
",",
"profile",
"=",
"None",
",",
"hosts",
"=",
"None",
",",
"scheme",
"=",
"None",
",",
"username",
"=",
"None",
",",
"password",
"=",
"None",
",",
"default_acl",
"=",
"No... | Set acls on a znode
path
path to znode
acls
list of acl dictionaries to set on the znode
version
only set acls if version matches (Default: -1 (always matches))
profile
Configured Zookeeper profile to authenticate with (Default: None)
hosts
Lists of Zooke... | [
"Set",
"acls",
"on",
"a",
"znode"
] | python | train | 29.659574 |
pypa/pipenv | pipenv/patched/notpip/_vendor/lockfile/pidlockfile.py | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/patched/notpip/_vendor/lockfile/pidlockfile.py#L176-L190 | def remove_existing_pidfile(pidfile_path):
""" Remove the named PID file if it exists.
Removing a PID file that doesn't already exist puts us in the
desired state, so we ignore the condition if the file does not
exist.
"""
try:
os.remove(pidfile_path)
except OSError... | [
"def",
"remove_existing_pidfile",
"(",
"pidfile_path",
")",
":",
"try",
":",
"os",
".",
"remove",
"(",
"pidfile_path",
")",
"except",
"OSError",
"as",
"exc",
":",
"if",
"exc",
".",
"errno",
"==",
"errno",
".",
"ENOENT",
":",
"pass",
"else",
":",
"raise"
... | Remove the named PID file if it exists.
Removing a PID file that doesn't already exist puts us in the
desired state, so we ignore the condition if the file does not
exist. | [
"Remove",
"the",
"named",
"PID",
"file",
"if",
"it",
"exists",
"."
] | python | train | 26.733333 |
python-diamond/Diamond | src/diamond/collector.py | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/diamond/collector.py#L544-L553 | def get_default_config(self):
"""
Returns the default collector settings
"""
config = super(ProcessCollector, self).get_default_config()
config.update({
'use_sudo': False,
'sudo_cmd': self.find_binary('/usr/bin/sudo'),
})
return con... | [
"def",
"get_default_config",
"(",
"self",
")",
":",
"config",
"=",
"super",
"(",
"ProcessCollector",
",",
"self",
")",
".",
"get_default_config",
"(",
")",
"config",
".",
"update",
"(",
"{",
"'use_sudo'",
":",
"False",
",",
"'sudo_cmd'",
":",
"self",
".",
... | Returns the default collector settings | [
"Returns",
"the",
"default",
"collector",
"settings"
] | python | train | 31.4 |
hannes-brt/hebel | hebel/layers/hidden_layer.py | https://github.com/hannes-brt/hebel/blob/1e2c3a9309c2646103901b26a55be4e312dd5005/hebel/layers/hidden_layer.py#L264-L323 | def backprop(self, input_data, df_output, cache=None):
""" Backpropagate through the hidden layer
**Parameters:**
input_data : ``GPUArray``
Input data to compute activations for.
df_output : ``GPUArray``
Gradients with respect to the activations of this layer
... | [
"def",
"backprop",
"(",
"self",
",",
"input_data",
",",
"df_output",
",",
"cache",
"=",
"None",
")",
":",
"# Get cache if it wasn't provided",
"if",
"cache",
"is",
"None",
":",
"cache",
"=",
"self",
".",
"feed_forward",
"(",
"input_data",
",",
"prediction",
... | Backpropagate through the hidden layer
**Parameters:**
input_data : ``GPUArray``
Input data to compute activations for.
df_output : ``GPUArray``
Gradients with respect to the activations of this layer
(received from the layer above).
cache : list o... | [
"Backpropagate",
"through",
"the",
"hidden",
"layer"
] | python | train | 31.5 |
Microsoft/nni | src/sdk/pynni/nni/networkmorphism_tuner/layer_transformer.py | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/networkmorphism_tuner/layer_transformer.py#L142-L166 | def wider_next_conv(layer, start_dim, total_dim, n_add, weighted=True):
'''wider next conv layer.
'''
n_dim = get_n_dim(layer)
if not weighted:
return get_conv_class(n_dim)(layer.input_channel + n_add,
layer.filters,
kerne... | [
"def",
"wider_next_conv",
"(",
"layer",
",",
"start_dim",
",",
"total_dim",
",",
"n_add",
",",
"weighted",
"=",
"True",
")",
":",
"n_dim",
"=",
"get_n_dim",
"(",
"layer",
")",
"if",
"not",
"weighted",
":",
"return",
"get_conv_class",
"(",
"n_dim",
")",
"... | wider next conv layer. | [
"wider",
"next",
"conv",
"layer",
"."
] | python | train | 45 |
siemens/django-dingos | dingos/models.py | https://github.com/siemens/django-dingos/blob/7154f75b06d2538568e2f2455a76f3d0db0b7d70/dingos/models.py#L1496-L1508 | def set_name(self,name=None):
"""
Set the name of the object. If no name is given, the
name is extracted via the extract_name method.
"""
if name:
self.name = name[:254]
else:
self.name = self.extract_name()[:254]
self.save()
retu... | [
"def",
"set_name",
"(",
"self",
",",
"name",
"=",
"None",
")",
":",
"if",
"name",
":",
"self",
".",
"name",
"=",
"name",
"[",
":",
"254",
"]",
"else",
":",
"self",
".",
"name",
"=",
"self",
".",
"extract_name",
"(",
")",
"[",
":",
"254",
"]",
... | Set the name of the object. If no name is given, the
name is extracted via the extract_name method. | [
"Set",
"the",
"name",
"of",
"the",
"object",
".",
"If",
"no",
"name",
"is",
"given",
"the",
"name",
"is",
"extracted",
"via",
"the",
"extract_name",
"method",
"."
] | python | train | 24.615385 |
aliyun/aliyun-odps-python-sdk | odps/df/expr/strings.py | https://github.com/aliyun/aliyun-odps-python-sdk/blob/4b0de18f5864386df6068f26f026e62f932c41e4/odps/df/expr/strings.py#L576-L597 | def _pad(expr, width, side='left', fillchar=' '):
"""
Pad strings in the sequence or scalar with an additional character to specified side.
:param expr:
:param width: Minimum width of resulting string; additional characters will be filled with spaces
:param side: {‘left’, ‘right’, ‘both’}, default ... | [
"def",
"_pad",
"(",
"expr",
",",
"width",
",",
"side",
"=",
"'left'",
",",
"fillchar",
"=",
"' '",
")",
":",
"if",
"not",
"isinstance",
"(",
"fillchar",
",",
"six",
".",
"string_types",
")",
":",
"msg",
"=",
"'fillchar must be a character, not {0}'",
"rais... | Pad strings in the sequence or scalar with an additional character to specified side.
:param expr:
:param width: Minimum width of resulting string; additional characters will be filled with spaces
:param side: {‘left’, ‘right’, ‘both’}, default ‘left’
:param fillchar: Additional character for filling, ... | [
"Pad",
"strings",
"in",
"the",
"sequence",
"or",
"scalar",
"with",
"an",
"additional",
"character",
"to",
"specified",
"side",
"."
] | python | train | 38.636364 |
raphaelm/django-hierarkey | hierarkey/proxy.py | https://github.com/raphaelm/django-hierarkey/blob/3ca822f94fa633c9a6d5abe9c80cb1551299ae46/hierarkey/proxy.py#L191-L207 | def set(self, key: str, value: Any) -> None:
"""
Stores a setting to the database of its object.
The write to the database is performed immediately and the cache in the cache backend is flushed.
The cache within this object will be updated correctly.
"""
wc = se... | [
"def",
"set",
"(",
"self",
",",
"key",
":",
"str",
",",
"value",
":",
"Any",
")",
"->",
"None",
":",
"wc",
"=",
"self",
".",
"_write_cache",
"(",
")",
"if",
"key",
"in",
"wc",
":",
"s",
"=",
"wc",
"[",
"key",
"]",
"else",
":",
"s",
"=",
"se... | Stores a setting to the database of its object.
The write to the database is performed immediately and the cache in the cache backend is flushed.
The cache within this object will be updated correctly. | [
"Stores",
"a",
"setting",
"to",
"the",
"database",
"of",
"its",
"object",
".",
"The",
"write",
"to",
"the",
"database",
"is",
"performed",
"immediately",
"and",
"the",
"cache",
"in",
"the",
"cache",
"backend",
"is",
"flushed",
".",
"The",
"cache",
"within"... | python | train | 34.529412 |
ska-sa/katcp-python | katcp/client.py | https://github.com/ska-sa/katcp-python/blob/9127c826a1d030c53b84d0e95743e20e5c5ea153/katcp/client.py#L1199-L1240 | def future_request(self, msg, timeout=None, use_mid=None):
"""Send a request messsage, with future replies.
Parameters
----------
msg : Message object
The request Message to send.
timeout : float in seconds
How long to wait for a reply. The default is the... | [
"def",
"future_request",
"(",
"self",
",",
"msg",
",",
"timeout",
"=",
"None",
",",
"use_mid",
"=",
"None",
")",
":",
"if",
"timeout",
"is",
"None",
":",
"timeout",
"=",
"self",
".",
"_request_timeout",
"f",
"=",
"tornado_Future",
"(",
")",
"informs",
... | Send a request messsage, with future replies.
Parameters
----------
msg : Message object
The request Message to send.
timeout : float in seconds
How long to wait for a reply. The default is the
the timeout set when creating the AsyncClient.
us... | [
"Send",
"a",
"request",
"messsage",
"with",
"future",
"replies",
"."
] | python | train | 29.833333 |
ldo/dbussy | dbussy.py | https://github.com/ldo/dbussy/blob/59e4fbe8b8111ceead884e50d1973901a0a2d240/dbussy.py#L5539-L5545 | def signature_validate(signature, error = None) :
"is signature a valid sequence of zero or more complete types."
error, my_error = _get_error(error)
result = dbus.dbus_signature_validate(signature.encode(), error._dbobj) != 0
my_error.raise_if_set()
return \
result | [
"def",
"signature_validate",
"(",
"signature",
",",
"error",
"=",
"None",
")",
":",
"error",
",",
"my_error",
"=",
"_get_error",
"(",
"error",
")",
"result",
"=",
"dbus",
".",
"dbus_signature_validate",
"(",
"signature",
".",
"encode",
"(",
")",
",",
"erro... | is signature a valid sequence of zero or more complete types. | [
"is",
"signature",
"a",
"valid",
"sequence",
"of",
"zero",
"or",
"more",
"complete",
"types",
"."
] | python | train | 41.142857 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavextra.py | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavextra.py#L170-L178 | def average(var, key, N):
'''average over N points'''
global average_data
if not key in average_data:
average_data[key] = [var]*N
return var
average_data[key].pop(0)
average_data[key].append(var)
return sum(average_data[key])/N | [
"def",
"average",
"(",
"var",
",",
"key",
",",
"N",
")",
":",
"global",
"average_data",
"if",
"not",
"key",
"in",
"average_data",
":",
"average_data",
"[",
"key",
"]",
"=",
"[",
"var",
"]",
"*",
"N",
"return",
"var",
"average_data",
"[",
"key",
"]",
... | average over N points | [
"average",
"over",
"N",
"points"
] | python | train | 28.777778 |
spyder-ide/spyder | spyder/py3compat.py | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/py3compat.py#L150-L160 | def to_binary_string(obj, encoding=None):
"""Convert `obj` to binary string (bytes in Python 3, str in Python 2)"""
if PY2:
# Python 2
if encoding is None:
return str(obj)
else:
return obj.encode(encoding)
else:
# Python 3
return byte... | [
"def",
"to_binary_string",
"(",
"obj",
",",
"encoding",
"=",
"None",
")",
":",
"if",
"PY2",
":",
"# Python 2\r",
"if",
"encoding",
"is",
"None",
":",
"return",
"str",
"(",
"obj",
")",
"else",
":",
"return",
"obj",
".",
"encode",
"(",
"encoding",
")",
... | Convert `obj` to binary string (bytes in Python 3, str in Python 2) | [
"Convert",
"obj",
"to",
"binary",
"string",
"(",
"bytes",
"in",
"Python",
"3",
"str",
"in",
"Python",
"2",
")"
] | python | train | 32.636364 |
assemblerflow/flowcraft | flowcraft/generator/inspect.py | https://github.com/assemblerflow/flowcraft/blob/fc3f4bddded1efc76006600016dc71a06dd908c0/flowcraft/generator/inspect.py#L1533-L1550 | def _get_run_hash(self):
"""Gets the hash of the nextflow file"""
# Get name and path of the pipeline from the log file
pipeline_path = get_nextflow_filepath(self.log_file)
# Get hash from the entire pipeline file
pipeline_hash = hashlib.md5()
with open(pipeline_path, "... | [
"def",
"_get_run_hash",
"(",
"self",
")",
":",
"# Get name and path of the pipeline from the log file",
"pipeline_path",
"=",
"get_nextflow_filepath",
"(",
"self",
".",
"log_file",
")",
"# Get hash from the entire pipeline file",
"pipeline_hash",
"=",
"hashlib",
".",
"md5",
... | Gets the hash of the nextflow file | [
"Gets",
"the",
"hash",
"of",
"the",
"nextflow",
"file"
] | python | test | 42.777778 |
msmbuilder/msmbuilder | msmbuilder/example_datasets/brownian1d.py | https://github.com/msmbuilder/msmbuilder/blob/556a93a170782f47be53f4a1e9d740fb1c8272b3/msmbuilder/example_datasets/brownian1d.py#L253-L258 | def _brownian_eigs(n_grid, lag_time, grad_potential, xmin, xmax, reflect_bc):
"""Analytic eigenvalues/eigenvectors for 1D Brownian dynamics
"""
transmat = _brownian_transmat(n_grid, lag_time, grad_potential, xmin, xmax, reflect_bc)
u, lv, rv = _solve_msm_eigensystem(transmat, k=len(transmat) - 1)
re... | [
"def",
"_brownian_eigs",
"(",
"n_grid",
",",
"lag_time",
",",
"grad_potential",
",",
"xmin",
",",
"xmax",
",",
"reflect_bc",
")",
":",
"transmat",
"=",
"_brownian_transmat",
"(",
"n_grid",
",",
"lag_time",
",",
"grad_potential",
",",
"xmin",
",",
"xmax",
","... | Analytic eigenvalues/eigenvectors for 1D Brownian dynamics | [
"Analytic",
"eigenvalues",
"/",
"eigenvectors",
"for",
"1D",
"Brownian",
"dynamics"
] | python | train | 54.166667 |
happyleavesaoc/python-voobly | voobly/__init__.py | https://github.com/happyleavesaoc/python-voobly/blob/83b4ab7d630a00459c2a64e55e3ac85c7be38194/voobly/__init__.py#L201-L210 | def get_user(session, user_id):
"""Get user."""
try:
user_id = int(user_id)
except ValueError:
user_id = find_user(session, user_id)
resp = _make_request(session, USER_URL, user_id)
if not resp:
raise VooblyError('user id not found')
return resp[0] | [
"def",
"get_user",
"(",
"session",
",",
"user_id",
")",
":",
"try",
":",
"user_id",
"=",
"int",
"(",
"user_id",
")",
"except",
"ValueError",
":",
"user_id",
"=",
"find_user",
"(",
"session",
",",
"user_id",
")",
"resp",
"=",
"_make_request",
"(",
"sessio... | Get user. | [
"Get",
"user",
"."
] | python | train | 28.7 |
JNRowe/jnrbase | jnrbase/template.py | https://github.com/JNRowe/jnrbase/blob/ae505ef69a9feb739b5f4e62c5a8e6533104d3ea/jnrbase/template.py#L145-L162 | def setup(__pkg: str) -> jinja2.Environment:
"""Configure a new Jinja environment with our filters.
Args:
__pkg: Package name to use as base for templates searches
Returns:
Configured Jinja environment
"""
dirs = [path.join(d, 'templates')
for d in xdg_basedir.get_data_d... | [
"def",
"setup",
"(",
"__pkg",
":",
"str",
")",
"->",
"jinja2",
".",
"Environment",
":",
"dirs",
"=",
"[",
"path",
".",
"join",
"(",
"d",
",",
"'templates'",
")",
"for",
"d",
"in",
"xdg_basedir",
".",
"get_data_dirs",
"(",
"__pkg",
")",
"]",
"env",
... | Configure a new Jinja environment with our filters.
Args:
__pkg: Package name to use as base for templates searches
Returns:
Configured Jinja environment | [
"Configure",
"a",
"new",
"Jinja",
"environment",
"with",
"our",
"filters",
"."
] | python | train | 33.722222 |
cltl/KafNafParserPy | KafNafParserPy/feature_extractor/constituency.py | https://github.com/cltl/KafNafParserPy/blob/9bc32e803c176404b255ba317479b8780ed5f569/KafNafParserPy/feature_extractor/constituency.py#L137-L173 | def get_path_from_to(self,from_tid, to_tid):
"""
This function returns the path (in terms of phrase types) from one term to another
@type from_tid: string
@param from_tid: one term id
@type to_tid: string
@param to_tid: another term id
@rtype: list
@return... | [
"def",
"get_path_from_to",
"(",
"self",
",",
"from_tid",
",",
"to_tid",
")",
":",
"shortest_subsumer",
"=",
"self",
".",
"get_least_common_subsumer",
"(",
"from_tid",
",",
"to_tid",
")",
"#print 'From:',self.naf.get_term(from_tid).get_lemma()",
"#print 'To:',self.naf.get_te... | This function returns the path (in terms of phrase types) from one term to another
@type from_tid: string
@param from_tid: one term id
@type to_tid: string
@param to_tid: another term id
@rtype: list
@return: the path, list of phrase types | [
"This",
"function",
"returns",
"the",
"path",
"(",
"in",
"terms",
"of",
"phrase",
"types",
")",
"from",
"one",
"term",
"to",
"another"
] | python | train | 35.567568 |
Bonsanto/polygon-geohasher | polygon_geohasher/polygon_geohasher.py | https://github.com/Bonsanto/polygon-geohasher/blob/63f27f41ea3e9d8fda7872d86217719286037c11/polygon_geohasher/polygon_geohasher.py#L23-L62 | def polygon_to_geohashes(polygon, precision, inner=True):
"""
:param polygon: shapely polygon.
:param precision: int. Geohashes' precision that form resulting polygon.
:param inner: bool, default 'True'. If false, geohashes that are completely outside from the polygon are ignored.
:return: set. Set ... | [
"def",
"polygon_to_geohashes",
"(",
"polygon",
",",
"precision",
",",
"inner",
"=",
"True",
")",
":",
"inner_geohashes",
"=",
"set",
"(",
")",
"outer_geohashes",
"=",
"set",
"(",
")",
"envelope",
"=",
"polygon",
".",
"envelope",
"centroid",
"=",
"polygon",
... | :param polygon: shapely polygon.
:param precision: int. Geohashes' precision that form resulting polygon.
:param inner: bool, default 'True'. If false, geohashes that are completely outside from the polygon are ignored.
:return: set. Set of geohashes that form the polygon. | [
":",
"param",
"polygon",
":",
"shapely",
"polygon",
".",
":",
"param",
"precision",
":",
"int",
".",
"Geohashes",
"precision",
"that",
"form",
"resulting",
"polygon",
".",
":",
"param",
"inner",
":",
"bool",
"default",
"True",
".",
"If",
"false",
"geohashe... | python | train | 41.45 |
CivicSpleen/ambry | ambry/orm/__init__.py | https://github.com/CivicSpleen/ambry/blob/d7f2be4bf1f7ffd086f3fadd4fcae60c32473e42/ambry/orm/__init__.py#L74-L89 | def table_convert_geometry(metadata, table_name):
"""Get table metadata from the database."""
from sqlalchemy import Table
from ..orm import Geometry
table = Table(table_name, metadata, autoload=True)
for c in table.columns:
# HACK! Sqlalchemy sees spatialte GEOMETRY types
# as NU... | [
"def",
"table_convert_geometry",
"(",
"metadata",
",",
"table_name",
")",
":",
"from",
"sqlalchemy",
"import",
"Table",
"from",
".",
".",
"orm",
"import",
"Geometry",
"table",
"=",
"Table",
"(",
"table_name",
",",
"metadata",
",",
"autoload",
"=",
"True",
")... | Get table metadata from the database. | [
"Get",
"table",
"metadata",
"from",
"the",
"database",
"."
] | python | train | 25.9375 |
estnltk/estnltk | estnltk/syntax/syntax_preprocessing.py | https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/syntax/syntax_preprocessing.py#L954-L960 | def process_Text( self, text, **kwargs ):
''' Executes the preprocessing pipeline on estnltk's Text object.
Returns a list: lines of analyses in the VISL CG3 input format;
'''
mrf_lines = convert_Text_to_mrf( text )
return self.process_mrf_lines( mrf_lines, **kwargs ) | [
"def",
"process_Text",
"(",
"self",
",",
"text",
",",
"*",
"*",
"kwargs",
")",
":",
"mrf_lines",
"=",
"convert_Text_to_mrf",
"(",
"text",
")",
"return",
"self",
".",
"process_mrf_lines",
"(",
"mrf_lines",
",",
"*",
"*",
"kwargs",
")"
] | Executes the preprocessing pipeline on estnltk's Text object.
Returns a list: lines of analyses in the VISL CG3 input format; | [
"Executes",
"the",
"preprocessing",
"pipeline",
"on",
"estnltk",
"s",
"Text",
"object",
"."
] | python | train | 44 |
pandeylab/pythomics | pythomics/proteomics/parsers.py | https://github.com/pandeylab/pythomics/blob/ab0a5651a2e02a25def4d277b35fa09d1631bfcb/pythomics/proteomics/parsers.py#L1490-L1526 | def getScans(self, modifications=False, fdr=True):
"""
get a random scan
"""
if fdr:
sql = self.base_sql+"WHERE p.ConfidenceLevel >= {} and p.SearchEngineRank <= {} {}".format(self.clvl, self.srank, self.extra)
try:
self.cur.execute(sql)
... | [
"def",
"getScans",
"(",
"self",
",",
"modifications",
"=",
"False",
",",
"fdr",
"=",
"True",
")",
":",
"if",
"fdr",
":",
"sql",
"=",
"self",
".",
"base_sql",
"+",
"\"WHERE p.ConfidenceLevel >= {} and p.SearchEngineRank <= {} {}\"",
".",
"format",
"(",
"self",
... | get a random scan | [
"get",
"a",
"random",
"scan"
] | python | train | 39.162162 |
programa-stic/barf-project | barf/core/reil/builder.py | https://github.com/programa-stic/barf-project/blob/18ed9e5eace55f7bf6015ec57f037c364099021c/barf/core/reil/builder.py#L122-L125 | def gen_stm(src, dst):
"""Return a STM instruction.
"""
return ReilBuilder.build(ReilMnemonic.STM, src, ReilEmptyOperand(), dst) | [
"def",
"gen_stm",
"(",
"src",
",",
"dst",
")",
":",
"return",
"ReilBuilder",
".",
"build",
"(",
"ReilMnemonic",
".",
"STM",
",",
"src",
",",
"ReilEmptyOperand",
"(",
")",
",",
"dst",
")"
] | Return a STM instruction. | [
"Return",
"a",
"STM",
"instruction",
"."
] | python | train | 37.25 |
angr/angr | angr/analyses/cfg/cfg_base.py | https://github.com/angr/angr/blob/4e2f97d56af5419ee73bdb30482c8dd8ff5f3e40/angr/analyses/cfg/cfg_base.py#L2120-L2143 | def _process_unresolved_indirect_jumps(self):
"""
Resolve all unresolved indirect jumps found in previous scanning.
Currently we support resolving the following types of indirect jumps:
- Ijk_Call: indirect calls where the function address is passed in from a proceeding basic block
... | [
"def",
"_process_unresolved_indirect_jumps",
"(",
"self",
")",
":",
"l",
".",
"info",
"(",
"\"%d indirect jumps to resolve.\"",
",",
"len",
"(",
"self",
".",
"_indirect_jumps_to_resolve",
")",
")",
"all_targets",
"=",
"set",
"(",
")",
"for",
"idx",
",",
"jump",
... | Resolve all unresolved indirect jumps found in previous scanning.
Currently we support resolving the following types of indirect jumps:
- Ijk_Call: indirect calls where the function address is passed in from a proceeding basic block
- Ijk_Boring: jump tables
- For an up-to-date list, se... | [
"Resolve",
"all",
"unresolved",
"indirect",
"jumps",
"found",
"in",
"previous",
"scanning",
"."
] | python | train | 39.333333 |
PyCQA/astroid | astroid/scoped_nodes.py | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/scoped_nodes.py#L145-L156 | def qname(self):
"""Get the 'qualified' name of the node.
For example: module.name, module.class.name ...
:returns: The qualified name.
:rtype: str
"""
# pylint: disable=no-member; github.com/pycqa/astroid/issues/278
if self.parent is None:
return se... | [
"def",
"qname",
"(",
"self",
")",
":",
"# pylint: disable=no-member; github.com/pycqa/astroid/issues/278",
"if",
"self",
".",
"parent",
"is",
"None",
":",
"return",
"self",
".",
"name",
"return",
"\"%s.%s\"",
"%",
"(",
"self",
".",
"parent",
".",
"frame",
"(",
... | Get the 'qualified' name of the node.
For example: module.name, module.class.name ...
:returns: The qualified name.
:rtype: str | [
"Get",
"the",
"qualified",
"name",
"of",
"the",
"node",
"."
] | python | train | 31.833333 |
mcs07/ChemDataExtractor | chemdataextractor/cli/chemdner.py | https://github.com/mcs07/ChemDataExtractor/blob/349a3bea965f2073141d62043b89319222e46af1/chemdataextractor/cli/chemdner.py#L47-L67 | def prepare_tokens(ctx, input, annotations, tout, lout):
"""Prepare tokenized and tagged corpus file from those supplied by CHEMDNER."""
click.echo('chemdataextractor.chemdner.prepare_tokens')
# Collect the annotations into a dict
anndict = defaultdict(list)
for line in annotations:
pmid, ta... | [
"def",
"prepare_tokens",
"(",
"ctx",
",",
"input",
",",
"annotations",
",",
"tout",
",",
"lout",
")",
":",
"click",
".",
"echo",
"(",
"'chemdataextractor.chemdner.prepare_tokens'",
")",
"# Collect the annotations into a dict",
"anndict",
"=",
"defaultdict",
"(",
"li... | Prepare tokenized and tagged corpus file from those supplied by CHEMDNER. | [
"Prepare",
"tokenized",
"and",
"tagged",
"corpus",
"file",
"from",
"those",
"supplied",
"by",
"CHEMDNER",
"."
] | python | train | 54.809524 |
NICTA/revrand | revrand/glm.py | https://github.com/NICTA/revrand/blob/4c1881b6c1772d2b988518e49dde954f165acfb6/revrand/glm.py#L349-L418 | def predict_moments(self, X, nsamples=200, likelihood_args=()):
r"""
Predictive moments, in particular mean and variance, of a Bayesian GLM.
This function uses Monte-Carlo sampling to evaluate the predictive mean
and variance of a Bayesian GLM. The exact expressions evaluated are,
... | [
"def",
"predict_moments",
"(",
"self",
",",
"X",
",",
"nsamples",
"=",
"200",
",",
"likelihood_args",
"=",
"(",
")",
")",
":",
"# Get latent function samples",
"N",
"=",
"X",
".",
"shape",
"[",
"0",
"]",
"ys",
"=",
"np",
".",
"empty",
"(",
"(",
"N",
... | r"""
Predictive moments, in particular mean and variance, of a Bayesian GLM.
This function uses Monte-Carlo sampling to evaluate the predictive mean
and variance of a Bayesian GLM. The exact expressions evaluated are,
.. math ::
\mathbb{E}[y^* | \mathbf{x^*}, \mathbf{X}, y... | [
"r",
"Predictive",
"moments",
"in",
"particular",
"mean",
"and",
"variance",
"of",
"a",
"Bayesian",
"GLM",
"."
] | python | train | 43.428571 |
Calysto/calysto | calysto/ai/conx.py | https://github.com/Calysto/calysto/blob/20813c0f48096317aa775d03a5c6b20f12fafc93/calysto/ai/conx.py#L372-L376 | def getCorrect(self, tolerance):
"""
Returns the number of nodes within tolerance of the target.
"""
return Numeric.add.reduce(Numeric.fabs(self.target - self.activation) < tolerance) | [
"def",
"getCorrect",
"(",
"self",
",",
"tolerance",
")",
":",
"return",
"Numeric",
".",
"add",
".",
"reduce",
"(",
"Numeric",
".",
"fabs",
"(",
"self",
".",
"target",
"-",
"self",
".",
"activation",
")",
"<",
"tolerance",
")"
] | Returns the number of nodes within tolerance of the target. | [
"Returns",
"the",
"number",
"of",
"nodes",
"within",
"tolerance",
"of",
"the",
"target",
"."
] | python | train | 42.2 |
DataDog/integrations-core | tokumx/datadog_checks/tokumx/vendor/pymongo/pool.py | https://github.com/DataDog/integrations-core/blob/ebd41c873cf9f97a8c51bf9459bc6a7536af8acd/tokumx/datadog_checks/tokumx/vendor/pymongo/pool.py#L533-L549 | def write_command(self, request_id, msg):
"""Send "insert" etc. command, returning response as a dict.
Can raise ConnectionFailure or OperationFailure.
:Parameters:
- `request_id`: an int.
- `msg`: bytes, the command message.
"""
self.send_message(msg, 0)
... | [
"def",
"write_command",
"(",
"self",
",",
"request_id",
",",
"msg",
")",
":",
"self",
".",
"send_message",
"(",
"msg",
",",
"0",
")",
"response",
"=",
"helpers",
".",
"_unpack_response",
"(",
"self",
".",
"receive_message",
"(",
"1",
",",
"request_id",
"... | Send "insert" etc. command, returning response as a dict.
Can raise ConnectionFailure or OperationFailure.
:Parameters:
- `request_id`: an int.
- `msg`: bytes, the command message. | [
"Send",
"insert",
"etc",
".",
"command",
"returning",
"response",
"as",
"a",
"dict",
"."
] | python | train | 34.764706 |
05bit/peewee-async | peewee_async.py | https://github.com/05bit/peewee-async/blob/d15f4629da1d9975da4ec37306188e68d288c862/peewee_async.py#L558-L577 | async def select(query):
"""Perform SELECT query asynchronously.
"""
assert isinstance(query, peewee.SelectQuery),\
("Error, trying to run select coroutine"
"with wrong query class %s" % str(query))
cursor = await _execute_query_async(query)
result = AsyncQueryWrapper(cursor=curso... | [
"async",
"def",
"select",
"(",
"query",
")",
":",
"assert",
"isinstance",
"(",
"query",
",",
"peewee",
".",
"SelectQuery",
")",
",",
"(",
"\"Error, trying to run select coroutine\"",
"\"with wrong query class %s\"",
"%",
"str",
"(",
"query",
")",
")",
"cursor",
... | Perform SELECT query asynchronously. | [
"Perform",
"SELECT",
"query",
"asynchronously",
"."
] | python | train | 24.2 |
saltstack/salt | salt/modules/jboss7.py | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/jboss7.py#L138-L174 | def create_datasource(jboss_config, name, datasource_properties, profile=None):
'''
Create datasource in running jboss instance
jboss_config
Configuration dictionary with properties specified above.
name
Datasource name
datasource_properties
A dictionary of datasource proper... | [
"def",
"create_datasource",
"(",
"jboss_config",
",",
"name",
",",
"datasource_properties",
",",
"profile",
"=",
"None",
")",
":",
"log",
".",
"debug",
"(",
"\"======================== MODULE FUNCTION: jboss7.create_datasource, name=%s, profile=%s\"",
",",
"name",
",",
"p... | Create datasource in running jboss instance
jboss_config
Configuration dictionary with properties specified above.
name
Datasource name
datasource_properties
A dictionary of datasource properties to be created:
- driver-name: mysql
- connection-url: 'jdbc:mysql:/... | [
"Create",
"datasource",
"in",
"running",
"jboss",
"instance"
] | python | train | 48.486486 |
NuGrid/NuGridPy | nugridpy/mesa.py | https://github.com/NuGrid/NuGridPy/blob/eee8047446e398be77362d82c1d8b3310054fab0/nugridpy/mesa.py#L898-L926 | def _read_starlog(self):
""" read history.data or star.log file again"""
sldir = self.sldir
slname = self.slname
slaname = slname+'sa'
if not os.path.exists(sldir+'/'+slaname):
print('No '+self.slname+'sa file found, create new one from '+self.slname)
... | [
"def",
"_read_starlog",
"(",
"self",
")",
":",
"sldir",
"=",
"self",
".",
"sldir",
"slname",
"=",
"self",
".",
"slname",
"slaname",
"=",
"slname",
"+",
"'sa'",
"if",
"not",
"os",
".",
"path",
".",
"exists",
"(",
"sldir",
"+",
"'/'",
"+",
"slaname",
... | read history.data or star.log file again | [
"read",
"history",
".",
"data",
"or",
"star",
".",
"log",
"file",
"again"
] | python | train | 33.241379 |
tensorpack/tensorpack | examples/SimilarityLearning/mnist-embeddings.py | https://github.com/tensorpack/tensorpack/blob/d7a13cb74c9066bc791d7aafc3b744b60ee79a9f/examples/SimilarityLearning/mnist-embeddings.py#L25-L65 | def contrastive_loss(left, right, y, margin, extra=False, scope="constrastive_loss"):
r"""Loss for Siamese networks as described in the paper:
`Learning a Similarity Metric Discriminatively, with Application to Face
Verification <http://yann.lecun.com/exdb/publis/pdf/chopra-05.pdf>`_ by Chopra et al.
.... | [
"def",
"contrastive_loss",
"(",
"left",
",",
"right",
",",
"y",
",",
"margin",
",",
"extra",
"=",
"False",
",",
"scope",
"=",
"\"constrastive_loss\"",
")",
":",
"with",
"tf",
".",
"name_scope",
"(",
"scope",
")",
":",
"y",
"=",
"tf",
".",
"cast",
"("... | r"""Loss for Siamese networks as described in the paper:
`Learning a Similarity Metric Discriminatively, with Application to Face
Verification <http://yann.lecun.com/exdb/publis/pdf/chopra-05.pdf>`_ by Chopra et al.
.. math::
\frac{1}{2} [y \cdot d^2 + (1-y) \cdot \max(0, m - d)^2], d = \Vert l - r... | [
"r",
"Loss",
"for",
"Siamese",
"networks",
"as",
"described",
"in",
"the",
"paper",
":",
"Learning",
"a",
"Similarity",
"Metric",
"Discriminatively",
"with",
"Application",
"to",
"Face",
"Verification",
"<http",
":",
"//",
"yann",
".",
"lecun",
".",
"com",
"... | python | train | 44.268293 |
coleifer/walrus | walrus/fts.py | https://github.com/coleifer/walrus/blob/82bf15a6613487b5b5fefeb488f186d7e0106547/walrus/fts.py#L65-L82 | def remove(self, key, preserve_data=False):
"""
:param key: Document unique identifier.
Remove the document from the search index.
"""
if self.members.remove(key) != 1:
raise KeyError('Document with key "%s" not found.' % key)
document_hash = self._get_hash(k... | [
"def",
"remove",
"(",
"self",
",",
"key",
",",
"preserve_data",
"=",
"False",
")",
":",
"if",
"self",
".",
"members",
".",
"remove",
"(",
"key",
")",
"!=",
"1",
":",
"raise",
"KeyError",
"(",
"'Document with key \"%s\" not found.'",
"%",
"key",
")",
"doc... | :param key: Document unique identifier.
Remove the document from the search index. | [
":",
"param",
"key",
":",
"Document",
"unique",
"identifier",
"."
] | python | train | 34.222222 |
nefarioustim/parker | parker/fileops.py | https://github.com/nefarioustim/parker/blob/ccc1de1ac6bfb5e0a8cfa4fdebb2f38f2ee027d6/parker/fileops.py#L32-L40 | def dump_string_to_file(string, filepath):
"""Dump @string as a line to @filepath."""
create_dirs(
os.path.dirname(filepath)
)
with open(filepath, 'a') as outfile:
outfile.write(string)
outfile.write('\n') | [
"def",
"dump_string_to_file",
"(",
"string",
",",
"filepath",
")",
":",
"create_dirs",
"(",
"os",
".",
"path",
".",
"dirname",
"(",
"filepath",
")",
")",
"with",
"open",
"(",
"filepath",
",",
"'a'",
")",
"as",
"outfile",
":",
"outfile",
".",
"write",
"... | Dump @string as a line to @filepath. | [
"Dump"
] | python | train | 26.444444 |
isogeo/isogeo-api-py-minsdk | isogeo_pysdk/checker.py | https://github.com/isogeo/isogeo-api-py-minsdk/blob/57a604be92c7767b26abd247012cc1a584b386a0/isogeo_pysdk/checker.py#L156-L173 | def check_api_response(self, response):
"""Check API response and raise exceptions if needed.
:param requests.models.Response response: request response to check
"""
# check response
if response.status_code == 200:
return True
elif response.status_code >= 400... | [
"def",
"check_api_response",
"(",
"self",
",",
"response",
")",
":",
"# check response",
"if",
"response",
".",
"status_code",
"==",
"200",
":",
"return",
"True",
"elif",
"response",
".",
"status_code",
">=",
"400",
":",
"logging",
".",
"error",
"(",
"\"{}: ... | Check API response and raise exceptions if needed.
:param requests.models.Response response: request response to check | [
"Check",
"API",
"response",
"and",
"raise",
"exceptions",
"if",
"needed",
"."
] | python | train | 34.944444 |
mottosso/be | be/vendor/requests/utils.py | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/vendor/requests/utils.py#L676-L692 | def to_native_string(string, encoding='ascii'):
"""
Given a string object, regardless of type, returns a representation of that
string in the native string type, encoding and decoding where necessary.
This assumes ASCII unless told otherwise.
"""
out = None
if isinstance(string, builtin_str... | [
"def",
"to_native_string",
"(",
"string",
",",
"encoding",
"=",
"'ascii'",
")",
":",
"out",
"=",
"None",
"if",
"isinstance",
"(",
"string",
",",
"builtin_str",
")",
":",
"out",
"=",
"string",
"else",
":",
"if",
"is_py2",
":",
"out",
"=",
"string",
".",... | Given a string object, regardless of type, returns a representation of that
string in the native string type, encoding and decoding where necessary.
This assumes ASCII unless told otherwise. | [
"Given",
"a",
"string",
"object",
"regardless",
"of",
"type",
"returns",
"a",
"representation",
"of",
"that",
"string",
"in",
"the",
"native",
"string",
"type",
"encoding",
"and",
"decoding",
"where",
"necessary",
".",
"This",
"assumes",
"ASCII",
"unless",
"to... | python | train | 27.647059 |
googlecolab/jupyter_http_over_ws | jupyter_http_over_ws/handlers.py | https://github.com/googlecolab/jupyter_http_over_ws/blob/21fe278cae6fca4e6c92f92d6d786fae8fdea9b1/jupyter_http_over_ws/handlers.py#L261-L288 | def streaming_callback(self, body_part):
"""Handles a streaming chunk of the response.
The streaming_response callback gives no indication about whether the
received chunk is the last in the stream. The "last_response" instance
variable allows us to keep track of the last received chunk of the
resp... | [
"def",
"streaming_callback",
"(",
"self",
",",
"body_part",
")",
":",
"b64_body_string",
"=",
"base64",
".",
"b64encode",
"(",
"body_part",
")",
".",
"decode",
"(",
"'utf-8'",
")",
"response",
"=",
"{",
"'message_id'",
":",
"self",
".",
"_message_id",
",",
... | Handles a streaming chunk of the response.
The streaming_response callback gives no indication about whether the
received chunk is the last in the stream. The "last_response" instance
variable allows us to keep track of the last received chunk of the
response. Each time this is called, the previous chu... | [
"Handles",
"a",
"streaming",
"chunk",
"of",
"the",
"response",
"."
] | python | train | 38.678571 |
ibis-project/ibis | ibis/expr/api.py | https://github.com/ibis-project/ibis/blob/1e39a5fd9ef088b45c155e8a5f541767ee8ef2e7/ibis/expr/api.py#L1300-L1330 | def quantile(arg, quantile, interpolation='linear'):
"""
Return value at the given quantile, a la numpy.percentile.
Parameters
----------
quantile : float/int or array-like
0 <= quantile <= 1, the quantile(s) to compute
interpolation : {'linear', 'lower', 'higher', 'midpoint', 'nearest'... | [
"def",
"quantile",
"(",
"arg",
",",
"quantile",
",",
"interpolation",
"=",
"'linear'",
")",
":",
"if",
"isinstance",
"(",
"quantile",
",",
"collections",
".",
"abc",
".",
"Sequence",
")",
":",
"op",
"=",
"ops",
".",
"MultiQuantile",
"(",
"arg",
",",
"q... | Return value at the given quantile, a la numpy.percentile.
Parameters
----------
quantile : float/int or array-like
0 <= quantile <= 1, the quantile(s) to compute
interpolation : {'linear', 'lower', 'higher', 'midpoint', 'nearest'}
This optional parameter specifies the interpolation me... | [
"Return",
"value",
"at",
"the",
"given",
"quantile",
"a",
"la",
"numpy",
".",
"percentile",
"."
] | python | train | 34.193548 |
mapbox/mapbox-cli-py | mapboxcli/scripts/mapmatching.py | https://github.com/mapbox/mapbox-cli-py/blob/b75544a2f83a4fda79d78b5673058e16e64a4f6d/mapboxcli/scripts/mapmatching.py#L15-L43 | def match(ctx, features, profile, gps_precision):
"""Mapbox Map Matching API lets you use snap your GPS traces
to the OpenStreetMap road and path network.
$ mapbox mapmatching trace.geojson
An access token is required, see `mapbox --help`.
"""
access_token = (ctx.obj and ctx.obj.get('access_token'))... | [
"def",
"match",
"(",
"ctx",
",",
"features",
",",
"profile",
",",
"gps_precision",
")",
":",
"access_token",
"=",
"(",
"ctx",
".",
"obj",
"and",
"ctx",
".",
"obj",
".",
"get",
"(",
"'access_token'",
")",
")",
"or",
"None",
"features",
"=",
"list",
"(... | Mapbox Map Matching API lets you use snap your GPS traces
to the OpenStreetMap road and path network.
$ mapbox mapmatching trace.geojson
An access token is required, see `mapbox --help`. | [
"Mapbox",
"Map",
"Matching",
"API",
"lets",
"you",
"use",
"snap",
"your",
"GPS",
"traces",
"to",
"the",
"OpenStreetMap",
"road",
"and",
"path",
"network",
"."
] | python | train | 31.689655 |
aetros/aetros-cli | aetros/client.py | https://github.com/aetros/aetros-cli/blob/a2a1f38d6af1660e1e2680c7d413ec2aef45faab/aetros/client.py#L712-L740 | def wait_for_at_least_one_message(self, channel):
"""
Reads until we receive at least one message we can unpack. Return all found messages.
"""
unpacker = msgpack.Unpacker(encoding='utf-8')
while True:
try:
start = time.time()
chunk =... | [
"def",
"wait_for_at_least_one_message",
"(",
"self",
",",
"channel",
")",
":",
"unpacker",
"=",
"msgpack",
".",
"Unpacker",
"(",
"encoding",
"=",
"'utf-8'",
")",
"while",
"True",
":",
"try",
":",
"start",
"=",
"time",
".",
"time",
"(",
")",
"chunk",
"=",... | Reads until we receive at least one message we can unpack. Return all found messages. | [
"Reads",
"until",
"we",
"receive",
"at",
"least",
"one",
"message",
"we",
"can",
"unpack",
".",
"Return",
"all",
"found",
"messages",
"."
] | python | train | 35.793103 |
googleapis/oauth2client | oauth2client/contrib/keyring_storage.py | https://github.com/googleapis/oauth2client/blob/50d20532a748f18e53f7d24ccbe6647132c979a9/oauth2client/contrib/keyring_storage.py#L62-L78 | def locked_get(self):
"""Retrieve Credential from file.
Returns:
oauth2client.client.Credentials
"""
credentials = None
content = keyring.get_password(self._service_name, self._user_name)
if content is not None:
try:
credentials =... | [
"def",
"locked_get",
"(",
"self",
")",
":",
"credentials",
"=",
"None",
"content",
"=",
"keyring",
".",
"get_password",
"(",
"self",
".",
"_service_name",
",",
"self",
".",
"_user_name",
")",
"if",
"content",
"is",
"not",
"None",
":",
"try",
":",
"creden... | Retrieve Credential from file.
Returns:
oauth2client.client.Credentials | [
"Retrieve",
"Credential",
"from",
"file",
"."
] | python | valid | 27.647059 |
iotile/coretools | iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Tool/m4.py | https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Tool/m4.py#L40-L54 | def generate(env):
"""Add Builders and construction variables for m4 to an Environment."""
M4Action = SCons.Action.Action('$M4COM', '$M4COMSTR')
bld = SCons.Builder.Builder(action = M4Action, src_suffix = '.m4')
env['BUILDERS']['M4'] = bld
# .m4 files might include other files, and it would be pre... | [
"def",
"generate",
"(",
"env",
")",
":",
"M4Action",
"=",
"SCons",
".",
"Action",
".",
"Action",
"(",
"'$M4COM'",
",",
"'$M4COMSTR'",
")",
"bld",
"=",
"SCons",
".",
"Builder",
".",
"Builder",
"(",
"action",
"=",
"M4Action",
",",
"src_suffix",
"=",
"'.m... | Add Builders and construction variables for m4 to an Environment. | [
"Add",
"Builders",
"and",
"construction",
"variables",
"for",
"m4",
"to",
"an",
"Environment",
"."
] | python | train | 45.2 |
vertexproject/synapse | synapse/lib/module.py | https://github.com/vertexproject/synapse/blob/22e67c5a8f6d7caddbcf34b39ab1bd2d6c4a6e0b/synapse/lib/module.py#L93-L107 | def getModPath(self, *paths):
'''
Construct a path relative to this module's working directory.
Args:
*paths: A list of path strings
Notes:
This creates the module specific directory if it does not exist.
Returns:
(str): The full path (or No... | [
"def",
"getModPath",
"(",
"self",
",",
"*",
"paths",
")",
":",
"dirn",
"=",
"self",
".",
"getModDir",
"(",
")",
"return",
"s_common",
".",
"genpath",
"(",
"dirn",
",",
"*",
"paths",
")"
] | Construct a path relative to this module's working directory.
Args:
*paths: A list of path strings
Notes:
This creates the module specific directory if it does not exist.
Returns:
(str): The full path (or None if no cortex dir is configured). | [
"Construct",
"a",
"path",
"relative",
"to",
"this",
"module",
"s",
"working",
"directory",
"."
] | python | train | 28.733333 |
ARMmbed/mbed-cloud-sdk-python | src/mbed_cloud/_backends/enrollment/models/enrollment_id.py | https://github.com/ARMmbed/mbed-cloud-sdk-python/blob/c0af86fb2cdd4dc7ed26f236139241067d293509/src/mbed_cloud/_backends/enrollment/models/enrollment_id.py#L61-L74 | def enrollment_identity(self, enrollment_identity):
"""
Sets the enrollment_identity of this EnrollmentId.
Enrollment identity.
:param enrollment_identity: The enrollment_identity of this EnrollmentId.
:type: str
"""
if enrollment_identity is None:
ra... | [
"def",
"enrollment_identity",
"(",
"self",
",",
"enrollment_identity",
")",
":",
"if",
"enrollment_identity",
"is",
"None",
":",
"raise",
"ValueError",
"(",
"\"Invalid value for `enrollment_identity`, must not be `None`\"",
")",
"if",
"enrollment_identity",
"is",
"not",
"... | Sets the enrollment_identity of this EnrollmentId.
Enrollment identity.
:param enrollment_identity: The enrollment_identity of this EnrollmentId.
:type: str | [
"Sets",
"the",
"enrollment_identity",
"of",
"this",
"EnrollmentId",
".",
"Enrollment",
"identity",
"."
] | python | train | 48.785714 |
mahmoudimus/nose-timer | nosetimer/plugin.py | https://github.com/mahmoudimus/nose-timer/blob/3d8ff21ce3a68efd6cd018ea67c32f1da27ea3f9/nosetimer/plugin.py#L236-L241 | def _colored_time(self, time_taken, color=None):
"""Get formatted and colored string for a given time taken."""
if self.timer_no_color:
return "{0:0.4f}s".format(time_taken)
return _colorize("{0:0.4f}s".format(time_taken), color) | [
"def",
"_colored_time",
"(",
"self",
",",
"time_taken",
",",
"color",
"=",
"None",
")",
":",
"if",
"self",
".",
"timer_no_color",
":",
"return",
"\"{0:0.4f}s\"",
".",
"format",
"(",
"time_taken",
")",
"return",
"_colorize",
"(",
"\"{0:0.4f}s\"",
".",
"format... | Get formatted and colored string for a given time taken. | [
"Get",
"formatted",
"and",
"colored",
"string",
"for",
"a",
"given",
"time",
"taken",
"."
] | python | train | 43.5 |
chartbeat-labs/swailing | swailing/logger.py | https://github.com/chartbeat-labs/swailing/blob/d55e0dd7af59a2ba93f7c9c46ff56f6a4080b222/swailing/logger.py#L103-L106 | def log(self, level, msg=None, *args, **kwargs):
"""Writes log out at any arbitray level."""
return self._log(level, msg, args, kwargs) | [
"def",
"log",
"(",
"self",
",",
"level",
",",
"msg",
"=",
"None",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"self",
".",
"_log",
"(",
"level",
",",
"msg",
",",
"args",
",",
"kwargs",
")"
] | Writes log out at any arbitray level. | [
"Writes",
"log",
"out",
"at",
"any",
"arbitray",
"level",
"."
] | python | train | 37.25 |
ewels/MultiQC | multiqc/modules/deeptools/estimateReadFiltering.py | https://github.com/ewels/MultiQC/blob/2037d6322b2554146a74efbf869156ad20d4c4ec/multiqc/modules/deeptools/estimateReadFiltering.py#L16-L129 | def parse_estimateReadFiltering(self):
"""Find estimateReadFiltering output. Only the output from --table is supported."""
self.deeptools_estimateReadFiltering = dict()
for f in self.find_log_files('deeptools/estimateReadFiltering'):
parsed_data = self.parseEstimateReadFilteringFile(... | [
"def",
"parse_estimateReadFiltering",
"(",
"self",
")",
":",
"self",
".",
"deeptools_estimateReadFiltering",
"=",
"dict",
"(",
")",
"for",
"f",
"in",
"self",
".",
"find_log_files",
"(",
"'deeptools/estimateReadFiltering'",
")",
":",
"parsed_data",
"=",
"self",
"."... | Find estimateReadFiltering output. Only the output from --table is supported. | [
"Find",
"estimateReadFiltering",
"output",
".",
"Only",
"the",
"output",
"from",
"--",
"table",
"is",
"supported",
"."
] | python | train | 45.219298 |
petl-developers/petlx | petlx/bio/tabix.py | https://github.com/petl-developers/petlx/blob/54039e30388c7da12407d6b5c3cb865b00436004/petlx/bio/tabix.py#L10-L47 | def fromtabix(filename, reference=None, start=None, stop=None, region=None,
header=None):
"""
Extract rows from a tabix indexed file, e.g.::
>>> import petl as etl
>>> # activate bio extensions
... import petlx.bio
>>> table1 = etl.fromtabix('fixture/test.bed.gz',
... | [
"def",
"fromtabix",
"(",
"filename",
",",
"reference",
"=",
"None",
",",
"start",
"=",
"None",
",",
"stop",
"=",
"None",
",",
"region",
"=",
"None",
",",
"header",
"=",
"None",
")",
":",
"return",
"TabixView",
"(",
"filename",
",",
"reference",
",",
... | Extract rows from a tabix indexed file, e.g.::
>>> import petl as etl
>>> # activate bio extensions
... import petlx.bio
>>> table1 = etl.fromtabix('fixture/test.bed.gz',
... region='Pf3D7_02_v3')
>>> table1
+---------------+----------+----... | [
"Extract",
"rows",
"from",
"a",
"tabix",
"indexed",
"file",
"e",
".",
"g",
".",
"::"
] | python | train | 50.078947 |
spyder-ide/spyder | spyder/plugins/projects/plugin.py | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/projects/plugin.py#L478-L484 | def is_valid_project(self, path):
"""Check if a directory is a valid Spyder project"""
spy_project_dir = osp.join(path, '.spyproject')
if osp.isdir(path) and osp.isdir(spy_project_dir):
return True
else:
return False | [
"def",
"is_valid_project",
"(",
"self",
",",
"path",
")",
":",
"spy_project_dir",
"=",
"osp",
".",
"join",
"(",
"path",
",",
"'.spyproject'",
")",
"if",
"osp",
".",
"isdir",
"(",
"path",
")",
"and",
"osp",
".",
"isdir",
"(",
"spy_project_dir",
")",
":"... | Check if a directory is a valid Spyder project | [
"Check",
"if",
"a",
"directory",
"is",
"a",
"valid",
"Spyder",
"project"
] | python | train | 38.857143 |
elastic/elasticsearch-py | elasticsearch/client/xpack/data_frame.py | https://github.com/elastic/elasticsearch-py/blob/2aab285c8f506f3863cbdaba3c90a685c510ba00/elasticsearch/client/xpack/data_frame.py#L100-L118 | def stop_data_frame_transform(self, transform_id, params=None):
"""
`<https://www.elastic.co/guide/en/elasticsearch/reference/current/stop-data-frame-transform.html>`_
:arg transform_id: The id of the transform to stop
:arg timeout: Controls the time to wait until the transform has stop... | [
"def",
"stop_data_frame_transform",
"(",
"self",
",",
"transform_id",
",",
"params",
"=",
"None",
")",
":",
"if",
"transform_id",
"in",
"SKIP_IN_PATH",
":",
"raise",
"ValueError",
"(",
"\"Empty value passed for a required argument 'transform_id'.\"",
")",
"return",
"sel... | `<https://www.elastic.co/guide/en/elasticsearch/reference/current/stop-data-frame-transform.html>`_
:arg transform_id: The id of the transform to stop
:arg timeout: Controls the time to wait until the transform has stopped.
Default to 30 seconds
:arg wait_for_completion: Whether to ... | [
"<https",
":",
"//",
"www",
".",
"elastic",
".",
"co",
"/",
"guide",
"/",
"en",
"/",
"elasticsearch",
"/",
"reference",
"/",
"current",
"/",
"stop",
"-",
"data",
"-",
"frame",
"-",
"transform",
".",
"html",
">",
"_"
] | python | train | 43.684211 |
signalfx/signalfx-python | signalfx/rest.py | https://github.com/signalfx/signalfx-python/blob/650eb9a2b301bcc795e4e3a8c031574ade69849d/signalfx/rest.py#L326-L336 | def delete_tag(self, tag_name, **kwargs):
"""delete a tag by name
Args:
tag_name (string): name of tag to delete
"""
resp = self._delete(self._u(self._TAG_ENDPOINT_SUFFIX, tag_name),
**kwargs)
resp.raise_for_status()
# successful d... | [
"def",
"delete_tag",
"(",
"self",
",",
"tag_name",
",",
"*",
"*",
"kwargs",
")",
":",
"resp",
"=",
"self",
".",
"_delete",
"(",
"self",
".",
"_u",
"(",
"self",
".",
"_TAG_ENDPOINT_SUFFIX",
",",
"tag_name",
")",
",",
"*",
"*",
"kwargs",
")",
"resp",
... | delete a tag by name
Args:
tag_name (string): name of tag to delete | [
"delete",
"a",
"tag",
"by",
"name"
] | python | train | 34.272727 |
BerkeleyAutomation/perception | perception/detector.py | https://github.com/BerkeleyAutomation/perception/blob/03d9b37dd6b66896cdfe173905c9413c8c3c5df6/perception/detector.py#L225-L298 | def _segment_color(self, color_im, bounding_box, bgmodel, cfg, vis_segmentation=False):
""" Re-segments a color image to isolate an object of interest using foreground masking and kmeans """
# read params
foreground_mask_tolerance = cfg['foreground_mask_tolerance']
color_seg_rgb_weight =... | [
"def",
"_segment_color",
"(",
"self",
",",
"color_im",
",",
"bounding_box",
",",
"bgmodel",
",",
"cfg",
",",
"vis_segmentation",
"=",
"False",
")",
":",
"# read params",
"foreground_mask_tolerance",
"=",
"cfg",
"[",
"'foreground_mask_tolerance'",
"]",
"color_seg_rgb... | Re-segments a color image to isolate an object of interest using foreground masking and kmeans | [
"Re",
"-",
"segments",
"a",
"color",
"image",
"to",
"isolate",
"an",
"object",
"of",
"interest",
"using",
"foreground",
"masking",
"and",
"kmeans"
] | python | train | 50.351351 |
berkeley-cocosci/Wallace | wallace/custom.py | https://github.com/berkeley-cocosci/Wallace/blob/3650c0bc3b0804d0adb1d178c5eba9992babb1b0/wallace/custom.py#L228-L236 | def quitter():
"""Overide the psiTurk quitter route."""
exp = experiment(session)
exp.log("Quitter route was hit.")
return Response(
dumps({"status": "success"}),
status=200,
mimetype='application/json') | [
"def",
"quitter",
"(",
")",
":",
"exp",
"=",
"experiment",
"(",
"session",
")",
"exp",
".",
"log",
"(",
"\"Quitter route was hit.\"",
")",
"return",
"Response",
"(",
"dumps",
"(",
"{",
"\"status\"",
":",
"\"success\"",
"}",
")",
",",
"status",
"=",
"200"... | Overide the psiTurk quitter route. | [
"Overide",
"the",
"psiTurk",
"quitter",
"route",
"."
] | python | train | 26.222222 |
openknowledge-archive/datapackage-registry-py | datapackage_registry/registry.py | https://github.com/openknowledge-archive/datapackage-registry-py/blob/02ba4d1ae6a75d8960abef0ffec3e9ec49ed26f9/datapackage_registry/registry.py#L112-L131 | def _load_json_file_or_url(self, json_path_or_url):
'''Return the JSON at the local path or URL as a dict
This method raises DataPackageRegistryException if there were any
errors.
'''
try:
if os.path.isfile(json_path_or_url):
with open(json_path_or_ur... | [
"def",
"_load_json_file_or_url",
"(",
"self",
",",
"json_path_or_url",
")",
":",
"try",
":",
"if",
"os",
".",
"path",
".",
"isfile",
"(",
"json_path_or_url",
")",
":",
"with",
"open",
"(",
"json_path_or_url",
",",
"'r'",
")",
"as",
"f",
":",
"result",
"=... | Return the JSON at the local path or URL as a dict
This method raises DataPackageRegistryException if there were any
errors. | [
"Return",
"the",
"JSON",
"at",
"the",
"local",
"path",
"or",
"URL",
"as",
"a",
"dict"
] | python | train | 34.05 |
nerdvegas/rez | src/rez/vendor/pygraph/mixins/labeling.py | https://github.com/nerdvegas/rez/blob/1d3b846d53b5b5404edfe8ddb9083f9ceec8c5e7/src/rez/vendor/pygraph/mixins/labeling.py#L79-L91 | def set_edge_weight(self, edge, wt):
"""
Set the weight of an edge.
@type edge: edge
@param edge: One edge.
@type wt: number
@param wt: Edge weight.
"""
self.set_edge_properties(edge, weight=wt )
if not self.DIRECTED:
self.set_edge_... | [
"def",
"set_edge_weight",
"(",
"self",
",",
"edge",
",",
"wt",
")",
":",
"self",
".",
"set_edge_properties",
"(",
"edge",
",",
"weight",
"=",
"wt",
")",
"if",
"not",
"self",
".",
"DIRECTED",
":",
"self",
".",
"set_edge_properties",
"(",
"(",
"edge",
"[... | Set the weight of an edge.
@type edge: edge
@param edge: One edge.
@type wt: number
@param wt: Edge weight. | [
"Set",
"the",
"weight",
"of",
"an",
"edge",
"."
] | python | train | 27 |
acutesoftware/AIKIF | aikif/programs.py | https://github.com/acutesoftware/AIKIF/blob/fcf1582dc5f884b9a4fa7c6e20e9de9d94d21d03/aikif/programs.py#L127-L137 | def get_file_info_web(self, fname, delim='<BR>\n'):
"""
gathers info on a python program in list and formats as string
"""
txt = ''
f = mod_file.File(fname[0])
txt += '<sup>' + f.name + '</sup>' + delim
txt += '<sup>' + fname[1] + '</sup>' + delim
txt +=... | [
"def",
"get_file_info_web",
"(",
"self",
",",
"fname",
",",
"delim",
"=",
"'<BR>\\n'",
")",
":",
"txt",
"=",
"''",
"f",
"=",
"mod_file",
".",
"File",
"(",
"fname",
"[",
"0",
"]",
")",
"txt",
"+=",
"'<sup>'",
"+",
"f",
".",
"name",
"+",
"'</sup>'",
... | gathers info on a python program in list and formats as string | [
"gathers",
"info",
"on",
"a",
"python",
"program",
"in",
"list",
"and",
"formats",
"as",
"string"
] | python | train | 47.090909 |
tducret/precisionmapper-python | python-flask/swagger_server/models/base_model_.py | https://github.com/tducret/precisionmapper-python/blob/462dcc5bccf6edec780b8b7bc42e8c1d717db942/python-flask/swagger_server/models/base_model_.py#L21-L23 | def from_dict(cls: typing.Type[T], dikt) -> T:
"""Returns the dict as a model"""
return util.deserialize_model(dikt, cls) | [
"def",
"from_dict",
"(",
"cls",
":",
"typing",
".",
"Type",
"[",
"T",
"]",
",",
"dikt",
")",
"->",
"T",
":",
"return",
"util",
".",
"deserialize_model",
"(",
"dikt",
",",
"cls",
")"
] | Returns the dict as a model | [
"Returns",
"the",
"dict",
"as",
"a",
"model"
] | python | train | 45 |
gwpy/gwpy | gwpy/plot/gps.py | https://github.com/gwpy/gwpy/blob/7a92b917e7dd2d99b15895293a1fa1d66cdb210a/gwpy/plot/gps.py#L118-L147 | def set_unit(self, unit):
"""Set the GPS step scale
"""
# accept all core time units
if unit is None or (isinstance(unit, units.NamedUnit) and
unit.physical_type == 'time'):
self._unit = unit
return
# convert float to custom uni... | [
"def",
"set_unit",
"(",
"self",
",",
"unit",
")",
":",
"# accept all core time units",
"if",
"unit",
"is",
"None",
"or",
"(",
"isinstance",
"(",
"unit",
",",
"units",
".",
"NamedUnit",
")",
"and",
"unit",
".",
"physical_type",
"==",
"'time'",
")",
":",
"... | Set the GPS step scale | [
"Set",
"the",
"GPS",
"step",
"scale"
] | python | train | 37.833333 |
ricequant/rqalpha | rqalpha/model/instrument.py | https://github.com/ricequant/rqalpha/blob/ac40a62d4e7eca9494b4d0a14f46facf5616820c/rqalpha/model/instrument.py#L140-L149 | def industry_code(self):
"""
[str] 国民经济行业分类代码,具体可参考“Industry列表” (股票专用)
"""
try:
return self.__dict__["industry_code"]
except (KeyError, ValueError):
raise AttributeError(
"Instrument(order_book_id={}) has no attribute 'industry_code' ".form... | [
"def",
"industry_code",
"(",
"self",
")",
":",
"try",
":",
"return",
"self",
".",
"__dict__",
"[",
"\"industry_code\"",
"]",
"except",
"(",
"KeyError",
",",
"ValueError",
")",
":",
"raise",
"AttributeError",
"(",
"\"Instrument(order_book_id={}) has no attribute 'ind... | [str] 国民经济行业分类代码,具体可参考“Industry列表” (股票专用) | [
"[",
"str",
"]",
"国民经济行业分类代码,具体可参考“Industry列表”",
"(股票专用)"
] | python | train | 34.7 |
mikedh/trimesh | trimesh/scene/scene.py | https://github.com/mikedh/trimesh/blob/25e059bf6d4caa74f62ffd58ce4f61a90ee4e518/trimesh/scene/scene.py#L411-L463 | def set_camera(self,
angles=None,
distance=None,
center=None,
resolution=None,
fov=None):
"""
Create a camera object for self.camera, and add
a transform to self.graph for it.
If arguments are... | [
"def",
"set_camera",
"(",
"self",
",",
"angles",
"=",
"None",
",",
"distance",
"=",
"None",
",",
"center",
"=",
"None",
",",
"resolution",
"=",
"None",
",",
"fov",
"=",
"None",
")",
":",
"if",
"fov",
"is",
"None",
":",
"fov",
"=",
"np",
".",
"arr... | Create a camera object for self.camera, and add
a transform to self.graph for it.
If arguments are not passed sane defaults will be figured
out which show the mesh roughly centered.
Parameters
-----------
angles : (3,) float
Initial euler angles in radians
... | [
"Create",
"a",
"camera",
"object",
"for",
"self",
".",
"camera",
"and",
"add",
"a",
"transform",
"to",
"self",
".",
"graph",
"for",
"it",
"."
] | python | train | 32.301887 |
jmwri/simplejwt | simplejwt/jwt.py | https://github.com/jmwri/simplejwt/blob/0828eaace0846918d2d202f5a60167a003e88b71/simplejwt/jwt.py#L30-L40 | def get_algorithm(alg: str) -> Callable:
"""
:param alg: The name of the requested `JSON Web Algorithm <https://tools.ietf.org/html/rfc7519#ref-JWA>`_. `RFC7518 <https://tools.ietf.org/html/rfc7518#section-3.2>`_ is related.
:type alg: str
:return: The requested algorithm.
:rtype: Callable
:rais... | [
"def",
"get_algorithm",
"(",
"alg",
":",
"str",
")",
"->",
"Callable",
":",
"if",
"alg",
"not",
"in",
"algorithms",
":",
"raise",
"ValueError",
"(",
"'Invalid algorithm: {:s}'",
".",
"format",
"(",
"alg",
")",
")",
"return",
"algorithms",
"[",
"alg",
"]"
] | :param alg: The name of the requested `JSON Web Algorithm <https://tools.ietf.org/html/rfc7519#ref-JWA>`_. `RFC7518 <https://tools.ietf.org/html/rfc7518#section-3.2>`_ is related.
:type alg: str
:return: The requested algorithm.
:rtype: Callable
:raises: ValueError | [
":",
"param",
"alg",
":",
"The",
"name",
"of",
"the",
"requested",
"JSON",
"Web",
"Algorithm",
"<https",
":",
"//",
"tools",
".",
"ietf",
".",
"org",
"/",
"html",
"/",
"rfc7519#ref",
"-",
"JWA",
">",
"_",
".",
"RFC7518",
"<https",
":",
"//",
"tools",... | python | valid | 41.181818 |
limix/glimix-core | glimix_core/lmm/_lmm.py | https://github.com/limix/glimix-core/blob/cddd0994591d100499cc41c1f480ddd575e7a980/glimix_core/lmm/_lmm.py#L209-L234 | def beta_covariance(self):
"""
Estimates the covariance-matrix of the optimal beta.
Returns
-------
beta-covariance : ndarray
(Xᵀ(s((1-𝛿)K + 𝛿I))⁻¹X)⁻¹.
References
----------
.. Rencher, A. C., & Schaalje, G. B. (2008). Linear models in sta... | [
"def",
"beta_covariance",
"(",
"self",
")",
":",
"from",
"numpy_sugar",
".",
"linalg",
"import",
"ddot",
"tX",
"=",
"self",
".",
"_X",
"[",
"\"tX\"",
"]",
"Q",
"=",
"concatenate",
"(",
"self",
".",
"_QS",
"[",
"0",
"]",
",",
"axis",
"=",
"1",
")",
... | Estimates the covariance-matrix of the optimal beta.
Returns
-------
beta-covariance : ndarray
(Xᵀ(s((1-𝛿)K + 𝛿I))⁻¹X)⁻¹.
References
----------
.. Rencher, A. C., & Schaalje, G. B. (2008). Linear models in statistics. John
Wiley & Sons. | [
"Estimates",
"the",
"covariance",
"-",
"matrix",
"of",
"the",
"optimal",
"beta",
"."
] | python | valid | 29.538462 |
rhayes777/PyAutoFit | autofit/mapper/model_mapper.py | https://github.com/rhayes777/PyAutoFit/blob/a9e6144abb08edfc6a6906c4030d7119bf8d3e14/autofit/mapper/model_mapper.py#L193-L202 | def prior_prior_model_dict(self):
"""
Returns
-------
prior_prior_model_dict: {Prior: PriorModel}
A dictionary mapping priors to associated prior models. Each prior will only have one prior model; if a
prior is shared by two prior models then one of those prior mo... | [
"def",
"prior_prior_model_dict",
"(",
"self",
")",
":",
"return",
"{",
"prior",
":",
"prior_model",
"[",
"1",
"]",
"for",
"prior_model",
"in",
"self",
".",
"prior_model_tuples",
"for",
"_",
",",
"prior",
"in",
"prior_model",
"[",
"1",
"]",
".",
"prior_tupl... | Returns
-------
prior_prior_model_dict: {Prior: PriorModel}
A dictionary mapping priors to associated prior models. Each prior will only have one prior model; if a
prior is shared by two prior models then one of those prior models will be in this dictionary. | [
"Returns",
"-------",
"prior_prior_model_dict",
":",
"{",
"Prior",
":",
"PriorModel",
"}",
"A",
"dictionary",
"mapping",
"priors",
"to",
"associated",
"prior",
"models",
".",
"Each",
"prior",
"will",
"only",
"have",
"one",
"prior",
"model",
";",
"if",
"a",
"... | python | train | 49.7 |
materialsproject/pymatgen | pymatgen/analysis/eos.py | https://github.com/materialsproject/pymatgen/blob/4ca558cf72f8d5f8a1f21dfdfc0181a971c186da/pymatgen/analysis/eos.py#L52-L73 | def _initial_guess(self):
"""
Quadratic fit to get an initial guess for the parameters.
Returns:
tuple: (e0, b0, b1, v0)
"""
a, b, c = np.polyfit(self.volumes, self.energies, 2)
self.eos_params = [a, b, c]
v0 = -b/(2*a)
e0 = a*(v0**2) + b*v0 ... | [
"def",
"_initial_guess",
"(",
"self",
")",
":",
"a",
",",
"b",
",",
"c",
"=",
"np",
".",
"polyfit",
"(",
"self",
".",
"volumes",
",",
"self",
".",
"energies",
",",
"2",
")",
"self",
".",
"eos_params",
"=",
"[",
"a",
",",
"b",
",",
"c",
"]",
"... | Quadratic fit to get an initial guess for the parameters.
Returns:
tuple: (e0, b0, b1, v0) | [
"Quadratic",
"fit",
"to",
"get",
"an",
"initial",
"guess",
"for",
"the",
"parameters",
"."
] | python | train | 29.181818 |
nathan-hoad/aiomanhole | aiomanhole/__init__.py | https://github.com/nathan-hoad/aiomanhole/blob/a13394c79e1878cde67aa2637ae5664df468ed04/aiomanhole/__init__.py#L88-L96 | def handle_one_command(self):
"""Process a single command. May have many lines."""
while True:
yield from self.write_prompt()
codeobj = yield from self.read_command()
if codeobj is not None:
yield from self.run_command(codeobj) | [
"def",
"handle_one_command",
"(",
"self",
")",
":",
"while",
"True",
":",
"yield",
"from",
"self",
".",
"write_prompt",
"(",
")",
"codeobj",
"=",
"yield",
"from",
"self",
".",
"read_command",
"(",
")",
"if",
"codeobj",
"is",
"not",
"None",
":",
"yield",
... | Process a single command. May have many lines. | [
"Process",
"a",
"single",
"command",
".",
"May",
"have",
"many",
"lines",
"."
] | python | train | 32.111111 |
konstantint/matplotlib-venn | matplotlib_venn/_venn2.py | https://github.com/konstantint/matplotlib-venn/blob/c26796c9925bdac512edf48387452fbd1848c791/matplotlib_venn/_venn2.py#L183-L258 | def venn2(subsets, set_labels=('A', 'B'), set_colors=('r', 'g'), alpha=0.4, normalize_to=1.0, ax=None, subset_label_formatter=None):
'''Plots a 2-set area-weighted Venn diagram.
The subsets parameter can be one of the following:
- A list (or a tuple) containing two set objects.
- A dict, providing siz... | [
"def",
"venn2",
"(",
"subsets",
",",
"set_labels",
"=",
"(",
"'A'",
",",
"'B'",
")",
",",
"set_colors",
"=",
"(",
"'r'",
",",
"'g'",
")",
",",
"alpha",
"=",
"0.4",
",",
"normalize_to",
"=",
"1.0",
",",
"ax",
"=",
"None",
",",
"subset_label_formatter"... | Plots a 2-set area-weighted Venn diagram.
The subsets parameter can be one of the following:
- A list (or a tuple) containing two set objects.
- A dict, providing sizes of three diagram regions.
The regions are identified via two-letter binary codes ('10', '01', and '11'), hence a valid set could l... | [
"Plots",
"a",
"2",
"-",
"set",
"area",
"-",
"weighted",
"Venn",
"diagram",
".",
"The",
"subsets",
"parameter",
"can",
"be",
"one",
"of",
"the",
"following",
":",
"-",
"A",
"list",
"(",
"or",
"a",
"tuple",
")",
"containing",
"two",
"set",
"objects",
"... | python | train | 50.723684 |
rigetti/pyquil | pyquil/paulis.py | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/paulis.py#L952-L995 | def trotterize(first_pauli_term, second_pauli_term, trotter_order=1,
trotter_steps=1):
"""
Create a Quil program that approximates exp( (A + B)t) where A and B are
PauliTerm operators.
:param PauliTerm first_pauli_term: PauliTerm denoted `A`
:param PauliTerm second_pauli_term: PauliT... | [
"def",
"trotterize",
"(",
"first_pauli_term",
",",
"second_pauli_term",
",",
"trotter_order",
"=",
"1",
",",
"trotter_steps",
"=",
"1",
")",
":",
"if",
"not",
"(",
"1",
"<=",
"trotter_order",
"<",
"5",
")",
":",
"raise",
"ValueError",
"(",
"\"trotterize only... | Create a Quil program that approximates exp( (A + B)t) where A and B are
PauliTerm operators.
:param PauliTerm first_pauli_term: PauliTerm denoted `A`
:param PauliTerm second_pauli_term: PauliTerm denoted `B`
:param int trotter_order: Optional argument indicating the Suzuki-Trotter
... | [
"Create",
"a",
"Quil",
"program",
"that",
"approximates",
"exp",
"(",
"(",
"A",
"+",
"B",
")",
"t",
")",
"where",
"A",
"and",
"B",
"are",
"PauliTerm",
"operators",
"."
] | python | train | 37.454545 |
lrq3000/pyFileFixity | pyFileFixity/lib/profilers/visual/pympler/classtracker_stats.py | https://github.com/lrq3000/pyFileFixity/blob/fd5ef23bb13835faf1e3baa773619b86a1cc9bdf/pyFileFixity/lib/profilers/visual/pympler/classtracker_stats.py#L115-L130 | def dump_stats(self, fdump, close=True):
"""
Dump the logged data to a file.
The argument `file` can be either a filename or an open file object
that requires write access. `close` controls if the file is closed
before leaving this method (the default behaviour).
"""
... | [
"def",
"dump_stats",
"(",
"self",
",",
"fdump",
",",
"close",
"=",
"True",
")",
":",
"if",
"self",
".",
"tracker",
":",
"self",
".",
"tracker",
".",
"stop_periodic_snapshots",
"(",
")",
"if",
"isinstance",
"(",
"fdump",
",",
"type",
"(",
"''",
")",
"... | Dump the logged data to a file.
The argument `file` can be either a filename or an open file object
that requires write access. `close` controls if the file is closed
before leaving this method (the default behaviour). | [
"Dump",
"the",
"logged",
"data",
"to",
"a",
"file",
".",
"The",
"argument",
"file",
"can",
"be",
"either",
"a",
"filename",
"or",
"an",
"open",
"file",
"object",
"that",
"requires",
"write",
"access",
".",
"close",
"controls",
"if",
"the",
"file",
"is",
... | python | train | 40.5625 |
JelleAalbers/multihist | multihist.py | https://github.com/JelleAalbers/multihist/blob/072288277f807e7e388fdf424c3921c80576f3ab/multihist.py#L545-L558 | def average(self, axis):
"""Returns d-1 dimensional histogram of (estimated) mean value of axis
NB this is very different from averaging over the axis!!!
"""
axis = self.get_axis_number(axis)
avg_hist = np.ma.average(self.all_axis_bin_centers(axis),
... | [
"def",
"average",
"(",
"self",
",",
"axis",
")",
":",
"axis",
"=",
"self",
".",
"get_axis_number",
"(",
"axis",
")",
"avg_hist",
"=",
"np",
".",
"ma",
".",
"average",
"(",
"self",
".",
"all_axis_bin_centers",
"(",
"axis",
")",
",",
"weights",
"=",
"s... | Returns d-1 dimensional histogram of (estimated) mean value of axis
NB this is very different from averaging over the axis!!! | [
"Returns",
"d",
"-",
"1",
"dimensional",
"histogram",
"of",
"(",
"estimated",
")",
"mean",
"value",
"of",
"axis",
"NB",
"this",
"is",
"very",
"different",
"from",
"averaging",
"over",
"the",
"axis!!!"
] | python | train | 49.428571 |
dwavesystems/dwave_networkx | dwave_networkx/generators/chimera.py | https://github.com/dwavesystems/dwave_networkx/blob/9ea1223ddbc7e86db2f90b8b23e250e6642c3d68/dwave_networkx/generators/chimera.py#L401-L418 | def ints(self, qlist):
"""
Converts a sequence of chimera_index node labels into
linear_index node labels, preserving order
Parameters
----------
qlist : sequence of ints
The chimera_index node labels
Returns
-------
rlist : iterable ... | [
"def",
"ints",
"(",
"self",
",",
"qlist",
")",
":",
"m",
",",
"n",
",",
"t",
"=",
"self",
".",
"args",
"return",
"(",
"(",
"(",
"n",
"*",
"i",
"+",
"j",
")",
"*",
"2",
"+",
"u",
")",
"*",
"t",
"+",
"k",
"for",
"(",
"i",
",",
"j",
",",... | Converts a sequence of chimera_index node labels into
linear_index node labels, preserving order
Parameters
----------
qlist : sequence of ints
The chimera_index node labels
Returns
-------
rlist : iterable of tuples
The linear_lindex nod... | [
"Converts",
"a",
"sequence",
"of",
"chimera_index",
"node",
"labels",
"into",
"linear_index",
"node",
"labels",
"preserving",
"order"
] | python | train | 26.944444 |
pypa/pipenv | pipenv/vendor/jinja2/lexer.py | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/jinja2/lexer.py#L178-L186 | def describe_token_expr(expr):
"""Like `describe_token` but for token expressions."""
if ':' in expr:
type, value = expr.split(':', 1)
if type == 'name':
return value
else:
type = expr
return _describe_token_type(type) | [
"def",
"describe_token_expr",
"(",
"expr",
")",
":",
"if",
"':'",
"in",
"expr",
":",
"type",
",",
"value",
"=",
"expr",
".",
"split",
"(",
"':'",
",",
"1",
")",
"if",
"type",
"==",
"'name'",
":",
"return",
"value",
"else",
":",
"type",
"=",
"expr",... | Like `describe_token` but for token expressions. | [
"Like",
"describe_token",
"but",
"for",
"token",
"expressions",
"."
] | python | train | 29.111111 |
vtkiorg/vtki | vtki/geometric_objects.py | https://github.com/vtkiorg/vtki/blob/5ccad7ae6d64a03e9594c9c7474c8aab3eb22dd1/vtki/geometric_objects.py#L194-L236 | def Plane(center=(0, 0, 0), direction=(0, 0, 1), i_size=1, j_size=1,
i_resolution=10, j_resolution=10):
"""
Create a plane
Parameters
----------
center : list or np.ndarray
Location of the centroid in [x, y, z]
direction : list or np.ndarray
Direction cylinder points ... | [
"def",
"Plane",
"(",
"center",
"=",
"(",
"0",
",",
"0",
",",
"0",
")",
",",
"direction",
"=",
"(",
"0",
",",
"0",
",",
"1",
")",
",",
"i_size",
"=",
"1",
",",
"j_size",
"=",
"1",
",",
"i_resolution",
"=",
"10",
",",
"j_resolution",
"=",
"10",... | Create a plane
Parameters
----------
center : list or np.ndarray
Location of the centroid in [x, y, z]
direction : list or np.ndarray
Direction cylinder points to in [x, y, z]
i_size : float
Size of the plane in the i direction.
j_size : float
Size of the pla... | [
"Create",
"a",
"plane"
] | python | train | 23.534884 |
idank/bashlex | bashlex/parser.py | https://github.com/idank/bashlex/blob/800cb7e3c634eaa3c81f8a8648fd7fd4e27050ac/bashlex/parser.py#L15-L28 | def p_inputunit(p):
'''inputunit : simple_list simple_list_terminator
| NEWLINE
| error NEWLINE
| EOF'''
# XXX
if p.lexer._parserstate & flags.parser.CMDSUBST:
p.lexer._parserstate.add(flags.parser.EOFTOKEN)
if isinstance(p[1], ast.node):
... | [
"def",
"p_inputunit",
"(",
"p",
")",
":",
"# XXX",
"if",
"p",
".",
"lexer",
".",
"_parserstate",
"&",
"flags",
".",
"parser",
".",
"CMDSUBST",
":",
"p",
".",
"lexer",
".",
"_parserstate",
".",
"add",
"(",
"flags",
".",
"parser",
".",
"EOFTOKEN",
")",... | inputunit : simple_list simple_list_terminator
| NEWLINE
| error NEWLINE
| EOF | [
"inputunit",
":",
"simple_list",
"simple_list_terminator",
"|",
"NEWLINE",
"|",
"error",
"NEWLINE",
"|",
"EOF"
] | python | train | 32.642857 |
numenta/nupic | src/nupic/algorithms/fdrutilities.py | https://github.com/numenta/nupic/blob/5922fafffdccc8812e72b3324965ad2f7d4bbdad/src/nupic/algorithms/fdrutilities.py#L65-L94 | def generateCoincMatrix(nCoinc=10, length=500, activity=50):
"""
Generate a coincidence matrix. This is used to generate random inputs to the
temporal learner and to compare the predicted output against.
It generates a matrix of nCoinc rows, each row has length 'length' and has
a total of 'activity' bits on.... | [
"def",
"generateCoincMatrix",
"(",
"nCoinc",
"=",
"10",
",",
"length",
"=",
"500",
",",
"activity",
"=",
"50",
")",
":",
"coincMatrix0",
"=",
"SM32",
"(",
"int",
"(",
"nCoinc",
")",
",",
"int",
"(",
"length",
")",
")",
"theOnes",
"=",
"numpy",
".",
... | Generate a coincidence matrix. This is used to generate random inputs to the
temporal learner and to compare the predicted output against.
It generates a matrix of nCoinc rows, each row has length 'length' and has
a total of 'activity' bits on.
Parameters:
-----------------------------------------------
n... | [
"Generate",
"a",
"coincidence",
"matrix",
".",
"This",
"is",
"used",
"to",
"generate",
"random",
"inputs",
"to",
"the",
"temporal",
"learner",
"and",
"to",
"compare",
"the",
"predicted",
"output",
"against",
"."
] | python | valid | 35.2 |
google/prettytensor | prettytensor/pretty_tensor_image_methods.py | https://github.com/google/prettytensor/blob/75daa0b11252590f548da5647addc0ea610c4c45/prettytensor/pretty_tensor_image_methods.py#L75-L103 | def max_pool(input_layer, kernel, stride, edges=PAD_SAME, name=PROVIDED):
"""Performs max pooling.
`kernel` is the patch that will be pooled and it describes the pooling along
each of the 4 dimensions. `stride` is how big to take each step.
Because more often than not, pooling is only done
on the width and... | [
"def",
"max_pool",
"(",
"input_layer",
",",
"kernel",
",",
"stride",
",",
"edges",
"=",
"PAD_SAME",
",",
"name",
"=",
"PROVIDED",
")",
":",
"return",
"_pool",
"(",
"input_layer",
",",
"tf",
".",
"nn",
".",
"max_pool",
",",
"kernel",
",",
"stride",
",",... | Performs max pooling.
`kernel` is the patch that will be pooled and it describes the pooling along
each of the 4 dimensions. `stride` is how big to take each step.
Because more often than not, pooling is only done
on the width and height of the image, the following shorthands are supported:
* scalar (e.g.... | [
"Performs",
"max",
"pooling",
"."
] | python | train | 43.965517 |
cloud9ers/gurumate | environment/lib/python2.7/site-packages/IPython/frontend/qt/console/completion_lexer.py | https://github.com/cloud9ers/gurumate/blob/075dc74d1ee62a8c6b7a8bf2b271364f01629d1e/environment/lib/python2.7/site-packages/IPython/frontend/qt/console/completion_lexer.py#L20-L61 | def get_context(self, string):
""" Assuming the cursor is at the end of the specified string, get the
context (a list of names) for the symbol at cursor position.
"""
context = []
reversed_tokens = list(self._lexer.get_tokens(string))
reversed_tokens.reverse()
... | [
"def",
"get_context",
"(",
"self",
",",
"string",
")",
":",
"context",
"=",
"[",
"]",
"reversed_tokens",
"=",
"list",
"(",
"self",
".",
"_lexer",
".",
"get_tokens",
"(",
"string",
")",
")",
"reversed_tokens",
".",
"reverse",
"(",
")",
"# Pygments often tac... | Assuming the cursor is at the end of the specified string, get the
context (a list of names) for the symbol at cursor position. | [
"Assuming",
"the",
"cursor",
"is",
"at",
"the",
"end",
"of",
"the",
"specified",
"string",
"get",
"the",
"context",
"(",
"a",
"list",
"of",
"names",
")",
"for",
"the",
"symbol",
"at",
"cursor",
"position",
"."
] | python | test | 35.97619 |
vecnet/vecnet.openmalaria | vecnet/openmalaria/scenario/interventions.py | https://github.com/vecnet/vecnet.openmalaria/blob/795bc9d1b81a6c664f14879edda7a7c41188e95a/vecnet/openmalaria/scenario/interventions.py#L989-L1000 | def anopheles(self):
"""
:rtype: Anopheles
"""
list_of_anopheles = []
desc = self.et.find("description")
if desc is not None:
for anopheles in desc.findall("anopheles"):
list_of_anopheles.append(Anopheles(anopheles))
return list_of_an... | [
"def",
"anopheles",
"(",
"self",
")",
":",
"list_of_anopheles",
"=",
"[",
"]",
"desc",
"=",
"self",
".",
"et",
".",
"find",
"(",
"\"description\"",
")",
"if",
"desc",
"is",
"not",
"None",
":",
"for",
"anopheles",
"in",
"desc",
".",
"findall",
"(",
"\... | :rtype: Anopheles | [
":",
"rtype",
":",
"Anopheles"
] | python | train | 26.333333 |
frnmst/md-toc | md_toc/cli.py | https://github.com/frnmst/md-toc/blob/86d2002ecf52fa9e1e5316a31f7eb7d549cb0830/md_toc/cli.py#L85-L229 | def create_parser(self):
"""Create the CLI parser."""
parser = argparse.ArgumentParser(
description=PROGRAM_DESCRIPTION,
formatter_class=argparse.RawDescriptionHelpFormatter,
epilog=textwrap.dedent(PROGRAM_EPILOG))
parser.add_argument(
'filename',... | [
"def",
"create_parser",
"(",
"self",
")",
":",
"parser",
"=",
"argparse",
".",
"ArgumentParser",
"(",
"description",
"=",
"PROGRAM_DESCRIPTION",
",",
"formatter_class",
"=",
"argparse",
".",
"RawDescriptionHelpFormatter",
",",
"epilog",
"=",
"textwrap",
".",
"dede... | Create the CLI parser. | [
"Create",
"the",
"CLI",
"parser",
"."
] | python | train | 40.606897 |
planetlabs/planet-client-python | planet/scripts/cli.py | https://github.com/planetlabs/planet-client-python/blob/1c62ce7d416819951dddee0c22068fef6d40b027/planet/scripts/cli.py#L66-L75 | def cli(context, verbose, api_key, base_url, workers):
'''Planet API Client'''
configure_logging(verbose)
client_params.clear()
client_params['api_key'] = api_key
client_params['workers'] = workers
if base_url:
client_params['base_url'] = base_url | [
"def",
"cli",
"(",
"context",
",",
"verbose",
",",
"api_key",
",",
"base_url",
",",
"workers",
")",
":",
"configure_logging",
"(",
"verbose",
")",
"client_params",
".",
"clear",
"(",
")",
"client_params",
"[",
"'api_key'",
"]",
"=",
"api_key",
"client_params... | Planet API Client | [
"Planet",
"API",
"Client"
] | python | train | 27.2 |
google/apitools | apitools/base/py/base_api.py | https://github.com/google/apitools/blob/f3745a7ea535aa0e88b0650c16479b696d6fd446/apitools/base/py/base_api.py#L658-L687 | def PrepareHttpRequest(self, method_config, request, global_params=None,
upload=None, upload_config=None, download=None):
"""Prepares an HTTP request to be sent."""
request_type = _LoadClass(
method_config.request_type_name, self.__client.MESSAGES_MODULE)
u... | [
"def",
"PrepareHttpRequest",
"(",
"self",
",",
"method_config",
",",
"request",
",",
"global_params",
"=",
"None",
",",
"upload",
"=",
"None",
",",
"upload_config",
"=",
"None",
",",
"download",
"=",
"None",
")",
":",
"request_type",
"=",
"_LoadClass",
"(",
... | Prepares an HTTP request to be sent. | [
"Prepares",
"an",
"HTTP",
"request",
"to",
"be",
"sent",
"."
] | python | train | 48.766667 |
tnkteja/myhelp | virtualEnvironment/lib/python2.7/site-packages/twine/utils.py | https://github.com/tnkteja/myhelp/blob/fb3a4809d448ad14d5b2e6ddf2e7e89ad52b71cb/virtualEnvironment/lib/python2.7/site-packages/twine/utils.py#L89-L114 | def get_userpass_value(cli_value, config, key, prompt_strategy):
"""Gets the username / password from config.
Uses the following rules:
1. If it is specified on the cli (`cli_value`), use that.
2. If `config[key]` is specified, use that.
3. Otherwise prompt using `prompt_strategy`.
:param cli... | [
"def",
"get_userpass_value",
"(",
"cli_value",
",",
"config",
",",
"key",
",",
"prompt_strategy",
")",
":",
"if",
"cli_value",
"is",
"not",
"None",
":",
"return",
"cli_value",
"elif",
"config",
".",
"get",
"(",
"key",
")",
":",
"return",
"config",
"[",
"... | Gets the username / password from config.
Uses the following rules:
1. If it is specified on the cli (`cli_value`), use that.
2. If `config[key]` is specified, use that.
3. Otherwise prompt using `prompt_strategy`.
:param cli_value: The value supplied from the command line or `None`.
:type cl... | [
"Gets",
"the",
"username",
"/",
"password",
"from",
"config",
"."
] | python | test | 33.038462 |
django-parler/django-parler | parler/utils/views.py | https://github.com/django-parler/django-parler/blob/11ae4af5e8faddb74c69c848870122df4006a54e/parler/utils/views.py#L31-L72 | def get_language_tabs(request, current_language, available_languages, css_class=None):
"""
Determine the language tabs to show.
"""
tabs = TabsList(css_class=css_class)
get = request.GET.copy() # QueryDict object
tab_languages = []
site_id = getattr(settings, 'SITE_ID', None)
for lang_... | [
"def",
"get_language_tabs",
"(",
"request",
",",
"current_language",
",",
"available_languages",
",",
"css_class",
"=",
"None",
")",
":",
"tabs",
"=",
"TabsList",
"(",
"css_class",
"=",
"css_class",
")",
"get",
"=",
"request",
".",
"GET",
".",
"copy",
"(",
... | Determine the language tabs to show. | [
"Determine",
"the",
"language",
"tabs",
"to",
"show",
"."
] | python | train | 33.5 |
StorjOld/heartbeat | heartbeat/OneHash/OneHash.py | https://github.com/StorjOld/heartbeat/blob/4d54f2011f1e9f688073d4347bc51bb7bd682718/heartbeat/OneHash/OneHash.py#L92-L110 | def generate_challenges(self, num, root_seed):
""" Generate the specified number of hash challenges.
:param num: The number of hash challenges we want to generate.
:param root_seed: Some value that we use to generate our seeds from.
"""
# Generate a series of seeds
seed... | [
"def",
"generate_challenges",
"(",
"self",
",",
"num",
",",
"root_seed",
")",
":",
"# Generate a series of seeds",
"seeds",
"=",
"self",
".",
"generate_seeds",
"(",
"num",
",",
"root_seed",
",",
"self",
".",
"secret",
")",
"blocks",
"=",
"self",
".",
"pick_b... | Generate the specified number of hash challenges.
:param num: The number of hash challenges we want to generate.
:param root_seed: Some value that we use to generate our seeds from. | [
"Generate",
"the",
"specified",
"number",
"of",
"hash",
"challenges",
"."
] | python | train | 39.473684 |
StackStorm/pybind | pybind/nos/v6_0_2f/rbridge_id/router/router_bgp/address_family/ipv4/ipv4_unicast/__init__.py | https://github.com/StackStorm/pybind/blob/44c467e71b2b425be63867aba6e6fa28b2cfe7fb/pybind/nos/v6_0_2f/rbridge_id/router/router_bgp/address_family/ipv4/ipv4_unicast/__init__.py#L127-L148 | def _set_af_vrf(self, v, load=False):
"""
Setter method for af_vrf, mapped from YANG variable /rbridge_id/router/router_bgp/address_family/ipv4/ipv4_unicast/af_vrf (list)
If this variable is read-only (config: false) in the
source YANG file, then _set_af_vrf is considered as a private
method. Backen... | [
"def",
"_set_af_vrf",
"(",
"self",
",",
"v",
",",
"load",
"=",
"False",
")",
":",
"if",
"hasattr",
"(",
"v",
",",
"\"_utype\"",
")",
":",
"v",
"=",
"v",
".",
"_utype",
"(",
"v",
")",
"try",
":",
"t",
"=",
"YANGDynClass",
"(",
"v",
",",
"base",
... | Setter method for af_vrf, mapped from YANG variable /rbridge_id/router/router_bgp/address_family/ipv4/ipv4_unicast/af_vrf (list)
If this variable is read-only (config: false) in the
source YANG file, then _set_af_vrf is considered as a private
method. Backends looking to populate this variable should
do... | [
"Setter",
"method",
"for",
"af_vrf",
"mapped",
"from",
"YANG",
"variable",
"/",
"rbridge_id",
"/",
"router",
"/",
"router_bgp",
"/",
"address_family",
"/",
"ipv4",
"/",
"ipv4_unicast",
"/",
"af_vrf",
"(",
"list",
")",
"If",
"this",
"variable",
"is",
"read",
... | python | train | 120.227273 |
MSchnei/pyprf_feature | pyprf_feature/analysis/old/pRF_utils.py | https://github.com/MSchnei/pyprf_feature/blob/49004ede7ae1ddee07a30afe9ce3e2776750805c/pyprf_feature/analysis/old/pRF_utils.py#L90-L105 | def calcR2(predTst, yTest, axis=0):
"""calculate coefficient of determination. Assumes that axis=0 is time
Parameters
----------
predTst : np.array, predicted reponse for yTest
yTest : np.array, acxtually observed response for yTest
Returns
-------
aryFunc : ... | [
"def",
"calcR2",
"(",
"predTst",
",",
"yTest",
",",
"axis",
"=",
"0",
")",
":",
"rss",
"=",
"np",
".",
"sum",
"(",
"(",
"yTest",
"-",
"predTst",
")",
"**",
"2",
",",
"axis",
"=",
"axis",
")",
"tss",
"=",
"np",
".",
"sum",
"(",
"(",
"yTest",
... | calculate coefficient of determination. Assumes that axis=0 is time
Parameters
----------
predTst : np.array, predicted reponse for yTest
yTest : np.array, acxtually observed response for yTest
Returns
-------
aryFunc : np.array
R2 | [
"calculate",
"coefficient",
"of",
"determination",
".",
"Assumes",
"that",
"axis",
"=",
"0",
"is",
"time"
] | python | train | 29.3125 |
google/neuroglancer | python/neuroglancer/server.py | https://github.com/google/neuroglancer/blob/9efd12741013f464286f0bf3fa0b667f75a66658/python/neuroglancer/server.py#L245-L258 | def stop():
"""Stop the server, invalidating any viewer URLs.
This allows any previously-referenced data arrays to be garbage collected if there are no other
references to them.
"""
global global_server
if global_server is not None:
ioloop = global_server.ioloop
def stop_ioloop(... | [
"def",
"stop",
"(",
")",
":",
"global",
"global_server",
"if",
"global_server",
"is",
"not",
"None",
":",
"ioloop",
"=",
"global_server",
".",
"ioloop",
"def",
"stop_ioloop",
"(",
")",
":",
"ioloop",
".",
"stop",
"(",
")",
"ioloop",
".",
"close",
"(",
... | Stop the server, invalidating any viewer URLs.
This allows any previously-referenced data arrays to be garbage collected if there are no other
references to them. | [
"Stop",
"the",
"server",
"invalidating",
"any",
"viewer",
"URLs",
"."
] | python | train | 31.857143 |
ethereum/pyrlp | rlp/codec.py | https://github.com/ethereum/pyrlp/blob/bb898f8056da3973204c699621350bf9565e43df/rlp/codec.py#L98-L111 | def length_prefix(length, offset):
"""Construct the prefix to lists or strings denoting their length.
:param length: the length of the item in bytes
:param offset: ``0x80`` when encoding raw bytes, ``0xc0`` when encoding a
list
"""
if length < 56:
return ALL_BYTES[offset ... | [
"def",
"length_prefix",
"(",
"length",
",",
"offset",
")",
":",
"if",
"length",
"<",
"56",
":",
"return",
"ALL_BYTES",
"[",
"offset",
"+",
"length",
"]",
"elif",
"length",
"<",
"LONG_LENGTH",
":",
"length_string",
"=",
"int_to_big_endian",
"(",
"length",
"... | Construct the prefix to lists or strings denoting their length.
:param length: the length of the item in bytes
:param offset: ``0x80`` when encoding raw bytes, ``0xc0`` when encoding a
list | [
"Construct",
"the",
"prefix",
"to",
"lists",
"or",
"strings",
"denoting",
"their",
"length",
"."
] | python | train | 38.642857 |
nvbn/thefuck | thefuck/types.py | https://github.com/nvbn/thefuck/blob/40ab4eb62db57627bff10cf029d29c94704086a2/thefuck/types.py#L131-L147 | def from_path(cls, path):
"""Creates rule instance from path.
:type path: pathlib.Path
:rtype: Rule
"""
name = path.name[:-3]
with logs.debug_time(u'Importing rule: {};'.format(name)):
rule_module = load_source(name, str(path))
priority = getattr... | [
"def",
"from_path",
"(",
"cls",
",",
"path",
")",
":",
"name",
"=",
"path",
".",
"name",
"[",
":",
"-",
"3",
"]",
"with",
"logs",
".",
"debug_time",
"(",
"u'Importing rule: {};'",
".",
"format",
"(",
"name",
")",
")",
":",
"rule_module",
"=",
"load_s... | Creates rule instance from path.
:type path: pathlib.Path
:rtype: Rule | [
"Creates",
"rule",
"instance",
"from",
"path",
"."
] | python | train | 40.823529 |
zimeon/iiif | iiif/static.py | https://github.com/zimeon/iiif/blob/9d10018d01202fa2a76dfa61598dc6eca07b471f/iiif/static.py#L214-L261 | def generate(self, src=None, identifier=None):
"""Generate static files for one source image."""
self.src = src
self.identifier = identifier
# Get image details and calculate tiles
im = self.manipulator_klass()
im.srcfile = self.src
im.set_max_image_pixels(self.ma... | [
"def",
"generate",
"(",
"self",
",",
"src",
"=",
"None",
",",
"identifier",
"=",
"None",
")",
":",
"self",
".",
"src",
"=",
"src",
"self",
".",
"identifier",
"=",
"identifier",
"# Get image details and calculate tiles",
"im",
"=",
"self",
".",
"manipulator_k... | Generate static files for one source image. | [
"Generate",
"static",
"files",
"for",
"one",
"source",
"image",
"."
] | python | train | 48.333333 |
openstax/cnx-publishing | cnxpublishing/views/publishing.py | https://github.com/openstax/cnx-publishing/blob/f55b4a2c45d8618737288f1b74b4139d5ac74154/cnxpublishing/views/publishing.py#L77-L108 | def get_accept_license(request):
"""This produces JSON data for a user (at ``uid``) to view the license(s)
they have accepted or will need to accept for a publication (at ``id``).
"""
publication_id = request.matchdict['id']
user_id = request.matchdict['uid']
# FIXME Is this an active publicati... | [
"def",
"get_accept_license",
"(",
"request",
")",
":",
"publication_id",
"=",
"request",
".",
"matchdict",
"[",
"'id'",
"]",
"user_id",
"=",
"request",
".",
"matchdict",
"[",
"'uid'",
"]",
"# FIXME Is this an active publication?",
"# TODO Verify the accepting user is th... | This produces JSON data for a user (at ``uid``) to view the license(s)
they have accepted or will need to accept for a publication (at ``id``). | [
"This",
"produces",
"JSON",
"data",
"for",
"a",
"user",
"(",
"at",
"uid",
")",
"to",
"view",
"the",
"license",
"(",
"s",
")",
"they",
"have",
"accepted",
"or",
"will",
"need",
"to",
"accept",
"for",
"a",
"publication",
"(",
"at",
"id",
")",
"."
] | python | valid | 33.84375 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.