tabulardelta package

Subpackages

Submodules

Module contents

class tabulardelta.Comparator(*args, **kwargs)[source]

Bases: Protocol[T]

Protocol for offering table comparison logic for TabularDelta.

Ensures compatibility with all Formatter implementations.

Methods

compare(old: T, new: T) -> TabularDelta:

Compare two tables

compare(old: T, new: T) TabularDelta[source]

Compare two tables.

Arguments:
old T:

The old table (first table to compare).

new T:

The new table (second table to compare).

Returns TabularDelta:

Metadata and results of the comparison.

class tabulardelta.DetailedTextFormatter[source]

Bases: object

Implements Formatter protocol for detailed report of single comparison.

Tries to show as much information as possible, without overwhelming the user.

Methods

format(delta: TabularDelta) -> str:

Formats comparison result

column_changes = True

Whether to show column and type changes in the report.

errors = True

Whether to show errors in the report.

format(delta: TabularDelta) str[source]

Formats comparison result.

Arguments:
delta TabularDelta:

Metadata and result of a comparison.

Returns str:

Detailed comparison report.

infos = True

Whether to show additional information in the report.

row_examples = 3

How many examples to show for added and removed rows in the report.

0 to disable.

row_overview = True

Whether to show graphical row matching in the report.

value_change_height = 5

Maximum lines to show per value change in the report.

Uses line-by-line diff if cells are too large.

value_changes = 5

How many value changes per column to show in the report.

0 to disable.

warnings = True

Whether to show warnings in the report.

class tabulardelta.Formatter(*args, **kwargs)[source]

Bases: Protocol[T]

Protocol for offering visualizations or further analyses for TabularDelta.

Ensures compatibility with all Comparator implementations.

Methods

format(delta: TabularDelta) -> T:

Formats comparison result

format(delta: TabularDelta) T[source]

Formats comparison result.

Arguments:
delta TabularDelta:

Metadata and result of a comparison.

Returns T:

Arbitrary output. Usually strings visualizing the comparison.

class tabulardelta.OverviewRowFormatter(warnings: bool = True, errors: bool = True, state: list[~tabulardelta.formatters.overview_row_formatter.Row] = <factory>)[source]

Bases: object

Implements Formatter protocol for combining multiple comparisons.

This formatter is stateful to accumulate TabularDelta comparisons as rows.

Additional rows can be added using add_str, add_row, add_header, and add_legend. Call table() to retrieve the table, which by default resets the state of the formatter.

Methods

format(delta: TabularDelta) -> None:

Stores comparison as row in internal state

add_header(title: str = “ TABLE”) -> None:

Add header row to internal state

add_legend() -> None:

Add legend as rows to internal state

add_str(row: str) -> None:

Add string as row to internal state

add_row(char: str, name: str, rows: int, cols: int) -> None:

Manually add table as row to internal state

table(keep_state: bool = False) -> str:

Retrieve report from internal state

add_header(title: str = '  TABLE') None[source]

Add header row to internal state.

This should be called at least once in the beginning.

Use this method with the optional title, to separate different chunks of comparisons.

Arguments:
title str:

Title describing the following tables.

Returns None:

No return value. Use table() to retrieve report.

add_legend() None[source]

Add legend as rows to internal state.

This should be called in the end, if the users aren’t familiar with the column meanings.

Returns None:

No return value. Use table() to retrieve report.

add_row(char: str, name: str, rows: int, cols: int) None[source]

Manually add table as row to internal state.

This is especially helpful for including added or removed tables.

add_row("+", "table", 10, 5) will result in

  TABLE  ROWS  COLUMNS
+ table  10    5
Arguments:
char str:

One-char summary of comparison, please refer to the legend.

name str:

Name of the table.

rows int:

Number of rows in the table.

cols int:

Number of columns in the table.

Returns None:

No return value. Use table() to retrieve report.

add_str(row: str) None[source]

Add string as row to internal state.

This can be used to customize the report with additional information.

Arguments:
row str:

Content of the row.

Returns None:

No return value. Use table() to retrieve report.

errors: bool = True

Whether to show errors in the report.

format(delta: TabularDelta) None[source]

Stores comparison as row in internal state.

Arguments:
delta TabularDelta:

Metadata and result of a comparison.

Returns None:

No return value. Use table() to retrieve report.

state: list[Row]

Internal state of the formatter.

May be used to do custom modifications/analyses. May change.

table(keep_state: bool = False) str[source]

Retrieve report from internal state.

Arguments:
keep_state bool:

