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 |
|---|---|---|---|---|---|---|---|---|
ecederstrand/exchangelib | exchangelib/protocol.py | https://github.com/ecederstrand/exchangelib/blob/736347b337c239fcd6d592db5b29e819f753c1ba/exchangelib/protocol.py#L100-L115 | def decrease_poolsize(self):
"""Decreases the session pool size in response to error messages from the server requesting to rate-limit
requests. We decrease by one session per call.
"""
# Take a single session from the pool and discard it. We need to protect this with a lock while we are... | [
"def",
"decrease_poolsize",
"(",
"self",
")",
":",
"# Take a single session from the pool and discard it. We need to protect this with a lock while we are changing",
"# the pool size variable, to avoid race conditions. We must keep at least one session in the pool.",
"if",
"self",
".",
"_sessi... | Decreases the session pool size in response to error messages from the server requesting to rate-limit
requests. We decrease by one session per call. | [
"Decreases",
"the",
"session",
"pool",
"size",
"in",
"response",
"to",
"error",
"messages",
"from",
"the",
"server",
"requesting",
"to",
"rate",
"-",
"limit",
"requests",
".",
"We",
"decrease",
"by",
"one",
"session",
"per",
"call",
"."
] | python | train |
CellProfiler/centrosome | centrosome/cpmorphology.py | https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/cpmorphology.py#L2084-L2091 | def within_hull(point, hull):
'''Return true if the point is within the convex hull'''
h_prev_pt = hull[-1,:]
for h_pt in hull:
if np.cross(h_pt-h_prev_pt, point - h_pt) >= 0:
return False
h_prev_pt = h_pt
return True | [
"def",
"within_hull",
"(",
"point",
",",
"hull",
")",
":",
"h_prev_pt",
"=",
"hull",
"[",
"-",
"1",
",",
":",
"]",
"for",
"h_pt",
"in",
"hull",
":",
"if",
"np",
".",
"cross",
"(",
"h_pt",
"-",
"h_prev_pt",
",",
"point",
"-",
"h_pt",
")",
">=",
... | Return true if the point is within the convex hull | [
"Return",
"true",
"if",
"the",
"point",
"is",
"within",
"the",
"convex",
"hull"
] | python | train |
UCL-INGI/INGInious | base-containers/base/inginious/input.py | https://github.com/UCL-INGI/INGInious/blob/cbda9a9c7f2b8e8eb1e6d7d51f0d18092086300c/base-containers/base/inginious/input.py#L49-L92 | def parse_template(input_filename, output_filename=''):
""" Parses a template file
Replaces all occurences of @@problem_id@@ by the value
of the 'problem_id' key in data dictionary
input_filename: file to parse
output_filename: if not specified, overwrite input file
"""
... | [
"def",
"parse_template",
"(",
"input_filename",
",",
"output_filename",
"=",
"''",
")",
":",
"data",
"=",
"load_input",
"(",
")",
"with",
"open",
"(",
"input_filename",
",",
"'rb'",
")",
"as",
"file",
":",
"template",
"=",
"file",
".",
"read",
"(",
")",
... | Parses a template file
Replaces all occurences of @@problem_id@@ by the value
of the 'problem_id' key in data dictionary
input_filename: file to parse
output_filename: if not specified, overwrite input file | [
"Parses",
"a",
"template",
"file",
"Replaces",
"all",
"occurences",
"of"
] | python | train |
CEA-COSMIC/ModOpt | modopt/math/matrix.py | https://github.com/CEA-COSMIC/ModOpt/blob/019b189cb897cbb4d210c44a100daaa08468830c/modopt/math/matrix.py#L77-L111 | def nuclear_norm(data):
r"""Nuclear norm
This method computes the nuclear (or trace) norm of the input data.
Parameters
----------
data : np.ndarray
Input data array
Returns
-------
float nuclear norm value
Examples
--------
>>> from modopt.math.matrix import nucl... | [
"def",
"nuclear_norm",
"(",
"data",
")",
":",
"# Get SVD of the data.",
"u",
",",
"s",
",",
"v",
"=",
"np",
".",
"linalg",
".",
"svd",
"(",
"data",
")",
"# Return nuclear norm.",
"return",
"np",
".",
"sum",
"(",
"s",
")"
] | r"""Nuclear norm
This method computes the nuclear (or trace) norm of the input data.
Parameters
----------
data : np.ndarray
Input data array
Returns
-------
float nuclear norm value
Examples
--------
>>> from modopt.math.matrix import nuclear_norm
>>> a = np.aran... | [
"r",
"Nuclear",
"norm"
] | python | train |
tijme/not-your-average-web-crawler | nyawc/QueueItem.py | https://github.com/tijme/not-your-average-web-crawler/blob/d77c14e1616c541bb3980f649a7e6f8ed02761fb/nyawc/QueueItem.py#L118-L152 | def get_hash(self):
"""Generate and return the dict index hash of the given queue item.
Note:
Cookies should not be included in the hash calculation because
otherwise requests are crawled multiple times with e.g. different
session keys, causing infinite crawling recu... | [
"def",
"get_hash",
"(",
"self",
")",
":",
"if",
"self",
".",
"__index_hash",
":",
"return",
"self",
".",
"__index_hash",
"key",
"=",
"self",
".",
"request",
".",
"method",
"key",
"+=",
"URLHelper",
".",
"get_protocol",
"(",
"self",
".",
"request",
".",
... | Generate and return the dict index hash of the given queue item.
Note:
Cookies should not be included in the hash calculation because
otherwise requests are crawled multiple times with e.g. different
session keys, causing infinite crawling recursion.
Note:
... | [
"Generate",
"and",
"return",
"the",
"dict",
"index",
"hash",
"of",
"the",
"given",
"queue",
"item",
"."
] | python | train |
spyder-ide/spyder | spyder/plugins/explorer/widgets.py | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/plugins/explorer/widgets.py#L682-L709 | def rename_file(self, fname):
"""Rename file"""
path, valid = QInputDialog.getText(self, _('Rename'),
_('New name:'), QLineEdit.Normal,
osp.basename(fname))
if valid:
path = osp.join(osp.dirname(fname), to_text_string(... | [
"def",
"rename_file",
"(",
"self",
",",
"fname",
")",
":",
"path",
",",
"valid",
"=",
"QInputDialog",
".",
"getText",
"(",
"self",
",",
"_",
"(",
"'Rename'",
")",
",",
"_",
"(",
"'New name:'",
")",
",",
"QLineEdit",
".",
"Normal",
",",
"osp",
".",
... | Rename file | [
"Rename",
"file"
] | python | train |
spyder-ide/spyder | spyder/utils/programs.py | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/utils/programs.py#L34-L54 | def get_temp_dir(suffix=None):
"""
Return temporary Spyder directory, checking previously that it exists.
"""
to_join = [tempfile.gettempdir()]
if os.name == 'nt':
to_join.append('spyder')
else:
username = encoding.to_unicode_from_fs(getuser())
to_join.append('... | [
"def",
"get_temp_dir",
"(",
"suffix",
"=",
"None",
")",
":",
"to_join",
"=",
"[",
"tempfile",
".",
"gettempdir",
"(",
")",
"]",
"if",
"os",
".",
"name",
"==",
"'nt'",
":",
"to_join",
".",
"append",
"(",
"'spyder'",
")",
"else",
":",
"username",
"=",
... | Return temporary Spyder directory, checking previously that it exists. | [
"Return",
"temporary",
"Spyder",
"directory",
"checking",
"previously",
"that",
"it",
"exists",
"."
] | python | train |
pallets/werkzeug | src/werkzeug/wrappers/base_request.py | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/wrappers/base_request.py#L532-L540 | def path(self):
"""Requested path as unicode. This works a bit like the regular path
info in the WSGI environment but will always include a leading slash,
even if the URL root is accessed.
"""
raw_path = wsgi_decoding_dance(
self.environ.get("PATH_INFO") or "", self.... | [
"def",
"path",
"(",
"self",
")",
":",
"raw_path",
"=",
"wsgi_decoding_dance",
"(",
"self",
".",
"environ",
".",
"get",
"(",
"\"PATH_INFO\"",
")",
"or",
"\"\"",
",",
"self",
".",
"charset",
",",
"self",
".",
"encoding_errors",
")",
"return",
"\"/\"",
"+",... | Requested path as unicode. This works a bit like the regular path
info in the WSGI environment but will always include a leading slash,
even if the URL root is accessed. | [
"Requested",
"path",
"as",
"unicode",
".",
"This",
"works",
"a",
"bit",
"like",
"the",
"regular",
"path",
"info",
"in",
"the",
"WSGI",
"environment",
"but",
"will",
"always",
"include",
"a",
"leading",
"slash",
"even",
"if",
"the",
"URL",
"root",
"is",
"... | python | train |
ArchiveTeam/wpull | wpull/scraper/html.py | https://github.com/ArchiveTeam/wpull/blob/ddf051aa3322479325ba20aa778cb2cb97606bf5/wpull/scraper/html.py#L551-L575 | def iter_links_script_element(self, element):
'''Iterate a ``script`` element.'''
if self.javascript_scraper and element.text:
link_iter = self.javascript_scraper.scrape_links(element.text,
context=True)
for link, cont... | [
"def",
"iter_links_script_element",
"(",
"self",
",",
"element",
")",
":",
"if",
"self",
".",
"javascript_scraper",
"and",
"element",
".",
"text",
":",
"link_iter",
"=",
"self",
".",
"javascript_scraper",
".",
"scrape_links",
"(",
"element",
".",
"text",
",",
... | Iterate a ``script`` element. | [
"Iterate",
"a",
"script",
"element",
"."
] | python | train |
codelv/enaml-native | src/enamlnative/android/android_web_view.py | https://github.com/codelv/enaml-native/blob/c33986e9eda468c508806e0a3e73c771401e5718/src/enamlnative/android/android_web_view.py#L95-L103 | def destroy(self):
""" Destroy the client
"""
if self.client:
#: Stop listening
self.client.setWebView(self.widget, None)
del self.client
super(AndroidWebView, self).destroy() | [
"def",
"destroy",
"(",
"self",
")",
":",
"if",
"self",
".",
"client",
":",
"#: Stop listening",
"self",
".",
"client",
".",
"setWebView",
"(",
"self",
".",
"widget",
",",
"None",
")",
"del",
"self",
".",
"client",
"super",
"(",
"AndroidWebView",
",",
"... | Destroy the client | [
"Destroy",
"the",
"client"
] | python | train |
pyroscope/pyrocore | src/pyrocore/torrent/rtorrent.py | https://github.com/pyroscope/pyrocore/blob/89ad01346a570943d20311a0b488440975876612/src/pyrocore/torrent/rtorrent.py#L399-L503 | def cull(self, file_filter=None, attrs=None):
""" Delete ALL data files and remove torrent from client.
@param file_filter: Optional callable for selecting a subset of all files.
The callable gets a file item as described for RtorrentItem._get_files
and must return T... | [
"def",
"cull",
"(",
"self",
",",
"file_filter",
"=",
"None",
",",
"attrs",
"=",
"None",
")",
":",
"dry_run",
"=",
"0",
"# set to 1 for testing",
"def",
"remove_with_links",
"(",
"path",
")",
":",
"\"Remove a path including any symlink chains leading to it.\"",
"rm_p... | Delete ALL data files and remove torrent from client.
@param file_filter: Optional callable for selecting a subset of all files.
The callable gets a file item as described for RtorrentItem._get_files
and must return True for items eligible for deletion.
@param at... | [
"Delete",
"ALL",
"data",
"files",
"and",
"remove",
"torrent",
"from",
"client",
"."
] | python | train |
rjdkmr/do_x3dna | dnaMD/dnaMD/dnaEY.py | https://github.com/rjdkmr/do_x3dna/blob/fe910335eefcada76737f9e7cd6f25036cd32ab6/dnaMD/dnaMD/dnaEY.py#L1183-L1267 | def calculateLocalElasticitySegments(self, bp, span=2, frameGap=None, helical=False, unit='kT',
err_type='block', tool='gmx analyze', outFile=None):
"""Calculate local elastic properties of consecutive overlapped DNA segments
Calculate local elastic properties o... | [
"def",
"calculateLocalElasticitySegments",
"(",
"self",
",",
"bp",
",",
"span",
"=",
"2",
",",
"frameGap",
"=",
"None",
",",
"helical",
"=",
"False",
",",
"unit",
"=",
"'kT'",
",",
"err_type",
"=",
"'block'",
",",
"tool",
"=",
"'gmx analyze'",
",",
"outF... | Calculate local elastic properties of consecutive overlapped DNA segments
Calculate local elastic properties of consecutive overlapped DNA segments of length given by `span`.
Parameters
----------
bp : list
List of two base-steps forming the global DNA segment.
... | [
"Calculate",
"local",
"elastic",
"properties",
"of",
"consecutive",
"overlapped",
"DNA",
"segments"
] | python | train |
aliyun/aliyun-odps-python-sdk | odps/df/expr/element.py | https://github.com/aliyun/aliyun-odps-python-sdk/blob/4b0de18f5864386df6068f26f026e62f932c41e4/odps/df/expr/element.py#L599-L653 | def _switch(expr, *args, **kw):
"""
Similar to the case-when in SQL. Refer to the example below
:param expr:
:param args:
:param kw:
:return: sequence or scalar
:Example:
>>> # if df.id == 3 then df.name
>>> # elif df.id == df.fid.abs() then df.name + 'test'
>>> # default: 'te... | [
"def",
"_switch",
"(",
"expr",
",",
"*",
"args",
",",
"*",
"*",
"kw",
")",
":",
"default",
"=",
"_scalar",
"(",
"kw",
".",
"get",
"(",
"'default'",
")",
")",
"if",
"len",
"(",
"args",
")",
"<=",
"0",
":",
"raise",
"errors",
".",
"ExpressionError"... | Similar to the case-when in SQL. Refer to the example below
:param expr:
:param args:
:param kw:
:return: sequence or scalar
:Example:
>>> # if df.id == 3 then df.name
>>> # elif df.id == df.fid.abs() then df.name + 'test'
>>> # default: 'test'
>>> df.id.switch(3, df.name, df.fid.... | [
"Similar",
"to",
"the",
"case",
"-",
"when",
"in",
"SQL",
".",
"Refer",
"to",
"the",
"example",
"below"
] | python | train |
AshleySetter/optoanalysis | optoanalysis/optoanalysis/optoanalysis.py | https://github.com/AshleySetter/optoanalysis/blob/9d390acc834d70024d47b574aea14189a5a5714e/optoanalysis/optoanalysis/optoanalysis.py#L3728-L3757 | def dynamical_potential(xdata, dt, order=3):
"""
Computes potential from spring function
Parameters
----------
xdata : ndarray
Position data for a degree of freedom,
at which to calculate potential
dt : float
time between measurements
order : int
order of pol... | [
"def",
"dynamical_potential",
"(",
"xdata",
",",
"dt",
",",
"order",
"=",
"3",
")",
":",
"import",
"numpy",
"as",
"_np",
"adata",
"=",
"calc_acceleration",
"(",
"xdata",
",",
"dt",
")",
"xdata",
"=",
"xdata",
"[",
"2",
":",
"]",
"# removes first 2 values... | Computes potential from spring function
Parameters
----------
xdata : ndarray
Position data for a degree of freedom,
at which to calculate potential
dt : float
time between measurements
order : int
order of polynomial to fit
Returns
-------
Potential : n... | [
"Computes",
"potential",
"from",
"spring",
"function"
] | python | train |
PBR/MQ2 | MQ2/add_marker_to_qtls.py | https://github.com/PBR/MQ2/blob/6d84dea47e6751333004743f588f03158e35c28d/MQ2/add_marker_to_qtls.py#L38-L55 | def add_marker_to_qtl(qtl, map_list):
"""Add the closest marker to the given QTL.
:arg qtl: a row of the QTL list.
:arg map_list: the genetic map containing the list of markers.
"""
closest = ''
diff = None
for marker in map_list:
if qtl[1] == marker[1]:
tmp_diff = floa... | [
"def",
"add_marker_to_qtl",
"(",
"qtl",
",",
"map_list",
")",
":",
"closest",
"=",
"''",
"diff",
"=",
"None",
"for",
"marker",
"in",
"map_list",
":",
"if",
"qtl",
"[",
"1",
"]",
"==",
"marker",
"[",
"1",
"]",
":",
"tmp_diff",
"=",
"float",
"(",
"qt... | Add the closest marker to the given QTL.
:arg qtl: a row of the QTL list.
:arg map_list: the genetic map containing the list of markers. | [
"Add",
"the",
"closest",
"marker",
"to",
"the",
"given",
"QTL",
"."
] | python | train |
draios/python-sdc-client | sdcclient/_monitor.py | https://github.com/draios/python-sdc-client/blob/47f83415842048778939b90944f64386a3bcb205/sdcclient/_monitor.py#L94-L170 | def create_alert(self, name=None, description=None, severity=None, for_atleast_s=None, condition=None,
segmentby=[], segment_condition='ANY', user_filter='', notify=None, enabled=True,
annotations={}, alert_obj=None):
'''**Description**
Create a threshold-ba... | [
"def",
"create_alert",
"(",
"self",
",",
"name",
"=",
"None",
",",
"description",
"=",
"None",
",",
"severity",
"=",
"None",
",",
"for_atleast_s",
"=",
"None",
",",
"condition",
"=",
"None",
",",
"segmentby",
"=",
"[",
"]",
",",
"segment_condition",
"=",... | **Description**
Create a threshold-based alert.
**Arguments**
- **name**: the alert name. This will appear in the Sysdig Monitor UI and in notification emails.
- **description**: the alert description. This will appear in the Sysdig Monitor UI and in notification emails.
... | [
"**",
"Description",
"**",
"Create",
"a",
"threshold",
"-",
"based",
"alert",
"."
] | python | test |
edx/edx-enterprise | enterprise/admin/views.py | https://github.com/edx/edx-enterprise/blob/aea91379ab0a87cd3bc798961fce28b60ee49a80/enterprise/admin/views.py#L676-L696 | def get_failed_enrollment_message(cls, users, enrolled_in):
"""
Create message for the users who were not able to be enrolled in a course or program.
Args:
users: An iterable of users who were not successfully enrolled
enrolled_in (str): A string identifier for the cours... | [
"def",
"get_failed_enrollment_message",
"(",
"cls",
",",
"users",
",",
"enrolled_in",
")",
":",
"failed_emails",
"=",
"[",
"user",
".",
"email",
"for",
"user",
"in",
"users",
"]",
"return",
"(",
"'error'",
",",
"_",
"(",
"'The following learners could not be enr... | Create message for the users who were not able to be enrolled in a course or program.
Args:
users: An iterable of users who were not successfully enrolled
enrolled_in (str): A string identifier for the course or program with which enrollment was attempted
Returns:
tuple... | [
"Create",
"message",
"for",
"the",
"users",
"who",
"were",
"not",
"able",
"to",
"be",
"enrolled",
"in",
"a",
"course",
"or",
"program",
"."
] | python | valid |
ewiger/mlab | src/mlab/awmstools.py | https://github.com/ewiger/mlab/blob/72a98adf6499f548848ad44c604f74d68f07fe4f/src/mlab/awmstools.py#L1011-L1022 | def without(seq1, seq2):
r"""Return a list with all elements in `seq2` removed from `seq1`, order
preserved.
Examples:
>>> without([1,2,3,1,2], [1])
[2, 3, 2]
"""
if isSet(seq2): d2 = seq2
else: d2 = set(seq2)
return [elt for elt in seq1 if elt not in d2] | [
"def",
"without",
"(",
"seq1",
",",
"seq2",
")",
":",
"if",
"isSet",
"(",
"seq2",
")",
":",
"d2",
"=",
"seq2",
"else",
":",
"d2",
"=",
"set",
"(",
"seq2",
")",
"return",
"[",
"elt",
"for",
"elt",
"in",
"seq1",
"if",
"elt",
"not",
"in",
"d2",
... | r"""Return a list with all elements in `seq2` removed from `seq1`, order
preserved.
Examples:
>>> without([1,2,3,1,2], [1])
[2, 3, 2] | [
"r",
"Return",
"a",
"list",
"with",
"all",
"elements",
"in",
"seq2",
"removed",
"from",
"seq1",
"order",
"preserved",
"."
] | python | train |
rtfd/sphinx-autoapi | autoapi/mappers/javascript.py | https://github.com/rtfd/sphinx-autoapi/blob/9735f43a8d9ff4620c7bcbd177fd1bb7608052e9/autoapi/mappers/javascript.py#L42-L48 | def map(self, options=None):
"""Trigger find of serialized sources and build objects"""
for path, data in self.paths.items():
for item in data:
for obj in self.create_class(item, options):
obj.jinja_env = self.jinja_env
self.add_object(... | [
"def",
"map",
"(",
"self",
",",
"options",
"=",
"None",
")",
":",
"for",
"path",
",",
"data",
"in",
"self",
".",
"paths",
".",
"items",
"(",
")",
":",
"for",
"item",
"in",
"data",
":",
"for",
"obj",
"in",
"self",
".",
"create_class",
"(",
"item",... | Trigger find of serialized sources and build objects | [
"Trigger",
"find",
"of",
"serialized",
"sources",
"and",
"build",
"objects"
] | python | train |
wummel/linkchecker | linkcheck/director/aggregator.py | https://github.com/wummel/linkchecker/blob/c2ce810c3fb00b895a841a7be6b2e78c64e7b042/linkcheck/director/aggregator.py#L211-L217 | def end_log_output(self, **kwargs):
"""Print ending output to log."""
kwargs.update(dict(
downloaded_bytes=self.downloaded_bytes,
num_urls = len(self.result_cache),
))
self.logger.end_log_output(**kwargs) | [
"def",
"end_log_output",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"kwargs",
".",
"update",
"(",
"dict",
"(",
"downloaded_bytes",
"=",
"self",
".",
"downloaded_bytes",
",",
"num_urls",
"=",
"len",
"(",
"self",
".",
"result_cache",
")",
",",
")",
... | Print ending output to log. | [
"Print",
"ending",
"output",
"to",
"log",
"."
] | python | train |
bcbio/bcbio-nextgen | bcbio/bam/__init__.py | https://github.com/bcbio/bcbio-nextgen/blob/6a9348c0054ccd5baffd22f1bb7d0422f6978b20/bcbio/bam/__init__.py#L253-L257 | def check_header(in_bam, rgnames, ref_file, config):
"""Ensure passed in BAM header matches reference file and read groups names.
"""
_check_bam_contigs(in_bam, ref_file, config)
_check_sample(in_bam, rgnames) | [
"def",
"check_header",
"(",
"in_bam",
",",
"rgnames",
",",
"ref_file",
",",
"config",
")",
":",
"_check_bam_contigs",
"(",
"in_bam",
",",
"ref_file",
",",
"config",
")",
"_check_sample",
"(",
"in_bam",
",",
"rgnames",
")"
] | Ensure passed in BAM header matches reference file and read groups names. | [
"Ensure",
"passed",
"in",
"BAM",
"header",
"matches",
"reference",
"file",
"and",
"read",
"groups",
"names",
"."
] | python | train |
mitsei/dlkit | dlkit/records/assessment/basic/feedback_answer_records.py | https://github.com/mitsei/dlkit/blob/445f968a175d61c8d92c0f617a3c17dc1dc7c584/dlkit/records/assessment/basic/feedback_answer_records.py#L77-L82 | def _init_map(self):
"""stub"""
self.my_osid_object_form._my_map['confusedLearningObjectiveIds'] = \
self._confused_learning_objectives_metadata['default_list_values'][0]
self.my_osid_object_form._my_map['feedback'] = \
self._feedback_metadata['default_string_values'][0] | [
"def",
"_init_map",
"(",
"self",
")",
":",
"self",
".",
"my_osid_object_form",
".",
"_my_map",
"[",
"'confusedLearningObjectiveIds'",
"]",
"=",
"self",
".",
"_confused_learning_objectives_metadata",
"[",
"'default_list_values'",
"]",
"[",
"0",
"]",
"self",
".",
"m... | stub | [
"stub"
] | python | train |
pgmpy/pgmpy | pgmpy/sampling/HMC.py | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/sampling/HMC.py#L518-L594 | def generate_sample(self, initial_pos, num_adapt, num_samples, trajectory_length, stepsize=None):
"""
Method returns a generator type object whose each iteration yields a sample
using Hamiltonian Monte Carlo
Parameters
----------
initial_pos: A 1d array like object
... | [
"def",
"generate_sample",
"(",
"self",
",",
"initial_pos",
",",
"num_adapt",
",",
"num_samples",
",",
"trajectory_length",
",",
"stepsize",
"=",
"None",
")",
":",
"self",
".",
"accepted_proposals",
"=",
"0",
"initial_pos",
"=",
"_check_1d_array_object",
"(",
"in... | Method returns a generator type object whose each iteration yields a sample
using Hamiltonian Monte Carlo
Parameters
----------
initial_pos: A 1d array like object
Vector representing values of parameter position, the starting
state in markov chain.
num_... | [
"Method",
"returns",
"a",
"generator",
"type",
"object",
"whose",
"each",
"iteration",
"yields",
"a",
"sample",
"using",
"Hamiltonian",
"Monte",
"Carlo"
] | python | train |
sethmlarson/virtualbox-python | virtualbox/library.py | https://github.com/sethmlarson/virtualbox-python/blob/706c8e3f6e3aee17eb06458e73cbb4bc2d37878b/virtualbox/library.py#L8554-L8568 | def set_settings_secret(self, password):
"""Unlocks the secret data by passing the unlock password to the
server. The server will cache the password for that machine.
in password of type str
The cipher key.
raises :class:`VBoxErrorInvalidVmState`
Virtual machine... | [
"def",
"set_settings_secret",
"(",
"self",
",",
"password",
")",
":",
"if",
"not",
"isinstance",
"(",
"password",
",",
"basestring",
")",
":",
"raise",
"TypeError",
"(",
"\"password can only be an instance of type basestring\"",
")",
"self",
".",
"_call",
"(",
"\"... | Unlocks the secret data by passing the unlock password to the
server. The server will cache the password for that machine.
in password of type str
The cipher key.
raises :class:`VBoxErrorInvalidVmState`
Virtual machine is not mutable. | [
"Unlocks",
"the",
"secret",
"data",
"by",
"passing",
"the",
"unlock",
"password",
"to",
"the",
"server",
".",
"The",
"server",
"will",
"cache",
"the",
"password",
"for",
"that",
"machine",
"."
] | python | train |
xapple/plumbing | plumbing/databases/sqlite_database.py | https://github.com/xapple/plumbing/blob/4a7706c7722f5996d0ca366f191aff9ac145880a/plumbing/databases/sqlite_database.py#L334-L345 | def get_and_order(self, ids, column=None, table=None):
"""Get specific entries and order them in the same way."""
command = """
SELECT rowid, * from "data"
WHERE rowid in (%s)
ORDER BY CASE rowid
%s
END;
"""
ordered = ','.join(map(str,ids))
... | [
"def",
"get_and_order",
"(",
"self",
",",
"ids",
",",
"column",
"=",
"None",
",",
"table",
"=",
"None",
")",
":",
"command",
"=",
"\"\"\"\n SELECT rowid, * from \"data\"\n WHERE rowid in (%s)\n ORDER BY CASE rowid\n %s\n END;\n \"\"\"",
... | Get specific entries and order them in the same way. | [
"Get",
"specific",
"entries",
"and",
"order",
"them",
"in",
"the",
"same",
"way",
"."
] | python | train |
OCHA-DAP/hdx-python-api | src/hdx/data/dataset.py | https://github.com/OCHA-DAP/hdx-python-api/blob/212440f54f73805826a16db77dbcb6033b18a313/src/hdx/data/dataset.py#L355-L374 | def _dataset_merge_filestore_resource(self, resource, updated_resource, filestore_resources, ignore_fields):
# type: (hdx.data.Resource, hdx.data.Resource, List[hdx.data.Resource], List[str]) -> None
"""Helper method to merge updated resource from dataset into HDX resource read from HDX including filest... | [
"def",
"_dataset_merge_filestore_resource",
"(",
"self",
",",
"resource",
",",
"updated_resource",
",",
"filestore_resources",
",",
"ignore_fields",
")",
":",
"# type: (hdx.data.Resource, hdx.data.Resource, List[hdx.data.Resource], List[str]) -> None",
"if",
"updated_resource",
"."... | Helper method to merge updated resource from dataset into HDX resource read from HDX including filestore.
Args:
resource (hdx.data.Resource): Resource read from HDX
updated_resource (hdx.data.Resource): Updated resource from dataset
filestore_resources (List[hdx.data.Resourc... | [
"Helper",
"method",
"to",
"merge",
"updated",
"resource",
"from",
"dataset",
"into",
"HDX",
"resource",
"read",
"from",
"HDX",
"including",
"filestore",
"."
] | python | train |
Parsl/parsl | parsl/executors/serialize/canning.py | https://github.com/Parsl/parsl/blob/d7afb3bc37f50dcf224ae78637944172edb35dac/parsl/executors/serialize/canning.py#L87-L96 | def use_pickle():
"""Revert to using stdlib pickle.
Reverts custom serialization enabled by use_dill|cloudpickle.
"""
from . import serialize
serialize.pickle = serialize._stdlib_pickle
# restore special function handling
can_map[FunctionType] = _original_can_map[FunctionType] | [
"def",
"use_pickle",
"(",
")",
":",
"from",
".",
"import",
"serialize",
"serialize",
".",
"pickle",
"=",
"serialize",
".",
"_stdlib_pickle",
"# restore special function handling",
"can_map",
"[",
"FunctionType",
"]",
"=",
"_original_can_map",
"[",
"FunctionType",
"]... | Revert to using stdlib pickle.
Reverts custom serialization enabled by use_dill|cloudpickle. | [
"Revert",
"to",
"using",
"stdlib",
"pickle",
"."
] | python | valid |
apache/airflow | airflow/security/kerberos.py | https://github.com/apache/airflow/blob/b69c686ad8a0c89b9136bb4b31767257eb7b2597/airflow/security/kerberos.py#L100-L110 | def detect_conf_var():
"""Return true if the ticket cache contains "conf" information as is found
in ticket caches of Kerberos 1.8.1 or later. This is incompatible with the
Sun Java Krb5LoginModule in Java6, so we need to take an action to work
around it.
"""
ticket_cache = configuration.conf.ge... | [
"def",
"detect_conf_var",
"(",
")",
":",
"ticket_cache",
"=",
"configuration",
".",
"conf",
".",
"get",
"(",
"'kerberos'",
",",
"'ccache'",
")",
"with",
"open",
"(",
"ticket_cache",
",",
"'rb'",
")",
"as",
"f",
":",
"# Note: this file is binary, so we check agai... | Return true if the ticket cache contains "conf" information as is found
in ticket caches of Kerberos 1.8.1 or later. This is incompatible with the
Sun Java Krb5LoginModule in Java6, so we need to take an action to work
around it. | [
"Return",
"true",
"if",
"the",
"ticket",
"cache",
"contains",
"conf",
"information",
"as",
"is",
"found",
"in",
"ticket",
"caches",
"of",
"Kerberos",
"1",
".",
"8",
".",
"1",
"or",
"later",
".",
"This",
"is",
"incompatible",
"with",
"the",
"Sun",
"Java",... | python | test |
Accelize/pycosio | pycosio/_core/functions_os_path.py | https://github.com/Accelize/pycosio/blob/1cc1f8fdf5394d92918b7bae2bfa682169ccc48c/pycosio/_core/functions_os_path.py#L176-L202 | def relpath(path, start=None):
"""
Return a relative file path to path either from the
current directory or from an optional start directory.
For storage objects, "path" and "start" are relative to
storage root.
"/" are not stripped on storage objects path. The ending slash is required
on ... | [
"def",
"relpath",
"(",
"path",
",",
"start",
"=",
"None",
")",
":",
"relative",
"=",
"get_instance",
"(",
"path",
")",
".",
"relpath",
"(",
"path",
")",
"if",
"start",
":",
"# Storage relative path",
"# Replaces \"\\\" by \"/\" for Windows.",
"return",
"os_path_... | Return a relative file path to path either from the
current directory or from an optional start directory.
For storage objects, "path" and "start" are relative to
storage root.
"/" are not stripped on storage objects path. The ending slash is required
on some storage to signify that target is a di... | [
"Return",
"a",
"relative",
"file",
"path",
"to",
"path",
"either",
"from",
"the",
"current",
"directory",
"or",
"from",
"an",
"optional",
"start",
"directory",
"."
] | python | train |
awslabs/aws-shell | awsshell/utils.py | https://github.com/awslabs/aws-shell/blob/8950f03d9d720879890af6c11537b8f9789ce5a9/awsshell/utils.py#L73-L87 | def file_contents(self, filename, binary=False):
"""Return the file for a given filename.
If you want binary content use ``mode='rb'``.
"""
if binary:
mode = 'rb'
else:
mode = 'r'
try:
with open(filename, mode) as f:
r... | [
"def",
"file_contents",
"(",
"self",
",",
"filename",
",",
"binary",
"=",
"False",
")",
":",
"if",
"binary",
":",
"mode",
"=",
"'rb'",
"else",
":",
"mode",
"=",
"'r'",
"try",
":",
"with",
"open",
"(",
"filename",
",",
"mode",
")",
"as",
"f",
":",
... | Return the file for a given filename.
If you want binary content use ``mode='rb'``. | [
"Return",
"the",
"file",
"for",
"a",
"given",
"filename",
"."
] | python | train |
ricequant/rqalpha | rqalpha/api/api_base.py | https://github.com/ricequant/rqalpha/blob/ac40a62d4e7eca9494b4d0a14f46facf5616820c/rqalpha/api/api_base.py#L387-L407 | def unsubscribe(id_or_symbols):
"""
取消订阅合约行情。取消订阅会导致合约池内合约的减少,如果当前合约池中没有任何合约,则策略直接退出。
:param id_or_symbols: 标的物
:type id_or_symbols: :class:`~Instrument` object | `str` | List[:class:`~Instrument`] | List[`str`]
"""
current_universe = Environment.get_instance().get_universe()
if isinstance(... | [
"def",
"unsubscribe",
"(",
"id_or_symbols",
")",
":",
"current_universe",
"=",
"Environment",
".",
"get_instance",
"(",
")",
".",
"get_universe",
"(",
")",
"if",
"isinstance",
"(",
"id_or_symbols",
",",
"six",
".",
"string_types",
")",
":",
"order_book_id",
"=... | 取消订阅合约行情。取消订阅会导致合约池内合约的减少,如果当前合约池中没有任何合约,则策略直接退出。
:param id_or_symbols: 标的物
:type id_or_symbols: :class:`~Instrument` object | `str` | List[:class:`~Instrument`] | List[`str`] | [
"取消订阅合约行情。取消订阅会导致合约池内合约的减少,如果当前合约池中没有任何合约,则策略直接退出。"
] | python | train |
matrix-org/matrix-python-sdk | matrix_client/room.py | https://github.com/matrix-org/matrix-python-sdk/blob/e734cce3ccd35f2d355c6a19a7a701033472498a/matrix_client/room.py#L472-L478 | def add_room_alias(self, room_alias):
"""Add an alias to the room and return True if successful."""
try:
self.client.api.set_room_alias(self.room_id, room_alias)
return True
except MatrixRequestError:
return False | [
"def",
"add_room_alias",
"(",
"self",
",",
"room_alias",
")",
":",
"try",
":",
"self",
".",
"client",
".",
"api",
".",
"set_room_alias",
"(",
"self",
".",
"room_id",
",",
"room_alias",
")",
"return",
"True",
"except",
"MatrixRequestError",
":",
"return",
"... | Add an alias to the room and return True if successful. | [
"Add",
"an",
"alias",
"to",
"the",
"room",
"and",
"return",
"True",
"if",
"successful",
"."
] | python | train |
postlund/pyatv | pyatv/mrp/protocol.py | https://github.com/postlund/pyatv/blob/655dfcda4e2f9d1c501540e18da4f480d8bf0e70/pyatv/mrp/protocol.py#L53-L99 | async def start(self):
"""Connect to device and listen to incoming messages."""
if self.connection.connected:
return
await self.connection.connect()
# In case credentials have been given externally (i.e. not by pairing
# with a device), then use that client id
... | [
"async",
"def",
"start",
"(",
"self",
")",
":",
"if",
"self",
".",
"connection",
".",
"connected",
":",
"return",
"await",
"self",
".",
"connection",
".",
"connect",
"(",
")",
"# In case credentials have been given externally (i.e. not by pairing",
"# with a device), ... | Connect to device and listen to incoming messages. | [
"Connect",
"to",
"device",
"and",
"listen",
"to",
"incoming",
"messages",
"."
] | python | train |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/dialects/v10/matrixpilot.py | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/dialects/v10/matrixpilot.py#L11965-L11982 | def scaled_imu3_encode(self, time_boot_ms, xacc, yacc, zacc, xgyro, ygyro, zgyro, xmag, ymag, zmag):
'''
The RAW IMU readings for 3rd 9DOF sensor setup. This message should
contain the scaled values to the described units
time_boot_ms : Times... | [
"def",
"scaled_imu3_encode",
"(",
"self",
",",
"time_boot_ms",
",",
"xacc",
",",
"yacc",
",",
"zacc",
",",
"xgyro",
",",
"ygyro",
",",
"zgyro",
",",
"xmag",
",",
"ymag",
",",
"zmag",
")",
":",
"return",
"MAVLink_scaled_imu3_message",
"(",
"time_boot_ms",
"... | The RAW IMU readings for 3rd 9DOF sensor setup. This message should
contain the scaled values to the described units
time_boot_ms : Timestamp (milliseconds since system boot) (uint32_t)
xacc : X acceleration (mg) (int16_t)
... | [
"The",
"RAW",
"IMU",
"readings",
"for",
"3rd",
"9DOF",
"sensor",
"setup",
".",
"This",
"message",
"should",
"contain",
"the",
"scaled",
"values",
"to",
"the",
"described",
"units"
] | python | train |
project-ncl/pnc-cli | pnc_cli/buildconfigurationsets.py | https://github.com/project-ncl/pnc-cli/blob/3dc149bf84928f60a8044ac50b58bbaddd451902/pnc_cli/buildconfigurationsets.py#L44-L51 | def create_build_configuration_set_raw(**kwargs):
"""
Create a new BuildConfigurationSet.
"""
config_set = _create_build_config_set_object(**kwargs)
response = utils.checked_api_call(pnc_api.build_group_configs, 'create_new', body=config_set)
if response:
return response.content | [
"def",
"create_build_configuration_set_raw",
"(",
"*",
"*",
"kwargs",
")",
":",
"config_set",
"=",
"_create_build_config_set_object",
"(",
"*",
"*",
"kwargs",
")",
"response",
"=",
"utils",
".",
"checked_api_call",
"(",
"pnc_api",
".",
"build_group_configs",
",",
... | Create a new BuildConfigurationSet. | [
"Create",
"a",
"new",
"BuildConfigurationSet",
"."
] | python | train |
fake-name/ChromeController | ChromeController/Generator/Generated.py | https://github.com/fake-name/ChromeController/blob/914dd136184e8f1165c7aa6ef30418aaf10c61f0/ChromeController/Generator/Generated.py#L5043-L5060 | def ServiceWorker_updateRegistration(self, scopeURL):
"""
Function path: ServiceWorker.updateRegistration
Domain: ServiceWorker
Method name: updateRegistration
Parameters:
Required arguments:
'scopeURL' (type: string) -> No description
No return value.
"""
assert isinstance(scopeURL, ... | [
"def",
"ServiceWorker_updateRegistration",
"(",
"self",
",",
"scopeURL",
")",
":",
"assert",
"isinstance",
"(",
"scopeURL",
",",
"(",
"str",
",",
")",
")",
",",
"\"Argument 'scopeURL' must be of type '['str']'. Received type: '%s'\"",
"%",
"type",
"(",
"scopeURL",
")"... | Function path: ServiceWorker.updateRegistration
Domain: ServiceWorker
Method name: updateRegistration
Parameters:
Required arguments:
'scopeURL' (type: string) -> No description
No return value. | [
"Function",
"path",
":",
"ServiceWorker",
".",
"updateRegistration",
"Domain",
":",
"ServiceWorker",
"Method",
"name",
":",
"updateRegistration",
"Parameters",
":",
"Required",
"arguments",
":",
"scopeURL",
"(",
"type",
":",
"string",
")",
"-",
">",
"No",
"descr... | python | train |
liamw9534/bt-manager | bt_manager/audio.py | https://github.com/liamw9534/bt-manager/blob/51be2919394ce8134c698359649bfad09eedf4ec/bt_manager/audio.py#L252-L264 | def write_transport(self, data):
"""
Write data to media transport. The data is
encoded using the SBC codec and RTP encapsulated
before being written to the transport file
descriptor.
:param array{byte} data: Payload data to encode,
encapsulate and send.
... | [
"def",
"write_transport",
"(",
"self",
",",
"data",
")",
":",
"if",
"(",
"'w'",
"not",
"in",
"self",
".",
"access_type",
")",
":",
"raise",
"BTIncompatibleTransportAccessType",
"return",
"self",
".",
"codec",
".",
"encode",
"(",
"self",
".",
"fd",
",",
"... | Write data to media transport. The data is
encoded using the SBC codec and RTP encapsulated
before being written to the transport file
descriptor.
:param array{byte} data: Payload data to encode,
encapsulate and send. | [
"Write",
"data",
"to",
"media",
"transport",
".",
"The",
"data",
"is",
"encoded",
"using",
"the",
"SBC",
"codec",
"and",
"RTP",
"encapsulated",
"before",
"being",
"written",
"to",
"the",
"transport",
"file",
"descriptor",
"."
] | python | train |
Erotemic/utool | utool/util_inspect.py | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_inspect.py#L1683-L1792 | def find_funcs_called_with_kwargs(sourcecode, target_kwargs_name='kwargs'):
r"""
Finds functions that are called with the keyword `kwargs` variable
CommandLine:
python3 -m utool.util_inspect find_funcs_called_with_kwargs
Example:
>>> # ENABLE_DOCTEST
>>> import utool as ut
... | [
"def",
"find_funcs_called_with_kwargs",
"(",
"sourcecode",
",",
"target_kwargs_name",
"=",
"'kwargs'",
")",
":",
"import",
"ast",
"sourcecode",
"=",
"'from __future__ import print_function\\n'",
"+",
"sourcecode",
"pt",
"=",
"ast",
".",
"parse",
"(",
"sourcecode",
")"... | r"""
Finds functions that are called with the keyword `kwargs` variable
CommandLine:
python3 -m utool.util_inspect find_funcs_called_with_kwargs
Example:
>>> # ENABLE_DOCTEST
>>> import utool as ut
>>> sourcecode = ut.codeblock(
'''
x, y = li... | [
"r",
"Finds",
"functions",
"that",
"are",
"called",
"with",
"the",
"keyword",
"kwargs",
"variable"
] | python | train |
welbornprod/colr | colr/colr_docopt.py | https://github.com/welbornprod/colr/blob/417117fdbddbc53142096685ac2af006b2bd0220/colr/colr_docopt.py#L57-L104 | def _coloredhelp(s):
""" Colorize the usage string for docopt
(ColorDocoptExit, docoptextras)
"""
newlines = []
bigindent = (' ' * 16)
in_opts = False
for line in s.split('\n'):
linestripped = line.strip('\n').strip().strip(':')
if linestripped == 'Usage':
# l... | [
"def",
"_coloredhelp",
"(",
"s",
")",
":",
"newlines",
"=",
"[",
"]",
"bigindent",
"=",
"(",
"' '",
"*",
"16",
")",
"in_opts",
"=",
"False",
"for",
"line",
"in",
"s",
".",
"split",
"(",
"'\\n'",
")",
":",
"linestripped",
"=",
"line",
".",
"strip",
... | Colorize the usage string for docopt
(ColorDocoptExit, docoptextras) | [
"Colorize",
"the",
"usage",
"string",
"for",
"docopt",
"(",
"ColorDocoptExit",
"docoptextras",
")"
] | python | train |
abe-winter/pg13-py | pg13/diff.py | https://github.com/abe-winter/pg13-py/blob/c78806f99f35541a8756987e86edca3438aa97f5/pg13/diff.py#L96-L108 | def rediff(a,b,global_a_slice=None):
"recursive diff (splits around longest substring and runs diff on head and tail remnants).\
global_a_slice is used for recursion and should be left undefined in outer call.\
returns a list of Delta tuples."
if not (a or b): return []
global_a_slice=global_a_slice or (... | [
"def",
"rediff",
"(",
"a",
",",
"b",
",",
"global_a_slice",
"=",
"None",
")",
":",
"if",
"not",
"(",
"a",
"or",
"b",
")",
":",
"return",
"[",
"]",
"global_a_slice",
"=",
"global_a_slice",
"or",
"(",
"0",
",",
"len",
"(",
"a",
")",
")",
"csresult"... | recursive diff (splits around longest substring and runs diff on head and tail remnants).\
global_a_slice is used for recursion and should be left undefined in outer call.\
returns a list of Delta tuples. | [
"recursive",
"diff",
"(",
"splits",
"around",
"longest",
"substring",
"and",
"runs",
"diff",
"on",
"head",
"and",
"tail",
"remnants",
")",
".",
"\\",
"global_a_slice",
"is",
"used",
"for",
"recursion",
"and",
"should",
"be",
"left",
"undefined",
"in",
"outer... | python | train |
googleapis/google-cloud-python | firestore/google/cloud/firestore_v1beta1/query.py | https://github.com/googleapis/google-cloud-python/blob/85e80125a59cb10f8cb105f25ecc099e4b940b50/firestore/google/cloud/firestore_v1beta1/query.py#L283-L324 | def order_by(self, field_path, direction=ASCENDING):
"""Modify the query to add an order clause on a specific field.
See :meth:`~.firestore_v1beta1.client.Client.field_path` for
more information on **field paths**.
Successive :meth:`~.firestore_v1beta1.query.Query.order_by` calls
... | [
"def",
"order_by",
"(",
"self",
",",
"field_path",
",",
"direction",
"=",
"ASCENDING",
")",
":",
"field_path_module",
".",
"split_field_path",
"(",
"field_path",
")",
"# raises",
"order_pb",
"=",
"self",
".",
"_make_order",
"(",
"field_path",
",",
"direction",
... | Modify the query to add an order clause on a specific field.
See :meth:`~.firestore_v1beta1.client.Client.field_path` for
more information on **field paths**.
Successive :meth:`~.firestore_v1beta1.query.Query.order_by` calls
will further refine the ordering of results returned by the q... | [
"Modify",
"the",
"query",
"to",
"add",
"an",
"order",
"clause",
"on",
"a",
"specific",
"field",
"."
] | python | train |
nschloe/matplotlib2tikz | matplotlib2tikz/text.py | https://github.com/nschloe/matplotlib2tikz/blob/ac5daca6f38b834d757f6c6ae6cc34121956f46b/matplotlib2tikz/text.py#L8-L126 | def draw_text(data, obj):
"""Paints text on the graph.
"""
content = []
properties = []
style = []
if isinstance(obj, mpl.text.Annotation):
_annotation(obj, data, content)
# 1: coordinates
# 2: properties (shapes, rotation, etc)
# 3: text style
# 4: the text
# ... | [
"def",
"draw_text",
"(",
"data",
",",
"obj",
")",
":",
"content",
"=",
"[",
"]",
"properties",
"=",
"[",
"]",
"style",
"=",
"[",
"]",
"if",
"isinstance",
"(",
"obj",
",",
"mpl",
".",
"text",
".",
"Annotation",
")",
":",
"_annotation",
"(",
"obj",
... | Paints text on the graph. | [
"Paints",
"text",
"on",
"the",
"graph",
"."
] | python | train |
bykof/billomapy | billomapy/billomapy.py | https://github.com/bykof/billomapy/blob/a28ba69fd37654fa145d0411d52c200e7f8984ab/billomapy/billomapy.py#L559-L567 | def update_supplier(self, supplier_id, supplier_dict):
"""
Updates a supplier
:param supplier_id: the supplier id
:param supplier_dict: dict
:return: dict
"""
return self._create_put_request(resource=SUPPLIERS, billomat_id=supplier_id, send_data=supplier_dict) | [
"def",
"update_supplier",
"(",
"self",
",",
"supplier_id",
",",
"supplier_dict",
")",
":",
"return",
"self",
".",
"_create_put_request",
"(",
"resource",
"=",
"SUPPLIERS",
",",
"billomat_id",
"=",
"supplier_id",
",",
"send_data",
"=",
"supplier_dict",
")"
] | Updates a supplier
:param supplier_id: the supplier id
:param supplier_dict: dict
:return: dict | [
"Updates",
"a",
"supplier"
] | python | train |
bunq/sdk_python | bunq/sdk/model/generated/endpoint.py | https://github.com/bunq/sdk_python/blob/da6c9b83e6d83ee8062617f53c6eb7293c0d863d/bunq/sdk/model/generated/endpoint.py#L31600-L31639 | def create(cls, client_payment_service_provider_certificate,
client_payment_service_provider_certificate_chain,
client_public_key_signature, custom_headers=None):
"""
:param client_payment_service_provider_certificate: Payment Services
Directive 2 compatible QSEAL c... | [
"def",
"create",
"(",
"cls",
",",
"client_payment_service_provider_certificate",
",",
"client_payment_service_provider_certificate_chain",
",",
"client_public_key_signature",
",",
"custom_headers",
"=",
"None",
")",
":",
"if",
"custom_headers",
"is",
"None",
":",
"custom_he... | :param client_payment_service_provider_certificate: Payment Services
Directive 2 compatible QSEAL certificate
:type client_payment_service_provider_certificate: str
:param client_payment_service_provider_certificate_chain: Intermediate
and root certificate belonging to the provided certi... | [
":",
"param",
"client_payment_service_provider_certificate",
":",
"Payment",
"Services",
"Directive",
"2",
"compatible",
"QSEAL",
"certificate",
":",
"type",
"client_payment_service_provider_certificate",
":",
"str",
":",
"param",
"client_payment_service_provider_certificate_chai... | python | train |
portfoliome/foil | foil/dates.py | https://github.com/portfoliome/foil/blob/b66d8cf4ab048a387d8c7a033b47e922ed6917d6/foil/dates.py#L47-L52 | def parse_date(date_str: str, pattern=_RE_DATE) -> dt.date:
"""Parse datetime.date from YYYY-MM-DD format."""
groups = re.match(pattern, date_str)
return dt.date(*_date_to_tuple(groups.groupdict())) | [
"def",
"parse_date",
"(",
"date_str",
":",
"str",
",",
"pattern",
"=",
"_RE_DATE",
")",
"->",
"dt",
".",
"date",
":",
"groups",
"=",
"re",
".",
"match",
"(",
"pattern",
",",
"date_str",
")",
"return",
"dt",
".",
"date",
"(",
"*",
"_date_to_tuple",
"(... | Parse datetime.date from YYYY-MM-DD format. | [
"Parse",
"datetime",
".",
"date",
"from",
"YYYY",
"-",
"MM",
"-",
"DD",
"format",
"."
] | python | train |
pymc-devs/pymc | pymc/distributions.py | https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/distributions.py#L2283-L2293 | def truncated_pareto_expval(alpha, m, b):
"""
Expected value of truncated Pareto distribution.
"""
if alpha <= 1:
return inf
part1 = (m ** alpha) / (1. - (m / b) ** alpha)
part2 = 1. * alpha / (alpha - 1)
part3 = (1. / (m ** (alpha - 1)) - 1. / (b ** (alpha - 1.)))
return part1 ... | [
"def",
"truncated_pareto_expval",
"(",
"alpha",
",",
"m",
",",
"b",
")",
":",
"if",
"alpha",
"<=",
"1",
":",
"return",
"inf",
"part1",
"=",
"(",
"m",
"**",
"alpha",
")",
"/",
"(",
"1.",
"-",
"(",
"m",
"/",
"b",
")",
"**",
"alpha",
")",
"part2",... | Expected value of truncated Pareto distribution. | [
"Expected",
"value",
"of",
"truncated",
"Pareto",
"distribution",
"."
] | python | train |
ynop/audiomate | audiomate/corpus/io/tatoeba.py | https://github.com/ynop/audiomate/blob/61727920b23a708293c3d526fa3000d4de9c6c21/audiomate/corpus/io/tatoeba.py#L123-L134 | def _download_audio_files(self, records, target_path):
"""
Download all audio files based on the given records.
"""
for record in records:
audio_folder = os.path.join(target_path, 'audio', record[2])
audio_file = os.path.join(audio_folder, '{}.mp3'.format(record[... | [
"def",
"_download_audio_files",
"(",
"self",
",",
"records",
",",
"target_path",
")",
":",
"for",
"record",
"in",
"records",
":",
"audio_folder",
"=",
"os",
".",
"path",
".",
"join",
"(",
"target_path",
",",
"'audio'",
",",
"record",
"[",
"2",
"]",
")",
... | Download all audio files based on the given records. | [
"Download",
"all",
"audio",
"files",
"based",
"on",
"the",
"given",
"records",
"."
] | python | train |
mapnik/Cascadenik | cascadenik/compile.py | https://github.com/mapnik/Cascadenik/blob/82f66859340a31dfcb24af127274f262d4f3ad85/cascadenik/compile.py#L1449-L1621 | def compile(src, dirs, verbose=False, srs=None, datasources_cfg=None, user_styles=[], scale=1):
""" Compile a Cascadenik MML file, returning a cascadenik.output.Map object.
Parameters:
src:
Path to .mml file, or raw .mml file content.
dirs:
... | [
"def",
"compile",
"(",
"src",
",",
"dirs",
",",
"verbose",
"=",
"False",
",",
"srs",
"=",
"None",
",",
"datasources_cfg",
"=",
"None",
",",
"user_styles",
"=",
"[",
"]",
",",
"scale",
"=",
"1",
")",
":",
"global",
"VERBOSE",
"if",
"verbose",
":",
"... | Compile a Cascadenik MML file, returning a cascadenik.output.Map object.
Parameters:
src:
Path to .mml file, or raw .mml file content.
dirs:
Object with directory names in 'cache', 'output', and 'source' attributes.
dirs.source is ... | [
"Compile",
"a",
"Cascadenik",
"MML",
"file",
"returning",
"a",
"cascadenik",
".",
"output",
".",
"Map",
"object",
".",
"Parameters",
":",
"src",
":",
"Path",
"to",
".",
"mml",
"file",
"or",
"raw",
".",
"mml",
"file",
"content",
".",
"dirs",
":",
"Objec... | python | train |
trec-kba/streamcorpus-pipeline | streamcorpus_pipeline/_kvlayer_table_names.py | https://github.com/trec-kba/streamcorpus-pipeline/blob/8bb82ea1beb83c6b40ed03fa1659df2897c2292a/streamcorpus_pipeline/_kvlayer_table_names.py#L174-L187 | def kvlayer_key_to_stream_id(k):
'''Convert a kvlayer key to a text stream ID.
`k` should be of the same form produced by
:func:`stream_id_to_kvlayer_key`.
:param k: :mod:`kvlayer` key tuple
:return: converted stream ID
:returntype str:
'''
abs_url_hash, epoch_ticks = k
return '{0... | [
"def",
"kvlayer_key_to_stream_id",
"(",
"k",
")",
":",
"abs_url_hash",
",",
"epoch_ticks",
"=",
"k",
"return",
"'{0}-{1}'",
".",
"format",
"(",
"epoch_ticks",
",",
"base64",
".",
"b16encode",
"(",
"abs_url_hash",
")",
".",
"lower",
"(",
")",
")"
] | Convert a kvlayer key to a text stream ID.
`k` should be of the same form produced by
:func:`stream_id_to_kvlayer_key`.
:param k: :mod:`kvlayer` key tuple
:return: converted stream ID
:returntype str: | [
"Convert",
"a",
"kvlayer",
"key",
"to",
"a",
"text",
"stream",
"ID",
"."
] | python | test |
ryan-roemer/django-cloud-browser | cloud_browser/cloud/errors.py | https://github.com/ryan-roemer/django-cloud-browser/blob/b06cdd24885a6309e843ed924dbf1705b67e7f48/cloud_browser/cloud/errors.py#L111-L123 | def translate(self, exc):
"""Return translation of exception to new class.
Calling code should only raise exception if exception class is passed
in, else ``None`` (which signifies no wrapping should be done).
"""
# Find actual class.
for key in self.translations.keys():
... | [
"def",
"translate",
"(",
"self",
",",
"exc",
")",
":",
"# Find actual class.",
"for",
"key",
"in",
"self",
".",
"translations",
".",
"keys",
"(",
")",
":",
"if",
"isinstance",
"(",
"exc",
",",
"key",
")",
":",
"# pylint: disable=unsubscriptable-object",
"ret... | Return translation of exception to new class.
Calling code should only raise exception if exception class is passed
in, else ``None`` (which signifies no wrapping should be done). | [
"Return",
"translation",
"of",
"exception",
"to",
"new",
"class",
"."
] | python | train |
flowersteam/explauto | explauto/sensorimotor_model/inverse/cma.py | https://github.com/flowersteam/explauto/blob/cf0f81ecb9f6412f7276a95bd27359000e1e26b6/explauto/sensorimotor_model/inverse/cma.py#L813-L851 | def update(self, arx, xarchive=None, arf=None, evals=None):
"""checks for better solutions in list `arx`.
Based on the smallest corresponding value in `arf`,
alternatively, `update` may be called with a `BestSolution`
instance like ``update(another_best_solution)`` in which case
... | [
"def",
"update",
"(",
"self",
",",
"arx",
",",
"xarchive",
"=",
"None",
",",
"arf",
"=",
"None",
",",
"evals",
"=",
"None",
")",
":",
"if",
"isinstance",
"(",
"arx",
",",
"BestSolution",
")",
":",
"if",
"self",
".",
"evalsall",
"is",
"None",
":",
... | checks for better solutions in list `arx`.
Based on the smallest corresponding value in `arf`,
alternatively, `update` may be called with a `BestSolution`
instance like ``update(another_best_solution)`` in which case
the better solution becomes the current best.
`xarchive` is u... | [
"checks",
"for",
"better",
"solutions",
"in",
"list",
"arx",
"."
] | python | train |
darkfeline/animanager | animanager/anidb.py | https://github.com/darkfeline/animanager/blob/55d92e4cbdc12aac8ebe302420d2cff3fa9fa148/animanager/anidb.py#L58-L65 | def number(self) -> int:
"""Episode number.
Unique for an anime and episode type, but not unique across episode
types for the same anime.
"""
match = self._NUMBER_SUFFIX.search(self.epno)
return int(match.group(1)) | [
"def",
"number",
"(",
"self",
")",
"->",
"int",
":",
"match",
"=",
"self",
".",
"_NUMBER_SUFFIX",
".",
"search",
"(",
"self",
".",
"epno",
")",
"return",
"int",
"(",
"match",
".",
"group",
"(",
"1",
")",
")"
] | Episode number.
Unique for an anime and episode type, but not unique across episode
types for the same anime. | [
"Episode",
"number",
"."
] | python | train |
chovanecm/sacredboard | sacredboard/app/process/process.py | https://github.com/chovanecm/sacredboard/blob/47e1c99e3be3c1b099d3772bc077f5666020eb0b/sacredboard/app/process/process.py#L146-L155 | def read_line(self, time_limit=None):
"""
Read a line from the process.
On Windows, this the time_limit has no effect, it always blocks.
"""
if self.proc is not None:
return self.proc.stdout.readline().decode()
else:
return None | [
"def",
"read_line",
"(",
"self",
",",
"time_limit",
"=",
"None",
")",
":",
"if",
"self",
".",
"proc",
"is",
"not",
"None",
":",
"return",
"self",
".",
"proc",
".",
"stdout",
".",
"readline",
"(",
")",
".",
"decode",
"(",
")",
"else",
":",
"return",... | Read a line from the process.
On Windows, this the time_limit has no effect, it always blocks. | [
"Read",
"a",
"line",
"from",
"the",
"process",
"."
] | python | train |
noahbenson/neuropythy | neuropythy/optimize/core.py | https://github.com/noahbenson/neuropythy/blob/b588889f6db36ddb9602ae4a72c1c0d3f41586b2/neuropythy/optimize/core.py#L274-L281 | def const_potential(f):
'''
const_potential(f) yields f if f is a constant potential function; if f is a constant, yields
a potential function that always yields f; otherwise raises an error.
'''
if is_const_potential(f): return f
elif pimms.is_array(f, 'number'): return PotentialConstant(f)
... | [
"def",
"const_potential",
"(",
"f",
")",
":",
"if",
"is_const_potential",
"(",
"f",
")",
":",
"return",
"f",
"elif",
"pimms",
".",
"is_array",
"(",
"f",
",",
"'number'",
")",
":",
"return",
"PotentialConstant",
"(",
"f",
")",
"else",
":",
"raise",
"Val... | const_potential(f) yields f if f is a constant potential function; if f is a constant, yields
a potential function that always yields f; otherwise raises an error. | [
"const_potential",
"(",
"f",
")",
"yields",
"f",
"if",
"f",
"is",
"a",
"constant",
"potential",
"function",
";",
"if",
"f",
"is",
"a",
"constant",
"yields",
"a",
"potential",
"function",
"that",
"always",
"yields",
"f",
";",
"otherwise",
"raises",
"an",
... | python | train |
saltstack/salt | salt/runners/reactor.py | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/runners/reactor.py#L36-L59 | def list_(saltenv='base', test=None):
'''
List currently configured reactors
CLI Example:
.. code-block:: bash
salt-run reactor.list
'''
sevent = salt.utils.event.get_event(
'master',
__opts__['sock_dir'],
__opts__['transport'],
opts=__o... | [
"def",
"list_",
"(",
"saltenv",
"=",
"'base'",
",",
"test",
"=",
"None",
")",
":",
"sevent",
"=",
"salt",
".",
"utils",
".",
"event",
".",
"get_event",
"(",
"'master'",
",",
"__opts__",
"[",
"'sock_dir'",
"]",
",",
"__opts__",
"[",
"'transport'",
"]",
... | List currently configured reactors
CLI Example:
.. code-block:: bash
salt-run reactor.list | [
"List",
"currently",
"configured",
"reactors"
] | python | train |
aparo/pyes | pyes/queryset.py | https://github.com/aparo/pyes/blob/712eb6095961755067b2b5baa262008ade6584b3/pyes/queryset.py#L456-L470 | def update(self, **kwargs):
"""
Updates all elements in the current QuerySet, setting all the given
fields to the appropriate values.
"""
query = self._build_query()
connection = get_es_connection(self.es_url, self.es_kwargs)
results = connection.search(query, ind... | [
"def",
"update",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"query",
"=",
"self",
".",
"_build_query",
"(",
")",
"connection",
"=",
"get_es_connection",
"(",
"self",
".",
"es_url",
",",
"self",
".",
"es_kwargs",
")",
"results",
"=",
"connection",
... | Updates all elements in the current QuerySet, setting all the given
fields to the appropriate values. | [
"Updates",
"all",
"elements",
"in",
"the",
"current",
"QuerySet",
"setting",
"all",
"the",
"given",
"fields",
"to",
"the",
"appropriate",
"values",
"."
] | python | train |
seleniumbase/SeleniumBase | seleniumbase/plugins/db_reporting_plugin.py | https://github.com/seleniumbase/SeleniumBase/blob/62e5b43ee1f90a9ed923841bdd53b1b38358f43a/seleniumbase/plugins/db_reporting_plugin.py#L92-L96 | def addError(self, test, err, capt=None):
"""
After a test error, we want to record testcase run information.
"""
self.__insert_test_result(constants.State.ERROR, test, err) | [
"def",
"addError",
"(",
"self",
",",
"test",
",",
"err",
",",
"capt",
"=",
"None",
")",
":",
"self",
".",
"__insert_test_result",
"(",
"constants",
".",
"State",
".",
"ERROR",
",",
"test",
",",
"err",
")"
] | After a test error, we want to record testcase run information. | [
"After",
"a",
"test",
"error",
"we",
"want",
"to",
"record",
"testcase",
"run",
"information",
"."
] | python | train |
hyperledger/sawtooth-core | validator/sawtooth_validator/gossip/permission_verifier.py | https://github.com/hyperledger/sawtooth-core/blob/8cf473bc2207e51f02bd182d825158a57d72b098/validator/sawtooth_validator/gossip/permission_verifier.py#L106-L176 | def is_transaction_signer_authorized(self, transactions, state_root,
from_state):
""" Check the transaction signing key against the allowed transactor
permissions. The roles being checked are the following, from first
to last:
"tra... | [
"def",
"is_transaction_signer_authorized",
"(",
"self",
",",
"transactions",
",",
"state_root",
",",
"from_state",
")",
":",
"role",
"=",
"None",
"if",
"role",
"is",
"None",
":",
"role",
"=",
"self",
".",
"_cache",
".",
"get_role",
"(",
"\"transactor.transacti... | Check the transaction signing key against the allowed transactor
permissions. The roles being checked are the following, from first
to last:
"transactor.transaction_signer.<TP_Name>"
"transactor.transaction_signer"
"transactor"
"def... | [
"Check",
"the",
"transaction",
"signing",
"key",
"against",
"the",
"allowed",
"transactor",
"permissions",
".",
"The",
"roles",
"being",
"checked",
"are",
"the",
"following",
"from",
"first",
"to",
"last",
":",
"transactor",
".",
"transaction_signer",
".",
"<TP_... | python | train |
barryp/py-amqplib | amqplib/client_0_8/channel.py | https://github.com/barryp/py-amqplib/blob/2b3a47de34b4712c111d0a55d7ff109dffc2a7b2/amqplib/client_0_8/channel.py#L2513-L2554 | def _basic_return(self, args, msg):
"""
return a failed message
This method returns an undeliverable message that was
published with the "immediate" flag set, or an unroutable
message published with the "mandatory" flag set. The reply
code and text provide information ab... | [
"def",
"_basic_return",
"(",
"self",
",",
"args",
",",
"msg",
")",
":",
"reply_code",
"=",
"args",
".",
"read_short",
"(",
")",
"reply_text",
"=",
"args",
".",
"read_shortstr",
"(",
")",
"exchange",
"=",
"args",
".",
"read_shortstr",
"(",
")",
"routing_k... | return a failed message
This method returns an undeliverable message that was
published with the "immediate" flag set, or an unroutable
message published with the "mandatory" flag set. The reply
code and text provide information about the reason that the
message was undeliverabl... | [
"return",
"a",
"failed",
"message"
] | python | train |
idlesign/django-sitemessage | sitemessage/messengers/telegram.py | https://github.com/idlesign/django-sitemessage/blob/25b179b798370354c5988042ec209e255d23793f/sitemessage/messengers/telegram.py#L56-L69 | def get_chat_ids(self):
"""Returns unique chat IDs from `/start` command messages sent to our bot by users.
Those chat IDs can be used to send messages to chats.
:rtype: list
"""
updates = self.get_updates()
chat_ids = []
if updates:
for update in upd... | [
"def",
"get_chat_ids",
"(",
"self",
")",
":",
"updates",
"=",
"self",
".",
"get_updates",
"(",
")",
"chat_ids",
"=",
"[",
"]",
"if",
"updates",
":",
"for",
"update",
"in",
"updates",
":",
"message",
"=",
"update",
"[",
"'message'",
"]",
"if",
"message"... | Returns unique chat IDs from `/start` command messages sent to our bot by users.
Those chat IDs can be used to send messages to chats.
:rtype: list | [
"Returns",
"unique",
"chat",
"IDs",
"from",
"/",
"start",
"command",
"messages",
"sent",
"to",
"our",
"bot",
"by",
"users",
".",
"Those",
"chat",
"IDs",
"can",
"be",
"used",
"to",
"send",
"messages",
"to",
"chats",
"."
] | python | train |
smarie/python-parsyfiles | parsyfiles/global_config.py | https://github.com/smarie/python-parsyfiles/blob/344b37e1151e8d4e7c2ee49ae09d6568715ae64e/parsyfiles/global_config.py#L17-L35 | def parsyfiles_global_config(multiple_errors_tb_limit: int = None, full_paths_in_logs: bool = None,
dict_to_object_subclass_limit: int = None):
"""
This is the method you should use to configure the parsyfiles library
:param multiple_errors_tb_limit: the traceback size (defaul... | [
"def",
"parsyfiles_global_config",
"(",
"multiple_errors_tb_limit",
":",
"int",
"=",
"None",
",",
"full_paths_in_logs",
":",
"bool",
"=",
"None",
",",
"dict_to_object_subclass_limit",
":",
"int",
"=",
"None",
")",
":",
"if",
"multiple_errors_tb_limit",
"is",
"not",
... | This is the method you should use to configure the parsyfiles library
:param multiple_errors_tb_limit: the traceback size (default is 3) of individual parsers exceptions displayed when
parsyfiles tries several parsing chains and all of them fail.
:param full_paths_in_logs: if True, full file paths will be ... | [
"This",
"is",
"the",
"method",
"you",
"should",
"use",
"to",
"configure",
"the",
"parsyfiles",
"library"
] | python | train |
aio-libs/aioftp | aioftp/common.py | https://github.com/aio-libs/aioftp/blob/b45395b1aba41301b898040acade7010e6878a08/aioftp/common.py#L408-L421 | def from_limits(cls, read_speed_limit=None, write_speed_limit=None):
"""
Simple wrapper for creation :py:class:`aioftp.StreamThrottle`
:param read_speed_limit: stream read speed limit in bytes or
:py:class:`None` for unlimited
:type read_speed_limit: :py:class:`int` or :py:c... | [
"def",
"from_limits",
"(",
"cls",
",",
"read_speed_limit",
"=",
"None",
",",
"write_speed_limit",
"=",
"None",
")",
":",
"return",
"cls",
"(",
"read",
"=",
"Throttle",
"(",
"limit",
"=",
"read_speed_limit",
")",
",",
"write",
"=",
"Throttle",
"(",
"limit",... | Simple wrapper for creation :py:class:`aioftp.StreamThrottle`
:param read_speed_limit: stream read speed limit in bytes or
:py:class:`None` for unlimited
:type read_speed_limit: :py:class:`int` or :py:class:`None`
:param write_speed_limit: stream write speed limit in bytes or
... | [
"Simple",
"wrapper",
"for",
"creation",
":",
"py",
":",
"class",
":",
"aioftp",
".",
"StreamThrottle"
] | python | valid |
kushaldas/retask | retask/queue.py | https://github.com/kushaldas/retask/blob/5c955b8386653d3f0591ca2f4b1a213ff4b5a018/retask/queue.py#L79-L96 | def length(self):
"""
Gives the length of the queue. Returns ``None`` if the queue is not
connected.
If the queue is not connected then it will raise
:class:`retask.ConnectionError`.
"""
if not self.connected:
raise ConnectionError('Queue is not conn... | [
"def",
"length",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"connected",
":",
"raise",
"ConnectionError",
"(",
"'Queue is not connected'",
")",
"try",
":",
"length",
"=",
"self",
".",
"rdb",
".",
"llen",
"(",
"self",
".",
"_name",
")",
"except",
... | Gives the length of the queue. Returns ``None`` if the queue is not
connected.
If the queue is not connected then it will raise
:class:`retask.ConnectionError`. | [
"Gives",
"the",
"length",
"of",
"the",
"queue",
".",
"Returns",
"None",
"if",
"the",
"queue",
"is",
"not",
"connected",
"."
] | python | train |
tmr232/Sark | sark/enum.py | https://github.com/tmr232/Sark/blob/bee62879c2aea553a3924d887e2b30f2a6008581/sark/enum.py#L79-L84 | def _add_enum_member(enum, name, value, bitmask=DEFMASK):
"""Add an enum member."""
error = idaapi.add_enum_member(enum, name, value, bitmask)
if error:
raise _enum_member_error(error, enum, name, value, bitmask) | [
"def",
"_add_enum_member",
"(",
"enum",
",",
"name",
",",
"value",
",",
"bitmask",
"=",
"DEFMASK",
")",
":",
"error",
"=",
"idaapi",
".",
"add_enum_member",
"(",
"enum",
",",
"name",
",",
"value",
",",
"bitmask",
")",
"if",
"error",
":",
"raise",
"_enu... | Add an enum member. | [
"Add",
"an",
"enum",
"member",
"."
] | python | train |
RiotGames/cloud-inquisitor | backend/cloud_inquisitor/plugins/views/templates.py | https://github.com/RiotGames/cloud-inquisitor/blob/181dc2566ca59fc855f695b7fcc2c3b934e6ee9f/backend/cloud_inquisitor/plugins/views/templates.py#L114-L127 | def delete(self, template_name):
"""Delete a template"""
template = db.Template.find_one(template_name=template_name)
if not template:
return self.make_response('No such template found', HTTP.NOT_FOUND)
db.session.delete(template)
db.session.commit()
auditlog... | [
"def",
"delete",
"(",
"self",
",",
"template_name",
")",
":",
"template",
"=",
"db",
".",
"Template",
".",
"find_one",
"(",
"template_name",
"=",
"template_name",
")",
"if",
"not",
"template",
":",
"return",
"self",
".",
"make_response",
"(",
"'No such templ... | Delete a template | [
"Delete",
"a",
"template"
] | python | train |
cuihantao/andes | andes/variables/dae.py | https://github.com/cuihantao/andes/blob/7067898d4f26ce7534e968b8486c4aa8fe3a511a/andes/variables/dae.py#L700-L705 | def reset_small(self, eq):
"""Reset numbers smaller than 1e-12 in f and g equations"""
assert eq in ('f', 'g')
for idx, var in enumerate(self.__dict__[eq]):
if abs(var) <= 1e-12:
self.__dict__[eq][idx] = 0 | [
"def",
"reset_small",
"(",
"self",
",",
"eq",
")",
":",
"assert",
"eq",
"in",
"(",
"'f'",
",",
"'g'",
")",
"for",
"idx",
",",
"var",
"in",
"enumerate",
"(",
"self",
".",
"__dict__",
"[",
"eq",
"]",
")",
":",
"if",
"abs",
"(",
"var",
")",
"<=",
... | Reset numbers smaller than 1e-12 in f and g equations | [
"Reset",
"numbers",
"smaller",
"than",
"1e",
"-",
"12",
"in",
"f",
"and",
"g",
"equations"
] | python | train |
QInfer/python-qinfer | src/qinfer/tomography/models.py | https://github.com/QInfer/python-qinfer/blob/8170c84a0be1723f8c6b09e0d3c7a40a886f1fe3/src/qinfer/tomography/models.py#L172-L192 | def trunc_neg_eigs(self, particle):
"""
Given a state represented as a model parameter vector,
returns a model parameter vector representing the same
state with any negative eigenvalues set to zero.
:param np.ndarray particle: Vector of length ``(dim ** 2, )``
repres... | [
"def",
"trunc_neg_eigs",
"(",
"self",
",",
"particle",
")",
":",
"arr",
"=",
"np",
".",
"tensordot",
"(",
"particle",
",",
"self",
".",
"_basis",
".",
"data",
".",
"conj",
"(",
")",
",",
"1",
")",
"w",
",",
"v",
"=",
"np",
".",
"linalg",
".",
"... | Given a state represented as a model parameter vector,
returns a model parameter vector representing the same
state with any negative eigenvalues set to zero.
:param np.ndarray particle: Vector of length ``(dim ** 2, )``
representing a state.
:return: The same state with any... | [
"Given",
"a",
"state",
"represented",
"as",
"a",
"model",
"parameter",
"vector",
"returns",
"a",
"model",
"parameter",
"vector",
"representing",
"the",
"same",
"state",
"with",
"any",
"negative",
"eigenvalues",
"set",
"to",
"zero",
"."
] | python | train |
Opentrons/opentrons | update-server/otupdate/buildroot/update.py | https://github.com/Opentrons/opentrons/blob/a7c15cc2636ecb64ab56c7edc1d8a57163aaeadf/update-server/otupdate/buildroot/update.py#L171-L186 | async def commit(
request: web.Request, session: UpdateSession) -> web.Response:
""" Serves /update/:session/commit """
if session.stage != Stages.DONE:
return web.json_response(
data={'error': 'not-ready',
'message': f'System is not ready to commit the update '
... | [
"async",
"def",
"commit",
"(",
"request",
":",
"web",
".",
"Request",
",",
"session",
":",
"UpdateSession",
")",
"->",
"web",
".",
"Response",
":",
"if",
"session",
".",
"stage",
"!=",
"Stages",
".",
"DONE",
":",
"return",
"web",
".",
"json_response",
... | Serves /update/:session/commit | [
"Serves",
"/",
"update",
"/",
":",
"session",
"/",
"commit"
] | python | train |
gmcguire/django-db-pool | dbpool/db/backends/postgresql_psycopg2/base.py | https://github.com/gmcguire/django-db-pool/blob/d4e0aa6a150fd7bd2024e079cd3b7147ea341e63/dbpool/db/backends/postgresql_psycopg2/base.py#L56-L63 | def close(self):
'''
Override to return the connection to the pool rather than closing it.
'''
if self._wrapped_connection and self._pool:
logger.debug("Returning connection %s to pool %s" % (self._wrapped_connection, self._pool))
self._pool.putconn(self._wrapped_... | [
"def",
"close",
"(",
"self",
")",
":",
"if",
"self",
".",
"_wrapped_connection",
"and",
"self",
".",
"_pool",
":",
"logger",
".",
"debug",
"(",
"\"Returning connection %s to pool %s\"",
"%",
"(",
"self",
".",
"_wrapped_connection",
",",
"self",
".",
"_pool",
... | Override to return the connection to the pool rather than closing it. | [
"Override",
"to",
"return",
"the",
"connection",
"to",
"the",
"pool",
"rather",
"than",
"closing",
"it",
"."
] | python | train |
shapiromatron/bmds | bmds/batch.py | https://github.com/shapiromatron/bmds/blob/395c6ce84ad82876fd9fa4a89a3497fb61616de0/bmds/batch.py#L59-L84 | def to_json(self, filename, indent=2):
"""
Return a JSON string of all model inputs and outputs.
Parameters
----------
filename : str or file
Either the file name (string) or an open file (file-like object)
where the data will be saved.
indent : i... | [
"def",
"to_json",
"(",
"self",
",",
"filename",
",",
"indent",
"=",
"2",
")",
":",
"d",
"=",
"self",
".",
"to_dicts",
"(",
")",
"if",
"hasattr",
"(",
"filename",
",",
"\"write\"",
")",
":",
"json",
".",
"dump",
"(",
"d",
",",
"filename",
",",
"in... | Return a JSON string of all model inputs and outputs.
Parameters
----------
filename : str or file
Either the file name (string) or an open file (file-like object)
where the data will be saved.
indent : int, optional
Indentation level for JSON output.... | [
"Return",
"a",
"JSON",
"string",
"of",
"all",
"model",
"inputs",
"and",
"outputs",
"."
] | python | train |
StackStorm/pybind | pybind/slxos/v17s_1_02/qos/__init__.py | https://github.com/StackStorm/pybind/blob/44c467e71b2b425be63867aba6e6fa28b2cfe7fb/pybind/slxos/v17s_1_02/qos/__init__.py#L168-L189 | def _set_tx_queue(self, v, load=False):
"""
Setter method for tx_queue, mapped from YANG variable /qos/tx_queue (container)
If this variable is read-only (config: false) in the
source YANG file, then _set_tx_queue is considered as a private
method. Backends looking to populate this variable should
... | [
"def",
"_set_tx_queue",
"(",
"self",
",",
"v",
",",
"load",
"=",
"False",
")",
":",
"if",
"hasattr",
"(",
"v",
",",
"\"_utype\"",
")",
":",
"v",
"=",
"v",
".",
"_utype",
"(",
"v",
")",
"try",
":",
"t",
"=",
"YANGDynClass",
"(",
"v",
",",
"base"... | Setter method for tx_queue, mapped from YANG variable /qos/tx_queue (container)
If this variable is read-only (config: false) in the
source YANG file, then _set_tx_queue is considered as a private
method. Backends looking to populate this variable should
do so via calling thisObj._set_tx_queue() directl... | [
"Setter",
"method",
"for",
"tx_queue",
"mapped",
"from",
"YANG",
"variable",
"/",
"qos",
"/",
"tx_queue",
"(",
"container",
")",
"If",
"this",
"variable",
"is",
"read",
"-",
"only",
"(",
"config",
":",
"false",
")",
"in",
"the",
"source",
"YANG",
"file",... | python | train |
konstantint/matplotlib-venn | matplotlib_venn/_util.py | https://github.com/konstantint/matplotlib-venn/blob/c26796c9925bdac512edf48387452fbd1848c791/matplotlib_venn/_util.py#L40-L63 | def venn3_unweighted(subsets, set_labels=('A', 'B', 'C'), set_colors=('r', 'g', 'b'), alpha=0.4, normalize_to=1.0, subset_areas=(1, 1, 1, 1, 1, 1, 1), ax=None, subset_label_formatter=None):
'''
The version of venn3 without area-weighting.
It is implemented as a wrapper around venn3. Namely, venn3 is invoked... | [
"def",
"venn3_unweighted",
"(",
"subsets",
",",
"set_labels",
"=",
"(",
"'A'",
",",
"'B'",
",",
"'C'",
")",
",",
"set_colors",
"=",
"(",
"'r'",
",",
"'g'",
",",
"'b'",
")",
",",
"alpha",
"=",
"0.4",
",",
"normalize_to",
"=",
"1.0",
",",
"subset_areas... | The version of venn3 without area-weighting.
It is implemented as a wrapper around venn3. Namely, venn3 is invoked as usual, but with all subset areas
set to 1. The subset labels are then replaced in the resulting diagram with the provided subset sizes.
The parameters are all the same as that of venn2.... | [
"The",
"version",
"of",
"venn3",
"without",
"area",
"-",
"weighting",
".",
"It",
"is",
"implemented",
"as",
"a",
"wrapper",
"around",
"venn3",
".",
"Namely",
"venn3",
"is",
"invoked",
"as",
"usual",
"but",
"with",
"all",
"subset",
"areas",
"set",
"to",
"... | python | train |
hyperledger/sawtooth-core | validator/sawtooth_validator/networking/dispatch.py | https://github.com/hyperledger/sawtooth-core/blob/8cf473bc2207e51f02bd182d825158a57d72b098/validator/sawtooth_validator/networking/dispatch.py#L76-L89 | def add_send_message(self, connection, send_message):
"""Adds a send_message function to the Dispatcher's
dictionary of functions indexed by connection.
Args:
connection (str): A locally unique identifier
provided by the receiver of messages.
send_message... | [
"def",
"add_send_message",
"(",
"self",
",",
"connection",
",",
"send_message",
")",
":",
"self",
".",
"_send_message",
"[",
"connection",
"]",
"=",
"send_message",
"LOGGER",
".",
"debug",
"(",
"\"Added send_message function \"",
"\"for connection %s\"",
",",
"conne... | Adds a send_message function to the Dispatcher's
dictionary of functions indexed by connection.
Args:
connection (str): A locally unique identifier
provided by the receiver of messages.
send_message (fn): The method that should be called
by the di... | [
"Adds",
"a",
"send_message",
"function",
"to",
"the",
"Dispatcher",
"s",
"dictionary",
"of",
"functions",
"indexed",
"by",
"connection",
"."
] | python | train |
satellogic/telluric | telluric/georaster.py | https://github.com/satellogic/telluric/blob/e752cd3ee71e339f79717e526fde362e80055d9e/telluric/georaster.py#L765-L769 | def shape(self):
"""Raster shape."""
if self._shape is None:
self._populate_from_rasterio_object(read_image=False)
return self._shape | [
"def",
"shape",
"(",
"self",
")",
":",
"if",
"self",
".",
"_shape",
"is",
"None",
":",
"self",
".",
"_populate_from_rasterio_object",
"(",
"read_image",
"=",
"False",
")",
"return",
"self",
".",
"_shape"
] | Raster shape. | [
"Raster",
"shape",
"."
] | python | train |
lk-geimfari/mimesis | mimesis/providers/payment.py | https://github.com/lk-geimfari/mimesis/blob/4b16ee7a8dba6281a904654a88dbb4b052869fc5/mimesis/providers/payment.py#L95-L133 | def credit_card_number(self, card_type: Optional[CardType] = None) -> str:
"""Generate a random credit card number.
:param card_type: Issuing Network. Default is Visa.
:return: Credit card number.
:raises NotImplementedError: if cart_type is not supported.
:Example:
... | [
"def",
"credit_card_number",
"(",
"self",
",",
"card_type",
":",
"Optional",
"[",
"CardType",
"]",
"=",
"None",
")",
"->",
"str",
":",
"length",
"=",
"16",
"regex",
"=",
"re",
".",
"compile",
"(",
"r'(\\d{4})(\\d{4})(\\d{4})(\\d{4})'",
")",
"if",
"card_type"... | Generate a random credit card number.
:param card_type: Issuing Network. Default is Visa.
:return: Credit card number.
:raises NotImplementedError: if cart_type is not supported.
:Example:
4455 5299 1152 2450 | [
"Generate",
"a",
"random",
"credit",
"card",
"number",
"."
] | python | train |
farshidce/touchworks-python | touchworks/api/http.py | https://github.com/farshidce/touchworks-python/blob/ea8f93a0f4273de1317a318e945a571f5038ba62/touchworks/api/http.py#L627-L648 | def get_task_list(self, since='', task_types='', task_status=''):
"""
invokes TouchWorksMagicConstants.ACTION_GET_TASK_LIST action
:param since - If given a datetime, retrieves only tasks created (or last modified)
after that date and time. Defaults to 1/1/1900.
:param task_s... | [
"def",
"get_task_list",
"(",
"self",
",",
"since",
"=",
"''",
",",
"task_types",
"=",
"''",
",",
"task_status",
"=",
"''",
")",
":",
"magic",
"=",
"self",
".",
"_magic_json",
"(",
"action",
"=",
"TouchWorksMagicConstants",
".",
"ACTION_GET_TASK_LIST",
",",
... | invokes TouchWorksMagicConstants.ACTION_GET_TASK_LIST action
:param since - If given a datetime, retrieves only tasks created (or last modified)
after that date and time. Defaults to 1/1/1900.
:param task_status - Optional list of pipe-delimited task status names.
For example, "A... | [
"invokes",
"TouchWorksMagicConstants",
".",
"ACTION_GET_TASK_LIST",
"action",
":",
"param",
"since",
"-",
"If",
"given",
"a",
"datetime",
"retrieves",
"only",
"tasks",
"created",
"(",
"or",
"last",
"modified",
")",
"after",
"that",
"date",
"and",
"time",
".",
... | python | train |
tanghaibao/goatools | goatools/grouper/plotobj.py | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/plotobj.py#L207-L212 | def _get_gos_upper(self, ntpltgo1, max_upper, go2parentids):
"""Plot a GO DAG for the upper portion of a single Group of user GOs."""
# Get GO IDs which are in the hdrgo path
goids_possible = ntpltgo1.gosubdag.go2obj.keys()
# Get upper GO IDs which have the most descendants
retur... | [
"def",
"_get_gos_upper",
"(",
"self",
",",
"ntpltgo1",
",",
"max_upper",
",",
"go2parentids",
")",
":",
"# Get GO IDs which are in the hdrgo path",
"goids_possible",
"=",
"ntpltgo1",
".",
"gosubdag",
".",
"go2obj",
".",
"keys",
"(",
")",
"# Get upper GO IDs which have... | Plot a GO DAG for the upper portion of a single Group of user GOs. | [
"Plot",
"a",
"GO",
"DAG",
"for",
"the",
"upper",
"portion",
"of",
"a",
"single",
"Group",
"of",
"user",
"GOs",
"."
] | python | train |
mabuchilab/QNET | src/qnet/algebra/core/abstract_quantum_algebra.py | https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/core/abstract_quantum_algebra.py#L783-L800 | def free_symbols(self):
"""Set of free SymPy symbols contained within the expression."""
if self._free_symbols is None:
if len(self._vals) == 0:
self._free_symbols = self.operand.free_symbols
else:
dummy_map = {}
for sym in self._va... | [
"def",
"free_symbols",
"(",
"self",
")",
":",
"if",
"self",
".",
"_free_symbols",
"is",
"None",
":",
"if",
"len",
"(",
"self",
".",
"_vals",
")",
"==",
"0",
":",
"self",
".",
"_free_symbols",
"=",
"self",
".",
"operand",
".",
"free_symbols",
"else",
... | Set of free SymPy symbols contained within the expression. | [
"Set",
"of",
"free",
"SymPy",
"symbols",
"contained",
"within",
"the",
"expression",
"."
] | python | train |
michael-lazar/rtv | rtv/packages/praw/__init__.py | https://github.com/michael-lazar/rtv/blob/ccef2af042566ad384977028cf0bde01bc524dda/rtv/packages/praw/__init__.py#L1215-L1223 | def is_username_available(self, username):
"""Return True if username is valid and available, otherwise False."""
params = {'user': username}
try:
result = self.request_json(self.config['username_available'],
params=params)
except errors... | [
"def",
"is_username_available",
"(",
"self",
",",
"username",
")",
":",
"params",
"=",
"{",
"'user'",
":",
"username",
"}",
"try",
":",
"result",
"=",
"self",
".",
"request_json",
"(",
"self",
".",
"config",
"[",
"'username_available'",
"]",
",",
"params",... | Return True if username is valid and available, otherwise False. | [
"Return",
"True",
"if",
"username",
"is",
"valid",
"and",
"available",
"otherwise",
"False",
"."
] | python | train |
ozgur/python-firebase | firebase/firebase.py | https://github.com/ozgur/python-firebase/blob/6b96b326f6d8f477503ca42fdfbd81bcbe1f9e0d/firebase/firebase.py#L46-L72 | def make_put_request(url, data, params, headers, connection):
"""
Helper function that makes an HTTP PUT request to the given firebase
endpoint. Timeout is 60 seconds.
`url`: The full URL of the firebase endpoint (DSN appended.)
`data`: JSON serializable dict that will be stored in the remote storag... | [
"def",
"make_put_request",
"(",
"url",
",",
"data",
",",
"params",
",",
"headers",
",",
"connection",
")",
":",
"timeout",
"=",
"getattr",
"(",
"connection",
",",
"'timeout'",
")",
"response",
"=",
"connection",
".",
"put",
"(",
"url",
",",
"data",
"=",
... | Helper function that makes an HTTP PUT request to the given firebase
endpoint. Timeout is 60 seconds.
`url`: The full URL of the firebase endpoint (DSN appended.)
`data`: JSON serializable dict that will be stored in the remote storage.
`params`: Python dict that is appended to the URL like a querystrin... | [
"Helper",
"function",
"that",
"makes",
"an",
"HTTP",
"PUT",
"request",
"to",
"the",
"given",
"firebase",
"endpoint",
".",
"Timeout",
"is",
"60",
"seconds",
".",
"url",
":",
"The",
"full",
"URL",
"of",
"the",
"firebase",
"endpoint",
"(",
"DSN",
"appended",
... | python | valid |
google/prettytensor | prettytensor/tutorial/data_utils.py | https://github.com/google/prettytensor/blob/75daa0b11252590f548da5647addc0ea610c4c45/prettytensor/tutorial/data_utils.py#L92-L106 | def mnist(training):
"""Downloads MNIST and loads it into numpy arrays."""
if training:
data_filename = 'train-images-idx3-ubyte.gz'
labels_filename = 'train-labels-idx1-ubyte.gz'
count = 60000
else:
data_filename = 't10k-images-idx3-ubyte.gz'
labels_filename = 't10k-labels-idx1-ubyte.gz'
... | [
"def",
"mnist",
"(",
"training",
")",
":",
"if",
"training",
":",
"data_filename",
"=",
"'train-images-idx3-ubyte.gz'",
"labels_filename",
"=",
"'train-labels-idx1-ubyte.gz'",
"count",
"=",
"60000",
"else",
":",
"data_filename",
"=",
"'t10k-images-idx3-ubyte.gz'",
"labe... | Downloads MNIST and loads it into numpy arrays. | [
"Downloads",
"MNIST",
"and",
"loads",
"it",
"into",
"numpy",
"arrays",
"."
] | python | train |
ultrabug/py3status | py3status/modules/battery_level.py | https://github.com/ultrabug/py3status/blob/4c105f1b44f7384ca4f7da5f821a47e468c7dee2/py3status/modules/battery_level.py#L190-L213 | def on_click(self, event):
"""
Display a notification following the specified format
"""
if not self.notification:
return
if self.charging:
format = self.format_notify_charging
else:
format = self.format_notify_discharging
mes... | [
"def",
"on_click",
"(",
"self",
",",
"event",
")",
":",
"if",
"not",
"self",
".",
"notification",
":",
"return",
"if",
"self",
".",
"charging",
":",
"format",
"=",
"self",
".",
"format_notify_charging",
"else",
":",
"format",
"=",
"self",
".",
"format_no... | Display a notification following the specified format | [
"Display",
"a",
"notification",
"following",
"the",
"specified",
"format"
] | python | train |
kipe/enocean | enocean/utils.py | https://github.com/kipe/enocean/blob/99fa03f47004eef74c7987545c33ecd01af0de07/enocean/utils.py#L10-L15 | def combine_hex(data):
''' Combine list of integer values to one big integer '''
output = 0x00
for i, value in enumerate(reversed(data)):
output |= (value << i * 8)
return output | [
"def",
"combine_hex",
"(",
"data",
")",
":",
"output",
"=",
"0x00",
"for",
"i",
",",
"value",
"in",
"enumerate",
"(",
"reversed",
"(",
"data",
")",
")",
":",
"output",
"|=",
"(",
"value",
"<<",
"i",
"*",
"8",
")",
"return",
"output"
] | Combine list of integer values to one big integer | [
"Combine",
"list",
"of",
"integer",
"values",
"to",
"one",
"big",
"integer"
] | python | train |
streamlink/streamlink | src/streamlink/plugins/ustvnow.py | https://github.com/streamlink/streamlink/blob/c8ed1daff14ac03195870238b9b900c1109dd5c1/src/streamlink/plugins/ustvnow.py#L66-L99 | def _get_streams(self):
"""
Finds the streams from tvcatchup.com.
"""
token = self.login(self.get_option("username"), self.get_option("password"))
m = self._url_re.match(self.url)
scode = m and m.group("scode") or self.get_option("station_code")
res = self.sessio... | [
"def",
"_get_streams",
"(",
"self",
")",
":",
"token",
"=",
"self",
".",
"login",
"(",
"self",
".",
"get_option",
"(",
"\"username\"",
")",
",",
"self",
".",
"get_option",
"(",
"\"password\"",
")",
")",
"m",
"=",
"self",
".",
"_url_re",
".",
"match",
... | Finds the streams from tvcatchup.com. | [
"Finds",
"the",
"streams",
"from",
"tvcatchup",
".",
"com",
"."
] | python | test |
EntilZha/PyFunctional | functional/transformations.py | https://github.com/EntilZha/PyFunctional/blob/ac04e4a8552b0c464a7f492f7c9862424867b63e/functional/transformations.py#L176-L190 | def drop_right_t(n):
"""
Transformation for Sequence.drop_right
:param n: number to drop from right
:return: transformation
"""
if n <= 0:
end_index = None
else:
end_index = -n
return Transformation(
'drop_right({0})'.format(n),
lambda sequence: sequence[:... | [
"def",
"drop_right_t",
"(",
"n",
")",
":",
"if",
"n",
"<=",
"0",
":",
"end_index",
"=",
"None",
"else",
":",
"end_index",
"=",
"-",
"n",
"return",
"Transformation",
"(",
"'drop_right({0})'",
".",
"format",
"(",
"n",
")",
",",
"lambda",
"sequence",
":",... | Transformation for Sequence.drop_right
:param n: number to drop from right
:return: transformation | [
"Transformation",
"for",
"Sequence",
".",
"drop_right",
":",
"param",
"n",
":",
"number",
"to",
"drop",
"from",
"right",
":",
"return",
":",
"transformation"
] | python | train |
ic-labs/django-icekit | icekit/api/base_serializers.py | https://github.com/ic-labs/django-icekit/blob/c507ea5b1864303732c53ad7c5800571fca5fa94/icekit/api/base_serializers.py#L51-L69 | def get_fields(self):
"""
Convert default field names for this sub-serializer into versions where
the field name has the prefix removed, but each field object knows the
real model field name by setting the field's `source` attribute.
"""
prefix = getattr(self.Meta, 'sourc... | [
"def",
"get_fields",
"(",
"self",
")",
":",
"prefix",
"=",
"getattr",
"(",
"self",
".",
"Meta",
",",
"'source_prefix'",
",",
"''",
")",
"fields",
"=",
"super",
"(",
"ModelSubSerializer",
",",
"self",
")",
".",
"get_fields",
"(",
")",
"fields_without_prefix... | Convert default field names for this sub-serializer into versions where
the field name has the prefix removed, but each field object knows the
real model field name by setting the field's `source` attribute. | [
"Convert",
"default",
"field",
"names",
"for",
"this",
"sub",
"-",
"serializer",
"into",
"versions",
"where",
"the",
"field",
"name",
"has",
"the",
"prefix",
"removed",
"but",
"each",
"field",
"object",
"knows",
"the",
"real",
"model",
"field",
"name",
"by",... | python | train |
nevimov/django-easycart | easycart/cart.py | https://github.com/nevimov/django-easycart/blob/81b7d7d4b197e34d21dcd8cb9eb9104b565041a9/easycart/cart.py#L497-L514 | def count_items(self, unique=True):
"""Count items in the cart.
Parameters
----------
unique : bool-convertible, optional
Returns
-------
int
If `unique` is truthy, then the result is the number of
items in the cart. Otherwise, it's the s... | [
"def",
"count_items",
"(",
"self",
",",
"unique",
"=",
"True",
")",
":",
"if",
"unique",
":",
"return",
"len",
"(",
"self",
".",
"items",
")",
"return",
"sum",
"(",
"[",
"item",
".",
"quantity",
"for",
"item",
"in",
"self",
".",
"items",
".",
"valu... | Count items in the cart.
Parameters
----------
unique : bool-convertible, optional
Returns
-------
int
If `unique` is truthy, then the result is the number of
items in the cart. Otherwise, it's the sum of all item
quantities. | [
"Count",
"items",
"in",
"the",
"cart",
"."
] | python | train |
bcbio/bcbio-nextgen | scripts/bcbio_nextgen.py | https://github.com/bcbio/bcbio-nextgen/blob/6a9348c0054ccd5baffd22f1bb7d0422f6978b20/scripts/bcbio_nextgen.py#L162-L216 | def _add_inputs_to_kwargs(args, kwargs, parser):
"""Convert input system config, flow cell directory and sample yaml to kwargs.
Handles back compatibility with previous commandlines while allowing flexible
specification of input parameters.
"""
inputs = [x for x in [args.global_config, args.fc_dir]... | [
"def",
"_add_inputs_to_kwargs",
"(",
"args",
",",
"kwargs",
",",
"parser",
")",
":",
"inputs",
"=",
"[",
"x",
"for",
"x",
"in",
"[",
"args",
".",
"global_config",
",",
"args",
".",
"fc_dir",
"]",
"+",
"args",
".",
"run_config",
"if",
"x",
"is",
"not"... | Convert input system config, flow cell directory and sample yaml to kwargs.
Handles back compatibility with previous commandlines while allowing flexible
specification of input parameters. | [
"Convert",
"input",
"system",
"config",
"flow",
"cell",
"directory",
"and",
"sample",
"yaml",
"to",
"kwargs",
"."
] | python | train |
cloudera/cm_api | python/src/cm_api/endpoints/types.py | https://github.com/cloudera/cm_api/blob/5d2512375bd94684b4da36df9e0d9177865ffcbb/python/src/cm_api/endpoints/types.py#L325-L331 | def _cmd(self, command, data=None, params=None, api_version=1):
"""
Invokes a command on the resource. Commands are expected to be under the
"commands/" sub-resource.
"""
return self._post("commands/" + command, ApiCommand,
data=data, params=params, api_version=api_version) | [
"def",
"_cmd",
"(",
"self",
",",
"command",
",",
"data",
"=",
"None",
",",
"params",
"=",
"None",
",",
"api_version",
"=",
"1",
")",
":",
"return",
"self",
".",
"_post",
"(",
"\"commands/\"",
"+",
"command",
",",
"ApiCommand",
",",
"data",
"=",
"data... | Invokes a command on the resource. Commands are expected to be under the
"commands/" sub-resource. | [
"Invokes",
"a",
"command",
"on",
"the",
"resource",
".",
"Commands",
"are",
"expected",
"to",
"be",
"under",
"the",
"commands",
"/",
"sub",
"-",
"resource",
"."
] | python | train |
cherrypy/cheroot | cheroot/server.py | https://github.com/cherrypy/cheroot/blob/2af3b1798d66da697957480d3a8b4831a405770b/cheroot/server.py#L1610-L1647 | def clear_stats(self):
"""Reset server stat counters.."""
self._start_time = None
self._run_time = 0
self.stats = {
'Enabled': False,
'Bind Address': lambda s: repr(self.bind_addr),
'Run time': lambda s: (not s['Enabled']) and -1 or self.runtime(),
... | [
"def",
"clear_stats",
"(",
"self",
")",
":",
"self",
".",
"_start_time",
"=",
"None",
"self",
".",
"_run_time",
"=",
"0",
"self",
".",
"stats",
"=",
"{",
"'Enabled'",
":",
"False",
",",
"'Bind Address'",
":",
"lambda",
"s",
":",
"repr",
"(",
"self",
... | Reset server stat counters.. | [
"Reset",
"server",
"stat",
"counters",
".."
] | python | train |
edx/edx-oauth2-provider | edx_oauth2_provider/oidc/core.py | https://github.com/edx/edx-oauth2-provider/blob/73e7569a8369e74c345022ccba634365e24befab/edx_oauth2_provider/oidc/core.py#L59-L99 | def id_token(access_token, nonce=None, claims_request=None):
"""
Returns data required for an OpenID Connect ID Token according to:
- http://openid.net/specs/openid-connect-basic-1_0.html#IDToken
Arguments:
access_token (:class:`AccessToken`): Associated OAuth2 access token.
nonce (str... | [
"def",
"id_token",
"(",
"access_token",
",",
"nonce",
"=",
"None",
",",
"claims_request",
"=",
"None",
")",
":",
"handlers",
"=",
"HANDLERS",
"[",
"'id_token'",
"]",
"# Select only the relevant section of the claims request.",
"claims_request_section",
"=",
"claims_requ... | Returns data required for an OpenID Connect ID Token according to:
- http://openid.net/specs/openid-connect-basic-1_0.html#IDToken
Arguments:
access_token (:class:`AccessToken`): Associated OAuth2 access token.
nonce (str): Optional nonce to protect against replay attacks.
claims_reque... | [
"Returns",
"data",
"required",
"for",
"an",
"OpenID",
"Connect",
"ID",
"Token",
"according",
"to",
":"
] | python | train |
dancsalo/TensorBase | tensorbase/base.py | https://github.com/dancsalo/TensorBase/blob/3d42a326452bd03427034916ff2fb90730020204/tensorbase/base.py#L262-L273 | def _set_tf_functions(self):
""" Sets up summary writer, saver, and session, with configurable gpu visibility """
merged = tf.summary.merge_all()
saver = tf.train.Saver()
if type(self.flags['GPU']) is int:
os.environ["CUDA_VISIBLE_DEVICES"] = str(self.flags['GPU'])
... | [
"def",
"_set_tf_functions",
"(",
"self",
")",
":",
"merged",
"=",
"tf",
".",
"summary",
".",
"merge_all",
"(",
")",
"saver",
"=",
"tf",
".",
"train",
".",
"Saver",
"(",
")",
"if",
"type",
"(",
"self",
".",
"flags",
"[",
"'GPU'",
"]",
")",
"is",
"... | Sets up summary writer, saver, and session, with configurable gpu visibility | [
"Sets",
"up",
"summary",
"writer",
"saver",
"and",
"session",
"with",
"configurable",
"gpu",
"visibility"
] | python | train |
googleapis/google-cloud-python | api_core/google/api_core/page_iterator.py | https://github.com/googleapis/google-cloud-python/blob/85e80125a59cb10f8cb105f25ecc099e4b940b50/api_core/google/api_core/page_iterator.py#L399-L418 | def _get_next_page_response(self):
"""Requests the next page from the path provided.
Returns:
dict: The parsed JSON response of the next page's contents.
Raises:
ValueError: If the HTTP method is not ``GET`` or ``POST``.
"""
params = self._get_query_para... | [
"def",
"_get_next_page_response",
"(",
"self",
")",
":",
"params",
"=",
"self",
".",
"_get_query_params",
"(",
")",
"if",
"self",
".",
"_HTTP_METHOD",
"==",
"\"GET\"",
":",
"return",
"self",
".",
"api_request",
"(",
"method",
"=",
"self",
".",
"_HTTP_METHOD"... | Requests the next page from the path provided.
Returns:
dict: The parsed JSON response of the next page's contents.
Raises:
ValueError: If the HTTP method is not ``GET`` or ``POST``. | [
"Requests",
"the",
"next",
"page",
"from",
"the",
"path",
"provided",
"."
] | python | train |
titusjan/argos | argos/inspector/qtplugins/table.py | https://github.com/titusjan/argos/blob/20d0a3cae26c36ea789a5d219c02ca7df21279dd/argos/inspector/qtplugins/table.py#L58-L98 | def makeReplacementField(formatSpec, altFormatSpec='', testValue=None):
""" Prepends a colon and wraps the formatSpec in curly braces to yield a replacement field.
The format specification is part of a replacement field, which can be used in new-style
string formatting. See:
https://doc... | [
"def",
"makeReplacementField",
"(",
"formatSpec",
",",
"altFormatSpec",
"=",
"''",
",",
"testValue",
"=",
"None",
")",
":",
"check_is_a_string",
"(",
"formatSpec",
")",
"check_is_a_string",
"(",
"altFormatSpec",
")",
"fmt",
"=",
"altFormatSpec",
"if",
"not",
"fo... | Prepends a colon and wraps the formatSpec in curly braces to yield a replacement field.
The format specification is part of a replacement field, which can be used in new-style
string formatting. See:
https://docs.python.org/3/library/string.html#format-string-syntax
https://docs... | [
"Prepends",
"a",
"colon",
"and",
"wraps",
"the",
"formatSpec",
"in",
"curly",
"braces",
"to",
"yield",
"a",
"replacement",
"field",
"."
] | python | train |
cimatosa/progression | progression/decorators.py | https://github.com/cimatosa/progression/blob/82cf74a25a47f9bda96157cc2c88e5975c20b41d/progression/decorators.py#L130-L136 | def _get_callargs(self, *args, **kwargs):
"""
Retrieve all arguments that `self.func` needs and
return a dictionary with call arguments.
"""
callargs = getcallargs(self.func, *args, **kwargs)
return callargs | [
"def",
"_get_callargs",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"callargs",
"=",
"getcallargs",
"(",
"self",
".",
"func",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
"return",
"callargs"
] | Retrieve all arguments that `self.func` needs and
return a dictionary with call arguments. | [
"Retrieve",
"all",
"arguments",
"that",
"self",
".",
"func",
"needs",
"and",
"return",
"a",
"dictionary",
"with",
"call",
"arguments",
"."
] | python | train |
pmacosta/peng | docs/support/requirements_to_rst.py | https://github.com/pmacosta/peng/blob/976935377adaa3de26fc5677aceb2cdfbd6f93a7/docs/support/requirements_to_rst.py#L53-L74 | def op_to_words(item):
"""Translate >=, ==, <= to words."""
sdicts = [
{"==": ""},
{">=": " or newer"},
{">": "newer than "},
{"<=": " or older"},
{"<": "older than "},
{"!=": "except "},
]
for sdict in sdicts:
prefix = list(sdict.keys())[0]
... | [
"def",
"op_to_words",
"(",
"item",
")",
":",
"sdicts",
"=",
"[",
"{",
"\"==\"",
":",
"\"\"",
"}",
",",
"{",
"\">=\"",
":",
"\" or newer\"",
"}",
",",
"{",
"\">\"",
":",
"\"newer than \"",
"}",
",",
"{",
"\"<=\"",
":",
"\" or older\"",
"}",
",",
"{",
... | Translate >=, ==, <= to words. | [
"Translate",
">",
"=",
"==",
"<",
"=",
"to",
"words",
"."
] | python | test |
senaite/senaite.core | bika/lims/browser/publish/reports_listing.py | https://github.com/senaite/senaite.core/blob/7602ce2ea2f9e81eb34e20ce17b98a3e70713f85/bika/lims/browser/publish/reports_listing.py#L103-L110 | def get_filesize(self, pdf):
"""Compute the filesize of the PDF
"""
try:
filesize = float(pdf.get_size())
return filesize / 1024
except (POSKeyError, TypeError):
return 0 | [
"def",
"get_filesize",
"(",
"self",
",",
"pdf",
")",
":",
"try",
":",
"filesize",
"=",
"float",
"(",
"pdf",
".",
"get_size",
"(",
")",
")",
"return",
"filesize",
"/",
"1024",
"except",
"(",
"POSKeyError",
",",
"TypeError",
")",
":",
"return",
"0"
] | Compute the filesize of the PDF | [
"Compute",
"the",
"filesize",
"of",
"the",
"PDF"
] | python | train |
rm-hull/luma.core | luma/core/virtual.py | https://github.com/rm-hull/luma.core/blob/034b628fb304a01e77732a299c0b42e94d6443db/luma/core/virtual.py#L88-L96 | def is_overlapping_viewport(self, hotspot, xy):
"""
Checks to see if the hotspot at position ``(x, y)``
is (at least partially) visible according to the
position of the viewport.
"""
l1, t1, r1, b1 = calc_bounds(xy, hotspot)
l2, t2, r2, b2 = calc_bounds(self._posi... | [
"def",
"is_overlapping_viewport",
"(",
"self",
",",
"hotspot",
",",
"xy",
")",
":",
"l1",
",",
"t1",
",",
"r1",
",",
"b1",
"=",
"calc_bounds",
"(",
"xy",
",",
"hotspot",
")",
"l2",
",",
"t2",
",",
"r2",
",",
"b2",
"=",
"calc_bounds",
"(",
"self",
... | Checks to see if the hotspot at position ``(x, y)``
is (at least partially) visible according to the
position of the viewport. | [
"Checks",
"to",
"see",
"if",
"the",
"hotspot",
"at",
"position",
"(",
"x",
"y",
")",
"is",
"(",
"at",
"least",
"partially",
")",
"visible",
"according",
"to",
"the",
"position",
"of",
"the",
"viewport",
"."
] | python | train |
mamrhein/specification | specification/_extd_ast_expr.py | https://github.com/mamrhein/specification/blob/a4c09a0d286cda7a04e8a189f12e23edd97f64ea/specification/_extd_ast_expr.py#L429-L450 | def visit_arguments(self, node: AST, dfltChaining: bool = True) -> str:
"""Return `node`s representation as argument list."""
args = node.args
dflts = node.defaults
vararg = node.vararg
kwargs = node.kwonlyargs
kwdflts = node.kw_defaults
kwarg = node.kwarg
... | [
"def",
"visit_arguments",
"(",
"self",
",",
"node",
":",
"AST",
",",
"dfltChaining",
":",
"bool",
"=",
"True",
")",
"->",
"str",
":",
"args",
"=",
"node",
".",
"args",
"dflts",
"=",
"node",
".",
"defaults",
"vararg",
"=",
"node",
".",
"vararg",
"kwar... | Return `node`s representation as argument list. | [
"Return",
"node",
"s",
"representation",
"as",
"argument",
"list",
"."
] | python | train |
CI-WATER/gsshapy | gsshapy/grid/grid_to_gssha.py | https://github.com/CI-WATER/gsshapy/blob/00fd4af0fd65f1614d75a52fe950a04fb0867f4c/gsshapy/grid/grid_to_gssha.py#L589-L606 | def xd(self):
"""get xarray dataset file handle to LSM files"""
if self._xd is None:
path_to_lsm_files = path.join(self.lsm_input_folder_path,
self.lsm_search_card)
self._xd = pa.open_mfdataset(path_to_lsm_files,
... | [
"def",
"xd",
"(",
"self",
")",
":",
"if",
"self",
".",
"_xd",
"is",
"None",
":",
"path_to_lsm_files",
"=",
"path",
".",
"join",
"(",
"self",
".",
"lsm_input_folder_path",
",",
"self",
".",
"lsm_search_card",
")",
"self",
".",
"_xd",
"=",
"pa",
".",
"... | get xarray dataset file handle to LSM files | [
"get",
"xarray",
"dataset",
"file",
"handle",
"to",
"LSM",
"files"
] | python | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.