DataComPy is a powerful Python library designed to simplify the comparison of two DataFrames, supporting various backends including Pandas, Spark, Polars, and Snowflake. It generates detailed, human-readable reports highlighting discrepancies at both row and column levels, and allows for the specification of absolute or relative tolerance levels for numeric comparisons. The library is currently at version 0.19.5 and is actively progressing towards a v1 release, with new features targeting development branches while the 0.19.x branch is for maintenance and critical fixes.
pip install datacompyVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to compare two Pandas DataFrames using `datacompy.Compare`. It initializes two sample DataFrames, then creates a `Compare` object specifying the join column and tolerance levels for numeric comparisons. Finally, it prints a comprehensive report of differences and checks for an overall match.
Migrate to `datacompy.spark.sql.SparkSQLCompare` or `datacompy.is_match` with Fugue backend. Consult the documentation for specific backend usage.
For large datasets, use `datacompy` with Spark, Polars, or Fugue backends after installing the relevant extras (e.g., `pip install datacompy[spark]`).
Set appropriate `abs_tol` and `rel_tol` values when initializing the `Compare` object (e.g., `abs_tol=0.0001`, `rel_tol=0.01`).
Ensure `join_columns` provide sufficient granularity to uniquely identify rows, or pre-process duplicates if specific matching behavior is required.
Either rename or replace 'DATACOMPY_NULL' values in your join columns before comparison, or fill nulls with a different sentinel value of your choice.
Monitor GitHub releases and documentation for `v1` migration guides when upgrading from `0.19.x`.
If using Spark or Ray with Fugue, consider using Python versions <3.12 until full compatibility is announced. Otherwise, Pandas and Polars backends are supported.