thoth.lab package

Submodules

thoth.lab.convert module

Utilities to work with package dependencies.

thoth.lab.graph module

Various helpers and utils for interaction with the graph database.

class thoth.lab.graph.DependencyGraph(incoming_graph_data=None, **attr)[source]

Bases: networkx.classes.ordered.OrderedDiGraph

Construct a dependency graph by extending nx.OrderedDiGraph.

adjlist_dict_factory

alias of collections.OrderedDict

static get_root(tree)[source]

Return root of the current graph, if any.

By default, tree topology is considered as input, so if there are multiple roots, only the first one is returned.

node_dict_factory

alias of collections.OrderedDict

class thoth.lab.graph.GraphQueryResult(result)[source]

Bases: object

Wrap results of graph database queries.

plot_bar()[source]

Plot histogram of results obtained.

plot_pie()[source]

Plot a pie of results into Jupyter notebook.

serialize()[source]

Serialize the output of graph query.

to_dataframe()[source]

Construct a panda’s dataframe on results.

thoth.lab.graph.get_root(tree)

Return root of the current graph, if any.

By default, tree topology is considered as input, so if there are multiple roots, only the first one is returned.

thoth.lab.inspection module

Inspection results processing and analysis.

thoth.lab.inspection.create_duration_box(data: pandas.core.frame.DataFrame, columns: Union[str, List[str]] = None, **kwargs)[source]

Create duration Box plot.

thoth.lab.inspection.create_duration_dataframe(inspection_df: pandas.core.frame.DataFrame) → pandas.core.frame.DataFrame[source]

Compute statistics and duration DataFrame.

thoth.lab.inspection.create_duration_histogram(data: pandas.core.frame.DataFrame, columns: Union[str, List[str]] = None, bins: int = None, **kwargs)[source]

Create duration Histogram plot.

thoth.lab.inspection.create_duration_scatter(data: pandas.core.frame.DataFrame, columns: Union[str, List[str]] = None, **kwargs)[source]

Create duration Scatter plot.

thoth.lab.inspection.create_duration_scatter_with_bounds(data: pandas.core.frame.DataFrame, col: str, index: Union[list, pandas.core.indexes.base.Index] = None, **kwargs)[source]

Create duration Scatter plot with upper and lower bounds.

thoth.lab.inspection.extract_keys_from_dataframe(df: pandas.core.frame.DataFrame, key: str)[source]

Filter the specific dataframe created for a certain key, combination of keys or for a tree depth.

thoth.lab.inspection.extract_structure_json(input_json: dict, upper_key: str, level: int, json_structure)[source]

Convert a json file structure into a list with rows showing tree depths, keys and values.

thoth.lab.inspection.make_subplots(data: pandas.core.frame.DataFrame, columns: List[str] = None, *, kind: str = 'box', **kwargs)[source]

Make subplots and arrange them in an optimized grid layout.

thoth.lab.inspection.process_inspection_results(inspection_results: List[dict], exclude: Union[list, set] = None, apply: List[Tuple] = None, drop: bool = True, verbose: bool = False) → pandas.core.frame.DataFrame[source]

Process inspection result into pd.DataFrame.

thoth.lab.inspection.query_inspection_dataframe(inspection_df: pandas.core.frame.DataFrame, *args, **kwargs) → pandas.core.frame.DataFrame[source]

Wrapper around _.query method which always include duration columns in filter expression.

thoth.lab.inspection.show_categories(inspection_df: pandas.core.frame.DataFrame)[source]

List categories in the given DataFrame.

thoth.lab.underscore module

Pandas common operations and utilities.

thoth.lab.underscore.rget(obj: Any, attr: str, default: Any = <object object>) → Any

Recursively retrieve nested attributes of an object.

Parameters
  • f – callable, function to be used as getattr

  • obj – Any, object to check

  • attr – str, attribute to find declared by dot notation accessor

  • default – default attribute, similar to getattr’s default

Returns

Any, retrieved attribute

thoth.lab.utils module

Various utilities for notebooks.

thoth.lab.utils.display_page(location: str, verify: bool = True, no_obtain_location: bool = False, width: int = 980, height: int = 900)[source]

