ddiff-tui 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,144 @@
1
+ name: CI and Release
2
+
3
+ on:
4
+ pull_request:
5
+ push:
6
+ branches:
7
+ - "**"
8
+ workflow_dispatch:
9
+
10
+ jobs:
11
+ quality:
12
+ name: Test (${{ matrix.os }}, Python ${{ matrix.python }})
13
+ strategy:
14
+ fail-fast: false
15
+ matrix:
16
+ os: [ubuntu-latest]
17
+ python: ["3.11", "3.12", "3.13", "3.14"]
18
+ include:
19
+ - os: windows-latest
20
+ python: "3.14"
21
+ runs-on: ${{ matrix.os }}
22
+ steps:
23
+ - uses: actions/checkout@v4
24
+
25
+ - uses: astral-sh/setup-uv@v6
26
+
27
+ - name: Sync dependencies
28
+ run: uv sync --python ${{ matrix.python }} --group dev
29
+
30
+ # Lint and formatting don't depend on the platform or Python
31
+ - name: Ruff lint
32
+ if: runner.os == 'Linux' && matrix.python == '3.14'
33
+ run: uv run ruff check
34
+
35
+ - name: Ruff format check
36
+ if: runner.os == 'Linux' && matrix.python == '3.14'
37
+ run: uv run ruff format --check
38
+
39
+ - name: Test
40
+ run: uv run python -m pytest -q
41
+
42
+ install:
43
+ name: uv tool install (${{ matrix.os }})
44
+ strategy:
45
+ fail-fast: false
46
+ matrix:
47
+ os: [ubuntu-latest, windows-latest]
48
+ runs-on: ${{ matrix.os }}
49
+ defaults:
50
+ run:
51
+ shell: bash
52
+ steps:
53
+ - uses: actions/checkout@v4
54
+
55
+ - uses: astral-sh/setup-uv@v6
56
+
57
+ - name: Build the wheel
58
+ run: uv build --wheel --out-dir dist
59
+
60
+ # The way users install ddiff: an isolated tool environment, Python fetched by uv
61
+ - name: Install with uv tool install
62
+ run: uv tool install --python 3.14 dist/*.whl
63
+
64
+ - name: Put uv's tool commands on PATH
65
+ run: uv tool dir --bin >> "$GITHUB_PATH"
66
+
67
+ - name: Run the installed command
68
+ run: ddiff --version
69
+
70
+ - name: Smoke test the installed package
71
+ run: |
72
+ tool_dir="$(uv tool dir)/ddiff-tui"
73
+ if [[ "$RUNNER_OS" == "Windows" ]]; then
74
+ python="$tool_dir/Scripts/python.exe"
75
+ else
76
+ python="$tool_dir/bin/python"
77
+ fi
78
+ "$python" tests/smoke_installed.py
79
+
80
+ pypi:
81
+ name: Publish to PyPI
82
+ needs: [quality, install]
83
+ if: github.event_name == 'push' && github.ref == 'refs/heads/main'
84
+ runs-on: ubuntu-latest
85
+ permissions:
86
+ contents: write
87
+ id-token: write
88
+ steps:
89
+ - uses: actions/checkout@v4
90
+
91
+ - uses: actions/setup-python@v5
92
+ with:
93
+ python-version: "3.14"
94
+
95
+ - uses: astral-sh/setup-uv@v6
96
+
97
+ - name: Build package
98
+ run: uv build
99
+
100
+ - name: Check if version already exists on PyPI
101
+ id: version_check
102
+ run: |
103
+ python - <<'PY'
104
+ import json, os, pathlib, tomllib, urllib.error, urllib.request
105
+
106
+ pyproject = tomllib.loads(pathlib.Path("pyproject.toml").read_text())
107
+ name = pyproject["project"]["name"]
108
+ version = pyproject["project"]["version"]
109
+ exists = False
110
+
111
+ try:
112
+ with urllib.request.urlopen(f"https://pypi.org/pypi/{name}/json", timeout=15) as r:
113
+ releases = json.load(r).get("releases", {})
114
+ exists = version in releases and bool(releases.get(version))
115
+ except urllib.error.HTTPError as e:
116
+ if e.code != 404:
117
+ raise
118
+
119
+ with open(os.environ["GITHUB_OUTPUT"], "a", encoding="utf-8") as f:
120
+ f.write(f"package_name={name}\n")
121
+ f.write(f"package_version={version}\n")
122
+ f.write(f"version_exists={str(exists).lower()}\n")
123
+ PY
124
+
125
+ - name: Publish to PyPI (OIDC trusted publishing)
126
+ if: steps.version_check.outputs.version_exists != 'true'
127
+ run: uv publish --trusted-publishing always dist/*
128
+
129
+ - name: Create GitHub Release
130
+ if: steps.version_check.outputs.version_exists != 'true'
131
+ uses: softprops/action-gh-release@v2
132
+ with:
133
+ tag_name: v${{ steps.version_check.outputs.package_version }}
134
+ target_commitish: ${{ github.sha }}
135
+ name: v${{ steps.version_check.outputs.package_version }}
136
+ generate_release_notes: true
137
+ # Not dist/*: uv build also writes a .gitignore there
138
+ files: |
139
+ dist/*.whl
140
+ dist/*.tar.gz
141
+
142
+ - name: Report skipped publish
143
+ if: steps.version_check.outputs.version_exists == 'true'
144
+ run: echo "PyPI publish skipped — v${{ steps.version_check.outputs.package_version }} already exists."
@@ -0,0 +1,8 @@
1
+ .venv/
2
+ __pycache__/
3
+ *.pyc
4
+ .pytest_cache/
5
+ .ruff_cache/
6
+ dist/
7
+ demo/
8
+ examples/
@@ -0,0 +1,103 @@
1
+ # Development notes
2
+
3
+ How ddiff works, the decisions behind it, and the problems hit while building
4
+ it. Read this before making big changes.
5
+
6
+ ## Layout
7
+
8
+ | Path | What |
9
+ |---|---|
10
+ | `src/ddiff/engine.py` | The diff: reading, key choice, the join, views, stats, column detail, save, SQL script, value formatting. No Textual. |
11
+ | `src/ddiff/grid.py` | `Grid`, a virtual table (Line API `ScrollView`) after dx's `DataGrid`, over a generic `Source`. |
12
+ | `src/ddiff/views.py` | Grid sources for the Rows and Columns tabs, and the Rich summary (also printed by `--summary`). |
13
+ | `src/ddiff/screens.py` | Dialogs: row detail, column detail, SQL, prompts, help. |
14
+ | `src/ddiff/app.py` | The app, its keys and the CLI. |
15
+ | `tests/test_engine.py` | Engine and CLI tests. |
16
+ | `tests/test_tui.py` | App tests through Textual's pilot. |
17
+ | `tools/make_demo_data.py`, `tools/screenshots.py` | The 10 M row demo files and the README screenshots. |
18
+
19
+ ## How a diff runs
20
+
21
+ 1. Each file is loaded into `a_data` / `b_data` in a temporary **on-disk** DuckDB
22
+ database (`tempfile.mkdtemp`, removed on close), so diffs can be bigger than RAM.
23
+ `a` and `b` are views adding the file row number (`rowid + 1`) and any `--where`.
24
+ 2. **Key**: `--key`, or the first column unique in both files. Candidates are
25
+ non-float, non-nested, non-boolean shared columns, id-like names first. They
26
+ are pre-filtered with `approx_count_distinct` and then confirmed with an exact
27
+ `count(DISTINCT)`. With no key, rows are matched by position.
28
+ 3. **Join**: `a FULL OUTER JOIN b`. Keys use `IS NOT DISTINCT FROM`, so NULL keys
29
+ match, and are cast to text if their types differ. Duplicate keys get an
30
+ occurrence number (`row_number() OVER (PARTITION BY key ORDER BY row)`), so
31
+ the n-th copy pairs with the n-th copy.
32
+ 4. Only differing rows are stored, in `d`, with positional column names (`__a3`,
33
+ `__b3`, `__ne3`). These keep any user column name safe: quotes, `[/]`, `__rid`.
34
+ Unchanged rows are counted (`same = rows_a − removed − changed`), never stored.
35
+ 5. **Views** (filters and sorts) are new tables with a dense `__pos`. A block of
36
+ rows is `WHERE __pos BETWEEN …`, which DuckDB's zone maps make cheap at any depth.
37
+
38
+ ## Decisions
39
+
40
+ - **DuckDB does everything; pandas only reads Excel.** A diff is a join plus
41
+ aggregates, which is exactly what DuckDB is good at, and it spills to disk.
42
+ - **The grid takes a generic source.** dx's `DataGrid` is tied to a pandas
43
+ frame. ddiff's rows live in DuckDB, so `Grid` asks a `Source` for 64-row blocks
44
+ of cells. Each cell is a tuple of `(text, style)` parts, so `old → new` gets two
45
+ colours. If dx and ddiff share a library one day, this grid is the one to share.
46
+ - **Values are shown exactly.** Floats use `repr` (shortest round-trip), so
47
+ `0.1 + 0.2` doesn't look like `0.3`. NULL is `∅` and `""` is shown as `""`.
48
+ Changes that are invisible as text (`"b"` → `"b "`, `"1"` → `1`) are shown quoted.
49
+ - **Tolerance only applies to non-integer numbers**:
50
+ `|a − b| ≤ atol + rtol·|b|`, numpy's `isclose` rule. NULL is never close to a number.
51
+ - **Column stats use `approx_count_distinct`.** It is about 10% low at 10 M rows,
52
+ so the header says `≈distinct`, and differences under 3% aren't highlighted.
53
+ Exact counts for every column of a wide file would take too long.
54
+ - **Exit codes follow `diff`**: 0 same, 1 different (including schema-only
55
+ differences), 2 trouble.
56
+
57
+ ## Problems hit
58
+
59
+ - **`row_number() OVER ()` serialises the read.** On 10 M rows it took 7.2 s per
60
+ file on disk, against 1.6 s for a plain parallel `CREATE TABLE AS`. With
61
+ `preserve_insertion_order` (the default), the table's `rowid` is the file row,
62
+ so `a` is a view over `a_data` adding `rowid + 1`. CSV went from 25 s to 9 s
63
+ and parquet from 16 s to 6 s. Parquet's `file_row_number` was as fast, but
64
+ only works for parquet.
65
+ - **`approx_count_distinct` undercounts by about 10%** (9.0 M for 10 M unique
66
+ ids). A 0.95 cut-off rejected the real key, and `ts` was chosen instead. The
67
+ pre-filter is now 0.75, and the exact count decides.
68
+ - **Textual name clashes.** `App._ready` and `Screen._render` are Textual
69
+ internals. Defining them breaks startup in confusing ways. A widget id
70
+ shared by a `TabPane` and a widget inside it (`#summary`) fails too. Tab panes
71
+ are `tab-*`.
72
+ - **`TabbedContent` follows focus** (as in dx). When a modal closes, the main
73
+ screen re-focuses the widget that had focus, which pulls its tab back to the
74
+ front. The order of that and the dialog's callback depends on timing:
75
+ `call_after_refresh` alone failed 17 times in 20 on one CPU core
76
+ (`taskset -c 0`), and on CI's Python 3.11 runner. `_after_dialog` sets the
77
+ *main screen's* focus to the new tab's widget first, so the refocus lands
78
+ there. Test focus changes under `taskset -c 0`.
79
+ - **Keys pressed while a view is building.** A filter or sort pressed mid-build
80
+ used to change the state but never re-run the query, so the screen and status
81
+ bar disagreed. Now they set `_pending`, and the view is rebuilt when the
82
+ current build finishes.
83
+ - **The `UNION ALL` in the demo generator widened `qty` to DOUBLE**, which looked
84
+ like a real type change. Cast both sides explicitly when making test data.
85
+ - **duckdb 2.x wheels need AVX2**, so `duckdb<2` is pinned, as in dx.
86
+
87
+ ## Testing
88
+
89
+ - `tests/test_tui.py` drives the app headlessly. `settle()` waits for `app.busy`
90
+ and all workers. The diff worker keeps running for the column stats after
91
+ the diff is ready.
92
+ - Render every visible line (`render_all`) after layout changes. Width and
93
+ styling bugs only show up in `render_line`.
94
+ - To check the look, `app.save_screenshot()` gives an SVG, and headless Chrome
95
+ turns it into a PNG (`tools/screenshots.py`).
96
+
97
+ ## Ideas not done yet
98
+
99
+ - HDF5 input (dx has a safe h5py reader to borrow).
100
+ - Per-side `--where-old` / `--where-new`, and `--key-old` / `--key-new` for renamed keys.
101
+ - Matching renamed columns (same values, different names).
102
+ - Comparing a folder of files, or two SQL queries / database tables.
103
+ - GIFs like dx's (`export_screenshot` → Playwright → Pillow).
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 jimhendy
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,173 @@
1
+ Metadata-Version: 2.5
2
+ Name: ddiff-tui
3
+ Version: 0.1.0
4
+ Summary: ddiff: see what changed between two data files (parquet, CSV, JSON, Excel) of any size, in your terminal
5
+ Project-URL: Homepage, https://github.com/jimhendy/ddiff
6
+ Project-URL: Issues, https://github.com/jimhendy/ddiff/issues
7
+ Author: jimhendy
8
+ License-Expression: MIT
9
+ License-File: LICENSE
10
+ Keywords: csv,data,diff,duckdb,parquet,terminal,textual,tui
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Environment :: Console :: Curses
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Intended Audience :: Science/Research
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Topic :: Scientific/Engineering :: Information Analysis
17
+ Classifier: Topic :: Utilities
18
+ Requires-Python: >=3.11
19
+ Requires-Dist: duckdb<2,>=1.1
20
+ Requires-Dist: openpyxl
21
+ Requires-Dist: pandas>=2.2
22
+ Requires-Dist: pyarrow>=15
23
+ Requires-Dist: textual>=8.0
24
+ Description-Content-Type: text/markdown
25
+
26
+ <div align="center">
27
+
28
+ # ddiff
29
+
30
+ **See what changed between two data files. Ten million rows in six seconds.**
31
+
32
+ parquet · CSV · TSV · JSON · JSON lines · Excel · Arrow, compared with [DuckDB](https://duckdb.org), shown with [Textual](https://textual.textualize.io)
33
+
34
+ [![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)
35
+ [![PyPI](https://img.shields.io/pypi/v/ddiff-tui)](https://pypi.org/project/ddiff-tui/)
36
+ ![python](https://img.shields.io/badge/python-3.11%20%E2%80%93%203.14-3776ab)
37
+ ![license](https://img.shields.io/badge/license-MIT-green)
38
+
39
+ <img src="assets/rows.png" alt="ddiff showing the rows of a 10 million row diff, sorted by the biggest price change" width="100%">
40
+
41
+ </div>
42
+
43
+ ```bash
44
+ uv tool install ddiff-tui # or: pipx install ddiff-tui
45
+ ddiff old.parquet new.parquet
46
+ ```
47
+
48
+ ## Why ddiff?
49
+
50
+ The pipeline changed, the vendor re-sent the file, someone "only refactored" a
51
+ query. Is the output the same? `diff` is useless on parquet and drowns on CSV.
52
+ Usually it ends in a notebook with `pd.merge(..., indicator=True)`, running out
53
+ of memory.
54
+
55
+ `ddiff old new` tells you straight away:
56
+
57
+ - **Which rows were added, removed or changed**, matched on a key. ddiff finds a
58
+ key for you (a column unique in both files, preferring id-like names) or you
59
+ pass `--key`. Rows can be in any order. With no key it compares row by row.
60
+ - **Which columns changed and how much**: columns added and removed, type
61
+ changes, the number of changed cells in each column, and how each column's
62
+ nulls, distinct values, min, max and mean moved.
63
+ - **Every changed cell as `old → new`**, filtered to one column, sorted by the
64
+ size of the change, and with any row's fields shown old beside new.
65
+ - **Files bigger than RAM.** DuckDB reads both files into a temporary on-disk
66
+ database and does the join. Only the rows that differ are stored, and the
67
+ table pages them in 64 rows at a time.
68
+ - **Scripts and CI too**: `--summary` or `--json` print the result, and the exit
69
+ code is 0 when the files match, 1 when they differ and 2 on an error, like
70
+ `diff`. `-o diff.parquet` saves the differences.
71
+ - **The SQL is yours**: `S` shows the DuckDB SQL behind the diff, ready to run.
72
+
73
+ ## How fast?
74
+
75
+ Two 10,000,000-row trade files (180 MB and 230 MB of parquet; 1% of prices
76
+ nudged, 0.2% of venues changed, 9,890 rows deleted, 20,000 added, a column
77
+ dropped and one added), on a 2017 laptop (i7-7700HQ, 4 cores):
78
+
79
+ | | |
80
+ |---|---|
81
+ | Diff two parquet files, choosing the key itself | **6.0 s** (1.4 GB RAM) |
82
+ | The same data as CSV (630 MB each) | **9.2 s** |
83
+ | Scroll, page, jump to the last of 149,229 differing rows | instant (3 ms a block) |
84
+ | Sort the differences by the size of the price change | **0.02 s** |
85
+ | Show only the rows where price changed | **0.02 s** |
86
+ | Per-column stats for both files | **1 s** (in the background) |
87
+
88
+ Make the same files with `uv run python tools/make_demo_data.py` and try it.
89
+
90
+ ## Summary
91
+
92
+ <img src="assets/summary.png" alt="the Summary tab: files, rows matched, added, removed, changed, column changes" width="100%">
93
+
94
+ Both files, how rows were matched, how many were unchanged, changed, added and
95
+ removed, which columns came and went, and which columns' values changed most.
96
+ `ddiff old new --summary` prints the same thing in your terminal.
97
+
98
+ ## Columns
99
+
100
+ <img src="assets/columns.png" alt="the Columns tab: one row per column with changed cells and stats on both sides" width="100%">
101
+
102
+ One row per column: whether it's the key, added, removed or changed, its type on
103
+ both sides, the share of rows whose value changed, and nulls, distinct values,
104
+ mean, min and max for the old and new file. A stat that moved is highlighted.
105
+ Type to filter by name and `s` to sort. `Enter` or `c` opens the column:
106
+
107
+ <img src="assets/column.png" alt="column details: stats, size of the changes, commonest old to new changes" width="100%">
108
+
109
+ The commonest `old → new` changes, the size of the numeric changes (new − old),
110
+ and the distribution of values in both files. `f` shows the rows where it changed.
111
+
112
+ ## Rows
113
+
114
+ Every differing row, with the key pinned at the left. A changed value shows as
115
+ `old → new`, and new rows are green and removed ones red. Columns with no
116
+ changes are hidden until you press `u`.
117
+
118
+ - `+` `-` `~` (or `a` `r` `m`) show or hide added, removed and modified rows
119
+ - `f` shows only the rows where the cursor's column changed
120
+ - `s` sorts by a column, `d` by the size of the change, biggest first
121
+ - `Enter` shows the row with every field old beside new; `↑` `↓` step through rows
122
+ - `w` saves the rows on show, `D` opens them in [dx](https://github.com/jimhendy/dx)
123
+
124
+ ## Options
125
+
126
+ ```bash
127
+ ddiff old.parquet new.parquet # explore
128
+ ddiff old.csv new.csv -k id # match rows on id
129
+ ddiff a.parquet b.parquet -k date,ticker # a key of two columns
130
+ ddiff a.xlsx::Sheet1 b.xlsx::Sheet1 # Excel sheets
131
+ ddiff a.parquet b.parquet --atol 1e-9 # numbers this close are equal (also --rtol)
132
+ ddiff a.parquet b.parquet -w "region = 'EU'" # an SQL filter on both files
133
+ ddiff a.parquet b.parquet -c price,qty # compare only these columns
134
+ ddiff a.parquet b.parquet -i updated_at # ignore these columns
135
+ ddiff a.parquet b.parquet --summary # print; exit 0 same, 1 different, 2 error
136
+ ddiff a.parquet b.parquet --json # the summary as JSON
137
+ ddiff a.parquet b.parquet -o diff.parquet # save the differing rows and exit
138
+ ```
139
+
140
+ Duplicate keys are matched in file order: the second `id = 7` in the old file
141
+ pairs with the second `id = 7` in the new one. Numbers compare across integer and
142
+ float types. Other type changes compare as text and are listed in the summary.
143
+ NULL is shown as `∅`, `""` is an empty string, and values that differ only in
144
+ whitespace are shown quoted so you can see the difference.
145
+
146
+ ## Keys
147
+
148
+ | Key | |
149
+ |---|---|
150
+ | `1` `2` `3` | Summary · Columns · Rows |
151
+ | arrows / `hjkl` · `PgUp` `PgDn` · `g` `G` · `Home` `End` | move · page · top / bottom · first / last column |
152
+ | `Enter` · `c` | row old beside new (Rows) or column details (Columns) · column details |
153
+ | `s` · `d` | sort: ascending → descending → off · by size of change |
154
+ | `f` · `+` `-` `~` · `u` · `x` | only this column's changes · added / removed / modified · unchanged columns · clear |
155
+ | `/` · `<` `>` | find a column · narrower / wider |
156
+ | `w` · `D` · `S` | save · open in dx · the SQL |
157
+ | `?` · `ctrl+p` · `q` | all keys · command palette and themes · quit |
158
+
159
+ ## Development
160
+
161
+ ```bash
162
+ just sync # install dev dependencies
163
+ just ci # lint, format check and tests, as in CI
164
+ just examples # example file pairs to play with (see examples/README.md)
165
+ just shots # README screenshots (makes the 10 M row demo files first)
166
+ ```
167
+
168
+ Pushing to `main` with a new version in `pyproject.toml` publishes it to PyPI
169
+ (as `ddiff-tui`; plain `ddiff` was taken) and creates a GitHub release.
170
+
171
+ See [DEVELOPMENT_NOTES.md](DEVELOPMENT_NOTES.md) for how it works and what was learned building it.
172
+
173
+ MIT licence.
@@ -0,0 +1,148 @@
1
+ <div align="center">
2
+
3
+ # ddiff
4
+
5
+ **See what changed between two data files. Ten million rows in six seconds.**
6
+
7
+ parquet · CSV · TSV · JSON · JSON lines · Excel · Arrow, compared with [DuckDB](https://duckdb.org), shown with [Textual](https://textual.textualize.io)
8
+
9
+ [![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)
10
+ [![PyPI](https://img.shields.io/pypi/v/ddiff-tui)](https://pypi.org/project/ddiff-tui/)
11
+ ![python](https://img.shields.io/badge/python-3.11%20%E2%80%93%203.14-3776ab)
12
+ ![license](https://img.shields.io/badge/license-MIT-green)
13
+
14
+ <img src="assets/rows.png" alt="ddiff showing the rows of a 10 million row diff, sorted by the biggest price change" width="100%">
15
+
16
+ </div>
17
+
18
+ ```bash
19
+ uv tool install ddiff-tui # or: pipx install ddiff-tui
20
+ ddiff old.parquet new.parquet
21
+ ```
22
+
23
+ ## Why ddiff?
24
+
25
+ The pipeline changed, the vendor re-sent the file, someone "only refactored" a
26
+ query. Is the output the same? `diff` is useless on parquet and drowns on CSV.
27
+ Usually it ends in a notebook with `pd.merge(..., indicator=True)`, running out
28
+ of memory.
29
+
30
+ `ddiff old new` tells you straight away:
31
+
32
+ - **Which rows were added, removed or changed**, matched on a key. ddiff finds a
33
+ key for you (a column unique in both files, preferring id-like names) or you
34
+ pass `--key`. Rows can be in any order. With no key it compares row by row.
35
+ - **Which columns changed and how much**: columns added and removed, type
36
+ changes, the number of changed cells in each column, and how each column's
37
+ nulls, distinct values, min, max and mean moved.
38
+ - **Every changed cell as `old → new`**, filtered to one column, sorted by the
39
+ size of the change, and with any row's fields shown old beside new.
40
+ - **Files bigger than RAM.** DuckDB reads both files into a temporary on-disk
41
+ database and does the join. Only the rows that differ are stored, and the
42
+ table pages them in 64 rows at a time.
43
+ - **Scripts and CI too**: `--summary` or `--json` print the result, and the exit
44
+ code is 0 when the files match, 1 when they differ and 2 on an error, like
45
+ `diff`. `-o diff.parquet` saves the differences.
46
+ - **The SQL is yours**: `S` shows the DuckDB SQL behind the diff, ready to run.
47
+
48
+ ## How fast?
49
+
50
+ Two 10,000,000-row trade files (180 MB and 230 MB of parquet; 1% of prices
51
+ nudged, 0.2% of venues changed, 9,890 rows deleted, 20,000 added, a column
52
+ dropped and one added), on a 2017 laptop (i7-7700HQ, 4 cores):
53
+
54
+ | | |
55
+ |---|---|
56
+ | Diff two parquet files, choosing the key itself | **6.0 s** (1.4 GB RAM) |
57
+ | The same data as CSV (630 MB each) | **9.2 s** |
58
+ | Scroll, page, jump to the last of 149,229 differing rows | instant (3 ms a block) |
59
+ | Sort the differences by the size of the price change | **0.02 s** |
60
+ | Show only the rows where price changed | **0.02 s** |
61
+ | Per-column stats for both files | **1 s** (in the background) |
62
+
63
+ Make the same files with `uv run python tools/make_demo_data.py` and try it.
64
+
65
+ ## Summary
66
+
67
+ <img src="assets/summary.png" alt="the Summary tab: files, rows matched, added, removed, changed, column changes" width="100%">
68
+
69
+ Both files, how rows were matched, how many were unchanged, changed, added and
70
+ removed, which columns came and went, and which columns' values changed most.
71
+ `ddiff old new --summary` prints the same thing in your terminal.
72
+
73
+ ## Columns
74
+
75
+ <img src="assets/columns.png" alt="the Columns tab: one row per column with changed cells and stats on both sides" width="100%">
76
+
77
+ One row per column: whether it's the key, added, removed or changed, its type on
78
+ both sides, the share of rows whose value changed, and nulls, distinct values,
79
+ mean, min and max for the old and new file. A stat that moved is highlighted.
80
+ Type to filter by name and `s` to sort. `Enter` or `c` opens the column:
81
+
82
+ <img src="assets/column.png" alt="column details: stats, size of the changes, commonest old to new changes" width="100%">
83
+
84
+ The commonest `old → new` changes, the size of the numeric changes (new − old),
85
+ and the distribution of values in both files. `f` shows the rows where it changed.
86
+
87
+ ## Rows
88
+
89
+ Every differing row, with the key pinned at the left. A changed value shows as
90
+ `old → new`, and new rows are green and removed ones red. Columns with no
91
+ changes are hidden until you press `u`.
92
+
93
+ - `+` `-` `~` (or `a` `r` `m`) show or hide added, removed and modified rows
94
+ - `f` shows only the rows where the cursor's column changed
95
+ - `s` sorts by a column, `d` by the size of the change, biggest first
96
+ - `Enter` shows the row with every field old beside new; `↑` `↓` step through rows
97
+ - `w` saves the rows on show, `D` opens them in [dx](https://github.com/jimhendy/dx)
98
+
99
+ ## Options
100
+
101
+ ```bash
102
+ ddiff old.parquet new.parquet # explore
103
+ ddiff old.csv new.csv -k id # match rows on id
104
+ ddiff a.parquet b.parquet -k date,ticker # a key of two columns
105
+ ddiff a.xlsx::Sheet1 b.xlsx::Sheet1 # Excel sheets
106
+ ddiff a.parquet b.parquet --atol 1e-9 # numbers this close are equal (also --rtol)
107
+ ddiff a.parquet b.parquet -w "region = 'EU'" # an SQL filter on both files
108
+ ddiff a.parquet b.parquet -c price,qty # compare only these columns
109
+ ddiff a.parquet b.parquet -i updated_at # ignore these columns
110
+ ddiff a.parquet b.parquet --summary # print; exit 0 same, 1 different, 2 error
111
+ ddiff a.parquet b.parquet --json # the summary as JSON
112
+ ddiff a.parquet b.parquet -o diff.parquet # save the differing rows and exit
113
+ ```
114
+
115
+ Duplicate keys are matched in file order: the second `id = 7` in the old file
116
+ pairs with the second `id = 7` in the new one. Numbers compare across integer and
117
+ float types. Other type changes compare as text and are listed in the summary.
118
+ NULL is shown as `∅`, `""` is an empty string, and values that differ only in
119
+ whitespace are shown quoted so you can see the difference.
120
+
121
+ ## Keys
122
+
123
+ | Key | |
124
+ |---|---|
125
+ | `1` `2` `3` | Summary · Columns · Rows |
126
+ | arrows / `hjkl` · `PgUp` `PgDn` · `g` `G` · `Home` `End` | move · page · top / bottom · first / last column |
127
+ | `Enter` · `c` | row old beside new (Rows) or column details (Columns) · column details |
128
+ | `s` · `d` | sort: ascending → descending → off · by size of change |
129
+ | `f` · `+` `-` `~` · `u` · `x` | only this column's changes · added / removed / modified · unchanged columns · clear |
130
+ | `/` · `<` `>` | find a column · narrower / wider |
131
+ | `w` · `D` · `S` | save · open in dx · the SQL |
132
+ | `?` · `ctrl+p` · `q` | all keys · command palette and themes · quit |
133
+
134
+ ## Development
135
+
136
+ ```bash
137
+ just sync # install dev dependencies
138
+ just ci # lint, format check and tests, as in CI
139
+ just examples # example file pairs to play with (see examples/README.md)
140
+ just shots # README screenshots (makes the 10 M row demo files first)
141
+ ```
142
+
143
+ Pushing to `main` with a new version in `pyproject.toml` publishes it to PyPI
144
+ (as `ddiff-tui`; plain `ddiff` was taken) and creates a GitHub release.
145
+
146
+ See [DEVELOPMENT_NOTES.md](DEVELOPMENT_NOTES.md) for how it works and what was learned building it.
147
+
148
+ MIT licence.
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,44 @@
1
+ set shell := ["bash", "-uc"]
2
+
3
+ default:
4
+ just --list
5
+
6
+ # Install/sync dev dependencies
7
+ sync:
8
+ uv sync --group dev
9
+
10
+ # Lint (matches CI)
11
+ lint:
12
+ uv run ruff check
13
+
14
+ # Format check (matches CI)
15
+ format-check:
16
+ uv run ruff format --check
17
+
18
+ # Auto-fix lint issues and format
19
+ fix:
20
+ uv run ruff check --fix
21
+ uv run ruff format
22
+
23
+ # Run the tests. Extra args are passed through, e.g. `just test -k tolerance`
24
+ test *args:
25
+ uv run python -m pytest -q {{args}}
26
+
27
+ # Everything CI runs
28
+ ci: sync lint format-check test
29
+
30
+ # The 10 M row demo files, in demo/
31
+ demo rows="10000000":
32
+ uv run python tools/make_demo_data.py {{rows}} demo
33
+
34
+ # Time the demo diff
35
+ bench: demo
36
+ uv run ddiff demo/old.parquet demo/new.parquet --summary || true
37
+
38
+ # README screenshots (needs Chrome)
39
+ shots: demo
40
+ uv run python tools/screenshots.py demo assets
41
+
42
+ # Small example file pairs, each showing a feature (see examples/README.md)
43
+ examples:
44
+ uv run python tools/make_examples.py examples