Metadata-Version: 2.5
Name: ddiff-tui
Version: 0.1.0
Summary: ddiff: see what changed between two data files (parquet, CSV, JSON, Excel) of any size, in your terminal
Project-URL: Homepage, https://github.com/jimhendy/ddiff
Project-URL: Issues, https://github.com/jimhendy/ddiff/issues
Author: jimhendy
License-Expression: MIT
License-File: LICENSE
Keywords: csv,data,diff,duckdb,parquet,terminal,textual,tui
Classifier: Development Status :: 3 - Alpha
Classifier: Environment :: Console :: Curses
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Scientific/Engineering :: Information Analysis
Classifier: Topic :: Utilities
Requires-Python: >=3.11
Requires-Dist: duckdb<2,>=1.1
Requires-Dist: openpyxl
Requires-Dist: pandas>=2.2
Requires-Dist: pyarrow>=15
Requires-Dist: textual>=8.0
Description-Content-Type: text/markdown

<div align="center">

# ddiff

**See what changed between two data files. Ten million rows in six seconds.**

parquet · CSV · TSV · JSON · JSON lines · Excel · Arrow, compared with [DuckDB](https://duckdb.org), shown with [Textual](https://textual.textualize.io)

[![CI and Release](https://github.com/jimhendy/ddiff/actions/workflows/ci-release.yml/badge.svg)](https://github.com/jimhendy/ddiff/actions/workflows/ci-release.yml)
[![PyPI](https://img.shields.io/pypi/v/ddiff-tui)](https://pypi.org/project/ddiff-tui/)
![python](https://img.shields.io/badge/python-3.11%20%E2%80%93%203.14-3776ab)
![license](https://img.shields.io/badge/license-MIT-green)

<img src="assets/rows.png" alt="ddiff showing the rows of a 10 million row diff, sorted by the biggest price change" width="100%">

</div>

```bash
uv tool install ddiff-tui      # or: pipx install ddiff-tui
ddiff old.parquet new.parquet
```

## Why ddiff?

The pipeline changed, the vendor re-sent the file, someone "only refactored" a
query. Is the output the same? `diff` is useless on parquet and drowns on CSV.
Usually it ends in a notebook with `pd.merge(..., indicator=True)`, running out
of memory.

`ddiff old new` tells you straight away:

- **Which rows were added, removed or changed**, matched on a key. ddiff finds a
  key for you (a column unique in both files, preferring id-like names) or you
  pass `--key`. Rows can be in any order. With no key it compares row by row.
- **Which columns changed and how much**: columns added and removed, type
  changes, the number of changed cells in each column, and how each column's
  nulls, distinct values, min, max and mean moved.
- **Every changed cell as `old → new`**, filtered to one column, sorted by the
  size of the change, and with any row's fields shown old beside new.
- **Files bigger than RAM.** DuckDB reads both files into a temporary on-disk
  database and does the join. Only the rows that differ are stored, and the
  table pages them in 64 rows at a time.
- **Scripts and CI too**: `--summary` or `--json` print the result, and the exit
  code is 0 when the files match, 1 when they differ and 2 on an error, like
  `diff`. `-o diff.parquet` saves the differences.
- **The SQL is yours**: `S` shows the DuckDB SQL behind the diff, ready to run.

## How fast?

Two 10,000,000-row trade files (180 MB and 230 MB of parquet; 1% of prices
nudged, 0.2% of venues changed, 9,890 rows deleted, 20,000 added, a column
dropped and one added), on a 2017 laptop (i7-7700HQ, 4 cores):

| | |
|---|---|
| Diff two parquet files, choosing the key itself | **6.0 s** (1.4 GB RAM) |
| The same data as CSV (630 MB each) | **9.2 s** |
| Scroll, page, jump to the last of 149,229 differing rows | instant (3 ms a block) |
| Sort the differences by the size of the price change | **0.02 s** |
| Show only the rows where price changed | **0.02 s** |
| Per-column stats for both files | **1 s** (in the background) |

Make the same files with `uv run python tools/make_demo_data.py` and try it.

## Summary

<img src="assets/summary.png" alt="the Summary tab: files, rows matched, added, removed, changed, column changes" width="100%">

Both files, how rows were matched, how many were unchanged, changed, added and
removed, which columns came and went, and which columns' values changed most.
`ddiff old new --summary` prints the same thing in your terminal.

## Columns

<img src="assets/columns.png" alt="the Columns tab: one row per column with changed cells and stats on both sides" width="100%">

One row per column: whether it's the key, added, removed or changed, its type on
both sides, the share of rows whose value changed, and nulls, distinct values,
mean, min and max for the old and new file. A stat that moved is highlighted.
Type to filter by name and `s` to sort. `Enter` or `c` opens the column:

<img src="assets/column.png" alt="column details: stats, size of the changes, commonest old to new changes" width="100%">

The commonest `old → new` changes, the size of the numeric changes (new − old),
and the distribution of values in both files. `f` shows the rows where it changed.

## Rows

Every differing row, with the key pinned at the left. A changed value shows as
`old → new`, and new rows are green and removed ones red. Columns with no
changes are hidden until you press `u`.

- `+` `-` `~` (or `a` `r` `m`) show or hide added, removed and modified rows
- `f` shows only the rows where the cursor's column changed
- `s` sorts by a column, `d` by the size of the change, biggest first
- `Enter` shows the row with every field old beside new; `↑` `↓` step through rows
- `w` saves the rows on show, `D` opens them in [dx](https://github.com/jimhendy/dx)

## Options

```bash
ddiff old.parquet new.parquet                    # explore
ddiff old.csv new.csv -k id                      # match rows on id
ddiff a.parquet b.parquet -k date,ticker         # a key of two columns
ddiff a.xlsx::Sheet1 b.xlsx::Sheet1              # Excel sheets
ddiff a.parquet b.parquet --atol 1e-9            # numbers this close are equal (also --rtol)
ddiff a.parquet b.parquet -w "region = 'EU'"     # an SQL filter on both files
ddiff a.parquet b.parquet -c price,qty           # compare only these columns
ddiff a.parquet b.parquet -i updated_at          # ignore these columns
ddiff a.parquet b.parquet --summary              # print; exit 0 same, 1 different, 2 error
ddiff a.parquet b.parquet --json                 # the summary as JSON
ddiff a.parquet b.parquet -o diff.parquet        # save the differing rows and exit
```

Duplicate keys are matched in file order: the second `id = 7` in the old file
pairs with the second `id = 7` in the new one. Numbers compare across integer and
float types. Other type changes compare as text and are listed in the summary.
NULL is shown as `∅`, `""` is an empty string, and values that differ only in
whitespace are shown quoted so you can see the difference.

## Keys

| Key | |
|---|---|
| `1` `2` `3` | Summary · Columns · Rows |
| arrows / `hjkl` · `PgUp` `PgDn` · `g` `G` · `Home` `End` | move · page · top / bottom · first / last column |
| `Enter` · `c` | row old beside new (Rows) or column details (Columns) · column details |
| `s` · `d` | sort: ascending → descending → off · by size of change |
| `f` · `+` `-` `~` · `u` · `x` | only this column's changes · added / removed / modified · unchanged columns · clear |
| `/` · `<` `>` | find a column · narrower / wider |
| `w` · `D` · `S` | save · open in dx · the SQL |
| `?` · `ctrl+p` · `q` | all keys · command palette and themes · quit |

## Development

```bash
just sync     # install dev dependencies
just ci       # lint, format check and tests, as in CI
just examples # example file pairs to play with (see examples/README.md)
just shots    # README screenshots (makes the 10 M row demo files first)
```

Pushing to `main` with a new version in `pyproject.toml` publishes it to PyPI
(as `ddiff-tui`; plain `ddiff` was taken) and creates a GitHub release.

See [DEVELOPMENT_NOTES.md](DEVELOPMENT_NOTES.md) for how it works and what was learned building it.

MIT licence.
