Skip to content

feat: add datacompy compare CLI with multi-backend support - #544

Merged
fdosani merged 9 commits into
mainfrom
cli-feature
Aug 6, 2026
Merged

feat: add datacompy compare CLI with multi-backend support#544
fdosani merged 9 commits into
mainfrom
cli-feature

Conversation

@fdosani

@fdosani fdosani commented Jul 31, 2026

Copy link
Copy Markdown
Member

Closes #530, Using this one in favour of #534

Adds a datacompy console script so two datasets can be compared from a shell without writing a throwaway script, for ad hoc checks and for CI pipelines that run as shell tasks.

datacompy compare --left before.csv --right after.csv --on id

Exit codes: 0 match, 1 mismatch or threshold exceeded, 2 error, 130 interrupt.
Supports the pandas, polars, Spark, and Snowflake backends over CSV, Parquet, and JSON.

Design notes:

  • parser.py holds one declarative OPTIONS table that drives both the argparse parser and the Compare constructor kwargs. Adding a library keyword to the CLI is a single new row rather than two hand-maintained lists, and tests/cli/test_parser.py checks every mapping against the real constructor signature via inspect.signature, so the two cannot silently drift.
  • Backend applicability, such as --on-index being pandas only and --cast-column-names-lower not applying to Snowflake, is data on the spec row rather than a validation branch.
  • backends.py defines a CLIBackend ABC mirroring the existing BaseCompare strategy pattern. Each backend owns its session, loaders, and constructor

@rhaffar rhaffar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good Faisal, just a few comments - thanks for incorporating some of the changes I recommended from the last PR

Comment thread datacompy/cli/backends.py
Comment thread datacompy/cli/backends.py Outdated
Comment thread datacompy/cli/compare.py
Comment on lines +107 to +113
if join_columns and on_index:
raise BadArgsError("--on and --on-index are mutually exclusive.")
if not join_columns and not on_index:
raise BadArgsError(
"--on is required. Specify at least one join column with --on COL, "
"or use --on-index with --backend pandas to join on the index."
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do check for this in the Pandas compare code - wondering if we should just passthrough both args and let the compare throw the error instead?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should catch it in the CLI process since its separate from the non-CLI part of datacompy. Open to changing it if you think otherwise!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, this one is more of a personal preference thing so more than ok to catch it in the CLI 👍

Comment thread datacompy/cli/parser.py Outdated
Comment thread datacompy/cli/parser.py
@fdosani

fdosani commented Aug 5, 2026

Copy link
Copy Markdown
Member Author

Thanks Raymond:

  • I added SNOWFLAKE_TOKEN with OAuth implied and SNOWFLAKE_USER optional under it (I'll check against a live accoun),
  • dropped BACKEND_NAMES in favour of ALL_BACKENDS.
  • On --on: kept the check, since join_columns is a required positional everywhere but pandas, without it you get an uncaught TypeError instead of the library's error, and only after Spark has already started a JVM and loaded both sides.

@rhaffar rhaffar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@fdosani
fdosani merged commit 89ee851 into main Aug 6, 2026
20 checks passed
@fdosani
fdosani deleted the cli-feature branch August 6, 2026 15:24
@fdosani
fdosani restored the cli-feature branch August 6, 2026 15:24
@fdosani
fdosani deleted the cli-feature branch August 7, 2026 01:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: Command Line Interface

2 participants