compare#

versus.compare(
table_a: DuckInput | 'DataFrame',
table_b: DuckInput | 'DataFrame',
*,
by: Sequence[str],
allow_both_na: bool = True,
coerce: bool = True,
table_id: Tuple[str, str] = ('a', 'b'),
con: duckdb.DuckDBPyConnection | None = None,
spark: 'SparkSession' | None = None,
materialize: Literal['all', 'summary', 'none'] = 'all',
) BaseComparison#

Compare two tables by key columns using DuckDB or PySpark.

Parameters:
table_a, table_bDuckDBPyRelation, pandas.DataFrame, polars.DataFrame, or pyspark.sql.DataFrame

Tabular inputs to compare. If either input is a PySpark DataFrame, or if spark= is supplied, the comparison runs on Spark and returns Spark-backed outputs. Otherwise DuckDB powers the comparison.

bysequence of str

Column names that uniquely identify rows.

allow_both_nabool, default True

Whether to treat NULL/NA values as equal when both sides are missing.

coercebool, default True

If True, allow DuckDB to coerce compatible types. If False, require exact type matches for shared columns.

table_idtuple[str, str], default (“a”, “b”)

Labels used in outputs for the two tables.

conduckdb.DuckDBPyConnection, optional

DuckDB connection used to register non-Spark inputs and run queries.

sparkpyspark.sql.SparkSession, optional

Spark session used when the comparison runs on Spark.

materialize{“all”, “summary”, “none”}, default “all”

Controls which helper tables are materialized upfront.

Returns:
Comparison

Backend-specific comparison object with summary tables and diff helpers.

Examples

>>> from versus import compare, examples
>>> comparison = compare(
...     examples.example_cars_a(),
...     examples.example_cars_b(),
...     by=["car"],
... )
>>> comparison.summary()
┌────────────────┬─────────┐
│   difference   │  found  │
│    varchar     │ boolean │
├────────────────┼─────────┤
│ value_diffs    │ true    │
│ unmatched_cols │ true    │
│ unmatched_rows │ true    │
│ type_diffs     │ false   │
└────────────────┴─────────┘