Whether to keep the internal state or clean it up.

Returns str:

Table combining comparisons as rows.

warnings: bool = True

Whether to show warnings in the report.

class tabulardelta.PandasComparator(join_columns: list[str] | None = None, name: str = '', float_rtol: float = 1e-05, float_atol: float = 0.0, check_row_order: bool = True)[source]

Bases: object

Implements Comparator protocol for comparing pandas DataFrames.

Attributes:
join_columns

Methods

compare(old: pd.DataFrame, new: pd.DataFrame) -> TabularDelta:

Compare two pandas DataFrames

check_row_order: bool = True

Check if row order changed.

Slight performance hit.

compare(old: DataFrame, new: DataFrame) TabularDelta[source]

Compare two pandas DataFrames.

Arguments:
old :pd.DataFrame:

The old table (first table to compare).

new :pd.DataFrame:

The new table (second table to compare).

Returns TabularDelta:

Metadata and results of the comparison.

float_atol: float = 0.0

Absolute tolerance for comparing floats.

float_rtol: float = 1e-05

Relative tolerance for comparing floats.

join_columns: list[str] | None = None

Columns to join on, uses index if unspecified.

name: str = ''

Name of the comparison/tables.

class tabulardelta.SqlCompyreComparator(engine: Engine, join_columns: list[str] | None = None, row_samples: int = 10, value_samples: int = 50, float_precision: float = 1e-06, warning_threshold: int = 10000)[source]

Bases: object

Implements Comparator protocol for comparing SQL Tables.

This is mostly a wrapper for SQLCompyre’s table comparison.

Attributes:
join_columns

Methods

compare(self, old: sa.Table | str, new: sa.Table | str) -> TabularDelta:

Compare two SQL tables

compare(old: Table | str, new: Table | str) TabularDelta[source]

Compare two SQL tables.

Arguments:
old sa.Table | str:

The old table (first table to compare).

new sa.Table | str:

The new table (second table to compare).

Returns TabularDelta:

Metadata and results of the comparison.

engine: Engine

SQLAlchemy engine to connect to the database.

float_precision: float = 1e-06

Relative precision for comparing floats.

join_columns: list[str] | None = None

Columns to join the two tables on.

If None, SQLCompyre will try to infer them.

row_samples: int = 10

Number of example rows to sample.

value_samples: int = 50

Number of example value changes to sample.

warning_threshold: int = 10000

Minimal number of rows to warn about when comparing tables.

class tabulardelta.SqlMetadataComparator(engine: ~sqlalchemy.engine.base.Engine, cache_db_metadata: bool = False, _cache: dict[~tabulardelta.comparators.sqlmetadata_comparator._TableDescr, ~tabulardelta.comparators.sqlmetadata_comparator._TableMetadata] = <factory>)[source]

Bases: object

Implements Comparator protocol for comparing SQL Tables.

This will only use metadata from the database, to be as fast as possible.

Methods

compare(self, old: sa.Table | str, new: sa.Table | str) -> TabularDelta:

Compare two SQL tables

cache_db_metadata: bool = False

Whether to cache metadata for whole database to speed up comparisons.

compare(old: Table | str, new: Table | str) TabularDelta[source]

Compare two SQL tables.

Arguments:
old sa.Table | str:

The old table (first table to compare).

new sa.Table | str:

The new table (second table to compare).

Returns TabularDelta:

Metadata and results of the comparison.

dialects = {'mssql': <function get_mssql_metadata>}

Dictionary of supported dialects and their metadata retrieval functions.

engine: Engine

SQLAlchemy engine to connect to the database.

class tabulardelta.TabularDelta(*args, **kwargs)[source]

Bases: Protocol

Generic collection of information gathered by one table comparison.

Contains metadata about the comparison, RowDelta and ColumnDelta.

Attributes:
cols

Column comparison containing information about columns, types, and value changes.

errors

Errors collected during the comparison.

info

Additional information collected during the comparison.

name

Name of the new table and therefore the comparison.

old_name

Optional name of the old table.

rows

Row comparison containing information about row changes and examples.

warnings

Warnings collected during the comparison.

property cols: ColumnDelta

Column comparison containing information about columns, types, and value changes.

property errors: Sequence[str]

Errors collected during the comparison.

property info: Sequence[str]

Additional information collected during the comparison.

property name: str

Name of the new table and therefore the comparison.

property old_name: str | None

Optional name of the old table.

property rows: RowDelta

Row comparison containing information about row changes and examples.

property warnings: Sequence[str]

Warnings collected during the comparison.