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 |
|---|---|---|---|---|---|---|---|---|
python-bonobo/bonobo | bonobo/nodes/basics.py | https://github.com/python-bonobo/bonobo/blob/70c8e62c4a88576976e5b52e58d380d6e3227ab4/bonobo/nodes/basics.py#L320-L356 | def MapFields(function, key=True):
"""
Transformation factory that maps `function` on the values of a row.
It can be applied either to
1. all columns (`key=True`),
2. no column (`key=False`), or
3. a subset of columns by passing a callable, which takes column name and returns `bool`
(same a... | [
"def",
"MapFields",
"(",
"function",
",",
"key",
"=",
"True",
")",
":",
"@",
"use_raw_input",
"def",
"_MapFields",
"(",
"bag",
")",
":",
"try",
":",
"factory",
"=",
"type",
"(",
"bag",
")",
".",
"_make",
"except",
"AttributeError",
":",
"factory",
"=",... | Transformation factory that maps `function` on the values of a row.
It can be applied either to
1. all columns (`key=True`),
2. no column (`key=False`), or
3. a subset of columns by passing a callable, which takes column name and returns `bool`
(same as the parameter `function` in `filter`).
:... | [
"Transformation",
"factory",
"that",
"maps",
"function",
"on",
"the",
"values",
"of",
"a",
"row",
".",
"It",
"can",
"be",
"applied",
"either",
"to",
"1",
".",
"all",
"columns",
"(",
"key",
"=",
"True",
")",
"2",
".",
"no",
"column",
"(",
"key",
"=",
... | python | train |
anlutro/diay.py | diay/__init__.py | https://github.com/anlutro/diay.py/blob/78cfd2b53c8dca3dbac468d620eaa0bb7af08275/diay/__init__.py#L173-L187 | def call(self, func, *args, **kwargs):
"""
Call a function, resolving any type-hinted arguments.
"""
guessed_kwargs = self._guess_kwargs(func)
for key, val in guessed_kwargs.items():
kwargs.setdefault(key, val)
try:
return func(*args, **kwargs)
... | [
"def",
"call",
"(",
"self",
",",
"func",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"guessed_kwargs",
"=",
"self",
".",
"_guess_kwargs",
"(",
"func",
")",
"for",
"key",
",",
"val",
"in",
"guessed_kwargs",
".",
"items",
"(",
")",
":",
"kwa... | Call a function, resolving any type-hinted arguments. | [
"Call",
"a",
"function",
"resolving",
"any",
"type",
"-",
"hinted",
"arguments",
"."
] | python | train |
toidi/hadoop-yarn-api-python-client | yarn_api_client/resource_manager.py | https://github.com/toidi/hadoop-yarn-api-python-client/blob/d245bd41808879be6637acfd7460633c0c7dfdd6/yarn_api_client/resource_manager.py#L68-L120 | def cluster_applications(self, state=None, final_status=None,
user=None, queue=None, limit=None,
started_time_begin=None, started_time_end=None,
finished_time_begin=None, finished_time_end=None):
"""
With the Applicat... | [
"def",
"cluster_applications",
"(",
"self",
",",
"state",
"=",
"None",
",",
"final_status",
"=",
"None",
",",
"user",
"=",
"None",
",",
"queue",
"=",
"None",
",",
"limit",
"=",
"None",
",",
"started_time_begin",
"=",
"None",
",",
"started_time_end",
"=",
... | With the Applications API, you can obtain a collection of resources,
each of which represents an application.
:param str state: state of the application
:param str final_status: the final status of the
application - reported by the application itself
:param str user: user na... | [
"With",
"the",
"Applications",
"API",
"you",
"can",
"obtain",
"a",
"collection",
"of",
"resources",
"each",
"of",
"which",
"represents",
"an",
"application",
"."
] | python | train |
benhoff/vexbot | vexbot/messaging.py | https://github.com/benhoff/vexbot/blob/9b844eb20e84eea92a0e7db7d86a90094956c38f/vexbot/messaging.py#L252-L267 | def send_request(self, target: str, *args, **kwargs):
"""
address must a list instance. Or a string which will be transformed into a address
"""
# TODO: Log error here if not found?
address = self._get_address_from_source(target)
if address is None:
return
... | [
"def",
"send_request",
"(",
"self",
",",
"target",
":",
"str",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"# TODO: Log error here if not found?",
"address",
"=",
"self",
".",
"_get_address_from_source",
"(",
"target",
")",
"if",
"address",
"is",
"N... | address must a list instance. Or a string which will be transformed into a address | [
"address",
"must",
"a",
"list",
"instance",
".",
"Or",
"a",
"string",
"which",
"will",
"be",
"transformed",
"into",
"a",
"address"
] | python | train |
Julian/Filesystems | filesystems/common.py | https://github.com/Julian/Filesystems/blob/f366e877d6970712bb91d47167209ee2d1e489c5/filesystems/common.py#L173-L186 | def _is_dir(fs, path):
"""
Check that the given path is a directory.
Note that unlike `os.path.isdir`, we *do* propagate file system errors
other than a non-existent path or non-existent directory component.
E.g., should EPERM or ELOOP be raised, an exception will bubble up.
"""
try:
... | [
"def",
"_is_dir",
"(",
"fs",
",",
"path",
")",
":",
"try",
":",
"return",
"stat",
".",
"S_ISDIR",
"(",
"fs",
".",
"stat",
"(",
"path",
")",
".",
"st_mode",
")",
"except",
"exceptions",
".",
"FileNotFound",
":",
"return",
"False"
] | Check that the given path is a directory.
Note that unlike `os.path.isdir`, we *do* propagate file system errors
other than a non-existent path or non-existent directory component.
E.g., should EPERM or ELOOP be raised, an exception will bubble up. | [
"Check",
"that",
"the",
"given",
"path",
"is",
"a",
"directory",
"."
] | python | train |
Spinmob/spinmob | egg/_gui.py | https://github.com/Spinmob/spinmob/blob/f037f5df07f194bcd4a01f4d9916e57b9e8fb45a/egg/_gui.py#L2162-L2209 | def get_value(self, name):
"""
Returns the value of the parameter with the specified name.
"""
# first clean up the name
name = self._clean_up_name(name)
# now get the parameter object
x = self._find_parameter(name.split('/'))
# quit if it pooped.
... | [
"def",
"get_value",
"(",
"self",
",",
"name",
")",
":",
"# first clean up the name",
"name",
"=",
"self",
".",
"_clean_up_name",
"(",
"name",
")",
"# now get the parameter object",
"x",
"=",
"self",
".",
"_find_parameter",
"(",
"name",
".",
"split",
"(",
"'/'"... | Returns the value of the parameter with the specified name. | [
"Returns",
"the",
"value",
"of",
"the",
"parameter",
"with",
"the",
"specified",
"name",
"."
] | python | train |
nerdvegas/rez | src/rez/packages_.py | https://github.com/nerdvegas/rez/blob/1d3b846d53b5b5404edfe8ddb9083f9ceec8c5e7/src/rez/packages_.py#L563-L575 | def get_package_from_string(txt, paths=None):
"""Get a package given a string.
Args:
txt (str): String such as 'foo', 'bah-1.3'.
paths (list of str, optional): paths to search for package, defaults
to `config.packages_path`.
Returns:
`Package` instance, or None if no pa... | [
"def",
"get_package_from_string",
"(",
"txt",
",",
"paths",
"=",
"None",
")",
":",
"o",
"=",
"VersionedObject",
"(",
"txt",
")",
"return",
"get_package",
"(",
"o",
".",
"name",
",",
"o",
".",
"version",
",",
"paths",
"=",
"paths",
")"
] | Get a package given a string.
Args:
txt (str): String such as 'foo', 'bah-1.3'.
paths (list of str, optional): paths to search for package, defaults
to `config.packages_path`.
Returns:
`Package` instance, or None if no package was found. | [
"Get",
"a",
"package",
"given",
"a",
"string",
"."
] | python | train |
pybel/pybel | src/pybel/struct/graph.py | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/struct/graph.py#L558-L560 | def has_edge_evidence(self, u: BaseEntity, v: BaseEntity, key: str) -> bool:
"""Check if the given edge has an evidence."""
return self._has_edge_attr(u, v, key, EVIDENCE) | [
"def",
"has_edge_evidence",
"(",
"self",
",",
"u",
":",
"BaseEntity",
",",
"v",
":",
"BaseEntity",
",",
"key",
":",
"str",
")",
"->",
"bool",
":",
"return",
"self",
".",
"_has_edge_attr",
"(",
"u",
",",
"v",
",",
"key",
",",
"EVIDENCE",
")"
] | Check if the given edge has an evidence. | [
"Check",
"if",
"the",
"given",
"edge",
"has",
"an",
"evidence",
"."
] | python | train |
PSPC-SPAC-buyandsell/von_anchor | von_anchor/wallet/wallet.py | https://github.com/PSPC-SPAC-buyandsell/von_anchor/blob/78ac1de67be42a676274f4bf71fe12f66e72f309/von_anchor/wallet/wallet.py#L492-L524 | async def create_link_secret(self, label: str) -> None:
"""
Create link secret (a.k.a. master secret) used in proofs by HolderProver, if the
current link secret does not already correspond to the input link secret label.
Raise WalletState if wallet is closed, or any other IndyError caus... | [
"async",
"def",
"create_link_secret",
"(",
"self",
",",
"label",
":",
"str",
")",
"->",
"None",
":",
"LOGGER",
".",
"debug",
"(",
"'Wallet.create_link_secret >>> label: %s'",
",",
"label",
")",
"if",
"not",
"self",
".",
"handle",
":",
"LOGGER",
".",
"debug",... | Create link secret (a.k.a. master secret) used in proofs by HolderProver, if the
current link secret does not already correspond to the input link secret label.
Raise WalletState if wallet is closed, or any other IndyError causing failure
to set link secret in wallet.
:param label: lab... | [
"Create",
"link",
"secret",
"(",
"a",
".",
"k",
".",
"a",
".",
"master",
"secret",
")",
"used",
"in",
"proofs",
"by",
"HolderProver",
"if",
"the",
"current",
"link",
"secret",
"does",
"not",
"already",
"correspond",
"to",
"the",
"input",
"link",
"secret"... | python | train |
theolind/pymysensors | mysensors/__init__.py | https://github.com/theolind/pymysensors/blob/a139ab6e2f6b71ebaf37282f69bfd0f7fe6193b6/mysensors/__init__.py#L236-L243 | def _poll_queue(self):
"""Poll the queue for work."""
while not self._stop_event.is_set():
reply = self.run_job()
self.send(reply)
if self.queue:
continue
time.sleep(0.02) | [
"def",
"_poll_queue",
"(",
"self",
")",
":",
"while",
"not",
"self",
".",
"_stop_event",
".",
"is_set",
"(",
")",
":",
"reply",
"=",
"self",
".",
"run_job",
"(",
")",
"self",
".",
"send",
"(",
"reply",
")",
"if",
"self",
".",
"queue",
":",
"continu... | Poll the queue for work. | [
"Poll",
"the",
"queue",
"for",
"work",
"."
] | python | train |
python-openxml/python-docx | docx/image/tiff.py | https://github.com/python-openxml/python-docx/blob/6756f6cd145511d3eb6d1d188beea391b1ddfd53/docx/image/tiff.py#L197-L205 | def iter_entries(self):
"""
Generate an |_IfdEntry| instance corresponding to each entry in the
directory.
"""
for idx in range(self._entry_count):
dir_entry_offset = self._offset + 2 + (idx*12)
ifd_entry = _IfdEntryFactory(self._stream_rdr, dir_entry_offs... | [
"def",
"iter_entries",
"(",
"self",
")",
":",
"for",
"idx",
"in",
"range",
"(",
"self",
".",
"_entry_count",
")",
":",
"dir_entry_offset",
"=",
"self",
".",
"_offset",
"+",
"2",
"+",
"(",
"idx",
"*",
"12",
")",
"ifd_entry",
"=",
"_IfdEntryFactory",
"("... | Generate an |_IfdEntry| instance corresponding to each entry in the
directory. | [
"Generate",
"an",
"|_IfdEntry|",
"instance",
"corresponding",
"to",
"each",
"entry",
"in",
"the",
"directory",
"."
] | python | train |
rigetti/pyquil | pyquil/api/_devices.py | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/api/_devices.py#L49-L99 | def list_lattices(device_name: str = None, num_qubits: int = None,
connection: ForestConnection = None):
"""
Query the Forest 2.0 server for its knowledge of lattices. Optionally filters by underlying
device name and lattice qubit count.
:return: A dictionary keyed on lattice names a... | [
"def",
"list_lattices",
"(",
"device_name",
":",
"str",
"=",
"None",
",",
"num_qubits",
":",
"int",
"=",
"None",
",",
"connection",
":",
"ForestConnection",
"=",
"None",
")",
":",
"if",
"connection",
"is",
"None",
":",
"connection",
"=",
"ForestConnection",
... | Query the Forest 2.0 server for its knowledge of lattices. Optionally filters by underlying
device name and lattice qubit count.
:return: A dictionary keyed on lattice names and valued in dictionaries of the form
{
"device_name": device_name,
"qubits": num_qubits
... | [
"Query",
"the",
"Forest",
"2",
".",
"0",
"server",
"for",
"its",
"knowledge",
"of",
"lattices",
".",
"Optionally",
"filters",
"by",
"underlying",
"device",
"name",
"and",
"lattice",
"qubit",
"count",
"."
] | python | train |
rocky/python3-trepan | trepan/bwprocessor/main.py | https://github.com/rocky/python3-trepan/blob/14e91bc0acce090d67be145b1ac040cab92ac5f3/trepan/bwprocessor/main.py#L259-L279 | def ok_for_running(self, cmd_obj, name, cmd_hash):
'''We separate some of the common debugger command checks here:
whether it makes sense to run the command in this execution state,
if the command has the right number of arguments and so on.
'''
if hasattr(cmd_obj, 'execution_set... | [
"def",
"ok_for_running",
"(",
"self",
",",
"cmd_obj",
",",
"name",
",",
"cmd_hash",
")",
":",
"if",
"hasattr",
"(",
"cmd_obj",
",",
"'execution_set'",
")",
":",
"if",
"not",
"(",
"self",
".",
"core",
".",
"execution_status",
"in",
"cmd_obj",
".",
"execut... | We separate some of the common debugger command checks here:
whether it makes sense to run the command in this execution state,
if the command has the right number of arguments and so on. | [
"We",
"separate",
"some",
"of",
"the",
"common",
"debugger",
"command",
"checks",
"here",
":",
"whether",
"it",
"makes",
"sense",
"to",
"run",
"the",
"command",
"in",
"this",
"execution",
"state",
"if",
"the",
"command",
"has",
"the",
"right",
"number",
"o... | python | test |
smartfile/client-python | smartfile/__init__.py | https://github.com/smartfile/client-python/blob/f9ccc40a2870df447c65b53dc0747e37cab62d63/smartfile/__init__.py#L50-L73 | def _do_request(self, request, url, **kwargs):
"Actually makes the HTTP request."
try:
response = request(url, stream=True, **kwargs)
except RequestException as e:
raise RequestError(e)
else:
if response.status_code >= 400:
raise Respon... | [
"def",
"_do_request",
"(",
"self",
",",
"request",
",",
"url",
",",
"*",
"*",
"kwargs",
")",
":",
"try",
":",
"response",
"=",
"request",
"(",
"url",
",",
"stream",
"=",
"True",
",",
"*",
"*",
"kwargs",
")",
"except",
"RequestException",
"as",
"e",
... | Actually makes the HTTP request. | [
"Actually",
"makes",
"the",
"HTTP",
"request",
"."
] | python | train |
tk0miya/tk.phpautodoc | src/phply/phpparse.py | https://github.com/tk0miya/tk.phpautodoc/blob/cf789f64abaf76351485cee231a075227e665fb6/src/phply/phpparse.py#L1003-L1015 | def p_expr_assign_op(p):
'''expr : variable PLUS_EQUAL expr
| variable MINUS_EQUAL expr
| variable MUL_EQUAL expr
| variable DIV_EQUAL expr
| variable CONCAT_EQUAL expr
| variable MOD_EQUAL expr
| variable AND_EQUAL expr
| variable ... | [
"def",
"p_expr_assign_op",
"(",
"p",
")",
":",
"p",
"[",
"0",
"]",
"=",
"ast",
".",
"AssignOp",
"(",
"p",
"[",
"2",
"]",
",",
"p",
"[",
"1",
"]",
",",
"p",
"[",
"3",
"]",
",",
"lineno",
"=",
"p",
".",
"lineno",
"(",
"2",
")",
")"
] | expr : variable PLUS_EQUAL expr
| variable MINUS_EQUAL expr
| variable MUL_EQUAL expr
| variable DIV_EQUAL expr
| variable CONCAT_EQUAL expr
| variable MOD_EQUAL expr
| variable AND_EQUAL expr
| variable OR_EQUAL expr
| vari... | [
"expr",
":",
"variable",
"PLUS_EQUAL",
"expr",
"|",
"variable",
"MINUS_EQUAL",
"expr",
"|",
"variable",
"MUL_EQUAL",
"expr",
"|",
"variable",
"DIV_EQUAL",
"expr",
"|",
"variable",
"CONCAT_EQUAL",
"expr",
"|",
"variable",
"MOD_EQUAL",
"expr",
"|",
"variable",
"AN... | python | train |
NLeSC/noodles | noodles/run/scheduler.py | https://github.com/NLeSC/noodles/blob/3759e24e6e54a3a1a364431309dbb1061f617c04/noodles/run/scheduler.py#L70-L159 | def run(self, connection: Connection, master: Workflow):
"""Run a workflow.
:param connection:
A connection giving a sink to the job-queue and a source yielding
results.
:type connection: Connection
:param master:
The workflow.
:type master: ... | [
"def",
"run",
"(",
"self",
",",
"connection",
":",
"Connection",
",",
"master",
":",
"Workflow",
")",
":",
"# initiate worker slave army and take up reins ...",
"source",
",",
"sink",
"=",
"connection",
".",
"setup",
"(",
")",
"# schedule work",
"self",
".",
"ad... | Run a workflow.
:param connection:
A connection giving a sink to the job-queue and a source yielding
results.
:type connection: Connection
:param master:
The workflow.
:type master: Workflow | [
"Run",
"a",
"workflow",
"."
] | python | train |
buildbot/buildbot | worker/buildbot_worker/runprocess.py | https://github.com/buildbot/buildbot/blob/5df3cfae6d760557d99156633c32b1822a1e130c/worker/buildbot_worker/runprocess.py#L671-L678 | def _sendMessage(self, msg):
"""
Collapse and send msg to the master
"""
if not msg:
return
msg = self._collapseMsg(msg)
self.sendStatus(msg) | [
"def",
"_sendMessage",
"(",
"self",
",",
"msg",
")",
":",
"if",
"not",
"msg",
":",
"return",
"msg",
"=",
"self",
".",
"_collapseMsg",
"(",
"msg",
")",
"self",
".",
"sendStatus",
"(",
"msg",
")"
] | Collapse and send msg to the master | [
"Collapse",
"and",
"send",
"msg",
"to",
"the",
"master"
] | python | train |
elastic/elasticsearch-py | elasticsearch/client/xpack/ml.py | https://github.com/elastic/elasticsearch-py/blob/2aab285c8f506f3863cbdaba3c90a685c510ba00/elasticsearch/client/xpack/ml.py#L674-L688 | def put_calendar_job(self, calendar_id, job_id, params=None):
"""
`<>`_
:arg calendar_id: The ID of the calendar to modify
:arg job_id: The ID of the job to add to the calendar
"""
for param in (calendar_id, job_id):
if param in SKIP_IN_PATH:
... | [
"def",
"put_calendar_job",
"(",
"self",
",",
"calendar_id",
",",
"job_id",
",",
"params",
"=",
"None",
")",
":",
"for",
"param",
"in",
"(",
"calendar_id",
",",
"job_id",
")",
":",
"if",
"param",
"in",
"SKIP_IN_PATH",
":",
"raise",
"ValueError",
"(",
"\"E... | `<>`_
:arg calendar_id: The ID of the calendar to modify
:arg job_id: The ID of the job to add to the calendar | [
"<",
">",
"_"
] | python | train |
buildbot/buildbot_travis | buildbot_travis/api.py | https://github.com/buildbot/buildbot_travis/blob/350c657b7aabaf5bc6a9fdb55febdd9d8eabd60c/buildbot_travis/api.py#L96-L117 | def saveConfig(self, request):
"""I save the config, and run check_config, potencially returning errors"""
res = yield self.assertAllowed(request)
if res:
defer.returnValue(res)
request.setHeader('Content-Type', 'application/json')
if self._in_progress:
de... | [
"def",
"saveConfig",
"(",
"self",
",",
"request",
")",
":",
"res",
"=",
"yield",
"self",
".",
"assertAllowed",
"(",
"request",
")",
"if",
"res",
":",
"defer",
".",
"returnValue",
"(",
"res",
")",
"request",
".",
"setHeader",
"(",
"'Content-Type'",
",",
... | I save the config, and run check_config, potencially returning errors | [
"I",
"save",
"the",
"config",
"and",
"run",
"check_config",
"potencially",
"returning",
"errors"
] | python | train |
rsheftel/raccoon | raccoon/dataframe.py | https://github.com/rsheftel/raccoon/blob/e5c4b5fb933b51f33aff11e8168c39790e9a7c75/raccoon/dataframe.py#L718-L751 | def append_rows(self, indexes, values, new_cols=True):
"""
Appends rows of values to the end of the data. If there are new columns in the values and new_cols is True
they will be added. Be very careful with this function as for sort DataFrames it will not enforce sort order.
Use this on... | [
"def",
"append_rows",
"(",
"self",
",",
"indexes",
",",
"values",
",",
"new_cols",
"=",
"True",
")",
":",
"# check that the values data is less than or equal to the length of the indexes",
"for",
"column",
"in",
"values",
":",
"if",
"len",
"(",
"values",
"[",
"colum... | Appends rows of values to the end of the data. If there are new columns in the values and new_cols is True
they will be added. Be very careful with this function as for sort DataFrames it will not enforce sort order.
Use this only for speed when needed, be careful.
:param indexes: list of inde... | [
"Appends",
"rows",
"of",
"values",
"to",
"the",
"end",
"of",
"the",
"data",
".",
"If",
"there",
"are",
"new",
"columns",
"in",
"the",
"values",
"and",
"new_cols",
"is",
"True",
"they",
"will",
"be",
"added",
".",
"Be",
"very",
"careful",
"with",
"this"... | python | train |
radjkarl/imgProcessor | imgProcessor/filters/removeSinglePixels.py | https://github.com/radjkarl/imgProcessor/blob/7c5a28718f81c01a430152c60a686ac50afbfd7c/imgProcessor/filters/removeSinglePixels.py#L5-L33 | def removeSinglePixels(img):
'''
img - boolean array
remove all pixels that have no neighbour
'''
gx = img.shape[0]
gy = img.shape[1]
for i in range(gx):
for j in range(gy):
if img[i, j]:
found_neighbour = False
for ii in... | [
"def",
"removeSinglePixels",
"(",
"img",
")",
":",
"gx",
"=",
"img",
".",
"shape",
"[",
"0",
"]",
"gy",
"=",
"img",
".",
"shape",
"[",
"1",
"]",
"for",
"i",
"in",
"range",
"(",
"gx",
")",
":",
"for",
"j",
"in",
"range",
"(",
"gy",
")",
":",
... | img - boolean array
remove all pixels that have no neighbour | [
"img",
"-",
"boolean",
"array",
"remove",
"all",
"pixels",
"that",
"have",
"no",
"neighbour"
] | python | train |
CivicSpleen/ambry | ambry/bundle/process.py | https://github.com/CivicSpleen/ambry/blob/d7f2be4bf1f7ffd086f3fadd4fcae60c32473e42/ambry/bundle/process.py#L135-L157 | def update(self, *args, **kwargs):
"""Update the last section record"""
self.augment_args(args, kwargs)
kwargs['log_action'] = kwargs.get('log_action', 'update')
if not self.rec:
return self.add(**kwargs)
else:
for k, v in kwargs.items():
... | [
"def",
"update",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"augment_args",
"(",
"args",
",",
"kwargs",
")",
"kwargs",
"[",
"'log_action'",
"]",
"=",
"kwargs",
".",
"get",
"(",
"'log_action'",
",",
"'update'",
")",... | Update the last section record | [
"Update",
"the",
"last",
"section",
"record"
] | python | train |
rackerlabs/fleece | fleece/requests.py | https://github.com/rackerlabs/fleece/blob/42d79dfa0777e99dbb09bc46105449a9be5dbaa9/fleece/requests.py#L39-L63 | def set_default_retries(*args, **kwargs):
"""
This function installs a default retry mechanism to be used in requests
calls. The arguments are those of urllib3's `Retry` object (see
http://urllib3.readthedocs.io/en/latest/reference/urllib3.util.html#urllib3.util.retry.Retry).
Examples:
# u... | [
"def",
"set_default_retries",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"global",
"DEFAULT_RETRY_ARGS",
"DEFAULT_RETRY_ARGS",
"=",
"kwargs",
"if",
"len",
"(",
"args",
")",
">",
"1",
":",
"ValueError",
"(",
"'too many arguments'",
")",
"elif",
"len... | This function installs a default retry mechanism to be used in requests
calls. The arguments are those of urllib3's `Retry` object (see
http://urllib3.readthedocs.io/en/latest/reference/urllib3.util.html#urllib3.util.retry.Retry).
Examples:
# use 3 retries, for default conditions only (network err... | [
"This",
"function",
"installs",
"a",
"default",
"retry",
"mechanism",
"to",
"be",
"used",
"in",
"requests",
"calls",
".",
"The",
"arguments",
"are",
"those",
"of",
"urllib3",
"s",
"Retry",
"object",
"(",
"see",
"http",
":",
"//",
"urllib3",
".",
"readthedo... | python | train |
duguyue100/minesweeper | minesweeper/msgame.py | https://github.com/duguyue100/minesweeper/blob/38b1910f4c34d0275ac10a300285aba6f1d91d61/minesweeper/msgame.py#L210-L229 | def parse_move(self, move_msg):
"""Parse a move from a string.
Parameters
----------
move_msg : string
a valid message should be in:
"[move type]: [X], [Y]"
Returns
-------
"""
# TODO: some condition check
type_idx = move_... | [
"def",
"parse_move",
"(",
"self",
",",
"move_msg",
")",
":",
"# TODO: some condition check",
"type_idx",
"=",
"move_msg",
".",
"index",
"(",
"\":\"",
")",
"move_type",
"=",
"move_msg",
"[",
":",
"type_idx",
"]",
"pos_idx",
"=",
"move_msg",
".",
"index",
"(",... | Parse a move from a string.
Parameters
----------
move_msg : string
a valid message should be in:
"[move type]: [X], [Y]"
Returns
------- | [
"Parse",
"a",
"move",
"from",
"a",
"string",
"."
] | python | train |
emilydolson/avida-spatial-tools | avidaspatial/utils.py | https://github.com/emilydolson/avida-spatial-tools/blob/7beb0166ccefad5fa722215b030ac2a53d62b59e/avidaspatial/utils.py#L217-L241 | def phenotype_to_res_set(phenotype, resources):
"""
Converts a binary string to a set containing the resources indicated by
the bits in the string.
Inputs: phenotype - a binary string
resources - a list of string indicating which resources correspond
to which indices... | [
"def",
"phenotype_to_res_set",
"(",
"phenotype",
",",
"resources",
")",
":",
"assert",
"(",
"phenotype",
"[",
"0",
":",
"2",
"]",
"==",
"\"0b\"",
")",
"phenotype",
"=",
"phenotype",
"[",
"2",
":",
"]",
"# Fill in leading zeroes",
"while",
"len",
"(",
"phen... | Converts a binary string to a set containing the resources indicated by
the bits in the string.
Inputs: phenotype - a binary string
resources - a list of string indicating which resources correspond
to which indices of the phenotype
returns: A set of strings indicating ... | [
"Converts",
"a",
"binary",
"string",
"to",
"a",
"set",
"containing",
"the",
"resources",
"indicated",
"by",
"the",
"bits",
"in",
"the",
"string",
"."
] | python | train |
CZ-NIC/python-rt | rt.py | https://github.com/CZ-NIC/python-rt/blob/e7a9f555e136708aec3317f857045145a2271e16/rt.py#L1359-L1389 | def edit_link(self, ticket_id, link_name, link_value, delete=False):
""" Creates or deletes a link between the specified tickets (undocumented API feature).
:param ticket_id: ID of ticket to edit
:param link_name: Name of link to edit (DependsOn, DependedOnBy,
RefersTo... | [
"def",
"edit_link",
"(",
"self",
",",
"ticket_id",
",",
"link_name",
",",
"link_value",
",",
"delete",
"=",
"False",
")",
":",
"valid_link_names",
"=",
"set",
"(",
"(",
"'dependson'",
",",
"'dependedonby'",
",",
"'refersto'",
",",
"'referredtoby'",
",",
"'ha... | Creates or deletes a link between the specified tickets (undocumented API feature).
:param ticket_id: ID of ticket to edit
:param link_name: Name of link to edit (DependsOn, DependedOnBy,
RefersTo, ReferredToBy, HasMember or MemberOf)
:param link_value: Either ticker I... | [
"Creates",
"or",
"deletes",
"a",
"link",
"between",
"the",
"specified",
"tickets",
"(",
"undocumented",
"API",
"feature",
")",
"."
] | python | train |
obulpathi/cdn-fastly-python | fastly/__init__.py | https://github.com/obulpathi/cdn-fastly-python/blob/db2564b047e8af4bce72c3b88d6c27d3d0291425/fastly/__init__.py#L882-L885 | def get_vcl(self, service_id, version_number, name, include_content=True):
"""Get the uploaded VCL for a particular service and version."""
content = self._fetch("/service/%s/version/%d/vcl/%s?include_content=%d" % (service_id, version_number, name, int(include_content)))
return FastlyVCL(self, content) | [
"def",
"get_vcl",
"(",
"self",
",",
"service_id",
",",
"version_number",
",",
"name",
",",
"include_content",
"=",
"True",
")",
":",
"content",
"=",
"self",
".",
"_fetch",
"(",
"\"/service/%s/version/%d/vcl/%s?include_content=%d\"",
"%",
"(",
"service_id",
",",
... | Get the uploaded VCL for a particular service and version. | [
"Get",
"the",
"uploaded",
"VCL",
"for",
"a",
"particular",
"service",
"and",
"version",
"."
] | python | train |
LEMS/pylems | lems/parser/expr.py | https://github.com/LEMS/pylems/blob/4eeb719d2f23650fe16c38626663b69b5c83818b/lems/parser/expr.py#L263-L315 | def tokenize(self):
"""
Tokenizes the string stored in the parser object into a list
of tokens.
"""
self.token_list = []
ps = self.parse_string.strip()
i = 0
last_token = None
while i < len(ps) and ps[i].isspace():
i += 1
wh... | [
"def",
"tokenize",
"(",
"self",
")",
":",
"self",
".",
"token_list",
"=",
"[",
"]",
"ps",
"=",
"self",
".",
"parse_string",
".",
"strip",
"(",
")",
"i",
"=",
"0",
"last_token",
"=",
"None",
"while",
"i",
"<",
"len",
"(",
"ps",
")",
"and",
"ps",
... | Tokenizes the string stored in the parser object into a list
of tokens. | [
"Tokenizes",
"the",
"string",
"stored",
"in",
"the",
"parser",
"object",
"into",
"a",
"list",
"of",
"tokens",
"."
] | python | train |
tensorflow/probability | tensorflow_probability/python/bijectors/bijector.py | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/python/bijectors/bijector.py#L122-L129 | def _deep_tuple(self, x):
"""Converts nested `tuple`, `list`, or `dict` to nested `tuple`."""
if isinstance(x, dict):
return self._deep_tuple(tuple(sorted(x.items())))
elif isinstance(x, (list, tuple)):
return tuple(map(self._deep_tuple, x))
return x | [
"def",
"_deep_tuple",
"(",
"self",
",",
"x",
")",
":",
"if",
"isinstance",
"(",
"x",
",",
"dict",
")",
":",
"return",
"self",
".",
"_deep_tuple",
"(",
"tuple",
"(",
"sorted",
"(",
"x",
".",
"items",
"(",
")",
")",
")",
")",
"elif",
"isinstance",
... | Converts nested `tuple`, `list`, or `dict` to nested `tuple`. | [
"Converts",
"nested",
"tuple",
"list",
"or",
"dict",
"to",
"nested",
"tuple",
"."
] | python | test |
ApproxEng/approxeng.input | src/python/approxeng/input/__init__.py | https://github.com/ApproxEng/approxeng.input/blob/0cdf8eed6bfd26ca3b20b4478f352787f60ae8ef/src/python/approxeng/input/__init__.py#L40-L72 | def map_single_axis(low, high, dead_zone, hot_zone, value):
"""
Apply dead and hot zones before mapping a value to a range. The dead and hot zones are both expressed as the
proportion of the axis range which should be regarded as 0.0 or 1.0 (or -1.0 depending on cardinality) respectively,
so for example... | [
"def",
"map_single_axis",
"(",
"low",
",",
"high",
",",
"dead_zone",
",",
"hot_zone",
",",
"value",
")",
":",
"input_range",
"=",
"high",
"-",
"low",
"corrected_low",
"=",
"low",
"+",
"input_range",
"*",
"dead_zone",
"corrected_high",
"=",
"high",
"-",
"in... | Apply dead and hot zones before mapping a value to a range. The dead and hot zones are both expressed as the
proportion of the axis range which should be regarded as 0.0 or 1.0 (or -1.0 depending on cardinality) respectively,
so for example setting dead zone to 0.2 means the first 20% of the range of the axis w... | [
"Apply",
"dead",
"and",
"hot",
"zones",
"before",
"mapping",
"a",
"value",
"to",
"a",
"range",
".",
"The",
"dead",
"and",
"hot",
"zones",
"are",
"both",
"expressed",
"as",
"the",
"proportion",
"of",
"the",
"axis",
"range",
"which",
"should",
"be",
"regar... | python | train |
pri22296/botify | botify/botify.py | https://github.com/pri22296/botify/blob/c3ff022f4c7314e508ffaa3ce1da1ef1e784afb2/botify/botify.py#L89-L120 | def add_modifier(self, modifier, keywords, relative_pos,
action, parameter=None):
"""Modify existing tasks based on presence of a keyword.
Parameters
----------
modifier : str
A string value which would trigger the given Modifier.
keywords : iter... | [
"def",
"add_modifier",
"(",
"self",
",",
"modifier",
",",
"keywords",
",",
"relative_pos",
",",
"action",
",",
"parameter",
"=",
"None",
")",
":",
"if",
"relative_pos",
"==",
"0",
":",
"raise",
"ValueError",
"(",
"\"relative_pos cannot be 0\"",
")",
"modifier_... | Modify existing tasks based on presence of a keyword.
Parameters
----------
modifier : str
A string value which would trigger the given Modifier.
keywords : iterable of str
sequence of strings which are keywords for some task,
which has to be modified... | [
"Modify",
"existing",
"tasks",
"based",
"on",
"presence",
"of",
"a",
"keyword",
"."
] | python | train |
barrust/mediawiki | mediawiki/mediawikipage.py | https://github.com/barrust/mediawiki/blob/292e0be6c752409062dceed325d74839caf16a9b/mediawiki/mediawikipage.py#L331-L348 | def backlinks(self):
""" list: Pages that link to this page
Note:
Not settable """
if self._backlinks is None:
self._backlinks = list()
params = {
"action": "query",
"list": "backlinks",
"bltitle": self.... | [
"def",
"backlinks",
"(",
"self",
")",
":",
"if",
"self",
".",
"_backlinks",
"is",
"None",
":",
"self",
".",
"_backlinks",
"=",
"list",
"(",
")",
"params",
"=",
"{",
"\"action\"",
":",
"\"query\"",
",",
"\"list\"",
":",
"\"backlinks\"",
",",
"\"bltitle\""... | list: Pages that link to this page
Note:
Not settable | [
"list",
":",
"Pages",
"that",
"link",
"to",
"this",
"page"
] | python | train |
gamechanger/dusty | dusty/systems/docker/__init__.py | https://github.com/gamechanger/dusty/blob/dc12de90bb6945023d6f43a8071e984313a1d984/dusty/systems/docker/__init__.py#L61-L72 | def get_dusty_containers(services, include_exited=False):
"""Get a list of containers associated with the list
of services. If no services are provided, attempts to
return all containers associated with Dusty."""
client = get_docker_client()
if services:
containers = [get_container_for_app_o... | [
"def",
"get_dusty_containers",
"(",
"services",
",",
"include_exited",
"=",
"False",
")",
":",
"client",
"=",
"get_docker_client",
"(",
")",
"if",
"services",
":",
"containers",
"=",
"[",
"get_container_for_app_or_service",
"(",
"service",
",",
"include_exited",
"... | Get a list of containers associated with the list
of services. If no services are provided, attempts to
return all containers associated with Dusty. | [
"Get",
"a",
"list",
"of",
"containers",
"associated",
"with",
"the",
"list",
"of",
"services",
".",
"If",
"no",
"services",
"are",
"provided",
"attempts",
"to",
"return",
"all",
"containers",
"associated",
"with",
"Dusty",
"."
] | python | valid |
scikit-learn-contrib/categorical-encoding | category_encoders/utils.py | https://github.com/scikit-learn-contrib/categorical-encoding/blob/5e9e803c9131b377af305d5302723ba2415001da/category_encoders/utils.py#L27-L36 | def get_obj_cols(df):
"""
Returns names of 'object' columns in the DataFrame.
"""
obj_cols = []
for idx, dt in enumerate(df.dtypes):
if dt == 'object' or is_category(dt):
obj_cols.append(df.columns.values[idx])
return obj_cols | [
"def",
"get_obj_cols",
"(",
"df",
")",
":",
"obj_cols",
"=",
"[",
"]",
"for",
"idx",
",",
"dt",
"in",
"enumerate",
"(",
"df",
".",
"dtypes",
")",
":",
"if",
"dt",
"==",
"'object'",
"or",
"is_category",
"(",
"dt",
")",
":",
"obj_cols",
".",
"append"... | Returns names of 'object' columns in the DataFrame. | [
"Returns",
"names",
"of",
"object",
"columns",
"in",
"the",
"DataFrame",
"."
] | python | valid |
django-admin-tools/django-admin-tools | admin_tools/utils.py | https://github.com/django-admin-tools/django-admin-tools/blob/ba6f46f51ebd84fcf84f2f79ec9487f45452d79b/admin_tools/utils.py#L20-L28 | def uniquify(value, seen_values):
""" Adds value to seen_values set and ensures it is unique """
id = 1
new_value = value
while new_value in seen_values:
new_value = "%s%s" % (value, id)
id += 1
seen_values.add(new_value)
return new_value | [
"def",
"uniquify",
"(",
"value",
",",
"seen_values",
")",
":",
"id",
"=",
"1",
"new_value",
"=",
"value",
"while",
"new_value",
"in",
"seen_values",
":",
"new_value",
"=",
"\"%s%s\"",
"%",
"(",
"value",
",",
"id",
")",
"id",
"+=",
"1",
"seen_values",
"... | Adds value to seen_values set and ensures it is unique | [
"Adds",
"value",
"to",
"seen_values",
"set",
"and",
"ensures",
"it",
"is",
"unique"
] | python | train |
bethgelab/foolbox | foolbox/criteria.py | https://github.com/bethgelab/foolbox/blob/8ab54248c70e45d8580a7d9ee44c9c0fb5755c4a/foolbox/criteria.py#L140-L157 | def name(self):
"""Concatenates the names of the given criteria in alphabetical order.
If a sub-criterion is itself a combined criterion, its name is
first split into the individual names and the names of the
sub-sub criteria is used instead of the name of the sub-criterion.
Thi... | [
"def",
"name",
"(",
"self",
")",
":",
"names",
"=",
"(",
"criterion",
".",
"name",
"(",
")",
"for",
"criterion",
"in",
"self",
".",
"_criteria",
")",
"return",
"'__'",
".",
"join",
"(",
"sorted",
"(",
"names",
")",
")"
] | Concatenates the names of the given criteria in alphabetical order.
If a sub-criterion is itself a combined criterion, its name is
first split into the individual names and the names of the
sub-sub criteria is used instead of the name of the sub-criterion.
This is done recursively to en... | [
"Concatenates",
"the",
"names",
"of",
"the",
"given",
"criteria",
"in",
"alphabetical",
"order",
"."
] | python | valid |
numenta/htmresearch | projects/nik/nik_htm.py | https://github.com/numenta/htmresearch/blob/70c096b09a577ea0432c3f3bfff4442d4871b7aa/projects/nik/nik_htm.py#L200-L209 | def encodeThetas(self, theta1, theta2):
"""Return the SDR for theta1 and theta2"""
# print >> sys.stderr, "encoded theta1 value = ", theta1
# print >> sys.stderr, "encoded theta2 value = ", theta2
t1e = self.theta1Encoder.encode(theta1)
t2e = self.theta2Encoder.encode(theta2)
# print >> sys.stde... | [
"def",
"encodeThetas",
"(",
"self",
",",
"theta1",
",",
"theta2",
")",
":",
"# print >> sys.stderr, \"encoded theta1 value = \", theta1",
"# print >> sys.stderr, \"encoded theta2 value = \", theta2",
"t1e",
"=",
"self",
".",
"theta1Encoder",
".",
"encode",
"(",
"theta1",
")... | Return the SDR for theta1 and theta2 | [
"Return",
"the",
"SDR",
"for",
"theta1",
"and",
"theta2"
] | python | train |
CalebBell/fluids | fluids/safety_valve.py | https://github.com/CalebBell/fluids/blob/57f556752e039f1d3e5a822f408c184783db2828/fluids/safety_valve.py#L507-L582 | def API520_A_g(m, T, Z, MW, k, P1, P2=101325, Kd=0.975, Kb=1, Kc=1):
r'''Calculates required relief valve area for an API 520 valve passing
a gas or a vapor, at either critical or sub-critical flow.
For critical flow:
.. math::
A = \frac{m}{CK_dP_1K_bK_c}\sqrt{\frac{TZ}{M}}
For sub-critic... | [
"def",
"API520_A_g",
"(",
"m",
",",
"T",
",",
"Z",
",",
"MW",
",",
"k",
",",
"P1",
",",
"P2",
"=",
"101325",
",",
"Kd",
"=",
"0.975",
",",
"Kb",
"=",
"1",
",",
"Kc",
"=",
"1",
")",
":",
"P1",
",",
"P2",
"=",
"P1",
"/",
"1000.",
",",
"P2... | r'''Calculates required relief valve area for an API 520 valve passing
a gas or a vapor, at either critical or sub-critical flow.
For critical flow:
.. math::
A = \frac{m}{CK_dP_1K_bK_c}\sqrt{\frac{TZ}{M}}
For sub-critical flow:
.. math::
A = \frac{17.9m}{F_2K_dK_c}\sqrt{\frac{TZ... | [
"r",
"Calculates",
"required",
"relief",
"valve",
"area",
"for",
"an",
"API",
"520",
"valve",
"passing",
"a",
"gas",
"or",
"a",
"vapor",
"at",
"either",
"critical",
"or",
"sub",
"-",
"critical",
"flow",
"."
] | python | train |
fugue/credstash | credstash-migrate-autoversion.py | https://github.com/fugue/credstash/blob/56df8e051fc4c8d15d5e7e373e88bf5bc13f3346/credstash-migrate-autoversion.py#L16-L37 | def updateVersions(region="us-east-1", table="credential-store"):
'''
do a full-table scan of the credential-store,
and update the version format of every credential if it is an integer
'''
dynamodb = boto3.resource('dynamodb', region_name=region)
secrets = dynamodb.Table(table)
response = ... | [
"def",
"updateVersions",
"(",
"region",
"=",
"\"us-east-1\"",
",",
"table",
"=",
"\"credential-store\"",
")",
":",
"dynamodb",
"=",
"boto3",
".",
"resource",
"(",
"'dynamodb'",
",",
"region_name",
"=",
"region",
")",
"secrets",
"=",
"dynamodb",
".",
"Table",
... | do a full-table scan of the credential-store,
and update the version format of every credential if it is an integer | [
"do",
"a",
"full",
"-",
"table",
"scan",
"of",
"the",
"credential",
"-",
"store",
"and",
"update",
"the",
"version",
"format",
"of",
"every",
"credential",
"if",
"it",
"is",
"an",
"integer"
] | python | train |
TDG-Platform/cloud-harness | gbdx_task_template/task.py | https://github.com/TDG-Platform/cloud-harness/blob/1d8f972f861816b90785a484e9bec5bd4bc2f569/gbdx_task_template/task.py#L101-L129 | def is_valid(self, remote=False):
"""
Check cloud-harness code is valid. task schema validation is
left to the API endpoint.
:param remote: Flag indicating if the task is being ran on the platform or not.
:return: is valid or not.
"""
if len(self.input_ports) < 1... | [
"def",
"is_valid",
"(",
"self",
",",
"remote",
"=",
"False",
")",
":",
"if",
"len",
"(",
"self",
".",
"input_ports",
")",
"<",
"1",
":",
"return",
"False",
"if",
"remote",
":",
"# Ignore output ports as value will overriden.",
"ports",
"=",
"[",
"port",
"f... | Check cloud-harness code is valid. task schema validation is
left to the API endpoint.
:param remote: Flag indicating if the task is being ran on the platform or not.
:return: is valid or not. | [
"Check",
"cloud",
"-",
"harness",
"code",
"is",
"valid",
".",
"task",
"schema",
"validation",
"is",
"left",
"to",
"the",
"API",
"endpoint",
".",
":",
"param",
"remote",
":",
"Flag",
"indicating",
"if",
"the",
"task",
"is",
"being",
"ran",
"on",
"the",
... | python | test |
romanz/trezor-agent | libagent/gpg/decode.py | https://github.com/romanz/trezor-agent/blob/513b1259c4d7aca5f88cd958edc11828d0712f1b/libagent/gpg/decode.py#L140-L187 | def _parse_pubkey(stream, packet_type='pubkey'):
"""See https://tools.ietf.org/html/rfc4880#section-5.5 for details."""
p = {'type': packet_type}
packet = io.BytesIO()
with stream.capture(packet):
p['version'] = stream.readfmt('B')
p['created'] = stream.readfmt('>L')
p['algo'] = ... | [
"def",
"_parse_pubkey",
"(",
"stream",
",",
"packet_type",
"=",
"'pubkey'",
")",
":",
"p",
"=",
"{",
"'type'",
":",
"packet_type",
"}",
"packet",
"=",
"io",
".",
"BytesIO",
"(",
")",
"with",
"stream",
".",
"capture",
"(",
"packet",
")",
":",
"p",
"["... | See https://tools.ietf.org/html/rfc4880#section-5.5 for details. | [
"See",
"https",
":",
"//",
"tools",
".",
"ietf",
".",
"org",
"/",
"html",
"/",
"rfc4880#section",
"-",
"5",
".",
"5",
"for",
"details",
"."
] | python | train |
facelessuser/pyspelling | pyspelling/filters/stylesheets.py | https://github.com/facelessuser/pyspelling/blob/c25d5292cc2687ad65891a12ead43f7182ca8bb3/pyspelling/filters/stylesheets.py#L62-L71 | def setup(self):
"""Setup."""
self.blocks = self.config['block_comments']
self.lines = self.config['line_comments']
self.group_comments = self.config['group_comments']
# If the style isn't found, just go with CSS, then use the appropriate prefix.
self.stylesheets = STYLE... | [
"def",
"setup",
"(",
"self",
")",
":",
"self",
".",
"blocks",
"=",
"self",
".",
"config",
"[",
"'block_comments'",
"]",
"self",
".",
"lines",
"=",
"self",
".",
"config",
"[",
"'line_comments'",
"]",
"self",
".",
"group_comments",
"=",
"self",
".",
"con... | Setup. | [
"Setup",
"."
] | python | train |
ManiacalLabs/BiblioPixel | bibliopixel/layout/matrix_drawing.py | https://github.com/ManiacalLabs/BiblioPixel/blob/fd97e6c651a4bbcade64733847f4eec8f7704b7c/bibliopixel/layout/matrix_drawing.py#L273-L279 | def fill_round_rect(setter, x, y, w, h, r, color=None, aa=False):
"""Draw solid rectangle with top-left corner at x,y, width w, height h,
and corner radius r"""
fill_rect(setter, x + r, y, w - 2 * r, h, color, aa)
_fill_circle_helper(setter, x + w - r - 1, y + r, r,
1, h - 2 * r ... | [
"def",
"fill_round_rect",
"(",
"setter",
",",
"x",
",",
"y",
",",
"w",
",",
"h",
",",
"r",
",",
"color",
"=",
"None",
",",
"aa",
"=",
"False",
")",
":",
"fill_rect",
"(",
"setter",
",",
"x",
"+",
"r",
",",
"y",
",",
"w",
"-",
"2",
"*",
"r",... | Draw solid rectangle with top-left corner at x,y, width w, height h,
and corner radius r | [
"Draw",
"solid",
"rectangle",
"with",
"top",
"-",
"left",
"corner",
"at",
"x",
"y",
"width",
"w",
"height",
"h",
"and",
"corner",
"radius",
"r"
] | python | valid |
mushkevych/scheduler | synergy/system/utils.py | https://github.com/mushkevych/scheduler/blob/6740331360f49083c208085fb5a60ce80ebf418b/synergy/system/utils.py#L91-L99 | def remove_pid_file(process_name):
""" removes pid file """
pid_filename = get_pid_filename(process_name)
try:
os.remove(pid_filename)
print('Removed pid file at: {0}'.format(pid_filename), file=sys.stdout)
except Exception as e:
print('Unable to remove pid file at: {0}, because ... | [
"def",
"remove_pid_file",
"(",
"process_name",
")",
":",
"pid_filename",
"=",
"get_pid_filename",
"(",
"process_name",
")",
"try",
":",
"os",
".",
"remove",
"(",
"pid_filename",
")",
"print",
"(",
"'Removed pid file at: {0}'",
".",
"format",
"(",
"pid_filename",
... | removes pid file | [
"removes",
"pid",
"file"
] | python | train |
blockcypher/blockcypher-python | blockcypher/api.py | https://github.com/blockcypher/blockcypher-python/blob/7601ea21916957ff279384fd699527ff9c28a56e/blockcypher/api.py#L1436-L1508 | def verify_unsigned_tx(unsigned_tx, outputs, inputs=None, sweep_funds=False,
change_address=None, coin_symbol='btc'):
'''
Takes an unsigned transaction and what was used to build it (in
create_unsigned_tx) and verifies that tosign_tx matches what is being
signed and what was reque... | [
"def",
"verify_unsigned_tx",
"(",
"unsigned_tx",
",",
"outputs",
",",
"inputs",
"=",
"None",
",",
"sweep_funds",
"=",
"False",
",",
"change_address",
"=",
"None",
",",
"coin_symbol",
"=",
"'btc'",
")",
":",
"if",
"not",
"(",
"change_address",
"or",
"sweep_fu... | Takes an unsigned transaction and what was used to build it (in
create_unsigned_tx) and verifies that tosign_tx matches what is being
signed and what was requestsed to be signed.
Returns if valid:
(True, '')
Returns if invalid:
(False, 'err_msg')
Specifically, this checks that the ... | [
"Takes",
"an",
"unsigned",
"transaction",
"and",
"what",
"was",
"used",
"to",
"build",
"it",
"(",
"in",
"create_unsigned_tx",
")",
"and",
"verifies",
"that",
"tosign_tx",
"matches",
"what",
"is",
"being",
"signed",
"and",
"what",
"was",
"requestsed",
"to",
"... | python | train |
bitesofcode/projexui | projexui/widgets/xgroupbox.py | https://github.com/bitesofcode/projexui/blob/f18a73bec84df90b034ca69b9deea118dbedfc4d/projexui/widgets/xgroupbox.py#L99-L126 | def matchCollapsedState( self ):
"""
Matches the collapsed state for this groupbox.
"""
collapsed = not self.isChecked()
if self._inverted:
collapsed = not collapsed
if ( not self.isCollapsible() or not collapsed ):
for child in self.c... | [
"def",
"matchCollapsedState",
"(",
"self",
")",
":",
"collapsed",
"=",
"not",
"self",
".",
"isChecked",
"(",
")",
"if",
"self",
".",
"_inverted",
":",
"collapsed",
"=",
"not",
"collapsed",
"if",
"(",
"not",
"self",
".",
"isCollapsible",
"(",
")",
"or",
... | Matches the collapsed state for this groupbox. | [
"Matches",
"the",
"collapsed",
"state",
"for",
"this",
"groupbox",
"."
] | python | train |
apache/incubator-superset | superset/forms.py | https://github.com/apache/incubator-superset/blob/ca2996c78f679260eb79c6008e276733df5fb653/superset/forms.py#L50-L57 | def filter_not_empty_values(value):
"""Returns a list of non empty values or None"""
if not value:
return None
data = [x for x in value if x]
if not data:
return None
return data | [
"def",
"filter_not_empty_values",
"(",
"value",
")",
":",
"if",
"not",
"value",
":",
"return",
"None",
"data",
"=",
"[",
"x",
"for",
"x",
"in",
"value",
"if",
"x",
"]",
"if",
"not",
"data",
":",
"return",
"None",
"return",
"data"
] | Returns a list of non empty values or None | [
"Returns",
"a",
"list",
"of",
"non",
"empty",
"values",
"or",
"None"
] | python | train |
HIPS/autograd | autograd/misc/optimizers.py | https://github.com/HIPS/autograd/blob/e3b525302529d7490769d5c0bcfc7457e24e3b3e/autograd/misc/optimizers.py#L16-L30 | def unflatten_optimizer(optimize):
"""Takes an optimizer that operates on flat 1D numpy arrays and returns a
wrapped version that handles trees of nested containers (lists/tuples/dicts)
with arrays/scalars at the leaves."""
@wraps(optimize)
def _optimize(grad, x0, callback=None, *args, **kwargs):
... | [
"def",
"unflatten_optimizer",
"(",
"optimize",
")",
":",
"@",
"wraps",
"(",
"optimize",
")",
"def",
"_optimize",
"(",
"grad",
",",
"x0",
",",
"callback",
"=",
"None",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"_x0",
",",
"unflatten",
"=",
... | Takes an optimizer that operates on flat 1D numpy arrays and returns a
wrapped version that handles trees of nested containers (lists/tuples/dicts)
with arrays/scalars at the leaves. | [
"Takes",
"an",
"optimizer",
"that",
"operates",
"on",
"flat",
"1D",
"numpy",
"arrays",
"and",
"returns",
"a",
"wrapped",
"version",
"that",
"handles",
"trees",
"of",
"nested",
"containers",
"(",
"lists",
"/",
"tuples",
"/",
"dicts",
")",
"with",
"arrays",
... | python | train |
nuagenetworks/bambou | bambou/nurest_modelcontroller.py | https://github.com/nuagenetworks/bambou/blob/d334fea23e384d3df8e552fe1849ad707941c666/bambou/nurest_modelcontroller.py#L121-L133 | def get_first_model_with_resource_name(cls, resource_name):
""" Get the first model corresponding to a resource_name
Args:
resource_name: the resource name
"""
models = cls.get_models_with_resource_name(resource_name)
if len(models) > 0:
return ... | [
"def",
"get_first_model_with_resource_name",
"(",
"cls",
",",
"resource_name",
")",
":",
"models",
"=",
"cls",
".",
"get_models_with_resource_name",
"(",
"resource_name",
")",
"if",
"len",
"(",
"models",
")",
">",
"0",
":",
"return",
"models",
"[",
"0",
"]",
... | Get the first model corresponding to a resource_name
Args:
resource_name: the resource name | [
"Get",
"the",
"first",
"model",
"corresponding",
"to",
"a",
"resource_name"
] | python | train |
roclark/sportsreference | sportsreference/ncaaf/rankings.py | https://github.com/roclark/sportsreference/blob/ea0bae432be76450e137671d2998eb38f962dffd/sportsreference/ncaaf/rankings.py#L49-L75 | def _get_team(self, team):
"""
Retrieve team's name and abbreviation.
The team's name and abbreviation are embedded within the 'school_name'
tag and, in the case of the abbreviation, require special parsing as it
is located in the middle of a URI. The name and abbreviation are
... | [
"def",
"_get_team",
"(",
"self",
",",
"team",
")",
":",
"name_tag",
"=",
"team",
"(",
"'td[data-stat=\"school_name\"]'",
")",
"abbreviation",
"=",
"re",
".",
"sub",
"(",
"r'.*/cfb/schools/'",
",",
"''",
",",
"str",
"(",
"name_tag",
"(",
"'a'",
")",
")",
... | Retrieve team's name and abbreviation.
The team's name and abbreviation are embedded within the 'school_name'
tag and, in the case of the abbreviation, require special parsing as it
is located in the middle of a URI. The name and abbreviation are
returned for the requested school.
... | [
"Retrieve",
"team",
"s",
"name",
"and",
"abbreviation",
"."
] | python | train |
StackStorm/pybind | pybind/nos/v6_0_2f/rbridge_id/threshold_monitor/interface/policy/area/__init__.py | https://github.com/StackStorm/pybind/blob/44c467e71b2b425be63867aba6e6fa28b2cfe7fb/pybind/nos/v6_0_2f/rbridge_id/threshold_monitor/interface/policy/area/__init__.py#L134-L160 | def _set_area_value(self, v, load=False):
"""
Setter method for area_value, mapped from YANG variable /rbridge_id/threshold_monitor/interface/policy/area/area_value (enumeration)
If this variable is read-only (config: false) in the
source YANG file, then _set_area_value is considered as a private
me... | [
"def",
"_set_area_value",
"(",
"self",
",",
"v",
",",
"load",
"=",
"False",
")",
":",
"parent",
"=",
"getattr",
"(",
"self",
",",
"\"_parent\"",
",",
"None",
")",
"if",
"parent",
"is",
"not",
"None",
"and",
"load",
"is",
"False",
":",
"raise",
"Attri... | Setter method for area_value, mapped from YANG variable /rbridge_id/threshold_monitor/interface/policy/area/area_value (enumeration)
If this variable is read-only (config: false) in the
source YANG file, then _set_area_value is considered as a private
method. Backends looking to populate this variable shoul... | [
"Setter",
"method",
"for",
"area_value",
"mapped",
"from",
"YANG",
"variable",
"/",
"rbridge_id",
"/",
"threshold_monitor",
"/",
"interface",
"/",
"policy",
"/",
"area",
"/",
"area_value",
"(",
"enumeration",
")",
"If",
"this",
"variable",
"is",
"read",
"-",
... | python | train |
ejhigson/nestcheck | nestcheck/diagnostics_tables.py | https://github.com/ejhigson/nestcheck/blob/29151c314deb89746fd674f27f6ce54b77603189/nestcheck/diagnostics_tables.py#L172-L228 | def error_values_summary(error_values, **summary_df_kwargs):
"""Get summary statistics about calculation errors, including estimated
implementation errors.
Parameters
----------
error_values: pandas DataFrame
Of format output by run_list_error_values (look at it for more
details).
... | [
"def",
"error_values_summary",
"(",
"error_values",
",",
"*",
"*",
"summary_df_kwargs",
")",
":",
"df",
"=",
"pf",
".",
"summary_df_from_multi",
"(",
"error_values",
",",
"*",
"*",
"summary_df_kwargs",
")",
"# get implementation stds",
"imp_std",
",",
"imp_std_unc",... | Get summary statistics about calculation errors, including estimated
implementation errors.
Parameters
----------
error_values: pandas DataFrame
Of format output by run_list_error_values (look at it for more
details).
summary_df_kwargs: dict, optional
See pandas_functions.su... | [
"Get",
"summary",
"statistics",
"about",
"calculation",
"errors",
"including",
"estimated",
"implementation",
"errors",
"."
] | python | train |
decryptus/sonicprobe | sonicprobe/libs/xys.py | https://github.com/decryptus/sonicprobe/blob/72f73f3a40d2982d79ad68686e36aa31d94b76f8/sonicprobe/libs/xys.py#L668-L847 | def validate(document, schema, log_qualifier = True):
"""
If the document is valid according to the schema, this function returns
True.
If the document is not valid according to the schema, errors are logged
then False is returned.
"""
if isinstance(schema, ValidatorNode):
if not val... | [
"def",
"validate",
"(",
"document",
",",
"schema",
",",
"log_qualifier",
"=",
"True",
")",
":",
"if",
"isinstance",
"(",
"schema",
",",
"ValidatorNode",
")",
":",
"if",
"not",
"validate",
"(",
"document",
",",
"schema",
".",
"content",
")",
":",
"return"... | If the document is valid according to the schema, this function returns
True.
If the document is not valid according to the schema, errors are logged
then False is returned. | [
"If",
"the",
"document",
"is",
"valid",
"according",
"to",
"the",
"schema",
"this",
"function",
"returns",
"True",
".",
"If",
"the",
"document",
"is",
"not",
"valid",
"according",
"to",
"the",
"schema",
"errors",
"are",
"logged",
"then",
"False",
"is",
"re... | python | train |
GoogleCloudPlatform/cloud-debug-python | src/googleclouddebugger/capture_collector.py | https://github.com/GoogleCloudPlatform/cloud-debug-python/blob/89ce3782c98b814838a3ecb5479ed3882368cbee/src/googleclouddebugger/capture_collector.py#L157-L175 | def GetLoggingLocation():
"""Search for and return the file and line number from the log collector.
Returns:
(pathname, lineno, func_name) The full path, line number, and function name
for the logpoint location.
"""
frame = inspect.currentframe()
this_file = frame.f_code.co_filename
frame = frame.f... | [
"def",
"GetLoggingLocation",
"(",
")",
":",
"frame",
"=",
"inspect",
".",
"currentframe",
"(",
")",
"this_file",
"=",
"frame",
".",
"f_code",
".",
"co_filename",
"frame",
"=",
"frame",
".",
"f_back",
"while",
"frame",
":",
"if",
"this_file",
"==",
"frame",... | Search for and return the file and line number from the log collector.
Returns:
(pathname, lineno, func_name) The full path, line number, and function name
for the logpoint location. | [
"Search",
"for",
"and",
"return",
"the",
"file",
"and",
"line",
"number",
"from",
"the",
"log",
"collector",
"."
] | python | train |
BrewBlox/brewblox-service | brewblox_service/scheduler.py | https://github.com/BrewBlox/brewblox-service/blob/f2572fcb5ea337c24aa5a28c2b0b19ebcfc076eb/brewblox_service/scheduler.py#L24-L58 | async def create_task(app: web.Application,
coro: Coroutine,
*args, **kwargs
) -> asyncio.Task:
"""
Convenience function for calling `TaskScheduler.create(coro)`
This will use the default `TaskScheduler` to create a new background task.
... | [
"async",
"def",
"create_task",
"(",
"app",
":",
"web",
".",
"Application",
",",
"coro",
":",
"Coroutine",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
"->",
"asyncio",
".",
"Task",
":",
"return",
"await",
"get_scheduler",
"(",
"app",
")",
".",
"cr... | Convenience function for calling `TaskScheduler.create(coro)`
This will use the default `TaskScheduler` to create a new background task.
Example:
import asyncio
from datetime import datetime
from brewblox_service import scheduler, service
async def current_time(interval):
... | [
"Convenience",
"function",
"for",
"calling",
"TaskScheduler",
".",
"create",
"(",
"coro",
")"
] | python | train |
kontron/python-aardvark | pyaardvark/aardvark.py | https://github.com/kontron/python-aardvark/blob/9827f669fbdc5bceb98e7d08a294b4e4e455d0d5/pyaardvark/aardvark.py#L620-L626 | def spi_ss_polarity(self, polarity):
"""Change the ouput polarity on the SS line.
Please note, that this only affects the master functions.
"""
ret = api.py_aa_spi_master_ss_polarity(self.handle, polarity)
_raise_error_if_negative(ret) | [
"def",
"spi_ss_polarity",
"(",
"self",
",",
"polarity",
")",
":",
"ret",
"=",
"api",
".",
"py_aa_spi_master_ss_polarity",
"(",
"self",
".",
"handle",
",",
"polarity",
")",
"_raise_error_if_negative",
"(",
"ret",
")"
] | Change the ouput polarity on the SS line.
Please note, that this only affects the master functions. | [
"Change",
"the",
"ouput",
"polarity",
"on",
"the",
"SS",
"line",
"."
] | python | train |
a1ezzz/wasp-general | wasp_general/task/thread_tracker.py | https://github.com/a1ezzz/wasp-general/blob/1029839d33eb663f8dec76c1c46754d53c1de4a9/wasp_general/task/thread_tracker.py#L494-L508 | def last_record(self, task_uid, *requested_events):
""" Search over registered :class:`.WScheduleTask` instances and return the last record that matches
search criteria.
:param task_uid: uid of :class:`.WScheduleTask` instance
:param requested_events: target events types
:return: WSimpleTrackerStorage.Recor... | [
"def",
"last_record",
"(",
"self",
",",
"task_uid",
",",
"*",
"requested_events",
")",
":",
"for",
"record",
"in",
"self",
":",
"if",
"isinstance",
"(",
"record",
".",
"thread_task",
",",
"WScheduleTask",
")",
"is",
"False",
":",
"continue",
"if",
"record"... | Search over registered :class:`.WScheduleTask` instances and return the last record that matches
search criteria.
:param task_uid: uid of :class:`.WScheduleTask` instance
:param requested_events: target events types
:return: WSimpleTrackerStorage.Record or None | [
"Search",
"over",
"registered",
":",
"class",
":",
".",
"WScheduleTask",
"instances",
"and",
"return",
"the",
"last",
"record",
"that",
"matches",
"search",
"criteria",
"."
] | python | train |
alephdata/memorious | memorious/ui/views.py | https://github.com/alephdata/memorious/blob/b4033c5064447ed5f696f9c2bbbc6c12062d2fa4/memorious/ui/views.py#L67-L77 | def index():
"""Generate a list of all crawlers, alphabetically, with op counts."""
crawlers = []
for crawler in manager:
data = Event.get_counts(crawler)
data['last_active'] = crawler.last_run
data['total_ops'] = crawler.op_count
data['running'] = crawler.is_running
... | [
"def",
"index",
"(",
")",
":",
"crawlers",
"=",
"[",
"]",
"for",
"crawler",
"in",
"manager",
":",
"data",
"=",
"Event",
".",
"get_counts",
"(",
"crawler",
")",
"data",
"[",
"'last_active'",
"]",
"=",
"crawler",
".",
"last_run",
"data",
"[",
"'total_ops... | Generate a list of all crawlers, alphabetically, with op counts. | [
"Generate",
"a",
"list",
"of",
"all",
"crawlers",
"alphabetically",
"with",
"op",
"counts",
"."
] | python | train |
CGATOxford/UMI-tools | umi_tools/sam_methods.py | https://github.com/CGATOxford/UMI-tools/blob/c4b5d84aac391d59916d294f8f4f8f5378abcfbe/umi_tools/sam_methods.py#L92-L103 | def get_cell_umi_read_string(read_id, sep="_"):
''' extract the umi and cell barcode from the read id (input as a
string) using the specified separator '''
try:
return (read_id.split(sep)[-1].encode('utf-8'),
read_id.split(sep)[-2].encode('utf-8'))
except IndexError:
rai... | [
"def",
"get_cell_umi_read_string",
"(",
"read_id",
",",
"sep",
"=",
"\"_\"",
")",
":",
"try",
":",
"return",
"(",
"read_id",
".",
"split",
"(",
"sep",
")",
"[",
"-",
"1",
"]",
".",
"encode",
"(",
"'utf-8'",
")",
",",
"read_id",
".",
"split",
"(",
"... | extract the umi and cell barcode from the read id (input as a
string) using the specified separator | [
"extract",
"the",
"umi",
"and",
"cell",
"barcode",
"from",
"the",
"read",
"id",
"(",
"input",
"as",
"a",
"string",
")",
"using",
"the",
"specified",
"separator"
] | python | train |
twitterdev/tweet_parser | tweet_parser/getter_methods/tweet_user.py | https://github.com/twitterdev/tweet_parser/blob/3435de8367d36b483a6cfd8d46cc28694ee8a42e/tweet_parser/getter_methods/tweet_user.py#L114-L153 | def get_bio(tweet):
"""
Get the bio text of the user who posted the Tweet
Args:
tweet (Tweet): A Tweet object (or a dictionary)
Returns:
str: the bio text of the user who posted the Tweet
In a payload the abscence of a bio seems to be represented by an
empty string or a... | [
"def",
"get_bio",
"(",
"tweet",
")",
":",
"if",
"is_original_format",
"(",
"tweet",
")",
":",
"bio_or_none",
"=",
"tweet",
"[",
"\"user\"",
"]",
".",
"get",
"(",
"\"description\"",
",",
"\"\"",
")",
"else",
":",
"bio_or_none",
"=",
"tweet",
"[",
"\"actor... | Get the bio text of the user who posted the Tweet
Args:
tweet (Tweet): A Tweet object (or a dictionary)
Returns:
str: the bio text of the user who posted the Tweet
In a payload the abscence of a bio seems to be represented by an
empty string or a None, this getter always return... | [
"Get",
"the",
"bio",
"text",
"of",
"the",
"user",
"who",
"posted",
"the",
"Tweet"
] | python | train |
cloud9ers/gurumate | environment/lib/python2.7/site-packages/nose/plugins/manager.py | https://github.com/cloud9ers/gurumate/blob/075dc74d1ee62a8c6b7a8bf2b271364f01629d1e/environment/lib/python2.7/site-packages/nose/plugins/manager.py#L146-L161 | def generate(self, *arg, **kw):
"""Call all plugins, yielding each item in each non-None result.
"""
for p, meth in self.plugins:
result = None
try:
result = meth(*arg, **kw)
if result is not None:
for r in result:
... | [
"def",
"generate",
"(",
"self",
",",
"*",
"arg",
",",
"*",
"*",
"kw",
")",
":",
"for",
"p",
",",
"meth",
"in",
"self",
".",
"plugins",
":",
"result",
"=",
"None",
"try",
":",
"result",
"=",
"meth",
"(",
"*",
"arg",
",",
"*",
"*",
"kw",
")",
... | Call all plugins, yielding each item in each non-None result. | [
"Call",
"all",
"plugins",
"yielding",
"each",
"item",
"in",
"each",
"non",
"-",
"None",
"result",
"."
] | python | test |
Jammy2211/PyAutoLens | autolens/data/ccd.py | https://github.com/Jammy2211/PyAutoLens/blob/91e50369c7a9c048c83d217625578b72423cd5a7/autolens/data/ccd.py#L416-L420 | def estimated_noise_map_counts(self):
""" The estimated noise_maps mappers of the image (using its background noise_maps mappers and image values
in counts) in counts.
"""
return np.sqrt((np.abs(self.image_counts) + np.square(self.background_noise_map_counts))) | [
"def",
"estimated_noise_map_counts",
"(",
"self",
")",
":",
"return",
"np",
".",
"sqrt",
"(",
"(",
"np",
".",
"abs",
"(",
"self",
".",
"image_counts",
")",
"+",
"np",
".",
"square",
"(",
"self",
".",
"background_noise_map_counts",
")",
")",
")"
] | The estimated noise_maps mappers of the image (using its background noise_maps mappers and image values
in counts) in counts. | [
"The",
"estimated",
"noise_maps",
"mappers",
"of",
"the",
"image",
"(",
"using",
"its",
"background",
"noise_maps",
"mappers",
"and",
"image",
"values",
"in",
"counts",
")",
"in",
"counts",
"."
] | python | valid |
drewsonne/aws-autodiscovery-templater | awsautodiscoverytemplater/command.py | https://github.com/drewsonne/aws-autodiscovery-templater/blob/9ef2edd6a373aeb5d343b841550c210966efe079/awsautodiscoverytemplater/command.py#L205-L244 | def _process_reservations(self, reservations):
"""
Given a dict with the structure of a response from boto3.ec2.describe_instances(...),
find the public/private ips.
:param reservations:
:return:
"""
reservations = reservations['Reservations']
private_ip... | [
"def",
"_process_reservations",
"(",
"self",
",",
"reservations",
")",
":",
"reservations",
"=",
"reservations",
"[",
"'Reservations'",
"]",
"private_ip_addresses",
"=",
"[",
"]",
"private_hostnames",
"=",
"[",
"]",
"public_ips",
"=",
"[",
"]",
"public_hostnames",... | Given a dict with the structure of a response from boto3.ec2.describe_instances(...),
find the public/private ips.
:param reservations:
:return: | [
"Given",
"a",
"dict",
"with",
"the",
"structure",
"of",
"a",
"response",
"from",
"boto3",
".",
"ec2",
".",
"describe_instances",
"(",
"...",
")",
"find",
"the",
"public",
"/",
"private",
"ips",
".",
":",
"param",
"reservations",
":",
":",
"return",
":"
] | python | train |
maxfischer2781/chainlet | chainlet/genlink.py | https://github.com/maxfischer2781/chainlet/blob/4e17f9992b4780bd0d9309202e2847df640bffe8/chainlet/genlink.py#L203-L239 | def genlet(generator_function=None, prime=True):
"""
Decorator to convert a generator function to a :py:class:`~chainlink.ChainLink`
:param generator_function: the generator function to convert
:type generator_function: generator
:param prime: advance the generator to the next/first yield
:type... | [
"def",
"genlet",
"(",
"generator_function",
"=",
"None",
",",
"prime",
"=",
"True",
")",
":",
"if",
"generator_function",
"is",
"None",
":",
"return",
"GeneratorLink",
".",
"wraplet",
"(",
"prime",
"=",
"prime",
")",
"elif",
"not",
"callable",
"(",
"genera... | Decorator to convert a generator function to a :py:class:`~chainlink.ChainLink`
:param generator_function: the generator function to convert
:type generator_function: generator
:param prime: advance the generator to the next/first yield
:type prime: bool
When used as a decorator, this function can... | [
"Decorator",
"to",
"convert",
"a",
"generator",
"function",
"to",
"a",
":",
"py",
":",
"class",
":",
"~chainlink",
".",
"ChainLink"
] | python | train |
alexhayes/django-pdfkit | django_pdfkit/views.py | https://github.com/alexhayes/django-pdfkit/blob/02774ae2cb67d05dd5e4cb50661c56464ebb2413/django_pdfkit/views.py#L31-L53 | def get(self, request, *args, **kwargs):
"""
Return a HTTPResponse either of a PDF file or HTML.
:rtype: HttpResponse
"""
if 'html' in request.GET:
# Output HTML
content = self.render_html(*args, **kwargs)
return HttpResponse(content)
... | [
"def",
"get",
"(",
"self",
",",
"request",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"'html'",
"in",
"request",
".",
"GET",
":",
"# Output HTML",
"content",
"=",
"self",
".",
"render_html",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs"... | Return a HTTPResponse either of a PDF file or HTML.
:rtype: HttpResponse | [
"Return",
"a",
"HTTPResponse",
"either",
"of",
"a",
"PDF",
"file",
"or",
"HTML",
"."
] | python | train |
cloudendpoints/endpoints-python | endpoints/api_config.py | https://github.com/cloudendpoints/endpoints-python/blob/00dd7c7a52a9ee39d5923191c2604b8eafdb3f24/endpoints/api_config.py#L1831-L1871 | def __request_message_descriptor(self, request_kind, message_type, method_id,
path):
"""Describes the parameters and body of the request.
Args:
request_kind: The type of request being made.
message_type: messages.Message or ResourceContainer class. The message to
... | [
"def",
"__request_message_descriptor",
"(",
"self",
",",
"request_kind",
",",
"message_type",
",",
"method_id",
",",
"path",
")",
":",
"descriptor",
"=",
"{",
"}",
"params",
",",
"param_order",
"=",
"self",
".",
"__params_descriptor",
"(",
"message_type",
",",
... | Describes the parameters and body of the request.
Args:
request_kind: The type of request being made.
message_type: messages.Message or ResourceContainer class. The message to
describe.
method_id: string, Unique method identifier (e.g. 'myapi.items.method')
path: string, HTTP path... | [
"Describes",
"the",
"parameters",
"and",
"body",
"of",
"the",
"request",
"."
] | python | train |
delicb/mvvm | mvvm.py | https://github.com/delicb/mvvm/blob/29bf0ab2cc0835b58bed75b2606a9b380c38a272/mvvm.py#L87-L101 | def instance(cls, interval=5):
'''
Returns existing instance of messenger. If one does not exist it will
be created and returned.
:param int interval:
Number of miliseconds that represents interval when messages will
be processed.
Note that this param... | [
"def",
"instance",
"(",
"cls",
",",
"interval",
"=",
"5",
")",
":",
"if",
"not",
"cls",
".",
"_instance",
":",
"cls",
".",
"_instance",
"=",
"_Messenger",
"(",
"interval",
")",
"return",
"cls",
".",
"_instance"
] | Returns existing instance of messenger. If one does not exist it will
be created and returned.
:param int interval:
Number of miliseconds that represents interval when messages will
be processed.
Note that this parameter will be used only the first time when
... | [
"Returns",
"existing",
"instance",
"of",
"messenger",
".",
"If",
"one",
"does",
"not",
"exist",
"it",
"will",
"be",
"created",
"and",
"returned",
"."
] | python | train |
pandas-dev/pandas | pandas/io/sas/sas_xport.py | https://github.com/pandas-dev/pandas/blob/9feb3ad92cc0397a04b665803a49299ee7aa1037/pandas/io/sas/sas_xport.py#L401-L416 | def get_chunk(self, size=None):
"""
Reads lines from Xport file and returns as dataframe
Parameters
----------
size : int, defaults to None
Number of lines to read. If None, reads whole file.
Returns
-------
DataFrame
"""
if ... | [
"def",
"get_chunk",
"(",
"self",
",",
"size",
"=",
"None",
")",
":",
"if",
"size",
"is",
"None",
":",
"size",
"=",
"self",
".",
"_chunksize",
"return",
"self",
".",
"read",
"(",
"nrows",
"=",
"size",
")"
] | Reads lines from Xport file and returns as dataframe
Parameters
----------
size : int, defaults to None
Number of lines to read. If None, reads whole file.
Returns
-------
DataFrame | [
"Reads",
"lines",
"from",
"Xport",
"file",
"and",
"returns",
"as",
"dataframe"
] | python | train |
psss/did | did/plugins/trello.py | https://github.com/psss/did/blob/04e4ee6f1aa14c0cae3ba9f9803871f3f98279cb/did/plugins/trello.py#L88-L112 | def get_actions(self, filters, since=None, before=None, limit=1000):
"""
Example of data structure:
https://api.trello.com/1/members/ben/actions?limit=2
"""
if limit > 1000:
raise NotImplementedError(
"Fetching more than 1000 items is not implemented")... | [
"def",
"get_actions",
"(",
"self",
",",
"filters",
",",
"since",
"=",
"None",
",",
"before",
"=",
"None",
",",
"limit",
"=",
"1000",
")",
":",
"if",
"limit",
">",
"1000",
":",
"raise",
"NotImplementedError",
"(",
"\"Fetching more than 1000 items is not impleme... | Example of data structure:
https://api.trello.com/1/members/ben/actions?limit=2 | [
"Example",
"of",
"data",
"structure",
":",
"https",
":",
"//",
"api",
".",
"trello",
".",
"com",
"/",
"1",
"/",
"members",
"/",
"ben",
"/",
"actions?limit",
"=",
"2"
] | python | train |
hmeine/qimage2ndarray | qimage2ndarray/__init__.py | https://github.com/hmeine/qimage2ndarray/blob/023f3c67f90e646ce2fd80418fed85b9c7660bfc/qimage2ndarray/__init__.py#L116-L134 | def alpha_view(qimage):
"""Returns alpha view of a given 32-bit color QImage_'s memory.
The result is a 2D numpy.uint8 array, equivalent to
byte_view(qimage)[...,3]. The image must have 32 bit pixel size,
i.e. be RGB32, ARGB32, or ARGB32_Premultiplied. Note that it is
not enforced that the given q... | [
"def",
"alpha_view",
"(",
"qimage",
")",
":",
"bytes",
"=",
"byte_view",
"(",
"qimage",
",",
"byteorder",
"=",
"None",
")",
"if",
"bytes",
".",
"shape",
"[",
"2",
"]",
"!=",
"4",
":",
"raise",
"ValueError",
"(",
"\"For alpha_view, the image must have 32 bit ... | Returns alpha view of a given 32-bit color QImage_'s memory.
The result is a 2D numpy.uint8 array, equivalent to
byte_view(qimage)[...,3]. The image must have 32 bit pixel size,
i.e. be RGB32, ARGB32, or ARGB32_Premultiplied. Note that it is
not enforced that the given qimage has a format that actuall... | [
"Returns",
"alpha",
"view",
"of",
"a",
"given",
"32",
"-",
"bit",
"color",
"QImage_",
"s",
"memory",
".",
"The",
"result",
"is",
"a",
"2D",
"numpy",
".",
"uint8",
"array",
"equivalent",
"to",
"byte_view",
"(",
"qimage",
")",
"[",
"...",
"3",
"]",
"."... | python | train |
apriha/lineage | src/lineage/individual.py | https://github.com/apriha/lineage/blob/13106a62a959a80ac26c68d1566422de08aa877b/src/lineage/individual.py#L267-L298 | def save_snps(self, filename=None):
""" Save SNPs to file.
Parameters
----------
filename : str
filename for file to save
Returns
-------
str
path to file in output directory if SNPs were saved, else empty str
"""
comment ... | [
"def",
"save_snps",
"(",
"self",
",",
"filename",
"=",
"None",
")",
":",
"comment",
"=",
"(",
"\"# Source(s): {}\\n\"",
"\"# Assembly: {}\\n\"",
"\"# SNPs: {}\\n\"",
"\"# Chromosomes: {}\\n\"",
".",
"format",
"(",
"self",
".",
"source",
",",
"self",
".",
"assembly... | Save SNPs to file.
Parameters
----------
filename : str
filename for file to save
Returns
-------
str
path to file in output directory if SNPs were saved, else empty str | [
"Save",
"SNPs",
"to",
"file",
"."
] | python | train |
spookey/photon | photon/meta.py | https://github.com/spookey/photon/blob/57212a26ce713ab7723910ee49e3d0ba1697799f/photon/meta.py#L127-L142 | def log(self, elem):
'''
.. seealso:: :attr:`log`
'''
if elem:
self.__meta['log'].update({get_timestamp(precice=True): elem})
mfile = self.__meta['header']['stage']
self.__lock.acquire()
try:
j = read_json(mfile)
if j != self.... | [
"def",
"log",
"(",
"self",
",",
"elem",
")",
":",
"if",
"elem",
":",
"self",
".",
"__meta",
"[",
"'log'",
"]",
".",
"update",
"(",
"{",
"get_timestamp",
"(",
"precice",
"=",
"True",
")",
":",
"elem",
"}",
")",
"mfile",
"=",
"self",
".",
"__meta",... | .. seealso:: :attr:`log` | [
"..",
"seealso",
"::",
":",
"attr",
":",
"log"
] | python | train |
noahbenson/neuropythy | neuropythy/freesurfer/core.py | https://github.com/noahbenson/neuropythy/blob/b588889f6db36ddb9602ae4a72c1c0d3f41586b2/neuropythy/freesurfer/core.py#L385-L432 | def subject(name, meta_data=None, check_path=True):
'''
subject(name) yields a freesurfer Subject object for the subject with the given name. Subjects
are cached and not reloaded, so multiple calls to subject(name) will yield the same immutable
subject object..
Note that subects returned by fre... | [
"def",
"subject",
"(",
"name",
",",
"meta_data",
"=",
"None",
",",
"check_path",
"=",
"True",
")",
":",
"name",
"=",
"os",
".",
"path",
".",
"expanduser",
"(",
"os",
".",
"path",
".",
"expandvars",
"(",
"name",
")",
")",
"if",
"check_path",
"is",
"... | subject(name) yields a freesurfer Subject object for the subject with the given name. Subjects
are cached and not reloaded, so multiple calls to subject(name) will yield the same immutable
subject object..
Note that subects returned by freesurfer_subject() are always persistent Immutable objects; this
... | [
"subject",
"(",
"name",
")",
"yields",
"a",
"freesurfer",
"Subject",
"object",
"for",
"the",
"subject",
"with",
"the",
"given",
"name",
".",
"Subjects",
"are",
"cached",
"and",
"not",
"reloaded",
"so",
"multiple",
"calls",
"to",
"subject",
"(",
"name",
")"... | python | train |
bosha/pypushalot | pushalot/apis.py | https://github.com/bosha/pypushalot/blob/c1b5c941210ae61716e1695816a40c1676733739/pushalot/apis.py#L97-L145 | def _build_params_from_kwargs(self, **kwargs):
"""Builds parameters from passed arguments
Search passed parameters in available methods,
prepend specified API key, and return dictionary
which can be sent directly to API server.
:param kwargs:
:type param: dict
... | [
"def",
"_build_params_from_kwargs",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"api_methods",
"=",
"self",
".",
"get_api_params",
"(",
")",
"required_methods",
"=",
"self",
".",
"get_api_required_params",
"(",
")",
"ret_kwargs",
"=",
"{",
"}",
"for",
"k... | Builds parameters from passed arguments
Search passed parameters in available methods,
prepend specified API key, and return dictionary
which can be sent directly to API server.
:param kwargs:
:type param: dict
:raises ValueError: If type of specified parameter doesn't... | [
"Builds",
"parameters",
"from",
"passed",
"arguments"
] | python | train |
quantopian/zipline | zipline/finance/slippage.py | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/finance/slippage.py#L399-L444 | def _get_window_data(self, data, asset, window_length):
"""
Internal utility method to return the trailing mean volume over the
past 'window_length' days, and volatility of close prices for a
specific asset.
Parameters
----------
data : The BarData from which to ... | [
"def",
"_get_window_data",
"(",
"self",
",",
"data",
",",
"asset",
",",
"window_length",
")",
":",
"try",
":",
"values",
"=",
"self",
".",
"_window_data_cache",
".",
"get",
"(",
"asset",
",",
"data",
".",
"current_session",
")",
"except",
"KeyError",
":",
... | Internal utility method to return the trailing mean volume over the
past 'window_length' days, and volatility of close prices for a
specific asset.
Parameters
----------
data : The BarData from which to fetch the daily windows.
asset : The Asset whose data we are fetchin... | [
"Internal",
"utility",
"method",
"to",
"return",
"the",
"trailing",
"mean",
"volume",
"over",
"the",
"past",
"window_length",
"days",
"and",
"volatility",
"of",
"close",
"prices",
"for",
"a",
"specific",
"asset",
"."
] | python | train |
tensorflow/probability | tensorflow_probability/python/mcmc/random_walk_metropolis.py | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/python/mcmc/random_walk_metropolis.py#L112-L170 | def random_walk_uniform_fn(scale=1., name=None):
"""Returns a callable that adds a random uniform perturbation to the input.
For more details on `random_walk_uniform_fn`, see
`random_walk_normal_fn`. `scale` might
be a `Tensor` or a list of `Tensor`s that should broadcast with state parts
of the `current_sta... | [
"def",
"random_walk_uniform_fn",
"(",
"scale",
"=",
"1.",
",",
"name",
"=",
"None",
")",
":",
"def",
"_fn",
"(",
"state_parts",
",",
"seed",
")",
":",
"\"\"\"Adds a uniform perturbation to the input state.\n\n Args:\n state_parts: A list of `Tensor`s of any shape and ... | Returns a callable that adds a random uniform perturbation to the input.
For more details on `random_walk_uniform_fn`, see
`random_walk_normal_fn`. `scale` might
be a `Tensor` or a list of `Tensor`s that should broadcast with state parts
of the `current_state`. The generated uniform perturbation is sampled as ... | [
"Returns",
"a",
"callable",
"that",
"adds",
"a",
"random",
"uniform",
"perturbation",
"to",
"the",
"input",
"."
] | python | test |
Koed00/django-q | django_q/cluster.py | https://github.com/Koed00/django-q/blob/c84fd11a67c9a47d821786dfcdc189bb258c6f54/django_q/cluster.py#L560-L594 | def set_cpu_affinity(n, process_ids, actual=not Conf.TESTING):
"""
Sets the cpu affinity for the supplied processes.
Requires the optional psutil module.
:param int n: affinity
:param list process_ids: a list of pids
:param bool actual: Test workaround for Travis not supporting cpu affinity
... | [
"def",
"set_cpu_affinity",
"(",
"n",
",",
"process_ids",
",",
"actual",
"=",
"not",
"Conf",
".",
"TESTING",
")",
":",
"# check if we have the psutil module",
"if",
"not",
"psutil",
":",
"logger",
".",
"warning",
"(",
"'Skipping cpu affinity because psutil was not foun... | Sets the cpu affinity for the supplied processes.
Requires the optional psutil module.
:param int n: affinity
:param list process_ids: a list of pids
:param bool actual: Test workaround for Travis not supporting cpu affinity | [
"Sets",
"the",
"cpu",
"affinity",
"for",
"the",
"supplied",
"processes",
".",
"Requires",
"the",
"optional",
"psutil",
"module",
".",
":",
"param",
"int",
"n",
":",
"affinity",
":",
"param",
"list",
"process_ids",
":",
"a",
"list",
"of",
"pids",
":",
"pa... | python | train |
inveniosoftware/invenio-records-rest | invenio_records_rest/serializers/base.py | https://github.com/inveniosoftware/invenio-records-rest/blob/e7b63c5f72cef03d06d3f1b4c12c0d37e3a628b9/invenio_records_rest/serializers/base.py#L140-L154 | def preprocess_record(self, pid, record, links_factory=None, **kwargs):
"""Prepare a record and persistent identifier for serialization."""
links_factory = links_factory or (lambda x, record=None, **k: dict())
metadata = copy.deepcopy(record.replace_refs()) if self.replace_refs \
els... | [
"def",
"preprocess_record",
"(",
"self",
",",
"pid",
",",
"record",
",",
"links_factory",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"links_factory",
"=",
"links_factory",
"or",
"(",
"lambda",
"x",
",",
"record",
"=",
"None",
",",
"*",
"*",
"k",
... | Prepare a record and persistent identifier for serialization. | [
"Prepare",
"a",
"record",
"and",
"persistent",
"identifier",
"for",
"serialization",
"."
] | python | train |
twisted/axiom | axiom/userbase.py | https://github.com/twisted/axiom/blob/7de70bc8fe1bb81f9c2339fba8daec9eb2e92b68/axiom/userbase.py#L465-L533 | def addAccount(self, username, domain, password, avatars=None,
protocol=u'email', disabled=0, internal=False,
verified=True):
"""
Create a user account, add it to this LoginBase, and return it.
This method must be called within a transaction in my store.
... | [
"def",
"addAccount",
"(",
"self",
",",
"username",
",",
"domain",
",",
"password",
",",
"avatars",
"=",
"None",
",",
"protocol",
"=",
"u'email'",
",",
"disabled",
"=",
"0",
",",
"internal",
"=",
"False",
",",
"verified",
"=",
"True",
")",
":",
"# unico... | Create a user account, add it to this LoginBase, and return it.
This method must be called within a transaction in my store.
@param username: the user's name.
@param domain: the domain part of the user's name [XXX TODO: this
really ought to say something about whether it's a Q2Q domai... | [
"Create",
"a",
"user",
"account",
"add",
"it",
"to",
"this",
"LoginBase",
"and",
"return",
"it",
"."
] | python | train |
mgoral/subconvert | src/subconvert/parsing/Offset.py | https://github.com/mgoral/subconvert/blob/59701e5e69ef1ca26ce7d1d766c936664aa2cb32/src/subconvert/parsing/Offset.py#L143-L148 | def _getLowestSyncPoint(self, syncPointList, subs):
"""Get the lowest possible sync point. If it is not the first one on the **sorted**
syncPointList, first subtitle will be converted to the one."""
if syncPointList[0].subNo == 0:
return syncPointList[0]
return SyncPoint(0, s... | [
"def",
"_getLowestSyncPoint",
"(",
"self",
",",
"syncPointList",
",",
"subs",
")",
":",
"if",
"syncPointList",
"[",
"0",
"]",
".",
"subNo",
"==",
"0",
":",
"return",
"syncPointList",
"[",
"0",
"]",
"return",
"SyncPoint",
"(",
"0",
",",
"subs",
"[",
"0"... | Get the lowest possible sync point. If it is not the first one on the **sorted**
syncPointList, first subtitle will be converted to the one. | [
"Get",
"the",
"lowest",
"possible",
"sync",
"point",
".",
"If",
"it",
"is",
"not",
"the",
"first",
"one",
"on",
"the",
"**",
"sorted",
"**",
"syncPointList",
"first",
"subtitle",
"will",
"be",
"converted",
"to",
"the",
"one",
"."
] | python | train |
Jammy2211/PyAutoLens | autolens/model/profiles/geometry_profiles.py | https://github.com/Jammy2211/PyAutoLens/blob/91e50369c7a9c048c83d217625578b72423cd5a7/autolens/model/profiles/geometry_profiles.py#L170-L180 | def grid_to_grid_radii(self, grid):
"""Convert a grid of (y, x) coordinates to a grid of their circular radii.
If the coordinates have not been transformed to the profile's centre, this is performed automatically.
Parameters
----------
grid : TransformedGrid(ndarray)
... | [
"def",
"grid_to_grid_radii",
"(",
"self",
",",
"grid",
")",
":",
"return",
"np",
".",
"sqrt",
"(",
"np",
".",
"add",
"(",
"np",
".",
"square",
"(",
"grid",
"[",
":",
",",
"0",
"]",
")",
",",
"np",
".",
"square",
"(",
"grid",
"[",
":",
",",
"1... | Convert a grid of (y, x) coordinates to a grid of their circular radii.
If the coordinates have not been transformed to the profile's centre, this is performed automatically.
Parameters
----------
grid : TransformedGrid(ndarray)
The (y, x) coordinates in the reference frame... | [
"Convert",
"a",
"grid",
"of",
"(",
"y",
"x",
")",
"coordinates",
"to",
"a",
"grid",
"of",
"their",
"circular",
"radii",
"."
] | python | valid |
agile-geoscience/welly | welly/well.py | https://github.com/agile-geoscience/welly/blob/ed4c991011d6290938fef365553041026ba29f42/welly/well.py#L933-L973 | def qc_table_html(self, tests, alias=None):
"""
Makes a nice table out of ``qc_data()``
Returns:
str. An HTML string.
"""
data = self.qc_data(tests, alias=alias)
all_tests = [list(d.keys()) for d in data.values()]
tests = list(set(utils.flatten_list(a... | [
"def",
"qc_table_html",
"(",
"self",
",",
"tests",
",",
"alias",
"=",
"None",
")",
":",
"data",
"=",
"self",
".",
"qc_data",
"(",
"tests",
",",
"alias",
"=",
"alias",
")",
"all_tests",
"=",
"[",
"list",
"(",
"d",
".",
"keys",
"(",
")",
")",
"for"... | Makes a nice table out of ``qc_data()``
Returns:
str. An HTML string. | [
"Makes",
"a",
"nice",
"table",
"out",
"of",
"qc_data",
"()"
] | python | train |
fprimex/zdesk | zdesk/zdesk_api.py | https://github.com/fprimex/zdesk/blob/851611c13b4d530e9df31390b3ec709baf0a0188/zdesk/zdesk_api.py#L317-L340 | def audit_logs_list(self, filter_actor_id=None, filter_created_at=None, filter_ip_address=None, filter_source_type=None, **kwargs):
"https://developer.zendesk.com/rest_api/docs/core/audit_logs#listing-audit-logs"
api_path = "/api/v2/audit_logs.json"
api_query = {}
if "query" in kwargs.ke... | [
"def",
"audit_logs_list",
"(",
"self",
",",
"filter_actor_id",
"=",
"None",
",",
"filter_created_at",
"=",
"None",
",",
"filter_ip_address",
"=",
"None",
",",
"filter_source_type",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"api_path",
"=",
"\"/api/v2/aud... | https://developer.zendesk.com/rest_api/docs/core/audit_logs#listing-audit-logs | [
"https",
":",
"//",
"developer",
".",
"zendesk",
".",
"com",
"/",
"rest_api",
"/",
"docs",
"/",
"core",
"/",
"audit_logs#listing",
"-",
"audit",
"-",
"logs"
] | python | train |
plone/plone.app.mosaic | src/plone/app/mosaic/transform.py | https://github.com/plone/plone.app.mosaic/blob/73b6acb18905025a76b239c86de9543ed9350991/src/plone/app/mosaic/transform.py#L26-L34 | def getContext(context):
"""Return a safe context.
In case a IBrowserView was passed (e.g. due to a 404 page), return the
portal object.
"""
context = aq_parent(aq_base(context))
if not context or IBrowserView.providedBy(context):
return getSite()
return context | [
"def",
"getContext",
"(",
"context",
")",
":",
"context",
"=",
"aq_parent",
"(",
"aq_base",
"(",
"context",
")",
")",
"if",
"not",
"context",
"or",
"IBrowserView",
".",
"providedBy",
"(",
"context",
")",
":",
"return",
"getSite",
"(",
")",
"return",
"con... | Return a safe context.
In case a IBrowserView was passed (e.g. due to a 404 page), return the
portal object. | [
"Return",
"a",
"safe",
"context",
".",
"In",
"case",
"a",
"IBrowserView",
"was",
"passed",
"(",
"e",
".",
"g",
".",
"due",
"to",
"a",
"404",
"page",
")",
"return",
"the",
"portal",
"object",
"."
] | python | train |
jgorset/django-respite | respite/urls/routes.py | https://github.com/jgorset/django-respite/blob/719469d11baf91d05917bab1623bd82adc543546/respite/urls/routes.py#L3-L18 | def route(regex, view, method, name):
"""
Route the given view.
:param regex: A string describing a regular expression to which the request path will be matched.
:param view: A string describing the name of the view to delegate the request to.
:param method: A string describing the HTTP method ... | [
"def",
"route",
"(",
"regex",
",",
"view",
",",
"method",
",",
"name",
")",
":",
"return",
"_Route",
"(",
"regex",
",",
"view",
",",
"method",
",",
"name",
")"
] | Route the given view.
:param regex: A string describing a regular expression to which the request path will be matched.
:param view: A string describing the name of the view to delegate the request to.
:param method: A string describing the HTTP method that this view accepts.
:param name: A string ... | [
"Route",
"the",
"given",
"view",
".",
":",
"param",
"regex",
":",
"A",
"string",
"describing",
"a",
"regular",
"expression",
"to",
"which",
"the",
"request",
"path",
"will",
"be",
"matched",
".",
":",
"param",
"view",
":",
"A",
"string",
"describing",
"t... | python | train |
blubberdiblub/eztemplate | eztemplate/__main__.py | https://github.com/blubberdiblub/eztemplate/blob/ab5b2b4987c045116d130fd83e216704b8edfb5d/eztemplate/__main__.py#L230-L238 | def check_engine(handle):
"""Check availability of requested template engine."""
if handle == 'help':
dump_engines()
sys.exit(0)
if handle not in engines.engines:
print('Engine "%s" is not available.' % (handle,), file=sys.stderr)
sys.exit(1) | [
"def",
"check_engine",
"(",
"handle",
")",
":",
"if",
"handle",
"==",
"'help'",
":",
"dump_engines",
"(",
")",
"sys",
".",
"exit",
"(",
"0",
")",
"if",
"handle",
"not",
"in",
"engines",
".",
"engines",
":",
"print",
"(",
"'Engine \"%s\" is not available.'"... | Check availability of requested template engine. | [
"Check",
"availability",
"of",
"requested",
"template",
"engine",
"."
] | python | train |
sassoftware/saspy | saspy/sasbase.py | https://github.com/sassoftware/saspy/blob/e433f71990f249d3a6c3db323ceb11cb2d462cf9/saspy/sasbase.py#L540-L549 | def exist(self, table: str, libref: str = "") -> bool:
"""
Does the SAS data set currently exist
:param table: the name of the SAS Data Set
:param libref: the libref for the Data Set, defaults to WORK, or USER if assigned
:return: Boolean True it the Data Set exists and False if... | [
"def",
"exist",
"(",
"self",
",",
"table",
":",
"str",
",",
"libref",
":",
"str",
"=",
"\"\"",
")",
"->",
"bool",
":",
"return",
"self",
".",
"_io",
".",
"exist",
"(",
"table",
",",
"libref",
")"
] | Does the SAS data set currently exist
:param table: the name of the SAS Data Set
:param libref: the libref for the Data Set, defaults to WORK, or USER if assigned
:return: Boolean True it the Data Set exists and False if it does not
:rtype: bool | [
"Does",
"the",
"SAS",
"data",
"set",
"currently",
"exist"
] | python | train |
google/grr | grr/server/grr_response_server/output_plugins/bigquery_plugin.py | https://github.com/google/grr/blob/5cef4e8e2f0d5df43ea4877e9c798e0bf60bfe74/grr/server/grr_response_server/output_plugins/bigquery_plugin.py#L215-L251 | def RDFValueToBigQuerySchema(self, value):
"""Convert Exported* rdfvalue into a BigQuery schema."""
fields_array = []
for type_info in value.__class__.type_infos:
# Nested structures are indicated by setting type "RECORD"
if type_info.__class__.__name__ == "ProtoEmbedded":
fields_array.a... | [
"def",
"RDFValueToBigQuerySchema",
"(",
"self",
",",
"value",
")",
":",
"fields_array",
"=",
"[",
"]",
"for",
"type_info",
"in",
"value",
".",
"__class__",
".",
"type_infos",
":",
"# Nested structures are indicated by setting type \"RECORD\"",
"if",
"type_info",
".",
... | Convert Exported* rdfvalue into a BigQuery schema. | [
"Convert",
"Exported",
"*",
"rdfvalue",
"into",
"a",
"BigQuery",
"schema",
"."
] | python | train |
mikedh/trimesh | trimesh/curvature.py | https://github.com/mikedh/trimesh/blob/25e059bf6d4caa74f62ffd58ce4f61a90ee4e518/trimesh/curvature.py#L121-L163 | def line_ball_intersection(start_points, end_points, center, radius):
"""
Compute the length of the intersection of a line segment with a ball.
Parameters
----------
start_points : (n,3) float, list of points in space
end_points : (n,3) float, list of points in space
center : (3,) f... | [
"def",
"line_ball_intersection",
"(",
"start_points",
",",
"end_points",
",",
"center",
",",
"radius",
")",
":",
"# We solve for the intersection of |x-c|**2 = r**2 and",
"# x = o + dL. This yields",
"# d = (-l.(o-c) +- sqrt[ l.(o-c)**2 - l.l((o-c).(o-c) - r^**2) ]) / l.l",
"L",
"=",... | Compute the length of the intersection of a line segment with a ball.
Parameters
----------
start_points : (n,3) float, list of points in space
end_points : (n,3) float, list of points in space
center : (3,) float, the sphere center
radius : float, the sphere radius
Returns
... | [
"Compute",
"the",
"length",
"of",
"the",
"intersection",
"of",
"a",
"line",
"segment",
"with",
"a",
"ball",
"."
] | python | train |
gtaylor/python-colormath | colormath/color_objects.py | https://github.com/gtaylor/python-colormath/blob/1d168613718d2d7d31ec4230524e987ef66823c7/colormath/color_objects.py#L530-L542 | def _clamp_rgb_coordinate(self, coord):
"""
Clamps an RGB coordinate, taking into account whether or not the
color is upscaled or not.
:param float coord: The coordinate value.
:rtype: float
:returns: The clamped value.
"""
if not self.is_upscaled:
... | [
"def",
"_clamp_rgb_coordinate",
"(",
"self",
",",
"coord",
")",
":",
"if",
"not",
"self",
".",
"is_upscaled",
":",
"return",
"min",
"(",
"max",
"(",
"coord",
",",
"0.0",
")",
",",
"1.0",
")",
"else",
":",
"return",
"min",
"(",
"max",
"(",
"coord",
... | Clamps an RGB coordinate, taking into account whether or not the
color is upscaled or not.
:param float coord: The coordinate value.
:rtype: float
:returns: The clamped value. | [
"Clamps",
"an",
"RGB",
"coordinate",
"taking",
"into",
"account",
"whether",
"or",
"not",
"the",
"color",
"is",
"upscaled",
"or",
"not",
"."
] | python | train |
limdauto/drf_openapi | drf_openapi/entities.py | https://github.com/limdauto/drf_openapi/blob/1673c6e039eec7f089336a83bdc31613f32f7e21/drf_openapi/entities.py#L294-L308 | def fallback_schema_from_field(self, field):
""" Fallback schema for field that isn't inspected properly by DRF
and probably won't land in upstream canon due to its hacky nature only for doc purposes
"""
title = force_text(field.label) if field.label else ''
description = force_t... | [
"def",
"fallback_schema_from_field",
"(",
"self",
",",
"field",
")",
":",
"title",
"=",
"force_text",
"(",
"field",
".",
"label",
")",
"if",
"field",
".",
"label",
"else",
"''",
"description",
"=",
"force_text",
"(",
"field",
".",
"help_text",
")",
"if",
... | Fallback schema for field that isn't inspected properly by DRF
and probably won't land in upstream canon due to its hacky nature only for doc purposes | [
"Fallback",
"schema",
"for",
"field",
"that",
"isn",
"t",
"inspected",
"properly",
"by",
"DRF",
"and",
"probably",
"won",
"t",
"land",
"in",
"upstream",
"canon",
"due",
"to",
"its",
"hacky",
"nature",
"only",
"for",
"doc",
"purposes"
] | python | train |
mitsei/dlkit | dlkit/json_/authorization/sessions.py | https://github.com/mitsei/dlkit/blob/445f968a175d61c8d92c0f617a3c17dc1dc7c584/dlkit/json_/authorization/sessions.py#L2815-L2842 | def delete_vault(self, vault_id):
"""Deletes a ``Vault``.
arg: vault_id (osid.id.Id): the ``Id`` of the ``Vault`` to
remove
raise: NotFound - ``vault_id`` not found
raise: NullArgument - ``vault_id`` is ``null``
raise: OperationFailed - unable to complete r... | [
"def",
"delete_vault",
"(",
"self",
",",
"vault_id",
")",
":",
"# Implemented from template for",
"# osid.resource.BinAdminSession.delete_bin_template",
"if",
"self",
".",
"_catalog_session",
"is",
"not",
"None",
":",
"return",
"self",
".",
"_catalog_session",
".",
"del... | Deletes a ``Vault``.
arg: vault_id (osid.id.Id): the ``Id`` of the ``Vault`` to
remove
raise: NotFound - ``vault_id`` not found
raise: NullArgument - ``vault_id`` is ``null``
raise: OperationFailed - unable to complete request
raise: PermissionDenied - aut... | [
"Deletes",
"a",
"Vault",
"."
] | python | train |
pypa/bandersnatch | src/bandersnatch_filter_plugins/blacklist_name.py | https://github.com/pypa/bandersnatch/blob/8b702c3bc128c5a1cbdd18890adede2f7f17fad4/src/bandersnatch_filter_plugins/blacklist_name.py#L139-L174 | def _check_match(self, name, version_string) -> bool:
"""
Check if the package name and version matches against a blacklisted
package version specifier.
Parameters
==========
name: str
Package name
version: str
Package version
Re... | [
"def",
"_check_match",
"(",
"self",
",",
"name",
",",
"version_string",
")",
"->",
"bool",
":",
"if",
"not",
"name",
"or",
"not",
"version_string",
":",
"return",
"False",
"try",
":",
"version",
"=",
"Version",
"(",
"version_string",
")",
"except",
"Invali... | Check if the package name and version matches against a blacklisted
package version specifier.
Parameters
==========
name: str
Package name
version: str
Package version
Returns
=======
bool:
True if it matches, False ... | [
"Check",
"if",
"the",
"package",
"name",
"and",
"version",
"matches",
"against",
"a",
"blacklisted",
"package",
"version",
"specifier",
"."
] | python | train |
hazelcast/hazelcast-python-client | hazelcast/proxy/map.py | https://github.com/hazelcast/hazelcast-python-client/blob/3f6639443c23d6d036aa343f8e094f052250d2c1/hazelcast/proxy/map.py#L316-L329 | def force_unlock(self, key):
"""
Releases the lock for the specified key regardless of the lock owner. It always successfully unlocks the key,
never blocks, and returns immediately.
**Warning: This method uses __hash__ and __eq__ methods of binary form of the key, not the actual impleme... | [
"def",
"force_unlock",
"(",
"self",
",",
"key",
")",
":",
"check_not_none",
"(",
"key",
",",
"\"key can't be None\"",
")",
"key_data",
"=",
"self",
".",
"_to_data",
"(",
"key",
")",
"return",
"self",
".",
"_encode_invoke_on_key",
"(",
"map_force_unlock_codec",
... | Releases the lock for the specified key regardless of the lock owner. It always successfully unlocks the key,
never blocks, and returns immediately.
**Warning: This method uses __hash__ and __eq__ methods of binary form of the key, not the actual implementations
of __hash__ and __eq__ defined i... | [
"Releases",
"the",
"lock",
"for",
"the",
"specified",
"key",
"regardless",
"of",
"the",
"lock",
"owner",
".",
"It",
"always",
"successfully",
"unlocks",
"the",
"key",
"never",
"blocks",
"and",
"returns",
"immediately",
"."
] | python | train |
peakwinter/python-nginx | nginx.py | https://github.com/peakwinter/python-nginx/blob/4ecd1cd2e1f11ffb633d188a578a004712eaae16/nginx.py#L581-L591 | def dumpf(obj, path):
"""
Write an nginx configuration to file.
:param obj obj: nginx object (Conf, Server, Container)
:param str path: path to nginx configuration on disk
:returns: path the configuration was written to
"""
with open(path, 'w') as f:
dump(obj, f)
return path | [
"def",
"dumpf",
"(",
"obj",
",",
"path",
")",
":",
"with",
"open",
"(",
"path",
",",
"'w'",
")",
"as",
"f",
":",
"dump",
"(",
"obj",
",",
"f",
")",
"return",
"path"
] | Write an nginx configuration to file.
:param obj obj: nginx object (Conf, Server, Container)
:param str path: path to nginx configuration on disk
:returns: path the configuration was written to | [
"Write",
"an",
"nginx",
"configuration",
"to",
"file",
"."
] | python | train |
SheffieldML/GPy | GPy/likelihoods/poisson.py | https://github.com/SheffieldML/GPy/blob/54c32d79d289d622fb18b898aee65a2a431d90cf/GPy/likelihoods/poisson.py#L33-L49 | def pdf_link(self, link_f, y, Y_metadata=None):
"""
Likelihood function given link(f)
.. math::
p(y_{i}|\\lambda(f_{i})) = \\frac{\\lambda(f_{i})^{y_{i}}}{y_{i}!}e^{-\\lambda(f_{i})}
:param link_f: latent variables link(f)
:type link_f: Nx1 array
:param y: d... | [
"def",
"pdf_link",
"(",
"self",
",",
"link_f",
",",
"y",
",",
"Y_metadata",
"=",
"None",
")",
":",
"assert",
"np",
".",
"atleast_1d",
"(",
"link_f",
")",
".",
"shape",
"==",
"np",
".",
"atleast_1d",
"(",
"y",
")",
".",
"shape",
"return",
"np",
".",... | Likelihood function given link(f)
.. math::
p(y_{i}|\\lambda(f_{i})) = \\frac{\\lambda(f_{i})^{y_{i}}}{y_{i}!}e^{-\\lambda(f_{i})}
:param link_f: latent variables link(f)
:type link_f: Nx1 array
:param y: data
:type y: Nx1 array
:param Y_metadata: Y_metadata... | [
"Likelihood",
"function",
"given",
"link",
"(",
"f",
")"
] | python | train |
azogue/dataweb | dataweb/classdataweb.py | https://github.com/azogue/dataweb/blob/085035855df7cef0fe7725bbe9a706832344d946/dataweb/classdataweb.py#L148-L157 | def printif(self, obj_print, tipo_print=None):
"""Color output & logging."""
if self.verbose:
print(obj_print)
if tipo_print == 'ok':
logging.info(obj_print)
elif tipo_print == 'error':
logging.error(obj_print)
elif tipo_print == 'warning':
... | [
"def",
"printif",
"(",
"self",
",",
"obj_print",
",",
"tipo_print",
"=",
"None",
")",
":",
"if",
"self",
".",
"verbose",
":",
"print",
"(",
"obj_print",
")",
"if",
"tipo_print",
"==",
"'ok'",
":",
"logging",
".",
"info",
"(",
"obj_print",
")",
"elif",
... | Color output & logging. | [
"Color",
"output",
"&",
"logging",
"."
] | python | train |
msmbuilder/osprey | osprey/utils.py | https://github.com/msmbuilder/osprey/blob/ea09da24e45820e1300e24a52fefa6c849f7a986/osprey/utils.py#L58-L65 | def in_directory(path):
"""Context manager (with statement) that changes the current directory
during the context.
"""
curdir = os.path.abspath(os.curdir)
os.chdir(path)
yield
os.chdir(curdir) | [
"def",
"in_directory",
"(",
"path",
")",
":",
"curdir",
"=",
"os",
".",
"path",
".",
"abspath",
"(",
"os",
".",
"curdir",
")",
"os",
".",
"chdir",
"(",
"path",
")",
"yield",
"os",
".",
"chdir",
"(",
"curdir",
")"
] | Context manager (with statement) that changes the current directory
during the context. | [
"Context",
"manager",
"(",
"with",
"statement",
")",
"that",
"changes",
"the",
"current",
"directory",
"during",
"the",
"context",
"."
] | python | valid |
coursera-dl/coursera-dl | coursera/api.py | https://github.com/coursera-dl/coursera-dl/blob/9b434bcf3c4011bf3181429fe674633ae5fb7d4d/coursera/api.py#L628-L638 | def list_courses(self):
"""
List enrolled courses.
@return: List of enrolled courses.
@rtype: [str]
"""
reply = get_page(self._session, OPENCOURSE_MEMBERSHIPS, json=True)
course_list = reply['linked']['courses.v1']
slugs = [element['slug'] for element in ... | [
"def",
"list_courses",
"(",
"self",
")",
":",
"reply",
"=",
"get_page",
"(",
"self",
".",
"_session",
",",
"OPENCOURSE_MEMBERSHIPS",
",",
"json",
"=",
"True",
")",
"course_list",
"=",
"reply",
"[",
"'linked'",
"]",
"[",
"'courses.v1'",
"]",
"slugs",
"=",
... | List enrolled courses.
@return: List of enrolled courses.
@rtype: [str] | [
"List",
"enrolled",
"courses",
"."
] | python | train |
dylanaraps/pywal | pywal/__main__.py | https://github.com/dylanaraps/pywal/blob/c823e3c9dbd0100ca09caf824e77d296685a1c1e/pywal/__main__.py#L29-L102 | def get_args():
"""Get the script arguments."""
description = "wal - Generate colorschemes on the fly"
arg = argparse.ArgumentParser(description=description)
arg.add_argument("-a", metavar="\"alpha\"",
help="Set terminal background transparency. \
*Only w... | [
"def",
"get_args",
"(",
")",
":",
"description",
"=",
"\"wal - Generate colorschemes on the fly\"",
"arg",
"=",
"argparse",
".",
"ArgumentParser",
"(",
"description",
"=",
"description",
")",
"arg",
".",
"add_argument",
"(",
"\"-a\"",
",",
"metavar",
"=",
"\"\\\"a... | Get the script arguments. | [
"Get",
"the",
"script",
"arguments",
"."
] | python | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.