repo stringlengths 7 54 | path stringlengths 4 192 | url stringlengths 87 284 | code stringlengths 78 104k | code_tokens list | docstring stringlengths 1 46.9k | docstring_tokens list | language stringclasses 1
value | partition stringclasses 3
values |
|---|---|---|---|---|---|---|---|---|
kobinpy/kobin | kobin/routes.py | https://github.com/kobinpy/kobin/blob/e6caff5af05db8a6e511d3de275d262466ab36a6/kobin/routes.py#L84-L102 | def match_url_vars_type(url_vars, type_hints):
""" Match types of url vars.
>>> match_url_vars_type({'user_id': '1'}, {'user_id': int})
(True, {'user_id': 1})
>>> match_url_vars_type({'user_id': 'foo'}, {'user_id': int})
(False, {})
"""
typed_url_vars = {}
try:
for k, v in url_v... | [
"def",
"match_url_vars_type",
"(",
"url_vars",
",",
"type_hints",
")",
":",
"typed_url_vars",
"=",
"{",
"}",
"try",
":",
"for",
"k",
",",
"v",
"in",
"url_vars",
".",
"items",
"(",
")",
":",
"arg_type",
"=",
"type_hints",
".",
"get",
"(",
"k",
")",
"i... | Match types of url vars.
>>> match_url_vars_type({'user_id': '1'}, {'user_id': int})
(True, {'user_id': 1})
>>> match_url_vars_type({'user_id': 'foo'}, {'user_id': int})
(False, {}) | [
"Match",
"types",
"of",
"url",
"vars",
"."
] | python | train |
xtuml/pyxtuml | bridgepoint/ooaofooa.py | https://github.com/xtuml/pyxtuml/blob/7dd9343b9a0191d1db1887ab9288d0a026608d9a/bridgepoint/ooaofooa.py#L448-L490 | def mk_component(bp_model, c_c=None, derived_attributes=False):
'''
Create a pyxtuml meta model from a BridgePoint model.
Optionally, restrict to classes and associations contained in the
component c_c.
'''
target = Domain()
c_c_filt = lambda sel: c_c is None or is_contained_in(sel, c_c)
... | [
"def",
"mk_component",
"(",
"bp_model",
",",
"c_c",
"=",
"None",
",",
"derived_attributes",
"=",
"False",
")",
":",
"target",
"=",
"Domain",
"(",
")",
"c_c_filt",
"=",
"lambda",
"sel",
":",
"c_c",
"is",
"None",
"or",
"is_contained_in",
"(",
"sel",
",",
... | Create a pyxtuml meta model from a BridgePoint model.
Optionally, restrict to classes and associations contained in the
component c_c. | [
"Create",
"a",
"pyxtuml",
"meta",
"model",
"from",
"a",
"BridgePoint",
"model",
".",
"Optionally",
"restrict",
"to",
"classes",
"and",
"associations",
"contained",
"in",
"the",
"component",
"c_c",
"."
] | python | test |
tisimst/pyDOE | pyDOE/doe_lhs.py | https://github.com/tisimst/pyDOE/blob/436143702507a5c8ff87b361223eee8171d6a1d7/pyDOE/doe_lhs.py#L21-L119 | def lhs(n, samples=None, criterion=None, iterations=None):
"""
Generate a latin-hypercube design
Parameters
----------
n : int
The number of factors to generate samples for
Optional
--------
samples : int
The number of samples to generate for each fa... | [
"def",
"lhs",
"(",
"n",
",",
"samples",
"=",
"None",
",",
"criterion",
"=",
"None",
",",
"iterations",
"=",
"None",
")",
":",
"H",
"=",
"None",
"if",
"samples",
"is",
"None",
":",
"samples",
"=",
"n",
"if",
"criterion",
"is",
"not",
"None",
":",
... | Generate a latin-hypercube design
Parameters
----------
n : int
The number of factors to generate samples for
Optional
--------
samples : int
The number of samples to generate for each factor (Default: n)
criterion : str
Allowable values are "cen... | [
"Generate",
"a",
"latin",
"-",
"hypercube",
"design",
"Parameters",
"----------",
"n",
":",
"int",
"The",
"number",
"of",
"factors",
"to",
"generate",
"samples",
"for",
"Optional",
"--------",
"samples",
":",
"int",
"The",
"number",
"of",
"samples",
"to",
"g... | python | train |
RI-imaging/qpsphere | qpsphere/cnvnc.py | https://github.com/RI-imaging/qpsphere/blob/3cfa0e9fb8e81be8c820abbeccd47242e7972ac1/qpsphere/cnvnc.py#L112-L142 | def bg_phase_mask_from_sim(sim, radial_clearance=1.1):
"""Return the background phase mask of a qpsphere simulation
Parameters
----------
sim: qpimage.QPImage
Quantitative phase data simulated with qpsphere;
The simulation keyword arguments "sim center", "sim radius",
and "pixel... | [
"def",
"bg_phase_mask_from_sim",
"(",
"sim",
",",
"radial_clearance",
"=",
"1.1",
")",
":",
"# Mask values around the object",
"cx",
",",
"cy",
"=",
"sim",
"[",
"\"sim center\"",
"]",
"radius",
"=",
"sim",
"[",
"\"sim radius\"",
"]",
"px_um",
"=",
"sim",
"[",
... | Return the background phase mask of a qpsphere simulation
Parameters
----------
sim: qpimage.QPImage
Quantitative phase data simulated with qpsphere;
The simulation keyword arguments "sim center", "sim radius",
and "pixel size" must be present in `sim.meta`.
radial_clearance: fl... | [
"Return",
"the",
"background",
"phase",
"mask",
"of",
"a",
"qpsphere",
"simulation"
] | python | train |
SoCo/SoCo | soco/discovery.py | https://github.com/SoCo/SoCo/blob/671937e07d7973b78c0cbee153d4f3ad68ec48c6/soco/discovery.py#L22-L185 | def discover(timeout=5, include_invisible=False, interface_addr=None):
""" Discover Sonos zones on the local network.
Return a set of `SoCo` instances for each zone found.
Include invisible zones (bridges and slave zones in stereo pairs if
``include_invisible`` is `True`. Will block for up to ``timeout... | [
"def",
"discover",
"(",
"timeout",
"=",
"5",
",",
"include_invisible",
"=",
"False",
",",
"interface_addr",
"=",
"None",
")",
":",
"def",
"create_socket",
"(",
"interface_addr",
"=",
"None",
")",
":",
"\"\"\" A helper function for creating a socket for discover purpos... | Discover Sonos zones on the local network.
Return a set of `SoCo` instances for each zone found.
Include invisible zones (bridges and slave zones in stereo pairs if
``include_invisible`` is `True`. Will block for up to ``timeout`` seconds,
after which return `None` if no zones found.
Args:
... | [
"Discover",
"Sonos",
"zones",
"on",
"the",
"local",
"network",
"."
] | python | train |
pysal/spglm | spglm/family.py | https://github.com/pysal/spglm/blob/1339898adcb7e1638f1da83d57aa37392525f018/spglm/family.py#L800-L831 | def deviance(self, endog, mu, freq_weights=1, scale=1., axis=None):
r'''
Deviance function for either Bernoulli or Binomial data.
Parameters
----------
endog : array-like
Endogenous response variable (already transformed to a probability
if appropriate).
... | [
"def",
"deviance",
"(",
"self",
",",
"endog",
",",
"mu",
",",
"freq_weights",
"=",
"1",
",",
"scale",
"=",
"1.",
",",
"axis",
"=",
"None",
")",
":",
"if",
"np",
".",
"shape",
"(",
"self",
".",
"n",
")",
"==",
"(",
")",
"and",
"self",
".",
"n"... | r'''
Deviance function for either Bernoulli or Binomial data.
Parameters
----------
endog : array-like
Endogenous response variable (already transformed to a probability
if appropriate).
mu : array
Fitted mean response variable
freq_we... | [
"r",
"Deviance",
"function",
"for",
"either",
"Bernoulli",
"or",
"Binomial",
"data",
"."
] | python | train |
GNS3/gns3-server | gns3server/compute/port_manager.py | https://github.com/GNS3/gns3-server/blob/a221678448fb5d24e977ef562f81d56aacc89ab1/gns3server/compute/port_manager.py#L168-L184 | def _check_port(host, port, socket_type):
"""
Check if an a port is available and raise an OSError if port is not available
:returns: boolean
"""
if socket_type == "UDP":
socket_type = socket.SOCK_DGRAM
else:
socket_type = socket.SOCK_STREAM
... | [
"def",
"_check_port",
"(",
"host",
",",
"port",
",",
"socket_type",
")",
":",
"if",
"socket_type",
"==",
"\"UDP\"",
":",
"socket_type",
"=",
"socket",
".",
"SOCK_DGRAM",
"else",
":",
"socket_type",
"=",
"socket",
".",
"SOCK_STREAM",
"for",
"res",
"in",
"so... | Check if an a port is available and raise an OSError if port is not available
:returns: boolean | [
"Check",
"if",
"an",
"a",
"port",
"is",
"available",
"and",
"raise",
"an",
"OSError",
"if",
"port",
"is",
"not",
"available"
] | python | train |
fbcotter/py3nvml | py3nvml/py3nvml.py | https://github.com/fbcotter/py3nvml/blob/47f0f2c0eee56dec4e4beebec26b734e01d357b7/py3nvml/py3nvml.py#L4417-L4445 | def nvmlDeviceGetSupportedEventTypes(handle):
r"""
/**
* Returns information about events supported on device
*
* For Fermi &tm; or newer fully supported devices.
*
* Events are not supported on Windows. So this function returns an empty mask in \a eventTypes on Windows.
*
* @... | [
"def",
"nvmlDeviceGetSupportedEventTypes",
"(",
"handle",
")",
":",
"c_eventTypes",
"=",
"c_ulonglong",
"(",
")",
"fn",
"=",
"_nvmlGetFunctionPointer",
"(",
"\"nvmlDeviceGetSupportedEventTypes\"",
")",
"ret",
"=",
"fn",
"(",
"handle",
",",
"byref",
"(",
"c_eventType... | r"""
/**
* Returns information about events supported on device
*
* For Fermi &tm; or newer fully supported devices.
*
* Events are not supported on Windows. So this function returns an empty mask in \a eventTypes on Windows.
*
* @param device The ide... | [
"r",
"/",
"**",
"*",
"Returns",
"information",
"about",
"events",
"supported",
"on",
"device",
"*",
"*",
"For",
"Fermi",
"&tm",
";",
"or",
"newer",
"fully",
"supported",
"devices",
".",
"*",
"*",
"Events",
"are",
"not",
"supported",
"on",
"Windows",
".",... | python | train |
numenta/htmresearch | htmresearch/algorithms/TM.py | https://github.com/numenta/htmresearch/blob/70c096b09a577ea0432c3f3bfff4442d4871b7aa/htmresearch/algorithms/TM.py#L2310-L2352 | def printSegment(self):
"""Print segment information for verbose messaging and debugging.
This uses the following format:
ID:54413 True 0.64801 (24/36) 101 [9,1]0.75 [10,1]0.75 [11,1]0.75
where:
54413 - is the unique segment id
True - is sequence segment
0.64801 - moving average dut... | [
"def",
"printSegment",
"(",
"self",
")",
":",
"# Segment ID",
"print",
"\"ID:%-5d\"",
"%",
"(",
"self",
".",
"segID",
")",
",",
"# Sequence segment or pooling segment",
"if",
"self",
".",
"isSequenceSeg",
":",
"print",
"\"True\"",
",",
"else",
":",
"print",
"\... | Print segment information for verbose messaging and debugging.
This uses the following format:
ID:54413 True 0.64801 (24/36) 101 [9,1]0.75 [10,1]0.75 [11,1]0.75
where:
54413 - is the unique segment id
True - is sequence segment
0.64801 - moving average duty cycle
(24/36) - (numPos... | [
"Print",
"segment",
"information",
"for",
"verbose",
"messaging",
"and",
"debugging",
".",
"This",
"uses",
"the",
"following",
"format",
":"
] | python | train |
limix/glimix-core | glimix_core/glmm/_glmm.py | https://github.com/limix/glimix-core/blob/cddd0994591d100499cc41c1f480ddd575e7a980/glimix_core/glmm/_glmm.py#L231-L235 | def posteriori_covariance(self):
r""" Covariance of the estimated posteriori."""
K = GLMM.covariance(self)
tau = self._ep._posterior.tau
return pinv(pinv(K) + diag(1 / tau)) | [
"def",
"posteriori_covariance",
"(",
"self",
")",
":",
"K",
"=",
"GLMM",
".",
"covariance",
"(",
"self",
")",
"tau",
"=",
"self",
".",
"_ep",
".",
"_posterior",
".",
"tau",
"return",
"pinv",
"(",
"pinv",
"(",
"K",
")",
"+",
"diag",
"(",
"1",
"/",
... | r""" Covariance of the estimated posteriori. | [
"r",
"Covariance",
"of",
"the",
"estimated",
"posteriori",
"."
] | python | valid |
rigetti/pyquil | pyquil/operator_estimation.py | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/operator_estimation.py#L746-L900 | def measure_observables(qc: QuantumComputer, tomo_experiment: TomographyExperiment,
n_shots: int = 10000, progress_callback=None, active_reset=False,
symmetrize_readout: str = 'exhaustive',
calibrate_readout: str = 'plus-eig'):
"""
Measure ... | [
"def",
"measure_observables",
"(",
"qc",
":",
"QuantumComputer",
",",
"tomo_experiment",
":",
"TomographyExperiment",
",",
"n_shots",
":",
"int",
"=",
"10000",
",",
"progress_callback",
"=",
"None",
",",
"active_reset",
"=",
"False",
",",
"symmetrize_readout",
":"... | Measure all the observables in a TomographyExperiment.
:param qc: A QuantumComputer which can run quantum programs
:param tomo_experiment: A suite of tomographic observables to measure
:param n_shots: The number of shots to take per ExperimentSetting
:param progress_callback: If not None, this function... | [
"Measure",
"all",
"the",
"observables",
"in",
"a",
"TomographyExperiment",
"."
] | python | train |
necaris/python3-openid | openid/message.py | https://github.com/necaris/python3-openid/blob/4911bbc196dfd6f9eda7155df9903d668720ecbf/openid/message.py#L256-L268 | def setOpenIDNamespace(self, openid_ns_uri, implicit):
"""Set the OpenID namespace URI used in this message.
@raises InvalidOpenIDNamespace: if the namespace is not in
L{Message.allowed_openid_namespaces}
"""
if isinstance(openid_ns_uri, bytes):
openid_ns_uri = s... | [
"def",
"setOpenIDNamespace",
"(",
"self",
",",
"openid_ns_uri",
",",
"implicit",
")",
":",
"if",
"isinstance",
"(",
"openid_ns_uri",
",",
"bytes",
")",
":",
"openid_ns_uri",
"=",
"str",
"(",
"openid_ns_uri",
",",
"encoding",
"=",
"\"utf-8\"",
")",
"if",
"ope... | Set the OpenID namespace URI used in this message.
@raises InvalidOpenIDNamespace: if the namespace is not in
L{Message.allowed_openid_namespaces} | [
"Set",
"the",
"OpenID",
"namespace",
"URI",
"used",
"in",
"this",
"message",
"."
] | python | train |
fastai/fastai | fastai/vision/image.py | https://github.com/fastai/fastai/blob/9fb84a5cdefe5a766cdb792b8f5d8971737b7e67/fastai/vision/image.py#L399-L401 | def open_mask(fn:PathOrStr, div=False, convert_mode='L', after_open:Callable=None)->ImageSegment:
"Return `ImageSegment` object create from mask in file `fn`. If `div`, divides pixel values by 255."
return open_image(fn, div=div, convert_mode=convert_mode, cls=ImageSegment, after_open=after_open) | [
"def",
"open_mask",
"(",
"fn",
":",
"PathOrStr",
",",
"div",
"=",
"False",
",",
"convert_mode",
"=",
"'L'",
",",
"after_open",
":",
"Callable",
"=",
"None",
")",
"->",
"ImageSegment",
":",
"return",
"open_image",
"(",
"fn",
",",
"div",
"=",
"div",
",",... | Return `ImageSegment` object create from mask in file `fn`. If `div`, divides pixel values by 255. | [
"Return",
"ImageSegment",
"object",
"create",
"from",
"mask",
"in",
"file",
"fn",
".",
"If",
"div",
"divides",
"pixel",
"values",
"by",
"255",
"."
] | python | train |
deepmind/pysc2 | pysc2/lib/stopwatch.py | https://github.com/deepmind/pysc2/blob/df4cc4b00f07a2242be9ba153d4a7f4ad2017897/pysc2/lib/stopwatch.py#L60-L64 | def dev(self):
"""Standard deviation."""
if self.num == 0:
return 0
return math.sqrt(max(0, self.sum_sq / self.num - (self.sum / self.num)**2)) | [
"def",
"dev",
"(",
"self",
")",
":",
"if",
"self",
".",
"num",
"==",
"0",
":",
"return",
"0",
"return",
"math",
".",
"sqrt",
"(",
"max",
"(",
"0",
",",
"self",
".",
"sum_sq",
"/",
"self",
".",
"num",
"-",
"(",
"self",
".",
"sum",
"/",
"self",... | Standard deviation. | [
"Standard",
"deviation",
"."
] | python | train |
Parquery/icontract | icontract/_recompute.py | https://github.com/Parquery/icontract/blob/846e3187869a9ba790e9b893c98e5055e1cce274/icontract/_recompute.py#L386-L394 | def visit_SetComp(self, node: ast.SetComp) -> Any:
"""Compile the set comprehension as a function and call it."""
result = self._execute_comprehension(node=node)
for generator in node.generators:
self.visit(generator.iter)
self.recomputed_values[node] = result
retur... | [
"def",
"visit_SetComp",
"(",
"self",
",",
"node",
":",
"ast",
".",
"SetComp",
")",
"->",
"Any",
":",
"result",
"=",
"self",
".",
"_execute_comprehension",
"(",
"node",
"=",
"node",
")",
"for",
"generator",
"in",
"node",
".",
"generators",
":",
"self",
... | Compile the set comprehension as a function and call it. | [
"Compile",
"the",
"set",
"comprehension",
"as",
"a",
"function",
"and",
"call",
"it",
"."
] | python | train |
uw-it-aca/uw-restclients-sws | uw_sws/enrollment.py | https://github.com/uw-it-aca/uw-restclients-sws/blob/4d36776dcca36855fc15c1b8fe7650ae045194cf/uw_sws/enrollment.py#L216-L228 | def get_enrollment_history_by_regid(regid,
verbose='true',
transcriptable_course='all',
changed_since_date='',
include_unfinished_pce_course_reg=False):
"""
:return: a ... | [
"def",
"get_enrollment_history_by_regid",
"(",
"regid",
",",
"verbose",
"=",
"'true'",
",",
"transcriptable_course",
"=",
"'all'",
",",
"changed_since_date",
"=",
"''",
",",
"include_unfinished_pce_course_reg",
"=",
"False",
")",
":",
"return",
"_json_to_enrollment_list... | :return: a complete chronological list of all the enrollemnts
[Enrollment], where the Enrollment object has a term element. | [
":",
"return",
":",
"a",
"complete",
"chronological",
"list",
"of",
"all",
"the",
"enrollemnts",
"[",
"Enrollment",
"]",
"where",
"the",
"Enrollment",
"object",
"has",
"a",
"term",
"element",
"."
] | python | train |
etingof/pysnmp | pysnmp/smi/mibs/SNMPv2-TC.py | https://github.com/etingof/pysnmp/blob/cde062dd42f67dfd2d7686286a322d40e9c3a4b7/pysnmp/smi/mibs/SNMPv2-TC.py#L250-L437 | def prettyIn(self, value): # override asn1 type method
"""Implements DISPLAY-HINT parsing into base SNMP value
Proper parsing seems impossible due to ambiguities.
Here we are trying to do our best, but be prepared
for failures on complicated DISPLAY-HINTs.
Keep in mind that th... | [
"def",
"prettyIn",
"(",
"self",
",",
"value",
")",
":",
"# override asn1 type method",
"for",
"base",
"in",
"inspect",
".",
"getmro",
"(",
"self",
".",
"__class__",
")",
":",
"if",
"not",
"issubclass",
"(",
"base",
",",
"TextualConvention",
")",
"and",
"is... | Implements DISPLAY-HINT parsing into base SNMP value
Proper parsing seems impossible due to ambiguities.
Here we are trying to do our best, but be prepared
for failures on complicated DISPLAY-HINTs.
Keep in mind that this parser only works with "text"
input meaning `unicode` (P... | [
"Implements",
"DISPLAY",
"-",
"HINT",
"parsing",
"into",
"base",
"SNMP",
"value"
] | python | train |
mozilla/crontabber | crontabber/mixins.py | https://github.com/mozilla/crontabber/blob/b510be349e71f165c1a9506db95bda0b88728f8b/crontabber/mixins.py#L118-L141 | def with_resource_connection_as_argument(resource_name):
"""a class decorator for Crontabber Apps. This decorator will a class a
_run_proxy method that passes a databsase connection as a context manager
into the CronApp's run method. The connection will automatically be closed
when the ConApp's run me... | [
"def",
"with_resource_connection_as_argument",
"(",
"resource_name",
")",
":",
"connection_factory_attr_name",
"=",
"'%s_connection_factory'",
"%",
"resource_name",
"def",
"class_decorator",
"(",
"cls",
")",
":",
"def",
"_run_proxy",
"(",
"self",
",",
"*",
"args",
","... | a class decorator for Crontabber Apps. This decorator will a class a
_run_proxy method that passes a databsase connection as a context manager
into the CronApp's run method. The connection will automatically be closed
when the ConApp's run method ends.
In order for this dectorator to function properl... | [
"a",
"class",
"decorator",
"for",
"Crontabber",
"Apps",
".",
"This",
"decorator",
"will",
"a",
"class",
"a",
"_run_proxy",
"method",
"that",
"passes",
"a",
"databsase",
"connection",
"as",
"a",
"context",
"manager",
"into",
"the",
"CronApp",
"s",
"run",
"met... | python | train |
aio-libs/aioftp | aioftp/server.py | https://github.com/aio-libs/aioftp/blob/b45395b1aba41301b898040acade7010e6878a08/aioftp/server.py#L391-L424 | async def start(self, host=None, port=0, **kwargs):
"""
:py:func:`asyncio.coroutine`
Start server.
:param host: ip address to bind for listening.
:type host: :py:class:`str`
:param port: port number to bind for listening.
:type port: :py:class:`int`
:p... | [
"async",
"def",
"start",
"(",
"self",
",",
"host",
"=",
"None",
",",
"port",
"=",
"0",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"_start_server_extra_arguments",
"=",
"kwargs",
"self",
".",
"connections",
"=",
"{",
"}",
"self",
".",
"server_host"... | :py:func:`asyncio.coroutine`
Start server.
:param host: ip address to bind for listening.
:type host: :py:class:`str`
:param port: port number to bind for listening.
:type port: :py:class:`int`
:param kwargs: keyword arguments, they passed to
:py:func:`asy... | [
":",
"py",
":",
"func",
":",
"asyncio",
".",
"coroutine"
] | python | valid |
BerkeleyAutomation/perception | perception/image.py | https://github.com/BerkeleyAutomation/perception/blob/03d9b37dd6b66896cdfe173905c9413c8c3c5df6/perception/image.py#L2964-L2990 | def crop(self, height, width, center_i=None, center_j=None):
"""Crop the image centered around center_i, center_j.
Parameters
----------
height : int
The height of the desired image.
width : int
The width of the desired image.
center_i : int
... | [
"def",
"crop",
"(",
"self",
",",
"height",
",",
"width",
",",
"center_i",
"=",
"None",
",",
"center_j",
"=",
"None",
")",
":",
"color_im_crop",
"=",
"self",
".",
"color",
".",
"crop",
"(",
"height",
",",
"width",
",",
"center_i",
",",
"center_j",
")"... | Crop the image centered around center_i, center_j.
Parameters
----------
height : int
The height of the desired image.
width : int
The width of the desired image.
center_i : int
The center height point at which to crop. If not specified, the... | [
"Crop",
"the",
"image",
"centered",
"around",
"center_i",
"center_j",
"."
] | python | train |
stsouko/CIMtools | CIMtools/applicability_domain/leverage.py | https://github.com/stsouko/CIMtools/blob/cbb46e68eaa1fe7e7b6cb311fc7063e97096bdf3/CIMtools/applicability_domain/leverage.py#L151-L170 | def predict(self, X):
"""Predict inside or outside AD for X.
Parameters
----------
X : array-like or sparse matrix, shape (n_samples, n_features)
The input samples. Internally, it will be converted to
``dtype=np.float32`` and if a sparse matrix is provided
... | [
"def",
"predict",
"(",
"self",
",",
"X",
")",
":",
"# Check is fit had been called",
"check_is_fitted",
"(",
"self",
",",
"[",
"'inverse_influence_matrix'",
"]",
")",
"# Check that X have correct shape",
"X",
"=",
"check_array",
"(",
"X",
")",
"return",
"self",
".... | Predict inside or outside AD for X.
Parameters
----------
X : array-like or sparse matrix, shape (n_samples, n_features)
The input samples. Internally, it will be converted to
``dtype=np.float32`` and if a sparse matrix is provided
to a sparse ``csr_matrix``.... | [
"Predict",
"inside",
"or",
"outside",
"AD",
"for",
"X",
"."
] | python | valid |
theislab/scanpy | scanpy/datasets/__init__.py | https://github.com/theislab/scanpy/blob/9e4e5ee02e04cf618872d9b098e24f0542e8b227/scanpy/datasets/__init__.py#L177-L192 | def toggleswitch() -> AnnData:
"""Simulated toggleswitch.
Data obtained simulating a simple toggleswitch `Gardner *et al.*, Nature
(2000) <https://doi.org/10.1038/35002131>`__.
Simulate via :func:`~scanpy.api.sim`.
Returns
-------
Annotated data matrix.
"""
filename = os.path.dirn... | [
"def",
"toggleswitch",
"(",
")",
"->",
"AnnData",
":",
"filename",
"=",
"os",
".",
"path",
".",
"dirname",
"(",
"__file__",
")",
"+",
"'/toggleswitch.txt'",
"adata",
"=",
"sc",
".",
"read",
"(",
"filename",
",",
"first_column_names",
"=",
"True",
")",
"a... | Simulated toggleswitch.
Data obtained simulating a simple toggleswitch `Gardner *et al.*, Nature
(2000) <https://doi.org/10.1038/35002131>`__.
Simulate via :func:`~scanpy.api.sim`.
Returns
-------
Annotated data matrix. | [
"Simulated",
"toggleswitch",
"."
] | python | train |
samjabrahams/anchorhub | anchorhub/builtin/github/cstrategies.py | https://github.com/samjabrahams/anchorhub/blob/5ade359b08297d4003a5f477389c01de9e634b54/anchorhub/builtin/github/cstrategies.py#L46-L64 | def get(self, file_lines, index):
"""
Extract the specified AnchorHub tag, as well as the portion of the
line that should be converted from the ATX style Markdown header.
:param file_lines: List of strings corresponding to lines in a text file
:param index: index of file_lines c... | [
"def",
"get",
"(",
"self",
",",
"file_lines",
",",
"index",
")",
":",
"line",
"=",
"file_lines",
"[",
"index",
"]",
"start_index",
"=",
"line",
".",
"find",
"(",
"'# '",
")",
"+",
"2",
"# Start index for header text",
"start_tag",
"=",
"line",
".",
"rfin... | Extract the specified AnchorHub tag, as well as the portion of the
line that should be converted from the ATX style Markdown header.
:param file_lines: List of strings corresponding to lines in a text file
:param index: index of file_lines corresponding to the current line
:return: [tag... | [
"Extract",
"the",
"specified",
"AnchorHub",
"tag",
"as",
"well",
"as",
"the",
"portion",
"of",
"the",
"line",
"that",
"should",
"be",
"converted",
"from",
"the",
"ATX",
"style",
"Markdown",
"header",
"."
] | python | train |
theonion/django-bulbs | bulbs/promotion/views.py | https://github.com/theonion/django-bulbs/blob/0c0e6e3127a7dc487b96677fab95cacd2b3806da/bulbs/promotion/views.py#L171-L179 | def perform_update(self, serializer):
"""creates a record in the `bulbs.promotion.PZoneHistory`
:param obj: the instance saved
:param created: boolean expressing if the object was newly created (`False` if updated)
"""
instance = serializer.save()
# create history object... | [
"def",
"perform_update",
"(",
"self",
",",
"serializer",
")",
":",
"instance",
"=",
"serializer",
".",
"save",
"(",
")",
"# create history object",
"instance",
".",
"history",
".",
"create",
"(",
"data",
"=",
"instance",
".",
"data",
")"
] | creates a record in the `bulbs.promotion.PZoneHistory`
:param obj: the instance saved
:param created: boolean expressing if the object was newly created (`False` if updated) | [
"creates",
"a",
"record",
"in",
"the",
"bulbs",
".",
"promotion",
".",
"PZoneHistory"
] | python | train |
kgori/treeCl | treeCl/tree.py | https://github.com/kgori/treeCl/blob/fed624b3db1c19cc07175ca04e3eda6905a8d305/treeCl/tree.py#L1091-L1114 | def autocorrelated_relaxed_clock(self, root_rate, autocorrel,
distribution='lognormal'):
"""
Attaches rates to each node according to autocorrelated lognormal
model from Kishino et al.(2001), or autocorrelated exponential
"""
optioncheck(distr... | [
"def",
"autocorrelated_relaxed_clock",
"(",
"self",
",",
"root_rate",
",",
"autocorrel",
",",
"distribution",
"=",
"'lognormal'",
")",
":",
"optioncheck",
"(",
"distribution",
",",
"[",
"'exponential'",
",",
"'lognormal'",
"]",
")",
"if",
"autocorrel",
"==",
"0"... | Attaches rates to each node according to autocorrelated lognormal
model from Kishino et al.(2001), or autocorrelated exponential | [
"Attaches",
"rates",
"to",
"each",
"node",
"according",
"to",
"autocorrelated",
"lognormal",
"model",
"from",
"Kishino",
"et",
"al",
".",
"(",
"2001",
")",
"or",
"autocorrelated",
"exponential"
] | python | train |
geophysics-ubonn/reda | lib/reda/eis/plots.py | https://github.com/geophysics-ubonn/reda/blob/46a939729e40c7c4723315c03679c40761152e9e/lib/reda/eis/plots.py#L358-L370 | def add(self, response, label=None):
"""add one response object to the list
"""
if not isinstance(response, sip_response.sip_response):
raise Exception(
'can only add sip_reponse.sip_response objects'
)
self.objects.append(response)
if lab... | [
"def",
"add",
"(",
"self",
",",
"response",
",",
"label",
"=",
"None",
")",
":",
"if",
"not",
"isinstance",
"(",
"response",
",",
"sip_response",
".",
"sip_response",
")",
":",
"raise",
"Exception",
"(",
"'can only add sip_reponse.sip_response objects'",
")",
... | add one response object to the list | [
"add",
"one",
"response",
"object",
"to",
"the",
"list"
] | python | train |
mitsei/dlkit | dlkit/json_/assessment/mixins.py | https://github.com/mitsei/dlkit/blob/445f968a175d61c8d92c0f617a3c17dc1dc7c584/dlkit/json_/assessment/mixins.py#L660-L666 | def is_question_answered(self, question_id):
"""has the question matching item_id been answered and not skipped"""
question_map = self._get_question_map(question_id) # will raise NotFound()
if 'missingResponse' in question_map['responses'][0]:
return False
else:
... | [
"def",
"is_question_answered",
"(",
"self",
",",
"question_id",
")",
":",
"question_map",
"=",
"self",
".",
"_get_question_map",
"(",
"question_id",
")",
"# will raise NotFound()",
"if",
"'missingResponse'",
"in",
"question_map",
"[",
"'responses'",
"]",
"[",
"0",
... | has the question matching item_id been answered and not skipped | [
"has",
"the",
"question",
"matching",
"item_id",
"been",
"answered",
"and",
"not",
"skipped"
] | python | train |
slundberg/shap | shap/benchmark/metrics.py | https://github.com/slundberg/shap/blob/b280cb81d498b9d98565cad8dd16fc88ae52649f/shap/benchmark/metrics.py#L297-L304 | def keep_absolute_impute__roc_auc(X, y, model_generator, method_name, num_fcounts=11):
""" Keep Absolute (impute)
xlabel = "Max fraction of features kept"
ylabel = "ROC AUC"
transform = "identity"
sort_order = 19
"""
return __run_measure(measures.keep_mask, X, y, model_generator, method_name... | [
"def",
"keep_absolute_impute__roc_auc",
"(",
"X",
",",
"y",
",",
"model_generator",
",",
"method_name",
",",
"num_fcounts",
"=",
"11",
")",
":",
"return",
"__run_measure",
"(",
"measures",
".",
"keep_mask",
",",
"X",
",",
"y",
",",
"model_generator",
",",
"m... | Keep Absolute (impute)
xlabel = "Max fraction of features kept"
ylabel = "ROC AUC"
transform = "identity"
sort_order = 19 | [
"Keep",
"Absolute",
"(",
"impute",
")",
"xlabel",
"=",
"Max",
"fraction",
"of",
"features",
"kept",
"ylabel",
"=",
"ROC",
"AUC",
"transform",
"=",
"identity",
"sort_order",
"=",
"19"
] | python | train |
heikomuller/sco-datastore | scodata/__init__.py | https://github.com/heikomuller/sco-datastore/blob/7180a6b51150667e47629da566aedaa742e39342/scodata/__init__.py#L398-L427 | def experiments_predictions_attachments_download(self, experiment_id, run_id, resource_id):
"""Download a data file that has been attached with a successful model
run.
Parameters
----------
experiment_id : string
Unique experiment identifier
model_id : string... | [
"def",
"experiments_predictions_attachments_download",
"(",
"self",
",",
"experiment_id",
",",
"run_id",
",",
"resource_id",
")",
":",
"# Get experiment to ensure that it exists",
"if",
"self",
".",
"experiments_get",
"(",
"experiment_id",
")",
"is",
"None",
":",
"retur... | Download a data file that has been attached with a successful model
run.
Parameters
----------
experiment_id : string
Unique experiment identifier
model_id : string
Unique identifier of model to run
resource_id : string
Unique attachme... | [
"Download",
"a",
"data",
"file",
"that",
"has",
"been",
"attached",
"with",
"a",
"successful",
"model",
"run",
"."
] | python | train |
rainwoodman/kdcount | kdcount/correlate.py | https://github.com/rainwoodman/kdcount/blob/483548f6d27a4f245cd5d98880b5f4edd6cc8dc1/kdcount/correlate.py#L317-L326 | def _update_mean_coords(self, dig, N, centers_sum, **paircoords):
"""
Update the mean coordinate sums
"""
if N is None or centers_sum is None: return
N.flat[:] += utils.bincount(dig, 1., minlength=N.size)
for i, dim in enumerate(self.dims):
size = centers_sum... | [
"def",
"_update_mean_coords",
"(",
"self",
",",
"dig",
",",
"N",
",",
"centers_sum",
",",
"*",
"*",
"paircoords",
")",
":",
"if",
"N",
"is",
"None",
"or",
"centers_sum",
"is",
"None",
":",
"return",
"N",
".",
"flat",
"[",
":",
"]",
"+=",
"utils",
"... | Update the mean coordinate sums | [
"Update",
"the",
"mean",
"coordinate",
"sums"
] | python | train |
PmagPy/PmagPy | programs/dayplot_magic.py | https://github.com/PmagPy/PmagPy/blob/c7984f8809bf40fe112e53dcc311a33293b62d0b/programs/dayplot_magic.py#L12-L45 | def main():
"""
NAME
dayplot_magic.py
DESCRIPTION
makes 'day plots' (Day et al. 1977) and squareness/coercivity,
plots 'linear mixing' curve from Dunlop and Carter-Stiglitz (2006).
squareness coercivity of remanence (Neel, 1955) plots after
Tauxe et al. (2002)
... | [
"def",
"main",
"(",
")",
":",
"args",
"=",
"sys",
".",
"argv",
"if",
"\"-h\"",
"in",
"args",
":",
"print",
"(",
"main",
".",
"__doc__",
")",
"sys",
".",
"exit",
"(",
")",
"dir_path",
"=",
"pmag",
".",
"get_named_arg",
"(",
"'-WD'",
",",
"'.'",
")... | NAME
dayplot_magic.py
DESCRIPTION
makes 'day plots' (Day et al. 1977) and squareness/coercivity,
plots 'linear mixing' curve from Dunlop and Carter-Stiglitz (2006).
squareness coercivity of remanence (Neel, 1955) plots after
Tauxe et al. (2002)
SYNTAX
dayplo... | [
"NAME",
"dayplot_magic",
".",
"py"
] | python | train |
fracpete/python-weka-wrapper3 | python/weka/core/typeconv.py | https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/core/typeconv.py#L25-L39 | def string_array_to_list(a):
"""
Turns the Java string array into Python unicode string list.
:param a: the string array to convert
:type a: JB_Object
:return: the string list
:rtype: list
"""
result = []
length = javabridge.get_env().get_array_length(a)
wrapped = javabridge.get... | [
"def",
"string_array_to_list",
"(",
"a",
")",
":",
"result",
"=",
"[",
"]",
"length",
"=",
"javabridge",
".",
"get_env",
"(",
")",
".",
"get_array_length",
"(",
"a",
")",
"wrapped",
"=",
"javabridge",
".",
"get_env",
"(",
")",
".",
"get_object_array_elemen... | Turns the Java string array into Python unicode string list.
:param a: the string array to convert
:type a: JB_Object
:return: the string list
:rtype: list | [
"Turns",
"the",
"Java",
"string",
"array",
"into",
"Python",
"unicode",
"string",
"list",
"."
] | python | train |
dariosky/wfcli | wfcli/tossl.py | https://github.com/dariosky/wfcli/blob/87a9ed30dbd456f801135a55099f0541b0614ccb/wfcli/tossl.py#L76-L88 | def get_affected_domains(self):
""" Return a list of all affected domain and subdomains """
results = set()
dotted_domain = ("." + self.domain) if self.domain else None
for website in self.websites:
for subdomain in website['subdomains']:
if self.domain is Non... | [
"def",
"get_affected_domains",
"(",
"self",
")",
":",
"results",
"=",
"set",
"(",
")",
"dotted_domain",
"=",
"(",
"\".\"",
"+",
"self",
".",
"domain",
")",
"if",
"self",
".",
"domain",
"else",
"None",
"for",
"website",
"in",
"self",
".",
"websites",
":... | Return a list of all affected domain and subdomains | [
"Return",
"a",
"list",
"of",
"all",
"affected",
"domain",
"and",
"subdomains"
] | python | train |
agoragames/haigha | haigha/channel.py | https://github.com/agoragames/haigha/blob/7b004e1c0316ec14b94fec1c54554654c38b1a25/haigha/channel.py#L214-L224 | def dispatch(self, method_frame):
'''
Dispatch a method.
'''
klass = self._class_map.get(method_frame.class_id)
if klass:
klass.dispatch(method_frame)
else:
raise Channel.InvalidClass(
"class %d is not supported on channel %d",
... | [
"def",
"dispatch",
"(",
"self",
",",
"method_frame",
")",
":",
"klass",
"=",
"self",
".",
"_class_map",
".",
"get",
"(",
"method_frame",
".",
"class_id",
")",
"if",
"klass",
":",
"klass",
".",
"dispatch",
"(",
"method_frame",
")",
"else",
":",
"raise",
... | Dispatch a method. | [
"Dispatch",
"a",
"method",
"."
] | python | train |
leonidessaguisagjr/unicodeutil | unicodeutil/hangulutil.py | https://github.com/leonidessaguisagjr/unicodeutil/blob/c25c882cf9cb38c123df49fad365be67e5818928/unicodeutil/hangulutil.py#L126-L167 | def compose_hangul_syllable(jamo):
"""
Function for taking a tuple or list of Unicode scalar values representing Jamo and composing it into a Hangul
syllable. If the values in the list or tuple passed in are not in the ranges of Jamo, a ValueError will be raised.
The algorithm for doing the compositio... | [
"def",
"compose_hangul_syllable",
"(",
"jamo",
")",
":",
"fmt_str_invalid_sequence",
"=",
"\"{0} does not represent a valid sequence of Jamo!\"",
"if",
"len",
"(",
"jamo",
")",
"==",
"3",
":",
"l_part",
",",
"v_part",
",",
"t_part",
"=",
"jamo",
"if",
"not",
"(",
... | Function for taking a tuple or list of Unicode scalar values representing Jamo and composing it into a Hangul
syllable. If the values in the list or tuple passed in are not in the ranges of Jamo, a ValueError will be raised.
The algorithm for doing the composition is described in the Unicode Standard, ch. 03,... | [
"Function",
"for",
"taking",
"a",
"tuple",
"or",
"list",
"of",
"Unicode",
"scalar",
"values",
"representing",
"Jamo",
"and",
"composing",
"it",
"into",
"a",
"Hangul",
"syllable",
".",
"If",
"the",
"values",
"in",
"the",
"list",
"or",
"tuple",
"passed",
"in... | python | train |
jrmontag/STLDecompose | stldecompose/forecast_funcs.py | https://github.com/jrmontag/STLDecompose/blob/f53f89dab4b13618c1cf13f88a01e3e3dc8abdec/stldecompose/forecast_funcs.py#L61-L76 | def drift(data, n=3, **kwargs):
"""The drift forecast for the next point is a linear extrapolation from the previous ``n``
points in the series.
Args:
data (np.array): Observed data, presumed to be ordered in time.
n (int): period over which to calculate linear model for extrapolation
... | [
"def",
"drift",
"(",
"data",
",",
"n",
"=",
"3",
",",
"*",
"*",
"kwargs",
")",
":",
"yi",
"=",
"data",
"[",
"-",
"n",
"]",
"yf",
"=",
"data",
"[",
"-",
"1",
"]",
"slope",
"=",
"(",
"yf",
"-",
"yi",
")",
"/",
"(",
"n",
"-",
"1",
")",
"... | The drift forecast for the next point is a linear extrapolation from the previous ``n``
points in the series.
Args:
data (np.array): Observed data, presumed to be ordered in time.
n (int): period over which to calculate linear model for extrapolation
Returns:
float: a single-val... | [
"The",
"drift",
"forecast",
"for",
"the",
"next",
"point",
"is",
"a",
"linear",
"extrapolation",
"from",
"the",
"previous",
"n",
"points",
"in",
"the",
"series",
"."
] | python | train |
arista-eosplus/pyeapi | pyeapi/api/abstract.py | https://github.com/arista-eosplus/pyeapi/blob/96a74faef1fe3bd79c4e900aed29c9956a0587d6/pyeapi/api/abstract.py#L78-L97 | def get_block(self, parent, config='running_config'):
""" Scans the config and returns a block of code
Args:
parent (str): The parent string to search the config for and
return the block
config (str): A text config string to be searched. Default
i... | [
"def",
"get_block",
"(",
"self",
",",
"parent",
",",
"config",
"=",
"'running_config'",
")",
":",
"try",
":",
"parent",
"=",
"r'^%s$'",
"%",
"parent",
"return",
"self",
".",
"node",
".",
"section",
"(",
"parent",
",",
"config",
"=",
"config",
")",
"exc... | Scans the config and returns a block of code
Args:
parent (str): The parent string to search the config for and
return the block
config (str): A text config string to be searched. Default
is to search the running-config of the Node.
Returns:
... | [
"Scans",
"the",
"config",
"and",
"returns",
"a",
"block",
"of",
"code"
] | python | train |
androguard/androguard | androguard/core/bytecodes/dvm.py | https://github.com/androguard/androguard/blob/984c0d981be2950cf0451e484f7b0d4d53bc4911/androguard/core/bytecodes/dvm.py#L4089-L4093 | def show(self, idx):
"""
Print the instruction
"""
print(self.get_name() + " " + self.get_output(idx), end=' ') | [
"def",
"show",
"(",
"self",
",",
"idx",
")",
":",
"print",
"(",
"self",
".",
"get_name",
"(",
")",
"+",
"\" \"",
"+",
"self",
".",
"get_output",
"(",
"idx",
")",
",",
"end",
"=",
"' '",
")"
] | Print the instruction | [
"Print",
"the",
"instruction"
] | python | train |
da4089/simplefix | simplefix/message.py | https://github.com/da4089/simplefix/blob/10f7f165a99a03467110bee69cc7c083c3531c68/simplefix/message.py#L384-L436 | def append_tz_time_only_parts(self, tag, h, m, s=None, ms=None, us=None,
offset=0, header=False):
"""Append a field with a TZTimeOnly value from components.
:param tag: Integer or string FIX tag number.
:param h: Hours, in range 0 to 23.
:param m: Minut... | [
"def",
"append_tz_time_only_parts",
"(",
"self",
",",
"tag",
",",
"h",
",",
"m",
",",
"s",
"=",
"None",
",",
"ms",
"=",
"None",
",",
"us",
"=",
"None",
",",
"offset",
"=",
"0",
",",
"header",
"=",
"False",
")",
":",
"ih",
"=",
"int",
"(",
"h",
... | Append a field with a TZTimeOnly value from components.
:param tag: Integer or string FIX tag number.
:param h: Hours, in range 0 to 23.
:param m: Minutes, in range 0 to 59.
:param s: Optional seconds, in range 0 to 59 (60 for leap second).
:param ms: Optional milliseconds, in r... | [
"Append",
"a",
"field",
"with",
"a",
"TZTimeOnly",
"value",
"from",
"components",
"."
] | python | train |
waqasbhatti/astrobase | astrobase/lcproc/awsrun.py | https://github.com/waqasbhatti/astrobase/blob/2922a14619d183fb28005fa7d02027ac436f2265/astrobase/lcproc/awsrun.py#L194-L225 | def cache_clean_handler(min_age_hours=1):
"""This periodically cleans up the ~/.astrobase cache to save us from
disk-space doom.
Parameters
----------
min_age_hours : int
Files older than this number of hours from the current time will be
deleted.
Returns
-------
Noth... | [
"def",
"cache_clean_handler",
"(",
"min_age_hours",
"=",
"1",
")",
":",
"# find the files to delete",
"cmd",
"=",
"(",
"\"find ~ec2-user/.astrobase -type f -mmin +{mmin} -exec rm -v '{{}}' \\;\"",
")",
"mmin",
"=",
"'%.1f'",
"%",
"(",
"min_age_hours",
"*",
"60.0",
")",
... | This periodically cleans up the ~/.astrobase cache to save us from
disk-space doom.
Parameters
----------
min_age_hours : int
Files older than this number of hours from the current time will be
deleted.
Returns
-------
Nothing. | [
"This",
"periodically",
"cleans",
"up",
"the",
"~",
"/",
".",
"astrobase",
"cache",
"to",
"save",
"us",
"from",
"disk",
"-",
"space",
"doom",
"."
] | python | valid |
blockstack/blockstack-core | blockstack/lib/snv.py | https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/snv.py#L58-L68 | def get_bitcoind_client():
"""
Connect to the bitcoind node
"""
bitcoind_opts = get_bitcoin_opts()
bitcoind_host = bitcoind_opts['bitcoind_server']
bitcoind_port = bitcoind_opts['bitcoind_port']
bitcoind_user = bitcoind_opts['bitcoind_user']
bitcoind_passwd = bitcoind_opts['bitcoind_pass... | [
"def",
"get_bitcoind_client",
"(",
")",
":",
"bitcoind_opts",
"=",
"get_bitcoin_opts",
"(",
")",
"bitcoind_host",
"=",
"bitcoind_opts",
"[",
"'bitcoind_server'",
"]",
"bitcoind_port",
"=",
"bitcoind_opts",
"[",
"'bitcoind_port'",
"]",
"bitcoind_user",
"=",
"bitcoind_o... | Connect to the bitcoind node | [
"Connect",
"to",
"the",
"bitcoind",
"node"
] | python | train |
tanghaibao/goatools | goatools/rpt/nts_xfrm.py | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/rpt/nts_xfrm.py#L15-L20 | def get_set(self, fieldname):
"""Get all study items (e.g., geneids)."""
set_items = set()
for ntdata in self.nts:
set_items |= getattr(ntdata, fieldname)
return set_items | [
"def",
"get_set",
"(",
"self",
",",
"fieldname",
")",
":",
"set_items",
"=",
"set",
"(",
")",
"for",
"ntdata",
"in",
"self",
".",
"nts",
":",
"set_items",
"|=",
"getattr",
"(",
"ntdata",
",",
"fieldname",
")",
"return",
"set_items"
] | Get all study items (e.g., geneids). | [
"Get",
"all",
"study",
"items",
"(",
"e",
".",
"g",
".",
"geneids",
")",
"."
] | python | train |
casebeer/factual | factual/v2/requests.py | https://github.com/casebeer/factual/blob/f2795a8c9fd447c5d62887ae0f960481ce13be84/factual/v2/requests.py#L13-L15 | def within(self, lat, lon, radius):
'''Convenience method to apply a $loc/$within/$center filter. Radius is in meters.'''
return self.filter(filter_helpers.within_(lat, lon, radius)) | [
"def",
"within",
"(",
"self",
",",
"lat",
",",
"lon",
",",
"radius",
")",
":",
"return",
"self",
".",
"filter",
"(",
"filter_helpers",
".",
"within_",
"(",
"lat",
",",
"lon",
",",
"radius",
")",
")"
] | Convenience method to apply a $loc/$within/$center filter. Radius is in meters. | [
"Convenience",
"method",
"to",
"apply",
"a",
"$loc",
"/",
"$within",
"/",
"$center",
"filter",
".",
"Radius",
"is",
"in",
"meters",
"."
] | python | train |
tensorpack/tensorpack | examples/FasterRCNN/dataset.py | https://github.com/tensorpack/tensorpack/blob/d7a13cb74c9066bc791d7aafc3b744b60ee79a9f/examples/FasterRCNN/dataset.py#L49-L75 | def print_coco_metrics(self, json_file):
"""
Args:
json_file (str): path to the results json file in coco format
Returns:
dict: the evaluation metrics
"""
from pycocotools.cocoeval import COCOeval
ret = {}
cocoDt = self.coco.loadRes(json_fi... | [
"def",
"print_coco_metrics",
"(",
"self",
",",
"json_file",
")",
":",
"from",
"pycocotools",
".",
"cocoeval",
"import",
"COCOeval",
"ret",
"=",
"{",
"}",
"cocoDt",
"=",
"self",
".",
"coco",
".",
"loadRes",
"(",
"json_file",
")",
"cocoEval",
"=",
"COCOeval"... | Args:
json_file (str): path to the results json file in coco format
Returns:
dict: the evaluation metrics | [
"Args",
":",
"json_file",
"(",
"str",
")",
":",
"path",
"to",
"the",
"results",
"json",
"file",
"in",
"coco",
"format",
"Returns",
":",
"dict",
":",
"the",
"evaluation",
"metrics"
] | python | train |
spyder-ide/spyder | spyder/plugins/editor/utils/editor.py | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/editor/utils/editor.py#L342-L354 | def set_line_text(self, line_nbr, new_text):
"""
Replace an entire line with ``new_text``.
:param line_nbr: line number of the line to change.
:param new_text: The replacement text.
"""
editor = self._editor
text_cursor = self._move_cursor_to(line_nbr)
t... | [
"def",
"set_line_text",
"(",
"self",
",",
"line_nbr",
",",
"new_text",
")",
":",
"editor",
"=",
"self",
".",
"_editor",
"text_cursor",
"=",
"self",
".",
"_move_cursor_to",
"(",
"line_nbr",
")",
"text_cursor",
".",
"select",
"(",
"text_cursor",
".",
"LineUnde... | Replace an entire line with ``new_text``.
:param line_nbr: line number of the line to change.
:param new_text: The replacement text. | [
"Replace",
"an",
"entire",
"line",
"with",
"new_text",
"."
] | python | train |
ubccr/pinky | pinky/perception/cycle.py | https://github.com/ubccr/pinky/blob/e9d6e8ff72aa7f670b591e3bd3629cb879db1a93/pinky/perception/cycle.py#L77-L91 | def set_aromatic(self):
"""set the cycle to be an aromatic ring"""
#XXX FIX ME
# this probably shouldn't be here
for atom in self.atoms:
atom.aromatic = 1
for bond in self.bonds:
bond.aromatic = 1
bond.bondorder = 1.5
b... | [
"def",
"set_aromatic",
"(",
"self",
")",
":",
"#XXX FIX ME",
"# this probably shouldn't be here",
"for",
"atom",
"in",
"self",
".",
"atoms",
":",
"atom",
".",
"aromatic",
"=",
"1",
"for",
"bond",
"in",
"self",
".",
"bonds",
":",
"bond",
".",
"aromatic",
"=... | set the cycle to be an aromatic ring | [
"set",
"the",
"cycle",
"to",
"be",
"an",
"aromatic",
"ring"
] | python | train |
googleads/googleads-python-lib | examples/adwords/adwords_appengine_demo/handlers/api_handler.py | https://github.com/googleads/googleads-python-lib/blob/aa3b1b474b0f9789ca55ca46f4b2b57aeae38874/examples/adwords/adwords_appengine_demo/handlers/api_handler.py#L150-L181 | def GetAdGroups(self, client_customer_id, campaign_id):
"""Retrieves all AdGroups for the given campaign that haven't been removed.
Args:
client_customer_id: str Client Customer Id being used in API request.
campaign_id: str id of the campaign for which to fetch ad groups.
Returns:
list ... | [
"def",
"GetAdGroups",
"(",
"self",
",",
"client_customer_id",
",",
"campaign_id",
")",
":",
"self",
".",
"client",
".",
"SetClientCustomerId",
"(",
"client_customer_id",
")",
"selector",
"=",
"{",
"'fields'",
":",
"[",
"'Id'",
",",
"'Name'",
",",
"'Status'",
... | Retrieves all AdGroups for the given campaign that haven't been removed.
Args:
client_customer_id: str Client Customer Id being used in API request.
campaign_id: str id of the campaign for which to fetch ad groups.
Returns:
list List of AdGroup data objects. | [
"Retrieves",
"all",
"AdGroups",
"for",
"the",
"given",
"campaign",
"that",
"haven",
"t",
"been",
"removed",
"."
] | python | train |
fitnr/convertdate | convertdate/french_republican.py | https://github.com/fitnr/convertdate/blob/e920f168a87f99183b0aa7290d6c3af222582d43/convertdate/french_republican.py#L81-L95 | def premier_da_la_annee(jd):
'''Determine the year in the French revolutionary calendar in which a given Julian day falls.
Returns Julian day number containing fall equinox (first day of the FR year)'''
p = ephem.previous_fall_equinox(dublin.from_jd(jd))
previous = trunc(dublin.to_jd(p) - 0.5) + 0.5
... | [
"def",
"premier_da_la_annee",
"(",
"jd",
")",
":",
"p",
"=",
"ephem",
".",
"previous_fall_equinox",
"(",
"dublin",
".",
"from_jd",
"(",
"jd",
")",
")",
"previous",
"=",
"trunc",
"(",
"dublin",
".",
"to_jd",
"(",
"p",
")",
"-",
"0.5",
")",
"+",
"0.5",... | Determine the year in the French revolutionary calendar in which a given Julian day falls.
Returns Julian day number containing fall equinox (first day of the FR year) | [
"Determine",
"the",
"year",
"in",
"the",
"French",
"revolutionary",
"calendar",
"in",
"which",
"a",
"given",
"Julian",
"day",
"falls",
".",
"Returns",
"Julian",
"day",
"number",
"containing",
"fall",
"equinox",
"(",
"first",
"day",
"of",
"the",
"FR",
"year",... | python | train |
cole/aiosmtplib | src/aiosmtplib/esmtp.py | https://github.com/cole/aiosmtplib/blob/0cd00e5059005371cbdfca995feff9183a16a51f/src/aiosmtplib/esmtp.py#L189-L210 | async def expn(
self, address: str, timeout: DefaultNumType = _default
) -> SMTPResponse:
"""
Send an SMTP EXPN command, which expands a mailing list.
Not many servers support this command.
:raises SMTPResponseException: on unexpected server response code
"""
... | [
"async",
"def",
"expn",
"(",
"self",
",",
"address",
":",
"str",
",",
"timeout",
":",
"DefaultNumType",
"=",
"_default",
")",
"->",
"SMTPResponse",
":",
"await",
"self",
".",
"_ehlo_or_helo_if_needed",
"(",
")",
"parsed_address",
"=",
"parse_address",
"(",
"... | Send an SMTP EXPN command, which expands a mailing list.
Not many servers support this command.
:raises SMTPResponseException: on unexpected server response code | [
"Send",
"an",
"SMTP",
"EXPN",
"command",
"which",
"expands",
"a",
"mailing",
"list",
".",
"Not",
"many",
"servers",
"support",
"this",
"command",
"."
] | python | train |
HewlettPackard/python-hpOneView | hpOneView/oneview_client.py | https://github.com/HewlettPackard/python-hpOneView/blob/3c6219723ef25e6e0c83d44a89007f89bc325b89/hpOneView/oneview_client.py#L519-L528 | def id_pools(self):
"""
Gets the IdPools API client.
Returns:
IdPools:
"""
if not self.__id_pools:
self.__id_pools = IdPools(self.__connection)
return self.__id_pools | [
"def",
"id_pools",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"__id_pools",
":",
"self",
".",
"__id_pools",
"=",
"IdPools",
"(",
"self",
".",
"__connection",
")",
"return",
"self",
".",
"__id_pools"
] | Gets the IdPools API client.
Returns:
IdPools: | [
"Gets",
"the",
"IdPools",
"API",
"client",
"."
] | python | train |
collectiveacuity/labPack | labpack/events/meetup.py | https://github.com/collectiveacuity/labPack/blob/52949ece35e72e3cc308f54d9ffa6bfbd96805b8/labpack/events/meetup.py#L1082-L1134 | def get_member_brief(self, member_id=0):
''' a method to retrieve member profile info
:param member_id: [optional] integer with member id from member profile
:return: dictionary with member profile inside [json] key
member_profile = self.objects.profile_brief.schema
''... | [
"def",
"get_member_brief",
"(",
"self",
",",
"member_id",
"=",
"0",
")",
":",
"# https://www.meetup.com/meetup_api/docs/members/:member_id/#get\r",
"title",
"=",
"'%s.get_member_brief'",
"%",
"self",
".",
"__class__",
".",
"__name__",
"# validate inputs\r",
"input_fields",
... | a method to retrieve member profile info
:param member_id: [optional] integer with member id from member profile
:return: dictionary with member profile inside [json] key
member_profile = self.objects.profile_brief.schema | [
"a",
"method",
"to",
"retrieve",
"member",
"profile",
"info",
":",
"param",
"member_id",
":",
"[",
"optional",
"]",
"integer",
"with",
"member",
"id",
"from",
"member",
"profile",
":",
"return",
":",
"dictionary",
"with",
"member",
"profile",
"inside",
"[",
... | python | train |
marcomusy/vtkplotter | vtkplotter/shapes.py | https://github.com/marcomusy/vtkplotter/blob/692c3396782722ec525bc1346a26999868c650c6/vtkplotter/shapes.py#L948-L980 | def Plane(pos=(0, 0, 0), normal=(0, 0, 1), sx=1, sy=None, c="g", bc="darkgreen",
alpha=1, texture=None):
"""
Draw a plane of size `sx` and `sy` oriented perpendicular to vector `normal`
and so that it passes through point `pos`.
|Plane|
"""
if sy is None:
sy = sx
ps = vtk... | [
"def",
"Plane",
"(",
"pos",
"=",
"(",
"0",
",",
"0",
",",
"0",
")",
",",
"normal",
"=",
"(",
"0",
",",
"0",
",",
"1",
")",
",",
"sx",
"=",
"1",
",",
"sy",
"=",
"None",
",",
"c",
"=",
"\"g\"",
",",
"bc",
"=",
"\"darkgreen\"",
",",
"alpha",... | Draw a plane of size `sx` and `sy` oriented perpendicular to vector `normal`
and so that it passes through point `pos`.
|Plane| | [
"Draw",
"a",
"plane",
"of",
"size",
"sx",
"and",
"sy",
"oriented",
"perpendicular",
"to",
"vector",
"normal",
"and",
"so",
"that",
"it",
"passes",
"through",
"point",
"pos",
"."
] | python | train |
bitesofcode/projexui | projexui/widgets/xmultitagedit.py | https://github.com/bitesofcode/projexui/blob/f18a73bec84df90b034ca69b9deea118dbedfc4d/projexui/widgets/xmultitagedit.py#L79-L97 | def createEditor( self, parent, option, index ):
"""
Overloads the create editor method to assign the parent's completer to
any line edit created.
:param parent | <QWidget>
option | <QStyleOption>
index | <QModelIndex>
... | [
"def",
"createEditor",
"(",
"self",
",",
"parent",
",",
"option",
",",
"index",
")",
":",
"multi_tag",
"=",
"projexui",
".",
"ancestor",
"(",
"self",
",",
"XMultiTagEdit",
")",
"edit",
"=",
"QLineEdit",
"(",
"parent",
")",
"edit",
".",
"setFrame",
"(",
... | Overloads the create editor method to assign the parent's completer to
any line edit created.
:param parent | <QWidget>
option | <QStyleOption>
index | <QModelIndex>
:return <QWidget> || None | [
"Overloads",
"the",
"create",
"editor",
"method",
"to",
"assign",
"the",
"parent",
"s",
"completer",
"to",
"any",
"line",
"edit",
"created",
".",
":",
"param",
"parent",
"|",
"<QWidget",
">",
"option",
"|",
"<QStyleOption",
">",
"index",
"|",
"<QModelIndex",... | python | train |
ForensicArtifacts/artifacts | artifacts/source_type.py | https://github.com/ForensicArtifacts/artifacts/blob/044a63bfb4448af33d085c69066c80f9505ae7ca/artifacts/source_type.py#L460-L478 | def RegisterSourceType(cls, source_type_class):
"""Registers a source type.
Source types are identified based on their type indicator.
Args:
source_type_class (type): source type.
Raises:
KeyError: if source types is already set for the corresponding
type indicator.
"""
... | [
"def",
"RegisterSourceType",
"(",
"cls",
",",
"source_type_class",
")",
":",
"if",
"source_type_class",
".",
"TYPE_INDICATOR",
"in",
"cls",
".",
"_source_type_classes",
":",
"raise",
"KeyError",
"(",
"'Source type already set for type: {0:s}.'",
".",
"format",
"(",
"s... | Registers a source type.
Source types are identified based on their type indicator.
Args:
source_type_class (type): source type.
Raises:
KeyError: if source types is already set for the corresponding
type indicator. | [
"Registers",
"a",
"source",
"type",
"."
] | python | train |
foremast/gogo-utils | src/gogoutils/generator.py | https://github.com/foremast/gogo-utils/blob/3909c2d26e49baa8ad68e6be40977d4370d7c1ca/src/gogoutils/generator.py#L161-L168 | def archaius(self):
"""Generate archaius bucket path."""
bucket = self.format['s3_bucket'].format(**self.data)
path = self.format['s3_bucket_path'].format(**self.data)
archaius_name = self.format['s3_archaius_name'].format(**self.data)
archaius = {'s3': archaius_name, 'bucket': b... | [
"def",
"archaius",
"(",
"self",
")",
":",
"bucket",
"=",
"self",
".",
"format",
"[",
"'s3_bucket'",
"]",
".",
"format",
"(",
"*",
"*",
"self",
".",
"data",
")",
"path",
"=",
"self",
".",
"format",
"[",
"'s3_bucket_path'",
"]",
".",
"format",
"(",
"... | Generate archaius bucket path. | [
"Generate",
"archaius",
"bucket",
"path",
"."
] | python | train |
alerta/python-alerta-client | alertaclient/commands/cmd_signup.py | https://github.com/alerta/python-alerta-client/blob/7eb367b5fe87d5fc20b54dea8cddd7f09e251afa/alertaclient/commands/cmd_signup.py#L15-L30 | def cli(obj, name, email, password, status, text):
"""Create new Basic Auth user."""
client = obj['client']
if not email:
raise click.UsageError('Need "--email" to sign-up new user.')
if not password:
raise click.UsageError('Need "--password" to sign-up new user.')
try:
r = c... | [
"def",
"cli",
"(",
"obj",
",",
"name",
",",
"email",
",",
"password",
",",
"status",
",",
"text",
")",
":",
"client",
"=",
"obj",
"[",
"'client'",
"]",
"if",
"not",
"email",
":",
"raise",
"click",
".",
"UsageError",
"(",
"'Need \"--email\" to sign-up new... | Create new Basic Auth user. | [
"Create",
"new",
"Basic",
"Auth",
"user",
"."
] | python | train |
PyCQA/pylint | pylint/checkers/variables.py | https://github.com/PyCQA/pylint/blob/2bf5c61a3ff6ae90613b81679de42c0f19aea600/pylint/checkers/variables.py#L192-L232 | def _fix_dot_imports(not_consumed):
""" Try to fix imports with multiple dots, by returning a dictionary
with the import names expanded. The function unflattens root imports,
like 'xml' (when we have both 'xml.etree' and 'xml.sax'), to 'xml.etree'
and 'xml.sax' respectively.
"""
# TODO: this sho... | [
"def",
"_fix_dot_imports",
"(",
"not_consumed",
")",
":",
"# TODO: this should be improved in issue astroid #46",
"names",
"=",
"{",
"}",
"for",
"name",
",",
"stmts",
"in",
"not_consumed",
".",
"items",
"(",
")",
":",
"if",
"any",
"(",
"isinstance",
"(",
"stmt",... | Try to fix imports with multiple dots, by returning a dictionary
with the import names expanded. The function unflattens root imports,
like 'xml' (when we have both 'xml.etree' and 'xml.sax'), to 'xml.etree'
and 'xml.sax' respectively. | [
"Try",
"to",
"fix",
"imports",
"with",
"multiple",
"dots",
"by",
"returning",
"a",
"dictionary",
"with",
"the",
"import",
"names",
"expanded",
".",
"The",
"function",
"unflattens",
"root",
"imports",
"like",
"xml",
"(",
"when",
"we",
"have",
"both",
"xml",
... | python | test |
tensorpack/tensorpack | examples/FasterRCNN/eval.py | https://github.com/tensorpack/tensorpack/blob/d7a13cb74c9066bc791d7aafc3b744b60ee79a9f/examples/FasterRCNN/eval.py#L108-L146 | def predict_dataflow(df, model_func, tqdm_bar=None):
"""
Args:
df: a DataFlow which produces (image, image_id)
model_func: a callable from the TF model.
It takes image and returns (boxes, probs, labels, [masks])
tqdm_bar: a tqdm object to be shared among multiple evaluation i... | [
"def",
"predict_dataflow",
"(",
"df",
",",
"model_func",
",",
"tqdm_bar",
"=",
"None",
")",
":",
"df",
".",
"reset_state",
"(",
")",
"all_results",
"=",
"[",
"]",
"with",
"ExitStack",
"(",
")",
"as",
"stack",
":",
"# tqdm is not quite thread-safe: https://gith... | Args:
df: a DataFlow which produces (image, image_id)
model_func: a callable from the TF model.
It takes image and returns (boxes, probs, labels, [masks])
tqdm_bar: a tqdm object to be shared among multiple evaluation instances. If None,
will create a new one.
Return... | [
"Args",
":",
"df",
":",
"a",
"DataFlow",
"which",
"produces",
"(",
"image",
"image_id",
")",
"model_func",
":",
"a",
"callable",
"from",
"the",
"TF",
"model",
".",
"It",
"takes",
"image",
"and",
"returns",
"(",
"boxes",
"probs",
"labels",
"[",
"masks",
... | python | train |
opendatateam/udata | udata/frontend/csv.py | https://github.com/opendatateam/udata/blob/f016585af94b0ff6bd73738c700324adc8ba7f8f/udata/frontend/csv.py#L114-L117 | def header(self):
'''Generate the CSV header row'''
return (super(NestedAdapter, self).header() +
[name for name, getter in self.get_nested_fields()]) | [
"def",
"header",
"(",
"self",
")",
":",
"return",
"(",
"super",
"(",
"NestedAdapter",
",",
"self",
")",
".",
"header",
"(",
")",
"+",
"[",
"name",
"for",
"name",
",",
"getter",
"in",
"self",
".",
"get_nested_fields",
"(",
")",
"]",
")"
] | Generate the CSV header row | [
"Generate",
"the",
"CSV",
"header",
"row"
] | python | train |
mbr/flask-kvsession | flask_kvsession/__init__.py | https://github.com/mbr/flask-kvsession/blob/83238b74d4e4d2ffbdfd65c1c0a00ceb4bdfd9fa/flask_kvsession/__init__.py#L60-L67 | def unserialize(cls, string):
"""Unserializes from a string.
:param string: A string created by :meth:`serialize`.
"""
id_s, created_s = string.split('_')
return cls(int(id_s, 16),
datetime.utcfromtimestamp(int(created_s, 16))) | [
"def",
"unserialize",
"(",
"cls",
",",
"string",
")",
":",
"id_s",
",",
"created_s",
"=",
"string",
".",
"split",
"(",
"'_'",
")",
"return",
"cls",
"(",
"int",
"(",
"id_s",
",",
"16",
")",
",",
"datetime",
".",
"utcfromtimestamp",
"(",
"int",
"(",
... | Unserializes from a string.
:param string: A string created by :meth:`serialize`. | [
"Unserializes",
"from",
"a",
"string",
"."
] | python | train |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/dialects/v20/ardupilotmega.py | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/dialects/v20/ardupilotmega.py#L9951-L9962 | def mount_status_send(self, target_system, target_component, pointing_a, pointing_b, pointing_c, force_mavlink1=False):
'''
Message with some status from APM to GCS about camera or antenna mount
target_system : System ID (uint8_t)
target_compo... | [
"def",
"mount_status_send",
"(",
"self",
",",
"target_system",
",",
"target_component",
",",
"pointing_a",
",",
"pointing_b",
",",
"pointing_c",
",",
"force_mavlink1",
"=",
"False",
")",
":",
"return",
"self",
".",
"send",
"(",
"self",
".",
"mount_status_encode"... | Message with some status from APM to GCS about camera or antenna mount
target_system : System ID (uint8_t)
target_component : Component ID (uint8_t)
pointing_a : pitch(deg*100) (int32_t)
pointing_b : roll... | [
"Message",
"with",
"some",
"status",
"from",
"APM",
"to",
"GCS",
"about",
"camera",
"or",
"antenna",
"mount"
] | python | train |
googleapis/google-cloud-python | bigtable/google/cloud/bigtable_admin_v2/gapic/bigtable_table_admin_client.py | https://github.com/googleapis/google-cloud-python/blob/85e80125a59cb10f8cb105f25ecc099e4b940b50/bigtable/google/cloud/bigtable_admin_v2/gapic/bigtable_table_admin_client.py#L231-L339 | def create_table(
self,
parent,
table_id,
table,
initial_splits=None,
retry=google.api_core.gapic_v1.method.DEFAULT,
timeout=google.api_core.gapic_v1.method.DEFAULT,
metadata=None,
):
"""
Creates a new table in the specified instance.
... | [
"def",
"create_table",
"(",
"self",
",",
"parent",
",",
"table_id",
",",
"table",
",",
"initial_splits",
"=",
"None",
",",
"retry",
"=",
"google",
".",
"api_core",
".",
"gapic_v1",
".",
"method",
".",
"DEFAULT",
",",
"timeout",
"=",
"google",
".",
"api_c... | Creates a new table in the specified instance.
The table can be created with a full set of initial column families,
specified in the request.
Example:
>>> from google.cloud import bigtable_admin_v2
>>>
>>> client = bigtable_admin_v2.BigtableTableAdminClient()... | [
"Creates",
"a",
"new",
"table",
"in",
"the",
"specified",
"instance",
".",
"The",
"table",
"can",
"be",
"created",
"with",
"a",
"full",
"set",
"of",
"initial",
"column",
"families",
"specified",
"in",
"the",
"request",
"."
] | python | train |
inasafe/inasafe | safe/gui/tools/wizard/step_fc20_hazlayer_from_canvas.py | https://github.com/inasafe/inasafe/blob/831d60abba919f6d481dc94a8d988cc205130724/safe/gui/tools/wizard/step_fc20_hazlayer_from_canvas.py#L72-L90 | def selected_canvas_hazlayer(self):
"""Obtain the canvas layer selected by user.
:returns: The currently selected map layer in the list.
:rtype: QgsMapLayer
"""
if self.lstCanvasHazLayers.selectedItems():
item = self.lstCanvasHazLayers.currentItem()
else:
... | [
"def",
"selected_canvas_hazlayer",
"(",
"self",
")",
":",
"if",
"self",
".",
"lstCanvasHazLayers",
".",
"selectedItems",
"(",
")",
":",
"item",
"=",
"self",
".",
"lstCanvasHazLayers",
".",
"currentItem",
"(",
")",
"else",
":",
"return",
"None",
"try",
":",
... | Obtain the canvas layer selected by user.
:returns: The currently selected map layer in the list.
:rtype: QgsMapLayer | [
"Obtain",
"the",
"canvas",
"layer",
"selected",
"by",
"user",
"."
] | python | train |
hubo1016/vlcp | vlcp/utils/connector.py | https://github.com/hubo1016/vlcp/blob/239055229ec93a99cc7e15208075724ccf543bd1/vlcp/utils/connector.py#L474-L482 | async def run_async_task(self, container, asynctask, newthread = True):
"Run asynctask(sender) in task pool, call sender(events) to send customized events, return result"
e = TaskEvent(self, async_task = asynctask, newthread = newthread)
await container.wait_for_send(e)
ev = await TaskDo... | [
"async",
"def",
"run_async_task",
"(",
"self",
",",
"container",
",",
"asynctask",
",",
"newthread",
"=",
"True",
")",
":",
"e",
"=",
"TaskEvent",
"(",
"self",
",",
"async_task",
"=",
"asynctask",
",",
"newthread",
"=",
"newthread",
")",
"await",
"containe... | Run asynctask(sender) in task pool, call sender(events) to send customized events, return result | [
"Run",
"asynctask",
"(",
"sender",
")",
"in",
"task",
"pool",
"call",
"sender",
"(",
"events",
")",
"to",
"send",
"customized",
"events",
"return",
"result"
] | python | train |
KrzyHonk/bpmn-python | bpmn_python/bpmn_diagram_rep.py | https://github.com/KrzyHonk/bpmn-python/blob/6e5e28e3d656dbf5bd3d85d78fe8e3f2fb462629/bpmn_python/bpmn_diagram_rep.py#L105-L120 | def get_nodes(self, node_type=""):
"""
Gets all nodes of requested type. If no type is provided by user, all nodes in BPMN diagram graph are returned.
Returns a dictionary, where key is an ID of node, value is a dictionary of all node attributes.
:param node_type: string with valid BPMN... | [
"def",
"get_nodes",
"(",
"self",
",",
"node_type",
"=",
"\"\"",
")",
":",
"tmp_nodes",
"=",
"self",
".",
"diagram_graph",
".",
"nodes",
"(",
"True",
")",
"if",
"node_type",
"==",
"\"\"",
":",
"return",
"tmp_nodes",
"else",
":",
"nodes",
"=",
"[",
"]",
... | Gets all nodes of requested type. If no type is provided by user, all nodes in BPMN diagram graph are returned.
Returns a dictionary, where key is an ID of node, value is a dictionary of all node attributes.
:param node_type: string with valid BPMN XML tag name (e.g. 'task', 'sequenceFlow'). | [
"Gets",
"all",
"nodes",
"of",
"requested",
"type",
".",
"If",
"no",
"type",
"is",
"provided",
"by",
"user",
"all",
"nodes",
"in",
"BPMN",
"diagram",
"graph",
"are",
"returned",
".",
"Returns",
"a",
"dictionary",
"where",
"key",
"is",
"an",
"ID",
"of",
... | python | train |
uber/rides-python-sdk | uber_rides/request.py | https://github.com/uber/rides-python-sdk/blob/76ecd75ab5235d792ec1010e36eca679ba285127/uber_rides/request.py#L154-L190 | def _build_headers(self, method, auth_session):
"""Create headers for the request.
Parameters
method (str)
HTTP method (e.g. 'POST').
auth_session (Session)
The Session object containing OAuth 2.0 credentials.
Returns
headers ... | [
"def",
"_build_headers",
"(",
"self",
",",
"method",
",",
"auth_session",
")",
":",
"token_type",
"=",
"auth_session",
".",
"token_type",
"if",
"auth_session",
".",
"server_token",
":",
"token",
"=",
"auth_session",
".",
"server_token",
"else",
":",
"token",
"... | Create headers for the request.
Parameters
method (str)
HTTP method (e.g. 'POST').
auth_session (Session)
The Session object containing OAuth 2.0 credentials.
Returns
headers (dict)
Dictionary of access headers to atta... | [
"Create",
"headers",
"for",
"the",
"request",
"."
] | python | train |
bububa/pyTOP | pyTOP/packages/requests/packages/urllib3/_collections.py | https://github.com/bububa/pyTOP/blob/1e48009bcfe886be392628244b370e6374e1f2b2/pyTOP/packages/requests/packages/urllib3/_collections.py#L50-L56 | def _invalidate_entry(self, key):
"If exists: Invalidate old entry and return it."
old_entry = self.access_lookup.get(key)
if old_entry:
old_entry.is_valid = False
return old_entry | [
"def",
"_invalidate_entry",
"(",
"self",
",",
"key",
")",
":",
"old_entry",
"=",
"self",
".",
"access_lookup",
".",
"get",
"(",
"key",
")",
"if",
"old_entry",
":",
"old_entry",
".",
"is_valid",
"=",
"False",
"return",
"old_entry"
] | If exists: Invalidate old entry and return it. | [
"If",
"exists",
":",
"Invalidate",
"old",
"entry",
"and",
"return",
"it",
"."
] | python | train |
SuperCowPowers/workbench | workbench/workers/pe_peid.py | https://github.com/SuperCowPowers/workbench/blob/710232756dd717f734253315e3d0b33c9628dafb/workbench/workers/pe_peid.py#L31-L43 | def execute(self, input_data):
''' Execute the PEIDWorker '''
raw_bytes = input_data['sample']['raw_bytes']
# Have the PE File module process the file
try:
pefile_handle = pefile.PE(data=raw_bytes, fast_load=False)
except (AttributeError, pefile.PEFormatError), error... | [
"def",
"execute",
"(",
"self",
",",
"input_data",
")",
":",
"raw_bytes",
"=",
"input_data",
"[",
"'sample'",
"]",
"[",
"'raw_bytes'",
"]",
"# Have the PE File module process the file",
"try",
":",
"pefile_handle",
"=",
"pefile",
".",
"PE",
"(",
"data",
"=",
"r... | Execute the PEIDWorker | [
"Execute",
"the",
"PEIDWorker"
] | python | train |
eandersson/amqpstorm | amqpstorm/management/connection.py | https://github.com/eandersson/amqpstorm/blob/38330906c0af19eea482f43c5ce79bab98a1e064/amqpstorm/management/connection.py#L32-L52 | def close(self, connection, reason='Closed via management api'):
"""Close Connection.
:param str connection: Connection name
:param str reason: Reason for closing connection.
:raises ApiError: Raises if the remote server encountered an error.
:raises ApiConnectionError: Raises ... | [
"def",
"close",
"(",
"self",
",",
"connection",
",",
"reason",
"=",
"'Closed via management api'",
")",
":",
"close_payload",
"=",
"json",
".",
"dumps",
"(",
"{",
"'name'",
":",
"connection",
",",
"'reason'",
":",
"reason",
"}",
")",
"connection",
"=",
"qu... | Close Connection.
:param str connection: Connection name
:param str reason: Reason for closing connection.
:raises ApiError: Raises if the remote server encountered an error.
:raises ApiConnectionError: Raises if there was a connectivity issue.
:rtype: None | [
"Close",
"Connection",
"."
] | python | train |
CI-WATER/gsshapy | gsshapy/modeling/framework.py | https://github.com/CI-WATER/gsshapy/blob/00fd4af0fd65f1614d75a52fe950a04fb0867f4c/gsshapy/modeling/framework.py#L29-L37 | def replace_file(from_file, to_file):
"""
Replaces to_file with from_file
"""
try:
os.remove(to_file)
except OSError:
pass
copy(from_file, to_file) | [
"def",
"replace_file",
"(",
"from_file",
",",
"to_file",
")",
":",
"try",
":",
"os",
".",
"remove",
"(",
"to_file",
")",
"except",
"OSError",
":",
"pass",
"copy",
"(",
"from_file",
",",
"to_file",
")"
] | Replaces to_file with from_file | [
"Replaces",
"to_file",
"with",
"from_file"
] | python | train |
aviaryan/python-gsearch | gsearch/googlesearch.py | https://github.com/aviaryan/python-gsearch/blob/fba2f42fbf4c2672b72d05b53120adcb25ba8b69/gsearch/googlesearch.py#L101-L130 | def search(query, num_results=10):
"""
searches google for :query and returns a list of tuples
of the format (name, url)
"""
data = download(query, num_results)
results = re.findall(r'\<h3.*?\>.*?\<\/h3\>', data, re.IGNORECASE)
if results is None or len(results) == 0:
print('No results where found. Did the rat... | [
"def",
"search",
"(",
"query",
",",
"num_results",
"=",
"10",
")",
":",
"data",
"=",
"download",
"(",
"query",
",",
"num_results",
")",
"results",
"=",
"re",
".",
"findall",
"(",
"r'\\<h3.*?\\>.*?\\<\\/h3\\>'",
",",
"data",
",",
"re",
".",
"IGNORECASE",
... | searches google for :query and returns a list of tuples
of the format (name, url) | [
"searches",
"google",
"for",
":",
"query",
"and",
"returns",
"a",
"list",
"of",
"tuples",
"of",
"the",
"format",
"(",
"name",
"url",
")"
] | python | train |
Esri/ArcREST | src/arcrest/ags/_uploads.py | https://github.com/Esri/ArcREST/blob/ab240fde2b0200f61d4a5f6df033516e53f2f416/src/arcrest/ags/_uploads.py#L62-L91 | def upload(self, filePath, description=None):
"""
This operation uploads an item to the server. Each uploaded item is
identified by a unique itemID. Since this request uploads a file,
it must be a multi-part request as per IETF RFC1867.
All uploaded items are subjected to the del... | [
"def",
"upload",
"(",
"self",
",",
"filePath",
",",
"description",
"=",
"None",
")",
":",
"params",
"=",
"{",
"\"f\"",
":",
"\"json\"",
"}",
"if",
"description",
"is",
"not",
"None",
":",
"params",
"[",
"'description'",
"]",
"=",
"str",
"(",
"descripti... | This operation uploads an item to the server. Each uploaded item is
identified by a unique itemID. Since this request uploads a file,
it must be a multi-part request as per IETF RFC1867.
All uploaded items are subjected to the deletion rules set on the
upload directory by the administrat... | [
"This",
"operation",
"uploads",
"an",
"item",
"to",
"the",
"server",
".",
"Each",
"uploaded",
"item",
"is",
"identified",
"by",
"a",
"unique",
"itemID",
".",
"Since",
"this",
"request",
"uploads",
"a",
"file",
"it",
"must",
"be",
"a",
"multi",
"-",
"part... | python | train |
Kyria/EsiPy | esipy/security.py | https://github.com/Kyria/EsiPy/blob/06407a0218a126678f80d8a7e8a67b9729327865/esipy/security.py#L275-L292 | def update_token(self, response_json, **kwargs):
""" Update access_token, refresh_token and token_expiry from the
response body.
The response must be converted to a json object before being passed as
a parameter
:param response_json: the response body to use.
:par... | [
"def",
"update_token",
"(",
"self",
",",
"response_json",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"token_identifier",
"=",
"kwargs",
".",
"pop",
"(",
"'token_identifier'",
",",
"self",
".",
"token_identifier",
")",
"self",
".",
"access_token",
"=",
... | Update access_token, refresh_token and token_expiry from the
response body.
The response must be converted to a json object before being passed as
a parameter
:param response_json: the response body to use.
:param token_identifier: the user identifier for the token | [
"Update",
"access_token",
"refresh_token",
"and",
"token_expiry",
"from",
"the",
"response",
"body",
".",
"The",
"response",
"must",
"be",
"converted",
"to",
"a",
"json",
"object",
"before",
"being",
"passed",
"as",
"a",
"parameter",
":",
"param",
"response_json... | python | train |
Parsl/parsl | parsl/providers/aws/aws.py | https://github.com/Parsl/parsl/blob/d7afb3bc37f50dcf224ae78637944172edb35dac/parsl/providers/aws/aws.py#L434-L502 | def spin_up_instance(self, command, job_name):
"""Start an instance in the VPC in the first available subnet.
N instances will be started if nodes_per_block > 1.
Not supported. We only do 1 node per block.
Parameters
----------
command : str
Command string t... | [
"def",
"spin_up_instance",
"(",
"self",
",",
"command",
",",
"job_name",
")",
":",
"command",
"=",
"Template",
"(",
"template_string",
")",
".",
"substitute",
"(",
"jobname",
"=",
"job_name",
",",
"user_script",
"=",
"command",
",",
"linger",
"=",
"str",
"... | Start an instance in the VPC in the first available subnet.
N instances will be started if nodes_per_block > 1.
Not supported. We only do 1 node per block.
Parameters
----------
command : str
Command string to execute on the node.
job_name : str
... | [
"Start",
"an",
"instance",
"in",
"the",
"VPC",
"in",
"the",
"first",
"available",
"subnet",
"."
] | python | valid |
saltstack/salt | salt/states/boto_secgroup.py | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/states/boto_secgroup.py#L666-L761 | def _tags_present(name, tags, vpc_id=None, vpc_name=None, region=None,
key=None, keyid=None, profile=None):
'''
helper function to validate tags are correct
'''
ret = {'result': True, 'comment': '', 'changes': {}}
if tags:
sg = __salt__['boto_secgroup.get_config'](name=name... | [
"def",
"_tags_present",
"(",
"name",
",",
"tags",
",",
"vpc_id",
"=",
"None",
",",
"vpc_name",
"=",
"None",
",",
"region",
"=",
"None",
",",
"key",
"=",
"None",
",",
"keyid",
"=",
"None",
",",
"profile",
"=",
"None",
")",
":",
"ret",
"=",
"{",
"'... | helper function to validate tags are correct | [
"helper",
"function",
"to",
"validate",
"tags",
"are",
"correct"
] | python | train |
sdispater/orator | orator/orm/factory.py | https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/factory.py#L98-L111 | def register_as(self, klass, name, callback):
"""
Register a class with a function.
:param klass: The class
:type klass: class
:param callback: The callable
:type callback: callable
:param name: The short name
:type name: str
"""
return ... | [
"def",
"register_as",
"(",
"self",
",",
"klass",
",",
"name",
",",
"callback",
")",
":",
"return",
"self",
".",
"register",
"(",
"klass",
",",
"callback",
",",
"name",
")"
] | Register a class with a function.
:param klass: The class
:type klass: class
:param callback: The callable
:type callback: callable
:param name: The short name
:type name: str | [
"Register",
"a",
"class",
"with",
"a",
"function",
"."
] | python | train |
Clinical-Genomics/trailblazer | trailblazer/cli/clean.py | https://github.com/Clinical-Genomics/trailblazer/blob/27f3cd21043a1077bd7029e85783459a50a7b798/trailblazer/cli/clean.py#L14-L29 | def clean(context, days_ago, yes):
"""Clean up files from "old" analyses runs."""
number_of_days_ago = dt.datetime.now() - dt.timedelta(days=days_ago)
analyses = context.obj['store'].analyses(
status='completed',
before=number_of_days_ago,
deleted=False,
)
for analysis_obj in... | [
"def",
"clean",
"(",
"context",
",",
"days_ago",
",",
"yes",
")",
":",
"number_of_days_ago",
"=",
"dt",
".",
"datetime",
".",
"now",
"(",
")",
"-",
"dt",
".",
"timedelta",
"(",
"days",
"=",
"days_ago",
")",
"analyses",
"=",
"context",
".",
"obj",
"["... | Clean up files from "old" analyses runs. | [
"Clean",
"up",
"files",
"from",
"old",
"analyses",
"runs",
"."
] | python | train |
ivanyu/idx2numpy | idx2numpy/converters.py | https://github.com/ivanyu/idx2numpy/blob/9b88698314973226212181d1747dfad6c6974e51/idx2numpy/converters.py#L142-L149 | def convert_to_string(ndarr):
"""
Writes the contents of the numpy.ndarray ndarr to bytes in IDX format and
returns it.
"""
with contextlib.closing(BytesIO()) as bytesio:
_internal_write(bytesio, ndarr)
return bytesio.getvalue() | [
"def",
"convert_to_string",
"(",
"ndarr",
")",
":",
"with",
"contextlib",
".",
"closing",
"(",
"BytesIO",
"(",
")",
")",
"as",
"bytesio",
":",
"_internal_write",
"(",
"bytesio",
",",
"ndarr",
")",
"return",
"bytesio",
".",
"getvalue",
"(",
")"
] | Writes the contents of the numpy.ndarray ndarr to bytes in IDX format and
returns it. | [
"Writes",
"the",
"contents",
"of",
"the",
"numpy",
".",
"ndarray",
"ndarr",
"to",
"bytes",
"in",
"IDX",
"format",
"and",
"returns",
"it",
"."
] | python | train |
spacetelescope/drizzlepac | drizzlepac/wcs_functions.py | https://github.com/spacetelescope/drizzlepac/blob/15bec3c929a6a869d9e71b9398ced43ede0620f1/drizzlepac/wcs_functions.py#L170-L186 | def create_CD(orient, scale, cx=None, cy=None):
""" Create a (un?)distorted CD matrix from the basic inputs.
The 'cx' and 'cy' parameters, if given, provide the X and Y coefficients of
the distortion as returned by reading the IDCTAB. Only the first 2 elements
are used and should correspond to the 'OC... | [
"def",
"create_CD",
"(",
"orient",
",",
"scale",
",",
"cx",
"=",
"None",
",",
"cy",
"=",
"None",
")",
":",
"cxymat",
"=",
"np",
".",
"array",
"(",
"[",
"[",
"cx",
"[",
"1",
"]",
",",
"cx",
"[",
"0",
"]",
"]",
",",
"[",
"cy",
"[",
"1",
"]"... | Create a (un?)distorted CD matrix from the basic inputs.
The 'cx' and 'cy' parameters, if given, provide the X and Y coefficients of
the distortion as returned by reading the IDCTAB. Only the first 2 elements
are used and should correspond to the 'OC[X/Y]10' and 'OC[X/Y]11' terms in that
order as read... | [
"Create",
"a",
"(",
"un?",
")",
"distorted",
"CD",
"matrix",
"from",
"the",
"basic",
"inputs",
"."
] | python | train |
materials-data-facility/toolbox | mdf_toolbox/toolbox.py | https://github.com/materials-data-facility/toolbox/blob/2a4ac2b6a892238263008efa6a5f3923d9a83505/mdf_toolbox/toolbox.py#L257-L361 | def confidential_login(credentials=None, client_id=None, client_secret=None, services=None,
make_clients=True, token_dir=DEFAULT_CRED_PATH):
"""Log in to Globus services as a confidential client
(a client with its own login information).
Arguments:
credentials (str or dict): ... | [
"def",
"confidential_login",
"(",
"credentials",
"=",
"None",
",",
"client_id",
"=",
"None",
",",
"client_secret",
"=",
"None",
",",
"services",
"=",
"None",
",",
"make_clients",
"=",
"True",
",",
"token_dir",
"=",
"DEFAULT_CRED_PATH",
")",
":",
"DEFAULT_CRED_... | Log in to Globus services as a confidential client
(a client with its own login information).
Arguments:
credentials (str or dict): A string filename, string JSON, or dictionary
with credential and config information.
By default, uses the ``DEFAULT_CRED_FILENAME`` and to... | [
"Log",
"in",
"to",
"Globus",
"services",
"as",
"a",
"confidential",
"client",
"(",
"a",
"client",
"with",
"its",
"own",
"login",
"information",
")",
"."
] | python | train |
jrfonseca/xdot.py | xdot/ui/pen.py | https://github.com/jrfonseca/xdot.py/blob/6248c81c21a0fe825089311b17f2c302eea614a2/xdot/ui/pen.py#L46-L50 | def copy(self):
"""Create a copy of this pen."""
pen = Pen()
pen.__dict__ = self.__dict__.copy()
return pen | [
"def",
"copy",
"(",
"self",
")",
":",
"pen",
"=",
"Pen",
"(",
")",
"pen",
".",
"__dict__",
"=",
"self",
".",
"__dict__",
".",
"copy",
"(",
")",
"return",
"pen"
] | Create a copy of this pen. | [
"Create",
"a",
"copy",
"of",
"this",
"pen",
"."
] | python | test |
LogicalDash/LiSE | ELiDE/ELiDE/board/spot.py | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/ELiDE/ELiDE/board/spot.py#L81-L89 | def push_pos(self, *args):
"""Set my current position, expressed as proportions of the board's
width and height, into the ``_x`` and ``_y`` keys of the
entity in my ``proxy`` property, such that it will be
recorded in the database.
"""
self.proxy['_x'] = self.x / self.bo... | [
"def",
"push_pos",
"(",
"self",
",",
"*",
"args",
")",
":",
"self",
".",
"proxy",
"[",
"'_x'",
"]",
"=",
"self",
".",
"x",
"/",
"self",
".",
"board",
".",
"width",
"self",
".",
"proxy",
"[",
"'_y'",
"]",
"=",
"self",
".",
"y",
"/",
"self",
".... | Set my current position, expressed as proportions of the board's
width and height, into the ``_x`` and ``_y`` keys of the
entity in my ``proxy`` property, such that it will be
recorded in the database. | [
"Set",
"my",
"current",
"position",
"expressed",
"as",
"proportions",
"of",
"the",
"board",
"s",
"width",
"and",
"height",
"into",
"the",
"_x",
"and",
"_y",
"keys",
"of",
"the",
"entity",
"in",
"my",
"proxy",
"property",
"such",
"that",
"it",
"will",
"be... | python | train |
acroz/pylivy | livy/session.py | https://github.com/acroz/pylivy/blob/14fc65e19434c51ec959c92acb0925b87a6e3569/livy/session.py#L193-L200 | def state(self) -> SessionState:
"""The state of the managed Spark session."""
if self.session_id is None:
raise ValueError("session not yet started")
session = self.client.get_session(self.session_id)
if session is None:
raise ValueError("session not found - it m... | [
"def",
"state",
"(",
"self",
")",
"->",
"SessionState",
":",
"if",
"self",
".",
"session_id",
"is",
"None",
":",
"raise",
"ValueError",
"(",
"\"session not yet started\"",
")",
"session",
"=",
"self",
".",
"client",
".",
"get_session",
"(",
"self",
".",
"s... | The state of the managed Spark session. | [
"The",
"state",
"of",
"the",
"managed",
"Spark",
"session",
"."
] | python | train |
m110/climb | climb/core.py | https://github.com/m110/climb/blob/0a35dfb94df48f85963490fbe0514c2ea80bff34/climb/core.py#L32-L71 | def run(self):
"""Loops and executes commands in interactive mode."""
if self._skip_delims:
delims = readline.get_completer_delims()
for delim in self._skip_delims:
delims = delims.replace(delim, '')
readline.set_completer_delims(delims)
readl... | [
"def",
"run",
"(",
"self",
")",
":",
"if",
"self",
".",
"_skip_delims",
":",
"delims",
"=",
"readline",
".",
"get_completer_delims",
"(",
")",
"for",
"delim",
"in",
"self",
".",
"_skip_delims",
":",
"delims",
"=",
"delims",
".",
"replace",
"(",
"delim",
... | Loops and executes commands in interactive mode. | [
"Loops",
"and",
"executes",
"commands",
"in",
"interactive",
"mode",
"."
] | python | train |
kivy/python-for-android | pythonforandroid/bootstraps/pygame/build/buildlib/jinja2.egg/jinja2/bccache.py | https://github.com/kivy/python-for-android/blob/8e0e8056bc22e4d5bd3398a6b0301f38ff167933/pythonforandroid/bootstraps/pygame/build/buildlib/jinja2.egg/jinja2/bccache.py#L72-L81 | def write_bytecode(self, f):
"""Dump the bytecode into the file or file like object passed."""
if self.code is None:
raise TypeError('can\'t write empty bucket')
f.write(bc_magic)
pickle.dump(self.checksum, f, 2)
if isinstance(f, file):
marshal.dump(self.c... | [
"def",
"write_bytecode",
"(",
"self",
",",
"f",
")",
":",
"if",
"self",
".",
"code",
"is",
"None",
":",
"raise",
"TypeError",
"(",
"'can\\'t write empty bucket'",
")",
"f",
".",
"write",
"(",
"bc_magic",
")",
"pickle",
".",
"dump",
"(",
"self",
".",
"c... | Dump the bytecode into the file or file like object passed. | [
"Dump",
"the",
"bytecode",
"into",
"the",
"file",
"or",
"file",
"like",
"object",
"passed",
"."
] | python | train |
singularityhub/singularity-python | singularity/analysis/reproduce/levels.py | https://github.com/singularityhub/singularity-python/blob/498c3433724b332f7493fec632d8daf479f47b82/singularity/analysis/reproduce/levels.py#L155-L164 | def make_level_set(level):
'''make level set will convert one level into
a set'''
new_level = dict()
for key,value in level.items():
if isinstance(value,list):
new_level[key] = set(value)
else:
new_level[key] = value
return new_level | [
"def",
"make_level_set",
"(",
"level",
")",
":",
"new_level",
"=",
"dict",
"(",
")",
"for",
"key",
",",
"value",
"in",
"level",
".",
"items",
"(",
")",
":",
"if",
"isinstance",
"(",
"value",
",",
"list",
")",
":",
"new_level",
"[",
"key",
"]",
"=",... | make level set will convert one level into
a set | [
"make",
"level",
"set",
"will",
"convert",
"one",
"level",
"into",
"a",
"set"
] | python | train |
ArchiveTeam/wpull | wpull/document/htmlparse/lxml_.py | https://github.com/ArchiveTeam/wpull/blob/ddf051aa3322479325ba20aa778cb2cb97606bf5/wpull/document/htmlparse/lxml_.py#L189-L208 | def parse_doctype(cls, file, encoding=None):
'''Get the doctype from the document.
Returns:
str, None
'''
if encoding:
lxml_encoding = to_lxml_encoding(encoding) or 'latin1'
else:
lxml_encoding = encoding
try:
parser = lxm... | [
"def",
"parse_doctype",
"(",
"cls",
",",
"file",
",",
"encoding",
"=",
"None",
")",
":",
"if",
"encoding",
":",
"lxml_encoding",
"=",
"to_lxml_encoding",
"(",
"encoding",
")",
"or",
"'latin1'",
"else",
":",
"lxml_encoding",
"=",
"encoding",
"try",
":",
"pa... | Get the doctype from the document.
Returns:
str, None | [
"Get",
"the",
"doctype",
"from",
"the",
"document",
"."
] | python | train |
Kozea/cairocffi | cairocffi/fonts.py | https://github.com/Kozea/cairocffi/blob/450853add7e32eea20985b6aa5f54d9cb3cd04fe/cairocffi/fonts.py#L16-L20 | def _encode_string(string):
"""Return a byte string, encoding Unicode with UTF-8."""
if not isinstance(string, bytes):
string = string.encode('utf8')
return ffi.new('char[]', string) | [
"def",
"_encode_string",
"(",
"string",
")",
":",
"if",
"not",
"isinstance",
"(",
"string",
",",
"bytes",
")",
":",
"string",
"=",
"string",
".",
"encode",
"(",
"'utf8'",
")",
"return",
"ffi",
".",
"new",
"(",
"'char[]'",
",",
"string",
")"
] | Return a byte string, encoding Unicode with UTF-8. | [
"Return",
"a",
"byte",
"string",
"encoding",
"Unicode",
"with",
"UTF",
"-",
"8",
"."
] | python | train |
markdrago/pgsanity | pgsanity/pgsanity.py | https://github.com/markdrago/pgsanity/blob/3bd391be1c5f0e2ce041652bdaf1d6b54424c6d8/pgsanity/pgsanity.py#L46-L55 | def check_string(sql_string, add_semicolon=False):
"""
Check whether a string is valid PostgreSQL. Returns a boolean
indicating validity and a message from ecpg, which will be an
empty string if the input was valid, or a description of the
problem otherwise.
"""
prepped_sql = sqlprep.prepare... | [
"def",
"check_string",
"(",
"sql_string",
",",
"add_semicolon",
"=",
"False",
")",
":",
"prepped_sql",
"=",
"sqlprep",
".",
"prepare_sql",
"(",
"sql_string",
",",
"add_semicolon",
"=",
"add_semicolon",
")",
"success",
",",
"msg",
"=",
"ecpg",
".",
"check_synta... | Check whether a string is valid PostgreSQL. Returns a boolean
indicating validity and a message from ecpg, which will be an
empty string if the input was valid, or a description of the
problem otherwise. | [
"Check",
"whether",
"a",
"string",
"is",
"valid",
"PostgreSQL",
".",
"Returns",
"a",
"boolean",
"indicating",
"validity",
"and",
"a",
"message",
"from",
"ecpg",
"which",
"will",
"be",
"an",
"empty",
"string",
"if",
"the",
"input",
"was",
"valid",
"or",
"a"... | python | train |
Pipoline/rocket-python | rocketchat/api.py | https://github.com/Pipoline/rocket-python/blob/643ece8a9db106922e019984a859ca04283262ff/rocketchat/api.py#L39-L43 | def get_private_rooms(self, **kwargs):
"""
Get a listing of all private rooms with their names and IDs
"""
return GetPrivateRooms(settings=self.settings, **kwargs).call(**kwargs) | [
"def",
"get_private_rooms",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"GetPrivateRooms",
"(",
"settings",
"=",
"self",
".",
"settings",
",",
"*",
"*",
"kwargs",
")",
".",
"call",
"(",
"*",
"*",
"kwargs",
")"
] | Get a listing of all private rooms with their names and IDs | [
"Get",
"a",
"listing",
"of",
"all",
"private",
"rooms",
"with",
"their",
"names",
"and",
"IDs"
] | python | train |
django-leonardo/django-leonardo | leonardo/decorators.py | https://github.com/django-leonardo/django-leonardo/blob/4b933e1792221a13b4028753d5f1d3499b0816d4/leonardo/decorators.py#L53-L68 | def _decorate_urlconf(urlpatterns, decorator=require_auth, *args, **kwargs):
'''Decorate all urlpatterns by specified decorator'''
if isinstance(urlpatterns, (list, tuple)):
for pattern in urlpatterns:
if getattr(pattern, 'callback', None):
pattern._callback = decorator(
... | [
"def",
"_decorate_urlconf",
"(",
"urlpatterns",
",",
"decorator",
"=",
"require_auth",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"isinstance",
"(",
"urlpatterns",
",",
"(",
"list",
",",
"tuple",
")",
")",
":",
"for",
"pattern",
"in",
"... | Decorate all urlpatterns by specified decorator | [
"Decorate",
"all",
"urlpatterns",
"by",
"specified",
"decorator"
] | python | train |
Azure/msrest-for-python | msrest/serialization.py | https://github.com/Azure/msrest-for-python/blob/0732bc90bdb290e5f58c675ffdd7dbfa9acefc93/msrest/serialization.py#L1580-L1599 | def deserialize_unicode(data):
"""Preserve unicode objects in Python 2, otherwise return data
as a string.
:param str data: response string to be deserialized.
:rtype: str or unicode
"""
# We might be here because we have an enum modeled as string,
# and we try t... | [
"def",
"deserialize_unicode",
"(",
"data",
")",
":",
"# We might be here because we have an enum modeled as string,",
"# and we try to deserialize a partial dict with enum inside",
"if",
"isinstance",
"(",
"data",
",",
"Enum",
")",
":",
"return",
"data",
"# Consider this is real ... | Preserve unicode objects in Python 2, otherwise return data
as a string.
:param str data: response string to be deserialized.
:rtype: str or unicode | [
"Preserve",
"unicode",
"objects",
"in",
"Python",
"2",
"otherwise",
"return",
"data",
"as",
"a",
"string",
"."
] | python | train |
fastai/fastai | fastai/data_block.py | https://github.com/fastai/fastai/blob/9fb84a5cdefe5a766cdb792b8f5d8971737b7e67/fastai/data_block.py#L668-L670 | def load_empty(cls, path:PathOrStr, fn:PathOrStr):
"Load the state in `fn` to create an empty `LabelList` for inference."
return cls.load_state(path, pickle.load(open(Path(path)/fn, 'rb'))) | [
"def",
"load_empty",
"(",
"cls",
",",
"path",
":",
"PathOrStr",
",",
"fn",
":",
"PathOrStr",
")",
":",
"return",
"cls",
".",
"load_state",
"(",
"path",
",",
"pickle",
".",
"load",
"(",
"open",
"(",
"Path",
"(",
"path",
")",
"/",
"fn",
",",
"'rb'",
... | Load the state in `fn` to create an empty `LabelList` for inference. | [
"Load",
"the",
"state",
"in",
"fn",
"to",
"create",
"an",
"empty",
"LabelList",
"for",
"inference",
"."
] | python | train |
vimalkvn/riboplot | riboplot/ribocore.py | https://github.com/vimalkvn/riboplot/blob/914515df54eccc2e726ba71e751c3260f2066d97/riboplot/ribocore.py#L350-L363 | def check_rna_file(rna_file):
"""Check if bedtools is available and if the given RNA-Seq bam file is valid. """
try:
subprocess.check_output(['bedtools', '--version'])
except OSError:
log.error('Could not find bedtools in PATH. bedtools is required '
'for generating RNA cov... | [
"def",
"check_rna_file",
"(",
"rna_file",
")",
":",
"try",
":",
"subprocess",
".",
"check_output",
"(",
"[",
"'bedtools'",
",",
"'--version'",
"]",
")",
"except",
"OSError",
":",
"log",
".",
"error",
"(",
"'Could not find bedtools in PATH. bedtools is required '",
... | Check if bedtools is available and if the given RNA-Seq bam file is valid. | [
"Check",
"if",
"bedtools",
"is",
"available",
"and",
"if",
"the",
"given",
"RNA",
"-",
"Seq",
"bam",
"file",
"is",
"valid",
"."
] | python | train |
saltstack/salt | salt/modules/dockermod.py | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/dockermod.py#L1325-L1366 | def connected(name, verbose=False):
'''
.. versionadded:: 2018.3.0
Return a list of running containers attached to the specified network
name
Network name
verbose : False
If ``True``, return extended info about each container (IP
configuration, etc.)
CLI Example:
... | [
"def",
"connected",
"(",
"name",
",",
"verbose",
"=",
"False",
")",
":",
"containers",
"=",
"inspect_network",
"(",
"name",
")",
".",
"get",
"(",
"'Containers'",
",",
"{",
"}",
")",
"ret",
"=",
"{",
"}",
"for",
"cid",
",",
"cinfo",
"in",
"six",
"."... | .. versionadded:: 2018.3.0
Return a list of running containers attached to the specified network
name
Network name
verbose : False
If ``True``, return extended info about each container (IP
configuration, etc.)
CLI Example:
.. code-block:: bash
salt myminion doc... | [
"..",
"versionadded",
"::",
"2018",
".",
"3",
".",
"0"
] | python | train |
chimera0/accel-brain-code | Generative-Adversarial-Networks/pygan/generativemodel/conditionalgenerativemodel/conditional_convolutional_model.py | https://github.com/chimera0/accel-brain-code/blob/03661f6f544bed656269fcd4b3c23c9061629daa/Generative-Adversarial-Networks/pygan/generativemodel/conditionalgenerativemodel/conditional_convolutional_model.py#L190-L206 | def learn(self, grad_arr, fix_opt_flag=False):
'''
Update this Discriminator by ascending its stochastic gradient.
Args:
grad_arr: `np.ndarray` of gradients.
fix_opt_flag: If `False`, no optimization in this model will be done.
Returns:
... | [
"def",
"learn",
"(",
"self",
",",
"grad_arr",
",",
"fix_opt_flag",
"=",
"False",
")",
":",
"channel",
"=",
"grad_arr",
".",
"shape",
"[",
"1",
"]",
"//",
"2",
"grad_arr",
"=",
"self",
".",
"__deconvolution_model",
".",
"learn",
"(",
"grad_arr",
"[",
":... | Update this Discriminator by ascending its stochastic gradient.
Args:
grad_arr: `np.ndarray` of gradients.
fix_opt_flag: If `False`, no optimization in this model will be done.
Returns:
`np.ndarray` of delta or gradients. | [
"Update",
"this",
"Discriminator",
"by",
"ascending",
"its",
"stochastic",
"gradient",
".",
"Args",
":",
"grad_arr",
":",
"np",
".",
"ndarray",
"of",
"gradients",
".",
"fix_opt_flag",
":",
"If",
"False",
"no",
"optimization",
"in",
"this",
"model",
"will",
"... | python | train |
google/grr | grr/client/grr_response_client/windows/installers.py | https://github.com/google/grr/blob/5cef4e8e2f0d5df43ea4877e9c798e0bf60bfe74/grr/client/grr_response_client/windows/installers.py#L235-L255 | def InstallNanny(self):
"""Install the nanny program."""
# We need to copy the nanny sections to the registry to ensure the
# service is correctly configured.
new_config = config.CONFIG.MakeNewConfig()
new_config.SetWriteBack(config.CONFIG["Config.writeback"])
for option in self.nanny_options:
... | [
"def",
"InstallNanny",
"(",
"self",
")",
":",
"# We need to copy the nanny sections to the registry to ensure the",
"# service is correctly configured.",
"new_config",
"=",
"config",
".",
"CONFIG",
".",
"MakeNewConfig",
"(",
")",
"new_config",
".",
"SetWriteBack",
"(",
"con... | Install the nanny program. | [
"Install",
"the",
"nanny",
"program",
"."
] | python | train |
sassoo/goldman | goldman/validators/__init__.py | https://github.com/sassoo/goldman/blob/b72540c9ad06b5c68aadb1b4fa8cb0b716260bf2/goldman/validators/__init__.py#L24-L32 | def validate_uuid(value):
""" UUID 128-bit validator """
if value and not isinstance(value, UUID):
try:
return UUID(str(value), version=4)
except (AttributeError, ValueError):
raise ValidationError('not a valid UUID')
return value | [
"def",
"validate_uuid",
"(",
"value",
")",
":",
"if",
"value",
"and",
"not",
"isinstance",
"(",
"value",
",",
"UUID",
")",
":",
"try",
":",
"return",
"UUID",
"(",
"str",
"(",
"value",
")",
",",
"version",
"=",
"4",
")",
"except",
"(",
"AttributeError... | UUID 128-bit validator | [
"UUID",
"128",
"-",
"bit",
"validator"
] | python | train |
saltstack/salt | salt/modules/lxc.py | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/lxc.py#L2882-L2945 | def set_password(name, users, password, encrypted=True, path=None):
'''
.. versionchanged:: 2015.5.0
Function renamed from ``set_pass`` to ``set_password``. Additionally,
this function now supports (and defaults to using) a password hash
instead of a plaintext password.
Set the pass... | [
"def",
"set_password",
"(",
"name",
",",
"users",
",",
"password",
",",
"encrypted",
"=",
"True",
",",
"path",
"=",
"None",
")",
":",
"def",
"_bad_user_input",
"(",
")",
":",
"raise",
"SaltInvocationError",
"(",
"'Invalid input for \\'users\\' parameter'",
")",
... | .. versionchanged:: 2015.5.0
Function renamed from ``set_pass`` to ``set_password``. Additionally,
this function now supports (and defaults to using) a password hash
instead of a plaintext password.
Set the password of one or more system users inside containers
users
Comma-sep... | [
"..",
"versionchanged",
"::",
"2015",
".",
"5",
".",
"0",
"Function",
"renamed",
"from",
"set_pass",
"to",
"set_password",
".",
"Additionally",
"this",
"function",
"now",
"supports",
"(",
"and",
"defaults",
"to",
"using",
")",
"a",
"password",
"hash",
"inste... | python | train |
F5Networks/f5-common-python | f5-sdk-dist/build_pkgs.py | https://github.com/F5Networks/f5-common-python/blob/7e67d5acd757a60e3d5f8c88c534bd72208f5494/f5-sdk-dist/build_pkgs.py#L351-L366 | def store_json(obj, destination):
"""store_json
Takes in a json-portable object and a filesystem-based destination and stores
the json-portable object as JSON into the filesystem-based destination.
This is blind, dumb, and stupid; thus, it can fail if the object is more
complex than simple dict, list, int, str, e... | [
"def",
"store_json",
"(",
"obj",
",",
"destination",
")",
":",
"with",
"open",
"(",
"destination",
",",
"'r+'",
")",
"as",
"FH",
":",
"fcntl",
".",
"lockf",
"(",
"FH",
",",
"fcntl",
".",
"LOCK_EX",
")",
"json_in",
"=",
"json",
".",
"loads",
"(",
"F... | store_json
Takes in a json-portable object and a filesystem-based destination and stores
the json-portable object as JSON into the filesystem-based destination.
This is blind, dumb, and stupid; thus, it can fail if the object is more
complex than simple dict, list, int, str, etc. type object structures. | [
"store_json"
] | python | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.