repo stringlengths 7 55 | path stringlengths 4 127 | func_name stringlengths 1 88 | original_string stringlengths 75 19.8k | language stringclasses 1
value | code stringlengths 75 19.8k | code_tokens listlengths 20 707 | docstring stringlengths 3 17.3k | docstring_tokens listlengths 3 222 | sha stringlengths 40 40 | url stringlengths 87 242 | partition stringclasses 1
value | idx int64 0 252k |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
UDST/orca | orca/orca.py | add_injectable | def add_injectable(
name, value, autocall=True, cache=False, cache_scope=_CS_FOREVER,
memoize=False):
"""
Add a value that will be injected into other functions.
Parameters
----------
name : str
value
If a callable and `autocall` is True then the function's
argum... | python | def add_injectable(
name, value, autocall=True, cache=False, cache_scope=_CS_FOREVER,
memoize=False):
"""
Add a value that will be injected into other functions.
Parameters
----------
name : str
value
If a callable and `autocall` is True then the function's
argum... | [
"def",
"add_injectable",
"(",
"name",
",",
"value",
",",
"autocall",
"=",
"True",
",",
"cache",
"=",
"False",
",",
"cache_scope",
"=",
"_CS_FOREVER",
",",
"memoize",
"=",
"False",
")",
":",
"if",
"isinstance",
"(",
"value",
",",
"Callable",
")",
":",
"... | Add a value that will be injected into other functions.
Parameters
----------
name : str
value
If a callable and `autocall` is True then the function's
argument names and keyword argument values will be matched
to registered variables when the function needs to be
evalua... | [
"Add",
"a",
"value",
"that",
"will",
"be",
"injected",
"into",
"other",
"functions",
"."
] | 07b34aeef13cc87c966b2e30cbe7e76cc9d3622c | https://github.com/UDST/orca/blob/07b34aeef13cc87c966b2e30cbe7e76cc9d3622c/orca/orca.py#L1307-L1353 | train | 62,200 |
UDST/orca | orca/orca.py | injectable | def injectable(
name=None, autocall=True, cache=False, cache_scope=_CS_FOREVER,
memoize=False):
"""
Decorates functions that will be injected into other functions.
Decorator version of `add_injectable`. Name defaults to
name of function.
The function's argument names and keyword ar... | python | def injectable(
name=None, autocall=True, cache=False, cache_scope=_CS_FOREVER,
memoize=False):
"""
Decorates functions that will be injected into other functions.
Decorator version of `add_injectable`. Name defaults to
name of function.
The function's argument names and keyword ar... | [
"def",
"injectable",
"(",
"name",
"=",
"None",
",",
"autocall",
"=",
"True",
",",
"cache",
"=",
"False",
",",
"cache_scope",
"=",
"_CS_FOREVER",
",",
"memoize",
"=",
"False",
")",
":",
"def",
"decorator",
"(",
"func",
")",
":",
"if",
"name",
":",
"n"... | Decorates functions that will be injected into other functions.
Decorator version of `add_injectable`. Name defaults to
name of function.
The function's argument names and keyword argument values
will be matched to registered variables when the function
needs to be evaluated by Orca.
The argum... | [
"Decorates",
"functions",
"that",
"will",
"be",
"injected",
"into",
"other",
"functions",
"."
] | 07b34aeef13cc87c966b2e30cbe7e76cc9d3622c | https://github.com/UDST/orca/blob/07b34aeef13cc87c966b2e30cbe7e76cc9d3622c/orca/orca.py#L1356-L1381 | train | 62,201 |
UDST/orca | orca/orca.py | get_injectable_func_source_data | def get_injectable_func_source_data(name):
"""
Return data about an injectable function's source, including file name,
line number, and source code.
Parameters
----------
name : str
Returns
-------
filename : str
lineno : int
The line number on which the function starts... | python | def get_injectable_func_source_data(name):
"""
Return data about an injectable function's source, including file name,
line number, and source code.
Parameters
----------
name : str
Returns
-------
filename : str
lineno : int
The line number on which the function starts... | [
"def",
"get_injectable_func_source_data",
"(",
"name",
")",
":",
"if",
"injectable_type",
"(",
"name",
")",
"!=",
"'function'",
":",
"raise",
"ValueError",
"(",
"'injectable {!r} is not a function'",
".",
"format",
"(",
"name",
")",
")",
"inj",
"=",
"get_raw_injec... | Return data about an injectable function's source, including file name,
line number, and source code.
Parameters
----------
name : str
Returns
-------
filename : str
lineno : int
The line number on which the function starts.
source : str | [
"Return",
"data",
"about",
"an",
"injectable",
"function",
"s",
"source",
"including",
"file",
"name",
"line",
"number",
"and",
"source",
"code",
"."
] | 07b34aeef13cc87c966b2e30cbe7e76cc9d3622c | https://github.com/UDST/orca/blob/07b34aeef13cc87c966b2e30cbe7e76cc9d3622c/orca/orca.py#L1452-L1479 | train | 62,202 |
UDST/orca | orca/orca.py | add_step | def add_step(step_name, func):
"""
Add a step function to Orca.
The function's argument names and keyword argument values
will be matched to registered variables when the function
needs to be evaluated by Orca.
The argument name "iter_var" may be used to have the current
iteration variable ... | python | def add_step(step_name, func):
"""
Add a step function to Orca.
The function's argument names and keyword argument values
will be matched to registered variables when the function
needs to be evaluated by Orca.
The argument name "iter_var" may be used to have the current
iteration variable ... | [
"def",
"add_step",
"(",
"step_name",
",",
"func",
")",
":",
"if",
"isinstance",
"(",
"func",
",",
"Callable",
")",
":",
"logger",
".",
"debug",
"(",
"'registering step {!r}'",
".",
"format",
"(",
"step_name",
")",
")",
"_STEPS",
"[",
"step_name",
"]",
"=... | Add a step function to Orca.
The function's argument names and keyword argument values
will be matched to registered variables when the function
needs to be evaluated by Orca.
The argument name "iter_var" may be used to have the current
iteration variable injected.
Parameters
----------
... | [
"Add",
"a",
"step",
"function",
"to",
"Orca",
"."
] | 07b34aeef13cc87c966b2e30cbe7e76cc9d3622c | https://github.com/UDST/orca/blob/07b34aeef13cc87c966b2e30cbe7e76cc9d3622c/orca/orca.py#L1482-L1502 | train | 62,203 |
UDST/orca | orca/orca.py | step | def step(step_name=None):
"""
Decorates functions that will be called by the `run` function.
Decorator version of `add_step`. step name defaults to
name of function.
The function's argument names and keyword argument values
will be matched to registered variables when the function
needs to... | python | def step(step_name=None):
"""
Decorates functions that will be called by the `run` function.
Decorator version of `add_step`. step name defaults to
name of function.
The function's argument names and keyword argument values
will be matched to registered variables when the function
needs to... | [
"def",
"step",
"(",
"step_name",
"=",
"None",
")",
":",
"def",
"decorator",
"(",
"func",
")",
":",
"if",
"step_name",
":",
"name",
"=",
"step_name",
"else",
":",
"name",
"=",
"func",
".",
"__name__",
"add_step",
"(",
"name",
",",
"func",
")",
"return... | Decorates functions that will be called by the `run` function.
Decorator version of `add_step`. step name defaults to
name of function.
The function's argument names and keyword argument values
will be matched to registered variables when the function
needs to be evaluated by Orca.
The argumen... | [
"Decorates",
"functions",
"that",
"will",
"be",
"called",
"by",
"the",
"run",
"function",
"."
] | 07b34aeef13cc87c966b2e30cbe7e76cc9d3622c | https://github.com/UDST/orca/blob/07b34aeef13cc87c966b2e30cbe7e76cc9d3622c/orca/orca.py#L1505-L1526 | train | 62,204 |
UDST/orca | orca/orca.py | broadcast | def broadcast(cast, onto, cast_on=None, onto_on=None,
cast_index=False, onto_index=False):
"""
Register a rule for merging two tables by broadcasting one onto
the other.
Parameters
----------
cast, onto : str
Names of registered tables.
cast_on, onto_on : str, optional... | python | def broadcast(cast, onto, cast_on=None, onto_on=None,
cast_index=False, onto_index=False):
"""
Register a rule for merging two tables by broadcasting one onto
the other.
Parameters
----------
cast, onto : str
Names of registered tables.
cast_on, onto_on : str, optional... | [
"def",
"broadcast",
"(",
"cast",
",",
"onto",
",",
"cast_on",
"=",
"None",
",",
"onto_on",
"=",
"None",
",",
"cast_index",
"=",
"False",
",",
"onto_index",
"=",
"False",
")",
":",
"logger",
".",
"debug",
"(",
"'registering broadcast of table {!r} onto {!r}'",
... | Register a rule for merging two tables by broadcasting one onto
the other.
Parameters
----------
cast, onto : str
Names of registered tables.
cast_on, onto_on : str, optional
Column names used for merge, equivalent of ``left_on``/``right_on``
parameters of pandas.merge.
... | [
"Register",
"a",
"rule",
"for",
"merging",
"two",
"tables",
"by",
"broadcasting",
"one",
"onto",
"the",
"other",
"."
] | 07b34aeef13cc87c966b2e30cbe7e76cc9d3622c | https://github.com/UDST/orca/blob/07b34aeef13cc87c966b2e30cbe7e76cc9d3622c/orca/orca.py#L1556-L1577 | train | 62,205 |
UDST/orca | orca/orca.py | _get_broadcasts | def _get_broadcasts(tables):
"""
Get the broadcasts associated with a set of tables.
Parameters
----------
tables : sequence of str
Table names for which broadcasts have been registered.
Returns
-------
casts : dict of `Broadcast`
Keys are tuples of strings like (cast_n... | python | def _get_broadcasts(tables):
"""
Get the broadcasts associated with a set of tables.
Parameters
----------
tables : sequence of str
Table names for which broadcasts have been registered.
Returns
-------
casts : dict of `Broadcast`
Keys are tuples of strings like (cast_n... | [
"def",
"_get_broadcasts",
"(",
"tables",
")",
":",
"tables",
"=",
"set",
"(",
"tables",
")",
"casts",
"=",
"tz",
".",
"keyfilter",
"(",
"lambda",
"x",
":",
"x",
"[",
"0",
"]",
"in",
"tables",
"and",
"x",
"[",
"1",
"]",
"in",
"tables",
",",
"_BROA... | Get the broadcasts associated with a set of tables.
Parameters
----------
tables : sequence of str
Table names for which broadcasts have been registered.
Returns
-------
casts : dict of `Broadcast`
Keys are tuples of strings like (cast_name, onto_name). | [
"Get",
"the",
"broadcasts",
"associated",
"with",
"a",
"set",
"of",
"tables",
"."
] | 07b34aeef13cc87c966b2e30cbe7e76cc9d3622c | https://github.com/UDST/orca/blob/07b34aeef13cc87c966b2e30cbe7e76cc9d3622c/orca/orca.py#L1580-L1600 | train | 62,206 |
UDST/orca | orca/orca.py | get_broadcast | def get_broadcast(cast_name, onto_name):
"""
Get a single broadcast.
Broadcasts are stored data about how to do a Pandas join.
A Broadcast object is a namedtuple with these attributes:
- cast: the name of the table being broadcast
- onto: the name of the table onto which "cast" is broa... | python | def get_broadcast(cast_name, onto_name):
"""
Get a single broadcast.
Broadcasts are stored data about how to do a Pandas join.
A Broadcast object is a namedtuple with these attributes:
- cast: the name of the table being broadcast
- onto: the name of the table onto which "cast" is broa... | [
"def",
"get_broadcast",
"(",
"cast_name",
",",
"onto_name",
")",
":",
"if",
"is_broadcast",
"(",
"cast_name",
",",
"onto_name",
")",
":",
"return",
"_BROADCASTS",
"[",
"(",
"cast_name",
",",
"onto_name",
")",
"]",
"else",
":",
"raise",
"KeyError",
"(",
"'n... | Get a single broadcast.
Broadcasts are stored data about how to do a Pandas join.
A Broadcast object is a namedtuple with these attributes:
- cast: the name of the table being broadcast
- onto: the name of the table onto which "cast" is broadcast
- cast_on: The optional name of a colum... | [
"Get",
"a",
"single",
"broadcast",
"."
] | 07b34aeef13cc87c966b2e30cbe7e76cc9d3622c | https://github.com/UDST/orca/blob/07b34aeef13cc87c966b2e30cbe7e76cc9d3622c/orca/orca.py#L1612-L1645 | train | 62,207 |
UDST/orca | orca/orca.py | _all_reachable_tables | def _all_reachable_tables(t):
"""
A generator that provides all the names of tables that can be
reached via merges starting at the given target table.
"""
for k, v in t.items():
for tname in _all_reachable_tables(v):
yield tname
yield k | python | def _all_reachable_tables(t):
"""
A generator that provides all the names of tables that can be
reached via merges starting at the given target table.
"""
for k, v in t.items():
for tname in _all_reachable_tables(v):
yield tname
yield k | [
"def",
"_all_reachable_tables",
"(",
"t",
")",
":",
"for",
"k",
",",
"v",
"in",
"t",
".",
"items",
"(",
")",
":",
"for",
"tname",
"in",
"_all_reachable_tables",
"(",
"v",
")",
":",
"yield",
"tname",
"yield",
"k"
] | A generator that provides all the names of tables that can be
reached via merges starting at the given target table. | [
"A",
"generator",
"that",
"provides",
"all",
"the",
"names",
"of",
"tables",
"that",
"can",
"be",
"reached",
"via",
"merges",
"starting",
"at",
"the",
"given",
"target",
"table",
"."
] | 07b34aeef13cc87c966b2e30cbe7e76cc9d3622c | https://github.com/UDST/orca/blob/07b34aeef13cc87c966b2e30cbe7e76cc9d3622c/orca/orca.py#L1649-L1658 | train | 62,208 |
UDST/orca | orca/orca.py | _recursive_getitem | def _recursive_getitem(d, key):
"""
Descend into a dict of dicts to return the one that contains
a given key. Every value in the dict must be another dict.
"""
if key in d:
return d
else:
for v in d.values():
return _recursive_getitem(v, key)
else:
... | python | def _recursive_getitem(d, key):
"""
Descend into a dict of dicts to return the one that contains
a given key. Every value in the dict must be another dict.
"""
if key in d:
return d
else:
for v in d.values():
return _recursive_getitem(v, key)
else:
... | [
"def",
"_recursive_getitem",
"(",
"d",
",",
"key",
")",
":",
"if",
"key",
"in",
"d",
":",
"return",
"d",
"else",
":",
"for",
"v",
"in",
"d",
".",
"values",
"(",
")",
":",
"return",
"_recursive_getitem",
"(",
"v",
",",
"key",
")",
"else",
":",
"ra... | Descend into a dict of dicts to return the one that contains
a given key. Every value in the dict must be another dict. | [
"Descend",
"into",
"a",
"dict",
"of",
"dicts",
"to",
"return",
"the",
"one",
"that",
"contains",
"a",
"given",
"key",
".",
"Every",
"value",
"in",
"the",
"dict",
"must",
"be",
"another",
"dict",
"."
] | 07b34aeef13cc87c966b2e30cbe7e76cc9d3622c | https://github.com/UDST/orca/blob/07b34aeef13cc87c966b2e30cbe7e76cc9d3622c/orca/orca.py#L1661-L1673 | train | 62,209 |
UDST/orca | orca/orca.py | _next_merge | def _next_merge(merge_node):
"""
Gets a node that has only leaf nodes below it. This table and
the ones below are ready to be merged to make a new leaf node.
"""
if all(_is_leaf_node(d) for d in _dict_value_to_pairs(merge_node)):
return merge_node
else:
for d in tz.remove(_is_le... | python | def _next_merge(merge_node):
"""
Gets a node that has only leaf nodes below it. This table and
the ones below are ready to be merged to make a new leaf node.
"""
if all(_is_leaf_node(d) for d in _dict_value_to_pairs(merge_node)):
return merge_node
else:
for d in tz.remove(_is_le... | [
"def",
"_next_merge",
"(",
"merge_node",
")",
":",
"if",
"all",
"(",
"_is_leaf_node",
"(",
"d",
")",
"for",
"d",
"in",
"_dict_value_to_pairs",
"(",
"merge_node",
")",
")",
":",
"return",
"merge_node",
"else",
":",
"for",
"d",
"in",
"tz",
".",
"remove",
... | Gets a node that has only leaf nodes below it. This table and
the ones below are ready to be merged to make a new leaf node. | [
"Gets",
"a",
"node",
"that",
"has",
"only",
"leaf",
"nodes",
"below",
"it",
".",
"This",
"table",
"and",
"the",
"ones",
"below",
"are",
"ready",
"to",
"be",
"merged",
"to",
"make",
"a",
"new",
"leaf",
"node",
"."
] | 07b34aeef13cc87c966b2e30cbe7e76cc9d3622c | https://github.com/UDST/orca/blob/07b34aeef13cc87c966b2e30cbe7e76cc9d3622c/orca/orca.py#L1699-L1711 | train | 62,210 |
UDST/orca | orca/orca.py | get_step_table_names | def get_step_table_names(steps):
"""
Returns a list of table names injected into the provided steps.
Parameters
----------
steps: list of str
Steps to gather table inputs from.
Returns
-------
list of str
"""
table_names = set()
for s in steps:
table_names ... | python | def get_step_table_names(steps):
"""
Returns a list of table names injected into the provided steps.
Parameters
----------
steps: list of str
Steps to gather table inputs from.
Returns
-------
list of str
"""
table_names = set()
for s in steps:
table_names ... | [
"def",
"get_step_table_names",
"(",
"steps",
")",
":",
"table_names",
"=",
"set",
"(",
")",
"for",
"s",
"in",
"steps",
":",
"table_names",
"|=",
"get_step",
"(",
"s",
")",
".",
"_tables_used",
"(",
")",
"return",
"list",
"(",
"table_names",
")"
] | Returns a list of table names injected into the provided steps.
Parameters
----------
steps: list of str
Steps to gather table inputs from.
Returns
-------
list of str | [
"Returns",
"a",
"list",
"of",
"table",
"names",
"injected",
"into",
"the",
"provided",
"steps",
"."
] | 07b34aeef13cc87c966b2e30cbe7e76cc9d3622c | https://github.com/UDST/orca/blob/07b34aeef13cc87c966b2e30cbe7e76cc9d3622c/orca/orca.py#L1846-L1863 | train | 62,211 |
UDST/orca | orca/orca.py | write_tables | def write_tables(fname, table_names=None, prefix=None, compress=False, local=False):
"""
Writes tables to a pandas.HDFStore file.
Parameters
----------
fname : str
File name for HDFStore. Will be opened in append mode and closed
at the end of this function.
table_names: list of ... | python | def write_tables(fname, table_names=None, prefix=None, compress=False, local=False):
"""
Writes tables to a pandas.HDFStore file.
Parameters
----------
fname : str
File name for HDFStore. Will be opened in append mode and closed
at the end of this function.
table_names: list of ... | [
"def",
"write_tables",
"(",
"fname",
",",
"table_names",
"=",
"None",
",",
"prefix",
"=",
"None",
",",
"compress",
"=",
"False",
",",
"local",
"=",
"False",
")",
":",
"if",
"table_names",
"is",
"None",
":",
"table_names",
"=",
"list_tables",
"(",
")",
... | Writes tables to a pandas.HDFStore file.
Parameters
----------
fname : str
File name for HDFStore. Will be opened in append mode and closed
at the end of this function.
table_names: list of str, optional, default None
List of tables to write. If None, all registered tables will
... | [
"Writes",
"tables",
"to",
"a",
"pandas",
".",
"HDFStore",
"file",
"."
] | 07b34aeef13cc87c966b2e30cbe7e76cc9d3622c | https://github.com/UDST/orca/blob/07b34aeef13cc87c966b2e30cbe7e76cc9d3622c/orca/orca.py#L1866-L1902 | train | 62,212 |
UDST/orca | orca/orca.py | run | def run(steps, iter_vars=None, data_out=None, out_interval=1,
out_base_tables=None, out_run_tables=None, compress=False,
out_base_local=True, out_run_local=True):
"""
Run steps in series, optionally repeatedly over some sequence.
The current iteration variable is set as a global injectable
... | python | def run(steps, iter_vars=None, data_out=None, out_interval=1,
out_base_tables=None, out_run_tables=None, compress=False,
out_base_local=True, out_run_local=True):
"""
Run steps in series, optionally repeatedly over some sequence.
The current iteration variable is set as a global injectable
... | [
"def",
"run",
"(",
"steps",
",",
"iter_vars",
"=",
"None",
",",
"data_out",
"=",
"None",
",",
"out_interval",
"=",
"1",
",",
"out_base_tables",
"=",
"None",
",",
"out_run_tables",
"=",
"None",
",",
"compress",
"=",
"False",
",",
"out_base_local",
"=",
"T... | Run steps in series, optionally repeatedly over some sequence.
The current iteration variable is set as a global injectable
called ``iter_var``.
Parameters
----------
steps : list of str
List of steps to run identified by their name.
iter_vars : iterable, optional
The values of ... | [
"Run",
"steps",
"in",
"series",
"optionally",
"repeatedly",
"over",
"some",
"sequence",
".",
"The",
"current",
"iteration",
"variable",
"is",
"set",
"as",
"a",
"global",
"injectable",
"called",
"iter_var",
"."
] | 07b34aeef13cc87c966b2e30cbe7e76cc9d3622c | https://github.com/UDST/orca/blob/07b34aeef13cc87c966b2e30cbe7e76cc9d3622c/orca/orca.py#L1908-L2007 | train | 62,213 |
UDST/orca | orca/orca.py | injectables | def injectables(**kwargs):
"""
Temporarily add injectables to the pipeline environment.
Takes only keyword arguments.
Injectables will be returned to their original state when the context
manager exits.
"""
global _INJECTABLES
original = _INJECTABLES.copy()
_INJECTABLES.update(kwa... | python | def injectables(**kwargs):
"""
Temporarily add injectables to the pipeline environment.
Takes only keyword arguments.
Injectables will be returned to their original state when the context
manager exits.
"""
global _INJECTABLES
original = _INJECTABLES.copy()
_INJECTABLES.update(kwa... | [
"def",
"injectables",
"(",
"*",
"*",
"kwargs",
")",
":",
"global",
"_INJECTABLES",
"original",
"=",
"_INJECTABLES",
".",
"copy",
"(",
")",
"_INJECTABLES",
".",
"update",
"(",
"kwargs",
")",
"yield",
"_INJECTABLES",
"=",
"original"
] | Temporarily add injectables to the pipeline environment.
Takes only keyword arguments.
Injectables will be returned to their original state when the context
manager exits. | [
"Temporarily",
"add",
"injectables",
"to",
"the",
"pipeline",
"environment",
".",
"Takes",
"only",
"keyword",
"arguments",
"."
] | 07b34aeef13cc87c966b2e30cbe7e76cc9d3622c | https://github.com/UDST/orca/blob/07b34aeef13cc87c966b2e30cbe7e76cc9d3622c/orca/orca.py#L2011-L2025 | train | 62,214 |
UDST/orca | orca/orca.py | temporary_tables | def temporary_tables(**kwargs):
"""
Temporarily set DataFrames as registered tables.
Tables will be returned to their original state when the context
manager exits. Caching is not enabled for tables registered via
this function.
"""
global _TABLES
original = _TABLES.copy()
for k,... | python | def temporary_tables(**kwargs):
"""
Temporarily set DataFrames as registered tables.
Tables will be returned to their original state when the context
manager exits. Caching is not enabled for tables registered via
this function.
"""
global _TABLES
original = _TABLES.copy()
for k,... | [
"def",
"temporary_tables",
"(",
"*",
"*",
"kwargs",
")",
":",
"global",
"_TABLES",
"original",
"=",
"_TABLES",
".",
"copy",
"(",
")",
"for",
"k",
",",
"v",
"in",
"kwargs",
".",
"items",
"(",
")",
":",
"if",
"not",
"isinstance",
"(",
"v",
",",
"pd",... | Temporarily set DataFrames as registered tables.
Tables will be returned to their original state when the context
manager exits. Caching is not enabled for tables registered via
this function. | [
"Temporarily",
"set",
"DataFrames",
"as",
"registered",
"tables",
"."
] | 07b34aeef13cc87c966b2e30cbe7e76cc9d3622c | https://github.com/UDST/orca/blob/07b34aeef13cc87c966b2e30cbe7e76cc9d3622c/orca/orca.py#L2029-L2049 | train | 62,215 |
UDST/orca | orca/orca.py | eval_variable | def eval_variable(name, **kwargs):
"""
Execute a single variable function registered with Orca
and return the result. Any keyword arguments are temporarily set
as injectables. This gives the value as would be injected into a function.
Parameters
----------
name : str
Name of variabl... | python | def eval_variable(name, **kwargs):
"""
Execute a single variable function registered with Orca
and return the result. Any keyword arguments are temporarily set
as injectables. This gives the value as would be injected into a function.
Parameters
----------
name : str
Name of variabl... | [
"def",
"eval_variable",
"(",
"name",
",",
"*",
"*",
"kwargs",
")",
":",
"with",
"injectables",
"(",
"*",
"*",
"kwargs",
")",
":",
"vars",
"=",
"_collect_variables",
"(",
"[",
"name",
"]",
",",
"[",
"name",
"]",
")",
"return",
"vars",
"[",
"name",
"... | Execute a single variable function registered with Orca
and return the result. Any keyword arguments are temporarily set
as injectables. This gives the value as would be injected into a function.
Parameters
----------
name : str
Name of variable to evaluate.
Use variable expressions... | [
"Execute",
"a",
"single",
"variable",
"function",
"registered",
"with",
"Orca",
"and",
"return",
"the",
"result",
".",
"Any",
"keyword",
"arguments",
"are",
"temporarily",
"set",
"as",
"injectables",
".",
"This",
"gives",
"the",
"value",
"as",
"would",
"be",
... | 07b34aeef13cc87c966b2e30cbe7e76cc9d3622c | https://github.com/UDST/orca/blob/07b34aeef13cc87c966b2e30cbe7e76cc9d3622c/orca/orca.py#L2052-L2075 | train | 62,216 |
UDST/orca | orca/orca.py | DataFrameWrapper.to_frame | def to_frame(self, columns=None):
"""
Make a DataFrame with the given columns.
Will always return a copy of the underlying table.
Parameters
----------
columns : sequence or string, optional
Sequence of the column names desired in the DataFrame. A string
... | python | def to_frame(self, columns=None):
"""
Make a DataFrame with the given columns.
Will always return a copy of the underlying table.
Parameters
----------
columns : sequence or string, optional
Sequence of the column names desired in the DataFrame. A string
... | [
"def",
"to_frame",
"(",
"self",
",",
"columns",
"=",
"None",
")",
":",
"extra_cols",
"=",
"_columns_for_table",
"(",
"self",
".",
"name",
")",
"if",
"columns",
"is",
"not",
"None",
":",
"columns",
"=",
"[",
"columns",
"]",
"if",
"isinstance",
"(",
"col... | Make a DataFrame with the given columns.
Will always return a copy of the underlying table.
Parameters
----------
columns : sequence or string, optional
Sequence of the column names desired in the DataFrame. A string
can also be passed if only one column is desi... | [
"Make",
"a",
"DataFrame",
"with",
"the",
"given",
"columns",
"."
] | 07b34aeef13cc87c966b2e30cbe7e76cc9d3622c | https://github.com/UDST/orca/blob/07b34aeef13cc87c966b2e30cbe7e76cc9d3622c/orca/orca.py#L196-L237 | train | 62,217 |
UDST/orca | orca/orca.py | DataFrameWrapper.update_col | def update_col(self, column_name, series):
"""
Add or replace a column in the underlying DataFrame.
Parameters
----------
column_name : str
Column to add or replace.
series : pandas.Series or sequence
Column data.
"""
logger.debug... | python | def update_col(self, column_name, series):
"""
Add or replace a column in the underlying DataFrame.
Parameters
----------
column_name : str
Column to add or replace.
series : pandas.Series or sequence
Column data.
"""
logger.debug... | [
"def",
"update_col",
"(",
"self",
",",
"column_name",
",",
"series",
")",
":",
"logger",
".",
"debug",
"(",
"'updating column {!r} in table {!r}'",
".",
"format",
"(",
"column_name",
",",
"self",
".",
"name",
")",
")",
"self",
".",
"local",
"[",
"column_name... | Add or replace a column in the underlying DataFrame.
Parameters
----------
column_name : str
Column to add or replace.
series : pandas.Series or sequence
Column data. | [
"Add",
"or",
"replace",
"a",
"column",
"in",
"the",
"underlying",
"DataFrame",
"."
] | 07b34aeef13cc87c966b2e30cbe7e76cc9d3622c | https://github.com/UDST/orca/blob/07b34aeef13cc87c966b2e30cbe7e76cc9d3622c/orca/orca.py#L239-L253 | train | 62,218 |
UDST/orca | orca/orca.py | DataFrameWrapper.column_type | def column_type(self, column_name):
"""
Report column type as one of 'local', 'series', or 'function'.
Parameters
----------
column_name : str
Returns
-------
col_type : {'local', 'series', 'function'}
'local' means that the column is part of... | python | def column_type(self, column_name):
"""
Report column type as one of 'local', 'series', or 'function'.
Parameters
----------
column_name : str
Returns
-------
col_type : {'local', 'series', 'function'}
'local' means that the column is part of... | [
"def",
"column_type",
"(",
"self",
",",
"column_name",
")",
":",
"extra_cols",
"=",
"list_columns_for_table",
"(",
"self",
".",
"name",
")",
"if",
"column_name",
"in",
"extra_cols",
":",
"col",
"=",
"_COLUMNS",
"[",
"(",
"self",
".",
"name",
",",
"column_n... | Report column type as one of 'local', 'series', or 'function'.
Parameters
----------
column_name : str
Returns
-------
col_type : {'local', 'series', 'function'}
'local' means that the column is part of the registered table,
'series' means the co... | [
"Report",
"column",
"type",
"as",
"one",
"of",
"local",
"series",
"or",
"function",
"."
] | 07b34aeef13cc87c966b2e30cbe7e76cc9d3622c | https://github.com/UDST/orca/blob/07b34aeef13cc87c966b2e30cbe7e76cc9d3622c/orca/orca.py#L295-L325 | train | 62,219 |
UDST/orca | orca/orca.py | DataFrameWrapper.update_col_from_series | def update_col_from_series(self, column_name, series, cast=False):
"""
Update existing values in a column from another series.
Index values must match in both column and series. Optionally
casts data type to match the existing column.
Parameters
---------------
c... | python | def update_col_from_series(self, column_name, series, cast=False):
"""
Update existing values in a column from another series.
Index values must match in both column and series. Optionally
casts data type to match the existing column.
Parameters
---------------
c... | [
"def",
"update_col_from_series",
"(",
"self",
",",
"column_name",
",",
"series",
",",
"cast",
"=",
"False",
")",
":",
"logger",
".",
"debug",
"(",
"'updating column {!r} in table {!r}'",
".",
"format",
"(",
"column_name",
",",
"self",
".",
"name",
")",
")",
... | Update existing values in a column from another series.
Index values must match in both column and series. Optionally
casts data type to match the existing column.
Parameters
---------------
column_name : str
series : panas.Series
cast: bool, optional, default Fa... | [
"Update",
"existing",
"values",
"in",
"a",
"column",
"from",
"another",
"series",
".",
"Index",
"values",
"must",
"match",
"in",
"both",
"column",
"and",
"series",
".",
"Optionally",
"casts",
"data",
"type",
"to",
"match",
"the",
"existing",
"column",
"."
] | 07b34aeef13cc87c966b2e30cbe7e76cc9d3622c | https://github.com/UDST/orca/blob/07b34aeef13cc87c966b2e30cbe7e76cc9d3622c/orca/orca.py#L327-L351 | train | 62,220 |
UDST/orca | orca/orca.py | DataFrameWrapper.clear_cached | def clear_cached(self):
"""
Remove cached results from this table's computed columns.
"""
_TABLE_CACHE.pop(self.name, None)
for col in _columns_for_table(self.name).values():
col.clear_cached()
logger.debug('cleared cached columns for table {!r}'.format(self.... | python | def clear_cached(self):
"""
Remove cached results from this table's computed columns.
"""
_TABLE_CACHE.pop(self.name, None)
for col in _columns_for_table(self.name).values():
col.clear_cached()
logger.debug('cleared cached columns for table {!r}'.format(self.... | [
"def",
"clear_cached",
"(",
"self",
")",
":",
"_TABLE_CACHE",
".",
"pop",
"(",
"self",
".",
"name",
",",
"None",
")",
"for",
"col",
"in",
"_columns_for_table",
"(",
"self",
".",
"name",
")",
".",
"values",
"(",
")",
":",
"col",
".",
"clear_cached",
"... | Remove cached results from this table's computed columns. | [
"Remove",
"cached",
"results",
"from",
"this",
"table",
"s",
"computed",
"columns",
"."
] | 07b34aeef13cc87c966b2e30cbe7e76cc9d3622c | https://github.com/UDST/orca/blob/07b34aeef13cc87c966b2e30cbe7e76cc9d3622c/orca/orca.py#L356-L364 | train | 62,221 |
UDST/orca | orca/orca.py | TableFuncWrapper._call_func | def _call_func(self):
"""
Call the wrapped function and return the result wrapped by
DataFrameWrapper.
Also updates attributes like columns, index, and length.
"""
if _CACHING and self.cache and self.name in _TABLE_CACHE:
logger.debug('returning table {!r} fr... | python | def _call_func(self):
"""
Call the wrapped function and return the result wrapped by
DataFrameWrapper.
Also updates attributes like columns, index, and length.
"""
if _CACHING and self.cache and self.name in _TABLE_CACHE:
logger.debug('returning table {!r} fr... | [
"def",
"_call_func",
"(",
"self",
")",
":",
"if",
"_CACHING",
"and",
"self",
".",
"cache",
"and",
"self",
".",
"name",
"in",
"_TABLE_CACHE",
":",
"logger",
".",
"debug",
"(",
"'returning table {!r} from cache'",
".",
"format",
"(",
"self",
".",
"name",
")"... | Call the wrapped function and return the result wrapped by
DataFrameWrapper.
Also updates attributes like columns, index, and length. | [
"Call",
"the",
"wrapped",
"function",
"and",
"return",
"the",
"result",
"wrapped",
"by",
"DataFrameWrapper",
".",
"Also",
"updates",
"attributes",
"like",
"columns",
"index",
"and",
"length",
"."
] | 07b34aeef13cc87c966b2e30cbe7e76cc9d3622c | https://github.com/UDST/orca/blob/07b34aeef13cc87c966b2e30cbe7e76cc9d3622c/orca/orca.py#L441-L470 | train | 62,222 |
UDST/orca | orca/orca.py | _ColumnFuncWrapper.clear_cached | def clear_cached(self):
"""
Remove any cached result of this column.
"""
x = _COLUMN_CACHE.pop((self.table_name, self.name), None)
if x is not None:
logger.debug(
'cleared cached value for column {!r} in table {!r}'.format(
self.na... | python | def clear_cached(self):
"""
Remove any cached result of this column.
"""
x = _COLUMN_CACHE.pop((self.table_name, self.name), None)
if x is not None:
logger.debug(
'cleared cached value for column {!r} in table {!r}'.format(
self.na... | [
"def",
"clear_cached",
"(",
"self",
")",
":",
"x",
"=",
"_COLUMN_CACHE",
".",
"pop",
"(",
"(",
"self",
".",
"table_name",
",",
"self",
".",
"name",
")",
",",
"None",
")",
"if",
"x",
"is",
"not",
"None",
":",
"logger",
".",
"debug",
"(",
"'cleared c... | Remove any cached result of this column. | [
"Remove",
"any",
"cached",
"result",
"of",
"this",
"column",
"."
] | 07b34aeef13cc87c966b2e30cbe7e76cc9d3622c | https://github.com/UDST/orca/blob/07b34aeef13cc87c966b2e30cbe7e76cc9d3622c/orca/orca.py#L647-L656 | train | 62,223 |
UDST/orca | orca/orca.py | _InjectableFuncWrapper.clear_cached | def clear_cached(self):
"""
Clear a cached result for this injectable.
"""
x = _INJECTABLE_CACHE.pop(self.name, None)
if x:
logger.debug(
'injectable {!r} removed from cache'.format(self.name)) | python | def clear_cached(self):
"""
Clear a cached result for this injectable.
"""
x = _INJECTABLE_CACHE.pop(self.name, None)
if x:
logger.debug(
'injectable {!r} removed from cache'.format(self.name)) | [
"def",
"clear_cached",
"(",
"self",
")",
":",
"x",
"=",
"_INJECTABLE_CACHE",
".",
"pop",
"(",
"self",
".",
"name",
",",
"None",
")",
"if",
"x",
":",
"logger",
".",
"debug",
"(",
"'injectable {!r} removed from cache'",
".",
"format",
"(",
"self",
".",
"na... | Clear a cached result for this injectable. | [
"Clear",
"a",
"cached",
"result",
"for",
"this",
"injectable",
"."
] | 07b34aeef13cc87c966b2e30cbe7e76cc9d3622c | https://github.com/UDST/orca/blob/07b34aeef13cc87c966b2e30cbe7e76cc9d3622c/orca/orca.py#L762-L770 | train | 62,224 |
UDST/orca | orca/orca.py | _StepFuncWrapper._tables_used | def _tables_used(self):
"""
Tables injected into the step.
Returns
-------
tables : set of str
"""
args = list(self._argspec.args)
if self._argspec.defaults:
default_args = list(self._argspec.defaults)
else:
default_args =... | python | def _tables_used(self):
"""
Tables injected into the step.
Returns
-------
tables : set of str
"""
args = list(self._argspec.args)
if self._argspec.defaults:
default_args = list(self._argspec.defaults)
else:
default_args =... | [
"def",
"_tables_used",
"(",
"self",
")",
":",
"args",
"=",
"list",
"(",
"self",
".",
"_argspec",
".",
"args",
")",
"if",
"self",
".",
"_argspec",
".",
"defaults",
":",
"default_args",
"=",
"list",
"(",
"self",
".",
"_argspec",
".",
"defaults",
")",
"... | Tables injected into the step.
Returns
-------
tables : set of str | [
"Tables",
"injected",
"into",
"the",
"step",
"."
] | 07b34aeef13cc87c966b2e30cbe7e76cc9d3622c | https://github.com/UDST/orca/blob/07b34aeef13cc87c966b2e30cbe7e76cc9d3622c/orca/orca.py#L799-L820 | train | 62,225 |
versae/qbe | django_qbe/utils.py | qbe_tree | def qbe_tree(graph, nodes, root=None):
"""
Given a graph, nodes to explore and an optinal root, do a breadth-first
search in order to return the tree.
"""
if root:
start = root
else:
index = random.randint(0, len(nodes) - 1)
start = nodes[index]
# A queue to BFS inste... | python | def qbe_tree(graph, nodes, root=None):
"""
Given a graph, nodes to explore and an optinal root, do a breadth-first
search in order to return the tree.
"""
if root:
start = root
else:
index = random.randint(0, len(nodes) - 1)
start = nodes[index]
# A queue to BFS inste... | [
"def",
"qbe_tree",
"(",
"graph",
",",
"nodes",
",",
"root",
"=",
"None",
")",
":",
"if",
"root",
":",
"start",
"=",
"root",
"else",
":",
"index",
"=",
"random",
".",
"randint",
"(",
"0",
",",
"len",
"(",
"nodes",
")",
"-",
"1",
")",
"start",
"=... | Given a graph, nodes to explore and an optinal root, do a breadth-first
search in order to return the tree. | [
"Given",
"a",
"graph",
"nodes",
"to",
"explore",
"and",
"an",
"optinal",
"root",
"do",
"a",
"breadth",
"-",
"first",
"search",
"in",
"order",
"to",
"return",
"the",
"tree",
"."
] | be8b28de5bc67cf527ae5bcb183bffe5a91a41db | https://github.com/versae/qbe/blob/be8b28de5bc67cf527ae5bcb183bffe5a91a41db/django_qbe/utils.py#L244-L284 | train | 62,226 |
versae/qbe | django_qbe/utils.py | combine | def combine(items, k=None):
"""
Create a matrix in wich each row is a tuple containing one of solutions or
solution k-esima.
"""
length_items = len(items)
lengths = [len(i) for i in items]
length = reduce(lambda x, y: x * y, lengths)
repeats = [reduce(lambda x, y: x * y, lengths[i:])
... | python | def combine(items, k=None):
"""
Create a matrix in wich each row is a tuple containing one of solutions or
solution k-esima.
"""
length_items = len(items)
lengths = [len(i) for i in items]
length = reduce(lambda x, y: x * y, lengths)
repeats = [reduce(lambda x, y: x * y, lengths[i:])
... | [
"def",
"combine",
"(",
"items",
",",
"k",
"=",
"None",
")",
":",
"length_items",
"=",
"len",
"(",
"items",
")",
"lengths",
"=",
"[",
"len",
"(",
"i",
")",
"for",
"i",
"in",
"items",
"]",
"length",
"=",
"reduce",
"(",
"lambda",
"x",
",",
"y",
":... | Create a matrix in wich each row is a tuple containing one of solutions or
solution k-esima. | [
"Create",
"a",
"matrix",
"in",
"wich",
"each",
"row",
"is",
"a",
"tuple",
"containing",
"one",
"of",
"solutions",
"or",
"solution",
"k",
"-",
"esima",
"."
] | be8b28de5bc67cf527ae5bcb183bffe5a91a41db | https://github.com/versae/qbe/blob/be8b28de5bc67cf527ae5bcb183bffe5a91a41db/django_qbe/utils.py#L394-L419 | train | 62,227 |
versae/qbe | django_qbe/utils.py | pickle_encode | def pickle_encode(session_dict):
"Returns the given session dictionary pickled and encoded as a string."
pickled = pickle.dumps(session_dict, pickle.HIGHEST_PROTOCOL)
return base64.encodestring(pickled + get_query_hash(pickled).encode()) | python | def pickle_encode(session_dict):
"Returns the given session dictionary pickled and encoded as a string."
pickled = pickle.dumps(session_dict, pickle.HIGHEST_PROTOCOL)
return base64.encodestring(pickled + get_query_hash(pickled).encode()) | [
"def",
"pickle_encode",
"(",
"session_dict",
")",
":",
"pickled",
"=",
"pickle",
".",
"dumps",
"(",
"session_dict",
",",
"pickle",
".",
"HIGHEST_PROTOCOL",
")",
"return",
"base64",
".",
"encodestring",
"(",
"pickled",
"+",
"get_query_hash",
"(",
"pickled",
")"... | Returns the given session dictionary pickled and encoded as a string. | [
"Returns",
"the",
"given",
"session",
"dictionary",
"pickled",
"and",
"encoded",
"as",
"a",
"string",
"."
] | be8b28de5bc67cf527ae5bcb183bffe5a91a41db | https://github.com/versae/qbe/blob/be8b28de5bc67cf527ae5bcb183bffe5a91a41db/django_qbe/utils.py#L444-L447 | train | 62,228 |
UDST/orca | orca/utils/utils.py | func_source_data | def func_source_data(func):
"""
Return data about a function source, including file name,
line number, and source code.
Parameters
----------
func : object
May be anything support by the inspect module, such as a function,
method, or class.
Returns
-------
filename ... | python | def func_source_data(func):
"""
Return data about a function source, including file name,
line number, and source code.
Parameters
----------
func : object
May be anything support by the inspect module, such as a function,
method, or class.
Returns
-------
filename ... | [
"def",
"func_source_data",
"(",
"func",
")",
":",
"filename",
"=",
"inspect",
".",
"getsourcefile",
"(",
"func",
")",
"lineno",
"=",
"inspect",
".",
"getsourcelines",
"(",
"func",
")",
"[",
"1",
"]",
"source",
"=",
"inspect",
".",
"getsource",
"(",
"func... | Return data about a function source, including file name,
line number, and source code.
Parameters
----------
func : object
May be anything support by the inspect module, such as a function,
method, or class.
Returns
-------
filename : str
lineno : int
The line ... | [
"Return",
"data",
"about",
"a",
"function",
"source",
"including",
"file",
"name",
"line",
"number",
"and",
"source",
"code",
"."
] | 07b34aeef13cc87c966b2e30cbe7e76cc9d3622c | https://github.com/UDST/orca/blob/07b34aeef13cc87c966b2e30cbe7e76cc9d3622c/orca/utils/utils.py#L4-L27 | train | 62,229 |
versae/qbe | django_qbe/forms.py | BaseQueryByExampleFormSet.clean | def clean(self):
"""
Checks that there is almost one field to select
"""
if any(self.errors):
# Don't bother validating the formset unless each form is valid on
# its own
return
(selects, aliases, froms, wheres, sorts, groups_by,
param... | python | def clean(self):
"""
Checks that there is almost one field to select
"""
if any(self.errors):
# Don't bother validating the formset unless each form is valid on
# its own
return
(selects, aliases, froms, wheres, sorts, groups_by,
param... | [
"def",
"clean",
"(",
"self",
")",
":",
"if",
"any",
"(",
"self",
".",
"errors",
")",
":",
"# Don't bother validating the formset unless each form is valid on",
"# its own",
"return",
"(",
"selects",
",",
"aliases",
",",
"froms",
",",
"wheres",
",",
"sorts",
",",... | Checks that there is almost one field to select | [
"Checks",
"that",
"there",
"is",
"almost",
"one",
"field",
"to",
"select"
] | be8b28de5bc67cf527ae5bcb183bffe5a91a41db | https://github.com/versae/qbe/blob/be8b28de5bc67cf527ae5bcb183bffe5a91a41db/django_qbe/forms.py#L130-L149 | train | 62,230 |
versae/qbe | django_qbe/forms.py | BaseQueryByExampleFormSet.get_results | def get_results(self, limit=None, offset=None, query=None, admin_name=None,
row_number=False):
"""
Fetch all results after perform SQL query and
"""
add_extra_ids = (admin_name is not None)
if not query:
sql = self.get_raw_query(limit=limit, offset... | python | def get_results(self, limit=None, offset=None, query=None, admin_name=None,
row_number=False):
"""
Fetch all results after perform SQL query and
"""
add_extra_ids = (admin_name is not None)
if not query:
sql = self.get_raw_query(limit=limit, offset... | [
"def",
"get_results",
"(",
"self",
",",
"limit",
"=",
"None",
",",
"offset",
"=",
"None",
",",
"query",
"=",
"None",
",",
"admin_name",
"=",
"None",
",",
"row_number",
"=",
"False",
")",
":",
"add_extra_ids",
"=",
"(",
"admin_name",
"is",
"not",
"None"... | Fetch all results after perform SQL query and | [
"Fetch",
"all",
"results",
"after",
"perform",
"SQL",
"query",
"and"
] | be8b28de5bc67cf527ae5bcb183bffe5a91a41db | https://github.com/versae/qbe/blob/be8b28de5bc67cf527ae5bcb183bffe5a91a41db/django_qbe/forms.py#L313-L375 | train | 62,231 |
jgorset/django-respite | respite/utils/parsers.py | parse_content_type | def parse_content_type(content_type):
"""
Return a tuple of content type and charset.
:param content_type: A string describing a content type.
"""
if '; charset=' in content_type:
return tuple(content_type.split('; charset='))
else:
if 'text' in content_type:
encodin... | python | def parse_content_type(content_type):
"""
Return a tuple of content type and charset.
:param content_type: A string describing a content type.
"""
if '; charset=' in content_type:
return tuple(content_type.split('; charset='))
else:
if 'text' in content_type:
encodin... | [
"def",
"parse_content_type",
"(",
"content_type",
")",
":",
"if",
"'; charset='",
"in",
"content_type",
":",
"return",
"tuple",
"(",
"content_type",
".",
"split",
"(",
"'; charset='",
")",
")",
"else",
":",
"if",
"'text'",
"in",
"content_type",
":",
"encoding"... | Return a tuple of content type and charset.
:param content_type: A string describing a content type. | [
"Return",
"a",
"tuple",
"of",
"content",
"type",
"and",
"charset",
"."
] | 719469d11baf91d05917bab1623bd82adc543546 | https://github.com/jgorset/django-respite/blob/719469d11baf91d05917bab1623bd82adc543546/respite/utils/parsers.py#L10-L29 | train | 62,232 |
jgorset/django-respite | respite/utils/parsers.py | parse_http_accept_header | def parse_http_accept_header(header):
"""
Return a list of content types listed in the HTTP Accept header
ordered by quality.
:param header: A string describing the contents of the HTTP Accept header.
"""
components = [item.strip() for item in header.split(',')]
l = []
for component in... | python | def parse_http_accept_header(header):
"""
Return a list of content types listed in the HTTP Accept header
ordered by quality.
:param header: A string describing the contents of the HTTP Accept header.
"""
components = [item.strip() for item in header.split(',')]
l = []
for component in... | [
"def",
"parse_http_accept_header",
"(",
"header",
")",
":",
"components",
"=",
"[",
"item",
".",
"strip",
"(",
")",
"for",
"item",
"in",
"header",
".",
"split",
"(",
"','",
")",
"]",
"l",
"=",
"[",
"]",
"for",
"component",
"in",
"components",
":",
"i... | Return a list of content types listed in the HTTP Accept header
ordered by quality.
:param header: A string describing the contents of the HTTP Accept header. | [
"Return",
"a",
"list",
"of",
"content",
"types",
"listed",
"in",
"the",
"HTTP",
"Accept",
"header",
"ordered",
"by",
"quality",
"."
] | 719469d11baf91d05917bab1623bd82adc543546 | https://github.com/jgorset/django-respite/blob/719469d11baf91d05917bab1623bd82adc543546/respite/utils/parsers.py#L31-L62 | train | 62,233 |
jgorset/django-respite | respite/utils/parsers.py | parse_multipart_data | def parse_multipart_data(request):
"""
Parse a request with multipart data.
:param request: A HttpRequest instance.
"""
return MultiPartParser(
META=request.META,
input_data=StringIO(request.body),
upload_handlers=request.upload_handlers,
encoding=request.encoding
... | python | def parse_multipart_data(request):
"""
Parse a request with multipart data.
:param request: A HttpRequest instance.
"""
return MultiPartParser(
META=request.META,
input_data=StringIO(request.body),
upload_handlers=request.upload_handlers,
encoding=request.encoding
... | [
"def",
"parse_multipart_data",
"(",
"request",
")",
":",
"return",
"MultiPartParser",
"(",
"META",
"=",
"request",
".",
"META",
",",
"input_data",
"=",
"StringIO",
"(",
"request",
".",
"body",
")",
",",
"upload_handlers",
"=",
"request",
".",
"upload_handlers"... | Parse a request with multipart data.
:param request: A HttpRequest instance. | [
"Parse",
"a",
"request",
"with",
"multipart",
"data",
"."
] | 719469d11baf91d05917bab1623bd82adc543546 | https://github.com/jgorset/django-respite/blob/719469d11baf91d05917bab1623bd82adc543546/respite/utils/parsers.py#L64-L75 | train | 62,234 |
jgorset/django-respite | respite/decorators.py | override_supported_formats | def override_supported_formats(formats):
"""
Override the views class' supported formats for the decorated function.
Arguments:
formats -- A list of strings describing formats, e.g. ``['html', 'json']``.
"""
def decorator(function):
@wraps(function)
def wrapper(self, *args, **kw... | python | def override_supported_formats(formats):
"""
Override the views class' supported formats for the decorated function.
Arguments:
formats -- A list of strings describing formats, e.g. ``['html', 'json']``.
"""
def decorator(function):
@wraps(function)
def wrapper(self, *args, **kw... | [
"def",
"override_supported_formats",
"(",
"formats",
")",
":",
"def",
"decorator",
"(",
"function",
")",
":",
"@",
"wraps",
"(",
"function",
")",
"def",
"wrapper",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"supporte... | Override the views class' supported formats for the decorated function.
Arguments:
formats -- A list of strings describing formats, e.g. ``['html', 'json']``. | [
"Override",
"the",
"views",
"class",
"supported",
"formats",
"for",
"the",
"decorated",
"function",
"."
] | 719469d11baf91d05917bab1623bd82adc543546 | https://github.com/jgorset/django-respite/blob/719469d11baf91d05917bab1623bd82adc543546/respite/decorators.py#L9-L22 | train | 62,235 |
jgorset/django-respite | respite/decorators.py | route | def route(regex, method, name):
"""
Route the decorated view.
:param regex: A string describing a regular expression to which the request path will be matched.
:param method: A string describing the HTTP method that this view accepts.
:param name: A string describing the name of the URL pattern.
... | python | def route(regex, method, name):
"""
Route the decorated view.
:param regex: A string describing a regular expression to which the request path will be matched.
:param method: A string describing the HTTP method that this view accepts.
:param name: A string describing the name of the URL pattern.
... | [
"def",
"route",
"(",
"regex",
",",
"method",
",",
"name",
")",
":",
"def",
"decorator",
"(",
"function",
")",
":",
"function",
".",
"route",
"=",
"routes",
".",
"route",
"(",
"regex",
"=",
"regex",
",",
"view",
"=",
"function",
".",
"__name__",
",",
... | Route the decorated view.
:param regex: A string describing a regular expression to which the request path will be matched.
:param method: A string describing the HTTP method that this view accepts.
:param name: A string describing the name of the URL pattern.
``regex`` may also be a lambda that a... | [
"Route",
"the",
"decorated",
"view",
"."
] | 719469d11baf91d05917bab1623bd82adc543546 | https://github.com/jgorset/django-respite/blob/719469d11baf91d05917bab1623bd82adc543546/respite/decorators.py#L24-L52 | train | 62,236 |
jgorset/django-respite | respite/decorators.py | before | def before(method_name):
"""
Run the given method prior to the decorated view.
If you return anything besides ``None`` from the given method,
its return values will replace the arguments of the decorated
view.
If you return an instance of ``HttpResponse`` from the given method,
Respite wil... | python | def before(method_name):
"""
Run the given method prior to the decorated view.
If you return anything besides ``None`` from the given method,
its return values will replace the arguments of the decorated
view.
If you return an instance of ``HttpResponse`` from the given method,
Respite wil... | [
"def",
"before",
"(",
"method_name",
")",
":",
"def",
"decorator",
"(",
"function",
")",
":",
"@",
"wraps",
"(",
"function",
")",
"def",
"wrapper",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"returns",
"=",
"getattr",
"(",
"s... | Run the given method prior to the decorated view.
If you return anything besides ``None`` from the given method,
its return values will replace the arguments of the decorated
view.
If you return an instance of ``HttpResponse`` from the given method,
Respite will return it immediately without deleg... | [
"Run",
"the",
"given",
"method",
"prior",
"to",
"the",
"decorated",
"view",
"."
] | 719469d11baf91d05917bab1623bd82adc543546 | https://github.com/jgorset/django-respite/blob/719469d11baf91d05917bab1623bd82adc543546/respite/decorators.py#L54-L101 | train | 62,237 |
jgorset/django-respite | respite/views/resource.py | Resource.index | def index(self, request):
"""Render a list of objects."""
objects = self.model.objects.all()
return self._render(
request = request,
template = 'index',
context = {
cc2us(pluralize(self.model.__name__)): objects,
},
sta... | python | def index(self, request):
"""Render a list of objects."""
objects = self.model.objects.all()
return self._render(
request = request,
template = 'index',
context = {
cc2us(pluralize(self.model.__name__)): objects,
},
sta... | [
"def",
"index",
"(",
"self",
",",
"request",
")",
":",
"objects",
"=",
"self",
".",
"model",
".",
"objects",
".",
"all",
"(",
")",
"return",
"self",
".",
"_render",
"(",
"request",
"=",
"request",
",",
"template",
"=",
"'index'",
",",
"context",
"=",... | Render a list of objects. | [
"Render",
"a",
"list",
"of",
"objects",
"."
] | 719469d11baf91d05917bab1623bd82adc543546 | https://github.com/jgorset/django-respite/blob/719469d11baf91d05917bab1623bd82adc543546/respite/views/resource.py#L31-L42 | train | 62,238 |
jgorset/django-respite | respite/views/resource.py | Resource.new | def new(self, request):
"""Render a form to create a new object."""
form = (self.form or generate_form(self.model))()
return self._render(
request = request,
template = 'new',
context = {
'form': form
},
status = 200
... | python | def new(self, request):
"""Render a form to create a new object."""
form = (self.form or generate_form(self.model))()
return self._render(
request = request,
template = 'new',
context = {
'form': form
},
status = 200
... | [
"def",
"new",
"(",
"self",
",",
"request",
")",
":",
"form",
"=",
"(",
"self",
".",
"form",
"or",
"generate_form",
"(",
"self",
".",
"model",
")",
")",
"(",
")",
"return",
"self",
".",
"_render",
"(",
"request",
"=",
"request",
",",
"template",
"="... | Render a form to create a new object. | [
"Render",
"a",
"form",
"to",
"create",
"a",
"new",
"object",
"."
] | 719469d11baf91d05917bab1623bd82adc543546 | https://github.com/jgorset/django-respite/blob/719469d11baf91d05917bab1623bd82adc543546/respite/views/resource.py#L78-L89 | train | 62,239 |
jgorset/django-respite | respite/views/resource.py | Resource.edit | def edit(self, request, id):
"""Render a form to edit an object."""
try:
object = self.model.objects.get(id=id)
except self.model.DoesNotExist:
return self._render(
request = request,
template = '404',
context = {
... | python | def edit(self, request, id):
"""Render a form to edit an object."""
try:
object = self.model.objects.get(id=id)
except self.model.DoesNotExist:
return self._render(
request = request,
template = '404',
context = {
... | [
"def",
"edit",
"(",
"self",
",",
"request",
",",
"id",
")",
":",
"try",
":",
"object",
"=",
"self",
".",
"model",
".",
"objects",
".",
"get",
"(",
"id",
"=",
"id",
")",
"except",
"self",
".",
"model",
".",
"DoesNotExist",
":",
"return",
"self",
"... | Render a form to edit an object. | [
"Render",
"a",
"form",
"to",
"edit",
"an",
"object",
"."
] | 719469d11baf91d05917bab1623bd82adc543546 | https://github.com/jgorset/django-respite/blob/719469d11baf91d05917bab1623bd82adc543546/respite/views/resource.py#L126-L154 | train | 62,240 |
jgorset/django-respite | respite/views/resource.py | Resource.update | def update(self, request, id):
"""Update an object."""
try:
object = self.model.objects.get(id=id)
except self.model.DoesNotExist:
return self._render(
request = request,
template = '404',
context = {
'er... | python | def update(self, request, id):
"""Update an object."""
try:
object = self.model.objects.get(id=id)
except self.model.DoesNotExist:
return self._render(
request = request,
template = '404',
context = {
'er... | [
"def",
"update",
"(",
"self",
",",
"request",
",",
"id",
")",
":",
"try",
":",
"object",
"=",
"self",
".",
"model",
".",
"objects",
".",
"get",
"(",
"id",
"=",
"id",
")",
"except",
"self",
".",
"model",
".",
"DoesNotExist",
":",
"return",
"self",
... | Update an object. | [
"Update",
"an",
"object",
"."
] | 719469d11baf91d05917bab1623bd82adc543546 | https://github.com/jgorset/django-respite/blob/719469d11baf91d05917bab1623bd82adc543546/respite/views/resource.py#L161-L205 | train | 62,241 |
jgorset/django-respite | respite/views/resource.py | Resource.replace | def replace(self, request, id):
"""Replace an object."""
try:
object = self.model.objects.get(id=id)
except self.model.DoesNotExist:
return self._render(
request = request,
template = '404',
context = {
'... | python | def replace(self, request, id):
"""Replace an object."""
try:
object = self.model.objects.get(id=id)
except self.model.DoesNotExist:
return self._render(
request = request,
template = '404',
context = {
'... | [
"def",
"replace",
"(",
"self",
",",
"request",
",",
"id",
")",
":",
"try",
":",
"object",
"=",
"self",
".",
"model",
".",
"objects",
".",
"get",
"(",
"id",
"=",
"id",
")",
"except",
"self",
".",
"model",
".",
"DoesNotExist",
":",
"return",
"self",
... | Replace an object. | [
"Replace",
"an",
"object",
"."
] | 719469d11baf91d05917bab1623bd82adc543546 | https://github.com/jgorset/django-respite/blob/719469d11baf91d05917bab1623bd82adc543546/respite/views/resource.py#L212-L241 | train | 62,242 |
inmagik/django-search-views | search_views/filters.py | build_q | def build_q(fields_dict, params_dict, request=None):
"""
Returns a Q object from filters config and actual parmeters.
"""
# Building search query
# queries generated by different search_fields are ANDed
# if a search field is defined for more than one field, are put together with OR
and_quer... | python | def build_q(fields_dict, params_dict, request=None):
"""
Returns a Q object from filters config and actual parmeters.
"""
# Building search query
# queries generated by different search_fields are ANDed
# if a search field is defined for more than one field, are put together with OR
and_quer... | [
"def",
"build_q",
"(",
"fields_dict",
",",
"params_dict",
",",
"request",
"=",
"None",
")",
":",
"# Building search query",
"# queries generated by different search_fields are ANDed",
"# if a search field is defined for more than one field, are put together with OR",
"and_query",
"="... | Returns a Q object from filters config and actual parmeters. | [
"Returns",
"a",
"Q",
"object",
"from",
"filters",
"config",
"and",
"actual",
"parmeters",
"."
] | 315cbe8e6cac158884ced02069aa945bc7438dba | https://github.com/inmagik/django-search-views/blob/315cbe8e6cac158884ced02069aa945bc7438dba/search_views/filters.py#L3-L83 | train | 62,243 |
inmagik/django-search-views | search_views/filters.py | BaseFilter.get_search_fields | def get_search_fields(cls):
"""
Returns search fields in sfdict
"""
sfdict = {}
for klass in tuple(cls.__bases__) + (cls, ):
if hasattr(klass, 'search_fields'):
sfdict.update(klass.search_fields)
return sfdict | python | def get_search_fields(cls):
"""
Returns search fields in sfdict
"""
sfdict = {}
for klass in tuple(cls.__bases__) + (cls, ):
if hasattr(klass, 'search_fields'):
sfdict.update(klass.search_fields)
return sfdict | [
"def",
"get_search_fields",
"(",
"cls",
")",
":",
"sfdict",
"=",
"{",
"}",
"for",
"klass",
"in",
"tuple",
"(",
"cls",
".",
"__bases__",
")",
"+",
"(",
"cls",
",",
")",
":",
"if",
"hasattr",
"(",
"klass",
",",
"'search_fields'",
")",
":",
"sfdict",
... | Returns search fields in sfdict | [
"Returns",
"search",
"fields",
"in",
"sfdict"
] | 315cbe8e6cac158884ced02069aa945bc7438dba | https://github.com/inmagik/django-search-views/blob/315cbe8e6cac158884ced02069aa945bc7438dba/search_views/filters.py#L100-L108 | train | 62,244 |
jgorset/django-respite | respite/formats.py | find | def find(identifier):
"""
Find and return a format by name, acronym or extension.
:param identifier: A string describing the format.
"""
for format in FORMATS:
if identifier in [format.name, format.acronym, format.extension]:
return format
raise UnknownFormat('No format fou... | python | def find(identifier):
"""
Find and return a format by name, acronym or extension.
:param identifier: A string describing the format.
"""
for format in FORMATS:
if identifier in [format.name, format.acronym, format.extension]:
return format
raise UnknownFormat('No format fou... | [
"def",
"find",
"(",
"identifier",
")",
":",
"for",
"format",
"in",
"FORMATS",
":",
"if",
"identifier",
"in",
"[",
"format",
".",
"name",
",",
"format",
".",
"acronym",
",",
"format",
".",
"extension",
"]",
":",
"return",
"format",
"raise",
"UnknownFormat... | Find and return a format by name, acronym or extension.
:param identifier: A string describing the format. | [
"Find",
"and",
"return",
"a",
"format",
"by",
"name",
"acronym",
"or",
"extension",
"."
] | 719469d11baf91d05917bab1623bd82adc543546 | https://github.com/jgorset/django-respite/blob/719469d11baf91d05917bab1623bd82adc543546/respite/formats.py#L45-L55 | train | 62,245 |
jgorset/django-respite | respite/formats.py | find_by_name | def find_by_name(name):
"""
Find and return a format by name.
:param name: A string describing the name of the format.
"""
for format in FORMATS:
if name == format.name:
return format
raise UnknownFormat('No format found with name "%s"' % name) | python | def find_by_name(name):
"""
Find and return a format by name.
:param name: A string describing the name of the format.
"""
for format in FORMATS:
if name == format.name:
return format
raise UnknownFormat('No format found with name "%s"' % name) | [
"def",
"find_by_name",
"(",
"name",
")",
":",
"for",
"format",
"in",
"FORMATS",
":",
"if",
"name",
"==",
"format",
".",
"name",
":",
"return",
"format",
"raise",
"UnknownFormat",
"(",
"'No format found with name \"%s\"'",
"%",
"name",
")"
] | Find and return a format by name.
:param name: A string describing the name of the format. | [
"Find",
"and",
"return",
"a",
"format",
"by",
"name",
"."
] | 719469d11baf91d05917bab1623bd82adc543546 | https://github.com/jgorset/django-respite/blob/719469d11baf91d05917bab1623bd82adc543546/respite/formats.py#L57-L67 | train | 62,246 |
jgorset/django-respite | respite/formats.py | find_by_extension | def find_by_extension(extension):
"""
Find and return a format by extension.
:param extension: A string describing the extension of the format.
"""
for format in FORMATS:
if extension in format.extensions:
return format
raise UnknownFormat('No format found with extension "%... | python | def find_by_extension(extension):
"""
Find and return a format by extension.
:param extension: A string describing the extension of the format.
"""
for format in FORMATS:
if extension in format.extensions:
return format
raise UnknownFormat('No format found with extension "%... | [
"def",
"find_by_extension",
"(",
"extension",
")",
":",
"for",
"format",
"in",
"FORMATS",
":",
"if",
"extension",
"in",
"format",
".",
"extensions",
":",
"return",
"format",
"raise",
"UnknownFormat",
"(",
"'No format found with extension \"%s\"'",
"%",
"extension",
... | Find and return a format by extension.
:param extension: A string describing the extension of the format. | [
"Find",
"and",
"return",
"a",
"format",
"by",
"extension",
"."
] | 719469d11baf91d05917bab1623bd82adc543546 | https://github.com/jgorset/django-respite/blob/719469d11baf91d05917bab1623bd82adc543546/respite/formats.py#L69-L79 | train | 62,247 |
jgorset/django-respite | respite/formats.py | find_by_content_type | def find_by_content_type(content_type):
"""
Find and return a format by content type.
:param content_type: A string describing the internet media type of the format.
"""
for format in FORMATS:
if content_type in format.content_types:
return format
raise UnknownFormat('No fo... | python | def find_by_content_type(content_type):
"""
Find and return a format by content type.
:param content_type: A string describing the internet media type of the format.
"""
for format in FORMATS:
if content_type in format.content_types:
return format
raise UnknownFormat('No fo... | [
"def",
"find_by_content_type",
"(",
"content_type",
")",
":",
"for",
"format",
"in",
"FORMATS",
":",
"if",
"content_type",
"in",
"format",
".",
"content_types",
":",
"return",
"format",
"raise",
"UnknownFormat",
"(",
"'No format found with content type \"%s\"'",
"%",
... | Find and return a format by content type.
:param content_type: A string describing the internet media type of the format. | [
"Find",
"and",
"return",
"a",
"format",
"by",
"content",
"type",
"."
] | 719469d11baf91d05917bab1623bd82adc543546 | https://github.com/jgorset/django-respite/blob/719469d11baf91d05917bab1623bd82adc543546/respite/formats.py#L81-L91 | train | 62,248 |
jgorset/django-respite | respite/views/views.py | Views.options | def options(self, request, map, *args, **kwargs):
"""List communication options."""
options = {}
for method, function in map.items():
options[method] = function.__doc__
return self._render(
request = request,
template = 'options',
context ... | python | def options(self, request, map, *args, **kwargs):
"""List communication options."""
options = {}
for method, function in map.items():
options[method] = function.__doc__
return self._render(
request = request,
template = 'options',
context ... | [
"def",
"options",
"(",
"self",
",",
"request",
",",
"map",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"options",
"=",
"{",
"}",
"for",
"method",
",",
"function",
"in",
"map",
".",
"items",
"(",
")",
":",
"options",
"[",
"method",
"]",
... | List communication options. | [
"List",
"communication",
"options",
"."
] | 719469d11baf91d05917bab1623bd82adc543546 | https://github.com/jgorset/django-respite/blob/719469d11baf91d05917bab1623bd82adc543546/respite/views/views.py#L23-L39 | train | 62,249 |
jgorset/django-respite | respite/views/views.py | Views._get_format | def _get_format(self, request):
"""
Determine and return a 'formats.Format' instance describing the most desired response format
that is supported by these views.
:param request: A django.http.HttpRequest instance.
Formats specified by extension (e.g. '/articles/index.html') ta... | python | def _get_format(self, request):
"""
Determine and return a 'formats.Format' instance describing the most desired response format
that is supported by these views.
:param request: A django.http.HttpRequest instance.
Formats specified by extension (e.g. '/articles/index.html') ta... | [
"def",
"_get_format",
"(",
"self",
",",
"request",
")",
":",
"# Derive a list of 'formats.Format' instances from the list of formats these views support.",
"supported_formats",
"=",
"[",
"formats",
".",
"find",
"(",
"format",
")",
"for",
"format",
"in",
"self",
".",
"su... | Determine and return a 'formats.Format' instance describing the most desired response format
that is supported by these views.
:param request: A django.http.HttpRequest instance.
Formats specified by extension (e.g. '/articles/index.html') take precedence over formats
given in the HTTP... | [
"Determine",
"and",
"return",
"a",
"formats",
".",
"Format",
"instance",
"describing",
"the",
"most",
"desired",
"response",
"format",
"that",
"is",
"supported",
"by",
"these",
"views",
"."
] | 719469d11baf91d05917bab1623bd82adc543546 | https://github.com/jgorset/django-respite/blob/719469d11baf91d05917bab1623bd82adc543546/respite/views/views.py#L41-L105 | train | 62,250 |
jgorset/django-respite | respite/views/views.py | Views._render | def _render(self, request, template=None, status=200, context={}, headers={}, prefix_template_path=True):
"""
Render a HTTP response.
:param request: A django.http.HttpRequest instance.
:param template: A string describing the path to a template.
:param status: An integer descri... | python | def _render(self, request, template=None, status=200, context={}, headers={}, prefix_template_path=True):
"""
Render a HTTP response.
:param request: A django.http.HttpRequest instance.
:param template: A string describing the path to a template.
:param status: An integer descri... | [
"def",
"_render",
"(",
"self",
",",
"request",
",",
"template",
"=",
"None",
",",
"status",
"=",
"200",
",",
"context",
"=",
"{",
"}",
",",
"headers",
"=",
"{",
"}",
",",
"prefix_template_path",
"=",
"True",
")",
":",
"format",
"=",
"self",
".",
"_... | Render a HTTP response.
:param request: A django.http.HttpRequest instance.
:param template: A string describing the path to a template.
:param status: An integer describing the HTTP status code to respond with.
:param context: A dictionary describing variables to populate the template ... | [
"Render",
"a",
"HTTP",
"response",
"."
] | 719469d11baf91d05917bab1623bd82adc543546 | https://github.com/jgorset/django-respite/blob/719469d11baf91d05917bab1623bd82adc543546/respite/views/views.py#L107-L188 | train | 62,251 |
jgorset/django-respite | respite/views/views.py | Views._error | def _error(self, request, status, headers={}, prefix_template_path=False, **kwargs):
"""
Convenience method to render an error response. The template is inferred from the status code.
:param request: A django.http.HttpRequest instance.
:param status: An integer describing the HTTP statu... | python | def _error(self, request, status, headers={}, prefix_template_path=False, **kwargs):
"""
Convenience method to render an error response. The template is inferred from the status code.
:param request: A django.http.HttpRequest instance.
:param status: An integer describing the HTTP statu... | [
"def",
"_error",
"(",
"self",
",",
"request",
",",
"status",
",",
"headers",
"=",
"{",
"}",
",",
"prefix_template_path",
"=",
"False",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"self",
".",
"_render",
"(",
"request",
"=",
"request",
",",
"template",... | Convenience method to render an error response. The template is inferred from the status code.
:param request: A django.http.HttpRequest instance.
:param status: An integer describing the HTTP status code to respond with.
:param headers: A dictionary describing HTTP headers.
:param pref... | [
"Convenience",
"method",
"to",
"render",
"an",
"error",
"response",
".",
"The",
"template",
"is",
"inferred",
"from",
"the",
"status",
"code",
"."
] | 719469d11baf91d05917bab1623bd82adc543546 | https://github.com/jgorset/django-respite/blob/719469d11baf91d05917bab1623bd82adc543546/respite/views/views.py#L190-L212 | train | 62,252 |
jgorset/django-respite | respite/serializers/__init__.py | find | def find(format):
"""
Find and return a serializer for the given format.
Arguments:
format -- A Format instance.
"""
try:
serializer = SERIALIZERS[format]
except KeyError:
raise UnknownSerializer('No serializer found for %s' % format.acronym)
return serializer | python | def find(format):
"""
Find and return a serializer for the given format.
Arguments:
format -- A Format instance.
"""
try:
serializer = SERIALIZERS[format]
except KeyError:
raise UnknownSerializer('No serializer found for %s' % format.acronym)
return serializer | [
"def",
"find",
"(",
"format",
")",
":",
"try",
":",
"serializer",
"=",
"SERIALIZERS",
"[",
"format",
"]",
"except",
"KeyError",
":",
"raise",
"UnknownSerializer",
"(",
"'No serializer found for %s'",
"%",
"format",
".",
"acronym",
")",
"return",
"serializer"
] | Find and return a serializer for the given format.
Arguments:
format -- A Format instance. | [
"Find",
"and",
"return",
"a",
"serializer",
"for",
"the",
"given",
"format",
"."
] | 719469d11baf91d05917bab1623bd82adc543546 | https://github.com/jgorset/django-respite/blob/719469d11baf91d05917bab1623bd82adc543546/respite/serializers/__init__.py#L12-L24 | train | 62,253 |
inmagik/django-search-views | search_views/views.py | SearchListView.get_form_kwargs | def get_form_kwargs(self):
"""
Returns the keyword arguments for instantiating the search form.
"""
update_data ={}
sfdict = self.filter_class.get_search_fields()
for fieldname in sfdict:
try:
has_multiple = sfdict[fieldname].get('multiple', Fa... | python | def get_form_kwargs(self):
"""
Returns the keyword arguments for instantiating the search form.
"""
update_data ={}
sfdict = self.filter_class.get_search_fields()
for fieldname in sfdict:
try:
has_multiple = sfdict[fieldname].get('multiple', Fa... | [
"def",
"get_form_kwargs",
"(",
"self",
")",
":",
"update_data",
"=",
"{",
"}",
"sfdict",
"=",
"self",
".",
"filter_class",
".",
"get_search_fields",
"(",
")",
"for",
"fieldname",
"in",
"sfdict",
":",
"try",
":",
"has_multiple",
"=",
"sfdict",
"[",
"fieldna... | Returns the keyword arguments for instantiating the search form. | [
"Returns",
"the",
"keyword",
"arguments",
"for",
"instantiating",
"the",
"search",
"form",
"."
] | 315cbe8e6cac158884ced02069aa945bc7438dba | https://github.com/inmagik/django-search-views/blob/315cbe8e6cac158884ced02069aa945bc7438dba/search_views/views.py#L42-L76 | train | 62,254 |
jgorset/django-respite | respite/inflector.py | pluralize | def pluralize(word) :
"""Pluralize an English noun."""
rules = [
['(?i)(quiz)$' , '\\1zes'],
['^(?i)(ox)$' , '\\1en'],
['(?i)([m|l])ouse$' , '\\1ice'],
['(?i)(matr|vert|ind)ix|ex$' , '\\1ices'],
['(?i)(x|ch|ss|sh)$' , '\\1es'],
['(... | python | def pluralize(word) :
"""Pluralize an English noun."""
rules = [
['(?i)(quiz)$' , '\\1zes'],
['^(?i)(ox)$' , '\\1en'],
['(?i)([m|l])ouse$' , '\\1ice'],
['(?i)(matr|vert|ind)ix|ex$' , '\\1ices'],
['(?i)(x|ch|ss|sh)$' , '\\1es'],
['(... | [
"def",
"pluralize",
"(",
"word",
")",
":",
"rules",
"=",
"[",
"[",
"'(?i)(quiz)$'",
",",
"'\\\\1zes'",
"]",
",",
"[",
"'^(?i)(ox)$'",
",",
"'\\\\1en'",
"]",
",",
"[",
"'(?i)([m|l])ouse$'",
",",
"'\\\\1ice'",
"]",
",",
"[",
"'(?i)(matr|vert|ind)ix|ex$'",
",",... | Pluralize an English noun. | [
"Pluralize",
"an",
"English",
"noun",
"."
] | 719469d11baf91d05917bab1623bd82adc543546 | https://github.com/jgorset/django-respite/blob/719469d11baf91d05917bab1623bd82adc543546/respite/inflector.py#L3-L58 | train | 62,255 |
jgorset/django-respite | respite/inflector.py | us2mc | def us2mc(string):
"""Transform an underscore_case string to a mixedCase string"""
return re.sub(r'_([a-z])', lambda m: (m.group(1).upper()), string) | python | def us2mc(string):
"""Transform an underscore_case string to a mixedCase string"""
return re.sub(r'_([a-z])', lambda m: (m.group(1).upper()), string) | [
"def",
"us2mc",
"(",
"string",
")",
":",
"return",
"re",
".",
"sub",
"(",
"r'_([a-z])'",
",",
"lambda",
"m",
":",
"(",
"m",
".",
"group",
"(",
"1",
")",
".",
"upper",
"(",
")",
")",
",",
"string",
")"
] | Transform an underscore_case string to a mixedCase string | [
"Transform",
"an",
"underscore_case",
"string",
"to",
"a",
"mixedCase",
"string"
] | 719469d11baf91d05917bab1623bd82adc543546 | https://github.com/jgorset/django-respite/blob/719469d11baf91d05917bab1623bd82adc543546/respite/inflector.py#L131-L133 | train | 62,256 |
jgorset/django-respite | respite/utils/__init__.py | generate_form | def generate_form(model, form=None, fields=False, exclude=False):
"""
Generate a form from a model.
:param model: A Django model.
:param form: A Django form.
:param fields: A list of fields to include in this form.
:param exclude: A list of fields to exclude in this form.
"""
_model, _f... | python | def generate_form(model, form=None, fields=False, exclude=False):
"""
Generate a form from a model.
:param model: A Django model.
:param form: A Django form.
:param fields: A list of fields to include in this form.
:param exclude: A list of fields to exclude in this form.
"""
_model, _f... | [
"def",
"generate_form",
"(",
"model",
",",
"form",
"=",
"None",
",",
"fields",
"=",
"False",
",",
"exclude",
"=",
"False",
")",
":",
"_model",
",",
"_fields",
",",
"_exclude",
"=",
"model",
",",
"fields",
",",
"exclude",
"class",
"Form",
"(",
"form",
... | Generate a form from a model.
:param model: A Django model.
:param form: A Django form.
:param fields: A list of fields to include in this form.
:param exclude: A list of fields to exclude in this form. | [
"Generate",
"a",
"form",
"from",
"a",
"model",
"."
] | 719469d11baf91d05917bab1623bd82adc543546 | https://github.com/jgorset/django-respite/blob/719469d11baf91d05917bab1623bd82adc543546/respite/utils/__init__.py#L5-L26 | train | 62,257 |
pkgw/pwkit | pwkit/msmt.py | sample_double_norm | def sample_double_norm(mean, std_upper, std_lower, size):
"""Note that this function requires Scipy."""
from scipy.special import erfinv
# There's probably a better way to do this. We first draw percentiles
# uniformly between 0 and 1. We want the peak of the distribution to occur
# at `mean`. Howe... | python | def sample_double_norm(mean, std_upper, std_lower, size):
"""Note that this function requires Scipy."""
from scipy.special import erfinv
# There's probably a better way to do this. We first draw percentiles
# uniformly between 0 and 1. We want the peak of the distribution to occur
# at `mean`. Howe... | [
"def",
"sample_double_norm",
"(",
"mean",
",",
"std_upper",
",",
"std_lower",
",",
"size",
")",
":",
"from",
"scipy",
".",
"special",
"import",
"erfinv",
"# There's probably a better way to do this. We first draw percentiles",
"# uniformly between 0 and 1. We want the peak of t... | Note that this function requires Scipy. | [
"Note",
"that",
"this",
"function",
"requires",
"Scipy",
"."
] | d40957a1c3d2ea34e7ceac2267ee9635135f2793 | https://github.com/pkgw/pwkit/blob/d40957a1c3d2ea34e7ceac2267ee9635135f2793/pwkit/msmt.py#L125-L153 | train | 62,258 |
pkgw/pwkit | pwkit/msmt.py | find_gamma_params | def find_gamma_params(mode, std):
"""Given a modal value and a standard deviation, compute corresponding
parameters for the gamma distribution.
Intended to be used to replace normal distributions when the value must be
positive and the uncertainty is comparable to the best value. Conversion
equatio... | python | def find_gamma_params(mode, std):
"""Given a modal value and a standard deviation, compute corresponding
parameters for the gamma distribution.
Intended to be used to replace normal distributions when the value must be
positive and the uncertainty is comparable to the best value. Conversion
equatio... | [
"def",
"find_gamma_params",
"(",
"mode",
",",
"std",
")",
":",
"if",
"mode",
"<",
"0",
":",
"raise",
"ValueError",
"(",
"'input mode must be positive for gamma; got %e'",
"%",
"mode",
")",
"var",
"=",
"std",
"**",
"2",
"beta",
"=",
"(",
"mode",
"+",
"np",
... | Given a modal value and a standard deviation, compute corresponding
parameters for the gamma distribution.
Intended to be used to replace normal distributions when the value must be
positive and the uncertainty is comparable to the best value. Conversion
equations determined from the relations given in... | [
"Given",
"a",
"modal",
"value",
"and",
"a",
"standard",
"deviation",
"compute",
"corresponding",
"parameters",
"for",
"the",
"gamma",
"distribution",
"."
] | d40957a1c3d2ea34e7ceac2267ee9635135f2793 | https://github.com/pkgw/pwkit/blob/d40957a1c3d2ea34e7ceac2267ee9635135f2793/pwkit/msmt.py#L179-L201 | train | 62,259 |
pkgw/pwkit | pwkit/msmt.py | _lval_add_towards_polarity | def _lval_add_towards_polarity(x, polarity):
"""Compute the appropriate Lval "kind" for the limit of value `x` towards
`polarity`. Either 'toinf' or 'pastzero' depending on the sign of `x` and
the infinity direction of polarity.
"""
if x < 0:
if polarity < 0:
return Lval('toinf'... | python | def _lval_add_towards_polarity(x, polarity):
"""Compute the appropriate Lval "kind" for the limit of value `x` towards
`polarity`. Either 'toinf' or 'pastzero' depending on the sign of `x` and
the infinity direction of polarity.
"""
if x < 0:
if polarity < 0:
return Lval('toinf'... | [
"def",
"_lval_add_towards_polarity",
"(",
"x",
",",
"polarity",
")",
":",
"if",
"x",
"<",
"0",
":",
"if",
"polarity",
"<",
"0",
":",
"return",
"Lval",
"(",
"'toinf'",
",",
"x",
")",
"return",
"Lval",
"(",
"'pastzero'",
",",
"x",
")",
"elif",
"polarit... | Compute the appropriate Lval "kind" for the limit of value `x` towards
`polarity`. Either 'toinf' or 'pastzero' depending on the sign of `x` and
the infinity direction of polarity. | [
"Compute",
"the",
"appropriate",
"Lval",
"kind",
"for",
"the",
"limit",
"of",
"value",
"x",
"towards",
"polarity",
".",
"Either",
"toinf",
"or",
"pastzero",
"depending",
"on",
"the",
"sign",
"of",
"x",
"and",
"the",
"infinity",
"direction",
"of",
"polarity",... | d40957a1c3d2ea34e7ceac2267ee9635135f2793 | https://github.com/pkgw/pwkit/blob/d40957a1c3d2ea34e7ceac2267ee9635135f2793/pwkit/msmt.py#L806-L818 | train | 62,260 |
pkgw/pwkit | pwkit/msmt.py | limtype | def limtype(msmt):
"""Return -1 if this value is some kind of upper limit, 1 if this value
is some kind of lower limit, 0 otherwise."""
if np.isscalar(msmt):
return 0
if isinstance(msmt, Uval):
return 0
if isinstance(msmt, Lval):
if msmt.kind == 'undef':
raise Va... | python | def limtype(msmt):
"""Return -1 if this value is some kind of upper limit, 1 if this value
is some kind of lower limit, 0 otherwise."""
if np.isscalar(msmt):
return 0
if isinstance(msmt, Uval):
return 0
if isinstance(msmt, Lval):
if msmt.kind == 'undef':
raise Va... | [
"def",
"limtype",
"(",
"msmt",
")",
":",
"if",
"np",
".",
"isscalar",
"(",
"msmt",
")",
":",
"return",
"0",
"if",
"isinstance",
"(",
"msmt",
",",
"Uval",
")",
":",
"return",
"0",
"if",
"isinstance",
"(",
"msmt",
",",
"Lval",
")",
":",
"if",
"msmt... | Return -1 if this value is some kind of upper limit, 1 if this value
is some kind of lower limit, 0 otherwise. | [
"Return",
"-",
"1",
"if",
"this",
"value",
"is",
"some",
"kind",
"of",
"upper",
"limit",
"1",
"if",
"this",
"value",
"is",
"some",
"kind",
"of",
"lower",
"limit",
"0",
"otherwise",
"."
] | d40957a1c3d2ea34e7ceac2267ee9635135f2793 | https://github.com/pkgw/pwkit/blob/d40957a1c3d2ea34e7ceac2267ee9635135f2793/pwkit/msmt.py#L1903-L1927 | train | 62,261 |
pkgw/pwkit | pwkit/msmt.py | Uval.from_pcount | def from_pcount(nevents):
"""We assume a Poisson process. nevents is the number of events in
some interval. The distribution of values is the distribution of the
Poisson rate parameter given this observed number of events, where the
"rate" is in units of events per interval of the same d... | python | def from_pcount(nevents):
"""We assume a Poisson process. nevents is the number of events in
some interval. The distribution of values is the distribution of the
Poisson rate parameter given this observed number of events, where the
"rate" is in units of events per interval of the same d... | [
"def",
"from_pcount",
"(",
"nevents",
")",
":",
"if",
"nevents",
"<",
"0",
":",
"raise",
"ValueError",
"(",
"'Poisson parameter `nevents` must be nonnegative'",
")",
"return",
"Uval",
"(",
"np",
".",
"random",
".",
"gamma",
"(",
"nevents",
"+",
"1",
",",
"si... | We assume a Poisson process. nevents is the number of events in
some interval. The distribution of values is the distribution of the
Poisson rate parameter given this observed number of events, where the
"rate" is in units of events per interval of the same duration. The
max-likelihood v... | [
"We",
"assume",
"a",
"Poisson",
"process",
".",
"nevents",
"is",
"the",
"number",
"of",
"events",
"in",
"some",
"interval",
".",
"The",
"distribution",
"of",
"values",
"is",
"the",
"distribution",
"of",
"the",
"Poisson",
"rate",
"parameter",
"given",
"this",... | d40957a1c3d2ea34e7ceac2267ee9635135f2793 | https://github.com/pkgw/pwkit/blob/d40957a1c3d2ea34e7ceac2267ee9635135f2793/pwkit/msmt.py#L353-L363 | train | 62,262 |
pkgw/pwkit | pwkit/msmt.py | Uval.repvals | def repvals(self, method):
"""Compute representative statistical values for this Uval. `method`
may be either 'pct' or 'gauss'.
Returns (best, plus_one_sigma, minus_one_sigma), where `best` is the
"best" value in some sense, and the others correspond to values at
the ~84 and 16 ... | python | def repvals(self, method):
"""Compute representative statistical values for this Uval. `method`
may be either 'pct' or 'gauss'.
Returns (best, plus_one_sigma, minus_one_sigma), where `best` is the
"best" value in some sense, and the others correspond to values at
the ~84 and 16 ... | [
"def",
"repvals",
"(",
"self",
",",
"method",
")",
":",
"if",
"method",
"==",
"'pct'",
":",
"return",
"pk_scoreatpercentile",
"(",
"self",
".",
"d",
",",
"[",
"50.",
",",
"84.134",
",",
"15.866",
"]",
")",
"if",
"method",
"==",
"'gauss'",
":",
"m",
... | Compute representative statistical values for this Uval. `method`
may be either 'pct' or 'gauss'.
Returns (best, plus_one_sigma, minus_one_sigma), where `best` is the
"best" value in some sense, and the others correspond to values at
the ~84 and 16 percentile limits, respectively. Becau... | [
"Compute",
"representative",
"statistical",
"values",
"for",
"this",
"Uval",
".",
"method",
"may",
"be",
"either",
"pct",
"or",
"gauss",
"."
] | d40957a1c3d2ea34e7ceac2267ee9635135f2793 | https://github.com/pkgw/pwkit/blob/d40957a1c3d2ea34e7ceac2267ee9635135f2793/pwkit/msmt.py#L374-L396 | train | 62,263 |
pkgw/pwkit | pwkit/msmt.py | Textual.repval | def repval(self, limitsok=False):
"""Get a best-effort representative value as a float. This can be
DANGEROUS because it discards limit information, which is rarely wise."""
if not limitsok and self.dkind in ('lower', 'upper'):
raise LimitError()
if self.dkind == 'unif':
... | python | def repval(self, limitsok=False):
"""Get a best-effort representative value as a float. This can be
DANGEROUS because it discards limit information, which is rarely wise."""
if not limitsok and self.dkind in ('lower', 'upper'):
raise LimitError()
if self.dkind == 'unif':
... | [
"def",
"repval",
"(",
"self",
",",
"limitsok",
"=",
"False",
")",
":",
"if",
"not",
"limitsok",
"and",
"self",
".",
"dkind",
"in",
"(",
"'lower'",
",",
"'upper'",
")",
":",
"raise",
"LimitError",
"(",
")",
"if",
"self",
".",
"dkind",
"==",
"'unif'",
... | Get a best-effort representative value as a float. This can be
DANGEROUS because it discards limit information, which is rarely wise. | [
"Get",
"a",
"best",
"-",
"effort",
"representative",
"value",
"as",
"a",
"float",
".",
"This",
"can",
"be",
"DANGEROUS",
"because",
"it",
"discards",
"limit",
"information",
"which",
"is",
"rarely",
"wise",
"."
] | d40957a1c3d2ea34e7ceac2267ee9635135f2793 | https://github.com/pkgw/pwkit/blob/d40957a1c3d2ea34e7ceac2267ee9635135f2793/pwkit/msmt.py#L1662-L1681 | train | 62,264 |
pkgw/pwkit | pwkit/colormaps.py | moreland_adjusthue | def moreland_adjusthue (msh, m_unsat):
"""Moreland's AdjustHue procedure to adjust the hue value of an Msh color
based on ... some criterion.
*msh* should be of of shape (3, ). *m_unsat* is a scalar.
Return value is the adjusted h (hue) value.
"""
if msh[M] >= m_unsat:
return msh[H] #... | python | def moreland_adjusthue (msh, m_unsat):
"""Moreland's AdjustHue procedure to adjust the hue value of an Msh color
based on ... some criterion.
*msh* should be of of shape (3, ). *m_unsat* is a scalar.
Return value is the adjusted h (hue) value.
"""
if msh[M] >= m_unsat:
return msh[H] #... | [
"def",
"moreland_adjusthue",
"(",
"msh",
",",
"m_unsat",
")",
":",
"if",
"msh",
"[",
"M",
"]",
">=",
"m_unsat",
":",
"return",
"msh",
"[",
"H",
"]",
"# \"Best we can do\"",
"hspin",
"=",
"(",
"msh",
"[",
"S",
"]",
"*",
"np",
".",
"sqrt",
"(",
"m_un... | Moreland's AdjustHue procedure to adjust the hue value of an Msh color
based on ... some criterion.
*msh* should be of of shape (3, ). *m_unsat* is a scalar.
Return value is the adjusted h (hue) value. | [
"Moreland",
"s",
"AdjustHue",
"procedure",
"to",
"adjust",
"the",
"hue",
"value",
"of",
"an",
"Msh",
"color",
"based",
"on",
"...",
"some",
"criterion",
"."
] | d40957a1c3d2ea34e7ceac2267ee9635135f2793 | https://github.com/pkgw/pwkit/blob/d40957a1c3d2ea34e7ceac2267ee9635135f2793/pwkit/colormaps.py#L322-L339 | train | 62,265 |
kapadia/usgs | scripts/get_datasets_in_node.py | get_datasets_in_nodes | def get_datasets_in_nodes():
"""
Get the node associated with each dataset. Some datasets
will have an ambiguous node since they exists in more than
one node.
"""
data_dir = os.path.join(scriptdir, "..", "usgs", "data")
cwic = map(lambda d: d["datasetName"], api.datasets(None, CWIC_LSI_EXP... | python | def get_datasets_in_nodes():
"""
Get the node associated with each dataset. Some datasets
will have an ambiguous node since they exists in more than
one node.
"""
data_dir = os.path.join(scriptdir, "..", "usgs", "data")
cwic = map(lambda d: d["datasetName"], api.datasets(None, CWIC_LSI_EXP... | [
"def",
"get_datasets_in_nodes",
"(",
")",
":",
"data_dir",
"=",
"os",
".",
"path",
".",
"join",
"(",
"scriptdir",
",",
"\"..\"",
",",
"\"usgs\"",
",",
"\"data\"",
")",
"cwic",
"=",
"map",
"(",
"lambda",
"d",
":",
"d",
"[",
"\"datasetName\"",
"]",
",",
... | Get the node associated with each dataset. Some datasets
will have an ambiguous node since they exists in more than
one node. | [
"Get",
"the",
"node",
"associated",
"with",
"each",
"dataset",
".",
"Some",
"datasets",
"will",
"have",
"an",
"ambiguous",
"node",
"since",
"they",
"exists",
"in",
"more",
"than",
"one",
"node",
"."
] | 0608346f0bc3c34e20f4ecc77ad71d0b514db7ee | https://github.com/kapadia/usgs/blob/0608346f0bc3c34e20f4ecc77ad71d0b514db7ee/scripts/get_datasets_in_node.py#L13-L44 | train | 62,266 |
pkgw/pwkit | pwkit/synphot.py | pivot_wavelength_ee | def pivot_wavelength_ee(bpass):
"""Compute pivot wavelength assuming equal-energy convention.
`bpass` should have two properties, `resp` and `wlen`. The units of `wlen`
can be anything, and `resp` need not be normalized in any particular way.
"""
from scipy.integrate import simps
return np.sqr... | python | def pivot_wavelength_ee(bpass):
"""Compute pivot wavelength assuming equal-energy convention.
`bpass` should have two properties, `resp` and `wlen`. The units of `wlen`
can be anything, and `resp` need not be normalized in any particular way.
"""
from scipy.integrate import simps
return np.sqr... | [
"def",
"pivot_wavelength_ee",
"(",
"bpass",
")",
":",
"from",
"scipy",
".",
"integrate",
"import",
"simps",
"return",
"np",
".",
"sqrt",
"(",
"simps",
"(",
"bpass",
".",
"resp",
",",
"bpass",
".",
"wlen",
")",
"/",
"simps",
"(",
"bpass",
".",
"resp",
... | Compute pivot wavelength assuming equal-energy convention.
`bpass` should have two properties, `resp` and `wlen`. The units of `wlen`
can be anything, and `resp` need not be normalized in any particular way. | [
"Compute",
"pivot",
"wavelength",
"assuming",
"equal",
"-",
"energy",
"convention",
"."
] | d40957a1c3d2ea34e7ceac2267ee9635135f2793 | https://github.com/pkgw/pwkit/blob/d40957a1c3d2ea34e7ceac2267ee9635135f2793/pwkit/synphot.py#L169-L178 | train | 62,267 |
pkgw/pwkit | pwkit/synphot.py | get_std_registry | def get_std_registry():
"""Get a Registry object pre-filled with information for standard
telescopes.
"""
from six import itervalues
reg = Registry()
for fn in itervalues(builtin_registrars):
fn(reg)
return reg | python | def get_std_registry():
"""Get a Registry object pre-filled with information for standard
telescopes.
"""
from six import itervalues
reg = Registry()
for fn in itervalues(builtin_registrars):
fn(reg)
return reg | [
"def",
"get_std_registry",
"(",
")",
":",
"from",
"six",
"import",
"itervalues",
"reg",
"=",
"Registry",
"(",
")",
"for",
"fn",
"in",
"itervalues",
"(",
"builtin_registrars",
")",
":",
"fn",
"(",
"reg",
")",
"return",
"reg"
] | Get a Registry object pre-filled with information for standard
telescopes. | [
"Get",
"a",
"Registry",
"object",
"pre",
"-",
"filled",
"with",
"information",
"for",
"standard",
"telescopes",
"."
] | d40957a1c3d2ea34e7ceac2267ee9635135f2793 | https://github.com/pkgw/pwkit/blob/d40957a1c3d2ea34e7ceac2267ee9635135f2793/pwkit/synphot.py#L513-L522 | train | 62,268 |
pkgw/pwkit | pwkit/synphot.py | Bandpass.pivot_wavelength | def pivot_wavelength(self):
"""Get the bandpass' pivot wavelength.
Unlike calc_pivot_wavelength(), this function will use a cached
value if available.
"""
wl = self.registry._pivot_wavelengths.get((self.telescope, self.band))
if wl is not None:
return wl
... | python | def pivot_wavelength(self):
"""Get the bandpass' pivot wavelength.
Unlike calc_pivot_wavelength(), this function will use a cached
value if available.
"""
wl = self.registry._pivot_wavelengths.get((self.telescope, self.band))
if wl is not None:
return wl
... | [
"def",
"pivot_wavelength",
"(",
"self",
")",
":",
"wl",
"=",
"self",
".",
"registry",
".",
"_pivot_wavelengths",
".",
"get",
"(",
"(",
"self",
".",
"telescope",
",",
"self",
".",
"band",
")",
")",
"if",
"wl",
"is",
"not",
"None",
":",
"return",
"wl",... | Get the bandpass' pivot wavelength.
Unlike calc_pivot_wavelength(), this function will use a cached
value if available. | [
"Get",
"the",
"bandpass",
"pivot",
"wavelength",
"."
] | d40957a1c3d2ea34e7ceac2267ee9635135f2793 | https://github.com/pkgw/pwkit/blob/d40957a1c3d2ea34e7ceac2267ee9635135f2793/pwkit/synphot.py#L292-L305 | train | 62,269 |
pkgw/pwkit | pwkit/synphot.py | Bandpass.calc_halfmax_points | def calc_halfmax_points(self):
"""Calculate the wavelengths of the filter half-maximum values.
"""
d = self._ensure_data()
return interpolated_halfmax_points(d.wlen, d.resp) | python | def calc_halfmax_points(self):
"""Calculate the wavelengths of the filter half-maximum values.
"""
d = self._ensure_data()
return interpolated_halfmax_points(d.wlen, d.resp) | [
"def",
"calc_halfmax_points",
"(",
"self",
")",
":",
"d",
"=",
"self",
".",
"_ensure_data",
"(",
")",
"return",
"interpolated_halfmax_points",
"(",
"d",
".",
"wlen",
",",
"d",
".",
"resp",
")"
] | Calculate the wavelengths of the filter half-maximum values. | [
"Calculate",
"the",
"wavelengths",
"of",
"the",
"filter",
"half",
"-",
"maximum",
"values",
"."
] | d40957a1c3d2ea34e7ceac2267ee9635135f2793 | https://github.com/pkgw/pwkit/blob/d40957a1c3d2ea34e7ceac2267ee9635135f2793/pwkit/synphot.py#L308-L313 | train | 62,270 |
pkgw/pwkit | pwkit/synphot.py | Bandpass.halfmax_points | def halfmax_points(self):
"""Get the bandpass' half-maximum wavelengths. These can be used to
compute a representative bandwidth, or for display purposes.
Unlike calc_halfmax_points(), this function will use a cached value if
available.
"""
t = self.registry._halfmaxes.... | python | def halfmax_points(self):
"""Get the bandpass' half-maximum wavelengths. These can be used to
compute a representative bandwidth, or for display purposes.
Unlike calc_halfmax_points(), this function will use a cached value if
available.
"""
t = self.registry._halfmaxes.... | [
"def",
"halfmax_points",
"(",
"self",
")",
":",
"t",
"=",
"self",
".",
"registry",
".",
"_halfmaxes",
".",
"get",
"(",
"(",
"self",
".",
"telescope",
",",
"self",
".",
"band",
")",
")",
"if",
"t",
"is",
"not",
"None",
":",
"return",
"t",
"t",
"="... | Get the bandpass' half-maximum wavelengths. These can be used to
compute a representative bandwidth, or for display purposes.
Unlike calc_halfmax_points(), this function will use a cached value if
available. | [
"Get",
"the",
"bandpass",
"half",
"-",
"maximum",
"wavelengths",
".",
"These",
"can",
"be",
"used",
"to",
"compute",
"a",
"representative",
"bandwidth",
"or",
"for",
"display",
"purposes",
"."
] | d40957a1c3d2ea34e7ceac2267ee9635135f2793 | https://github.com/pkgw/pwkit/blob/d40957a1c3d2ea34e7ceac2267ee9635135f2793/pwkit/synphot.py#L316-L330 | train | 62,271 |
pkgw/pwkit | pwkit/synphot.py | Registry.bands | def bands(self, telescope):
"""Return a list of bands associated with the specified telescope."""
q = self._seen_bands.get(telescope)
if q is None:
return []
return list(q) | python | def bands(self, telescope):
"""Return a list of bands associated with the specified telescope."""
q = self._seen_bands.get(telescope)
if q is None:
return []
return list(q) | [
"def",
"bands",
"(",
"self",
",",
"telescope",
")",
":",
"q",
"=",
"self",
".",
"_seen_bands",
".",
"get",
"(",
"telescope",
")",
"if",
"q",
"is",
"None",
":",
"return",
"[",
"]",
"return",
"list",
"(",
"q",
")"
] | Return a list of bands associated with the specified telescope. | [
"Return",
"a",
"list",
"of",
"bands",
"associated",
"with",
"the",
"specified",
"telescope",
"."
] | d40957a1c3d2ea34e7ceac2267ee9635135f2793 | https://github.com/pkgw/pwkit/blob/d40957a1c3d2ea34e7ceac2267ee9635135f2793/pwkit/synphot.py#L456-L461 | train | 62,272 |
pkgw/pwkit | pwkit/synphot.py | Registry.register_pivot_wavelength | def register_pivot_wavelength(self, telescope, band, wlen):
"""Register precomputed pivot wavelengths."""
if (telescope, band) in self._pivot_wavelengths:
raise AlreadyDefinedError('pivot wavelength for %s/%s already '
'defined', telescope, band)
... | python | def register_pivot_wavelength(self, telescope, band, wlen):
"""Register precomputed pivot wavelengths."""
if (telescope, band) in self._pivot_wavelengths:
raise AlreadyDefinedError('pivot wavelength for %s/%s already '
'defined', telescope, band)
... | [
"def",
"register_pivot_wavelength",
"(",
"self",
",",
"telescope",
",",
"band",
",",
"wlen",
")",
":",
"if",
"(",
"telescope",
",",
"band",
")",
"in",
"self",
".",
"_pivot_wavelengths",
":",
"raise",
"AlreadyDefinedError",
"(",
"'pivot wavelength for %s/%s already... | Register precomputed pivot wavelengths. | [
"Register",
"precomputed",
"pivot",
"wavelengths",
"."
] | d40957a1c3d2ea34e7ceac2267ee9635135f2793 | https://github.com/pkgw/pwkit/blob/d40957a1c3d2ea34e7ceac2267ee9635135f2793/pwkit/synphot.py#L464-L471 | train | 62,273 |
pkgw/pwkit | pwkit/synphot.py | Registry.register_halfmaxes | def register_halfmaxes(self, telescope, band, lower, upper):
"""Register precomputed half-max points."""
if (telescope, band) in self._halfmaxes:
raise AlreadyDefinedError('half-max points for %s/%s already '
'defined', telescope, band)
self._no... | python | def register_halfmaxes(self, telescope, band, lower, upper):
"""Register precomputed half-max points."""
if (telescope, band) in self._halfmaxes:
raise AlreadyDefinedError('half-max points for %s/%s already '
'defined', telescope, band)
self._no... | [
"def",
"register_halfmaxes",
"(",
"self",
",",
"telescope",
",",
"band",
",",
"lower",
",",
"upper",
")",
":",
"if",
"(",
"telescope",
",",
"band",
")",
"in",
"self",
".",
"_halfmaxes",
":",
"raise",
"AlreadyDefinedError",
"(",
"'half-max points for %s/%s alre... | Register precomputed half-max points. | [
"Register",
"precomputed",
"half",
"-",
"max",
"points",
"."
] | d40957a1c3d2ea34e7ceac2267ee9635135f2793 | https://github.com/pkgw/pwkit/blob/d40957a1c3d2ea34e7ceac2267ee9635135f2793/pwkit/synphot.py#L474-L482 | train | 62,274 |
pkgw/pwkit | pwkit/synphot.py | Registry.register_bpass | def register_bpass(self, telescope, klass):
"""Register a Bandpass class."""
if telescope in self._bpass_classes:
raise AlreadyDefinedError('bandpass class for %s already '
'defined', telescope)
self._note(telescope, None)
self._bpass_cl... | python | def register_bpass(self, telescope, klass):
"""Register a Bandpass class."""
if telescope in self._bpass_classes:
raise AlreadyDefinedError('bandpass class for %s already '
'defined', telescope)
self._note(telescope, None)
self._bpass_cl... | [
"def",
"register_bpass",
"(",
"self",
",",
"telescope",
",",
"klass",
")",
":",
"if",
"telescope",
"in",
"self",
".",
"_bpass_classes",
":",
"raise",
"AlreadyDefinedError",
"(",
"'bandpass class for %s already '",
"'defined'",
",",
"telescope",
")",
"self",
".",
... | Register a Bandpass class. | [
"Register",
"a",
"Bandpass",
"class",
"."
] | d40957a1c3d2ea34e7ceac2267ee9635135f2793 | https://github.com/pkgw/pwkit/blob/d40957a1c3d2ea34e7ceac2267ee9635135f2793/pwkit/synphot.py#L485-L493 | train | 62,275 |
pkgw/pwkit | pwkit/synphot.py | Registry.get | def get(self, telescope, band):
"""Get a Bandpass object for a known telescope and filter."""
klass = self._bpass_classes.get(telescope)
if klass is None:
raise NotDefinedError('bandpass data for %s not defined', telescope)
bp = klass()
bp.registry = self
bp... | python | def get(self, telescope, band):
"""Get a Bandpass object for a known telescope and filter."""
klass = self._bpass_classes.get(telescope)
if klass is None:
raise NotDefinedError('bandpass data for %s not defined', telescope)
bp = klass()
bp.registry = self
bp... | [
"def",
"get",
"(",
"self",
",",
"telescope",
",",
"band",
")",
":",
"klass",
"=",
"self",
".",
"_bpass_classes",
".",
"get",
"(",
"telescope",
")",
"if",
"klass",
"is",
"None",
":",
"raise",
"NotDefinedError",
"(",
"'bandpass data for %s not defined'",
",",
... | Get a Bandpass object for a known telescope and filter. | [
"Get",
"a",
"Bandpass",
"object",
"for",
"a",
"known",
"telescope",
"and",
"filter",
"."
] | d40957a1c3d2ea34e7ceac2267ee9635135f2793 | https://github.com/pkgw/pwkit/blob/d40957a1c3d2ea34e7ceac2267ee9635135f2793/pwkit/synphot.py#L496-L507 | train | 62,276 |
pkgw/pwkit | pwkit/synphot.py | WiseBandpass._load_data | def _load_data(self, band):
"""From the WISE All-Sky Explanatory Supplement, IV.4.h.i.1, and Jarrett+
2011. These are relative response per erg and so can be integrated
directly against F_nu spectra. Wavelengths are in micron,
uncertainties are in parts per thousand.
"""
... | python | def _load_data(self, band):
"""From the WISE All-Sky Explanatory Supplement, IV.4.h.i.1, and Jarrett+
2011. These are relative response per erg and so can be integrated
directly against F_nu spectra. Wavelengths are in micron,
uncertainties are in parts per thousand.
"""
... | [
"def",
"_load_data",
"(",
"self",
",",
"band",
")",
":",
"# `band` should be 1, 2, 3, or 4.",
"df",
"=",
"bandpass_data_frame",
"(",
"'filter_wise_'",
"+",
"str",
"(",
"band",
")",
"+",
"'.dat'",
",",
"'wlen resp uncert'",
")",
"df",
".",
"wlen",
"*=",
"1e4",
... | From the WISE All-Sky Explanatory Supplement, IV.4.h.i.1, and Jarrett+
2011. These are relative response per erg and so can be integrated
directly against F_nu spectra. Wavelengths are in micron,
uncertainties are in parts per thousand. | [
"From",
"the",
"WISE",
"All",
"-",
"Sky",
"Explanatory",
"Supplement",
"IV",
".",
"4",
".",
"h",
".",
"i",
".",
"1",
"and",
"Jarrett",
"+",
"2011",
".",
"These",
"are",
"relative",
"response",
"per",
"erg",
"and",
"so",
"can",
"be",
"integrated",
"di... | d40957a1c3d2ea34e7ceac2267ee9635135f2793 | https://github.com/pkgw/pwkit/blob/d40957a1c3d2ea34e7ceac2267ee9635135f2793/pwkit/synphot.py#L930-L943 | train | 62,277 |
bibanon/BASC-py4chan | basc_py4chan/util.py | clean_comment_body | def clean_comment_body(body):
"""Returns given comment HTML as plaintext.
Converts all HTML tags and entities within 4chan comments
into human-readable text equivalents.
"""
body = _parser.unescape(body)
body = re.sub(r'<a [^>]+>(.+?)</a>', r'\1', body)
body = body.replace('<br>', '\n')
... | python | def clean_comment_body(body):
"""Returns given comment HTML as plaintext.
Converts all HTML tags and entities within 4chan comments
into human-readable text equivalents.
"""
body = _parser.unescape(body)
body = re.sub(r'<a [^>]+>(.+?)</a>', r'\1', body)
body = body.replace('<br>', '\n')
... | [
"def",
"clean_comment_body",
"(",
"body",
")",
":",
"body",
"=",
"_parser",
".",
"unescape",
"(",
"body",
")",
"body",
"=",
"re",
".",
"sub",
"(",
"r'<a [^>]+>(.+?)</a>'",
",",
"r'\\1'",
",",
"body",
")",
"body",
"=",
"body",
".",
"replace",
"(",
"'<br... | Returns given comment HTML as plaintext.
Converts all HTML tags and entities within 4chan comments
into human-readable text equivalents. | [
"Returns",
"given",
"comment",
"HTML",
"as",
"plaintext",
"."
] | 88e4866d73853e1025e549fbbe9744e750522359 | https://github.com/bibanon/BASC-py4chan/blob/88e4866d73853e1025e549fbbe9744e750522359/basc_py4chan/util.py#L16-L26 | train | 62,278 |
pkgw/pwkit | pwkit/astimage.py | _create_wcs | def _create_wcs (fitsheader):
"""For compatibility between astropy and pywcs."""
wcsmodule = _load_wcs_module ()
is_pywcs = hasattr (wcsmodule, 'UnitConverter')
wcs = wcsmodule.WCS (fitsheader)
wcs.wcs.set ()
wcs.wcs.fix () # I'm interested in MJD computation via datfix()
if hasattr (wcs, ... | python | def _create_wcs (fitsheader):
"""For compatibility between astropy and pywcs."""
wcsmodule = _load_wcs_module ()
is_pywcs = hasattr (wcsmodule, 'UnitConverter')
wcs = wcsmodule.WCS (fitsheader)
wcs.wcs.set ()
wcs.wcs.fix () # I'm interested in MJD computation via datfix()
if hasattr (wcs, ... | [
"def",
"_create_wcs",
"(",
"fitsheader",
")",
":",
"wcsmodule",
"=",
"_load_wcs_module",
"(",
")",
"is_pywcs",
"=",
"hasattr",
"(",
"wcsmodule",
",",
"'UnitConverter'",
")",
"wcs",
"=",
"wcsmodule",
".",
"WCS",
"(",
"fitsheader",
")",
"wcs",
".",
"wcs",
".... | For compatibility between astropy and pywcs. | [
"For",
"compatibility",
"between",
"astropy",
"and",
"pywcs",
"."
] | d40957a1c3d2ea34e7ceac2267ee9635135f2793 | https://github.com/pkgw/pwkit/blob/d40957a1c3d2ea34e7ceac2267ee9635135f2793/pwkit/astimage.py#L101-L114 | train | 62,279 |
pkgw/pwkit | pwkit/environments/casa/util.py | sanitize_unicode | def sanitize_unicode(item):
"""Safely pass string values to the CASA tools.
item
A value to be passed to a CASA tool.
In Python 2, the bindings to CASA tasks expect to receive all string values
as binary data (:class:`str`) and not Unicode. But :mod:`pwkit` often uses
the ``from __future__ i... | python | def sanitize_unicode(item):
"""Safely pass string values to the CASA tools.
item
A value to be passed to a CASA tool.
In Python 2, the bindings to CASA tasks expect to receive all string values
as binary data (:class:`str`) and not Unicode. But :mod:`pwkit` often uses
the ``from __future__ i... | [
"def",
"sanitize_unicode",
"(",
"item",
")",
":",
"if",
"isinstance",
"(",
"item",
",",
"text_type",
")",
":",
"return",
"item",
".",
"encode",
"(",
"'utf8'",
")",
"if",
"isinstance",
"(",
"item",
",",
"dict",
")",
":",
"return",
"dict",
"(",
"(",
"s... | Safely pass string values to the CASA tools.
item
A value to be passed to a CASA tool.
In Python 2, the bindings to CASA tasks expect to receive all string values
as binary data (:class:`str`) and not Unicode. But :mod:`pwkit` often uses
the ``from __future__ import unicode_literals`` statement ... | [
"Safely",
"pass",
"string",
"values",
"to",
"the",
"CASA",
"tools",
"."
] | d40957a1c3d2ea34e7ceac2267ee9635135f2793 | https://github.com/pkgw/pwkit/blob/d40957a1c3d2ea34e7ceac2267ee9635135f2793/pwkit/environments/casa/util.py#L62-L103 | train | 62,280 |
pkgw/pwkit | pwkit/environments/casa/util.py | datadir | def datadir(*subdirs):
"""Get a path within the CASA data directory.
subdirs
Extra elements to append to the returned path.
This function locates the directory where CASA resource data files (tables
of time offsets, calibrator models, etc.) are stored. If called with no
arguments, it simply ... | python | def datadir(*subdirs):
"""Get a path within the CASA data directory.
subdirs
Extra elements to append to the returned path.
This function locates the directory where CASA resource data files (tables
of time offsets, calibrator models, etc.) are stored. If called with no
arguments, it simply ... | [
"def",
"datadir",
"(",
"*",
"subdirs",
")",
":",
"import",
"os",
".",
"path",
"data",
"=",
"None",
"if",
"'CASAPATH'",
"in",
"os",
".",
"environ",
":",
"data",
"=",
"os",
".",
"path",
".",
"join",
"(",
"os",
".",
"environ",
"[",
"'CASAPATH'",
"]",
... | Get a path within the CASA data directory.
subdirs
Extra elements to append to the returned path.
This function locates the directory where CASA resource data files (tables
of time offsets, calibrator models, etc.) are stored. If called with no
arguments, it simply returns that path. If argument... | [
"Get",
"a",
"path",
"within",
"the",
"CASA",
"data",
"directory",
"."
] | d40957a1c3d2ea34e7ceac2267ee9635135f2793 | https://github.com/pkgw/pwkit/blob/d40957a1c3d2ea34e7ceac2267ee9635135f2793/pwkit/environments/casa/util.py#L108-L163 | train | 62,281 |
pkgw/pwkit | pwkit/environments/casa/util.py | logger | def logger(filter='WARN'):
"""Set up CASA to write log messages to standard output.
filter
The log level filter: less urgent messages will not be shown. Valid values
are strings: "DEBUG1", "INFO5", ... "INFO1", "INFO", "WARN", "SEVERE".
This function creates and returns a CASA ”log sink” objec... | python | def logger(filter='WARN'):
"""Set up CASA to write log messages to standard output.
filter
The log level filter: less urgent messages will not be shown. Valid values
are strings: "DEBUG1", "INFO5", ... "INFO1", "INFO", "WARN", "SEVERE".
This function creates and returns a CASA ”log sink” objec... | [
"def",
"logger",
"(",
"filter",
"=",
"'WARN'",
")",
":",
"import",
"os",
",",
"shutil",
",",
"tempfile",
"cwd",
"=",
"os",
".",
"getcwd",
"(",
")",
"tempdir",
"=",
"None",
"try",
":",
"tempdir",
"=",
"tempfile",
".",
"mkdtemp",
"(",
"prefix",
"=",
... | Set up CASA to write log messages to standard output.
filter
The log level filter: less urgent messages will not be shown. Valid values
are strings: "DEBUG1", "INFO5", ... "INFO1", "INFO", "WARN", "SEVERE".
This function creates and returns a CASA ”log sink” object that is
configured to write ... | [
"Set",
"up",
"CASA",
"to",
"write",
"log",
"messages",
"to",
"standard",
"output",
"."
] | d40957a1c3d2ea34e7ceac2267ee9635135f2793 | https://github.com/pkgw/pwkit/blob/d40957a1c3d2ea34e7ceac2267ee9635135f2793/pwkit/environments/casa/util.py#L176-L218 | train | 62,282 |
pkgw/pwkit | pwkit/environments/casa/util.py | forkandlog | def forkandlog(function, filter='INFO5', debug=False):
"""Fork a child process and read its CASA log output.
function
A function to run in the child process
filter
The CASA log level filter to apply in the child process: less urgent
messages will not be shown. Valid values are strings: "D... | python | def forkandlog(function, filter='INFO5', debug=False):
"""Fork a child process and read its CASA log output.
function
A function to run in the child process
filter
The CASA log level filter to apply in the child process: less urgent
messages will not be shown. Valid values are strings: "D... | [
"def",
"forkandlog",
"(",
"function",
",",
"filter",
"=",
"'INFO5'",
",",
"debug",
"=",
"False",
")",
":",
"import",
"sys",
",",
"os",
"readfd",
",",
"writefd",
"=",
"os",
".",
"pipe",
"(",
")",
"pid",
"=",
"os",
".",
"fork",
"(",
")",
"if",
"pid... | Fork a child process and read its CASA log output.
function
A function to run in the child process
filter
The CASA log level filter to apply in the child process: less urgent
messages will not be shown. Valid values are strings: "DEBUG1", "INFO5",
... "INFO1", "INFO", "WARN", "SEVERE".
... | [
"Fork",
"a",
"child",
"process",
"and",
"read",
"its",
"CASA",
"log",
"output",
"."
] | d40957a1c3d2ea34e7ceac2267ee9635135f2793 | https://github.com/pkgw/pwkit/blob/d40957a1c3d2ea34e7ceac2267ee9635135f2793/pwkit/environments/casa/util.py#L221-L306 | train | 62,283 |
kapadia/usgs | usgs/api.py | _get_extended | def _get_extended(scene, resp):
"""
Parse metadata returned from the metadataUrl of a USGS scene.
:param scene:
Dictionary representation of a USGS scene
:param resp:
Response object from requests/grequests
"""
root = ElementTree.fromstring(resp.text)
items = root.findall("e... | python | def _get_extended(scene, resp):
"""
Parse metadata returned from the metadataUrl of a USGS scene.
:param scene:
Dictionary representation of a USGS scene
:param resp:
Response object from requests/grequests
"""
root = ElementTree.fromstring(resp.text)
items = root.findall("e... | [
"def",
"_get_extended",
"(",
"scene",
",",
"resp",
")",
":",
"root",
"=",
"ElementTree",
".",
"fromstring",
"(",
"resp",
".",
"text",
")",
"items",
"=",
"root",
".",
"findall",
"(",
"\"eemetadata:metadataFields/eemetadata:metadataField\"",
",",
"NAMESPACES",
")"... | Parse metadata returned from the metadataUrl of a USGS scene.
:param scene:
Dictionary representation of a USGS scene
:param resp:
Response object from requests/grequests | [
"Parse",
"metadata",
"returned",
"from",
"the",
"metadataUrl",
"of",
"a",
"USGS",
"scene",
"."
] | 0608346f0bc3c34e20f4ecc77ad71d0b514db7ee | https://github.com/kapadia/usgs/blob/0608346f0bc3c34e20f4ecc77ad71d0b514db7ee/usgs/api.py#L38-L51 | train | 62,284 |
kapadia/usgs | usgs/api.py | _async_requests | def _async_requests(urls):
"""
Sends multiple non-blocking requests. Returns
a list of responses.
:param urls:
List of urls
"""
session = FuturesSession(max_workers=30)
futures = [
session.get(url)
for url in urls
]
return [ future.result() for future in futu... | python | def _async_requests(urls):
"""
Sends multiple non-blocking requests. Returns
a list of responses.
:param urls:
List of urls
"""
session = FuturesSession(max_workers=30)
futures = [
session.get(url)
for url in urls
]
return [ future.result() for future in futu... | [
"def",
"_async_requests",
"(",
"urls",
")",
":",
"session",
"=",
"FuturesSession",
"(",
"max_workers",
"=",
"30",
")",
"futures",
"=",
"[",
"session",
".",
"get",
"(",
"url",
")",
"for",
"url",
"in",
"urls",
"]",
"return",
"[",
"future",
".",
"result",... | Sends multiple non-blocking requests. Returns
a list of responses.
:param urls:
List of urls | [
"Sends",
"multiple",
"non",
"-",
"blocking",
"requests",
".",
"Returns",
"a",
"list",
"of",
"responses",
"."
] | 0608346f0bc3c34e20f4ecc77ad71d0b514db7ee | https://github.com/kapadia/usgs/blob/0608346f0bc3c34e20f4ecc77ad71d0b514db7ee/usgs/api.py#L54-L67 | train | 62,285 |
kapadia/usgs | usgs/api.py | metadata | def metadata(dataset, node, entityids, extended=False, api_key=None):
"""
Request metadata for a given scene in a USGS dataset.
:param dataset:
:param node:
:param entityids:
:param extended:
Send a second request to the metadata url to get extended metadata on the scene.
:param api... | python | def metadata(dataset, node, entityids, extended=False, api_key=None):
"""
Request metadata for a given scene in a USGS dataset.
:param dataset:
:param node:
:param entityids:
:param extended:
Send a second request to the metadata url to get extended metadata on the scene.
:param api... | [
"def",
"metadata",
"(",
"dataset",
",",
"node",
",",
"entityids",
",",
"extended",
"=",
"False",
",",
"api_key",
"=",
"None",
")",
":",
"api_key",
"=",
"_get_api_key",
"(",
"api_key",
")",
"url",
"=",
"'{}/metadata'",
".",
"format",
"(",
"USGS_API",
")",... | Request metadata for a given scene in a USGS dataset.
:param dataset:
:param node:
:param entityids:
:param extended:
Send a second request to the metadata url to get extended metadata on the scene.
:param api_key: | [
"Request",
"metadata",
"for",
"a",
"given",
"scene",
"in",
"a",
"USGS",
"dataset",
"."
] | 0608346f0bc3c34e20f4ecc77ad71d0b514db7ee | https://github.com/kapadia/usgs/blob/0608346f0bc3c34e20f4ecc77ad71d0b514db7ee/usgs/api.py#L217-L244 | train | 62,286 |
pkgw/pwkit | pwkit/__init__.py | reraise_context | def reraise_context(fmt, *args):
"""Reraise an exception with its message modified to specify additional
context.
This function tries to help provide context when a piece of code
encounters an exception while trying to get something done, and it wishes
to propagate contextual information farther up... | python | def reraise_context(fmt, *args):
"""Reraise an exception with its message modified to specify additional
context.
This function tries to help provide context when a piece of code
encounters an exception while trying to get something done, and it wishes
to propagate contextual information farther up... | [
"def",
"reraise_context",
"(",
"fmt",
",",
"*",
"args",
")",
":",
"import",
"sys",
"if",
"len",
"(",
"args",
")",
":",
"cstr",
"=",
"fmt",
"%",
"args",
"else",
":",
"cstr",
"=",
"text_type",
"(",
"fmt",
")",
"ex",
"=",
"sys",
".",
"exc_info",
"("... | Reraise an exception with its message modified to specify additional
context.
This function tries to help provide context when a piece of code
encounters an exception while trying to get something done, and it wishes
to propagate contextual information farther up the call stack. It only
makes sense... | [
"Reraise",
"an",
"exception",
"with",
"its",
"message",
"modified",
"to",
"specify",
"additional",
"context",
"."
] | d40957a1c3d2ea34e7ceac2267ee9635135f2793 | https://github.com/pkgw/pwkit/blob/d40957a1c3d2ea34e7ceac2267ee9635135f2793/pwkit/__init__.py#L59-L114 | train | 62,287 |
pkgw/pwkit | pwkit/__init__.py | Holder.copy | def copy(self):
"""Return a shallow copy of this object.
"""
new = self.__class__()
new.__dict__ = dict(self.__dict__)
return new | python | def copy(self):
"""Return a shallow copy of this object.
"""
new = self.__class__()
new.__dict__ = dict(self.__dict__)
return new | [
"def",
"copy",
"(",
"self",
")",
":",
"new",
"=",
"self",
".",
"__class__",
"(",
")",
"new",
".",
"__dict__",
"=",
"dict",
"(",
"self",
".",
"__dict__",
")",
"return",
"new"
] | Return a shallow copy of this object. | [
"Return",
"a",
"shallow",
"copy",
"of",
"this",
"object",
"."
] | d40957a1c3d2ea34e7ceac2267ee9635135f2793 | https://github.com/pkgw/pwkit/blob/d40957a1c3d2ea34e7ceac2267ee9635135f2793/pwkit/__init__.py#L205-L211 | train | 62,288 |
bibanon/BASC-py4chan | basc_py4chan/board.py | get_all_boards | def get_all_boards(*args, **kwargs):
"""Returns every board on 4chan.
Returns:
dict of :class:`basc_py4chan.Board`: All boards.
"""
# Use https based on how the Board class instances are to be instantiated
https = kwargs.get('https', args[1] if len(args) > 1 else False)
# Dummy URL gen... | python | def get_all_boards(*args, **kwargs):
"""Returns every board on 4chan.
Returns:
dict of :class:`basc_py4chan.Board`: All boards.
"""
# Use https based on how the Board class instances are to be instantiated
https = kwargs.get('https', args[1] if len(args) > 1 else False)
# Dummy URL gen... | [
"def",
"get_all_boards",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"# Use https based on how the Board class instances are to be instantiated",
"https",
"=",
"kwargs",
".",
"get",
"(",
"'https'",
",",
"args",
"[",
"1",
"]",
"if",
"len",
"(",
"args",
... | Returns every board on 4chan.
Returns:
dict of :class:`basc_py4chan.Board`: All boards. | [
"Returns",
"every",
"board",
"on",
"4chan",
"."
] | 88e4866d73853e1025e549fbbe9744e750522359 | https://github.com/bibanon/BASC-py4chan/blob/88e4866d73853e1025e549fbbe9744e750522359/basc_py4chan/board.py#L57-L70 | train | 62,289 |
bibanon/BASC-py4chan | basc_py4chan/board.py | Board.get_thread | def get_thread(self, thread_id, update_if_cached=True, raise_404=False):
"""Get a thread from 4chan via 4chan API.
Args:
thread_id (int): Thread ID
update_if_cached (bool): Whether the thread should be updated if it's already in our cache
raise_404 (bool): Raise an E... | python | def get_thread(self, thread_id, update_if_cached=True, raise_404=False):
"""Get a thread from 4chan via 4chan API.
Args:
thread_id (int): Thread ID
update_if_cached (bool): Whether the thread should be updated if it's already in our cache
raise_404 (bool): Raise an E... | [
"def",
"get_thread",
"(",
"self",
",",
"thread_id",
",",
"update_if_cached",
"=",
"True",
",",
"raise_404",
"=",
"False",
")",
":",
"# see if already cached",
"cached_thread",
"=",
"self",
".",
"_thread_cache",
".",
"get",
"(",
"thread_id",
")",
"if",
"cached_... | Get a thread from 4chan via 4chan API.
Args:
thread_id (int): Thread ID
update_if_cached (bool): Whether the thread should be updated if it's already in our cache
raise_404 (bool): Raise an Exception if thread has 404'd
Returns:
:class:`basc_py4chan.Thre... | [
"Get",
"a",
"thread",
"from",
"4chan",
"via",
"4chan",
"API",
"."
] | 88e4866d73853e1025e549fbbe9744e750522359 | https://github.com/bibanon/BASC-py4chan/blob/88e4866d73853e1025e549fbbe9744e750522359/basc_py4chan/board.py#L110-L143 | train | 62,290 |
bibanon/BASC-py4chan | basc_py4chan/board.py | Board.thread_exists | def thread_exists(self, thread_id):
"""Check if a thread exists or has 404'd.
Args:
thread_id (int): Thread ID
Returns:
bool: Whether the given thread exists on this board.
"""
return self._requests_session.head(
self._url.thread_api_url(
... | python | def thread_exists(self, thread_id):
"""Check if a thread exists or has 404'd.
Args:
thread_id (int): Thread ID
Returns:
bool: Whether the given thread exists on this board.
"""
return self._requests_session.head(
self._url.thread_api_url(
... | [
"def",
"thread_exists",
"(",
"self",
",",
"thread_id",
")",
":",
"return",
"self",
".",
"_requests_session",
".",
"head",
"(",
"self",
".",
"_url",
".",
"thread_api_url",
"(",
"thread_id",
"=",
"thread_id",
")",
")",
".",
"ok"
] | Check if a thread exists or has 404'd.
Args:
thread_id (int): Thread ID
Returns:
bool: Whether the given thread exists on this board. | [
"Check",
"if",
"a",
"thread",
"exists",
"or",
"has",
"404",
"d",
"."
] | 88e4866d73853e1025e549fbbe9744e750522359 | https://github.com/bibanon/BASC-py4chan/blob/88e4866d73853e1025e549fbbe9744e750522359/basc_py4chan/board.py#L145-L158 | train | 62,291 |
bibanon/BASC-py4chan | basc_py4chan/board.py | Board.get_threads | def get_threads(self, page=1):
"""Returns all threads on a certain page.
Gets a list of Thread objects for every thread on the given page. If a thread is
already in our cache, the cached version is returned and thread.want_update is
set to True on the specific thread object.
Pa... | python | def get_threads(self, page=1):
"""Returns all threads on a certain page.
Gets a list of Thread objects for every thread on the given page. If a thread is
already in our cache, the cached version is returned and thread.want_update is
set to True on the specific thread object.
Pa... | [
"def",
"get_threads",
"(",
"self",
",",
"page",
"=",
"1",
")",
":",
"url",
"=",
"self",
".",
"_url",
".",
"page_url",
"(",
"page",
")",
"return",
"self",
".",
"_request_threads",
"(",
"url",
")"
] | Returns all threads on a certain page.
Gets a list of Thread objects for every thread on the given page. If a thread is
already in our cache, the cached version is returned and thread.want_update is
set to True on the specific thread object.
Pages on 4chan are indexed from 1 onwards.
... | [
"Returns",
"all",
"threads",
"on",
"a",
"certain",
"page",
"."
] | 88e4866d73853e1025e549fbbe9744e750522359 | https://github.com/bibanon/BASC-py4chan/blob/88e4866d73853e1025e549fbbe9744e750522359/basc_py4chan/board.py#L192-L208 | train | 62,292 |
bibanon/BASC-py4chan | basc_py4chan/board.py | Board.get_all_thread_ids | def get_all_thread_ids(self):
"""Return the ID of every thread on this board.
Returns:
list of ints: List of IDs of every thread on this board.
"""
json = self._get_json(self._url.thread_list())
return [thread['no'] for page in json for thread in page['threads']] | python | def get_all_thread_ids(self):
"""Return the ID of every thread on this board.
Returns:
list of ints: List of IDs of every thread on this board.
"""
json = self._get_json(self._url.thread_list())
return [thread['no'] for page in json for thread in page['threads']] | [
"def",
"get_all_thread_ids",
"(",
"self",
")",
":",
"json",
"=",
"self",
".",
"_get_json",
"(",
"self",
".",
"_url",
".",
"thread_list",
"(",
")",
")",
"return",
"[",
"thread",
"[",
"'no'",
"]",
"for",
"page",
"in",
"json",
"for",
"thread",
"in",
"pa... | Return the ID of every thread on this board.
Returns:
list of ints: List of IDs of every thread on this board. | [
"Return",
"the",
"ID",
"of",
"every",
"thread",
"on",
"this",
"board",
"."
] | 88e4866d73853e1025e549fbbe9744e750522359 | https://github.com/bibanon/BASC-py4chan/blob/88e4866d73853e1025e549fbbe9744e750522359/basc_py4chan/board.py#L210-L217 | train | 62,293 |
bibanon/BASC-py4chan | basc_py4chan/board.py | Board.get_all_threads | def get_all_threads(self, expand=False):
"""Return every thread on this board.
If not expanded, result is same as get_threads run across all board pages,
with last 3-5 replies included.
Uses the catalog when not expanding, and uses the flat thread ID listing
at /{board}/threads... | python | def get_all_threads(self, expand=False):
"""Return every thread on this board.
If not expanded, result is same as get_threads run across all board pages,
with last 3-5 replies included.
Uses the catalog when not expanding, and uses the flat thread ID listing
at /{board}/threads... | [
"def",
"get_all_threads",
"(",
"self",
",",
"expand",
"=",
"False",
")",
":",
"if",
"not",
"expand",
":",
"return",
"self",
".",
"_request_threads",
"(",
"self",
".",
"_url",
".",
"catalog",
"(",
")",
")",
"thread_ids",
"=",
"self",
".",
"get_all_thread_... | Return every thread on this board.
If not expanded, result is same as get_threads run across all board pages,
with last 3-5 replies included.
Uses the catalog when not expanding, and uses the flat thread ID listing
at /{board}/threads.json when expanding for more efficient resource usa... | [
"Return",
"every",
"thread",
"on",
"this",
"board",
"."
] | 88e4866d73853e1025e549fbbe9744e750522359 | https://github.com/bibanon/BASC-py4chan/blob/88e4866d73853e1025e549fbbe9744e750522359/basc_py4chan/board.py#L219-L243 | train | 62,294 |
bibanon/BASC-py4chan | basc_py4chan/board.py | Board.refresh_cache | def refresh_cache(self, if_want_update=False):
"""Update all threads currently stored in our cache."""
for thread in tuple(self._thread_cache.values()):
if if_want_update:
if not thread.want_update:
continue
thread.update() | python | def refresh_cache(self, if_want_update=False):
"""Update all threads currently stored in our cache."""
for thread in tuple(self._thread_cache.values()):
if if_want_update:
if not thread.want_update:
continue
thread.update() | [
"def",
"refresh_cache",
"(",
"self",
",",
"if_want_update",
"=",
"False",
")",
":",
"for",
"thread",
"in",
"tuple",
"(",
"self",
".",
"_thread_cache",
".",
"values",
"(",
")",
")",
":",
"if",
"if_want_update",
":",
"if",
"not",
"thread",
".",
"want_updat... | Update all threads currently stored in our cache. | [
"Update",
"all",
"threads",
"currently",
"stored",
"in",
"our",
"cache",
"."
] | 88e4866d73853e1025e549fbbe9744e750522359 | https://github.com/bibanon/BASC-py4chan/blob/88e4866d73853e1025e549fbbe9744e750522359/basc_py4chan/board.py#L245-L251 | train | 62,295 |
pkgw/pwkit | pwkit/environments/casa/__init__.py | CasaEnvironment.modify_environment | def modify_environment(self, env):
"""Maintaining compatibility with different CASA versions is a pain."""
# Ugh. I don't see any way out of special-casing the RPM-based
# installations ... which only exist on NRAO computers, AFAICT.
# Hardcoding 64-bitness, hopefully that won't come ba... | python | def modify_environment(self, env):
"""Maintaining compatibility with different CASA versions is a pain."""
# Ugh. I don't see any way out of special-casing the RPM-based
# installations ... which only exist on NRAO computers, AFAICT.
# Hardcoding 64-bitness, hopefully that won't come ba... | [
"def",
"modify_environment",
"(",
"self",
",",
"env",
")",
":",
"# Ugh. I don't see any way out of special-casing the RPM-based",
"# installations ... which only exist on NRAO computers, AFAICT.",
"# Hardcoding 64-bitness, hopefully that won't come back to bite me.",
"is_rpm_install",
"=",
... | Maintaining compatibility with different CASA versions is a pain. | [
"Maintaining",
"compatibility",
"with",
"different",
"CASA",
"versions",
"is",
"a",
"pain",
"."
] | d40957a1c3d2ea34e7ceac2267ee9635135f2793 | https://github.com/pkgw/pwkit/blob/d40957a1c3d2ea34e7ceac2267ee9635135f2793/pwkit/environments/casa/__init__.py#L86-L140 | train | 62,296 |
pkgw/pwkit | pwkit/environments/ciao/analysis.py | compute_bgband | def compute_bgband (evtpath, srcreg, bkgreg, ebins, env=None):
"""Compute background information for a source in one or more energy bands.
evtpath
Path to a CIAO events file
srcreg
String specifying the source region to consider; use 'region(path.reg)' if you
have the region saved in a fi... | python | def compute_bgband (evtpath, srcreg, bkgreg, ebins, env=None):
"""Compute background information for a source in one or more energy bands.
evtpath
Path to a CIAO events file
srcreg
String specifying the source region to consider; use 'region(path.reg)' if you
have the region saved in a fi... | [
"def",
"compute_bgband",
"(",
"evtpath",
",",
"srcreg",
",",
"bkgreg",
",",
"ebins",
",",
"env",
"=",
"None",
")",
":",
"import",
"numpy",
"as",
"np",
"import",
"pandas",
"as",
"pd",
"from",
"scipy",
".",
"special",
"import",
"erfcinv",
",",
"gammaln",
... | Compute background information for a source in one or more energy bands.
evtpath
Path to a CIAO events file
srcreg
String specifying the source region to consider; use 'region(path.reg)' if you
have the region saved in a file.
bkgreg
String specifying the background region to consid... | [
"Compute",
"background",
"information",
"for",
"a",
"source",
"in",
"one",
"or",
"more",
"energy",
"bands",
"."
] | d40957a1c3d2ea34e7ceac2267ee9635135f2793 | https://github.com/pkgw/pwkit/blob/d40957a1c3d2ea34e7ceac2267ee9635135f2793/pwkit/environments/ciao/analysis.py#L50-L129 | train | 62,297 |
pkgw/pwkit | pwkit/environments/ciao/analysis.py | simple_srcflux | def simple_srcflux(env, infile=None, psfmethod='arfcorr', conf=0.68,
verbose=0, **kwargs):
"""Run the CIAO "srcflux" script and retrieve its results.
*infile*
The input events file; must be specified. The computation is done
in a temporary directory, so this path — and all others... | python | def simple_srcflux(env, infile=None, psfmethod='arfcorr', conf=0.68,
verbose=0, **kwargs):
"""Run the CIAO "srcflux" script and retrieve its results.
*infile*
The input events file; must be specified. The computation is done
in a temporary directory, so this path — and all others... | [
"def",
"simple_srcflux",
"(",
"env",
",",
"infile",
"=",
"None",
",",
"psfmethod",
"=",
"'arfcorr'",
",",
"conf",
"=",
"0.68",
",",
"verbose",
"=",
"0",
",",
"*",
"*",
"kwargs",
")",
":",
"from",
".",
".",
".",
"io",
"import",
"Path",
"import",
"sh... | Run the CIAO "srcflux" script and retrieve its results.
*infile*
The input events file; must be specified. The computation is done
in a temporary directory, so this path — and all others passed in
as arguments — **must be made absolute**.
*psfmethod* = "arfcorr"
The PSF modeling method ... | [
"Run",
"the",
"CIAO",
"srcflux",
"script",
"and",
"retrieve",
"its",
"results",
"."
] | d40957a1c3d2ea34e7ceac2267ee9635135f2793 | https://github.com/pkgw/pwkit/blob/d40957a1c3d2ea34e7ceac2267ee9635135f2793/pwkit/environments/ciao/analysis.py#L136-L199 | train | 62,298 |
pkgw/pwkit | pwkit/fk10.py | Calculator.new_for_fk10_fig9 | def new_for_fk10_fig9(cls, shlib_path):
"""Create a calculator initialized to reproduce Figure 9 from FK10.
This is mostly to provide a handy way to create a new
:class:`Calculator` instance that is initialized with reasonable
values for all of its parameters.
"""
inst ... | python | def new_for_fk10_fig9(cls, shlib_path):
"""Create a calculator initialized to reproduce Figure 9 from FK10.
This is mostly to provide a handy way to create a new
:class:`Calculator` instance that is initialized with reasonable
values for all of its parameters.
"""
inst ... | [
"def",
"new_for_fk10_fig9",
"(",
"cls",
",",
"shlib_path",
")",
":",
"inst",
"=",
"(",
"cls",
"(",
"shlib_path",
")",
".",
"set_thermal_background",
"(",
"2.1e7",
",",
"3e9",
")",
".",
"set_bfield",
"(",
"48",
")",
".",
"set_edist_powerlaw",
"(",
"0.016",
... | Create a calculator initialized to reproduce Figure 9 from FK10.
This is mostly to provide a handy way to create a new
:class:`Calculator` instance that is initialized with reasonable
values for all of its parameters. | [
"Create",
"a",
"calculator",
"initialized",
"to",
"reproduce",
"Figure",
"9",
"from",
"FK10",
"."
] | d40957a1c3d2ea34e7ceac2267ee9635135f2793 | https://github.com/pkgw/pwkit/blob/d40957a1c3d2ea34e7ceac2267ee9635135f2793/pwkit/fk10.py#L322-L344 | train | 62,299 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.