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 |
|---|---|---|---|---|---|---|---|---|
websauna/pyramid_notebook | pyramid_notebook/notebookmanager.py | https://github.com/websauna/pyramid_notebook/blob/8a7ecfa0259810de1a818e4b415a62811a7b077a/pyramid_notebook/notebookmanager.py#L128-L161 | def start_notebook(self, name, context: dict, fg=False):
"""Start new IPython Notebook daemon.
:param name: The owner of the Notebook will be *name*. He/she gets a new Notebook content folder created where all files are placed.
:param context: Extra context information passed to the started No... | [
"def",
"start_notebook",
"(",
"self",
",",
"name",
",",
"context",
":",
"dict",
",",
"fg",
"=",
"False",
")",
":",
"assert",
"context",
"assert",
"type",
"(",
"context",
")",
"==",
"dict",
"assert",
"\"context_hash\"",
"in",
"context",
"assert",
"type",
... | Start new IPython Notebook daemon.
:param name: The owner of the Notebook will be *name*. He/she gets a new Notebook content folder created where all files are placed.
:param context: Extra context information passed to the started Notebook. This must contain {context_hash:int} parameter used to ident... | [
"Start",
"new",
"IPython",
"Notebook",
"daemon",
"."
] | python | train |
Kortemme-Lab/klab | klab/benchmarking/analysis/ddg_monomeric_stability_analysis.py | https://github.com/Kortemme-Lab/klab/blob/6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b/klab/benchmarking/analysis/ddg_monomeric_stability_analysis.py#L1759-L1833 | def plot_optimum_prediction_fraction_correct_cutoffs_over_range(self, analysis_set, min_stability_classication_x_cutoff, max_stability_classication_x_cutoff, suppress_plot = False, analysis_file_prefix = None, verbose = True):
'''Plots the optimum cutoff for the predictions to maximize the fraction correct metr... | [
"def",
"plot_optimum_prediction_fraction_correct_cutoffs_over_range",
"(",
"self",
",",
"analysis_set",
",",
"min_stability_classication_x_cutoff",
",",
"max_stability_classication_x_cutoff",
",",
"suppress_plot",
"=",
"False",
",",
"analysis_file_prefix",
"=",
"None",
",",
"ve... | Plots the optimum cutoff for the predictions to maximize the fraction correct metric over a range of experimental cutoffs.
Returns the average scalar corresponding to the best value of fraction correct over a range of cutoff values for the experimental cutoffs. | [
"Plots",
"the",
"optimum",
"cutoff",
"for",
"the",
"predictions",
"to",
"maximize",
"the",
"fraction",
"correct",
"metric",
"over",
"a",
"range",
"of",
"experimental",
"cutoffs",
".",
"Returns",
"the",
"average",
"scalar",
"corresponding",
"to",
"the",
"best",
... | python | train |
swharden/SWHLab | doc/oldcode/swhlab/core/common.py | https://github.com/swharden/SWHLab/blob/a86c3c65323cec809a4bd4f81919644927094bf5/doc/oldcode/swhlab/core/common.py#L113-L123 | def dictAvg(listOfDicts,key,stdErr=False):
"""Given a list (l) of dicts (d), return AV and SD."""
vals=dictVals(listOfDicts,key)
if len(vals) and np.any(vals):
av=np.nanmean(vals)
er=np.nanstd(vals)
if stdErr:
er=er/np.sqrt(np.count_nonzero(~np.isnan(er)))
else:
... | [
"def",
"dictAvg",
"(",
"listOfDicts",
",",
"key",
",",
"stdErr",
"=",
"False",
")",
":",
"vals",
"=",
"dictVals",
"(",
"listOfDicts",
",",
"key",
")",
"if",
"len",
"(",
"vals",
")",
"and",
"np",
".",
"any",
"(",
"vals",
")",
":",
"av",
"=",
"np",... | Given a list (l) of dicts (d), return AV and SD. | [
"Given",
"a",
"list",
"(",
"l",
")",
"of",
"dicts",
"(",
"d",
")",
"return",
"AV",
"and",
"SD",
"."
] | python | valid |
WTRMQDev/lnoise | lnoise/noisetypes.py | https://github.com/WTRMQDev/lnoise/blob/7f8d9faf135025a6aac50131d14a34d1009e8cdd/lnoise/noisetypes.py#L113-L125 | def append(self, val):
"""Append byte string val to buffer
If the result exceeds the length of the buffer, behavior
depends on whether instance was initialized as strict.
In strict mode, a ValueError is raised.
In non-strict mode, the buffer is extended as necessary.
"""
... | [
"def",
"append",
"(",
"self",
",",
"val",
")",
":",
"new_len",
"=",
"self",
".",
"length",
"+",
"len",
"(",
"val",
")",
"to_add",
"=",
"new_len",
"-",
"len",
"(",
"self",
".",
"bfr",
")",
"if",
"self",
".",
"strict",
"and",
"to_add",
">",
"0",
... | Append byte string val to buffer
If the result exceeds the length of the buffer, behavior
depends on whether instance was initialized as strict.
In strict mode, a ValueError is raised.
In non-strict mode, the buffer is extended as necessary. | [
"Append",
"byte",
"string",
"val",
"to",
"buffer",
"If",
"the",
"result",
"exceeds",
"the",
"length",
"of",
"the",
"buffer",
"behavior",
"depends",
"on",
"whether",
"instance",
"was",
"initialized",
"as",
"strict",
".",
"In",
"strict",
"mode",
"a",
"ValueErr... | python | train |
influxdata/influxdb-python | influxdb/influxdb08/client.py | https://github.com/influxdata/influxdb-python/blob/d5d12499f3755199d5eedd8b363450f1cf4073bd/influxdb/influxdb08/client.py#L321-L331 | def write_points_with_precision(self, data, time_precision='s'):
"""Write to multiple time series names.
DEPRECATED.
"""
warnings.warn(
"write_points_with_precision is deprecated, and will be removed "
"in future versions. Please use "
"``InfluxDBClie... | [
"def",
"write_points_with_precision",
"(",
"self",
",",
"data",
",",
"time_precision",
"=",
"'s'",
")",
":",
"warnings",
".",
"warn",
"(",
"\"write_points_with_precision is deprecated, and will be removed \"",
"\"in future versions. Please use \"",
"\"``InfluxDBClient.write_point... | Write to multiple time series names.
DEPRECATED. | [
"Write",
"to",
"multiple",
"time",
"series",
"names",
"."
] | python | train |
mitsei/dlkit | dlkit/json_/authorization/sessions.py | https://github.com/mitsei/dlkit/blob/445f968a175d61c8d92c0f617a3c17dc1dc7c584/dlkit/json_/authorization/sessions.py#L3077-L3096 | def is_parent_of_vault(self, id_, vault_id):
"""Tests if an ``Id`` is a direct parent of a vault.
arg: id (osid.id.Id): an ``Id``
arg: vault_id (osid.id.Id): the ``Id`` of a vault
return: (boolean) - ``true`` if this ``id`` is a parent of
``vault_id,`` ``false`` o... | [
"def",
"is_parent_of_vault",
"(",
"self",
",",
"id_",
",",
"vault_id",
")",
":",
"# Implemented from template for",
"# osid.resource.BinHierarchySession.is_parent_of_bin",
"if",
"self",
".",
"_catalog_session",
"is",
"not",
"None",
":",
"return",
"self",
".",
"_catalog_... | Tests if an ``Id`` is a direct parent of a vault.
arg: id (osid.id.Id): an ``Id``
arg: vault_id (osid.id.Id): the ``Id`` of a vault
return: (boolean) - ``true`` if this ``id`` is a parent of
``vault_id,`` ``false`` otherwise
raise: NotFound - ``vault_id`` is not ... | [
"Tests",
"if",
"an",
"Id",
"is",
"a",
"direct",
"parent",
"of",
"a",
"vault",
"."
] | python | train |
bennylope/smartystreets.py | smartystreets/client.py | https://github.com/bennylope/smartystreets.py/blob/f45e37dd52ea7cec8ed43ce2b64724beb6dbbb69/smartystreets/client.py#L16-L34 | def validate_args(f):
"""
Ensures that *args consist of a consistent type
:param f: any client method with *args parameter
:return: function f
"""
def wrapper(self, args):
arg_types = set([type(arg) for arg in args])
if len(arg_types) > 1:
raise TypeError("Mixed inp... | [
"def",
"validate_args",
"(",
"f",
")",
":",
"def",
"wrapper",
"(",
"self",
",",
"args",
")",
":",
"arg_types",
"=",
"set",
"(",
"[",
"type",
"(",
"arg",
")",
"for",
"arg",
"in",
"args",
"]",
")",
"if",
"len",
"(",
"arg_types",
")",
">",
"1",
":... | Ensures that *args consist of a consistent type
:param f: any client method with *args parameter
:return: function f | [
"Ensures",
"that",
"*",
"args",
"consist",
"of",
"a",
"consistent",
"type"
] | python | train |
CalebBell/thermo | thermo/viscosity.py | https://github.com/CalebBell/thermo/blob/3857ed023a3e64fd3039a32d53576c24990ef1c3/thermo/viscosity.py#L1454-L1501 | def load_all_methods(self):
r'''Method which picks out coefficients for the specified chemical
from the various dictionaries and DataFrames storing it. All data is
stored as attributes. This method also sets :obj:`Tmin`, :obj:`Tmax`,
:obj:`all_methods` and obj:`all_methods_P` as a set of... | [
"def",
"load_all_methods",
"(",
"self",
")",
":",
"methods",
",",
"methods_P",
"=",
"[",
"]",
",",
"[",
"]",
"Tmins",
",",
"Tmaxs",
"=",
"[",
"]",
",",
"[",
"]",
"if",
"self",
".",
"CASRN",
"in",
"_VDISaturationDict",
":",
"methods",
".",
"append",
... | r'''Method which picks out coefficients for the specified chemical
from the various dictionaries and DataFrames storing it. All data is
stored as attributes. This method also sets :obj:`Tmin`, :obj:`Tmax`,
:obj:`all_methods` and obj:`all_methods_P` as a set of methods for
which the data ... | [
"r",
"Method",
"which",
"picks",
"out",
"coefficients",
"for",
"the",
"specified",
"chemical",
"from",
"the",
"various",
"dictionaries",
"and",
"DataFrames",
"storing",
"it",
".",
"All",
"data",
"is",
"stored",
"as",
"attributes",
".",
"This",
"method",
"also"... | python | valid |
python-openxml/python-docx | docx/enum/base.py | https://github.com/python-openxml/python-docx/blob/6756f6cd145511d3eb6d1d188beea391b1ddfd53/docx/enum/base.py#L15-L27 | def alias(*aliases):
"""
Decorating a class with @alias('FOO', 'BAR', ..) allows the class to
be referenced by each of the names provided as arguments.
"""
def decorator(cls):
# alias must be set in globals from caller's frame
caller = sys._getframe(1)
globals_dict = caller.f... | [
"def",
"alias",
"(",
"*",
"aliases",
")",
":",
"def",
"decorator",
"(",
"cls",
")",
":",
"# alias must be set in globals from caller's frame",
"caller",
"=",
"sys",
".",
"_getframe",
"(",
"1",
")",
"globals_dict",
"=",
"caller",
".",
"f_globals",
"for",
"alias... | Decorating a class with @alias('FOO', 'BAR', ..) allows the class to
be referenced by each of the names provided as arguments. | [
"Decorating",
"a",
"class",
"with"
] | python | train |
QuantEcon/QuantEcon.py | quantecon/dle.py | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/quantecon/dle.py#L299-L330 | def canonical(self):
"""
Compute canonical preference representation
Uses auxiliary problem of 9.4.2, with the preference shock process reintroduced
Calculates pihat, llambdahat and ubhat for the equivalent canonical household technology
"""
Ac1 = np.hstack((self.deltah,... | [
"def",
"canonical",
"(",
"self",
")",
":",
"Ac1",
"=",
"np",
".",
"hstack",
"(",
"(",
"self",
".",
"deltah",
",",
"np",
".",
"zeros",
"(",
"(",
"self",
".",
"nh",
",",
"self",
".",
"nz",
")",
")",
")",
")",
"Ac2",
"=",
"np",
".",
"hstack",
... | Compute canonical preference representation
Uses auxiliary problem of 9.4.2, with the preference shock process reintroduced
Calculates pihat, llambdahat and ubhat for the equivalent canonical household technology | [
"Compute",
"canonical",
"preference",
"representation",
"Uses",
"auxiliary",
"problem",
"of",
"9",
".",
"4",
".",
"2",
"with",
"the",
"preference",
"shock",
"process",
"reintroduced",
"Calculates",
"pihat",
"llambdahat",
"and",
"ubhat",
"for",
"the",
"equivalent",... | python | train |
mgoral/subconvert | src/subconvert/utils/SubFile.py | https://github.com/mgoral/subconvert/blob/59701e5e69ef1ca26ce7d1d766c936664aa2cb32/src/subconvert/utils/SubFile.py#L189-L194 | def detectFps(self, movieFile = None, default = 23.976):
"""Fetch movie FPS from MPlayer output or return given default."""
if movieFile is None:
movieFile = self._searchForMovieFile()
return File.detectFpsFromMovie(movieFile, default) | [
"def",
"detectFps",
"(",
"self",
",",
"movieFile",
"=",
"None",
",",
"default",
"=",
"23.976",
")",
":",
"if",
"movieFile",
"is",
"None",
":",
"movieFile",
"=",
"self",
".",
"_searchForMovieFile",
"(",
")",
"return",
"File",
".",
"detectFpsFromMovie",
"(",... | Fetch movie FPS from MPlayer output or return given default. | [
"Fetch",
"movie",
"FPS",
"from",
"MPlayer",
"output",
"or",
"return",
"given",
"default",
"."
] | python | train |
econ-ark/HARK | HARK/ConsumptionSaving/ConsAggShockModel.py | https://github.com/econ-ark/HARK/blob/3d184153a189e618a87c9540df1cd12044039cc5/HARK/ConsumptionSaving/ConsAggShockModel.py#L937-L967 | def update(self):
'''
Use primitive parameters (and perfect foresight calibrations) to make
interest factor and wage rate functions (of capital to labor ratio),
as well as discrete approximations to the aggregate shock distributions.
Parameters
----------
None
... | [
"def",
"update",
"(",
"self",
")",
":",
"self",
".",
"kSS",
"=",
"(",
"(",
"self",
".",
"getPermGroFacAggLR",
"(",
")",
"**",
"(",
"self",
".",
"CRRA",
")",
"/",
"self",
".",
"DiscFac",
"-",
"(",
"1.0",
"-",
"self",
".",
"DeprFac",
")",
")",
"/... | Use primitive parameters (and perfect foresight calibrations) to make
interest factor and wage rate functions (of capital to labor ratio),
as well as discrete approximations to the aggregate shock distributions.
Parameters
----------
None
Returns
-------
... | [
"Use",
"primitive",
"parameters",
"(",
"and",
"perfect",
"foresight",
"calibrations",
")",
"to",
"make",
"interest",
"factor",
"and",
"wage",
"rate",
"functions",
"(",
"of",
"capital",
"to",
"labor",
"ratio",
")",
"as",
"well",
"as",
"discrete",
"approximation... | python | train |
manahl/arctic | arctic/store/version_store.py | https://github.com/manahl/arctic/blob/57e110b6e182dbab00e7e214dc26f7d9ec47c120/arctic/store/version_store.py#L338-L383 | def read(self, symbol, as_of=None, date_range=None, from_version=None, allow_secondary=None, **kwargs):
"""
Read data for the named symbol. Returns a VersionedItem object with
a data and metdata element (as passed into write).
Parameters
----------
symbol : `str`
... | [
"def",
"read",
"(",
"self",
",",
"symbol",
",",
"as_of",
"=",
"None",
",",
"date_range",
"=",
"None",
",",
"from_version",
"=",
"None",
",",
"allow_secondary",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"try",
":",
"read_preference",
"=",
"self",
... | Read data for the named symbol. Returns a VersionedItem object with
a data and metdata element (as passed into write).
Parameters
----------
symbol : `str`
symbol name for the item
as_of : `str` or `int` or `datetime.datetime`
Return the data as it was a... | [
"Read",
"data",
"for",
"the",
"named",
"symbol",
".",
"Returns",
"a",
"VersionedItem",
"object",
"with",
"a",
"data",
"and",
"metdata",
"element",
"(",
"as",
"passed",
"into",
"write",
")",
"."
] | python | train |
pulumi/pulumi | sdk/python/lib/pulumi/resource.py | https://github.com/pulumi/pulumi/blob/95d51efe6ab9a533838b6d83aa240b5f912e72aa/sdk/python/lib/pulumi/resource.py#L321-L330 | def export(name: str, value: Any):
"""
Exports a named stack output.
:param str name: The name to assign to this output.
:param Any value: The value of this output.
"""
stack = get_root_resource()
if stack is not None:
stack.output(name, value) | [
"def",
"export",
"(",
"name",
":",
"str",
",",
"value",
":",
"Any",
")",
":",
"stack",
"=",
"get_root_resource",
"(",
")",
"if",
"stack",
"is",
"not",
"None",
":",
"stack",
".",
"output",
"(",
"name",
",",
"value",
")"
] | Exports a named stack output.
:param str name: The name to assign to this output.
:param Any value: The value of this output. | [
"Exports",
"a",
"named",
"stack",
"output",
"."
] | python | train |
nickpandolfi/Cyther | cyther/configuration.py | https://github.com/nickpandolfi/Cyther/blob/9fb0bd77af594008aa6ee8af460aa8c953abf5bc/cyther/configuration.py#L333-L353 | def generate_configurations(*, guided=False, fresh_start=False, save=False):
"""
If a config file is found in the standard locations, it will be loaded and
the config data would be retuned. If not found, then generate the data on
the fly, and return it
"""
if fresh_start:
purge_configs(... | [
"def",
"generate_configurations",
"(",
"*",
",",
"guided",
"=",
"False",
",",
"fresh_start",
"=",
"False",
",",
"save",
"=",
"False",
")",
":",
"if",
"fresh_start",
":",
"purge_configs",
"(",
")",
"loaded_status",
",",
"loaded_data",
"=",
"get_config",
"(",
... | If a config file is found in the standard locations, it will be loaded and
the config data would be retuned. If not found, then generate the data on
the fly, and return it | [
"If",
"a",
"config",
"file",
"is",
"found",
"in",
"the",
"standard",
"locations",
"it",
"will",
"be",
"loaded",
"and",
"the",
"config",
"data",
"would",
"be",
"retuned",
".",
"If",
"not",
"found",
"then",
"generate",
"the",
"data",
"on",
"the",
"fly",
... | python | train |
linkedin/pyexchange | pyexchange/exchange2010/__init__.py | https://github.com/linkedin/pyexchange/blob/d568f4edd326adb451b915ddf66cf1a37820e3ca/pyexchange/exchange2010/__init__.py#L154-L174 | def load_all_details(self):
"""
This function will execute all the event lookups for known events.
This is intended for use when you want to have a completely populated event entry, including
Organizer & Attendee details.
"""
log.debug(u"Loading all details")
if self.count > 0:
# Now,... | [
"def",
"load_all_details",
"(",
"self",
")",
":",
"log",
".",
"debug",
"(",
"u\"Loading all details\"",
")",
"if",
"self",
".",
"count",
">",
"0",
":",
"# Now, empty out the events to prevent duplicates!",
"del",
"(",
"self",
".",
"events",
"[",
":",
"]",
")",... | This function will execute all the event lookups for known events.
This is intended for use when you want to have a completely populated event entry, including
Organizer & Attendee details. | [
"This",
"function",
"will",
"execute",
"all",
"the",
"event",
"lookups",
"for",
"known",
"events",
"."
] | python | train |
tradenity/python-sdk | tradenity/resources/tax_rate.py | https://github.com/tradenity/python-sdk/blob/d13fbe23f4d6ff22554c6d8d2deaf209371adaf1/tradenity/resources/tax_rate.py#L339-L353 | def based_on(self, based_on):
"""Sets the based_on of this TaxRate.
:param based_on: The based_on of this TaxRate.
:type: str
"""
allowed_values = ["shippingAddress", "billingAddress"]
if based_on is not None and based_on not in allowed_values:
raise ValueEr... | [
"def",
"based_on",
"(",
"self",
",",
"based_on",
")",
":",
"allowed_values",
"=",
"[",
"\"shippingAddress\"",
",",
"\"billingAddress\"",
"]",
"if",
"based_on",
"is",
"not",
"None",
"and",
"based_on",
"not",
"in",
"allowed_values",
":",
"raise",
"ValueError",
"... | Sets the based_on of this TaxRate.
:param based_on: The based_on of this TaxRate.
:type: str | [
"Sets",
"the",
"based_on",
"of",
"this",
"TaxRate",
"."
] | python | train |
opinkerfi/nago | nago/settings/__init__.py | https://github.com/opinkerfi/nago/blob/85e1bdd1de0122f56868a483e7599e1b36a439b0/nago/settings/__init__.py#L96-L108 | def generate_configfile(cfg_file,defaults=defaults):
""" Write a new nago.ini config file from the defaults.
Arguments:
cfg_file -- File that is written to like /etc/nago/nago.ini
defaults -- Dictionary with default values to use
"""
# Create a directory if needed and write an empty f... | [
"def",
"generate_configfile",
"(",
"cfg_file",
",",
"defaults",
"=",
"defaults",
")",
":",
"# Create a directory if needed and write an empty file",
"_mkdir_for_config",
"(",
"cfg_file",
"=",
"cfg_file",
")",
"with",
"open",
"(",
"cfg_file",
",",
"'w'",
")",
"as",
"... | Write a new nago.ini config file from the defaults.
Arguments:
cfg_file -- File that is written to like /etc/nago/nago.ini
defaults -- Dictionary with default values to use | [
"Write",
"a",
"new",
"nago",
".",
"ini",
"config",
"file",
"from",
"the",
"defaults",
"."
] | python | train |
gwastro/pycbc | pycbc/inference/sampler/base_mcmc.py | https://github.com/gwastro/pycbc/blob/7a64cdd104d263f1b6ea0b01e6841837d05a4cb3/pycbc/inference/sampler/base_mcmc.py#L241-L249 | def niterations(self):
"""The current number of iterations."""
itercounter = self._itercounter
if itercounter is None:
itercounter = 0
lastclear = self._lastclear
if lastclear is None:
lastclear = 0
return itercounter + lastclear | [
"def",
"niterations",
"(",
"self",
")",
":",
"itercounter",
"=",
"self",
".",
"_itercounter",
"if",
"itercounter",
"is",
"None",
":",
"itercounter",
"=",
"0",
"lastclear",
"=",
"self",
".",
"_lastclear",
"if",
"lastclear",
"is",
"None",
":",
"lastclear",
"... | The current number of iterations. | [
"The",
"current",
"number",
"of",
"iterations",
"."
] | python | train |
joeblackwaslike/pricing | pricing/babel_numbers.py | https://github.com/joeblackwaslike/pricing/blob/be988b0851b4313af81f1db475bc33248700e39c/pricing/babel_numbers.py#L185-L259 | def apply(
self, value, locale, currency=None, currency_digits=True,
decimal_quantization=True):
"""Renders into a string a number following the defined pattern.
Forced decimal quantization is active by default so we'll produce a
number string that is strictly following C... | [
"def",
"apply",
"(",
"self",
",",
"value",
",",
"locale",
",",
"currency",
"=",
"None",
",",
"currency_digits",
"=",
"True",
",",
"decimal_quantization",
"=",
"True",
")",
":",
"if",
"not",
"isinstance",
"(",
"value",
",",
"decimal",
".",
"Decimal",
")",... | Renders into a string a number following the defined pattern.
Forced decimal quantization is active by default so we'll produce a
number string that is strictly following CLDR pattern definitions. | [
"Renders",
"into",
"a",
"string",
"a",
"number",
"following",
"the",
"defined",
"pattern",
".",
"Forced",
"decimal",
"quantization",
"is",
"active",
"by",
"default",
"so",
"we",
"ll",
"produce",
"a",
"number",
"string",
"that",
"is",
"strictly",
"following",
... | python | test |
numenta/nupic | src/nupic/algorithms/sdr_classifier.py | https://github.com/numenta/nupic/blob/5922fafffdccc8812e72b3324965ad2f7d4bbdad/src/nupic/algorithms/sdr_classifier.py#L478-L500 | def _calculateError(self, recordNum, bucketIdxList):
"""
Calculate error signal
:param bucketIdxList: list of encoder buckets
:return: dict containing error. The key is the number of steps
The value is a numpy array of error at the output layer
"""
error = dict()
targetDist = ... | [
"def",
"_calculateError",
"(",
"self",
",",
"recordNum",
",",
"bucketIdxList",
")",
":",
"error",
"=",
"dict",
"(",
")",
"targetDist",
"=",
"numpy",
".",
"zeros",
"(",
"self",
".",
"_maxBucketIdx",
"+",
"1",
")",
"numCategories",
"=",
"len",
"(",
"bucket... | Calculate error signal
:param bucketIdxList: list of encoder buckets
:return: dict containing error. The key is the number of steps
The value is a numpy array of error at the output layer | [
"Calculate",
"error",
"signal"
] | python | valid |
pytroll/satpy | satpy/composites/viirs.py | https://github.com/pytroll/satpy/blob/1f21d20ac686b745fb0da9b4030d139893e066dd/satpy/composites/viirs.py#L594-L819 | def local_histogram_equalization(data, mask_to_equalize, valid_data_mask=None, number_of_bins=1000,
std_mult_cutoff=3.0,
do_zerotoone_normalization=True,
local_radius_px=300,
clip_limit=60... | [
"def",
"local_histogram_equalization",
"(",
"data",
",",
"mask_to_equalize",
",",
"valid_data_mask",
"=",
"None",
",",
"number_of_bins",
"=",
"1000",
",",
"std_mult_cutoff",
"=",
"3.0",
",",
"do_zerotoone_normalization",
"=",
"True",
",",
"local_radius_px",
"=",
"30... | Equalize the provided data (in the mask_to_equalize) using adaptive histogram equalization.
tiles of width/height (2 * local_radius_px + 1) will be calculated and results for each pixel will be bilinerarly
interpolated from the nearest 4 tiles when pixels fall near the edge of the image (there is no adjacent t... | [
"Equalize",
"the",
"provided",
"data",
"(",
"in",
"the",
"mask_to_equalize",
")",
"using",
"adaptive",
"histogram",
"equalization",
"."
] | python | train |
HttpRunner/HttpRunner | httprunner/cli.py | https://github.com/HttpRunner/HttpRunner/blob/f259551bf9c8ba905eae5c1afcf2efea20ae0871/httprunner/cli.py#L91-L180 | def main_locust():
""" Performance test with locust: parse command line options and run commands.
"""
# monkey patch ssl at beginning to avoid RecursionError when running locust.
from gevent import monkey; monkey.patch_ssl()
import multiprocessing
import sys
from httprunner import logger
... | [
"def",
"main_locust",
"(",
")",
":",
"# monkey patch ssl at beginning to avoid RecursionError when running locust.",
"from",
"gevent",
"import",
"monkey",
"monkey",
".",
"patch_ssl",
"(",
")",
"import",
"multiprocessing",
"import",
"sys",
"from",
"httprunner",
"import",
"... | Performance test with locust: parse command line options and run commands. | [
"Performance",
"test",
"with",
"locust",
":",
"parse",
"command",
"line",
"options",
"and",
"run",
"commands",
"."
] | python | train |
Aloomaio/python-sdk | alooma_pysdk/alooma_pysdk.py | https://github.com/Aloomaio/python-sdk/blob/e6e7322d0b23d90b1ff0320e9a9c431c82c0c277/alooma_pysdk/alooma_pysdk.py#L274-L287 | def _notify(self, log_level, message):
"""
Calls the callback function and logs messages using the PySDK logger
:param log_level: An integer representing the log level, as specified
in the Python `logging` library
:param message: The actual message to be sent ... | [
"def",
"_notify",
"(",
"self",
",",
"log_level",
",",
"message",
")",
":",
"timestamp",
"=",
"datetime",
".",
"datetime",
".",
"utcnow",
"(",
")",
"logger",
".",
"log",
"(",
"log_level",
",",
"str",
"(",
"message",
")",
")",
"try",
":",
"self",
".",
... | Calls the callback function and logs messages using the PySDK logger
:param log_level: An integer representing the log level, as specified
in the Python `logging` library
:param message: The actual message to be sent to the logger and the
`callback` ... | [
"Calls",
"the",
"callback",
"function",
"and",
"logs",
"messages",
"using",
"the",
"PySDK",
"logger",
":",
"param",
"log_level",
":",
"An",
"integer",
"representing",
"the",
"log",
"level",
"as",
"specified",
"in",
"the",
"Python",
"logging",
"library",
":",
... | python | train |
open-mmlab/mmcv | mmcv/runner/priority.py | https://github.com/open-mmlab/mmcv/blob/0d77f61450aab4dde8b8585a577cc496acb95d7f/mmcv/runner/priority.py#L35-L53 | def get_priority(priority):
"""Get priority value.
Args:
priority (int or str or :obj:`Priority`): Priority.
Returns:
int: The priority value.
"""
if isinstance(priority, int):
if priority < 0 or priority > 100:
raise ValueError('priority must be between 0 and 1... | [
"def",
"get_priority",
"(",
"priority",
")",
":",
"if",
"isinstance",
"(",
"priority",
",",
"int",
")",
":",
"if",
"priority",
"<",
"0",
"or",
"priority",
">",
"100",
":",
"raise",
"ValueError",
"(",
"'priority must be between 0 and 100'",
")",
"return",
"pr... | Get priority value.
Args:
priority (int or str or :obj:`Priority`): Priority.
Returns:
int: The priority value. | [
"Get",
"priority",
"value",
"."
] | python | test |
centralniak/py-raildriver | raildriver/library.py | https://github.com/centralniak/py-raildriver/blob/c7f5f551e0436451b9507fc63a62e49a229282b9/raildriver/library.py#L134-L141 | def get_current_time(self):
"""
Get current time
:return: datetime.time
"""
hms = [int(self.get_current_controller_value(i)) for i in range(406, 409)]
return datetime.time(*hms) | [
"def",
"get_current_time",
"(",
"self",
")",
":",
"hms",
"=",
"[",
"int",
"(",
"self",
".",
"get_current_controller_value",
"(",
"i",
")",
")",
"for",
"i",
"in",
"range",
"(",
"406",
",",
"409",
")",
"]",
"return",
"datetime",
".",
"time",
"(",
"*",
... | Get current time
:return: datetime.time | [
"Get",
"current",
"time"
] | python | train |
10gen/mongo-orchestration | mongo_orchestration/replica_sets.py | https://github.com/10gen/mongo-orchestration/blob/81fd2224205922ea2178b08190b53a33aec47261/mongo_orchestration/replica_sets.py#L522-L541 | def wait_while_reachable(self, servers, timeout=60):
"""wait while all servers be reachable
Args:
servers - list of servers
"""
t_start = time.time()
while True:
try:
for server in servers:
# TODO: use state code to chec... | [
"def",
"wait_while_reachable",
"(",
"self",
",",
"servers",
",",
"timeout",
"=",
"60",
")",
":",
"t_start",
"=",
"time",
".",
"time",
"(",
")",
"while",
"True",
":",
"try",
":",
"for",
"server",
"in",
"servers",
":",
"# TODO: use state code to check if serve... | wait while all servers be reachable
Args:
servers - list of servers | [
"wait",
"while",
"all",
"servers",
"be",
"reachable",
"Args",
":",
"servers",
"-",
"list",
"of",
"servers"
] | python | train |
blockstack/blockstack-core | blockstack/blockstackd.py | https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/blockstackd.py#L1124-L1172 | def rpc_getinfo(self, **con_info):
"""
Get information from the running server:
* last_block_seen: the last block height seen
* consensus: the consensus hash for that block
* server_version: the server version
* last_block_processed: the last block processed
* ser... | [
"def",
"rpc_getinfo",
"(",
"self",
",",
"*",
"*",
"con_info",
")",
":",
"conf",
"=",
"get_blockstack_opts",
"(",
")",
"info",
"=",
"self",
".",
"get_bitcoind_info",
"(",
")",
"cinfo",
"=",
"self",
".",
"get_consensus_info",
"(",
")",
"reply",
"=",
"{",
... | Get information from the running server:
* last_block_seen: the last block height seen
* consensus: the consensus hash for that block
* server_version: the server version
* last_block_processed: the last block processed
* server_alive: True
* [optional] zonefile_count: th... | [
"Get",
"information",
"from",
"the",
"running",
"server",
":",
"*",
"last_block_seen",
":",
"the",
"last",
"block",
"height",
"seen",
"*",
"consensus",
":",
"the",
"consensus",
"hash",
"for",
"that",
"block",
"*",
"server_version",
":",
"the",
"server",
"ver... | python | train |
karan/TPB | tpb/utils.py | https://github.com/karan/TPB/blob/f424a73a10d4bcf4e363d7e7e8cb915a3a057671/tpb/utils.py#L56-L63 | def _segment(cls, segment):
"""
Returns a property capable of setting and getting a segment.
"""
return property(
fget=lambda x: cls._get_segment(x, segment),
fset=lambda x, v: cls._set_segment(x, segment, v),
) | [
"def",
"_segment",
"(",
"cls",
",",
"segment",
")",
":",
"return",
"property",
"(",
"fget",
"=",
"lambda",
"x",
":",
"cls",
".",
"_get_segment",
"(",
"x",
",",
"segment",
")",
",",
"fset",
"=",
"lambda",
"x",
",",
"v",
":",
"cls",
".",
"_set_segmen... | Returns a property capable of setting and getting a segment. | [
"Returns",
"a",
"property",
"capable",
"of",
"setting",
"and",
"getting",
"a",
"segment",
"."
] | python | train |
ZELLMECHANIK-DRESDEN/dclab | dclab/external/statsmodels/nonparametric/_kernel_base.py | https://github.com/ZELLMECHANIK-DRESDEN/dclab/blob/79002c4356e7020c2ba73ab0a3819c9abd4affec/dclab/external/statsmodels/nonparametric/_kernel_base.py#L58-L66 | def _set_defaults(self, defaults):
"""Sets the default values for the efficient estimation"""
self.n_res = defaults.n_res
self.n_sub = defaults.n_sub
self.randomize = defaults.randomize
self.return_median = defaults.return_median
self.efficient = defaults.efficient
... | [
"def",
"_set_defaults",
"(",
"self",
",",
"defaults",
")",
":",
"self",
".",
"n_res",
"=",
"defaults",
".",
"n_res",
"self",
".",
"n_sub",
"=",
"defaults",
".",
"n_sub",
"self",
".",
"randomize",
"=",
"defaults",
".",
"randomize",
"self",
".",
"return_me... | Sets the default values for the efficient estimation | [
"Sets",
"the",
"default",
"values",
"for",
"the",
"efficient",
"estimation"
] | python | train |
Miserlou/Zappa | zappa/cli.py | https://github.com/Miserlou/Zappa/blob/3ccf7490a8d8b8fa74a61ee39bf44234f3567739/zappa/cli.py#L2744-L2757 | def shamelessly_promote():
"""
Shamelessly promote our little community.
"""
click.echo("Need " + click.style("help", fg='green', bold=True) +
"? Found a " + click.style("bug", fg='green', bold=True) +
"? Let us " + click.style("know", fg='green', bold=True) + "! :D")
... | [
"def",
"shamelessly_promote",
"(",
")",
":",
"click",
".",
"echo",
"(",
"\"Need \"",
"+",
"click",
".",
"style",
"(",
"\"help\"",
",",
"fg",
"=",
"'green'",
",",
"bold",
"=",
"True",
")",
"+",
"\"? Found a \"",
"+",
"click",
".",
"style",
"(",
"\"bug\"... | Shamelessly promote our little community. | [
"Shamelessly",
"promote",
"our",
"little",
"community",
"."
] | python | train |
ConsenSys/mythril-classic | mythril/ethereum/interface/leveldb/accountindexing.py | https://github.com/ConsenSys/mythril-classic/blob/27af71c34b2ce94f4fae5613ec457f93df1a8f56/mythril/ethereum/interface/leveldb/accountindexing.py#L111-L177 | def updateIfNeeded(self):
"""update address index."""
headBlock = self.db.reader._get_head_block()
if headBlock is not None:
# avoid restarting search if head block is same & we already initialized
# this is required for fastSync handling
if self.lastBlock is ... | [
"def",
"updateIfNeeded",
"(",
"self",
")",
":",
"headBlock",
"=",
"self",
".",
"db",
".",
"reader",
".",
"_get_head_block",
"(",
")",
"if",
"headBlock",
"is",
"not",
"None",
":",
"# avoid restarting search if head block is same & we already initialized",
"# this is re... | update address index. | [
"update",
"address",
"index",
"."
] | python | train |
pyQode/pyqode.core | pyqode/core/widgets/splittable_tab_widget.py | https://github.com/pyQode/pyqode.core/blob/a99ec6cd22d519394f613309412f8329dc4e90cb/pyqode/core/widgets/splittable_tab_widget.py#L993-L1003 | def get_filter(cls, mimetype):
"""
Returns a filter string for the file dialog. The filter is based
on the mime type.
:param mimetype: path from which the filter must be derived.
:return: Filter string
"""
filters = ' '.join(
['*%s' % ext for ext in m... | [
"def",
"get_filter",
"(",
"cls",
",",
"mimetype",
")",
":",
"filters",
"=",
"' '",
".",
"join",
"(",
"[",
"'*%s'",
"%",
"ext",
"for",
"ext",
"in",
"mimetypes",
".",
"guess_all_extensions",
"(",
"mimetype",
")",
"]",
")",
"return",
"'%s (%s)'",
"%",
"("... | Returns a filter string for the file dialog. The filter is based
on the mime type.
:param mimetype: path from which the filter must be derived.
:return: Filter string | [
"Returns",
"a",
"filter",
"string",
"for",
"the",
"file",
"dialog",
".",
"The",
"filter",
"is",
"based",
"on",
"the",
"mime",
"type",
"."
] | python | train |
tjcsl/cslbot | cslbot/helpers/handler.py | https://github.com/tjcsl/cslbot/blob/aebe07be47141f61d7c180706bddfb707f19b2b5/cslbot/helpers/handler.py#L259-L285 | def do_part(self, cmdargs, nick, target, msgtype, send, c):
"""Leaves a channel.
Prevent user from leaving the primary channel.
"""
channel = self.config['core']['channel']
botnick = self.config['core']['nick']
if not cmdargs:
# don't leave the primary chann... | [
"def",
"do_part",
"(",
"self",
",",
"cmdargs",
",",
"nick",
",",
"target",
",",
"msgtype",
",",
"send",
",",
"c",
")",
":",
"channel",
"=",
"self",
".",
"config",
"[",
"'core'",
"]",
"[",
"'channel'",
"]",
"botnick",
"=",
"self",
".",
"config",
"["... | Leaves a channel.
Prevent user from leaving the primary channel. | [
"Leaves",
"a",
"channel",
"."
] | python | train |
Duke-GCB/DukeDSClient | ddsc/core/fileuploader.py | https://github.com/Duke-GCB/DukeDSClient/blob/117f68fb9bae82e4c81ea487ad5d61ac350f3726/ddsc/core/fileuploader.py#L126-L138 | def create_upload(self, project_id, path_data, hash_data, remote_filename=None, storage_provider_id=None):
"""
Create a chunked upload id to pass to create_file_chunk_url to create upload urls.
:param project_id: str: uuid of the project
:param path_data: PathData: holds file system data... | [
"def",
"create_upload",
"(",
"self",
",",
"project_id",
",",
"path_data",
",",
"hash_data",
",",
"remote_filename",
"=",
"None",
",",
"storage_provider_id",
"=",
"None",
")",
":",
"upload_response",
"=",
"self",
".",
"_create_upload",
"(",
"project_id",
",",
"... | Create a chunked upload id to pass to create_file_chunk_url to create upload urls.
:param project_id: str: uuid of the project
:param path_data: PathData: holds file system data about the file we are uploading
:param hash_data: HashData: contains hash alg and value for the file we are uploading
... | [
"Create",
"a",
"chunked",
"upload",
"id",
"to",
"pass",
"to",
"create_file_chunk_url",
"to",
"create",
"upload",
"urls",
".",
":",
"param",
"project_id",
":",
"str",
":",
"uuid",
"of",
"the",
"project",
":",
"param",
"path_data",
":",
"PathData",
":",
"hol... | python | train |
dstufft/storages | storages/core.py | https://github.com/dstufft/storages/blob/0d893afc1db32cd83eaf8e2ad4ed51b37933d5f0/storages/core.py#L79-L94 | def get_available_name(self, name):
"""
Returns a filename that's free on the target storage system, and
available for new content to be written to.
"""
dir_name, file_name = os.path.split(name)
file_root, file_ext = os.path.splitext(file_name)
# If the filename a... | [
"def",
"get_available_name",
"(",
"self",
",",
"name",
")",
":",
"dir_name",
",",
"file_name",
"=",
"os",
".",
"path",
".",
"split",
"(",
"name",
")",
"file_root",
",",
"file_ext",
"=",
"os",
".",
"path",
".",
"splitext",
"(",
"file_name",
")",
"# If t... | Returns a filename that's free on the target storage system, and
available for new content to be written to. | [
"Returns",
"a",
"filename",
"that",
"s",
"free",
"on",
"the",
"target",
"storage",
"system",
"and",
"available",
"for",
"new",
"content",
"to",
"be",
"written",
"to",
"."
] | python | train |
edibledinos/pwnypack | pwnypack/bytecode.py | https://github.com/edibledinos/pwnypack/blob/e0a5a8e6ef3f4f1f7e1b91ee379711f4a49cb0e6/pwnypack/bytecode.py#L574-L587 | def from_function(cls, f, *args, **kwargs):
"""
Create a new instance from a function. Gets the code object from
the function and passes it and any other specified parameters to
:meth:`from_code`.
Arguments:
f(function): The function to get the code object from.
... | [
"def",
"from_function",
"(",
"cls",
",",
"f",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"cls",
".",
"from_code",
"(",
"six",
".",
"get_function_code",
"(",
"f",
")",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")"
] | Create a new instance from a function. Gets the code object from
the function and passes it and any other specified parameters to
:meth:`from_code`.
Arguments:
f(function): The function to get the code object from.
Returns:
CodeObject: A new :class:`CodeObject` ... | [
"Create",
"a",
"new",
"instance",
"from",
"a",
"function",
".",
"Gets",
"the",
"code",
"object",
"from",
"the",
"function",
"and",
"passes",
"it",
"and",
"any",
"other",
"specified",
"parameters",
"to",
":",
"meth",
":",
"from_code",
"."
] | python | train |
juicer/juicer | juicer/utils/__init__.py | https://github.com/juicer/juicer/blob/0c9f0fd59e293d45df6b46e81f675d33221c600d/juicer/utils/__init__.py#L337-L352 | def find_pattern(search_base, pattern='*.rpm'):
"""
`search_base` - The directory to begin walking down.
`pattern` - File pattern to match for.
This is a generator which yields the full path to files (one at a
time) which match the given glob (`pattern`).
"""
# Stolen from http://rosettacod... | [
"def",
"find_pattern",
"(",
"search_base",
",",
"pattern",
"=",
"'*.rpm'",
")",
":",
"# Stolen from http://rosettacode.org/wiki/Walk_a_directory/Recursively#Python",
"if",
"(",
"not",
"os",
".",
"path",
".",
"isdir",
"(",
"search_base",
")",
")",
"and",
"os",
".",
... | `search_base` - The directory to begin walking down.
`pattern` - File pattern to match for.
This is a generator which yields the full path to files (one at a
time) which match the given glob (`pattern`). | [
"search_base",
"-",
"The",
"directory",
"to",
"begin",
"walking",
"down",
".",
"pattern",
"-",
"File",
"pattern",
"to",
"match",
"for",
"."
] | python | train |
InspectorMustache/base16-builder-python | pybase16_builder/updater.py | https://github.com/InspectorMustache/base16-builder-python/blob/586f1f87ee9f70696ab19c542af6ef55c6548a2e/pybase16_builder/updater.py#L34-L57 | def git_clone(git_url, path):
"""Clone git repository at $git_url to $path."""
if os.path.exists(os.path.join(path, '.git')):
# get rid of local repo if it already exists
shutil.rmtree(path)
os.makedirs(path, exist_ok=True)
print('Start cloning from {}…'.format(git_url))
git_proc = ... | [
"def",
"git_clone",
"(",
"git_url",
",",
"path",
")",
":",
"if",
"os",
".",
"path",
".",
"exists",
"(",
"os",
".",
"path",
".",
"join",
"(",
"path",
",",
"'.git'",
")",
")",
":",
"# get rid of local repo if it already exists",
"shutil",
".",
"rmtree",
"(... | Clone git repository at $git_url to $path. | [
"Clone",
"git",
"repository",
"at",
"$git_url",
"to",
"$path",
"."
] | python | train |
NiklasRosenstein-Python/nr-deprecated | nr/ast/dynamic_eval.py | https://github.com/NiklasRosenstein-Python/nr-deprecated/blob/f9f8b89ea1b084841a8ab65784eaf68852686b2a/nr/ast/dynamic_eval.py#L114-L123 | def __get_subscript(self, name, ctx=None):
"""
Returns `<data_var>["<name>"]`
"""
assert isinstance(name, string_types), name
return ast.Subscript(
value=ast.Name(id=self.data_var, ctx=ast.Load()),
slice=ast.Index(value=ast.Str(s=name)),
ctx=ctx) | [
"def",
"__get_subscript",
"(",
"self",
",",
"name",
",",
"ctx",
"=",
"None",
")",
":",
"assert",
"isinstance",
"(",
"name",
",",
"string_types",
")",
",",
"name",
"return",
"ast",
".",
"Subscript",
"(",
"value",
"=",
"ast",
".",
"Name",
"(",
"id",
"=... | Returns `<data_var>["<name>"]` | [
"Returns",
"<data_var",
">",
"[",
"<name",
">",
"]"
] | python | train |
hyperledger/indy-plenum | plenum/common/signer_did.py | https://github.com/hyperledger/indy-plenum/blob/dcd144e238af7f17a869ffc9412f13dc488b7020/plenum/common/signer_did.py#L122-L129 | def sign(self, msg: Dict) -> Dict:
"""
Return a signature for the given message.
"""
ser = serialize_msg_for_signing(msg, topLevelKeysToIgnore=[f.SIG.nm])
bsig = self.naclSigner.signature(ser)
sig = base58.b58encode(bsig).decode("utf-8")
return sig | [
"def",
"sign",
"(",
"self",
",",
"msg",
":",
"Dict",
")",
"->",
"Dict",
":",
"ser",
"=",
"serialize_msg_for_signing",
"(",
"msg",
",",
"topLevelKeysToIgnore",
"=",
"[",
"f",
".",
"SIG",
".",
"nm",
"]",
")",
"bsig",
"=",
"self",
".",
"naclSigner",
"."... | Return a signature for the given message. | [
"Return",
"a",
"signature",
"for",
"the",
"given",
"message",
"."
] | python | train |
connectordb/connectordb-python | connectordb/_websocket.py | https://github.com/connectordb/connectordb-python/blob/2092b0cb30898139a247176bcf433d5a4abde7cb/connectordb/_websocket.py#L69-L86 | def setauth(self,basic_auth):
""" setauth can be used during runtime to make sure that authentication is reset.
it can be used when changing passwords/apikeys to make sure reconnects succeed """
self.headers = []
# If we have auth
if basic_auth is not None:
# we use a... | [
"def",
"setauth",
"(",
"self",
",",
"basic_auth",
")",
":",
"self",
".",
"headers",
"=",
"[",
"]",
"# If we have auth",
"if",
"basic_auth",
"is",
"not",
"None",
":",
"# we use a cheap hack to get the basic auth header out of the auth object.",
"# This snippet ends up with... | setauth can be used during runtime to make sure that authentication is reset.
it can be used when changing passwords/apikeys to make sure reconnects succeed | [
"setauth",
"can",
"be",
"used",
"during",
"runtime",
"to",
"make",
"sure",
"that",
"authentication",
"is",
"reset",
".",
"it",
"can",
"be",
"used",
"when",
"changing",
"passwords",
"/",
"apikeys",
"to",
"make",
"sure",
"reconnects",
"succeed"
] | python | test |
pypa/pipenv | pipenv/vendor/pexpect/screen.py | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/pexpect/screen.py#L339-L345 | def scroll_constrain (self):
'''This keeps the scroll region within the screen region.'''
if self.scroll_row_start <= 0:
self.scroll_row_start = 1
if self.scroll_row_end > self.rows:
self.scroll_row_end = self.rows | [
"def",
"scroll_constrain",
"(",
"self",
")",
":",
"if",
"self",
".",
"scroll_row_start",
"<=",
"0",
":",
"self",
".",
"scroll_row_start",
"=",
"1",
"if",
"self",
".",
"scroll_row_end",
">",
"self",
".",
"rows",
":",
"self",
".",
"scroll_row_end",
"=",
"s... | This keeps the scroll region within the screen region. | [
"This",
"keeps",
"the",
"scroll",
"region",
"within",
"the",
"screen",
"region",
"."
] | python | train |
pydata/xarray | xarray/coding/variables.py | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/coding/variables.py#L116-L125 | def pop_to(source, dest, key, name=None):
"""
A convenience function which pops a key k from source to dest.
None values are not passed on. If k already exists in dest an
error is raised.
"""
value = source.pop(key, None)
if value is not None:
safe_setitem(dest, key, value, name=nam... | [
"def",
"pop_to",
"(",
"source",
",",
"dest",
",",
"key",
",",
"name",
"=",
"None",
")",
":",
"value",
"=",
"source",
".",
"pop",
"(",
"key",
",",
"None",
")",
"if",
"value",
"is",
"not",
"None",
":",
"safe_setitem",
"(",
"dest",
",",
"key",
",",
... | A convenience function which pops a key k from source to dest.
None values are not passed on. If k already exists in dest an
error is raised. | [
"A",
"convenience",
"function",
"which",
"pops",
"a",
"key",
"k",
"from",
"source",
"to",
"dest",
".",
"None",
"values",
"are",
"not",
"passed",
"on",
".",
"If",
"k",
"already",
"exists",
"in",
"dest",
"an",
"error",
"is",
"raised",
"."
] | python | train |
DataBiosphere/toil | src/toil/batchSystems/lsfHelper.py | https://github.com/DataBiosphere/toil/blob/a8252277ff814e7bee0971139c2344f88e44b644/src/toil/batchSystems/lsfHelper.py#L108-L117 | def apply_lsadmin(fn):
"""
apply fn to each line of lsadmin, returning the result
"""
cmd = ["lsadmin", "showconf", "lim"]
try:
output = subprocess.check_output(cmd).decode('utf-8')
except:
return None
return fn(output.split("\n")) | [
"def",
"apply_lsadmin",
"(",
"fn",
")",
":",
"cmd",
"=",
"[",
"\"lsadmin\"",
",",
"\"showconf\"",
",",
"\"lim\"",
"]",
"try",
":",
"output",
"=",
"subprocess",
".",
"check_output",
"(",
"cmd",
")",
".",
"decode",
"(",
"'utf-8'",
")",
"except",
":",
"re... | apply fn to each line of lsadmin, returning the result | [
"apply",
"fn",
"to",
"each",
"line",
"of",
"lsadmin",
"returning",
"the",
"result"
] | python | train |
watchforstock/evohome-client | evohomeclient2/__init__.py | https://github.com/watchforstock/evohome-client/blob/f1cb9273e97946d79c0651f00a218abbf7ada53a/evohomeclient2/__init__.py#L236-L243 | def gateway(self):
"""Return the detail of the gateway."""
url = 'https://tccna.honeywell.com/WebAPI/emea/api/v1/gateway'
response = requests.get(url, headers=self._headers())
response.raise_for_status()
return response.json() | [
"def",
"gateway",
"(",
"self",
")",
":",
"url",
"=",
"'https://tccna.honeywell.com/WebAPI/emea/api/v1/gateway'",
"response",
"=",
"requests",
".",
"get",
"(",
"url",
",",
"headers",
"=",
"self",
".",
"_headers",
"(",
")",
")",
"response",
".",
"raise_for_status"... | Return the detail of the gateway. | [
"Return",
"the",
"detail",
"of",
"the",
"gateway",
"."
] | python | train |
greenbone/ospd | ospd/misc.py | https://github.com/greenbone/ospd/blob/cef773166b15a19c17764721d3fe404fa0e107bf/ospd/misc.py#L565-L594 | def target_to_list(target):
""" Attempt to return a list of single hosts from a target string. """
# Is it an IPv4 address ?
new_list = target_to_ipv4(target)
# Is it an IPv6 address ?
if not new_list:
new_list = target_to_ipv6(target)
# Is it an IPv4 CIDR ?
if not new_list:
... | [
"def",
"target_to_list",
"(",
"target",
")",
":",
"# Is it an IPv4 address ?",
"new_list",
"=",
"target_to_ipv4",
"(",
"target",
")",
"# Is it an IPv6 address ?",
"if",
"not",
"new_list",
":",
"new_list",
"=",
"target_to_ipv6",
"(",
"target",
")",
"# Is it an IPv4 CID... | Attempt to return a list of single hosts from a target string. | [
"Attempt",
"to",
"return",
"a",
"list",
"of",
"single",
"hosts",
"from",
"a",
"target",
"string",
"."
] | python | train |
glitchassassin/lackey | lackey/RegionMatching.py | https://github.com/glitchassassin/lackey/blob/7adadfacd7f45d81186710be992f5668b15399fe/lackey/RegionMatching.py#L1506-L1515 | def getEvents(self):
""" Returns a list of all events that have occurred.
Empties the internal queue.
"""
caught_events = self._observer.caught_events
self._observer.caught_events = []
for event in caught_events:
self._observer.activate_event(event["name"])
... | [
"def",
"getEvents",
"(",
"self",
")",
":",
"caught_events",
"=",
"self",
".",
"_observer",
".",
"caught_events",
"self",
".",
"_observer",
".",
"caught_events",
"=",
"[",
"]",
"for",
"event",
"in",
"caught_events",
":",
"self",
".",
"_observer",
".",
"acti... | Returns a list of all events that have occurred.
Empties the internal queue. | [
"Returns",
"a",
"list",
"of",
"all",
"events",
"that",
"have",
"occurred",
"."
] | python | train |
wesm/feather | cpp/build-support/cpplint.py | https://github.com/wesm/feather/blob/99267b30461c46b9e437f95e1d9338a92a854270/cpp/build-support/cpplint.py#L6048-L6121 | def ProcessConfigOverrides(filename):
""" Loads the configuration files and processes the config overrides.
Args:
filename: The name of the file being processed by the linter.
Returns:
False if the current |filename| should not be processed further.
"""
abs_filename = os.path.abspath(filename)
cf... | [
"def",
"ProcessConfigOverrides",
"(",
"filename",
")",
":",
"abs_filename",
"=",
"os",
".",
"path",
".",
"abspath",
"(",
"filename",
")",
"cfg_filters",
"=",
"[",
"]",
"keep_looking",
"=",
"True",
"while",
"keep_looking",
":",
"abs_path",
",",
"base_name",
"... | Loads the configuration files and processes the config overrides.
Args:
filename: The name of the file being processed by the linter.
Returns:
False if the current |filename| should not be processed further. | [
"Loads",
"the",
"configuration",
"files",
"and",
"processes",
"the",
"config",
"overrides",
"."
] | python | train |
chemlab/chemlab | chemlab/utils/pbc.py | https://github.com/chemlab/chemlab/blob/c8730966316d101e24f39ac3b96b51282aba0abe/chemlab/utils/pbc.py#L123-L134 | def geometric_center(coords, periodic):
'''Geometric center taking into account periodic boundaries'''
max_vals = periodic
theta = 2 * np.pi * (coords / max_vals)
eps = np.cos(theta) * max_vals / (2 * np.pi)
zeta = np.sin(theta) * max_vals / (2 * np.pi)
eps_avg = eps.sum(axis=0)
zeta_avg = ... | [
"def",
"geometric_center",
"(",
"coords",
",",
"periodic",
")",
":",
"max_vals",
"=",
"periodic",
"theta",
"=",
"2",
"*",
"np",
".",
"pi",
"*",
"(",
"coords",
"/",
"max_vals",
")",
"eps",
"=",
"np",
".",
"cos",
"(",
"theta",
")",
"*",
"max_vals",
"... | Geometric center taking into account periodic boundaries | [
"Geometric",
"center",
"taking",
"into",
"account",
"periodic",
"boundaries"
] | python | train |
gsi-upm/soil | soil/history.py | https://github.com/gsi-upm/soil/blob/a3ea434f237f039c3cadbc2e0a83ae626d77b818/soil/history.py#L79-L90 | def save_record(self, agent_id, t_step, key, value):
'''
Save a collection of records to the database.
Database writes are cached.
'''
value = self.convert(key, value)
self._tups.append(Record(agent_id=agent_id,
t_step=t_step,
... | [
"def",
"save_record",
"(",
"self",
",",
"agent_id",
",",
"t_step",
",",
"key",
",",
"value",
")",
":",
"value",
"=",
"self",
".",
"convert",
"(",
"key",
",",
"value",
")",
"self",
".",
"_tups",
".",
"append",
"(",
"Record",
"(",
"agent_id",
"=",
"a... | Save a collection of records to the database.
Database writes are cached. | [
"Save",
"a",
"collection",
"of",
"records",
"to",
"the",
"database",
".",
"Database",
"writes",
"are",
"cached",
"."
] | python | train |
aiogram/aiogram | aiogram/bot/bot.py | https://github.com/aiogram/aiogram/blob/2af930149ce2482547721e2c8755c10307295e48/aiogram/bot/bot.py#L1325-L1346 | async def set_chat_sticker_set(self, chat_id: typing.Union[base.Integer, base.String],
sticker_set_name: base.String) -> base.Boolean:
"""
Use this method to set a new group sticker set for a supergroup.
The bot must be an administrator in the chat for this to ... | [
"async",
"def",
"set_chat_sticker_set",
"(",
"self",
",",
"chat_id",
":",
"typing",
".",
"Union",
"[",
"base",
".",
"Integer",
",",
"base",
".",
"String",
"]",
",",
"sticker_set_name",
":",
"base",
".",
"String",
")",
"->",
"base",
".",
"Boolean",
":",
... | Use this method to set a new group sticker set for a supergroup.
The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.
Use the field can_set_sticker_set optionally returned in getChat requests to check
if the bot can use this method.
... | [
"Use",
"this",
"method",
"to",
"set",
"a",
"new",
"group",
"sticker",
"set",
"for",
"a",
"supergroup",
".",
"The",
"bot",
"must",
"be",
"an",
"administrator",
"in",
"the",
"chat",
"for",
"this",
"to",
"work",
"and",
"must",
"have",
"the",
"appropriate",
... | python | train |
raiden-network/raiden | raiden/network/rpc/client.py | https://github.com/raiden-network/raiden/blob/407ba15c72074e9de88771d6b9661ff4dc36bef5/raiden/network/rpc/client.py#L232-L262 | def dependencies_order_of_build(target_contract, dependencies_map):
""" Return an ordered list of contracts that is sufficient to successfully
deploy the target contract.
Note:
This function assumes that the `dependencies_map` is an acyclic graph.
"""
if not dependencies_map:
return... | [
"def",
"dependencies_order_of_build",
"(",
"target_contract",
",",
"dependencies_map",
")",
":",
"if",
"not",
"dependencies_map",
":",
"return",
"[",
"target_contract",
"]",
"if",
"target_contract",
"not",
"in",
"dependencies_map",
":",
"raise",
"ValueError",
"(",
"... | Return an ordered list of contracts that is sufficient to successfully
deploy the target contract.
Note:
This function assumes that the `dependencies_map` is an acyclic graph. | [
"Return",
"an",
"ordered",
"list",
"of",
"contracts",
"that",
"is",
"sufficient",
"to",
"successfully",
"deploy",
"the",
"target",
"contract",
"."
] | python | train |
larsyencken/proj | proj/__init__.py | https://github.com/larsyencken/proj/blob/44fd72aeb9bbf72046d81c4e9e4306a23335dc0a/proj/__init__.py#L145-L161 | def restore(folder):
"Restore a project from the archive."
if os.path.isdir(folder):
bail('a folder of the same name already exists!')
pattern = os.path.join(PROJ_ARCHIVE, '*', '*', folder)
matches = glob.glob(pattern)
if not matches:
bail('no project matches: ' + folder)
if le... | [
"def",
"restore",
"(",
"folder",
")",
":",
"if",
"os",
".",
"path",
".",
"isdir",
"(",
"folder",
")",
":",
"bail",
"(",
"'a folder of the same name already exists!'",
")",
"pattern",
"=",
"os",
".",
"path",
".",
"join",
"(",
"PROJ_ARCHIVE",
",",
"'*'",
"... | Restore a project from the archive. | [
"Restore",
"a",
"project",
"from",
"the",
"archive",
"."
] | python | test |
vecnet/vecnet.simulation | vecnet/simulation/__init__.py | https://github.com/vecnet/vecnet.simulation/blob/3a4b3df7b12418c6fa8a7d9cd49656a1c031fc0e/vecnet/simulation/__init__.py#L32-L39 | def read_json_file(cls, path):
"""
Read an instance from a JSON-formatted file.
:return: A new instance
"""
with open(path, 'r') as f:
return cls.from_dict(json.load(f)) | [
"def",
"read_json_file",
"(",
"cls",
",",
"path",
")",
":",
"with",
"open",
"(",
"path",
",",
"'r'",
")",
"as",
"f",
":",
"return",
"cls",
".",
"from_dict",
"(",
"json",
".",
"load",
"(",
"f",
")",
")"
] | Read an instance from a JSON-formatted file.
:return: A new instance | [
"Read",
"an",
"instance",
"from",
"a",
"JSON",
"-",
"formatted",
"file",
"."
] | python | train |
pybel/pybel | src/pybel/parser/parse_bel.py | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/parser/parse_bel.py#L743-L772 | def _handle_relation(self, tokens: ParseResults) -> str:
"""Handle a relation."""
subject_node_dsl = self.ensure_node(tokens[SUBJECT])
object_node_dsl = self.ensure_node(tokens[OBJECT])
subject_modifier = modifier_po_to_dict(tokens[SUBJECT])
object_modifier = modifier_po_to_dict... | [
"def",
"_handle_relation",
"(",
"self",
",",
"tokens",
":",
"ParseResults",
")",
"->",
"str",
":",
"subject_node_dsl",
"=",
"self",
".",
"ensure_node",
"(",
"tokens",
"[",
"SUBJECT",
"]",
")",
"object_node_dsl",
"=",
"self",
".",
"ensure_node",
"(",
"tokens"... | Handle a relation. | [
"Handle",
"a",
"relation",
"."
] | python | train |
NJDFan/ctypes-bitfield | bitfield/walk.py | https://github.com/NJDFan/ctypes-bitfield/blob/ae76b1dcfef7ecc90bd1900735b94ddee41a6376/bitfield/walk.py#L361-L380 | def _createbound(obj):
"""Create a new BoundNode representing a given object."""
# Start by allowing objects to define custom unbound reference hooks
try:
kls = obj._unboundreference_()
except AttributeError:
kls = type(obj)
unbound = _createunbound(kls)
def valueget():
... | [
"def",
"_createbound",
"(",
"obj",
")",
":",
"# Start by allowing objects to define custom unbound reference hooks",
"try",
":",
"kls",
"=",
"obj",
".",
"_unboundreference_",
"(",
")",
"except",
"AttributeError",
":",
"kls",
"=",
"type",
"(",
"obj",
")",
"unbound",
... | Create a new BoundNode representing a given object. | [
"Create",
"a",
"new",
"BoundNode",
"representing",
"a",
"given",
"object",
"."
] | python | train |
pygobject/pgi | pgi/overrides/Gtk.py | https://github.com/pygobject/pgi/blob/2090435df6241a15ec2a78379a36b738b728652c/pgi/overrides/Gtk.py#L257-L278 | def insert_text(self, text, position):
"""insert_text(self, text, position)
:param new_text:
the text to append
:type new_text: :obj:`str`
:param position:
location of the position text will be inserted at
:type position: :obj:`int`
:returns:
... | [
"def",
"insert_text",
"(",
"self",
",",
"text",
",",
"position",
")",
":",
"return",
"super",
"(",
"Editable",
",",
"self",
")",
".",
"insert_text",
"(",
"text",
",",
"-",
"1",
",",
"position",
")"
] | insert_text(self, text, position)
:param new_text:
the text to append
:type new_text: :obj:`str`
:param position:
location of the position text will be inserted at
:type position: :obj:`int`
:returns:
location of the position text will be in... | [
"insert_text",
"(",
"self",
"text",
"position",
")"
] | python | train |
brocade/pynos | pynos/versions/ver_6/ver_6_0_1/yang/tailf_confd_monitoring.py | https://github.com/brocade/pynos/blob/bd8a34e98f322de3fc06750827d8bbc3a0c00380/pynos/versions/ver_6/ver_6_0_1/yang/tailf_confd_monitoring.py#L201-L213 | def confd_state_netconf_listen_tcp_port(self, **kwargs):
"""Auto Generated Code
"""
config = ET.Element("config")
confd_state = ET.SubElement(config, "confd-state", xmlns="http://tail-f.com/yang/confd-monitoring")
netconf = ET.SubElement(confd_state, "netconf")
listen = E... | [
"def",
"confd_state_netconf_listen_tcp_port",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"config",
"=",
"ET",
".",
"Element",
"(",
"\"config\"",
")",
"confd_state",
"=",
"ET",
".",
"SubElement",
"(",
"config",
",",
"\"confd-state\"",
",",
"xmlns",
"=",
... | Auto Generated Code | [
"Auto",
"Generated",
"Code"
] | python | train |
ClericPy/torequests | torequests/dummy.py | https://github.com/ClericPy/torequests/blob/1793261688d7a47e1c3a0830d83f8552f5e3e5d9/torequests/dummy.py#L235-L262 | def submit(self, coro, callback=None):
"""Submit a coro as NewTask to self.loop without loop.frequncy control.
::
from torequests.dummy import Loop
import asyncio
loop = Loop()
async def test(i):
result = await asyncio.sleep(1)
... | [
"def",
"submit",
"(",
"self",
",",
"coro",
",",
"callback",
"=",
"None",
")",
":",
"callback",
"=",
"callback",
"or",
"self",
".",
"default_callback",
"if",
"self",
".",
"async_running",
":",
"return",
"self",
".",
"run_coroutine_threadsafe",
"(",
"coro",
... | Submit a coro as NewTask to self.loop without loop.frequncy control.
::
from torequests.dummy import Loop
import asyncio
loop = Loop()
async def test(i):
result = await asyncio.sleep(1)
return (loop.frequency, i)
cor... | [
"Submit",
"a",
"coro",
"as",
"NewTask",
"to",
"self",
".",
"loop",
"without",
"loop",
".",
"frequncy",
"control",
"."
] | python | train |
jbarlow83/OCRmyPDF | src/ocrmypdf/pdfinfo/__init__.py | https://github.com/jbarlow83/OCRmyPDF/blob/79c84eefa353632a3d7ccddbd398c6678c1c1777/src/ocrmypdf/pdfinfo/__init__.py#L401-L426 | def _find_regular_images(container, contentsinfo):
"""Find images stored in the container's /Resources /XObject
Usually the container is a page, but it could also be a Form XObject
that contains images.
Generates images with their DPI at time of drawing.
"""
for pdfimage, xobj in _image_xobje... | [
"def",
"_find_regular_images",
"(",
"container",
",",
"contentsinfo",
")",
":",
"for",
"pdfimage",
",",
"xobj",
"in",
"_image_xobjects",
"(",
"container",
")",
":",
"# For each image that is drawn on this, check if we drawing the",
"# current image - yes this is O(n^2), but n =... | Find images stored in the container's /Resources /XObject
Usually the container is a page, but it could also be a Form XObject
that contains images.
Generates images with their DPI at time of drawing. | [
"Find",
"images",
"stored",
"in",
"the",
"container",
"s",
"/",
"Resources",
"/",
"XObject"
] | python | train |
cloud9ers/gurumate | environment/share/doc/ipython/examples/parallel/dagdeps.py | https://github.com/cloud9ers/gurumate/blob/075dc74d1ee62a8c6b7a8bf2b271364f01629d1e/environment/share/doc/ipython/examples/parallel/dagdeps.py#L48-L54 | def make_bintree(levels):
"""Make a symmetrical binary tree with @levels"""
G = nx.DiGraph()
root = '0'
G.add_node(root)
add_children(G, root, levels, 2)
return G | [
"def",
"make_bintree",
"(",
"levels",
")",
":",
"G",
"=",
"nx",
".",
"DiGraph",
"(",
")",
"root",
"=",
"'0'",
"G",
".",
"add_node",
"(",
"root",
")",
"add_children",
"(",
"G",
",",
"root",
",",
"levels",
",",
"2",
")",
"return",
"G"
] | Make a symmetrical binary tree with @levels | [
"Make",
"a",
"symmetrical",
"binary",
"tree",
"with"
] | python | test |
mwhooker/jones | jones/jones.py | https://github.com/mwhooker/jones/blob/121e89572ca063f456b8e94cbb8cbee26c307a8f/jones/jones.py#L65-L68 | def _set(self, data, version):
"""serialize and set data to self.path."""
self.zk.set(self.path, json.dumps(data), version) | [
"def",
"_set",
"(",
"self",
",",
"data",
",",
"version",
")",
":",
"self",
".",
"zk",
".",
"set",
"(",
"self",
".",
"path",
",",
"json",
".",
"dumps",
"(",
"data",
")",
",",
"version",
")"
] | serialize and set data to self.path. | [
"serialize",
"and",
"set",
"data",
"to",
"self",
".",
"path",
"."
] | python | train |
SmokinCaterpillar/pypet | pypet/naturalnaming.py | https://github.com/SmokinCaterpillar/pypet/blob/97ad3e80d46dbdea02deeb98ea41f05a19565826/pypet/naturalnaming.py#L3380-L3416 | def f_load(self, recursive=True, load_data=pypetconstants.LOAD_DATA,
max_depth=None):
"""Loads a group from disk.
:param recursive:
Default is ``True``.
Whether recursively all nodes below the current node should be loaded, too.
Note that links are ne... | [
"def",
"f_load",
"(",
"self",
",",
"recursive",
"=",
"True",
",",
"load_data",
"=",
"pypetconstants",
".",
"LOAD_DATA",
",",
"max_depth",
"=",
"None",
")",
":",
"traj",
"=",
"self",
".",
"_nn_interface",
".",
"_root_instance",
"storage_service",
"=",
"traj",... | Loads a group from disk.
:param recursive:
Default is ``True``.
Whether recursively all nodes below the current node should be loaded, too.
Note that links are never evaluated recursively. Only the linked node
will be loaded if it does not exist in the tree, yet... | [
"Loads",
"a",
"group",
"from",
"disk",
"."
] | python | test |
chrlie/shorten | shorten/__init__.py | https://github.com/chrlie/shorten/blob/fb762a199979aefaa28c88fa035e88ea8ce4d639/shorten/__init__.py#L23-L42 | def make_store(name, min_length=4, **kwargs):
"""\
Creates a store with a reasonable keygen.
.. deprecated:: 2.0.0
Instantiate stores directly e.g. ``shorten.MemoryStore(min_length=4)``
"""
if name not in stores:
raise ValueError('valid stores are {0}'.format(', '.join(stores)))
if n... | [
"def",
"make_store",
"(",
"name",
",",
"min_length",
"=",
"4",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"name",
"not",
"in",
"stores",
":",
"raise",
"ValueError",
"(",
"'valid stores are {0}'",
".",
"format",
"(",
"', '",
".",
"join",
"(",
"stores",
")... | \
Creates a store with a reasonable keygen.
.. deprecated:: 2.0.0
Instantiate stores directly e.g. ``shorten.MemoryStore(min_length=4)`` | [
"\\",
"Creates",
"a",
"store",
"with",
"a",
"reasonable",
"keygen",
"."
] | python | train |
jlmadurga/permabots | permabots/views/api/handler.py | https://github.com/jlmadurga/permabots/blob/781a91702529a23fe7bc2aa84c5d88e961412466/permabots/views/api/handler.py#L332-L341 | def get(self, request, bot_id, id, format=None):
"""
Get list of source state of a handler
---
serializer: StateSerializer
responseMessages:
- code: 401
message: Not authenticated
"""
return super(SourceStateList, self).get(request, bot_i... | [
"def",
"get",
"(",
"self",
",",
"request",
",",
"bot_id",
",",
"id",
",",
"format",
"=",
"None",
")",
":",
"return",
"super",
"(",
"SourceStateList",
",",
"self",
")",
".",
"get",
"(",
"request",
",",
"bot_id",
",",
"id",
",",
"format",
")"
] | Get list of source state of a handler
---
serializer: StateSerializer
responseMessages:
- code: 401
message: Not authenticated | [
"Get",
"list",
"of",
"source",
"state",
"of",
"a",
"handler",
"---",
"serializer",
":",
"StateSerializer",
"responseMessages",
":",
"-",
"code",
":",
"401",
"message",
":",
"Not",
"authenticated"
] | python | train |
rossant/ipymd | ipymd/core/format_manager.py | https://github.com/rossant/ipymd/blob/d87c9ebc59d67fe78b0139ee00e0e5307682e303/ipymd/core/format_manager.py#L166-L181 | def load(self, file, name=None):
"""Load a file. The format name can be specified explicitly or
inferred from the file extension."""
if name is None:
name = self.format_from_extension(op.splitext(file)[1])
file_format = self.file_type(name)
if file_format == 'text':
... | [
"def",
"load",
"(",
"self",
",",
"file",
",",
"name",
"=",
"None",
")",
":",
"if",
"name",
"is",
"None",
":",
"name",
"=",
"self",
".",
"format_from_extension",
"(",
"op",
".",
"splitext",
"(",
"file",
")",
"[",
"1",
"]",
")",
"file_format",
"=",
... | Load a file. The format name can be specified explicitly or
inferred from the file extension. | [
"Load",
"a",
"file",
".",
"The",
"format",
"name",
"can",
"be",
"specified",
"explicitly",
"or",
"inferred",
"from",
"the",
"file",
"extension",
"."
] | python | train |
inveniosoftware/invenio-oauthclient | invenio_oauthclient/contrib/cern.py | https://github.com/inveniosoftware/invenio-oauthclient/blob/2500dc6935738107617aeade79e050d7608004bb/invenio_oauthclient/contrib/cern.py#L219-L229 | def fetch_extra_data(resource):
"""Return a dict with extra data retrieved from cern oauth."""
person_id = resource.get('PersonID', [None])[0]
identity_class = resource.get('IdentityClass', [None])[0]
department = resource.get('Department', [None])[0]
return dict(
person_id=person_id,
... | [
"def",
"fetch_extra_data",
"(",
"resource",
")",
":",
"person_id",
"=",
"resource",
".",
"get",
"(",
"'PersonID'",
",",
"[",
"None",
"]",
")",
"[",
"0",
"]",
"identity_class",
"=",
"resource",
".",
"get",
"(",
"'IdentityClass'",
",",
"[",
"None",
"]",
... | Return a dict with extra data retrieved from cern oauth. | [
"Return",
"a",
"dict",
"with",
"extra",
"data",
"retrieved",
"from",
"cern",
"oauth",
"."
] | python | train |
koordinates/python-client | koordinates/sources.py | https://github.com/koordinates/python-client/blob/f3dc7cd164f5a9499b2454cd1d4516e9d4b3c252/koordinates/sources.py#L300-L307 | def get_log_lines(self, source_id, scan_id):
"""
Get the log text for a scan object
:rtype: Iterator over log lines.
"""
target_url = self.client.get_url('SCAN', 'GET', 'log', {'source_id': source_id, 'scan_id': scan_id})
r = self.client.request('GET', target_url, headers... | [
"def",
"get_log_lines",
"(",
"self",
",",
"source_id",
",",
"scan_id",
")",
":",
"target_url",
"=",
"self",
".",
"client",
".",
"get_url",
"(",
"'SCAN'",
",",
"'GET'",
",",
"'log'",
",",
"{",
"'source_id'",
":",
"source_id",
",",
"'scan_id'",
":",
"scan_... | Get the log text for a scan object
:rtype: Iterator over log lines. | [
"Get",
"the",
"log",
"text",
"for",
"a",
"scan",
"object",
":",
"rtype",
":",
"Iterator",
"over",
"log",
"lines",
"."
] | python | train |
saltstack/salt | salt/modules/ps.py | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/ps.py#L50-L59 | def _get_proc_cmdline(proc):
'''
Returns the cmdline of a Process instance.
It's backward compatible with < 2.0 versions of psutil.
'''
try:
return salt.utils.data.decode(proc.cmdline() if PSUTIL2 else proc.cmdline)
except (psutil.NoSuchProcess, psutil.AccessDenied):
return [] | [
"def",
"_get_proc_cmdline",
"(",
"proc",
")",
":",
"try",
":",
"return",
"salt",
".",
"utils",
".",
"data",
".",
"decode",
"(",
"proc",
".",
"cmdline",
"(",
")",
"if",
"PSUTIL2",
"else",
"proc",
".",
"cmdline",
")",
"except",
"(",
"psutil",
".",
"NoS... | Returns the cmdline of a Process instance.
It's backward compatible with < 2.0 versions of psutil. | [
"Returns",
"the",
"cmdline",
"of",
"a",
"Process",
"instance",
"."
] | python | train |
johntruckenbrodt/spatialist | spatialist/auxil.py | https://github.com/johntruckenbrodt/spatialist/blob/007f49296a156de8d7168ad235b5a5b8e8d3633d/spatialist/auxil.py#L137-L171 | def gdalbuildvrt(src, dst, options=None, void=True):
"""
a simple wrapper for :osgeo:func:`gdal.BuildVRT`
Parameters
----------
src: str, list, :osgeo:class:`ogr.DataSource` or :osgeo:class:`gdal.Dataset`
the input data set(s)
dst: str
the output data set
options: dict
... | [
"def",
"gdalbuildvrt",
"(",
"src",
",",
"dst",
",",
"options",
"=",
"None",
",",
"void",
"=",
"True",
")",
":",
"options",
"=",
"{",
"}",
"if",
"options",
"is",
"None",
"else",
"options",
"if",
"'outputBounds'",
"in",
"options",
".",
"keys",
"(",
")"... | a simple wrapper for :osgeo:func:`gdal.BuildVRT`
Parameters
----------
src: str, list, :osgeo:class:`ogr.DataSource` or :osgeo:class:`gdal.Dataset`
the input data set(s)
dst: str
the output data set
options: dict
additional parameters passed to gdal.BuildVRT; see :osgeo:func... | [
"a",
"simple",
"wrapper",
"for",
":",
"osgeo",
":",
"func",
":",
"gdal",
".",
"BuildVRT"
] | python | train |
AASHE/python-membersuite-api-client | membersuite_api_client/client.py | https://github.com/AASHE/python-membersuite-api-client/blob/221f5ed8bc7d4424237a4669c5af9edc11819ee9/membersuite_api_client/client.py#L45-L63 | def request_session(self):
"""
Performs initial request to initialize session and get session id
necessary to construct all future requests.
:return: Session ID to be placed in header of all other requests.
"""
concierge_request_header = self.construct_concierge_header(
... | [
"def",
"request_session",
"(",
"self",
")",
":",
"concierge_request_header",
"=",
"self",
".",
"construct_concierge_header",
"(",
"url",
"=",
"\"http://membersuite.com/contracts/IConciergeAPIService/WhoAmI\"",
")",
"result",
"=",
"self",
".",
"client",
".",
"service",
"... | Performs initial request to initialize session and get session id
necessary to construct all future requests.
:return: Session ID to be placed in header of all other requests. | [
"Performs",
"initial",
"request",
"to",
"initialize",
"session",
"and",
"get",
"session",
"id",
"necessary",
"to",
"construct",
"all",
"future",
"requests",
".",
":",
"return",
":",
"Session",
"ID",
"to",
"be",
"placed",
"in",
"header",
"of",
"all",
"other",... | python | train |
notanumber/xapian-haystack | xapian_backend.py | https://github.com/notanumber/xapian-haystack/blob/2247b23d3cb6322ce477d45f84d52da47a940348/xapian_backend.py#L1009-L1101 | def _do_date_facets(results, date_facets):
"""
Private method that facets a document by date ranges
Required arguments:
`results` -- A list SearchResults to facet
`date_facets` -- A dictionary containing facet parameters:
{'field': {'start_date': ..., 'en... | [
"def",
"_do_date_facets",
"(",
"results",
",",
"date_facets",
")",
":",
"def",
"next_datetime",
"(",
"previous",
",",
"gap_value",
",",
"gap_type",
")",
":",
"year",
"=",
"previous",
".",
"year",
"month",
"=",
"previous",
".",
"month",
"if",
"gap_type",
"=... | Private method that facets a document by date ranges
Required arguments:
`results` -- A list SearchResults to facet
`date_facets` -- A dictionary containing facet parameters:
{'field': {'start_date': ..., 'end_date': ...: 'gap_by': '...', 'gap_amount': n}}
... | [
"Private",
"method",
"that",
"facets",
"a",
"document",
"by",
"date",
"ranges"
] | python | train |
LuminosoInsight/luminoso-api-client-python | luminoso_api/v4_client.py | https://github.com/LuminosoInsight/luminoso-api-client-python/blob/3bedf2a454aee39214c11fbf556ead3eecc27881/luminoso_api/v4_client.py#L360-L387 | def change_path(self, path):
"""
Return a new LuminosoClient for a subpath of this one.
For example, you might want to start with a LuminosoClient for
`https://analytics.luminoso.com/api/v4/`, then get a new one for
`https://analytics.luminoso.com/api/v4/projects/myaccount/mypro... | [
"def",
"change_path",
"(",
"self",
",",
"path",
")",
":",
"if",
"path",
".",
"startswith",
"(",
"'/'",
")",
":",
"url",
"=",
"self",
".",
"root_url",
"+",
"path",
"else",
":",
"url",
"=",
"self",
".",
"url",
"+",
"path",
"return",
"self",
".",
"_... | Return a new LuminosoClient for a subpath of this one.
For example, you might want to start with a LuminosoClient for
`https://analytics.luminoso.com/api/v4/`, then get a new one for
`https://analytics.luminoso.com/api/v4/projects/myaccount/myprojectid`.
You accomplish that with the fol... | [
"Return",
"a",
"new",
"LuminosoClient",
"for",
"a",
"subpath",
"of",
"this",
"one",
"."
] | python | test |
saltstack/salt | salt/modules/localemod.py | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/localemod.py#L166-L228 | def set_locale(locale):
'''
Sets the current system locale
CLI Example:
.. code-block:: bash
salt '*' locale.set_locale 'en_US.UTF-8'
'''
lc_ctl = salt.utils.systemd.booted(__context__)
# localectl on SLE12 is installed but the integration is broken -- config is rewritten by YaST2... | [
"def",
"set_locale",
"(",
"locale",
")",
":",
"lc_ctl",
"=",
"salt",
".",
"utils",
".",
"systemd",
".",
"booted",
"(",
"__context__",
")",
"# localectl on SLE12 is installed but the integration is broken -- config is rewritten by YaST2",
"if",
"lc_ctl",
"and",
"not",
"(... | Sets the current system locale
CLI Example:
.. code-block:: bash
salt '*' locale.set_locale 'en_US.UTF-8' | [
"Sets",
"the",
"current",
"system",
"locale"
] | python | train |
WhyNotHugo/django-afip | django_afip/models.py | https://github.com/WhyNotHugo/django-afip/blob/5fb73213f1fe86ca52b501ffd0737911ef26ddb3/django_afip/models.py#L367-L371 | def get_ticket(self, service):
"""Return an existing AuthTicket for a given service."""
return self.auth_tickets \
.filter(expires__gt=datetime.now(timezone.utc), service=service) \
.last() | [
"def",
"get_ticket",
"(",
"self",
",",
"service",
")",
":",
"return",
"self",
".",
"auth_tickets",
".",
"filter",
"(",
"expires__gt",
"=",
"datetime",
".",
"now",
"(",
"timezone",
".",
"utc",
")",
",",
"service",
"=",
"service",
")",
".",
"last",
"(",
... | Return an existing AuthTicket for a given service. | [
"Return",
"an",
"existing",
"AuthTicket",
"for",
"a",
"given",
"service",
"."
] | python | train |
davidwtbuxton/notrequests | notrequests.py | https://github.com/davidwtbuxton/notrequests/blob/e48ee6107a58c2f373c33f78e3302608edeba7f3/notrequests.py#L193-L209 | def detect_encoding(value):
"""Returns the character encoding for a JSON string."""
# https://tools.ietf.org/html/rfc4627#section-3
if six.PY2:
null_pattern = tuple(bool(ord(char)) for char in value[:4])
else:
null_pattern = tuple(bool(char) for char in value[:4])
encodings = {
... | [
"def",
"detect_encoding",
"(",
"value",
")",
":",
"# https://tools.ietf.org/html/rfc4627#section-3",
"if",
"six",
".",
"PY2",
":",
"null_pattern",
"=",
"tuple",
"(",
"bool",
"(",
"ord",
"(",
"char",
")",
")",
"for",
"char",
"in",
"value",
"[",
":",
"4",
"]... | Returns the character encoding for a JSON string. | [
"Returns",
"the",
"character",
"encoding",
"for",
"a",
"JSON",
"string",
"."
] | python | train |
tensorflow/tensor2tensor | tensor2tensor/layers/common_attention.py | https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/layers/common_attention.py#L4302-L4365 | def multihead_attention_2d(query_antecedent,
memory_antecedent,
total_key_depth,
total_value_depth,
output_depth,
num_heads,
attention_type="local_attention_2... | [
"def",
"multihead_attention_2d",
"(",
"query_antecedent",
",",
"memory_antecedent",
",",
"total_key_depth",
",",
"total_value_depth",
",",
"output_depth",
",",
"num_heads",
",",
"attention_type",
"=",
"\"local_attention_2d\"",
",",
"query_shape",
"=",
"(",
"8",
",",
"... | 2d Multihead scaled-dot-product attention with inp/output transformations.
Args:
query_antecedent: a Tensor with shape [batch, h, w, depth_k]
memory_antecedent: a Tensor with shape [batch, h, w, depth_k]
total_key_depth: an integer
total_value_depth: an integer
output_depth: an integer
num_he... | [
"2d",
"Multihead",
"scaled",
"-",
"dot",
"-",
"product",
"attention",
"with",
"inp",
"/",
"output",
"transformations",
"."
] | python | train |
Alignak-monitoring-contrib/alignak-backend-client | alignak_backend_client/client.py | https://github.com/Alignak-monitoring-contrib/alignak-backend-client/blob/1e21f6ce703e66984d1f9b20fe7866460ab50b39/alignak_backend_client/client.py#L674-L694 | def delete(self, endpoint, headers):
"""
Method to delete an item or all items
headers['If-Match'] must contain the _etag identifier of the element to delete
:param endpoint: endpoint (API URL)
:type endpoint: str
:param headers: headers (example: Content-Type)
... | [
"def",
"delete",
"(",
"self",
",",
"endpoint",
",",
"headers",
")",
":",
"response",
"=",
"self",
".",
"get_response",
"(",
"method",
"=",
"'DELETE'",
",",
"endpoint",
"=",
"endpoint",
",",
"headers",
"=",
"headers",
")",
"logger",
".",
"debug",
"(",
"... | Method to delete an item or all items
headers['If-Match'] must contain the _etag identifier of the element to delete
:param endpoint: endpoint (API URL)
:type endpoint: str
:param headers: headers (example: Content-Type)
:type headers: dict
:return: response (deletion i... | [
"Method",
"to",
"delete",
"an",
"item",
"or",
"all",
"items"
] | python | test |
dwavesystems/dwave_networkx | dwave_networkx/algorithms/tsp.py | https://github.com/dwavesystems/dwave_networkx/blob/9ea1223ddbc7e86db2f90b8b23e250e6642c3d68/dwave_networkx/algorithms/tsp.py#L30-L107 | def traveling_salesman(G, sampler=None, lagrange=2, weight='weight',
**sampler_args):
"""Returns an approximate minimum traveling salesperson route.
Defines a QUBO with ground states corresponding to the
minimum routes and uses the sampler to sample
from it.
A route is a cyc... | [
"def",
"traveling_salesman",
"(",
"G",
",",
"sampler",
"=",
"None",
",",
"lagrange",
"=",
"2",
",",
"weight",
"=",
"'weight'",
",",
"*",
"*",
"sampler_args",
")",
":",
"# Get a QUBO representation of the problem",
"Q",
"=",
"traveling_salesman_qubo",
"(",
"G",
... | Returns an approximate minimum traveling salesperson route.
Defines a QUBO with ground states corresponding to the
minimum routes and uses the sampler to sample
from it.
A route is a cycle in the graph that reaches each node exactly once.
A minimum route is a route with the smallest total edge wei... | [
"Returns",
"an",
"approximate",
"minimum",
"traveling",
"salesperson",
"route",
"."
] | python | train |
opendatateam/udata | udata/core/dataset/rdf.py | https://github.com/opendatateam/udata/blob/f016585af94b0ff6bd73738c700324adc8ba7f8f/udata/core/dataset/rdf.py#L164-L214 | def dataset_to_rdf(dataset, graph=None):
'''
Map a dataset domain model to a DCAT/RDF graph
'''
# Use the unlocalized permalink to the dataset as URI when available
# unless there is already an upstream URI
if 'uri' in dataset.extras:
id = URIRef(dataset.extras['uri'])
elif dataset.i... | [
"def",
"dataset_to_rdf",
"(",
"dataset",
",",
"graph",
"=",
"None",
")",
":",
"# Use the unlocalized permalink to the dataset as URI when available",
"# unless there is already an upstream URI",
"if",
"'uri'",
"in",
"dataset",
".",
"extras",
":",
"id",
"=",
"URIRef",
"(",... | Map a dataset domain model to a DCAT/RDF graph | [
"Map",
"a",
"dataset",
"domain",
"model",
"to",
"a",
"DCAT",
"/",
"RDF",
"graph"
] | python | train |
keunwoochoi/kapre | kapre/backend_keras.py | https://github.com/keunwoochoi/kapre/blob/8517f45d3ccb9fff1ec0049b9c3e4389f81c20aa/kapre/backend_keras.py#L7-L25 | def amplitude_to_decibel(x, amin=1e-10, dynamic_range=80.0):
"""[K] Convert (linear) amplitude to decibel (log10(x)).
x: Keras *batch* tensor or variable. It has to be batch because of sample-wise `K.max()`.
amin: minimum amplitude. amplitude smaller than `amin` is set to this.
dynamic_range: dynamic... | [
"def",
"amplitude_to_decibel",
"(",
"x",
",",
"amin",
"=",
"1e-10",
",",
"dynamic_range",
"=",
"80.0",
")",
":",
"log_spec",
"=",
"10",
"*",
"K",
".",
"log",
"(",
"K",
".",
"maximum",
"(",
"x",
",",
"amin",
")",
")",
"/",
"np",
".",
"log",
"(",
... | [K] Convert (linear) amplitude to decibel (log10(x)).
x: Keras *batch* tensor or variable. It has to be batch because of sample-wise `K.max()`.
amin: minimum amplitude. amplitude smaller than `amin` is set to this.
dynamic_range: dynamic_range in decibel | [
"[",
"K",
"]",
"Convert",
"(",
"linear",
")",
"amplitude",
"to",
"decibel",
"(",
"log10",
"(",
"x",
"))",
"."
] | python | train |
elsampsa/valkka-live | valkka/live/filterchain.py | https://github.com/elsampsa/valkka-live/blob/218bb2ecf71c516c85b1b6e075454bba13090cd8/valkka/live/filterchain.py#L229-L244 | def getDevice(self, **kwargs):
"""Like get, but returns a Device instance (RTSPCameraDevice, etc.)
"""
filterchain = self.get(**kwargs)
if not filterchain:
return None
# get filterchain init parameters that are compatible with RTSPCameraDevice input... | [
"def",
"getDevice",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"filterchain",
"=",
"self",
".",
"get",
"(",
"*",
"*",
"kwargs",
")",
"if",
"not",
"filterchain",
":",
"return",
"None",
"# get filterchain init parameters that are compatible with RTSPCameraDevic... | Like get, but returns a Device instance (RTSPCameraDevice, etc.) | [
"Like",
"get",
"but",
"returns",
"a",
"Device",
"instance",
"(",
"RTSPCameraDevice",
"etc",
".",
")"
] | python | train |
watson-developer-cloud/python-sdk | ibm_watson/discovery_v1.py | https://github.com/watson-developer-cloud/python-sdk/blob/4c2c9df4466fcde88975da9ecd834e6ba95eb353/ibm_watson/discovery_v1.py#L12146-L12151 | def _to_dict(self):
"""Return a json dictionary representing this model."""
_dict = {}
if hasattr(self, 'xpaths') and self.xpaths is not None:
_dict['xpaths'] = self.xpaths
return _dict | [
"def",
"_to_dict",
"(",
"self",
")",
":",
"_dict",
"=",
"{",
"}",
"if",
"hasattr",
"(",
"self",
",",
"'xpaths'",
")",
"and",
"self",
".",
"xpaths",
"is",
"not",
"None",
":",
"_dict",
"[",
"'xpaths'",
"]",
"=",
"self",
".",
"xpaths",
"return",
"_dic... | Return a json dictionary representing this model. | [
"Return",
"a",
"json",
"dictionary",
"representing",
"this",
"model",
"."
] | python | train |
monarch-initiative/dipper | dipper/sources/OMIA.py | https://github.com/monarch-initiative/dipper/blob/24cc80db355bbe15776edc5c7b41e0886959ba41/dipper/sources/OMIA.py#L236-L304 | def find_omim_type(self):
'''
This f(x) needs to be rehomed and shared.
Use OMIM's discription of their identifiers
to heuristically partition them into genes | phenotypes-diseases
type could be
- `obsolete` Check `omim_replaced` populated as side effect
... | [
"def",
"find_omim_type",
"(",
"self",
")",
":",
"src_key",
"=",
"'mimtitles'",
"myfile",
"=",
"'/'",
".",
"join",
"(",
"(",
"self",
".",
"rawdir",
",",
"self",
".",
"files",
"[",
"src_key",
"]",
"[",
"'file'",
"]",
")",
")",
"# col = self.files[src_key][... | This f(x) needs to be rehomed and shared.
Use OMIM's discription of their identifiers
to heuristically partition them into genes | phenotypes-diseases
type could be
- `obsolete` Check `omim_replaced` populated as side effect
- 'Suspected' (phenotype) Ignoring thus far
... | [
"This",
"f",
"(",
"x",
")",
"needs",
"to",
"be",
"rehomed",
"and",
"shared",
".",
"Use",
"OMIM",
"s",
"discription",
"of",
"their",
"identifiers",
"to",
"heuristically",
"partition",
"them",
"into",
"genes",
"|",
"phenotypes",
"-",
"diseases",
"type",
"cou... | python | train |
mastro35/flows | flows/Actions/Action.py | https://github.com/mastro35/flows/blob/05e488385673a69597b5b39c7728795aa4d5eb18/flows/Actions/Action.py#L107-L121 | def send_message(self, output):
"""
Send a message to the socket
"""
file_system_event = None
if self.my_action_input:
file_system_event = self.my_action_input.file_system_event or None
output_action = ActionInput(file_system_event,
... | [
"def",
"send_message",
"(",
"self",
",",
"output",
")",
":",
"file_system_event",
"=",
"None",
"if",
"self",
".",
"my_action_input",
":",
"file_system_event",
"=",
"self",
".",
"my_action_input",
".",
"file_system_event",
"or",
"None",
"output_action",
"=",
"Act... | Send a message to the socket | [
"Send",
"a",
"message",
"to",
"the",
"socket"
] | python | train |
cloud9ers/gurumate | environment/lib/python2.7/site-packages/IPython/frontend/qt/console/console_widget.py | https://github.com/cloud9ers/gurumate/blob/075dc74d1ee62a8c6b7a8bf2b271364f01629d1e/environment/lib/python2.7/site-packages/IPython/frontend/qt/console/console_widget.py#L514-L520 | def cut(self):
""" Copy the currently selected text to the clipboard and delete it
if it's inside the input buffer.
"""
self.copy()
if self.can_cut():
self._control.textCursor().removeSelectedText() | [
"def",
"cut",
"(",
"self",
")",
":",
"self",
".",
"copy",
"(",
")",
"if",
"self",
".",
"can_cut",
"(",
")",
":",
"self",
".",
"_control",
".",
"textCursor",
"(",
")",
".",
"removeSelectedText",
"(",
")"
] | Copy the currently selected text to the clipboard and delete it
if it's inside the input buffer. | [
"Copy",
"the",
"currently",
"selected",
"text",
"to",
"the",
"clipboard",
"and",
"delete",
"it",
"if",
"it",
"s",
"inside",
"the",
"input",
"buffer",
"."
] | python | test |
materialsvirtuallab/monty | monty/dev.py | https://github.com/materialsvirtuallab/monty/blob/d99d6f3c68372d83489d28ff515566c93cd569e2/monty/dev.py#L97-L195 | def get_ncpus():
"""
.. note::
If you are using Python >= 2.7, multiprocessing.cpu_count() already
provides the number of CPUs. In fact, this is the first method tried.
The purpose of this function is to cater to old Python versions that
still exist on many Linux style clusters.... | [
"def",
"get_ncpus",
"(",
")",
":",
"# Python 2.6+",
"# May raise NonImplementedError",
"try",
":",
"return",
"multiprocessing",
".",
"cpu_count",
"(",
")",
"except",
"(",
"ImportError",
",",
"NotImplementedError",
")",
":",
"pass",
"# POSIX",
"try",
":",
"res",
... | .. note::
If you are using Python >= 2.7, multiprocessing.cpu_count() already
provides the number of CPUs. In fact, this is the first method tried.
The purpose of this function is to cater to old Python versions that
still exist on many Linux style clusters.
Number of virtual or ph... | [
"..",
"note",
"::"
] | python | train |
kata198/AdvancedHTMLParser | AdvancedHTMLParser/Tags.py | https://github.com/kata198/AdvancedHTMLParser/blob/06aeea5d8e2ea86e155aae0fc237623d3e9b7f9d/AdvancedHTMLParser/Tags.py#L2267-L2283 | def filterCollection(self, filterFunc):
'''
filterCollection - Filters only the immediate objects contained within this Collection against a function, not including any children
@param filterFunc <function> - A function or lambda expression that returns True to have that element match
... | [
"def",
"filterCollection",
"(",
"self",
",",
"filterFunc",
")",
":",
"ret",
"=",
"TagCollection",
"(",
")",
"if",
"len",
"(",
"self",
")",
"==",
"0",
":",
"return",
"ret",
"for",
"tag",
"in",
"self",
":",
"if",
"filterFunc",
"(",
"tag",
")",
"is",
... | filterCollection - Filters only the immediate objects contained within this Collection against a function, not including any children
@param filterFunc <function> - A function or lambda expression that returns True to have that element match
@return TagCollection<AdvancedTag> | [
"filterCollection",
"-",
"Filters",
"only",
"the",
"immediate",
"objects",
"contained",
"within",
"this",
"Collection",
"against",
"a",
"function",
"not",
"including",
"any",
"children"
] | python | train |
slawek87/yql-finance | examples/stock_price.py | https://github.com/slawek87/yql-finance/blob/52b1ac6720db09c4d8a9864b171506e90a8d3964/examples/stock_price.py#L17-L27 | def fetch_googl():
"""Returns stock prices for Google company."""
yql = YQL('GOOGL', '2014-01-01', '2014-01-10')
for item in yql:
print item.get('date'), item.get('price')
yql.select('GOOGL', '2014-01-01', '2014-01-10')
for item in yql:
print item.get('date'), item.get('price') | [
"def",
"fetch_googl",
"(",
")",
":",
"yql",
"=",
"YQL",
"(",
"'GOOGL'",
",",
"'2014-01-01'",
",",
"'2014-01-10'",
")",
"for",
"item",
"in",
"yql",
":",
"print",
"item",
".",
"get",
"(",
"'date'",
")",
",",
"item",
".",
"get",
"(",
"'price'",
")",
"... | Returns stock prices for Google company. | [
"Returns",
"stock",
"prices",
"for",
"Google",
"company",
"."
] | python | train |
cmbruns/pyopenvr | src/openvr/glframework/__init__.py | https://github.com/cmbruns/pyopenvr/blob/68395d26bb3df6ab1f0f059c38d441f962938be6/src/openvr/glframework/__init__.py#L26-L41 | def shader_substring(body, stack_frame=1):
"""
Call this method from a function that defines a literal shader string as the "body" argument.
Dresses up a shader string in two ways:
1) Insert #line number declaration
2) un-indents
The line number information can help debug glsl comp... | [
"def",
"shader_substring",
"(",
"body",
",",
"stack_frame",
"=",
"1",
")",
":",
"line_count",
"=",
"len",
"(",
"body",
".",
"splitlines",
"(",
"True",
")",
")",
"line_number",
"=",
"inspect",
".",
"stack",
"(",
")",
"[",
"stack_frame",
"]",
"[",
"2",
... | Call this method from a function that defines a literal shader string as the "body" argument.
Dresses up a shader string in two ways:
1) Insert #line number declaration
2) un-indents
The line number information can help debug glsl compile errors.
The unindenting allows you to type the s... | [
"Call",
"this",
"method",
"from",
"a",
"function",
"that",
"defines",
"a",
"literal",
"shader",
"string",
"as",
"the",
"body",
"argument",
".",
"Dresses",
"up",
"a",
"shader",
"string",
"in",
"two",
"ways",
":",
"1",
")",
"Insert",
"#line",
"number",
"de... | python | train |
awacha/sastool | sastool/fitting/fitfunctions/sasbasic.py | https://github.com/awacha/sastool/blob/deaddfa3002f3f6818697e36139633b7e30427a3/sastool/fitting/fitfunctions/sasbasic.py#L157-L182 | def GuinierPorodGuinier(q, G, Rg1, alpha, Rg2):
"""Empirical Guinier-Porod-Guinier scattering
Inputs:
-------
``q``: independent variable
``G``: factor for the first Guinier-branch
``Rg1``: the first radius of gyration
``alpha``: the power-law exponent
``Rg2``: the s... | [
"def",
"GuinierPorodGuinier",
"(",
"q",
",",
"G",
",",
"Rg1",
",",
"alpha",
",",
"Rg2",
")",
":",
"return",
"GuinierPorodMulti",
"(",
"q",
",",
"G",
",",
"Rg1",
",",
"alpha",
",",
"Rg2",
")"
] | Empirical Guinier-Porod-Guinier scattering
Inputs:
-------
``q``: independent variable
``G``: factor for the first Guinier-branch
``Rg1``: the first radius of gyration
``alpha``: the power-law exponent
``Rg2``: the second radius of gyration
Formula:
--------
... | [
"Empirical",
"Guinier",
"-",
"Porod",
"-",
"Guinier",
"scattering"
] | python | train |
eugene-eeo/graphlite | graphlite/query.py | https://github.com/eugene-eeo/graphlite/blob/8d17e9549ee8610570dcde1b427431a2584395b7/graphlite/query.py#L43-L50 | def gen_query(self):
"""
Generate an SQL query for the edge object.
"""
return (
SQL.forwards_relation(self.src, self.rel) if self.dst is None else
SQL.inverse_relation(self.dst, self.rel)
) | [
"def",
"gen_query",
"(",
"self",
")",
":",
"return",
"(",
"SQL",
".",
"forwards_relation",
"(",
"self",
".",
"src",
",",
"self",
".",
"rel",
")",
"if",
"self",
".",
"dst",
"is",
"None",
"else",
"SQL",
".",
"inverse_relation",
"(",
"self",
".",
"dst",... | Generate an SQL query for the edge object. | [
"Generate",
"an",
"SQL",
"query",
"for",
"the",
"edge",
"object",
"."
] | python | train |
nerdvegas/rez | src/rez/vendor/memcache/memcache.py | https://github.com/nerdvegas/rez/blob/1d3b846d53b5b5404edfe8ddb9083f9ceec8c5e7/src/rez/vendor/memcache/memcache.py#L550-L559 | def replace(self, key, val, time=0, min_compress_len=0):
'''Replace existing key with value.
Like L{set}, but only stores in memcache if the key already exists.
The opposite of L{add}.
@return: Nonzero on success.
@rtype: int
'''
return self._set("replace", key,... | [
"def",
"replace",
"(",
"self",
",",
"key",
",",
"val",
",",
"time",
"=",
"0",
",",
"min_compress_len",
"=",
"0",
")",
":",
"return",
"self",
".",
"_set",
"(",
"\"replace\"",
",",
"key",
",",
"val",
",",
"time",
",",
"min_compress_len",
")"
] | Replace existing key with value.
Like L{set}, but only stores in memcache if the key already exists.
The opposite of L{add}.
@return: Nonzero on success.
@rtype: int | [
"Replace",
"existing",
"key",
"with",
"value",
"."
] | python | train |
materialsproject/pymatgen | pymatgen/analysis/pourbaix_diagram.py | https://github.com/materialsproject/pymatgen/blob/4ca558cf72f8d5f8a1f21dfdfc0181a971c186da/pymatgen/analysis/pourbaix_diagram.py#L338-L342 | def from_dict(cls, d):
"""
Returns an IonEntry object from a dict.
"""
return IonEntry(Ion.from_dict(d["ion"]), d["energy"], d.get("name", None)) | [
"def",
"from_dict",
"(",
"cls",
",",
"d",
")",
":",
"return",
"IonEntry",
"(",
"Ion",
".",
"from_dict",
"(",
"d",
"[",
"\"ion\"",
"]",
")",
",",
"d",
"[",
"\"energy\"",
"]",
",",
"d",
".",
"get",
"(",
"\"name\"",
",",
"None",
")",
")"
] | Returns an IonEntry object from a dict. | [
"Returns",
"an",
"IonEntry",
"object",
"from",
"a",
"dict",
"."
] | python | train |
s0md3v/Photon | core/utils.py | https://github.com/s0md3v/Photon/blob/6a29f2c9782ea9b3dc090db1774a259033600e39/core/utils.py#L15-L23 | def regxy(pattern, response, supress_regex, custom):
"""Extract a string based on regex pattern supplied by user."""
try:
matches = re.findall(r'%s' % pattern, response)
for match in matches:
verb('Custom regex', match)
custom.add(match)
except:
supress_regex ... | [
"def",
"regxy",
"(",
"pattern",
",",
"response",
",",
"supress_regex",
",",
"custom",
")",
":",
"try",
":",
"matches",
"=",
"re",
".",
"findall",
"(",
"r'%s'",
"%",
"pattern",
",",
"response",
")",
"for",
"match",
"in",
"matches",
":",
"verb",
"(",
"... | Extract a string based on regex pattern supplied by user. | [
"Extract",
"a",
"string",
"based",
"on",
"regex",
"pattern",
"supplied",
"by",
"user",
"."
] | python | train |
mattupstate/flask-security | flask_security/views.py | https://github.com/mattupstate/flask-security/blob/a401fb47018fbbbe0b899ea55afadfd0e3cd847a/flask_security/views.py#L187-L210 | def send_confirmation():
"""View function which sends confirmation instructions."""
form_class = _security.send_confirmation_form
if request.is_json:
form = form_class(MultiDict(request.get_json()))
else:
form = form_class()
if form.validate_on_submit():
send_confirmation_... | [
"def",
"send_confirmation",
"(",
")",
":",
"form_class",
"=",
"_security",
".",
"send_confirmation_form",
"if",
"request",
".",
"is_json",
":",
"form",
"=",
"form_class",
"(",
"MultiDict",
"(",
"request",
".",
"get_json",
"(",
")",
")",
")",
"else",
":",
"... | View function which sends confirmation instructions. | [
"View",
"function",
"which",
"sends",
"confirmation",
"instructions",
"."
] | python | train |
oscarbranson/latools | latools/latools.py | https://github.com/oscarbranson/latools/blob/cd25a650cfee318152f234d992708511f7047fbe/latools/latools.py#L2308-L2347 | def correlation_plots(self, x_analyte, y_analyte, window=15, filt=True, recalc=False, samples=None, subset=None, outdir=None):
"""
Plot the local correlation between two analytes.
Parameters
----------
x_analyte, y_analyte : str
The names of the x and y analytes to c... | [
"def",
"correlation_plots",
"(",
"self",
",",
"x_analyte",
",",
"y_analyte",
",",
"window",
"=",
"15",
",",
"filt",
"=",
"True",
",",
"recalc",
"=",
"False",
",",
"samples",
"=",
"None",
",",
"subset",
"=",
"None",
",",
"outdir",
"=",
"None",
")",
":... | Plot the local correlation between two analytes.
Parameters
----------
x_analyte, y_analyte : str
The names of the x and y analytes to correlate.
window : int, None
The rolling window used when calculating the correlation.
filt : bool
Whether ... | [
"Plot",
"the",
"local",
"correlation",
"between",
"two",
"analytes",
"."
] | python | test |
openpermissions/perch | perch/model.py | https://github.com/openpermissions/perch/blob/36d78994133918f3c52c187f19e50132960a0156/perch/model.py#L469-L479 | def get_parent(self):
"""
Get the parent resource from the database
The get, create & update methods will populate the parent for you. Use
this method in the cases where parent has not been populated.
"""
if not self._parent:
self._parent = yield self.parent_... | [
"def",
"get_parent",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"_parent",
":",
"self",
".",
"_parent",
"=",
"yield",
"self",
".",
"parent_resource",
".",
"get",
"(",
"self",
".",
"parent_id",
")",
"raise",
"Return",
"(",
"self",
".",
"_parent",
... | Get the parent resource from the database
The get, create & update methods will populate the parent for you. Use
this method in the cases where parent has not been populated. | [
"Get",
"the",
"parent",
"resource",
"from",
"the",
"database"
] | python | train |
wummel/linkchecker | third_party/dnspython/dns/tokenizer.py | https://github.com/wummel/linkchecker/blob/c2ce810c3fb00b895a841a7be6b2e78c64e7b042/third_party/dnspython/dns/tokenizer.py#L522-L531 | def get_name(self, origin=None):
"""Read the next token and interpret it as a DNS name.
@raises dns.exception.SyntaxError:
@rtype: dns.name.Name object"""
token = self.get()
if not token.is_identifier():
raise dns.exception.SyntaxError('expecting an identifier')
... | [
"def",
"get_name",
"(",
"self",
",",
"origin",
"=",
"None",
")",
":",
"token",
"=",
"self",
".",
"get",
"(",
")",
"if",
"not",
"token",
".",
"is_identifier",
"(",
")",
":",
"raise",
"dns",
".",
"exception",
".",
"SyntaxError",
"(",
"'expecting an ident... | Read the next token and interpret it as a DNS name.
@raises dns.exception.SyntaxError:
@rtype: dns.name.Name object | [
"Read",
"the",
"next",
"token",
"and",
"interpret",
"it",
"as",
"a",
"DNS",
"name",
"."
] | python | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.