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 list | docstring stringlengths 3 17.3k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 87 242 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
has2k1/plotnine | plotnine/stats/smoothers.py | wls_prediction_std | def wls_prediction_std(res, exog=None, weights=None, alpha=0.05,
interval='confidence'):
"""
calculate standard deviation and confidence interval
Applies to WLS and OLS, not to general GLS,
that is independently but not identically distributed observations
Parameters
---... | python | def wls_prediction_std(res, exog=None, weights=None, alpha=0.05,
interval='confidence'):
"""
calculate standard deviation and confidence interval
Applies to WLS and OLS, not to general GLS,
that is independently but not identically distributed observations
Parameters
---... | [
"def",
"wls_prediction_std",
"(",
"res",
",",
"exog",
"=",
"None",
",",
"weights",
"=",
"None",
",",
"alpha",
"=",
"0.05",
",",
"interval",
"=",
"'confidence'",
")",
":",
"# work around current bug:",
"# fit doesn't attach results to model, predict broken",
"# res.... | calculate standard deviation and confidence interval
Applies to WLS and OLS, not to general GLS,
that is independently but not identically distributed observations
Parameters
----------
res : regression result instance
results of WLS or OLS regression required attributes see notes
exog... | [
"calculate",
"standard",
"deviation",
"and",
"confidence",
"interval"
] | 566e579af705367e584fb27a74e6c5199624ca89 | https://github.com/has2k1/plotnine/blob/566e579af705367e584fb27a74e6c5199624ca89/plotnine/stats/smoothers.py#L293-L371 | train |
has2k1/plotnine | plotnine/facets/layout.py | Layout.setup | def setup(self, layers, plot):
"""
Create a layout for the panels
The layout is a dataframe that stores all the
structual information about the panels that will
make up the plot. The actual layout depends on
the type of facet.
This method ensures that each layer... | python | def setup(self, layers, plot):
"""
Create a layout for the panels
The layout is a dataframe that stores all the
structual information about the panels that will
make up the plot. The actual layout depends on
the type of facet.
This method ensures that each layer... | [
"def",
"setup",
"(",
"self",
",",
"layers",
",",
"plot",
")",
":",
"data",
"=",
"[",
"l",
".",
"data",
"for",
"l",
"in",
"layers",
"]",
"# setup facets",
"self",
".",
"facet",
"=",
"plot",
".",
"facet",
"self",
".",
"facet",
".",
"setup_params",
"(... | Create a layout for the panels
The layout is a dataframe that stores all the
structual information about the panels that will
make up the plot. The actual layout depends on
the type of facet.
This method ensures that each layer has a copy of the
data it needs in `layer.... | [
"Create",
"a",
"layout",
"for",
"the",
"panels"
] | 566e579af705367e584fb27a74e6c5199624ca89 | https://github.com/has2k1/plotnine/blob/566e579af705367e584fb27a74e6c5199624ca89/plotnine/facets/layout.py#L30-L64 | train |
has2k1/plotnine | plotnine/facets/layout.py | Layout.train_position | def train_position(self, layers, x_scale, y_scale):
"""
Create all the required x & y panel_scales y_scales
and set the ranges for each scale according to the data.
Notes
-----
The number of x or y scales depends on the facetting,
particularly the scales paramete... | python | def train_position(self, layers, x_scale, y_scale):
"""
Create all the required x & y panel_scales y_scales
and set the ranges for each scale according to the data.
Notes
-----
The number of x or y scales depends on the facetting,
particularly the scales paramete... | [
"def",
"train_position",
"(",
"self",
",",
"layers",
",",
"x_scale",
",",
"y_scale",
")",
":",
"layout",
"=",
"self",
".",
"layout",
"if",
"self",
".",
"panel_scales_x",
"is",
"None",
"and",
"x_scale",
":",
"result",
"=",
"self",
".",
"facet",
".",
"in... | Create all the required x & y panel_scales y_scales
and set the ranges for each scale according to the data.
Notes
-----
The number of x or y scales depends on the facetting,
particularly the scales parameter. e.g if `scales='free'`
then each panel will have separate x a... | [
"Create",
"all",
"the",
"required",
"x",
"&",
"y",
"panel_scales",
"y_scales",
"and",
"set",
"the",
"ranges",
"for",
"each",
"scale",
"according",
"to",
"the",
"data",
"."
] | 566e579af705367e584fb27a74e6c5199624ca89 | https://github.com/has2k1/plotnine/blob/566e579af705367e584fb27a74e6c5199624ca89/plotnine/facets/layout.py#L66-L88 | train |
has2k1/plotnine | plotnine/facets/layout.py | Layout.get_scales | def get_scales(self, i):
"""
Return x & y scales for panel i
Parameters
----------
i : int
Panel id
Returns
-------
scales : types.SimpleNamespace
Class attributes *x* for the x scale and *y*
for the y scale of the panel
... | python | def get_scales(self, i):
"""
Return x & y scales for panel i
Parameters
----------
i : int
Panel id
Returns
-------
scales : types.SimpleNamespace
Class attributes *x* for the x scale and *y*
for the y scale of the panel
... | [
"def",
"get_scales",
"(",
"self",
",",
"i",
")",
":",
"# wrapping with np.asarray prevents an exception",
"# on some datasets",
"bool_idx",
"=",
"(",
"np",
".",
"asarray",
"(",
"self",
".",
"layout",
"[",
"'PANEL'",
"]",
")",
"==",
"i",
")",
"xsc",
"=",
"Non... | Return x & y scales for panel i
Parameters
----------
i : int
Panel id
Returns
-------
scales : types.SimpleNamespace
Class attributes *x* for the x scale and *y*
for the y scale of the panel | [
"Return",
"x",
"&",
"y",
"scales",
"for",
"panel",
"i"
] | 566e579af705367e584fb27a74e6c5199624ca89 | https://github.com/has2k1/plotnine/blob/566e579af705367e584fb27a74e6c5199624ca89/plotnine/facets/layout.py#L116-L146 | train |
has2k1/plotnine | plotnine/facets/layout.py | Layout.reset_position_scales | def reset_position_scales(self):
"""
Reset x and y scales
"""
if not self.facet.shrink:
return
with suppress(AttributeError):
self.panel_scales_x.reset()
with suppress(AttributeError):
self.panel_scales_y.reset() | python | def reset_position_scales(self):
"""
Reset x and y scales
"""
if not self.facet.shrink:
return
with suppress(AttributeError):
self.panel_scales_x.reset()
with suppress(AttributeError):
self.panel_scales_y.reset() | [
"def",
"reset_position_scales",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"facet",
".",
"shrink",
":",
"return",
"with",
"suppress",
"(",
"AttributeError",
")",
":",
"self",
".",
"panel_scales_x",
".",
"reset",
"(",
")",
"with",
"suppress",
"(",
"... | Reset x and y scales | [
"Reset",
"x",
"and",
"y",
"scales"
] | 566e579af705367e584fb27a74e6c5199624ca89 | https://github.com/has2k1/plotnine/blob/566e579af705367e584fb27a74e6c5199624ca89/plotnine/facets/layout.py#L148-L159 | train |
has2k1/plotnine | plotnine/facets/layout.py | Layout.setup_panel_params | def setup_panel_params(self, coord):
"""
Calculate the x & y range & breaks information for each panel
Parameters
----------
coord : coord
Coordinate
"""
if not self.panel_scales_x:
raise PlotnineError('Missing an x scale')
if not... | python | def setup_panel_params(self, coord):
"""
Calculate the x & y range & breaks information for each panel
Parameters
----------
coord : coord
Coordinate
"""
if not self.panel_scales_x:
raise PlotnineError('Missing an x scale')
if not... | [
"def",
"setup_panel_params",
"(",
"self",
",",
"coord",
")",
":",
"if",
"not",
"self",
".",
"panel_scales_x",
":",
"raise",
"PlotnineError",
"(",
"'Missing an x scale'",
")",
"if",
"not",
"self",
".",
"panel_scales_y",
":",
"raise",
"PlotnineError",
"(",
"'Mis... | Calculate the x & y range & breaks information for each panel
Parameters
----------
coord : coord
Coordinate | [
"Calculate",
"the",
"x",
"&",
"y",
"range",
"&",
"breaks",
"information",
"for",
"each",
"panel"
] | 566e579af705367e584fb27a74e6c5199624ca89 | https://github.com/has2k1/plotnine/blob/566e579af705367e584fb27a74e6c5199624ca89/plotnine/facets/layout.py#L161-L183 | train |
has2k1/plotnine | plotnine/facets/layout.py | Layout.finish_data | def finish_data(self, layers):
"""
Modify data before it is drawn out by the geom
Parameters
----------
layers : list
List of layers
"""
for layer in layers:
layer.data = self.facet.finish_data(layer.data, self) | python | def finish_data(self, layers):
"""
Modify data before it is drawn out by the geom
Parameters
----------
layers : list
List of layers
"""
for layer in layers:
layer.data = self.facet.finish_data(layer.data, self) | [
"def",
"finish_data",
"(",
"self",
",",
"layers",
")",
":",
"for",
"layer",
"in",
"layers",
":",
"layer",
".",
"data",
"=",
"self",
".",
"facet",
".",
"finish_data",
"(",
"layer",
".",
"data",
",",
"self",
")"
] | Modify data before it is drawn out by the geom
Parameters
----------
layers : list
List of layers | [
"Modify",
"data",
"before",
"it",
"is",
"drawn",
"out",
"by",
"the",
"geom"
] | 566e579af705367e584fb27a74e6c5199624ca89 | https://github.com/has2k1/plotnine/blob/566e579af705367e584fb27a74e6c5199624ca89/plotnine/facets/layout.py#L185-L195 | train |
has2k1/plotnine | plotnine/guides/guide.py | guide._set_defaults | def _set_defaults(self):
"""
Set configuration parameters for drawing guide
"""
valid_locations = {'top', 'bottom', 'left', 'right'}
horizontal_locations = {'left', 'right'}
get_property = self.theme.themeables.property
margin_location_lookup = {'t': 'b', 'b': 't'... | python | def _set_defaults(self):
"""
Set configuration parameters for drawing guide
"""
valid_locations = {'top', 'bottom', 'left', 'right'}
horizontal_locations = {'left', 'right'}
get_property = self.theme.themeables.property
margin_location_lookup = {'t': 'b', 'b': 't'... | [
"def",
"_set_defaults",
"(",
"self",
")",
":",
"valid_locations",
"=",
"{",
"'top'",
",",
"'bottom'",
",",
"'left'",
",",
"'right'",
"}",
"horizontal_locations",
"=",
"{",
"'left'",
",",
"'right'",
"}",
"get_property",
"=",
"self",
".",
"theme",
".",
"them... | Set configuration parameters for drawing guide | [
"Set",
"configuration",
"parameters",
"for",
"drawing",
"guide"
] | 566e579af705367e584fb27a74e6c5199624ca89 | https://github.com/has2k1/plotnine/blob/566e579af705367e584fb27a74e6c5199624ca89/plotnine/guides/guide.py#L107-L195 | train |
has2k1/plotnine | plotnine/guides/guide.py | guide.legend_aesthetics | def legend_aesthetics(self, layer, plot):
"""
Return the aesthetics that contribute to the legend
Parameters
----------
layer : Layer
Layer whose legend is to be drawn
plot : ggplot
Plot object
Returns
-------
matched : li... | python | def legend_aesthetics(self, layer, plot):
"""
Return the aesthetics that contribute to the legend
Parameters
----------
layer : Layer
Layer whose legend is to be drawn
plot : ggplot
Plot object
Returns
-------
matched : li... | [
"def",
"legend_aesthetics",
"(",
"self",
",",
"layer",
",",
"plot",
")",
":",
"l",
"=",
"layer",
"legend_ae",
"=",
"set",
"(",
"self",
".",
"key",
".",
"columns",
")",
"-",
"{",
"'label'",
"}",
"all_ae",
"=",
"(",
"l",
".",
"mapping",
".",
"keys",
... | Return the aesthetics that contribute to the legend
Parameters
----------
layer : Layer
Layer whose legend is to be drawn
plot : ggplot
Plot object
Returns
-------
matched : list
List of the names of the aethetics that contrib... | [
"Return",
"the",
"aesthetics",
"that",
"contribute",
"to",
"the",
"legend"
] | 566e579af705367e584fb27a74e6c5199624ca89 | https://github.com/has2k1/plotnine/blob/566e579af705367e584fb27a74e6c5199624ca89/plotnine/guides/guide.py#L197-L222 | train |
has2k1/plotnine | plotnine/scales/scale.py | scale.train_df | def train_df(self, df):
"""
Train scale from a dataframe
"""
aesthetics = sorted(set(self.aesthetics) & set(df.columns))
for ae in aesthetics:
self.train(df[ae]) | python | def train_df(self, df):
"""
Train scale from a dataframe
"""
aesthetics = sorted(set(self.aesthetics) & set(df.columns))
for ae in aesthetics:
self.train(df[ae]) | [
"def",
"train_df",
"(",
"self",
",",
"df",
")",
":",
"aesthetics",
"=",
"sorted",
"(",
"set",
"(",
"self",
".",
"aesthetics",
")",
"&",
"set",
"(",
"df",
".",
"columns",
")",
")",
"for",
"ae",
"in",
"aesthetics",
":",
"self",
".",
"train",
"(",
"... | Train scale from a dataframe | [
"Train",
"scale",
"from",
"a",
"dataframe"
] | 566e579af705367e584fb27a74e6c5199624ca89 | https://github.com/has2k1/plotnine/blob/566e579af705367e584fb27a74e6c5199624ca89/plotnine/scales/scale.py#L214-L220 | train |
has2k1/plotnine | plotnine/guides/guide_legend.py | guide_legend.train | def train(self, scale, aesthetic=None):
"""
Create the key for the guide
The key is a dataframe with two columns:
- scale name : values
- label : labels for each value
scale name is one of the aesthetics
['x', 'y', 'color', 'fill', 'size', 'shape', 'alph... | python | def train(self, scale, aesthetic=None):
"""
Create the key for the guide
The key is a dataframe with two columns:
- scale name : values
- label : labels for each value
scale name is one of the aesthetics
['x', 'y', 'color', 'fill', 'size', 'shape', 'alph... | [
"def",
"train",
"(",
"self",
",",
"scale",
",",
"aesthetic",
"=",
"None",
")",
":",
"if",
"aesthetic",
"is",
"None",
":",
"aesthetic",
"=",
"scale",
".",
"aesthetics",
"[",
"0",
"]",
"breaks",
"=",
"scale",
".",
"get_breaks",
"(",
")",
"if",
"isinsta... | Create the key for the guide
The key is a dataframe with two columns:
- scale name : values
- label : labels for each value
scale name is one of the aesthetics
['x', 'y', 'color', 'fill', 'size', 'shape', 'alpha',
'stroke']
Returns this guide if traini... | [
"Create",
"the",
"key",
"for",
"the",
"guide"
] | 566e579af705367e584fb27a74e6c5199624ca89 | https://github.com/has2k1/plotnine/blob/566e579af705367e584fb27a74e6c5199624ca89/plotnine/guides/guide_legend.py#L54-L108 | train |
has2k1/plotnine | plotnine/guides/guide_legend.py | guide_legend.create_geoms | def create_geoms(self, plot):
"""
Make information needed to draw a legend for each of the layers.
For each layer, that information is a dictionary with the geom
to draw the guide together with the data and the parameters that
will be used in the call to geom.
"""
... | python | def create_geoms(self, plot):
"""
Make information needed to draw a legend for each of the layers.
For each layer, that information is a dictionary with the geom
to draw the guide together with the data and the parameters that
will be used in the call to geom.
"""
... | [
"def",
"create_geoms",
"(",
"self",
",",
"plot",
")",
":",
"def",
"get_legend_geom",
"(",
"layer",
")",
":",
"if",
"hasattr",
"(",
"layer",
".",
"geom",
",",
"'draw_legend'",
")",
":",
"geom",
"=",
"layer",
".",
"geom",
".",
"__class__",
"else",
":",
... | Make information needed to draw a legend for each of the layers.
For each layer, that information is a dictionary with the geom
to draw the guide together with the data and the parameters that
will be used in the call to geom. | [
"Make",
"information",
"needed",
"to",
"draw",
"a",
"legend",
"for",
"each",
"of",
"the",
"layers",
"."
] | 566e579af705367e584fb27a74e6c5199624ca89 | https://github.com/has2k1/plotnine/blob/566e579af705367e584fb27a74e6c5199624ca89/plotnine/guides/guide_legend.py#L132-L182 | train |
has2k1/plotnine | setup.py | get_package_data | def get_package_data():
"""
Return package data
For example:
{'': ['*.txt', '*.rst'],
'hello': ['*.msg']}
means:
- If any package contains *.txt or *.rst files,
include them
- And include any *.msg files found in
the 'hello' package, too:
"""
... | python | def get_package_data():
"""
Return package data
For example:
{'': ['*.txt', '*.rst'],
'hello': ['*.msg']}
means:
- If any package contains *.txt or *.rst files,
include them
- And include any *.msg files found in
the 'hello' package, too:
"""
... | [
"def",
"get_package_data",
"(",
")",
":",
"baseline_images",
"=",
"[",
"'tests/baseline_images/%s/*'",
"%",
"x",
"for",
"x",
"in",
"os",
".",
"listdir",
"(",
"'plotnine/tests/baseline_images'",
")",
"]",
"csv_data",
"=",
"[",
"'data/*.csv'",
"]",
"package_data",
... | Return package data
For example:
{'': ['*.txt', '*.rst'],
'hello': ['*.msg']}
means:
- If any package contains *.txt or *.rst files,
include them
- And include any *.msg files found in
the 'hello' package, too: | [
"Return",
"package",
"data"
] | 566e579af705367e584fb27a74e6c5199624ca89 | https://github.com/has2k1/plotnine/blob/566e579af705367e584fb27a74e6c5199624ca89/setup.py#L73-L93 | train |
has2k1/plotnine | plotnine/__init__.py | _get_all_imports | def _get_all_imports():
"""
Return list of all the imports
This prevents sub-modules (geoms, stats, utils, ...)
from being imported into the user namespace by the
following import statement
from plotnine import *
This is because `from Module import Something`
leads to `Module` its... | python | def _get_all_imports():
"""
Return list of all the imports
This prevents sub-modules (geoms, stats, utils, ...)
from being imported into the user namespace by the
following import statement
from plotnine import *
This is because `from Module import Something`
leads to `Module` its... | [
"def",
"_get_all_imports",
"(",
")",
":",
"import",
"types",
"lst",
"=",
"[",
"name",
"for",
"name",
",",
"obj",
"in",
"globals",
"(",
")",
".",
"items",
"(",
")",
"if",
"not",
"(",
"name",
".",
"startswith",
"(",
"'_'",
")",
"or",
"name",
"==",
... | Return list of all the imports
This prevents sub-modules (geoms, stats, utils, ...)
from being imported into the user namespace by the
following import statement
from plotnine import *
This is because `from Module import Something`
leads to `Module` itself coming into the namespace!! | [
"Return",
"list",
"of",
"all",
"the",
"imports"
] | 566e579af705367e584fb27a74e6c5199624ca89 | https://github.com/has2k1/plotnine/blob/566e579af705367e584fb27a74e6c5199624ca89/plotnine/__init__.py#L22-L40 | train |
has2k1/plotnine | plotnine/geoms/geom_rect.py | _rectangles_to_polygons | def _rectangles_to_polygons(df):
"""
Convert rect data to polygons
Paramters
---------
df : dataframe
Dataframe with *xmin*, *xmax*, *ymin* and *ymax* columns,
plus others for aesthetics ...
Returns
-------
data : dataframe
Dataframe with *x* and *y* columns, pl... | python | def _rectangles_to_polygons(df):
"""
Convert rect data to polygons
Paramters
---------
df : dataframe
Dataframe with *xmin*, *xmax*, *ymin* and *ymax* columns,
plus others for aesthetics ...
Returns
-------
data : dataframe
Dataframe with *x* and *y* columns, pl... | [
"def",
"_rectangles_to_polygons",
"(",
"df",
")",
":",
"n",
"=",
"len",
"(",
"df",
")",
"# Helper indexing arrays",
"xmin_idx",
"=",
"np",
".",
"tile",
"(",
"[",
"True",
",",
"True",
",",
"False",
",",
"False",
"]",
",",
"n",
")",
"xmax_idx",
"=",
"~... | Convert rect data to polygons
Paramters
---------
df : dataframe
Dataframe with *xmin*, *xmax*, *ymin* and *ymax* columns,
plus others for aesthetics ...
Returns
-------
data : dataframe
Dataframe with *x* and *y* columns, plus others for
aesthetics ... | [
"Convert",
"rect",
"data",
"to",
"polygons"
] | 566e579af705367e584fb27a74e6c5199624ca89 | https://github.com/has2k1/plotnine/blob/566e579af705367e584fb27a74e6c5199624ca89/plotnine/geoms/geom_rect.py#L73-L116 | train |
has2k1/plotnine | plotnine/aes.py | rename_aesthetics | def rename_aesthetics(obj):
"""
Rename aesthetics in obj
Parameters
----------
obj : dict or list
Object that contains aesthetics names
Returns
-------
obj : dict or list
Object that contains aesthetics names
"""
if isinstance(obj, dict):
for name in obj... | python | def rename_aesthetics(obj):
"""
Rename aesthetics in obj
Parameters
----------
obj : dict or list
Object that contains aesthetics names
Returns
-------
obj : dict or list
Object that contains aesthetics names
"""
if isinstance(obj, dict):
for name in obj... | [
"def",
"rename_aesthetics",
"(",
"obj",
")",
":",
"if",
"isinstance",
"(",
"obj",
",",
"dict",
")",
":",
"for",
"name",
"in",
"obj",
":",
"new_name",
"=",
"name",
".",
"replace",
"(",
"'colour'",
",",
"'color'",
")",
"if",
"name",
"!=",
"new_name",
"... | Rename aesthetics in obj
Parameters
----------
obj : dict or list
Object that contains aesthetics names
Returns
-------
obj : dict or list
Object that contains aesthetics names | [
"Rename",
"aesthetics",
"in",
"obj"
] | 566e579af705367e584fb27a74e6c5199624ca89 | https://github.com/has2k1/plotnine/blob/566e579af705367e584fb27a74e6c5199624ca89/plotnine/aes.py#L144-L166 | train |
has2k1/plotnine | plotnine/aes.py | get_calculated_aes | def get_calculated_aes(aesthetics):
"""
Return a list of the aesthetics that are calculated
"""
calculated_aesthetics = []
for name, value in aesthetics.items():
if is_calculated_aes(value):
calculated_aesthetics.append(name)
return calculated_aesthetics | python | def get_calculated_aes(aesthetics):
"""
Return a list of the aesthetics that are calculated
"""
calculated_aesthetics = []
for name, value in aesthetics.items():
if is_calculated_aes(value):
calculated_aesthetics.append(name)
return calculated_aesthetics | [
"def",
"get_calculated_aes",
"(",
"aesthetics",
")",
":",
"calculated_aesthetics",
"=",
"[",
"]",
"for",
"name",
",",
"value",
"in",
"aesthetics",
".",
"items",
"(",
")",
":",
"if",
"is_calculated_aes",
"(",
"value",
")",
":",
"calculated_aesthetics",
".",
"... | Return a list of the aesthetics that are calculated | [
"Return",
"a",
"list",
"of",
"the",
"aesthetics",
"that",
"are",
"calculated"
] | 566e579af705367e584fb27a74e6c5199624ca89 | https://github.com/has2k1/plotnine/blob/566e579af705367e584fb27a74e6c5199624ca89/plotnine/aes.py#L169-L177 | train |
has2k1/plotnine | plotnine/aes.py | is_calculated_aes | def is_calculated_aes(ae):
"""
Return a True if of the aesthetics that are calculated
Parameters
----------
ae : object
Aesthetic mapping
>>> is_calculated_aes('density')
False
>>> is_calculated_aes(4)
False
>>> is_calculated_aes('..density..')
True
>>> is_ca... | python | def is_calculated_aes(ae):
"""
Return a True if of the aesthetics that are calculated
Parameters
----------
ae : object
Aesthetic mapping
>>> is_calculated_aes('density')
False
>>> is_calculated_aes(4)
False
>>> is_calculated_aes('..density..')
True
>>> is_ca... | [
"def",
"is_calculated_aes",
"(",
"ae",
")",
":",
"if",
"not",
"isinstance",
"(",
"ae",
",",
"str",
")",
":",
"return",
"False",
"for",
"pattern",
"in",
"(",
"STAT_RE",
",",
"DOTS_RE",
")",
":",
"if",
"pattern",
".",
"search",
"(",
"ae",
")",
":",
"... | Return a True if of the aesthetics that are calculated
Parameters
----------
ae : object
Aesthetic mapping
>>> is_calculated_aes('density')
False
>>> is_calculated_aes(4)
False
>>> is_calculated_aes('..density..')
True
>>> is_calculated_aes('stat(density)')
True
... | [
"Return",
"a",
"True",
"if",
"of",
"the",
"aesthetics",
"that",
"are",
"calculated"
] | 566e579af705367e584fb27a74e6c5199624ca89 | https://github.com/has2k1/plotnine/blob/566e579af705367e584fb27a74e6c5199624ca89/plotnine/aes.py#L180-L214 | train |
has2k1/plotnine | plotnine/aes.py | strip_stat | def strip_stat(value):
"""
Remove calc function that mark calculated aesthetics
Parameters
----------
value : object
Aesthetic value. In most cases this will be a string
but other types will pass through unmodified.
Return
------
out : object
Aesthetic value wit... | python | def strip_stat(value):
"""
Remove calc function that mark calculated aesthetics
Parameters
----------
value : object
Aesthetic value. In most cases this will be a string
but other types will pass through unmodified.
Return
------
out : object
Aesthetic value wit... | [
"def",
"strip_stat",
"(",
"value",
")",
":",
"def",
"strip_hanging_closing_parens",
"(",
"s",
")",
":",
"\"\"\"\n Remove leftover parens\n \"\"\"",
"# Use and integer stack to track parens",
"# and ignore leftover closing parens",
"stack",
"=",
"0",
"idx",
"=",
... | Remove calc function that mark calculated aesthetics
Parameters
----------
value : object
Aesthetic value. In most cases this will be a string
but other types will pass through unmodified.
Return
------
out : object
Aesthetic value with the dots removed.
>>> strip_... | [
"Remove",
"calc",
"function",
"that",
"mark",
"calculated",
"aesthetics"
] | 566e579af705367e584fb27a74e6c5199624ca89 | https://github.com/has2k1/plotnine/blob/566e579af705367e584fb27a74e6c5199624ca89/plotnine/aes.py#L234-L291 | train |
has2k1/plotnine | plotnine/aes.py | is_position_aes | def is_position_aes(vars_):
"""
Figure out if an aesthetic is a position aesthetic or not
"""
try:
return all([aes_to_scale(v) in {'x', 'y'} for v in vars_])
except TypeError:
return aes_to_scale(vars_) in {'x', 'y'} | python | def is_position_aes(vars_):
"""
Figure out if an aesthetic is a position aesthetic or not
"""
try:
return all([aes_to_scale(v) in {'x', 'y'} for v in vars_])
except TypeError:
return aes_to_scale(vars_) in {'x', 'y'} | [
"def",
"is_position_aes",
"(",
"vars_",
")",
":",
"try",
":",
"return",
"all",
"(",
"[",
"aes_to_scale",
"(",
"v",
")",
"in",
"{",
"'x'",
",",
"'y'",
"}",
"for",
"v",
"in",
"vars_",
"]",
")",
"except",
"TypeError",
":",
"return",
"aes_to_scale",
"(",... | Figure out if an aesthetic is a position aesthetic or not | [
"Figure",
"out",
"if",
"an",
"aesthetic",
"is",
"a",
"position",
"aesthetic",
"or",
"not"
] | 566e579af705367e584fb27a74e6c5199624ca89 | https://github.com/has2k1/plotnine/blob/566e579af705367e584fb27a74e6c5199624ca89/plotnine/aes.py#L343-L350 | train |
has2k1/plotnine | plotnine/aes.py | make_labels | def make_labels(mapping):
"""
Convert aesthetic mapping into text labels
"""
labels = mapping.copy()
for ae in labels:
labels[ae] = strip_calculated_markers(labels[ae])
return labels | python | def make_labels(mapping):
"""
Convert aesthetic mapping into text labels
"""
labels = mapping.copy()
for ae in labels:
labels[ae] = strip_calculated_markers(labels[ae])
return labels | [
"def",
"make_labels",
"(",
"mapping",
")",
":",
"labels",
"=",
"mapping",
".",
"copy",
"(",
")",
"for",
"ae",
"in",
"labels",
":",
"labels",
"[",
"ae",
"]",
"=",
"strip_calculated_markers",
"(",
"labels",
"[",
"ae",
"]",
")",
"return",
"labels"
] | Convert aesthetic mapping into text labels | [
"Convert",
"aesthetic",
"mapping",
"into",
"text",
"labels"
] | 566e579af705367e584fb27a74e6c5199624ca89 | https://github.com/has2k1/plotnine/blob/566e579af705367e584fb27a74e6c5199624ca89/plotnine/aes.py#L353-L360 | train |
has2k1/plotnine | plotnine/aes.py | is_valid_aesthetic | def is_valid_aesthetic(value, ae):
"""
Return True if `value` looks valid.
Parameters
----------
value : object
Value to check
ae : str
Aesthetic name
Returns
-------
out : bool
Whether the value is of a valid looking form.
Notes
-----
There are... | python | def is_valid_aesthetic(value, ae):
"""
Return True if `value` looks valid.
Parameters
----------
value : object
Value to check
ae : str
Aesthetic name
Returns
-------
out : bool
Whether the value is of a valid looking form.
Notes
-----
There are... | [
"def",
"is_valid_aesthetic",
"(",
"value",
",",
"ae",
")",
":",
"if",
"ae",
"==",
"'linetype'",
":",
"named",
"=",
"{",
"'solid'",
",",
"'dashed'",
",",
"'dashdot'",
",",
"'dotted'",
",",
"'_'",
",",
"'--'",
",",
"'-.'",
",",
"':'",
",",
"'None'",
",... | Return True if `value` looks valid.
Parameters
----------
value : object
Value to check
ae : str
Aesthetic name
Returns
-------
out : bool
Whether the value is of a valid looking form.
Notes
-----
There are no guarantees that he value is spot on
val... | [
"Return",
"True",
"if",
"value",
"looks",
"valid",
"."
] | 566e579af705367e584fb27a74e6c5199624ca89 | https://github.com/has2k1/plotnine/blob/566e579af705367e584fb27a74e6c5199624ca89/plotnine/aes.py#L363-L428 | train |
has2k1/plotnine | plotnine/facets/facet_wrap.py | parse_wrap_facets | def parse_wrap_facets(facets):
"""
Return list of facetting variables
"""
valid_forms = ['~ var1', '~ var1 + var2']
error_msg = ("Valid formula for 'facet_wrap' look like"
" {}".format(valid_forms))
if isinstance(facets, (list, tuple)):
return facets
if not isinsta... | python | def parse_wrap_facets(facets):
"""
Return list of facetting variables
"""
valid_forms = ['~ var1', '~ var1 + var2']
error_msg = ("Valid formula for 'facet_wrap' look like"
" {}".format(valid_forms))
if isinstance(facets, (list, tuple)):
return facets
if not isinsta... | [
"def",
"parse_wrap_facets",
"(",
"facets",
")",
":",
"valid_forms",
"=",
"[",
"'~ var1'",
",",
"'~ var1 + var2'",
"]",
"error_msg",
"=",
"(",
"\"Valid formula for 'facet_wrap' look like\"",
"\" {}\"",
".",
"format",
"(",
"valid_forms",
")",
")",
"if",
"isinstance",
... | Return list of facetting variables | [
"Return",
"list",
"of",
"facetting",
"variables"
] | 566e579af705367e584fb27a74e6c5199624ca89 | https://github.com/has2k1/plotnine/blob/566e579af705367e584fb27a74e6c5199624ca89/plotnine/facets/facet_wrap.py#L256-L284 | train |
has2k1/plotnine | plotnine/facets/facet_wrap.py | n2mfrow | def n2mfrow(nr_plots):
"""
Compute the rows and columns given the number
of plots.
This is a port of grDevices::n2mfrow from R
"""
if nr_plots <= 3:
nrow, ncol = nr_plots, 1
elif nr_plots <= 6:
nrow, ncol = (nr_plots + 1) // 2, 2
elif nr_plots <= 12:
nrow, ncol =... | python | def n2mfrow(nr_plots):
"""
Compute the rows and columns given the number
of plots.
This is a port of grDevices::n2mfrow from R
"""
if nr_plots <= 3:
nrow, ncol = nr_plots, 1
elif nr_plots <= 6:
nrow, ncol = (nr_plots + 1) // 2, 2
elif nr_plots <= 12:
nrow, ncol =... | [
"def",
"n2mfrow",
"(",
"nr_plots",
")",
":",
"if",
"nr_plots",
"<=",
"3",
":",
"nrow",
",",
"ncol",
"=",
"nr_plots",
",",
"1",
"elif",
"nr_plots",
"<=",
"6",
":",
"nrow",
",",
"ncol",
"=",
"(",
"nr_plots",
"+",
"1",
")",
"//",
"2",
",",
"2",
"e... | Compute the rows and columns given the number
of plots.
This is a port of grDevices::n2mfrow from R | [
"Compute",
"the",
"rows",
"and",
"columns",
"given",
"the",
"number",
"of",
"plots",
"."
] | 566e579af705367e584fb27a74e6c5199624ca89 | https://github.com/has2k1/plotnine/blob/566e579af705367e584fb27a74e6c5199624ca89/plotnine/facets/facet_wrap.py#L302-L318 | train |
has2k1/plotnine | plotnine/facets/facet_wrap.py | facet_wrap.spaceout_and_resize_panels | def spaceout_and_resize_panels(self):
"""
Adjust the spacing between the panels and resize them
to meet the aspect ratio
"""
ncol = self.ncol
nrow = self.nrow
figure = self.figure
theme = self.theme
get_property = theme.themeables.property
... | python | def spaceout_and_resize_panels(self):
"""
Adjust the spacing between the panels and resize them
to meet the aspect ratio
"""
ncol = self.ncol
nrow = self.nrow
figure = self.figure
theme = self.theme
get_property = theme.themeables.property
... | [
"def",
"spaceout_and_resize_panels",
"(",
"self",
")",
":",
"ncol",
"=",
"self",
".",
"ncol",
"nrow",
"=",
"self",
".",
"nrow",
"figure",
"=",
"self",
".",
"figure",
"theme",
"=",
"self",
".",
"theme",
"get_property",
"=",
"theme",
".",
"themeables",
"."... | Adjust the spacing between the panels and resize them
to meet the aspect ratio | [
"Adjust",
"the",
"spacing",
"between",
"the",
"panels",
"and",
"resize",
"them",
"to",
"meet",
"the",
"aspect",
"ratio"
] | 566e579af705367e584fb27a74e6c5199624ca89 | https://github.com/has2k1/plotnine/blob/566e579af705367e584fb27a74e6c5199624ca89/plotnine/facets/facet_wrap.py#L149-L215 | train |
has2k1/plotnine | plotnine/themes/elements.py | Margin.get_as | def get_as(self, key, units='pt'):
"""
Return key in given units
"""
dpi = 72
size = self.element.properties.get('size', 0)
value = self[key]
functions = {
'pt-lines': lambda x: x/size,
'pt-in': lambda x: x/dpi,
'lines-pt': lam... | python | def get_as(self, key, units='pt'):
"""
Return key in given units
"""
dpi = 72
size = self.element.properties.get('size', 0)
value = self[key]
functions = {
'pt-lines': lambda x: x/size,
'pt-in': lambda x: x/dpi,
'lines-pt': lam... | [
"def",
"get_as",
"(",
"self",
",",
"key",
",",
"units",
"=",
"'pt'",
")",
":",
"dpi",
"=",
"72",
"size",
"=",
"self",
".",
"element",
".",
"properties",
".",
"get",
"(",
"'size'",
",",
"0",
")",
"value",
"=",
"self",
"[",
"key",
"]",
"functions",... | Return key in given units | [
"Return",
"key",
"in",
"given",
"units"
] | 566e579af705367e584fb27a74e6c5199624ca89 | https://github.com/has2k1/plotnine/blob/566e579af705367e584fb27a74e6c5199624ca89/plotnine/themes/elements.py#L223-L247 | train |
has2k1/plotnine | plotnine/layer.py | discrete_columns | def discrete_columns(df, ignore):
"""
Return a list of the discrete columns in the
dataframe `df`. `ignore` is a list|set|tuple with the
names of the columns to skip.
"""
lst = []
for col in df:
if array_kind.discrete(df[col]) and (col not in ignore):
# Some columns are r... | python | def discrete_columns(df, ignore):
"""
Return a list of the discrete columns in the
dataframe `df`. `ignore` is a list|set|tuple with the
names of the columns to skip.
"""
lst = []
for col in df:
if array_kind.discrete(df[col]) and (col not in ignore):
# Some columns are r... | [
"def",
"discrete_columns",
"(",
"df",
",",
"ignore",
")",
":",
"lst",
"=",
"[",
"]",
"for",
"col",
"in",
"df",
":",
"if",
"array_kind",
".",
"discrete",
"(",
"df",
"[",
"col",
"]",
")",
"and",
"(",
"col",
"not",
"in",
"ignore",
")",
":",
"# Some ... | Return a list of the discrete columns in the
dataframe `df`. `ignore` is a list|set|tuple with the
names of the columns to skip. | [
"Return",
"a",
"list",
"of",
"the",
"discrete",
"columns",
"in",
"the",
"dataframe",
"df",
".",
"ignore",
"is",
"a",
"list|set|tuple",
"with",
"the",
"names",
"of",
"the",
"columns",
"to",
"skip",
"."
] | 566e579af705367e584fb27a74e6c5199624ca89 | https://github.com/has2k1/plotnine/blob/566e579af705367e584fb27a74e6c5199624ca89/plotnine/layer.py#L490-L506 | train |
has2k1/plotnine | plotnine/layer.py | is_known_scalar | def is_known_scalar(value):
"""
Return True if value is a type we expect in a dataframe
"""
def _is_datetime_or_timedelta(value):
# Using pandas.Series helps catch python, numpy and pandas
# versions of these types
return pd.Series(value).dtype.kind in ('M', 'm')
return not ... | python | def is_known_scalar(value):
"""
Return True if value is a type we expect in a dataframe
"""
def _is_datetime_or_timedelta(value):
# Using pandas.Series helps catch python, numpy and pandas
# versions of these types
return pd.Series(value).dtype.kind in ('M', 'm')
return not ... | [
"def",
"is_known_scalar",
"(",
"value",
")",
":",
"def",
"_is_datetime_or_timedelta",
"(",
"value",
")",
":",
"# Using pandas.Series helps catch python, numpy and pandas",
"# versions of these types",
"return",
"pd",
".",
"Series",
"(",
"value",
")",
".",
"dtype",
".",
... | Return True if value is a type we expect in a dataframe | [
"Return",
"True",
"if",
"value",
"is",
"a",
"type",
"we",
"expect",
"in",
"a",
"dataframe"
] | 566e579af705367e584fb27a74e6c5199624ca89 | https://github.com/has2k1/plotnine/blob/566e579af705367e584fb27a74e6c5199624ca89/plotnine/layer.py#L509-L519 | train |
has2k1/plotnine | plotnine/layer.py | layer.generate_data | def generate_data(self, plot_data):
"""
Generate data to be used by this layer
Parameters
----------
plot_data : dataframe
ggplot object data
"""
# Each layer that does not have data gets a copy of
# of the ggplot.data. If the has data it is r... | python | def generate_data(self, plot_data):
"""
Generate data to be used by this layer
Parameters
----------
plot_data : dataframe
ggplot object data
"""
# Each layer that does not have data gets a copy of
# of the ggplot.data. If the has data it is r... | [
"def",
"generate_data",
"(",
"self",
",",
"plot_data",
")",
":",
"# Each layer that does not have data gets a copy of",
"# of the ggplot.data. If the has data it is replaced",
"# by copy so that we do not alter the users data",
"if",
"self",
".",
"data",
"is",
"None",
":",
"self"... | Generate data to be used by this layer
Parameters
----------
plot_data : dataframe
ggplot object data | [
"Generate",
"data",
"to",
"be",
"used",
"by",
"this",
"layer"
] | 566e579af705367e584fb27a74e6c5199624ca89 | https://github.com/has2k1/plotnine/blob/566e579af705367e584fb27a74e6c5199624ca89/plotnine/layer.py#L229-L249 | train |
has2k1/plotnine | plotnine/layer.py | layer.layer_mapping | def layer_mapping(self, mapping):
"""
Return the mappings that are active in this layer
Parameters
----------
mapping : aes
mappings in the ggplot call
Notes
-----
Once computed the layer mappings are also stored
in self._active_mappi... | python | def layer_mapping(self, mapping):
"""
Return the mappings that are active in this layer
Parameters
----------
mapping : aes
mappings in the ggplot call
Notes
-----
Once computed the layer mappings are also stored
in self._active_mappi... | [
"def",
"layer_mapping",
"(",
"self",
",",
"mapping",
")",
":",
"# For certain geoms, it is useful to be able to",
"# ignore the default aesthetics and only use those",
"# set in the layer",
"if",
"self",
".",
"inherit_aes",
":",
"aesthetics",
"=",
"defaults",
"(",
"self",
"... | Return the mappings that are active in this layer
Parameters
----------
mapping : aes
mappings in the ggplot call
Notes
-----
Once computed the layer mappings are also stored
in self._active_mapping | [
"Return",
"the",
"mappings",
"that",
"are",
"active",
"in",
"this",
"layer"
] | 566e579af705367e584fb27a74e6c5199624ca89 | https://github.com/has2k1/plotnine/blob/566e579af705367e584fb27a74e6c5199624ca89/plotnine/layer.py#L251-L279 | train |
has2k1/plotnine | plotnine/layer.py | layer.compute_aesthetics | def compute_aesthetics(self, plot):
"""
Return a dataframe where the columns match the
aesthetic mappings.
Transformations like 'factor(cyl)' and other
expression evaluation are made in here
"""
data = self.data
aesthetics = self.layer_mapping(plot.mappi... | python | def compute_aesthetics(self, plot):
"""
Return a dataframe where the columns match the
aesthetic mappings.
Transformations like 'factor(cyl)' and other
expression evaluation are made in here
"""
data = self.data
aesthetics = self.layer_mapping(plot.mappi... | [
"def",
"compute_aesthetics",
"(",
"self",
",",
"plot",
")",
":",
"data",
"=",
"self",
".",
"data",
"aesthetics",
"=",
"self",
".",
"layer_mapping",
"(",
"plot",
".",
"mapping",
")",
"# Override grouping if set in layer.",
"with",
"suppress",
"(",
"KeyError",
"... | Return a dataframe where the columns match the
aesthetic mappings.
Transformations like 'factor(cyl)' and other
expression evaluation are made in here | [
"Return",
"a",
"dataframe",
"where",
"the",
"columns",
"match",
"the",
"aesthetic",
"mappings",
"."
] | 566e579af705367e584fb27a74e6c5199624ca89 | https://github.com/has2k1/plotnine/blob/566e579af705367e584fb27a74e6c5199624ca89/plotnine/layer.py#L281-L348 | train |
has2k1/plotnine | plotnine/layer.py | layer.compute_statistic | def compute_statistic(self, layout):
"""
Compute & return statistics for this layer
"""
data = self.data
if not len(data):
return type(data)()
params = self.stat.setup_params(data)
data = self.stat.use_defaults(data)
data = self.stat.setup_dat... | python | def compute_statistic(self, layout):
"""
Compute & return statistics for this layer
"""
data = self.data
if not len(data):
return type(data)()
params = self.stat.setup_params(data)
data = self.stat.use_defaults(data)
data = self.stat.setup_dat... | [
"def",
"compute_statistic",
"(",
"self",
",",
"layout",
")",
":",
"data",
"=",
"self",
".",
"data",
"if",
"not",
"len",
"(",
"data",
")",
":",
"return",
"type",
"(",
"data",
")",
"(",
")",
"params",
"=",
"self",
".",
"stat",
".",
"setup_params",
"(... | Compute & return statistics for this layer | [
"Compute",
"&",
"return",
"statistics",
"for",
"this",
"layer"
] | 566e579af705367e584fb27a74e6c5199624ca89 | https://github.com/has2k1/plotnine/blob/566e579af705367e584fb27a74e6c5199624ca89/plotnine/layer.py#L350-L362 | train |
has2k1/plotnine | plotnine/layer.py | layer.map_statistic | def map_statistic(self, plot):
"""
Mapping aesthetics to computed statistics
"""
data = self.data
if not len(data):
return type(data)()
# Assemble aesthetics from layer, plot and stat mappings
aesthetics = deepcopy(self.mapping)
if self.inheri... | python | def map_statistic(self, plot):
"""
Mapping aesthetics to computed statistics
"""
data = self.data
if not len(data):
return type(data)()
# Assemble aesthetics from layer, plot and stat mappings
aesthetics = deepcopy(self.mapping)
if self.inheri... | [
"def",
"map_statistic",
"(",
"self",
",",
"plot",
")",
":",
"data",
"=",
"self",
".",
"data",
"if",
"not",
"len",
"(",
"data",
")",
":",
"return",
"type",
"(",
"data",
")",
"(",
")",
"# Assemble aesthetics from layer, plot and stat mappings",
"aesthetics",
"... | Mapping aesthetics to computed statistics | [
"Mapping",
"aesthetics",
"to",
"computed",
"statistics"
] | 566e579af705367e584fb27a74e6c5199624ca89 | https://github.com/has2k1/plotnine/blob/566e579af705367e584fb27a74e6c5199624ca89/plotnine/layer.py#L364-L409 | train |
has2k1/plotnine | plotnine/layer.py | layer.compute_position | def compute_position(self, layout):
"""
Compute the position of each geometric object
in concert with the other objects in the panel
"""
params = self.position.setup_params(self.data)
data = self.position.setup_data(self.data, params)
data = self.position.compute_... | python | def compute_position(self, layout):
"""
Compute the position of each geometric object
in concert with the other objects in the panel
"""
params = self.position.setup_params(self.data)
data = self.position.setup_data(self.data, params)
data = self.position.compute_... | [
"def",
"compute_position",
"(",
"self",
",",
"layout",
")",
":",
"params",
"=",
"self",
".",
"position",
".",
"setup_params",
"(",
"self",
".",
"data",
")",
"data",
"=",
"self",
".",
"position",
".",
"setup_data",
"(",
"self",
".",
"data",
",",
"params... | Compute the position of each geometric object
in concert with the other objects in the panel | [
"Compute",
"the",
"position",
"of",
"each",
"geometric",
"object",
"in",
"concert",
"with",
"the",
"other",
"objects",
"in",
"the",
"panel"
] | 566e579af705367e584fb27a74e6c5199624ca89 | https://github.com/has2k1/plotnine/blob/566e579af705367e584fb27a74e6c5199624ca89/plotnine/layer.py#L428-L436 | train |
has2k1/plotnine | plotnine/scales/range.py | RangeContinuous.train | def train(self, x):
"""
Train continuous range
"""
self.range = scale_continuous.train(x, self.range) | python | def train(self, x):
"""
Train continuous range
"""
self.range = scale_continuous.train(x, self.range) | [
"def",
"train",
"(",
"self",
",",
"x",
")",
":",
"self",
".",
"range",
"=",
"scale_continuous",
".",
"train",
"(",
"x",
",",
"self",
".",
"range",
")"
] | Train continuous range | [
"Train",
"continuous",
"range"
] | 566e579af705367e584fb27a74e6c5199624ca89 | https://github.com/has2k1/plotnine/blob/566e579af705367e584fb27a74e6c5199624ca89/plotnine/scales/range.py#L28-L32 | train |
has2k1/plotnine | plotnine/scales/range.py | RangeDiscrete.train | def train(self, x, drop=False, na_rm=False):
"""
Train discrete range
"""
self.range = scale_discrete.train(x, self.range, drop, na_rm=na_rm) | python | def train(self, x, drop=False, na_rm=False):
"""
Train discrete range
"""
self.range = scale_discrete.train(x, self.range, drop, na_rm=na_rm) | [
"def",
"train",
"(",
"self",
",",
"x",
",",
"drop",
"=",
"False",
",",
"na_rm",
"=",
"False",
")",
":",
"self",
".",
"range",
"=",
"scale_discrete",
".",
"train",
"(",
"x",
",",
"self",
".",
"range",
",",
"drop",
",",
"na_rm",
"=",
"na_rm",
")"
] | Train discrete range | [
"Train",
"discrete",
"range"
] | 566e579af705367e584fb27a74e6c5199624ca89 | https://github.com/has2k1/plotnine/blob/566e579af705367e584fb27a74e6c5199624ca89/plotnine/scales/range.py#L39-L43 | train |
has2k1/plotnine | plotnine/utils.py | _margins | def _margins(vars, margins=True):
"""
Figure out margining variables.
Given the variables that form the rows and
columns, and a set of desired margins, works
out which ones are possible. Variables that
can't be margined over are dropped silently.
Parameters
----------
vars : list
... | python | def _margins(vars, margins=True):
"""
Figure out margining variables.
Given the variables that form the rows and
columns, and a set of desired margins, works
out which ones are possible. Variables that
can't be margined over are dropped silently.
Parameters
----------
vars : list
... | [
"def",
"_margins",
"(",
"vars",
",",
"margins",
"=",
"True",
")",
":",
"if",
"margins",
"is",
"False",
":",
"return",
"[",
"]",
"def",
"fn",
"(",
"_vars",
")",
":",
"\"The margin variables for a given row or column\"",
"# The first item is and empty list for no marg... | Figure out margining variables.
Given the variables that form the rows and
columns, and a set of desired margins, works
out which ones are possible. Variables that
can't be margined over are dropped silently.
Parameters
----------
vars : list
variable names for rows and columns
... | [
"Figure",
"out",
"margining",
"variables",
"."
] | 566e579af705367e584fb27a74e6c5199624ca89 | https://github.com/has2k1/plotnine/blob/566e579af705367e584fb27a74e6c5199624ca89/plotnine/utils.py#L143-L191 | train |
has2k1/plotnine | plotnine/utils.py | add_margins | def add_margins(df, vars, margins=True):
"""
Add margins to a data frame.
All margining variables will be converted to factors.
Parameters
----------
df : dataframe
input data frame
vars : list
a list of 2 lists | tuples vectors giving the
variables in each dimensi... | python | def add_margins(df, vars, margins=True):
"""
Add margins to a data frame.
All margining variables will be converted to factors.
Parameters
----------
df : dataframe
input data frame
vars : list
a list of 2 lists | tuples vectors giving the
variables in each dimensi... | [
"def",
"add_margins",
"(",
"df",
",",
"vars",
",",
"margins",
"=",
"True",
")",
":",
"margin_vars",
"=",
"_margins",
"(",
"vars",
",",
"margins",
")",
"if",
"not",
"margin_vars",
":",
"return",
"df",
"# create margin dataframes",
"margin_dfs",
"=",
"[",
"d... | Add margins to a data frame.
All margining variables will be converted to factors.
Parameters
----------
df : dataframe
input data frame
vars : list
a list of 2 lists | tuples vectors giving the
variables in each dimension
margins : bool | list
variable names ... | [
"Add",
"margins",
"to",
"a",
"data",
"frame",
"."
] | 566e579af705367e584fb27a74e6c5199624ca89 | https://github.com/has2k1/plotnine/blob/566e579af705367e584fb27a74e6c5199624ca89/plotnine/utils.py#L194-L244 | train |
has2k1/plotnine | plotnine/utils.py | _id_var | def _id_var(x, drop=False):
"""
Assign ids to items in x. If two items
are the same, they get the same id.
Parameters
----------
x : array-like
items to associate ids with
drop : bool
Whether to drop unused factor levels
"""
if len(x) == 0:
return []
cat... | python | def _id_var(x, drop=False):
"""
Assign ids to items in x. If two items
are the same, they get the same id.
Parameters
----------
x : array-like
items to associate ids with
drop : bool
Whether to drop unused factor levels
"""
if len(x) == 0:
return []
cat... | [
"def",
"_id_var",
"(",
"x",
",",
"drop",
"=",
"False",
")",
":",
"if",
"len",
"(",
"x",
")",
"==",
"0",
":",
"return",
"[",
"]",
"categorical",
"=",
"pdtypes",
".",
"is_categorical_dtype",
"(",
"x",
")",
"if",
"categorical",
":",
"if",
"drop",
":",... | Assign ids to items in x. If two items
are the same, they get the same id.
Parameters
----------
x : array-like
items to associate ids with
drop : bool
Whether to drop unused factor levels | [
"Assign",
"ids",
"to",
"items",
"in",
"x",
".",
"If",
"two",
"items",
"are",
"the",
"same",
"they",
"get",
"the",
"same",
"id",
"."
] | 566e579af705367e584fb27a74e6c5199624ca89 | https://github.com/has2k1/plotnine/blob/566e579af705367e584fb27a74e6c5199624ca89/plotnine/utils.py#L299-L339 | train |
has2k1/plotnine | plotnine/utils.py | join_keys | def join_keys(x, y, by=None):
"""
Join keys.
Given two data frames, create a unique key for each row.
Parameters
-----------
x : dataframe
y : dataframe
by : list-like
Column names to join by
Returns
-------
out : dict
Dictionary with keys x and y. The valu... | python | def join_keys(x, y, by=None):
"""
Join keys.
Given two data frames, create a unique key for each row.
Parameters
-----------
x : dataframe
y : dataframe
by : list-like
Column names to join by
Returns
-------
out : dict
Dictionary with keys x and y. The valu... | [
"def",
"join_keys",
"(",
"x",
",",
"y",
",",
"by",
"=",
"None",
")",
":",
"if",
"by",
"is",
"None",
":",
"by",
"=",
"slice",
"(",
"None",
",",
"None",
",",
"None",
")",
"if",
"isinstance",
"(",
"by",
",",
"tuple",
")",
":",
"by",
"=",
"list",... | Join keys.
Given two data frames, create a unique key for each row.
Parameters
-----------
x : dataframe
y : dataframe
by : list-like
Column names to join by
Returns
-------
out : dict
Dictionary with keys x and y. The values of both keys
are arrays with in... | [
"Join",
"keys",
"."
] | 566e579af705367e584fb27a74e6c5199624ca89 | https://github.com/has2k1/plotnine/blob/566e579af705367e584fb27a74e6c5199624ca89/plotnine/utils.py#L342-L374 | train |
has2k1/plotnine | plotnine/utils.py | uniquecols | def uniquecols(df):
"""
Return unique columns
This is used for figuring out which columns are
constant within a group
"""
bool_idx = df.apply(lambda col: len(np.unique(col)) == 1, axis=0)
df = df.loc[:, bool_idx].iloc[0:1, :].reset_index(drop=True)
return df | python | def uniquecols(df):
"""
Return unique columns
This is used for figuring out which columns are
constant within a group
"""
bool_idx = df.apply(lambda col: len(np.unique(col)) == 1, axis=0)
df = df.loc[:, bool_idx].iloc[0:1, :].reset_index(drop=True)
return df | [
"def",
"uniquecols",
"(",
"df",
")",
":",
"bool_idx",
"=",
"df",
".",
"apply",
"(",
"lambda",
"col",
":",
"len",
"(",
"np",
".",
"unique",
"(",
"col",
")",
")",
"==",
"1",
",",
"axis",
"=",
"0",
")",
"df",
"=",
"df",
".",
"loc",
"[",
":",
"... | Return unique columns
This is used for figuring out which columns are
constant within a group | [
"Return",
"unique",
"columns"
] | 566e579af705367e584fb27a74e6c5199624ca89 | https://github.com/has2k1/plotnine/blob/566e579af705367e584fb27a74e6c5199624ca89/plotnine/utils.py#L386-L395 | train |
has2k1/plotnine | plotnine/utils.py | defaults | def defaults(d1, d2):
"""
Update a copy of d1 with the contents of d2 that are
not in d1. d1 and d2 are dictionary like objects.
Parameters
----------
d1 : dict | dataframe
dict with the preferred values
d2 : dict | dataframe
dict with the default values
Returns
---... | python | def defaults(d1, d2):
"""
Update a copy of d1 with the contents of d2 that are
not in d1. d1 and d2 are dictionary like objects.
Parameters
----------
d1 : dict | dataframe
dict with the preferred values
d2 : dict | dataframe
dict with the default values
Returns
---... | [
"def",
"defaults",
"(",
"d1",
",",
"d2",
")",
":",
"d1",
"=",
"d1",
".",
"copy",
"(",
")",
"tolist",
"=",
"isinstance",
"(",
"d2",
",",
"pd",
".",
"DataFrame",
")",
"keys",
"=",
"(",
"k",
"for",
"k",
"in",
"d2",
"if",
"k",
"not",
"in",
"d1",
... | Update a copy of d1 with the contents of d2 that are
not in d1. d1 and d2 are dictionary like objects.
Parameters
----------
d1 : dict | dataframe
dict with the preferred values
d2 : dict | dataframe
dict with the default values
Returns
-------
out : dict | dataframe
... | [
"Update",
"a",
"copy",
"of",
"d1",
"with",
"the",
"contents",
"of",
"d2",
"that",
"are",
"not",
"in",
"d1",
".",
"d1",
"and",
"d2",
"are",
"dictionary",
"like",
"objects",
"."
] | 566e579af705367e584fb27a74e6c5199624ca89 | https://github.com/has2k1/plotnine/blob/566e579af705367e584fb27a74e6c5199624ca89/plotnine/utils.py#L398-L424 | train |
has2k1/plotnine | plotnine/utils.py | jitter | def jitter(x, factor=1, amount=None, random_state=None):
"""
Add a small amount of noise to values in an array_like
Parameters
----------
x : array_like
Values to apply a jitter
factor : float
Multiplicative value to used in automatically determining
the `amount`. If the... | python | def jitter(x, factor=1, amount=None, random_state=None):
"""
Add a small amount of noise to values in an array_like
Parameters
----------
x : array_like
Values to apply a jitter
factor : float
Multiplicative value to used in automatically determining
the `amount`. If the... | [
"def",
"jitter",
"(",
"x",
",",
"factor",
"=",
"1",
",",
"amount",
"=",
"None",
",",
"random_state",
"=",
"None",
")",
":",
"if",
"len",
"(",
"x",
")",
"==",
"0",
":",
"return",
"x",
"if",
"random_state",
"is",
"None",
":",
"random_state",
"=",
"... | Add a small amount of noise to values in an array_like
Parameters
----------
x : array_like
Values to apply a jitter
factor : float
Multiplicative value to used in automatically determining
the `amount`. If the `amount` is given then the `factor`
has no effect.
amoun... | [
"Add",
"a",
"small",
"amount",
"of",
"noise",
"to",
"values",
"in",
"an",
"array_like"
] | 566e579af705367e584fb27a74e6c5199624ca89 | https://github.com/has2k1/plotnine/blob/566e579af705367e584fb27a74e6c5199624ca89/plotnine/utils.py#L427-L489 | train |
has2k1/plotnine | plotnine/utils.py | remove_missing | def remove_missing(df, na_rm=False, vars=None, name='', finite=False):
"""
Convenience function to remove missing values from a dataframe
Parameters
----------
df : dataframe
na_rm : bool
If False remove all non-complete rows with and show warning.
vars : list-like
columns t... | python | def remove_missing(df, na_rm=False, vars=None, name='', finite=False):
"""
Convenience function to remove missing values from a dataframe
Parameters
----------
df : dataframe
na_rm : bool
If False remove all non-complete rows with and show warning.
vars : list-like
columns t... | [
"def",
"remove_missing",
"(",
"df",
",",
"na_rm",
"=",
"False",
",",
"vars",
"=",
"None",
",",
"name",
"=",
"''",
",",
"finite",
"=",
"False",
")",
":",
"n",
"=",
"len",
"(",
"df",
")",
"if",
"vars",
"is",
"None",
":",
"vars",
"=",
"df",
".",
... | Convenience function to remove missing values from a dataframe
Parameters
----------
df : dataframe
na_rm : bool
If False remove all non-complete rows with and show warning.
vars : list-like
columns to act on
name : str
Name of calling method for a more informative messa... | [
"Convenience",
"function",
"to",
"remove",
"missing",
"values",
"from",
"a",
"dataframe"
] | 566e579af705367e584fb27a74e6c5199624ca89 | https://github.com/has2k1/plotnine/blob/566e579af705367e584fb27a74e6c5199624ca89/plotnine/utils.py#L492-L528 | train |
has2k1/plotnine | plotnine/utils.py | to_rgba | def to_rgba(colors, alpha):
"""
Covert hex colors to rgba values.
Parameters
----------
colors : iterable | str
colors to convert
alphas : iterable | float
alpha values
Returns
-------
out : ndarray | tuple
rgba color(s)
Notes
-----
Matplotlib p... | python | def to_rgba(colors, alpha):
"""
Covert hex colors to rgba values.
Parameters
----------
colors : iterable | str
colors to convert
alphas : iterable | float
alpha values
Returns
-------
out : ndarray | tuple
rgba color(s)
Notes
-----
Matplotlib p... | [
"def",
"to_rgba",
"(",
"colors",
",",
"alpha",
")",
":",
"def",
"is_iterable",
"(",
"var",
")",
":",
"return",
"cbook",
".",
"iterable",
"(",
"var",
")",
"and",
"not",
"is_string",
"(",
"var",
")",
"def",
"has_alpha",
"(",
"c",
")",
":",
"if",
"isi... | Covert hex colors to rgba values.
Parameters
----------
colors : iterable | str
colors to convert
alphas : iterable | float
alpha values
Returns
-------
out : ndarray | tuple
rgba color(s)
Notes
-----
Matplotlib plotting functions only accept scalar
... | [
"Covert",
"hex",
"colors",
"to",
"rgba",
"values",
"."
] | 566e579af705367e584fb27a74e6c5199624ca89 | https://github.com/has2k1/plotnine/blob/566e579af705367e584fb27a74e6c5199624ca89/plotnine/utils.py#L531-L601 | train |
has2k1/plotnine | plotnine/utils.py | groupby_apply | def groupby_apply(df, cols, func, *args, **kwargs):
"""
Groupby cols and call the function fn on each grouped dataframe.
Parameters
----------
cols : str | list of str
columns to groupby
func : function
function to call on the grouped data
*args : tuple
positional pa... | python | def groupby_apply(df, cols, func, *args, **kwargs):
"""
Groupby cols and call the function fn on each grouped dataframe.
Parameters
----------
cols : str | list of str
columns to groupby
func : function
function to call on the grouped data
*args : tuple
positional pa... | [
"def",
"groupby_apply",
"(",
"df",
",",
"cols",
",",
"func",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"try",
":",
"axis",
"=",
"kwargs",
".",
"pop",
"(",
"'axis'",
")",
"except",
"KeyError",
":",
"axis",
"=",
"0",
"lst",
"=",
"[",
"... | Groupby cols and call the function fn on each grouped dataframe.
Parameters
----------
cols : str | list of str
columns to groupby
func : function
function to call on the grouped data
*args : tuple
positional parameters to pass to func
**kwargs : dict
keyword par... | [
"Groupby",
"cols",
"and",
"call",
"the",
"function",
"fn",
"on",
"each",
"grouped",
"dataframe",
"."
] | 566e579af705367e584fb27a74e6c5199624ca89 | https://github.com/has2k1/plotnine/blob/566e579af705367e584fb27a74e6c5199624ca89/plotnine/utils.py#L604-L633 | train |
has2k1/plotnine | plotnine/utils.py | pivot_apply | def pivot_apply(df, column, index, func, *args, **kwargs):
"""
Apply a function to each group of a column
The function is kind of equivalent to R's *tapply*.
Parameters
----------
df : dataframe
Dataframe to be pivoted
column : str
Column to apply function to.
index : s... | python | def pivot_apply(df, column, index, func, *args, **kwargs):
"""
Apply a function to each group of a column
The function is kind of equivalent to R's *tapply*.
Parameters
----------
df : dataframe
Dataframe to be pivoted
column : str
Column to apply function to.
index : s... | [
"def",
"pivot_apply",
"(",
"df",
",",
"column",
",",
"index",
",",
"func",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"def",
"_func",
"(",
"x",
")",
":",
"return",
"func",
"(",
"x",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
"r... | Apply a function to each group of a column
The function is kind of equivalent to R's *tapply*.
Parameters
----------
df : dataframe
Dataframe to be pivoted
column : str
Column to apply function to.
index : str
Column that will be grouped on (and whose unique values
... | [
"Apply",
"a",
"function",
"to",
"each",
"group",
"of",
"a",
"column"
] | 566e579af705367e584fb27a74e6c5199624ca89 | https://github.com/has2k1/plotnine/blob/566e579af705367e584fb27a74e6c5199624ca89/plotnine/utils.py#L636-L668 | train |
has2k1/plotnine | plotnine/utils.py | copy_keys | def copy_keys(source, destination, keys=None):
"""
Add keys in source to destination
Parameters
----------
source : dict
destination: dict
keys : None | iterable
The keys in source to be copied into destination. If
None, then `keys = destination.keys()`
"""
if keys... | python | def copy_keys(source, destination, keys=None):
"""
Add keys in source to destination
Parameters
----------
source : dict
destination: dict
keys : None | iterable
The keys in source to be copied into destination. If
None, then `keys = destination.keys()`
"""
if keys... | [
"def",
"copy_keys",
"(",
"source",
",",
"destination",
",",
"keys",
"=",
"None",
")",
":",
"if",
"keys",
"is",
"None",
":",
"keys",
"=",
"destination",
".",
"keys",
"(",
")",
"for",
"k",
"in",
"set",
"(",
"source",
")",
"&",
"set",
"(",
"keys",
"... | Add keys in source to destination
Parameters
----------
source : dict
destination: dict
keys : None | iterable
The keys in source to be copied into destination. If
None, then `keys = destination.keys()` | [
"Add",
"keys",
"in",
"source",
"to",
"destination"
] | 566e579af705367e584fb27a74e6c5199624ca89 | https://github.com/has2k1/plotnine/blob/566e579af705367e584fb27a74e6c5199624ca89/plotnine/utils.py#L766-L784 | train |
has2k1/plotnine | plotnine/utils.py | alias | def alias(name, class_object):
"""
Create an alias of a class object
The objective of this method is to have
an alias that is Registered. i.e If we have
class_b = class_a
Makes `class_b` an alias of `class_a`, but if
`class_a` is registered by its metaclass,
`class_b` is not. The ... | python | def alias(name, class_object):
"""
Create an alias of a class object
The objective of this method is to have
an alias that is Registered. i.e If we have
class_b = class_a
Makes `class_b` an alias of `class_a`, but if
`class_a` is registered by its metaclass,
`class_b` is not. The ... | [
"def",
"alias",
"(",
"name",
",",
"class_object",
")",
":",
"module",
"=",
"inspect",
".",
"getmodule",
"(",
"class_object",
")",
"module",
".",
"__dict__",
"[",
"name",
"]",
"=",
"class_object",
"if",
"isinstance",
"(",
"class_object",
",",
"Registry",
")... | Create an alias of a class object
The objective of this method is to have
an alias that is Registered. i.e If we have
class_b = class_a
Makes `class_b` an alias of `class_a`, but if
`class_a` is registered by its metaclass,
`class_b` is not. The solution
alias('class_b', class_a)... | [
"Create",
"an",
"alias",
"of",
"a",
"class",
"object"
] | 566e579af705367e584fb27a74e6c5199624ca89 | https://github.com/has2k1/plotnine/blob/566e579af705367e584fb27a74e6c5199624ca89/plotnine/utils.py#L881-L904 | train |
has2k1/plotnine | plotnine/utils.py | get_kwarg_names | def get_kwarg_names(func):
"""
Return a list of valid kwargs to function func
"""
sig = inspect.signature(func)
kwonlyargs = [p.name for p in sig.parameters.values()
if p.default is not p.empty]
return kwonlyargs | python | def get_kwarg_names(func):
"""
Return a list of valid kwargs to function func
"""
sig = inspect.signature(func)
kwonlyargs = [p.name for p in sig.parameters.values()
if p.default is not p.empty]
return kwonlyargs | [
"def",
"get_kwarg_names",
"(",
"func",
")",
":",
"sig",
"=",
"inspect",
".",
"signature",
"(",
"func",
")",
"kwonlyargs",
"=",
"[",
"p",
".",
"name",
"for",
"p",
"in",
"sig",
".",
"parameters",
".",
"values",
"(",
")",
"if",
"p",
".",
"default",
"i... | Return a list of valid kwargs to function func | [
"Return",
"a",
"list",
"of",
"valid",
"kwargs",
"to",
"function",
"func"
] | 566e579af705367e584fb27a74e6c5199624ca89 | https://github.com/has2k1/plotnine/blob/566e579af705367e584fb27a74e6c5199624ca89/plotnine/utils.py#L907-L914 | train |
has2k1/plotnine | plotnine/utils.py | get_valid_kwargs | def get_valid_kwargs(func, potential_kwargs):
"""
Return valid kwargs to function func
"""
kwargs = {}
for name in get_kwarg_names(func):
with suppress(KeyError):
kwargs[name] = potential_kwargs[name]
return kwargs | python | def get_valid_kwargs(func, potential_kwargs):
"""
Return valid kwargs to function func
"""
kwargs = {}
for name in get_kwarg_names(func):
with suppress(KeyError):
kwargs[name] = potential_kwargs[name]
return kwargs | [
"def",
"get_valid_kwargs",
"(",
"func",
",",
"potential_kwargs",
")",
":",
"kwargs",
"=",
"{",
"}",
"for",
"name",
"in",
"get_kwarg_names",
"(",
"func",
")",
":",
"with",
"suppress",
"(",
"KeyError",
")",
":",
"kwargs",
"[",
"name",
"]",
"=",
"potential_... | Return valid kwargs to function func | [
"Return",
"valid",
"kwargs",
"to",
"function",
"func"
] | 566e579af705367e584fb27a74e6c5199624ca89 | https://github.com/has2k1/plotnine/blob/566e579af705367e584fb27a74e6c5199624ca89/plotnine/utils.py#L917-L925 | train |
has2k1/plotnine | plotnine/utils.py | copy_missing_columns | def copy_missing_columns(df, ref_df):
"""
Copy missing columns from ref_df to df
If df and ref_df are the same length, the columns are
copied in the entirety. If the length ofref_df is a
divisor of the length of df, then the values of the
columns from ref_df are repeated.
Otherwise if not ... | python | def copy_missing_columns(df, ref_df):
"""
Copy missing columns from ref_df to df
If df and ref_df are the same length, the columns are
copied in the entirety. If the length ofref_df is a
divisor of the length of df, then the values of the
columns from ref_df are repeated.
Otherwise if not ... | [
"def",
"copy_missing_columns",
"(",
"df",
",",
"ref_df",
")",
":",
"cols",
"=",
"ref_df",
".",
"columns",
".",
"difference",
"(",
"df",
".",
"columns",
")",
"_loc",
"=",
"ref_df",
".",
"columns",
".",
"get_loc",
"l1",
",",
"l2",
"=",
"len",
"(",
"df"... | Copy missing columns from ref_df to df
If df and ref_df are the same length, the columns are
copied in the entirety. If the length ofref_df is a
divisor of the length of df, then the values of the
columns from ref_df are repeated.
Otherwise if not the same length, df gets a column
where all el... | [
"Copy",
"missing",
"columns",
"from",
"ref_df",
"to",
"df"
] | 566e579af705367e584fb27a74e6c5199624ca89 | https://github.com/has2k1/plotnine/blob/566e579af705367e584fb27a74e6c5199624ca89/plotnine/utils.py#L928-L958 | train |
has2k1/plotnine | plotnine/utils.py | data_mapping_as_kwargs | def data_mapping_as_kwargs(args, kwargs):
"""
Return kwargs with the mapping and data values
Parameters
----------
args : tuple
Arguments to :class:`geom` or :class:`stat`.
kwargs : dict
Keyword arguments to :class:`geom` or :class:`stat`.
Returns
-------
out : dict... | python | def data_mapping_as_kwargs(args, kwargs):
"""
Return kwargs with the mapping and data values
Parameters
----------
args : tuple
Arguments to :class:`geom` or :class:`stat`.
kwargs : dict
Keyword arguments to :class:`geom` or :class:`stat`.
Returns
-------
out : dict... | [
"def",
"data_mapping_as_kwargs",
"(",
"args",
",",
"kwargs",
")",
":",
"# No need to be strict about the aesthetic superclass",
"aes",
"=",
"dict",
"mapping",
",",
"data",
"=",
"aes",
"(",
")",
",",
"None",
"aes_err",
"=",
"(",
"\"Found more than one aes argument. \""... | Return kwargs with the mapping and data values
Parameters
----------
args : tuple
Arguments to :class:`geom` or :class:`stat`.
kwargs : dict
Keyword arguments to :class:`geom` or :class:`stat`.
Returns
-------
out : dict
kwargs that includes 'data' and 'mapping' key... | [
"Return",
"kwargs",
"with",
"the",
"mapping",
"and",
"data",
"values"
] | 566e579af705367e584fb27a74e6c5199624ca89 | https://github.com/has2k1/plotnine/blob/566e579af705367e584fb27a74e6c5199624ca89/plotnine/utils.py#L961-L1013 | train |
has2k1/plotnine | plotnine/utils.py | resolution | def resolution(x, zero=True):
"""
Compute the resolution of a data vector
Resolution is smallest non-zero distance between adjacent values
Parameters
----------
x : 1D array-like
zero : Boolean
Whether to include zero values in the computation
Result
------
res : re... | python | def resolution(x, zero=True):
"""
Compute the resolution of a data vector
Resolution is smallest non-zero distance between adjacent values
Parameters
----------
x : 1D array-like
zero : Boolean
Whether to include zero values in the computation
Result
------
res : re... | [
"def",
"resolution",
"(",
"x",
",",
"zero",
"=",
"True",
")",
":",
"x",
"=",
"np",
".",
"asarray",
"(",
"x",
")",
"# (unsigned) integers or an effective range of zero",
"_x",
"=",
"x",
"[",
"~",
"np",
".",
"isnan",
"(",
"x",
")",
"]",
"_x",
"=",
"(",... | Compute the resolution of a data vector
Resolution is smallest non-zero distance between adjacent values
Parameters
----------
x : 1D array-like
zero : Boolean
Whether to include zero values in the computation
Result
------
res : resolution of x
If x is an integer a... | [
"Compute",
"the",
"resolution",
"of",
"a",
"data",
"vector"
] | 566e579af705367e584fb27a74e6c5199624ca89 | https://github.com/has2k1/plotnine/blob/566e579af705367e584fb27a74e6c5199624ca89/plotnine/utils.py#L1035-L1064 | train |
has2k1/plotnine | plotnine/utils.py | cross_join | def cross_join(df1, df2):
"""
Return a dataframe that is a cross between dataframes
df1 and df2
ref: https://github.com/pydata/pandas/issues/5401
"""
if len(df1) == 0:
return df2
if len(df2) == 0:
return df1
# Add as lists so that the new index keeps the items in
#... | python | def cross_join(df1, df2):
"""
Return a dataframe that is a cross between dataframes
df1 and df2
ref: https://github.com/pydata/pandas/issues/5401
"""
if len(df1) == 0:
return df2
if len(df2) == 0:
return df1
# Add as lists so that the new index keeps the items in
#... | [
"def",
"cross_join",
"(",
"df1",
",",
"df2",
")",
":",
"if",
"len",
"(",
"df1",
")",
"==",
"0",
":",
"return",
"df2",
"if",
"len",
"(",
"df2",
")",
"==",
"0",
":",
"return",
"df1",
"# Add as lists so that the new index keeps the items in",
"# the order that ... | Return a dataframe that is a cross between dataframes
df1 and df2
ref: https://github.com/pydata/pandas/issues/5401 | [
"Return",
"a",
"dataframe",
"that",
"is",
"a",
"cross",
"between",
"dataframes",
"df1",
"and",
"df2"
] | 566e579af705367e584fb27a74e6c5199624ca89 | https://github.com/has2k1/plotnine/blob/566e579af705367e584fb27a74e6c5199624ca89/plotnine/utils.py#L1067-L1085 | train |
has2k1/plotnine | plotnine/utils.py | to_inches | def to_inches(value, units):
"""
Convert value to inches
Parameters
----------
value : float
Value to be converted
units : str
Units of value. Must be one of
`['in', 'cm', 'mm']`.
"""
lookup = {'in': lambda x: x,
'cm': lambda x: x/2.54,
... | python | def to_inches(value, units):
"""
Convert value to inches
Parameters
----------
value : float
Value to be converted
units : str
Units of value. Must be one of
`['in', 'cm', 'mm']`.
"""
lookup = {'in': lambda x: x,
'cm': lambda x: x/2.54,
... | [
"def",
"to_inches",
"(",
"value",
",",
"units",
")",
":",
"lookup",
"=",
"{",
"'in'",
":",
"lambda",
"x",
":",
"x",
",",
"'cm'",
":",
"lambda",
"x",
":",
"x",
"/",
"2.54",
",",
"'mm'",
":",
"lambda",
"x",
":",
"x",
"/",
"(",
"2.54",
"*",
"10"... | Convert value to inches
Parameters
----------
value : float
Value to be converted
units : str
Units of value. Must be one of
`['in', 'cm', 'mm']`. | [
"Convert",
"value",
"to",
"inches"
] | 566e579af705367e584fb27a74e6c5199624ca89 | https://github.com/has2k1/plotnine/blob/566e579af705367e584fb27a74e6c5199624ca89/plotnine/utils.py#L1088-L1106 | train |
has2k1/plotnine | plotnine/utils.py | from_inches | def from_inches(value, units):
"""
Convert value in inches to given units
Parameters
----------
value : float
Value to be converted
units : str
Units to convert value to. Must be one of
`['in', 'cm', 'mm']`.
"""
lookup = {'in': lambda x: x,
'cm': la... | python | def from_inches(value, units):
"""
Convert value in inches to given units
Parameters
----------
value : float
Value to be converted
units : str
Units to convert value to. Must be one of
`['in', 'cm', 'mm']`.
"""
lookup = {'in': lambda x: x,
'cm': la... | [
"def",
"from_inches",
"(",
"value",
",",
"units",
")",
":",
"lookup",
"=",
"{",
"'in'",
":",
"lambda",
"x",
":",
"x",
",",
"'cm'",
":",
"lambda",
"x",
":",
"x",
"*",
"2.54",
",",
"'mm'",
":",
"lambda",
"x",
":",
"x",
"*",
"2.54",
"*",
"10",
"... | Convert value in inches to given units
Parameters
----------
value : float
Value to be converted
units : str
Units to convert value to. Must be one of
`['in', 'cm', 'mm']`. | [
"Convert",
"value",
"in",
"inches",
"to",
"given",
"units"
] | 566e579af705367e584fb27a74e6c5199624ca89 | https://github.com/has2k1/plotnine/blob/566e579af705367e584fb27a74e6c5199624ca89/plotnine/utils.py#L1109-L1127 | train |
has2k1/plotnine | plotnine/utils.py | log | def log(x, base=None):
"""
Calculate the log
Parameters
----------
x : float or array_like
Input values
base : int or float (Default: None)
Base of the log. If `None`, the natural logarithm
is computed (`base=np.e`).
Returns
-------
out : float or ndarray
... | python | def log(x, base=None):
"""
Calculate the log
Parameters
----------
x : float or array_like
Input values
base : int or float (Default: None)
Base of the log. If `None`, the natural logarithm
is computed (`base=np.e`).
Returns
-------
out : float or ndarray
... | [
"def",
"log",
"(",
"x",
",",
"base",
"=",
"None",
")",
":",
"if",
"base",
"==",
"10",
":",
"return",
"np",
".",
"log10",
"(",
"x",
")",
"elif",
"base",
"==",
"2",
":",
"return",
"np",
".",
"log2",
"(",
"x",
")",
"elif",
"base",
"is",
"None",
... | Calculate the log
Parameters
----------
x : float or array_like
Input values
base : int or float (Default: None)
Base of the log. If `None`, the natural logarithm
is computed (`base=np.e`).
Returns
-------
out : float or ndarray
Calculated result | [
"Calculate",
"the",
"log"
] | 566e579af705367e584fb27a74e6c5199624ca89 | https://github.com/has2k1/plotnine/blob/566e579af705367e584fb27a74e6c5199624ca89/plotnine/utils.py#L1174-L1198 | train |
cloudtools/stacker | stacker/lookups/handlers/hook_data.py | HookDataLookup.handle | def handle(cls, value, context, **kwargs):
"""Returns the value of a key for a given hook in hook_data.
Format of value:
<hook_name>::<key>
"""
try:
hook_name, key = value.split("::")
except ValueError:
raise ValueError("Invalid value for hoo... | python | def handle(cls, value, context, **kwargs):
"""Returns the value of a key for a given hook in hook_data.
Format of value:
<hook_name>::<key>
"""
try:
hook_name, key = value.split("::")
except ValueError:
raise ValueError("Invalid value for hoo... | [
"def",
"handle",
"(",
"cls",
",",
"value",
",",
"context",
",",
"*",
"*",
"kwargs",
")",
":",
"try",
":",
"hook_name",
",",
"key",
"=",
"value",
".",
"split",
"(",
"\"::\"",
")",
"except",
"ValueError",
":",
"raise",
"ValueError",
"(",
"\"Invalid value... | Returns the value of a key for a given hook in hook_data.
Format of value:
<hook_name>::<key> | [
"Returns",
"the",
"value",
"of",
"a",
"key",
"for",
"a",
"given",
"hook",
"in",
"hook_data",
"."
] | ad6013a03a560c46ba3c63c4d153336273e6da5d | https://github.com/cloudtools/stacker/blob/ad6013a03a560c46ba3c63c4d153336273e6da5d/stacker/lookups/handlers/hook_data.py#L13-L26 | train |
cloudtools/stacker | stacker/variables.py | resolve_variables | def resolve_variables(variables, context, provider):
"""Given a list of variables, resolve all of them.
Args:
variables (list of :class:`stacker.variables.Variable`): list of
variables
context (:class:`stacker.context.Context`): stacker context
provider (:class:`stacker.prov... | python | def resolve_variables(variables, context, provider):
"""Given a list of variables, resolve all of them.
Args:
variables (list of :class:`stacker.variables.Variable`): list of
variables
context (:class:`stacker.context.Context`): stacker context
provider (:class:`stacker.prov... | [
"def",
"resolve_variables",
"(",
"variables",
",",
"context",
",",
"provider",
")",
":",
"for",
"variable",
"in",
"variables",
":",
"variable",
".",
"resolve",
"(",
"context",
",",
"provider",
")"
] | Given a list of variables, resolve all of them.
Args:
variables (list of :class:`stacker.variables.Variable`): list of
variables
context (:class:`stacker.context.Context`): stacker context
provider (:class:`stacker.provider.base.BaseProvider`): subclass of the
base p... | [
"Given",
"a",
"list",
"of",
"variables",
"resolve",
"all",
"of",
"them",
"."
] | ad6013a03a560c46ba3c63c4d153336273e6da5d | https://github.com/cloudtools/stacker/blob/ad6013a03a560c46ba3c63c4d153336273e6da5d/stacker/variables.py#L23-L35 | train |
cloudtools/stacker | stacker/variables.py | Variable.value | def value(self):
"""Return the current value of the Variable.
"""
try:
return self._value.value()
except UnresolvedVariableValue:
raise UnresolvedVariable("<unknown>", self)
except InvalidLookupConcatenation as e:
raise InvalidLookupCombination... | python | def value(self):
"""Return the current value of the Variable.
"""
try:
return self._value.value()
except UnresolvedVariableValue:
raise UnresolvedVariable("<unknown>", self)
except InvalidLookupConcatenation as e:
raise InvalidLookupCombination... | [
"def",
"value",
"(",
"self",
")",
":",
"try",
":",
"return",
"self",
".",
"_value",
".",
"value",
"(",
")",
"except",
"UnresolvedVariableValue",
":",
"raise",
"UnresolvedVariable",
"(",
"\"<unknown>\"",
",",
"self",
")",
"except",
"InvalidLookupConcatenation",
... | Return the current value of the Variable. | [
"Return",
"the",
"current",
"value",
"of",
"the",
"Variable",
"."
] | ad6013a03a560c46ba3c63c4d153336273e6da5d | https://github.com/cloudtools/stacker/blob/ad6013a03a560c46ba3c63c4d153336273e6da5d/stacker/variables.py#L53-L61 | train |
cloudtools/stacker | stacker/variables.py | Variable.resolve | def resolve(self, context, provider):
"""Recursively resolve any lookups with the Variable.
Args:
context (:class:`stacker.context.Context`): Current context for
building the stack
provider (:class:`stacker.provider.base.BaseProvider`): subclass of
... | python | def resolve(self, context, provider):
"""Recursively resolve any lookups with the Variable.
Args:
context (:class:`stacker.context.Context`): Current context for
building the stack
provider (:class:`stacker.provider.base.BaseProvider`): subclass of
... | [
"def",
"resolve",
"(",
"self",
",",
"context",
",",
"provider",
")",
":",
"try",
":",
"self",
".",
"_value",
".",
"resolve",
"(",
"context",
",",
"provider",
")",
"except",
"FailedLookup",
"as",
"e",
":",
"raise",
"FailedVariableLookup",
"(",
"self",
"."... | Recursively resolve any lookups with the Variable.
Args:
context (:class:`stacker.context.Context`): Current context for
building the stack
provider (:class:`stacker.provider.base.BaseProvider`): subclass of
the base provider | [
"Recursively",
"resolve",
"any",
"lookups",
"with",
"the",
"Variable",
"."
] | ad6013a03a560c46ba3c63c4d153336273e6da5d | https://github.com/cloudtools/stacker/blob/ad6013a03a560c46ba3c63c4d153336273e6da5d/stacker/variables.py#L71-L84 | train |
cloudtools/stacker | stacker/plan.py | Step.run | def run(self):
"""Runs this step until it has completed successfully, or been
skipped.
"""
stop_watcher = threading.Event()
watcher = None
if self.watch_func:
watcher = threading.Thread(
target=self.watch_func,
args=(self.stack... | python | def run(self):
"""Runs this step until it has completed successfully, or been
skipped.
"""
stop_watcher = threading.Event()
watcher = None
if self.watch_func:
watcher = threading.Thread(
target=self.watch_func,
args=(self.stack... | [
"def",
"run",
"(",
"self",
")",
":",
"stop_watcher",
"=",
"threading",
".",
"Event",
"(",
")",
"watcher",
"=",
"None",
"if",
"self",
".",
"watch_func",
":",
"watcher",
"=",
"threading",
".",
"Thread",
"(",
"target",
"=",
"self",
".",
"watch_func",
",",... | Runs this step until it has completed successfully, or been
skipped. | [
"Runs",
"this",
"step",
"until",
"it",
"has",
"completed",
"successfully",
"or",
"been",
"skipped",
"."
] | ad6013a03a560c46ba3c63c4d153336273e6da5d | https://github.com/cloudtools/stacker/blob/ad6013a03a560c46ba3c63c4d153336273e6da5d/stacker/plan.py#L68-L89 | train |
cloudtools/stacker | stacker/plan.py | Graph.downstream | def downstream(self, step_name):
"""Returns the direct dependencies of the given step"""
return list(self.steps[dep] for dep in self.dag.downstream(step_name)) | python | def downstream(self, step_name):
"""Returns the direct dependencies of the given step"""
return list(self.steps[dep] for dep in self.dag.downstream(step_name)) | [
"def",
"downstream",
"(",
"self",
",",
"step_name",
")",
":",
"return",
"list",
"(",
"self",
".",
"steps",
"[",
"dep",
"]",
"for",
"dep",
"in",
"self",
".",
"dag",
".",
"downstream",
"(",
"step_name",
")",
")"
] | Returns the direct dependencies of the given step | [
"Returns",
"the",
"direct",
"dependencies",
"of",
"the",
"given",
"step"
] | ad6013a03a560c46ba3c63c4d153336273e6da5d | https://github.com/cloudtools/stacker/blob/ad6013a03a560c46ba3c63c4d153336273e6da5d/stacker/plan.py#L272-L274 | train |
cloudtools/stacker | stacker/plan.py | Graph.transposed | def transposed(self):
"""Returns a "transposed" version of this graph. Useful for walking in
reverse.
"""
return Graph(steps=self.steps, dag=self.dag.transpose()) | python | def transposed(self):
"""Returns a "transposed" version of this graph. Useful for walking in
reverse.
"""
return Graph(steps=self.steps, dag=self.dag.transpose()) | [
"def",
"transposed",
"(",
"self",
")",
":",
"return",
"Graph",
"(",
"steps",
"=",
"self",
".",
"steps",
",",
"dag",
"=",
"self",
".",
"dag",
".",
"transpose",
"(",
")",
")"
] | Returns a "transposed" version of this graph. Useful for walking in
reverse. | [
"Returns",
"a",
"transposed",
"version",
"of",
"this",
"graph",
".",
"Useful",
"for",
"walking",
"in",
"reverse",
"."
] | ad6013a03a560c46ba3c63c4d153336273e6da5d | https://github.com/cloudtools/stacker/blob/ad6013a03a560c46ba3c63c4d153336273e6da5d/stacker/plan.py#L276-L280 | train |
cloudtools/stacker | stacker/plan.py | Graph.filtered | def filtered(self, step_names):
"""Returns a "filtered" version of this graph."""
return Graph(steps=self.steps, dag=self.dag.filter(step_names)) | python | def filtered(self, step_names):
"""Returns a "filtered" version of this graph."""
return Graph(steps=self.steps, dag=self.dag.filter(step_names)) | [
"def",
"filtered",
"(",
"self",
",",
"step_names",
")",
":",
"return",
"Graph",
"(",
"steps",
"=",
"self",
".",
"steps",
",",
"dag",
"=",
"self",
".",
"dag",
".",
"filter",
"(",
"step_names",
")",
")"
] | Returns a "filtered" version of this graph. | [
"Returns",
"a",
"filtered",
"version",
"of",
"this",
"graph",
"."
] | ad6013a03a560c46ba3c63c4d153336273e6da5d | https://github.com/cloudtools/stacker/blob/ad6013a03a560c46ba3c63c4d153336273e6da5d/stacker/plan.py#L282-L284 | train |
cloudtools/stacker | stacker/plan.py | Plan.execute | def execute(self, *args, **kwargs):
"""Walks each step in the underlying graph, and raises an exception if
any of the steps fail.
Raises:
PlanFailed: Raised if any of the steps fail.
"""
self.walk(*args, **kwargs)
failed_steps = [step for step in self.steps ... | python | def execute(self, *args, **kwargs):
"""Walks each step in the underlying graph, and raises an exception if
any of the steps fail.
Raises:
PlanFailed: Raised if any of the steps fail.
"""
self.walk(*args, **kwargs)
failed_steps = [step for step in self.steps ... | [
"def",
"execute",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"walk",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
"failed_steps",
"=",
"[",
"step",
"for",
"step",
"in",
"self",
".",
"steps",
"if",
"step",
... | Walks each step in the underlying graph, and raises an exception if
any of the steps fail.
Raises:
PlanFailed: Raised if any of the steps fail. | [
"Walks",
"each",
"step",
"in",
"the",
"underlying",
"graph",
"and",
"raises",
"an",
"exception",
"if",
"any",
"of",
"the",
"steps",
"fail",
"."
] | ad6013a03a560c46ba3c63c4d153336273e6da5d | https://github.com/cloudtools/stacker/blob/ad6013a03a560c46ba3c63c4d153336273e6da5d/stacker/plan.py#L358-L369 | train |
cloudtools/stacker | stacker/plan.py | Plan.walk | def walk(self, walker):
"""Walks each step in the underlying graph, in topological order.
Args:
walker (func): a walker function to be passed to
:class:`stacker.dag.DAG` to walk the graph.
"""
def walk_func(step):
# Before we execute the step, we... | python | def walk(self, walker):
"""Walks each step in the underlying graph, in topological order.
Args:
walker (func): a walker function to be passed to
:class:`stacker.dag.DAG` to walk the graph.
"""
def walk_func(step):
# Before we execute the step, we... | [
"def",
"walk",
"(",
"self",
",",
"walker",
")",
":",
"def",
"walk_func",
"(",
"step",
")",
":",
"# Before we execute the step, we need to ensure that it's",
"# transitive dependencies are all in an \"ok\" state. If not, we",
"# won't execute this step.",
"for",
"dep",
"in",
"... | Walks each step in the underlying graph, in topological order.
Args:
walker (func): a walker function to be passed to
:class:`stacker.dag.DAG` to walk the graph. | [
"Walks",
"each",
"step",
"in",
"the",
"underlying",
"graph",
"in",
"topological",
"order",
"."
] | ad6013a03a560c46ba3c63c4d153336273e6da5d | https://github.com/cloudtools/stacker/blob/ad6013a03a560c46ba3c63c4d153336273e6da5d/stacker/plan.py#L371-L390 | train |
cloudtools/stacker | stacker/blueprints/variables/types.py | TroposphereType.create | def create(self, value):
"""Create the troposphere type from the value.
Args:
value (Union[dict, list]): A dictionary or list of dictionaries
(see class documentation for details) to use as parameters to
create the Troposphere type instance.
E... | python | def create(self, value):
"""Create the troposphere type from the value.
Args:
value (Union[dict, list]): A dictionary or list of dictionaries
(see class documentation for details) to use as parameters to
create the Troposphere type instance.
E... | [
"def",
"create",
"(",
"self",
",",
"value",
")",
":",
"# Explicitly check with len such that non-sequence types throw.",
"if",
"self",
".",
"_optional",
"and",
"(",
"value",
"is",
"None",
"or",
"len",
"(",
"value",
")",
"==",
"0",
")",
":",
"return",
"None",
... | Create the troposphere type from the value.
Args:
value (Union[dict, list]): A dictionary or list of dictionaries
(see class documentation for details) to use as parameters to
create the Troposphere type instance.
Each dictionary will be passed to the... | [
"Create",
"the",
"troposphere",
"type",
"from",
"the",
"value",
"."
] | ad6013a03a560c46ba3c63c4d153336273e6da5d | https://github.com/cloudtools/stacker/blob/ad6013a03a560c46ba3c63c4d153336273e6da5d/stacker/blueprints/variables/types.py#L61-L110 | train |
cloudtools/stacker | stacker/lookups/handlers/dynamodb.py | _lookup_key_parse | def _lookup_key_parse(table_keys):
"""Return the order in which the stacks should be executed.
Args:
dependencies (dict): a dictionary where each key should be the
fully qualified name of a stack whose value is an array of
fully qualified stack names that the stack depends on. T... | python | def _lookup_key_parse(table_keys):
"""Return the order in which the stacks should be executed.
Args:
dependencies (dict): a dictionary where each key should be the
fully qualified name of a stack whose value is an array of
fully qualified stack names that the stack depends on. T... | [
"def",
"_lookup_key_parse",
"(",
"table_keys",
")",
":",
"# we need to parse the key lookup passed in",
"regex_matcher",
"=",
"'\\[([^\\]]+)]'",
"valid_dynamodb_datatypes",
"=",
"[",
"'M'",
",",
"'S'",
",",
"'N'",
",",
"'L'",
"]",
"clean_table_keys",
"=",
"[",
"]",
... | Return the order in which the stacks should be executed.
Args:
dependencies (dict): a dictionary where each key should be the
fully qualified name of a stack whose value is an array of
fully qualified stack names that the stack depends on. This is
used to generate the or... | [
"Return",
"the",
"order",
"in",
"which",
"the",
"stacks",
"should",
"be",
"executed",
"."
] | ad6013a03a560c46ba3c63c4d153336273e6da5d | https://github.com/cloudtools/stacker/blob/ad6013a03a560c46ba3c63c4d153336273e6da5d/stacker/lookups/handlers/dynamodb.py#L85-L126 | train |
cloudtools/stacker | stacker/lookups/handlers/dynamodb.py | _build_projection_expression | def _build_projection_expression(clean_table_keys):
"""Given cleaned up keys, this will return a projection expression for
the dynamodb lookup.
Args:
clean_table_keys (dict): keys without the data types attached
Returns:
str: A projection expression for the dynamodb lookup.
"""
... | python | def _build_projection_expression(clean_table_keys):
"""Given cleaned up keys, this will return a projection expression for
the dynamodb lookup.
Args:
clean_table_keys (dict): keys without the data types attached
Returns:
str: A projection expression for the dynamodb lookup.
"""
... | [
"def",
"_build_projection_expression",
"(",
"clean_table_keys",
")",
":",
"projection_expression",
"=",
"''",
"for",
"key",
"in",
"clean_table_keys",
"[",
":",
"-",
"1",
"]",
":",
"projection_expression",
"+=",
"(",
"'{},'",
")",
".",
"format",
"(",
"key",
")"... | Given cleaned up keys, this will return a projection expression for
the dynamodb lookup.
Args:
clean_table_keys (dict): keys without the data types attached
Returns:
str: A projection expression for the dynamodb lookup. | [
"Given",
"cleaned",
"up",
"keys",
"this",
"will",
"return",
"a",
"projection",
"expression",
"for",
"the",
"dynamodb",
"lookup",
"."
] | ad6013a03a560c46ba3c63c4d153336273e6da5d | https://github.com/cloudtools/stacker/blob/ad6013a03a560c46ba3c63c4d153336273e6da5d/stacker/lookups/handlers/dynamodb.py#L129-L143 | train |
cloudtools/stacker | stacker/lookups/handlers/dynamodb.py | _convert_ddb_list_to_list | def _convert_ddb_list_to_list(conversion_list):
"""Given a dynamodb list, it will return a python list without the dynamodb
datatypes
Args:
conversion_list (dict): a dynamodb list which includes the
datatypes
Returns:
list: Returns a sanitized list without the dynamodb ... | python | def _convert_ddb_list_to_list(conversion_list):
"""Given a dynamodb list, it will return a python list without the dynamodb
datatypes
Args:
conversion_list (dict): a dynamodb list which includes the
datatypes
Returns:
list: Returns a sanitized list without the dynamodb ... | [
"def",
"_convert_ddb_list_to_list",
"(",
"conversion_list",
")",
":",
"ret_list",
"=",
"[",
"]",
"for",
"v",
"in",
"conversion_list",
":",
"for",
"v1",
"in",
"v",
":",
"ret_list",
".",
"append",
"(",
"v",
"[",
"v1",
"]",
")",
"return",
"ret_list"
] | Given a dynamodb list, it will return a python list without the dynamodb
datatypes
Args:
conversion_list (dict): a dynamodb list which includes the
datatypes
Returns:
list: Returns a sanitized list without the dynamodb datatypes | [
"Given",
"a",
"dynamodb",
"list",
"it",
"will",
"return",
"a",
"python",
"list",
"without",
"the",
"dynamodb",
"datatypes"
] | ad6013a03a560c46ba3c63c4d153336273e6da5d | https://github.com/cloudtools/stacker/blob/ad6013a03a560c46ba3c63c4d153336273e6da5d/stacker/lookups/handlers/dynamodb.py#L180-L195 | train |
cloudtools/stacker | stacker/lookups/handlers/dynamodb.py | DynamodbLookup.handle | def handle(cls, value, **kwargs):
"""Get a value from a dynamodb table
dynamodb field types should be in the following format:
[<region>:]<tablename>@<primarypartionkey>:<keyvalue>.<keyvalue>...
Note: The region is optional, and defaults to the environment's
`AWS_DEFAULT_R... | python | def handle(cls, value, **kwargs):
"""Get a value from a dynamodb table
dynamodb field types should be in the following format:
[<region>:]<tablename>@<primarypartionkey>:<keyvalue>.<keyvalue>...
Note: The region is optional, and defaults to the environment's
`AWS_DEFAULT_R... | [
"def",
"handle",
"(",
"cls",
",",
"value",
",",
"*",
"*",
"kwargs",
")",
":",
"value",
"=",
"read_value_from_path",
"(",
"value",
")",
"table_info",
"=",
"None",
"table_keys",
"=",
"None",
"region",
"=",
"None",
"table_name",
"=",
"None",
"if",
"'@'",
... | Get a value from a dynamodb table
dynamodb field types should be in the following format:
[<region>:]<tablename>@<primarypartionkey>:<keyvalue>.<keyvalue>...
Note: The region is optional, and defaults to the environment's
`AWS_DEFAULT_REGION` if not specified. | [
"Get",
"a",
"value",
"from",
"a",
"dynamodb",
"table"
] | ad6013a03a560c46ba3c63c4d153336273e6da5d | https://github.com/cloudtools/stacker/blob/ad6013a03a560c46ba3c63c4d153336273e6da5d/stacker/lookups/handlers/dynamodb.py#L17-L82 | train |
cloudtools/stacker | stacker/actions/base.py | plan | def plan(description, stack_action, context,
tail=None, reverse=False):
"""A simple helper that builds a graph based plan from a set of stacks.
Args:
description (str): a description of the plan.
action (func): a function to call for each stack.
context (:class:`stacker.context... | python | def plan(description, stack_action, context,
tail=None, reverse=False):
"""A simple helper that builds a graph based plan from a set of stacks.
Args:
description (str): a description of the plan.
action (func): a function to call for each stack.
context (:class:`stacker.context... | [
"def",
"plan",
"(",
"description",
",",
"stack_action",
",",
"context",
",",
"tail",
"=",
"None",
",",
"reverse",
"=",
"False",
")",
":",
"def",
"target_fn",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"COMPLETE",
"steps",
"=",
"["... | A simple helper that builds a graph based plan from a set of stacks.
Args:
description (str): a description of the plan.
action (func): a function to call for each stack.
context (:class:`stacker.context.Context`): a
:class:`stacker.context.Context` to build the plan from.
... | [
"A",
"simple",
"helper",
"that",
"builds",
"a",
"graph",
"based",
"plan",
"from",
"a",
"set",
"of",
"stacks",
"."
] | ad6013a03a560c46ba3c63c4d153336273e6da5d | https://github.com/cloudtools/stacker/blob/ad6013a03a560c46ba3c63c4d153336273e6da5d/stacker/actions/base.py#L64-L97 | train |
cloudtools/stacker | stacker/actions/base.py | stack_template_key_name | def stack_template_key_name(blueprint):
"""Given a blueprint, produce an appropriate key name.
Args:
blueprint (:class:`stacker.blueprints.base.Blueprint`): The blueprint
object to create the key from.
Returns:
string: Key name resulting from blueprint.
"""
name = bluep... | python | def stack_template_key_name(blueprint):
"""Given a blueprint, produce an appropriate key name.
Args:
blueprint (:class:`stacker.blueprints.base.Blueprint`): The blueprint
object to create the key from.
Returns:
string: Key name resulting from blueprint.
"""
name = bluep... | [
"def",
"stack_template_key_name",
"(",
"blueprint",
")",
":",
"name",
"=",
"blueprint",
".",
"name",
"return",
"\"stack_templates/%s/%s-%s.json\"",
"%",
"(",
"blueprint",
".",
"context",
".",
"get_fqn",
"(",
"name",
")",
",",
"name",
",",
"blueprint",
".",
"ve... | Given a blueprint, produce an appropriate key name.
Args:
blueprint (:class:`stacker.blueprints.base.Blueprint`): The blueprint
object to create the key from.
Returns:
string: Key name resulting from blueprint. | [
"Given",
"a",
"blueprint",
"produce",
"an",
"appropriate",
"key",
"name",
"."
] | ad6013a03a560c46ba3c63c4d153336273e6da5d | https://github.com/cloudtools/stacker/blob/ad6013a03a560c46ba3c63c4d153336273e6da5d/stacker/actions/base.py#L100-L113 | train |
cloudtools/stacker | stacker/actions/base.py | stack_template_url | def stack_template_url(bucket_name, blueprint, endpoint):
"""Produces an s3 url for a given blueprint.
Args:
bucket_name (string): The name of the S3 bucket where the resulting
templates are stored.
blueprint (:class:`stacker.blueprints.base.Blueprint`): The blueprint
ob... | python | def stack_template_url(bucket_name, blueprint, endpoint):
"""Produces an s3 url for a given blueprint.
Args:
bucket_name (string): The name of the S3 bucket where the resulting
templates are stored.
blueprint (:class:`stacker.blueprints.base.Blueprint`): The blueprint
ob... | [
"def",
"stack_template_url",
"(",
"bucket_name",
",",
"blueprint",
",",
"endpoint",
")",
":",
"key_name",
"=",
"stack_template_key_name",
"(",
"blueprint",
")",
"return",
"\"%s/%s/%s\"",
"%",
"(",
"endpoint",
",",
"bucket_name",
",",
"key_name",
")"
] | Produces an s3 url for a given blueprint.
Args:
bucket_name (string): The name of the S3 bucket where the resulting
templates are stored.
blueprint (:class:`stacker.blueprints.base.Blueprint`): The blueprint
object to create the URL to.
endpoint (string): The s3 endp... | [
"Produces",
"an",
"s3",
"url",
"for",
"a",
"given",
"blueprint",
"."
] | ad6013a03a560c46ba3c63c4d153336273e6da5d | https://github.com/cloudtools/stacker/blob/ad6013a03a560c46ba3c63c4d153336273e6da5d/stacker/actions/base.py#L116-L130 | train |
cloudtools/stacker | stacker/actions/base.py | BaseAction.ensure_cfn_bucket | def ensure_cfn_bucket(self):
"""The CloudFormation bucket where templates will be stored."""
if self.bucket_name:
ensure_s3_bucket(self.s3_conn,
self.bucket_name,
self.bucket_region) | python | def ensure_cfn_bucket(self):
"""The CloudFormation bucket where templates will be stored."""
if self.bucket_name:
ensure_s3_bucket(self.s3_conn,
self.bucket_name,
self.bucket_region) | [
"def",
"ensure_cfn_bucket",
"(",
"self",
")",
":",
"if",
"self",
".",
"bucket_name",
":",
"ensure_s3_bucket",
"(",
"self",
".",
"s3_conn",
",",
"self",
".",
"bucket_name",
",",
"self",
".",
"bucket_region",
")"
] | The CloudFormation bucket where templates will be stored. | [
"The",
"CloudFormation",
"bucket",
"where",
"templates",
"will",
"be",
"stored",
"."
] | ad6013a03a560c46ba3c63c4d153336273e6da5d | https://github.com/cloudtools/stacker/blob/ad6013a03a560c46ba3c63c4d153336273e6da5d/stacker/actions/base.py#L159-L164 | train |
cloudtools/stacker | stacker/actions/base.py | BaseAction.s3_stack_push | def s3_stack_push(self, blueprint, force=False):
"""Pushes the rendered blueprint's template to S3.
Verifies that the template doesn't already exist in S3 before
pushing.
Returns the URL to the template in S3.
"""
key_name = stack_template_key_name(blueprint)
te... | python | def s3_stack_push(self, blueprint, force=False):
"""Pushes the rendered blueprint's template to S3.
Verifies that the template doesn't already exist in S3 before
pushing.
Returns the URL to the template in S3.
"""
key_name = stack_template_key_name(blueprint)
te... | [
"def",
"s3_stack_push",
"(",
"self",
",",
"blueprint",
",",
"force",
"=",
"False",
")",
":",
"key_name",
"=",
"stack_template_key_name",
"(",
"blueprint",
")",
"template_url",
"=",
"self",
".",
"stack_template_url",
"(",
"blueprint",
")",
"try",
":",
"template... | Pushes the rendered blueprint's template to S3.
Verifies that the template doesn't already exist in S3 before
pushing.
Returns the URL to the template in S3. | [
"Pushes",
"the",
"rendered",
"blueprint",
"s",
"template",
"to",
"S3",
"."
] | ad6013a03a560c46ba3c63c4d153336273e6da5d | https://github.com/cloudtools/stacker/blob/ad6013a03a560c46ba3c63c4d153336273e6da5d/stacker/actions/base.py#L171-L201 | train |
cloudtools/stacker | stacker/hooks/aws_lambda.py | _zip_files | def _zip_files(files, root):
"""Generates a ZIP file in-memory from a list of files.
Files will be stored in the archive with relative names, and have their
UNIX permissions forced to 755 or 644 (depending on whether they are
user-executable in the source filesystem).
Args:
files (list[str... | python | def _zip_files(files, root):
"""Generates a ZIP file in-memory from a list of files.
Files will be stored in the archive with relative names, and have their
UNIX permissions forced to 755 or 644 (depending on whether they are
user-executable in the source filesystem).
Args:
files (list[str... | [
"def",
"_zip_files",
"(",
"files",
",",
"root",
")",
":",
"zip_data",
"=",
"StringIO",
"(",
")",
"with",
"ZipFile",
"(",
"zip_data",
",",
"'w'",
",",
"ZIP_DEFLATED",
")",
"as",
"zip_file",
":",
"for",
"fname",
"in",
"files",
":",
"zip_file",
".",
"writ... | Generates a ZIP file in-memory from a list of files.
Files will be stored in the archive with relative names, and have their
UNIX permissions forced to 755 or 644 (depending on whether they are
user-executable in the source filesystem).
Args:
files (list[str]): file names to add to the archive... | [
"Generates",
"a",
"ZIP",
"file",
"in",
"-",
"memory",
"from",
"a",
"list",
"of",
"files",
"."
] | ad6013a03a560c46ba3c63c4d153336273e6da5d | https://github.com/cloudtools/stacker/blob/ad6013a03a560c46ba3c63c4d153336273e6da5d/stacker/hooks/aws_lambda.py#L33-L75 | train |
cloudtools/stacker | stacker/hooks/aws_lambda.py | _calculate_hash | def _calculate_hash(files, root):
""" Returns a hash of all of the given files at the given root.
Args:
files (list[str]): file names to include in the hash calculation,
relative to ``root``.
root (str): base directory to analyze files in.
Returns:
str: A hash of the ha... | python | def _calculate_hash(files, root):
""" Returns a hash of all of the given files at the given root.
Args:
files (list[str]): file names to include in the hash calculation,
relative to ``root``.
root (str): base directory to analyze files in.
Returns:
str: A hash of the ha... | [
"def",
"_calculate_hash",
"(",
"files",
",",
"root",
")",
":",
"file_hash",
"=",
"hashlib",
".",
"md5",
"(",
")",
"for",
"fname",
"in",
"sorted",
"(",
"files",
")",
":",
"f",
"=",
"os",
".",
"path",
".",
"join",
"(",
"root",
",",
"fname",
")",
"f... | Returns a hash of all of the given files at the given root.
Args:
files (list[str]): file names to include in the hash calculation,
relative to ``root``.
root (str): base directory to analyze files in.
Returns:
str: A hash of the hashes of the given files. | [
"Returns",
"a",
"hash",
"of",
"all",
"of",
"the",
"given",
"files",
"at",
"the",
"given",
"root",
"."
] | ad6013a03a560c46ba3c63c4d153336273e6da5d | https://github.com/cloudtools/stacker/blob/ad6013a03a560c46ba3c63c4d153336273e6da5d/stacker/hooks/aws_lambda.py#L78-L100 | train |
cloudtools/stacker | stacker/hooks/aws_lambda.py | _find_files | def _find_files(root, includes, excludes, follow_symlinks):
"""List files inside a directory based on include and exclude rules.
This is a more advanced version of `glob.glob`, that accepts multiple
complex patterns.
Args:
root (str): base directory to list files from.
includes (list[s... | python | def _find_files(root, includes, excludes, follow_symlinks):
"""List files inside a directory based on include and exclude rules.
This is a more advanced version of `glob.glob`, that accepts multiple
complex patterns.
Args:
root (str): base directory to list files from.
includes (list[s... | [
"def",
"_find_files",
"(",
"root",
",",
"includes",
",",
"excludes",
",",
"follow_symlinks",
")",
":",
"root",
"=",
"os",
".",
"path",
".",
"abspath",
"(",
"root",
")",
"file_set",
"=",
"formic",
".",
"FileSet",
"(",
"directory",
"=",
"root",
",",
"inc... | List files inside a directory based on include and exclude rules.
This is a more advanced version of `glob.glob`, that accepts multiple
complex patterns.
Args:
root (str): base directory to list files from.
includes (list[str]): inclusion patterns. Only files matching those
pat... | [
"List",
"files",
"inside",
"a",
"directory",
"based",
"on",
"include",
"and",
"exclude",
"rules",
"."
] | ad6013a03a560c46ba3c63c4d153336273e6da5d | https://github.com/cloudtools/stacker/blob/ad6013a03a560c46ba3c63c4d153336273e6da5d/stacker/hooks/aws_lambda.py#L103-L134 | train |
cloudtools/stacker | stacker/hooks/aws_lambda.py | _zip_from_file_patterns | def _zip_from_file_patterns(root, includes, excludes, follow_symlinks):
"""Generates a ZIP file in-memory from file search patterns.
Args:
root (str): base directory to list files from.
includes (list[str]): inclusion patterns. Only files matching those
patterns will be included in... | python | def _zip_from_file_patterns(root, includes, excludes, follow_symlinks):
"""Generates a ZIP file in-memory from file search patterns.
Args:
root (str): base directory to list files from.
includes (list[str]): inclusion patterns. Only files matching those
patterns will be included in... | [
"def",
"_zip_from_file_patterns",
"(",
"root",
",",
"includes",
",",
"excludes",
",",
"follow_symlinks",
")",
":",
"logger",
".",
"info",
"(",
"'lambda: base directory: %s'",
",",
"root",
")",
"files",
"=",
"list",
"(",
"_find_files",
"(",
"root",
",",
"includ... | Generates a ZIP file in-memory from file search patterns.
Args:
root (str): base directory to list files from.
includes (list[str]): inclusion patterns. Only files matching those
patterns will be included in the result.
excludes (list[str]): exclusion patterns. Files matching t... | [
"Generates",
"a",
"ZIP",
"file",
"in",
"-",
"memory",
"from",
"file",
"search",
"patterns",
"."
] | ad6013a03a560c46ba3c63c4d153336273e6da5d | https://github.com/cloudtools/stacker/blob/ad6013a03a560c46ba3c63c4d153336273e6da5d/stacker/hooks/aws_lambda.py#L137-L169 | train |
cloudtools/stacker | stacker/hooks/aws_lambda.py | _head_object | def _head_object(s3_conn, bucket, key):
"""Retrieve information about an object in S3 if it exists.
Args:
s3_conn (botocore.client.S3): S3 connection to use for operations.
bucket (str): name of the bucket containing the key.
key (str): name of the key to lookup.
Returns:
d... | python | def _head_object(s3_conn, bucket, key):
"""Retrieve information about an object in S3 if it exists.
Args:
s3_conn (botocore.client.S3): S3 connection to use for operations.
bucket (str): name of the bucket containing the key.
key (str): name of the key to lookup.
Returns:
d... | [
"def",
"_head_object",
"(",
"s3_conn",
",",
"bucket",
",",
"key",
")",
":",
"try",
":",
"return",
"s3_conn",
".",
"head_object",
"(",
"Bucket",
"=",
"bucket",
",",
"Key",
"=",
"key",
")",
"except",
"botocore",
".",
"exceptions",
".",
"ClientError",
"as",... | Retrieve information about an object in S3 if it exists.
Args:
s3_conn (botocore.client.S3): S3 connection to use for operations.
bucket (str): name of the bucket containing the key.
key (str): name of the key to lookup.
Returns:
dict: S3 object information, or None if the obje... | [
"Retrieve",
"information",
"about",
"an",
"object",
"in",
"S3",
"if",
"it",
"exists",
"."
] | ad6013a03a560c46ba3c63c4d153336273e6da5d | https://github.com/cloudtools/stacker/blob/ad6013a03a560c46ba3c63c4d153336273e6da5d/stacker/hooks/aws_lambda.py#L172-L194 | train |
cloudtools/stacker | stacker/hooks/aws_lambda.py | _upload_code | def _upload_code(s3_conn, bucket, prefix, name, contents, content_hash,
payload_acl):
"""Upload a ZIP file to S3 for use by Lambda.
The key used for the upload will be unique based on the checksum of the
contents. No changes will be made if the contents in S3 already match the
expected... | python | def _upload_code(s3_conn, bucket, prefix, name, contents, content_hash,
payload_acl):
"""Upload a ZIP file to S3 for use by Lambda.
The key used for the upload will be unique based on the checksum of the
contents. No changes will be made if the contents in S3 already match the
expected... | [
"def",
"_upload_code",
"(",
"s3_conn",
",",
"bucket",
",",
"prefix",
",",
"name",
",",
"contents",
",",
"content_hash",
",",
"payload_acl",
")",
":",
"logger",
".",
"debug",
"(",
"'lambda: ZIP hash: %s'",
",",
"content_hash",
")",
"key",
"=",
"'{}lambda-{}-{}.... | Upload a ZIP file to S3 for use by Lambda.
The key used for the upload will be unique based on the checksum of the
contents. No changes will be made if the contents in S3 already match the
expected contents.
Args:
s3_conn (botocore.client.S3): S3 connection to use for operations.
bucke... | [
"Upload",
"a",
"ZIP",
"file",
"to",
"S3",
"for",
"use",
"by",
"Lambda",
"."
] | ad6013a03a560c46ba3c63c4d153336273e6da5d | https://github.com/cloudtools/stacker/blob/ad6013a03a560c46ba3c63c4d153336273e6da5d/stacker/hooks/aws_lambda.py#L197-L237 | train |
cloudtools/stacker | stacker/hooks/aws_lambda.py | _check_pattern_list | def _check_pattern_list(patterns, key, default=None):
"""Validates file search patterns from user configuration.
Acceptable input is a string (which will be converted to a singleton list),
a list of strings, or anything falsy (such as None or an empty dictionary).
Empty or unset input will be converted... | python | def _check_pattern_list(patterns, key, default=None):
"""Validates file search patterns from user configuration.
Acceptable input is a string (which will be converted to a singleton list),
a list of strings, or anything falsy (such as None or an empty dictionary).
Empty or unset input will be converted... | [
"def",
"_check_pattern_list",
"(",
"patterns",
",",
"key",
",",
"default",
"=",
"None",
")",
":",
"if",
"not",
"patterns",
":",
"return",
"default",
"if",
"isinstance",
"(",
"patterns",
",",
"basestring",
")",
":",
"return",
"[",
"patterns",
"]",
"if",
"... | Validates file search patterns from user configuration.
Acceptable input is a string (which will be converted to a singleton list),
a list of strings, or anything falsy (such as None or an empty dictionary).
Empty or unset input will be converted to a default.
Args:
patterns: input from user c... | [
"Validates",
"file",
"search",
"patterns",
"from",
"user",
"configuration",
"."
] | ad6013a03a560c46ba3c63c4d153336273e6da5d | https://github.com/cloudtools/stacker/blob/ad6013a03a560c46ba3c63c4d153336273e6da5d/stacker/hooks/aws_lambda.py#L240-L272 | train |
cloudtools/stacker | stacker/hooks/aws_lambda.py | _upload_function | def _upload_function(s3_conn, bucket, prefix, name, options, follow_symlinks,
payload_acl):
"""Builds a Lambda payload from user configuration and uploads it to S3.
Args:
s3_conn (botocore.client.S3): S3 connection to use for operations.
bucket (str): name of the bucket to ... | python | def _upload_function(s3_conn, bucket, prefix, name, options, follow_symlinks,
payload_acl):
"""Builds a Lambda payload from user configuration and uploads it to S3.
Args:
s3_conn (botocore.client.S3): S3 connection to use for operations.
bucket (str): name of the bucket to ... | [
"def",
"_upload_function",
"(",
"s3_conn",
",",
"bucket",
",",
"prefix",
",",
"name",
",",
"options",
",",
"follow_symlinks",
",",
"payload_acl",
")",
":",
"try",
":",
"root",
"=",
"os",
".",
"path",
".",
"expanduser",
"(",
"options",
"[",
"'path'",
"]",... | Builds a Lambda payload from user configuration and uploads it to S3.
Args:
s3_conn (botocore.client.S3): S3 connection to use for operations.
bucket (str): name of the bucket to upload to.
prefix (str): S3 prefix to prepend to the constructed key name for
the uploaded file
... | [
"Builds",
"a",
"Lambda",
"payload",
"from",
"user",
"configuration",
"and",
"uploads",
"it",
"to",
"S3",
"."
] | ad6013a03a560c46ba3c63c4d153336273e6da5d | https://github.com/cloudtools/stacker/blob/ad6013a03a560c46ba3c63c4d153336273e6da5d/stacker/hooks/aws_lambda.py#L275-L335 | train |
cloudtools/stacker | stacker/hooks/aws_lambda.py | select_bucket_region | def select_bucket_region(custom_bucket, hook_region, stacker_bucket_region,
provider_region):
"""Returns the appropriate region to use when uploading functions.
Select the appropriate region for the bucket where lambdas are uploaded in.
Args:
custom_bucket (str, None): The... | python | def select_bucket_region(custom_bucket, hook_region, stacker_bucket_region,
provider_region):
"""Returns the appropriate region to use when uploading functions.
Select the appropriate region for the bucket where lambdas are uploaded in.
Args:
custom_bucket (str, None): The... | [
"def",
"select_bucket_region",
"(",
"custom_bucket",
",",
"hook_region",
",",
"stacker_bucket_region",
",",
"provider_region",
")",
":",
"region",
"=",
"None",
"if",
"custom_bucket",
":",
"region",
"=",
"hook_region",
"else",
":",
"region",
"=",
"stacker_bucket_regi... | Returns the appropriate region to use when uploading functions.
Select the appropriate region for the bucket where lambdas are uploaded in.
Args:
custom_bucket (str, None): The custom bucket name provided by the
`bucket` kwarg of the aws_lambda hook, if provided.
hook_region (str):... | [
"Returns",
"the",
"appropriate",
"region",
"to",
"use",
"when",
"uploading",
"functions",
"."
] | ad6013a03a560c46ba3c63c4d153336273e6da5d | https://github.com/cloudtools/stacker/blob/ad6013a03a560c46ba3c63c4d153336273e6da5d/stacker/hooks/aws_lambda.py#L338-L361 | train |
cloudtools/stacker | stacker/hooks/aws_lambda.py | upload_lambda_functions | def upload_lambda_functions(context, provider, **kwargs):
"""Builds Lambda payloads from user configuration and uploads them to S3.
Constructs ZIP archives containing files matching specified patterns for
each function, uploads the result to Amazon S3, then stores objects (of
type :class:`troposphere.a... | python | def upload_lambda_functions(context, provider, **kwargs):
"""Builds Lambda payloads from user configuration and uploads them to S3.
Constructs ZIP archives containing files matching specified patterns for
each function, uploads the result to Amazon S3, then stores objects (of
type :class:`troposphere.a... | [
"def",
"upload_lambda_functions",
"(",
"context",
",",
"provider",
",",
"*",
"*",
"kwargs",
")",
":",
"custom_bucket",
"=",
"kwargs",
".",
"get",
"(",
"'bucket'",
")",
"if",
"not",
"custom_bucket",
":",
"bucket_name",
"=",
"context",
".",
"bucket_name",
"log... | Builds Lambda payloads from user configuration and uploads them to S3.
Constructs ZIP archives containing files matching specified patterns for
each function, uploads the result to Amazon S3, then stores objects (of
type :class:`troposphere.awslambda.Code`) in the context's hook data,
ready to be refer... | [
"Builds",
"Lambda",
"payloads",
"from",
"user",
"configuration",
"and",
"uploads",
"them",
"to",
"S3",
"."
] | ad6013a03a560c46ba3c63c4d153336273e6da5d | https://github.com/cloudtools/stacker/blob/ad6013a03a560c46ba3c63c4d153336273e6da5d/stacker/hooks/aws_lambda.py#L364-L523 | train |
cloudtools/stacker | stacker/lookups/handlers/kms.py | KmsLookup.handle | def handle(cls, value, **kwargs):
"""Decrypt the specified value with a master key in KMS.
kmssimple field types should be in the following format:
[<region>@]<base64 encrypted value>
Note: The region is optional, and defaults to the environment's
`AWS_DEFAULT_REGION` if n... | python | def handle(cls, value, **kwargs):
"""Decrypt the specified value with a master key in KMS.
kmssimple field types should be in the following format:
[<region>@]<base64 encrypted value>
Note: The region is optional, and defaults to the environment's
`AWS_DEFAULT_REGION` if n... | [
"def",
"handle",
"(",
"cls",
",",
"value",
",",
"*",
"*",
"kwargs",
")",
":",
"value",
"=",
"read_value_from_path",
"(",
"value",
")",
"region",
"=",
"None",
"if",
"\"@\"",
"in",
"value",
":",
"region",
",",
"value",
"=",
"value",
".",
"split",
"(",
... | Decrypt the specified value with a master key in KMS.
kmssimple field types should be in the following format:
[<region>@]<base64 encrypted value>
Note: The region is optional, and defaults to the environment's
`AWS_DEFAULT_REGION` if not specified.
For example:
... | [
"Decrypt",
"the",
"specified",
"value",
"with",
"a",
"master",
"key",
"in",
"KMS",
"."
] | ad6013a03a560c46ba3c63c4d153336273e6da5d | https://github.com/cloudtools/stacker/blob/ad6013a03a560c46ba3c63c4d153336273e6da5d/stacker/lookups/handlers/kms.py#L15-L67 | train |
cloudtools/stacker | stacker/actions/diff.py | diff_dictionaries | def diff_dictionaries(old_dict, new_dict):
"""Diffs two single dimension dictionaries
Returns the number of changes and an unordered list
expressing the common entries and changes.
Args:
old_dict(dict): old dictionary
new_dict(dict): new dictionary
Returns: list()
int: num... | python | def diff_dictionaries(old_dict, new_dict):
"""Diffs two single dimension dictionaries
Returns the number of changes and an unordered list
expressing the common entries and changes.
Args:
old_dict(dict): old dictionary
new_dict(dict): new dictionary
Returns: list()
int: num... | [
"def",
"diff_dictionaries",
"(",
"old_dict",
",",
"new_dict",
")",
":",
"old_set",
"=",
"set",
"(",
"old_dict",
")",
"new_set",
"=",
"set",
"(",
"new_dict",
")",
"added_set",
"=",
"new_set",
"-",
"old_set",
"removed_set",
"=",
"old_set",
"-",
"new_set",
"c... | Diffs two single dimension dictionaries
Returns the number of changes and an unordered list
expressing the common entries and changes.
Args:
old_dict(dict): old dictionary
new_dict(dict): new dictionary
Returns: list()
int: number of changed records
list: [DictValue] | [
"Diffs",
"two",
"single",
"dimension",
"dictionaries"
] | ad6013a03a560c46ba3c63c4d153336273e6da5d | https://github.com/cloudtools/stacker/blob/ad6013a03a560c46ba3c63c4d153336273e6da5d/stacker/actions/diff.py#L73-L111 | train |
cloudtools/stacker | stacker/actions/diff.py | diff_parameters | def diff_parameters(old_params, new_params):
"""Compares the old vs. new parameters and returns a "diff"
If there are no changes, we return an empty list.
Args:
old_params(dict): old paramters
new_params(dict): new parameters
Returns:
list: A list of differences
"""
[c... | python | def diff_parameters(old_params, new_params):
"""Compares the old vs. new parameters and returns a "diff"
If there are no changes, we return an empty list.
Args:
old_params(dict): old paramters
new_params(dict): new parameters
Returns:
list: A list of differences
"""
[c... | [
"def",
"diff_parameters",
"(",
"old_params",
",",
"new_params",
")",
":",
"[",
"changes",
",",
"diff",
"]",
"=",
"diff_dictionaries",
"(",
"old_params",
",",
"new_params",
")",
"if",
"changes",
"==",
"0",
":",
"return",
"[",
"]",
"return",
"diff"
] | Compares the old vs. new parameters and returns a "diff"
If there are no changes, we return an empty list.
Args:
old_params(dict): old paramters
new_params(dict): new parameters
Returns:
list: A list of differences | [
"Compares",
"the",
"old",
"vs",
".",
"new",
"parameters",
"and",
"returns",
"a",
"diff"
] | ad6013a03a560c46ba3c63c4d153336273e6da5d | https://github.com/cloudtools/stacker/blob/ad6013a03a560c46ba3c63c4d153336273e6da5d/stacker/actions/diff.py#L133-L148 | train |
cloudtools/stacker | stacker/actions/diff.py | normalize_json | def normalize_json(template):
"""Normalize our template for diffing.
Args:
template(str): string representing the template
Returns:
list: json representation of the parameters
"""
obj = parse_cloudformation_template(template)
json_str = json.dumps(
obj, sort_keys=True, ... | python | def normalize_json(template):
"""Normalize our template for diffing.
Args:
template(str): string representing the template
Returns:
list: json representation of the parameters
"""
obj = parse_cloudformation_template(template)
json_str = json.dumps(
obj, sort_keys=True, ... | [
"def",
"normalize_json",
"(",
"template",
")",
":",
"obj",
"=",
"parse_cloudformation_template",
"(",
"template",
")",
"json_str",
"=",
"json",
".",
"dumps",
"(",
"obj",
",",
"sort_keys",
"=",
"True",
",",
"indent",
"=",
"4",
",",
"default",
"=",
"str",
... | Normalize our template for diffing.
Args:
template(str): string representing the template
Returns:
list: json representation of the parameters | [
"Normalize",
"our",
"template",
"for",
"diffing",
"."
] | ad6013a03a560c46ba3c63c4d153336273e6da5d | https://github.com/cloudtools/stacker/blob/ad6013a03a560c46ba3c63c4d153336273e6da5d/stacker/actions/diff.py#L151-L168 | train |
cloudtools/stacker | stacker/actions/diff.py | DictValue.changes | def changes(self):
"""Returns a list of changes to represent the diff between
old and new value.
Returns:
list: [string] representation of the change (if any)
between old and new value
"""
output = []
if self.status() is self.UNMODIFIED:
... | python | def changes(self):
"""Returns a list of changes to represent the diff between
old and new value.
Returns:
list: [string] representation of the change (if any)
between old and new value
"""
output = []
if self.status() is self.UNMODIFIED:
... | [
"def",
"changes",
"(",
"self",
")",
":",
"output",
"=",
"[",
"]",
"if",
"self",
".",
"status",
"(",
")",
"is",
"self",
".",
"UNMODIFIED",
":",
"output",
"=",
"[",
"self",
".",
"formatter",
"%",
"(",
"' '",
",",
"self",
".",
"key",
",",
"self",
... | Returns a list of changes to represent the diff between
old and new value.
Returns:
list: [string] representation of the change (if any)
between old and new value | [
"Returns",
"a",
"list",
"of",
"changes",
"to",
"represent",
"the",
"diff",
"between",
"old",
"and",
"new",
"value",
"."
] | ad6013a03a560c46ba3c63c4d153336273e6da5d | https://github.com/cloudtools/stacker/blob/ad6013a03a560c46ba3c63c4d153336273e6da5d/stacker/actions/diff.py#L42-L60 | train |
cloudtools/stacker | stacker/actions/diff.py | Action._diff_stack | def _diff_stack(self, stack, **kwargs):
"""Handles the diffing a stack in CloudFormation vs our config"""
if self.cancel.wait(0):
return INTERRUPTED
if not build.should_submit(stack):
return NotSubmittedStatus()
if not build.should_update(stack):
ret... | python | def _diff_stack(self, stack, **kwargs):
"""Handles the diffing a stack in CloudFormation vs our config"""
if self.cancel.wait(0):
return INTERRUPTED
if not build.should_submit(stack):
return NotSubmittedStatus()
if not build.should_update(stack):
ret... | [
"def",
"_diff_stack",
"(",
"self",
",",
"stack",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"self",
".",
"cancel",
".",
"wait",
"(",
"0",
")",
":",
"return",
"INTERRUPTED",
"if",
"not",
"build",
".",
"should_submit",
"(",
"stack",
")",
":",
"return",
... | Handles the diffing a stack in CloudFormation vs our config | [
"Handles",
"the",
"diffing",
"a",
"stack",
"in",
"CloudFormation",
"vs",
"our",
"config"
] | ad6013a03a560c46ba3c63c4d153336273e6da5d | https://github.com/cloudtools/stacker/blob/ad6013a03a560c46ba3c63c4d153336273e6da5d/stacker/actions/diff.py#L220-L278 | train |
cloudtools/stacker | stacker/actions/graph.py | each_step | def each_step(graph):
"""Returns an iterator that yields each step and it's direct
dependencies.
"""
steps = graph.topological_sort()
steps.reverse()
for step in steps:
deps = graph.downstream(step.name)
yield (step, deps) | python | def each_step(graph):
"""Returns an iterator that yields each step and it's direct
dependencies.
"""
steps = graph.topological_sort()
steps.reverse()
for step in steps:
deps = graph.downstream(step.name)
yield (step, deps) | [
"def",
"each_step",
"(",
"graph",
")",
":",
"steps",
"=",
"graph",
".",
"topological_sort",
"(",
")",
"steps",
".",
"reverse",
"(",
")",
"for",
"step",
"in",
"steps",
":",
"deps",
"=",
"graph",
".",
"downstream",
"(",
"step",
".",
"name",
")",
"yield... | Returns an iterator that yields each step and it's direct
dependencies. | [
"Returns",
"an",
"iterator",
"that",
"yields",
"each",
"step",
"and",
"it",
"s",
"direct",
"dependencies",
"."
] | ad6013a03a560c46ba3c63c4d153336273e6da5d | https://github.com/cloudtools/stacker/blob/ad6013a03a560c46ba3c63c4d153336273e6da5d/stacker/actions/graph.py#L14-L24 | train |
cloudtools/stacker | stacker/actions/graph.py | dot_format | def dot_format(out, graph, name="digraph"):
"""Outputs the graph using the graphviz "dot" format."""
out.write("digraph %s {\n" % name)
for step, deps in each_step(graph):
for dep in deps:
out.write(" \"%s\" -> \"%s\";\n" % (step, dep))
out.write("}\n") | python | def dot_format(out, graph, name="digraph"):
"""Outputs the graph using the graphviz "dot" format."""
out.write("digraph %s {\n" % name)
for step, deps in each_step(graph):
for dep in deps:
out.write(" \"%s\" -> \"%s\";\n" % (step, dep))
out.write("}\n") | [
"def",
"dot_format",
"(",
"out",
",",
"graph",
",",
"name",
"=",
"\"digraph\"",
")",
":",
"out",
".",
"write",
"(",
"\"digraph %s {\\n\"",
"%",
"name",
")",
"for",
"step",
",",
"deps",
"in",
"each_step",
"(",
"graph",
")",
":",
"for",
"dep",
"in",
"d... | Outputs the graph using the graphviz "dot" format. | [
"Outputs",
"the",
"graph",
"using",
"the",
"graphviz",
"dot",
"format",
"."
] | ad6013a03a560c46ba3c63c4d153336273e6da5d | https://github.com/cloudtools/stacker/blob/ad6013a03a560c46ba3c63c4d153336273e6da5d/stacker/actions/graph.py#L27-L35 | train |
cloudtools/stacker | stacker/actions/graph.py | json_format | def json_format(out, graph):
"""Outputs the graph in a machine readable JSON format."""
steps = {}
for step, deps in each_step(graph):
steps[step.name] = {}
steps[step.name]["deps"] = [dep.name for dep in deps]
json.dump({"steps": steps}, out, indent=4)
out.write("\n") | python | def json_format(out, graph):
"""Outputs the graph in a machine readable JSON format."""
steps = {}
for step, deps in each_step(graph):
steps[step.name] = {}
steps[step.name]["deps"] = [dep.name for dep in deps]
json.dump({"steps": steps}, out, indent=4)
out.write("\n") | [
"def",
"json_format",
"(",
"out",
",",
"graph",
")",
":",
"steps",
"=",
"{",
"}",
"for",
"step",
",",
"deps",
"in",
"each_step",
"(",
"graph",
")",
":",
"steps",
"[",
"step",
".",
"name",
"]",
"=",
"{",
"}",
"steps",
"[",
"step",
".",
"name",
"... | Outputs the graph in a machine readable JSON format. | [
"Outputs",
"the",
"graph",
"in",
"a",
"machine",
"readable",
"JSON",
"format",
"."
] | ad6013a03a560c46ba3c63c4d153336273e6da5d | https://github.com/cloudtools/stacker/blob/ad6013a03a560c46ba3c63c4d153336273e6da5d/stacker/actions/graph.py#L38-L46 | train |
cloudtools/stacker | stacker/actions/graph.py | Action.run | def run(self, format=None, reduce=False, *args, **kwargs):
"""Generates the underlying graph and prints it.
"""
plan = self._generate_plan()
if reduce:
# This will performa a transitive reduction on the underlying
# graph, producing less edges. Mostly useful for ... | python | def run(self, format=None, reduce=False, *args, **kwargs):
"""Generates the underlying graph and prints it.
"""
plan = self._generate_plan()
if reduce:
# This will performa a transitive reduction on the underlying
# graph, producing less edges. Mostly useful for ... | [
"def",
"run",
"(",
"self",
",",
"format",
"=",
"None",
",",
"reduce",
"=",
"False",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"plan",
"=",
"self",
".",
"_generate_plan",
"(",
")",
"if",
"reduce",
":",
"# This will performa a transitive reducti... | Generates the underlying graph and prints it. | [
"Generates",
"the",
"underlying",
"graph",
"and",
"prints",
"it",
"."
] | ad6013a03a560c46ba3c63c4d153336273e6da5d | https://github.com/cloudtools/stacker/blob/ad6013a03a560c46ba3c63c4d153336273e6da5d/stacker/actions/graph.py#L63-L77 | train |
cloudtools/stacker | stacker/hooks/iam.py | get_cert_contents | def get_cert_contents(kwargs):
"""Builds parameters with server cert file contents.
Args:
kwargs(dict): The keyword args passed to ensure_server_cert_exists,
optionally containing the paths to the cert, key and chain files.
Returns:
dict: A dictionary containing the appropriate... | python | def get_cert_contents(kwargs):
"""Builds parameters with server cert file contents.
Args:
kwargs(dict): The keyword args passed to ensure_server_cert_exists,
optionally containing the paths to the cert, key and chain files.
Returns:
dict: A dictionary containing the appropriate... | [
"def",
"get_cert_contents",
"(",
"kwargs",
")",
":",
"paths",
"=",
"{",
"\"certificate\"",
":",
"kwargs",
".",
"get",
"(",
"\"path_to_certificate\"",
")",
",",
"\"private_key\"",
":",
"kwargs",
".",
"get",
"(",
"\"path_to_private_key\"",
")",
",",
"\"chain\"",
... | Builds parameters with server cert file contents.
Args:
kwargs(dict): The keyword args passed to ensure_server_cert_exists,
optionally containing the paths to the cert, key and chain files.
Returns:
dict: A dictionary containing the appropriate parameters to supply to
u... | [
"Builds",
"parameters",
"with",
"server",
"cert",
"file",
"contents",
"."
] | ad6013a03a560c46ba3c63c4d153336273e6da5d | https://github.com/cloudtools/stacker/blob/ad6013a03a560c46ba3c63c4d153336273e6da5d/stacker/hooks/iam.py#L74-L124 | train |
cloudtools/stacker | stacker/blueprints/raw.py | get_template_path | def get_template_path(filename):
"""Find raw template in working directory or in sys.path.
template_path from config may refer to templates colocated with the Stacker
config, or files in remote package_sources. Here, we emulate python module
loading to find the path to the template.
Args:
... | python | def get_template_path(filename):
"""Find raw template in working directory or in sys.path.
template_path from config may refer to templates colocated with the Stacker
config, or files in remote package_sources. Here, we emulate python module
loading to find the path to the template.
Args:
... | [
"def",
"get_template_path",
"(",
"filename",
")",
":",
"if",
"os",
".",
"path",
".",
"isfile",
"(",
"filename",
")",
":",
"return",
"os",
".",
"path",
".",
"abspath",
"(",
"filename",
")",
"for",
"i",
"in",
"sys",
".",
"path",
":",
"if",
"os",
".",... | Find raw template in working directory or in sys.path.
template_path from config may refer to templates colocated with the Stacker
config, or files in remote package_sources. Here, we emulate python module
loading to find the path to the template.
Args:
filename (str): Template filename.
... | [
"Find",
"raw",
"template",
"in",
"working",
"directory",
"or",
"in",
"sys",
".",
"path",
"."
] | ad6013a03a560c46ba3c63c4d153336273e6da5d | https://github.com/cloudtools/stacker/blob/ad6013a03a560c46ba3c63c4d153336273e6da5d/stacker/blueprints/raw.py#L18-L38 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.