Display the given page in notebook as iframe.

thoth.lab.utils.get(obj, attr, *, default: Any = <object object>)[source]

Combine both getattr and dict.get into universal get.

thoth.lab.utils.get_column_group(df: pandas.core.frame.DataFrame, columns: Union[List[Union[str, int]], pandas.core.indexes.base.Index] = None, label: str = None) → pandas.core.series.Series[source]

Group columns of the DataFrame into a single column group.

thoth.lab.utils.get_index_group(df: pandas.core.frame.DataFrame, names: List[Union[str, int]] = None, label: str = None) → pandas.core.series.Series[source]

Group multiple index levels into single index group.

thoth.lab.utils.group_columns(df: pandas.core.frame.DataFrame, columns: Union[List[Union[str, int]], pandas.core.indexes.base.Index] = None, label: str = None, inplace: bool = False) → pandas.core.series.Series[source]

Group columns of the DataFrame into a single column group and set it to the DataFrame.

thoth.lab.utils.group_index(df: pandas.core.frame.DataFrame, names: List[Union[str, int]] = None, label: str = None, inplace: bool = False) → pandas.core.frame.DataFrame[source]

Group multiple index levels into single index group and set it as index to the DataFrame.

thoth.lab.utils.has(obj, attr)[source]

Combine both hasattr and in into universal has.

thoth.lab.utils.highlight(df: pandas.core.frame.DataFrame, content: str = None, column_class: str = None, colours: Union[list, str] = None)[source]

Highlight rows of content column of a given DataFrame.

Highlight can be based on column_class or custom colours provided.

thoth.lab.utils.obtain_location(name: str, verify: bool = False, only_netloc: bool = False) → str[source]

Obtain location of a service based on it’s name in Red Hat’s internal network.

This function basically checks redirect of URL registered at Red Hat’s internal network. By doing so it is prevented to expose internal URLs. There is queried https://url.corp.redhat.com for redirects.

>>> obtain_location('thoth-sbu', verify=False)
thoth.lab.utils.packages_info(thoth_packages: bool = True) → pandas.core.frame.DataFrame[source]

Display information about versions of packages available in the installation.

thoth.lab.utils.resolve_query(query: str, context: pandas.core.frame.DataFrame = None, resolvers: tuple = None, engine: str = None, parser: str = 'pandas')[source]

Resolve query in the given context.

thoth.lab.utils.rget(obj: Any, attr: str, default: Any = <object object>) → Any

Recursively retrieve nested attributes of an object.

Parameters
  • f – callable, function to be used as getattr

  • obj – Any, object to check

  • attr – str, attribute to find declared by dot notation accessor

  • default – default attribute, similar to getattr’s default

Returns

Any, retrieved attribute

thoth.lab.utils.rgetattr(obj: Any, attr: str, default: Any = <object object>) → Any

Recursively retrieve nested attributes of an object.

Parameters
  • f – callable, function to be used as getattr

  • obj – Any, object to check

  • attr – str, attribute to find declared by dot notation accessor

  • default – default attribute, similar to getattr’s default

Returns

Any, retrieved attribute

thoth.lab.utils.rhas(obj: Any, attr: str) → bool

Recursively check nested attributes of an object.

Parameters
  • fhas – callable, function to be used as hasattr

  • fget – callable, function to be used as getattr

  • obj – Any, object to check

  • attr – str, attribute to find declared by dot notation accessor

Returns

bool, whether the object has the given attribute

thoth.lab.utils.rhasattr(obj: Any, attr: str) → bool

Recursively check nested attributes of an object.

Parameters
  • fhas – callable, function to be used as hasattr

  • fget – callable, function to be used as getattr

  • obj – Any, object to check

  • attr – str, attribute to find declared by dot notation accessor

Returns

bool, whether the object has the given attribute

thoth.lab.utils.scale_colour_continuous(arr: Iterable, colour_palette=None, n_colours: int = 10, norm=False)[source]

Scale given arrays into colour array by specific palette.

The default number of colours is 10, which translates to dividing an array on a scale from 0 to 1 into 0.1 colour bins.

Module contents

Routines for experiments in Thoth not only for Jupyter notebooks.