csvhonest 0.1.4__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.
Files changed (36) hide show
  1. csvhonest-0.1.4/LICENSE +21 -0
  2. csvhonest-0.1.4/MANIFEST.in +1 -0
  3. csvhonest-0.1.4/PKG-INFO +269 -0
  4. csvhonest-0.1.4/README.md +247 -0
  5. csvhonest-0.1.4/examples/import-surprises.csv +4 -0
  6. csvhonest-0.1.4/pyproject.toml +36 -0
  7. csvhonest-0.1.4/setup.cfg +4 -0
  8. csvhonest-0.1.4/src/csvhonest/__init__.py +15 -0
  9. csvhonest-0.1.4/src/csvhonest/__main__.py +5 -0
  10. csvhonest-0.1.4/src/csvhonest/cli.py +126 -0
  11. csvhonest-0.1.4/src/csvhonest/dialect.py +150 -0
  12. csvhonest-0.1.4/src/csvhonest/duckdb_verify.py +71 -0
  13. csvhonest-0.1.4/src/csvhonest/profiles.py +88 -0
  14. csvhonest-0.1.4/src/csvhonest/report.py +218 -0
  15. csvhonest-0.1.4/src/csvhonest/rules.py +712 -0
  16. csvhonest-0.1.4/src/csvhonest/scan.py +323 -0
  17. csvhonest-0.1.4/src/csvhonest/snapshot.py +25 -0
  18. csvhonest-0.1.4/src/csvhonest/verify.py +318 -0
  19. csvhonest-0.1.4/src/csvhonest.egg-info/PKG-INFO +269 -0
  20. csvhonest-0.1.4/src/csvhonest.egg-info/SOURCES.txt +34 -0
  21. csvhonest-0.1.4/src/csvhonest.egg-info/dependency_links.txt +1 -0
  22. csvhonest-0.1.4/src/csvhonest.egg-info/entry_points.txt +2 -0
  23. csvhonest-0.1.4/src/csvhonest.egg-info/requires.txt +3 -0
  24. csvhonest-0.1.4/src/csvhonest.egg-info/top_level.txt +1 -0
  25. csvhonest-0.1.4/tests/test_blank_alignment.py +147 -0
  26. csvhonest-0.1.4/tests/test_dialect.py +47 -0
  27. csvhonest-0.1.4/tests/test_duckdb_verify.py +156 -0
  28. csvhonest-0.1.4/tests/test_handoff.py +184 -0
  29. csvhonest-0.1.4/tests/test_loader_claims.py +146 -0
  30. csvhonest-0.1.4/tests/test_numeric_spelling.py +90 -0
  31. csvhonest-0.1.4/tests/test_readme_demo.py +20 -0
  32. csvhonest-0.1.4/tests/test_review_regressions.py +195 -0
  33. csvhonest-0.1.4/tests/test_rules.py +176 -0
  34. csvhonest-0.1.4/tests/test_scan_and_cli.py +128 -0
  35. csvhonest-0.1.4/tests/test_snapshot.py +109 -0
  36. csvhonest-0.1.4/tests/test_verify.py +92 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Anish Pentyala
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 @@
1
+ include examples/import-surprises.csv
@@ -0,0 +1,269 @@
1
+ Metadata-Version: 2.4
2
+ Name: csvhonest
3
+ Version: 0.1.4
4
+ Summary: Audit what your CSV loader will silently change before you load it.
5
+ Author: Anish Pentyala
6
+ License: MIT
7
+ Keywords: csv,pandas,polars,data-quality,etl,data-loss
8
+ Classifier: Development Status :: 3 - Alpha
9
+ Classifier: Environment :: Console
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: Intended Audience :: Science/Research
12
+ Classifier: License :: OSI Approved :: MIT License
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Topic :: Scientific/Engineering :: Information Analysis
15
+ Classifier: Topic :: Utilities
16
+ Requires-Python: >=3.9
17
+ Description-Content-Type: text/markdown
18
+ License-File: LICENSE
19
+ Provides-Extra: dev
20
+ Requires-Dist: pytest>=7; extra == "dev"
21
+ Dynamic: license-file
22
+
23
+ # csvhonest
24
+
25
+ **Audit what your CSV loader will silently change - before you load it.**
26
+
27
+ A CSV can look right in a text editor and change when pandas reads it. Catch lost ZIP-code zeros, a literal `NA` becoming missing, or an ID rounding before those values reach your analysis.
28
+
29
+ ## Try it in 60 seconds
30
+
31
+ Install the versioned source release (Python 3.9+, Git required):
32
+
33
+ ```sh
34
+ python -m pip install "git+https://github.com/anishpentyala/csvhonest.git@v0.1.4"
35
+ ```
36
+
37
+ Create this **synthetic** sample as `surprises.csv`:
38
+
39
+ ```csv
40
+ zip,country,customer_id
41
+ 02139,NA,9007199254740993
42
+ 00501,US,
43
+ 10001,GB,42
44
+ ```
45
+
46
+ Then run:
47
+
48
+ ```sh
49
+ csvhonest surprises.csv
50
+ ```
51
+
52
+ The report flags three high-severity risks: `LEADING_ZERO_LOSS`, `NA_COLLISION`, and `FLOAT64_PRECISION_LOSS`. It exits **1 because it found risks**, not because installation failed. The same input is bundled as [`examples/import-surprises.csv`](examples/import-surprises.csv).
53
+
54
+ Want to see what actually changes? Install pandas and verify this file with its default reader:
55
+
56
+ ```sh
57
+ python -m pip install "pandas==2.3.3"
58
+ csvhonest surprises.csv --verify pandas
59
+ ```
60
+
61
+ The verification reports four changed cells:
62
+
63
+ | Raw CSV text | pandas 2.3.3 default load | Why it matters |
64
+ | --- | --- | --- |
65
+ | `02139` | `2139` | ZIP-code zeros disappear |
66
+ | `00501` | `501` | Another ZIP code changes form |
67
+ | `NA` | missing | A literal country code is lost |
68
+ | `9007199254740993` | `9007199254740992` | An ID changes value after float conversion |
69
+
70
+ These are results from this tiny synthetic file, not a user benchmark. The missing ID makes pandas infer a floating-point column. Static scanning reports risks; `--verify pandas` loads and compares the actual file using the pandas version installed in your environment. Other inputs, loader versions and options can behave differently. Verification uses temporary local disk, as described below.
71
+
72
+ ## When to use it
73
+
74
+ Use csvhonest before loading unfamiliar CSV exports, or in a pipeline that should stop on a risky import. It runs locally and the static scan needs only Python's standard library. Optional verification needs the loader being checked.
75
+
76
+ If you already know the schema, **explicit loader options are the first fix**, not another tool. For this sample, preserving every cell as text is as simple as:
77
+
78
+ ```python
79
+ import pandas as pd
80
+
81
+ frame = pd.read_csv("surprises.csv", dtype=str, keep_default_na=False)
82
+ ```
83
+
84
+ That is appropriate here because ZIP codes, country codes and customer IDs are text. It is not a universal loading policy: real numeric columns and missing values need a deliberate schema. csvhonest helps identify where to make that choice; it does not decide the intended meaning of your data.
85
+
86
+ ## Install options
87
+
88
+ The pinned Git command above installs source without a manual clone. There is no PyPI release under the name `csvhonest`.
89
+
90
+ From a source checkout:
91
+
92
+ ```sh
93
+ git clone https://github.com/anishpentyala/csvhonest.git
94
+ cd csvhonest
95
+ python -m pip install .
96
+ csvhonest examples/import-surprises.csv
97
+ ```
98
+
99
+ Building needs setuptools >= 68. If an older pip cannot build the package, update pip in your virtual environment first. No pandas or Polars dependency is required for a static scan.
100
+
101
+ ## Use
102
+
103
+ ```
104
+ csvhonest data.csv # human report
105
+ csvhonest data.csv --format json # machine report for CI
106
+ csvhonest data.csv --verify both # also run pandas+polars and diff raw vs loaded
107
+ csvhonest a.csv b.csv --fail-on medium
108
+ csvhonest data.csv --no-header # force first row to be data
109
+ ```
110
+
111
+ `--verify pandas` (or `polars`, `both`) goes beyond static analysis: it
112
+ loads the file with the installed loader's defaults and reports the cells
113
+ that actually changed, per distinct raw value (`'02139' -> 2139`,
114
+ `'NA' -> <missing>`), plus the dtype each column landed on.
115
+
116
+ Numeric verification compares the exact source decimal spelling to the displayed
117
+ loaded number. A lost digit or nonzero value underflowing to zero is a
118
+ `value_changed`, even when the source uses a decimal point or exponent.
119
+ `1e2 -> 100` remains `form_changed`; ordinary `0.1` is not flagged for the
120
+ binary float's internal expansion. This is a comparison of displayed numeric
121
+ values, not a bit-exact floating-point audit or a guarantee for every loader.
122
+
123
+ Exit code is 1 when a finding at or above `--fail-on` (default `high`)
124
+ exists, so the check slots into a pipeline or pre-commit step.
125
+ A requested verification that cannot load the file, read its raw comparison,
126
+ or establish matching row/column shapes exits **2**, even if the static scan
127
+ found no high-severity risks. It returns a verification error with no cell
128
+ mutation claims, rather than comparing a potentially shifted prefix.
129
+
130
+ Pandas verification skips unquoted ASCII space/tab-only physical lines at CSV
131
+ record boundaries, including before the header. Quoted whitespace, embedded
132
+ blank lines inside a multiline quoted cell, and space/tab delimiters remain
133
+ data. Polars keeps its existing blank-record policy. This behavior was checked
134
+ with pandas 2.3.3 and polars 2.0.0; it does not certify every future loader
135
+ version or unusual parser configuration. Verification still uses each loader's
136
+ normal header interpretation, even when the static scanner was told
137
+ `--no-header`. With `--verify`, the CLI first copies the full input into a private temporary
138
+ directory. Static scanning and both loaders then use that capture; a rewrite or
139
+ deletion of the original after capture cannot fabricate mutation evidence.
140
+ The Python `verify_with_pandas` / `verify_with_polars` functions each capture
141
+ their input before loading and comparing. They do not retroactively make an
142
+ earlier independent `scan_file()` call part of that capture.
143
+
144
+ Capturing is a streaming disk copy, not a filesystem transaction: a writer can
145
+ still change bytes while the copy is in progress. All comparisons describe the
146
+ captured bytes, not a guaranteed point-in-time version of a concurrently written
147
+ file. Verification copies the complete input even with `--max-rows`; temporary
148
+ disk space can reach twice its size because a CLI capture and one verifier
149
+ capture coexist. Files are removed on success or failure. Without `--verify`,
150
+ static scanning keeps its existing streaming path. Matching shapes still cannot
151
+ detect every possible parser disagreement.
152
+
153
+
154
+ From Python:
155
+
156
+ ```python
157
+ from csvhonest import scan_file
158
+
159
+ result = scan_file("orders.csv")
160
+ for finding in result.findings:
161
+ print(finding.severity, finding.code, finding.message)
162
+ ```
163
+
164
+ ## Optional DuckDB verification
165
+
166
+ ```sh
167
+ python -m pip install "duckdb==1.5.6"
168
+ csvhonest data.csv --verify duckdb
169
+ ```
170
+
171
+ `--verify duckdb` compares raw cells with the installed DuckDB default CSV
172
+ reader in a temporary in-memory database. DuckDB is optional and is imported
173
+ only when selected. `--verify both` still means pandas plus Polars. Static-risk
174
+ profiles remain pandas and Polars; this release adds no DuckDB static profile.
175
+
176
+ Tested DuckDB versions: **1.3.2, 1.4.4, and 1.5.6**. Other versions are unverified;
177
+ this is not a minimum-version or all-versions compatibility claim. Synthetic
178
+ late-sample tests cover decimal rounding, lost zeros, small values becoming
179
+ zero, and timestamps becoming dates. These are reproduction tests, not user
180
+ trials or adoption results. DuckDB preserves the leading zeros and literal
181
+ `NA` in the small pandas example above; do not apply its pandas results to DuckDB.
182
+
183
+ Scope is deliberately narrow: UTF-8 (including BOM), a detected header,
184
+ a one-character delimiter, no skipped preamble or comments, and conventional
185
+ quoting. Unsupported encodings or layouts produce a verification error rather
186
+ than cell claims. This is not a custom SQL, user-schema, or post-ingest verifier.
187
+ DuckDB may infer a different table shape, including treating a ragged comma
188
+ file as a single text column. No mutations does not certify the intended schema.
189
+ Duplicate-header column names are DuckDB's renamed names, not the raw headers.
190
+
191
+ The adapter copies the complete captured input to a fixed temporary filename
192
+ so glob characters in the original name are literal. The CLI capture and this
193
+ adapter copy can coexist, requiring roughly **twice the full file size** in
194
+ temporary disk space. Copies are removed on success or failure. `--max-rows`
195
+ limits compared/fetched rows, not capture size or DuckDB's default sniffing
196
+ work. A capped comparison cannot find mutations beyond its prefix. No memory,
197
+ throughput, whole-file safety, or concurrent-writer transaction guarantee is made.
198
+
199
+ ## What it checks
200
+
201
+ | Code | Severity | What silently happens |
202
+ | --- | --- | --- |
203
+ | `LEADING_ZERO_LOSS` | high | `02139` loads as `2139` when the column infers numeric (pandas, polars) |
204
+ | `PADDED_LEADING_ZERO_LOSS` | high | whitespace-padded numbers with leading zeros: pandas trims and parses them, losing zeros and padding; polars keeps the original strings |
205
+ | `NA_COLLISION` | high | `"NA"`, `"None"`, `"null"` become NaN (pandas defaults) |
206
+ | `INT64_OVERFLOW` | high | pandas switches to uint64, or text (object in pandas 2, str in pandas 3) when signs mix; polars 2.x to Int128 (1.x raises) |
207
+ | `FLOAT64_PRECISION_LOSS` | high | integers above 2^53 lose exactness under float64: mixed int/float columns (pandas, polars) or int columns with holes (pandas) |
208
+ | `WHITESPACE_KEY_COLLISION` | high | `"WA"` and `"WA "` merge on any strip, collapsing distinct records |
209
+ | `UNICODE_FORM_COLLISION` | high | visually identical strings in different normal forms load as separate keys |
210
+ | `DUPLICATE_HEADERS` | high | pandas renames `a, a.1`; polars renames `a, a_duplicated_0` |
211
+ | `RAGGED_ROWS` | high | short rows are silently padded with missing values (pandas NaN, polars null); long rows make both loaders raise |
212
+ | `INVALID_ENCODING_BYTES` | medium | byte sequences invalid for the detected encoding; loaders reject or mangle them |
213
+ | `SCI_NOTATION_FORM_LOSS` | medium | `"1E2"` becomes `100.0`; IDs that look like E-notation change value |
214
+ | `THOUSANDS_SEPARATOR` | medium | `"1,234"` blocks numeric inference; column stays text |
215
+ | `AMBIGUOUS_DATE` | medium | `01/02/03` parses day-first or month-first depending on the tool |
216
+ | `CURRENCY_OR_PERCENT` | medium | `"$5.00"`, `"5%"` load as text; naive casts misread them |
217
+ | `INVISIBLE_CHARACTERS` | medium | no-break spaces and zero-width characters break equality and joins |
218
+ | `FOOTER_ROWS` | medium | `Total`/`Source:` rows inside numeric columns |
219
+ | `NON_UTF8_ENCODING` | medium | cp1252 export that UTF-8-assuming tools reject or mangle |
220
+ | `INT_BECOMES_FLOAT64` | low | all-integer column with missing cells loads as float64 (pandas) |
221
+ | `BOOL_COERCION` | low | `"True"/"False"` strings become booleans |
222
+ | `WHITESPACE_EDGED_VALUES` | low | padded values survive the load but fail joins |
223
+ | `DIALECT_GUESSED` | low | the delimiter had to be inferred; verify it |
224
+
225
+ ## Design notes
226
+
227
+ - **Reads raw text, never mutates.** Findings come from a single streamed
228
+ pass with per-column value counters bounded in both entries
229
+ (`--distinct-cap`, default 100k) and bytes (64 MB), so memory stays
230
+ bounded on multi-GB files; `--max-rows` bounds time. Columns that hit a
231
+ cap are named in the report and their findings reflect a partial sample.
232
+ - **Loader profiles, not vibes.** Findings are attributed to the loaders
233
+ whose defaults trigger them (pandas and polars today), and
234
+ `tests/test_loader_claims.py` re-verifies each claim against the
235
+ installed versions.
236
+ - **Actionable output.** Every finding carries a fix, and the report ends
237
+ with ready-to-paste `pd.read_csv` / `pl.read_csv` arguments that prevent
238
+ the high-severity mutations.
239
+
240
+ ## Limits, stated honestly
241
+
242
+ - **Header auto-detection is a heuristic.** A header made of numeric names
243
+ (e.g. year columns `2020,2021,2022`) is misclassified as data. The
244
+ report states which way the detection went; use `--header` /
245
+ `--no-header` when you know.
246
+ - **Loader claims are version-pinned.** Each claim is verified against the
247
+ installed pandas/polars in `tests/test_loader_claims.py` (developed
248
+ against pandas 2.3.3, polars 2.0.0). Other versions can differ; the
249
+ tests will say so. Findings about risks outside a default load carry
250
+ `loaders: ["downstream-parse"]` instead of naming a loader.
251
+ - **Static findings are risks; `--verify` is proof.** The default scan
252
+ infers what loader defaults would do. `--verify pandas|polars|both|duckdb`
253
+ actually loads the file and diffs every cell against the raw text.
254
+ - **The distinct-value caps bound memory, not correctness.** Past
255
+ `--distinct-cap` (default 100k entries, 64 MB of stored values) a
256
+ column's examples come from the capped sample and the column is named
257
+ as capped in the report; rules still run.
258
+ - **Encoding is detected from a 64 KB sample.** Invalid bytes past the
259
+ sample are replaced with U+FFFD and reported as
260
+ `INVALID_ENCODING_BYTES`, not crashed on; the reported encoding is not
261
+ a whole-file guarantee.
262
+ - **`--verify` replicates each loader's row handling** (first row is the
263
+ header, pandas skips blank lines, polars keeps them as null rows, short
264
+ rows are loader-filled) so the diff compares aligned rows; any residual
265
+ row-count mismatch is stated as an alignment note.
266
+
267
+ ## License
268
+
269
+ MIT
@@ -0,0 +1,247 @@
1
+ # csvhonest
2
+
3
+ **Audit what your CSV loader will silently change - before you load it.**
4
+
5
+ A CSV can look right in a text editor and change when pandas reads it. Catch lost ZIP-code zeros, a literal `NA` becoming missing, or an ID rounding before those values reach your analysis.
6
+
7
+ ## Try it in 60 seconds
8
+
9
+ Install the versioned source release (Python 3.9+, Git required):
10
+
11
+ ```sh
12
+ python -m pip install "git+https://github.com/anishpentyala/csvhonest.git@v0.1.4"
13
+ ```
14
+
15
+ Create this **synthetic** sample as `surprises.csv`:
16
+
17
+ ```csv
18
+ zip,country,customer_id
19
+ 02139,NA,9007199254740993
20
+ 00501,US,
21
+ 10001,GB,42
22
+ ```
23
+
24
+ Then run:
25
+
26
+ ```sh
27
+ csvhonest surprises.csv
28
+ ```
29
+
30
+ The report flags three high-severity risks: `LEADING_ZERO_LOSS`, `NA_COLLISION`, and `FLOAT64_PRECISION_LOSS`. It exits **1 because it found risks**, not because installation failed. The same input is bundled as [`examples/import-surprises.csv`](examples/import-surprises.csv).
31
+
32
+ Want to see what actually changes? Install pandas and verify this file with its default reader:
33
+
34
+ ```sh
35
+ python -m pip install "pandas==2.3.3"
36
+ csvhonest surprises.csv --verify pandas
37
+ ```
38
+
39
+ The verification reports four changed cells:
40
+
41
+ | Raw CSV text | pandas 2.3.3 default load | Why it matters |
42
+ | --- | --- | --- |
43
+ | `02139` | `2139` | ZIP-code zeros disappear |
44
+ | `00501` | `501` | Another ZIP code changes form |
45
+ | `NA` | missing | A literal country code is lost |
46
+ | `9007199254740993` | `9007199254740992` | An ID changes value after float conversion |
47
+
48
+ These are results from this tiny synthetic file, not a user benchmark. The missing ID makes pandas infer a floating-point column. Static scanning reports risks; `--verify pandas` loads and compares the actual file using the pandas version installed in your environment. Other inputs, loader versions and options can behave differently. Verification uses temporary local disk, as described below.
49
+
50
+ ## When to use it
51
+
52
+ Use csvhonest before loading unfamiliar CSV exports, or in a pipeline that should stop on a risky import. It runs locally and the static scan needs only Python's standard library. Optional verification needs the loader being checked.
53
+
54
+ If you already know the schema, **explicit loader options are the first fix**, not another tool. For this sample, preserving every cell as text is as simple as:
55
+
56
+ ```python
57
+ import pandas as pd
58
+
59
+ frame = pd.read_csv("surprises.csv", dtype=str, keep_default_na=False)
60
+ ```
61
+
62
+ That is appropriate here because ZIP codes, country codes and customer IDs are text. It is not a universal loading policy: real numeric columns and missing values need a deliberate schema. csvhonest helps identify where to make that choice; it does not decide the intended meaning of your data.
63
+
64
+ ## Install options
65
+
66
+ The pinned Git command above installs source without a manual clone. There is no PyPI release under the name `csvhonest`.
67
+
68
+ From a source checkout:
69
+
70
+ ```sh
71
+ git clone https://github.com/anishpentyala/csvhonest.git
72
+ cd csvhonest
73
+ python -m pip install .
74
+ csvhonest examples/import-surprises.csv
75
+ ```
76
+
77
+ Building needs setuptools >= 68. If an older pip cannot build the package, update pip in your virtual environment first. No pandas or Polars dependency is required for a static scan.
78
+
79
+ ## Use
80
+
81
+ ```
82
+ csvhonest data.csv # human report
83
+ csvhonest data.csv --format json # machine report for CI
84
+ csvhonest data.csv --verify both # also run pandas+polars and diff raw vs loaded
85
+ csvhonest a.csv b.csv --fail-on medium
86
+ csvhonest data.csv --no-header # force first row to be data
87
+ ```
88
+
89
+ `--verify pandas` (or `polars`, `both`) goes beyond static analysis: it
90
+ loads the file with the installed loader's defaults and reports the cells
91
+ that actually changed, per distinct raw value (`'02139' -> 2139`,
92
+ `'NA' -> <missing>`), plus the dtype each column landed on.
93
+
94
+ Numeric verification compares the exact source decimal spelling to the displayed
95
+ loaded number. A lost digit or nonzero value underflowing to zero is a
96
+ `value_changed`, even when the source uses a decimal point or exponent.
97
+ `1e2 -> 100` remains `form_changed`; ordinary `0.1` is not flagged for the
98
+ binary float's internal expansion. This is a comparison of displayed numeric
99
+ values, not a bit-exact floating-point audit or a guarantee for every loader.
100
+
101
+ Exit code is 1 when a finding at or above `--fail-on` (default `high`)
102
+ exists, so the check slots into a pipeline or pre-commit step.
103
+ A requested verification that cannot load the file, read its raw comparison,
104
+ or establish matching row/column shapes exits **2**, even if the static scan
105
+ found no high-severity risks. It returns a verification error with no cell
106
+ mutation claims, rather than comparing a potentially shifted prefix.
107
+
108
+ Pandas verification skips unquoted ASCII space/tab-only physical lines at CSV
109
+ record boundaries, including before the header. Quoted whitespace, embedded
110
+ blank lines inside a multiline quoted cell, and space/tab delimiters remain
111
+ data. Polars keeps its existing blank-record policy. This behavior was checked
112
+ with pandas 2.3.3 and polars 2.0.0; it does not certify every future loader
113
+ version or unusual parser configuration. Verification still uses each loader's
114
+ normal header interpretation, even when the static scanner was told
115
+ `--no-header`. With `--verify`, the CLI first copies the full input into a private temporary
116
+ directory. Static scanning and both loaders then use that capture; a rewrite or
117
+ deletion of the original after capture cannot fabricate mutation evidence.
118
+ The Python `verify_with_pandas` / `verify_with_polars` functions each capture
119
+ their input before loading and comparing. They do not retroactively make an
120
+ earlier independent `scan_file()` call part of that capture.
121
+
122
+ Capturing is a streaming disk copy, not a filesystem transaction: a writer can
123
+ still change bytes while the copy is in progress. All comparisons describe the
124
+ captured bytes, not a guaranteed point-in-time version of a concurrently written
125
+ file. Verification copies the complete input even with `--max-rows`; temporary
126
+ disk space can reach twice its size because a CLI capture and one verifier
127
+ capture coexist. Files are removed on success or failure. Without `--verify`,
128
+ static scanning keeps its existing streaming path. Matching shapes still cannot
129
+ detect every possible parser disagreement.
130
+
131
+
132
+ From Python:
133
+
134
+ ```python
135
+ from csvhonest import scan_file
136
+
137
+ result = scan_file("orders.csv")
138
+ for finding in result.findings:
139
+ print(finding.severity, finding.code, finding.message)
140
+ ```
141
+
142
+ ## Optional DuckDB verification
143
+
144
+ ```sh
145
+ python -m pip install "duckdb==1.5.6"
146
+ csvhonest data.csv --verify duckdb
147
+ ```
148
+
149
+ `--verify duckdb` compares raw cells with the installed DuckDB default CSV
150
+ reader in a temporary in-memory database. DuckDB is optional and is imported
151
+ only when selected. `--verify both` still means pandas plus Polars. Static-risk
152
+ profiles remain pandas and Polars; this release adds no DuckDB static profile.
153
+
154
+ Tested DuckDB versions: **1.3.2, 1.4.4, and 1.5.6**. Other versions are unverified;
155
+ this is not a minimum-version or all-versions compatibility claim. Synthetic
156
+ late-sample tests cover decimal rounding, lost zeros, small values becoming
157
+ zero, and timestamps becoming dates. These are reproduction tests, not user
158
+ trials or adoption results. DuckDB preserves the leading zeros and literal
159
+ `NA` in the small pandas example above; do not apply its pandas results to DuckDB.
160
+
161
+ Scope is deliberately narrow: UTF-8 (including BOM), a detected header,
162
+ a one-character delimiter, no skipped preamble or comments, and conventional
163
+ quoting. Unsupported encodings or layouts produce a verification error rather
164
+ than cell claims. This is not a custom SQL, user-schema, or post-ingest verifier.
165
+ DuckDB may infer a different table shape, including treating a ragged comma
166
+ file as a single text column. No mutations does not certify the intended schema.
167
+ Duplicate-header column names are DuckDB's renamed names, not the raw headers.
168
+
169
+ The adapter copies the complete captured input to a fixed temporary filename
170
+ so glob characters in the original name are literal. The CLI capture and this
171
+ adapter copy can coexist, requiring roughly **twice the full file size** in
172
+ temporary disk space. Copies are removed on success or failure. `--max-rows`
173
+ limits compared/fetched rows, not capture size or DuckDB's default sniffing
174
+ work. A capped comparison cannot find mutations beyond its prefix. No memory,
175
+ throughput, whole-file safety, or concurrent-writer transaction guarantee is made.
176
+
177
+ ## What it checks
178
+
179
+ | Code | Severity | What silently happens |
180
+ | --- | --- | --- |
181
+ | `LEADING_ZERO_LOSS` | high | `02139` loads as `2139` when the column infers numeric (pandas, polars) |
182
+ | `PADDED_LEADING_ZERO_LOSS` | high | whitespace-padded numbers with leading zeros: pandas trims and parses them, losing zeros and padding; polars keeps the original strings |
183
+ | `NA_COLLISION` | high | `"NA"`, `"None"`, `"null"` become NaN (pandas defaults) |
184
+ | `INT64_OVERFLOW` | high | pandas switches to uint64, or text (object in pandas 2, str in pandas 3) when signs mix; polars 2.x to Int128 (1.x raises) |
185
+ | `FLOAT64_PRECISION_LOSS` | high | integers above 2^53 lose exactness under float64: mixed int/float columns (pandas, polars) or int columns with holes (pandas) |
186
+ | `WHITESPACE_KEY_COLLISION` | high | `"WA"` and `"WA "` merge on any strip, collapsing distinct records |
187
+ | `UNICODE_FORM_COLLISION` | high | visually identical strings in different normal forms load as separate keys |
188
+ | `DUPLICATE_HEADERS` | high | pandas renames `a, a.1`; polars renames `a, a_duplicated_0` |
189
+ | `RAGGED_ROWS` | high | short rows are silently padded with missing values (pandas NaN, polars null); long rows make both loaders raise |
190
+ | `INVALID_ENCODING_BYTES` | medium | byte sequences invalid for the detected encoding; loaders reject or mangle them |
191
+ | `SCI_NOTATION_FORM_LOSS` | medium | `"1E2"` becomes `100.0`; IDs that look like E-notation change value |
192
+ | `THOUSANDS_SEPARATOR` | medium | `"1,234"` blocks numeric inference; column stays text |
193
+ | `AMBIGUOUS_DATE` | medium | `01/02/03` parses day-first or month-first depending on the tool |
194
+ | `CURRENCY_OR_PERCENT` | medium | `"$5.00"`, `"5%"` load as text; naive casts misread them |
195
+ | `INVISIBLE_CHARACTERS` | medium | no-break spaces and zero-width characters break equality and joins |
196
+ | `FOOTER_ROWS` | medium | `Total`/`Source:` rows inside numeric columns |
197
+ | `NON_UTF8_ENCODING` | medium | cp1252 export that UTF-8-assuming tools reject or mangle |
198
+ | `INT_BECOMES_FLOAT64` | low | all-integer column with missing cells loads as float64 (pandas) |
199
+ | `BOOL_COERCION` | low | `"True"/"False"` strings become booleans |
200
+ | `WHITESPACE_EDGED_VALUES` | low | padded values survive the load but fail joins |
201
+ | `DIALECT_GUESSED` | low | the delimiter had to be inferred; verify it |
202
+
203
+ ## Design notes
204
+
205
+ - **Reads raw text, never mutates.** Findings come from a single streamed
206
+ pass with per-column value counters bounded in both entries
207
+ (`--distinct-cap`, default 100k) and bytes (64 MB), so memory stays
208
+ bounded on multi-GB files; `--max-rows` bounds time. Columns that hit a
209
+ cap are named in the report and their findings reflect a partial sample.
210
+ - **Loader profiles, not vibes.** Findings are attributed to the loaders
211
+ whose defaults trigger them (pandas and polars today), and
212
+ `tests/test_loader_claims.py` re-verifies each claim against the
213
+ installed versions.
214
+ - **Actionable output.** Every finding carries a fix, and the report ends
215
+ with ready-to-paste `pd.read_csv` / `pl.read_csv` arguments that prevent
216
+ the high-severity mutations.
217
+
218
+ ## Limits, stated honestly
219
+
220
+ - **Header auto-detection is a heuristic.** A header made of numeric names
221
+ (e.g. year columns `2020,2021,2022`) is misclassified as data. The
222
+ report states which way the detection went; use `--header` /
223
+ `--no-header` when you know.
224
+ - **Loader claims are version-pinned.** Each claim is verified against the
225
+ installed pandas/polars in `tests/test_loader_claims.py` (developed
226
+ against pandas 2.3.3, polars 2.0.0). Other versions can differ; the
227
+ tests will say so. Findings about risks outside a default load carry
228
+ `loaders: ["downstream-parse"]` instead of naming a loader.
229
+ - **Static findings are risks; `--verify` is proof.** The default scan
230
+ infers what loader defaults would do. `--verify pandas|polars|both|duckdb`
231
+ actually loads the file and diffs every cell against the raw text.
232
+ - **The distinct-value caps bound memory, not correctness.** Past
233
+ `--distinct-cap` (default 100k entries, 64 MB of stored values) a
234
+ column's examples come from the capped sample and the column is named
235
+ as capped in the report; rules still run.
236
+ - **Encoding is detected from a 64 KB sample.** Invalid bytes past the
237
+ sample are replaced with U+FFFD and reported as
238
+ `INVALID_ENCODING_BYTES`, not crashed on; the reported encoding is not
239
+ a whole-file guarantee.
240
+ - **`--verify` replicates each loader's row handling** (first row is the
241
+ header, pandas skips blank lines, polars keeps them as null rows, short
242
+ rows are loader-filled) so the diff compares aligned rows; any residual
243
+ row-count mismatch is stated as an alignment note.
244
+
245
+ ## License
246
+
247
+ MIT
@@ -0,0 +1,4 @@
1
+ zip,country,customer_id
2
+ 02139,NA,9007199254740993
3
+ 00501,US,
4
+ 10001,GB,42
@@ -0,0 +1,36 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "csvhonest"
7
+ version = "0.1.4"
8
+ description = "Audit what your CSV loader will silently change before you load it."
9
+ readme = "README.md"
10
+ requires-python = ">=3.9"
11
+ license = { text = "MIT" }
12
+ authors = [{ name = "Anish Pentyala" }]
13
+ keywords = ["csv", "pandas", "polars", "data-quality", "etl", "data-loss"]
14
+ classifiers = [
15
+ "Development Status :: 3 - Alpha",
16
+ "Environment :: Console",
17
+ "Intended Audience :: Developers",
18
+ "Intended Audience :: Science/Research",
19
+ "License :: OSI Approved :: MIT License",
20
+ "Programming Language :: Python :: 3",
21
+ "Topic :: Scientific/Engineering :: Information Analysis",
22
+ "Topic :: Utilities",
23
+ ]
24
+ dependencies = []
25
+
26
+ [project.optional-dependencies]
27
+ dev = ["pytest>=7"]
28
+
29
+ [project.scripts]
30
+ csvhonest = "csvhonest.cli:main"
31
+
32
+ [tool.setuptools.packages.find]
33
+ where = ["src"]
34
+
35
+ [tool.pytest.ini_options]
36
+ testpaths = ["tests"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,15 @@
1
+ """csvhonest: audit what your CSV loader will silently change before you load it.
2
+
3
+ csvhonest scans raw CSV text and reports the values that default loader
4
+ settings (pandas.read_csv, polars.read_csv) would silently mutate: leading
5
+ zeros dropped from IDs, strings like "NA" turned into NaN, large integers
6
+ losing exactness under float64 coercion, ambiguous dates, and lookalike
7
+ keys that collapse when stripped or Unicode-normalized.
8
+ """
9
+
10
+ from .scan import scan_file, ScanResult
11
+ from .report import render_text, render_json
12
+
13
+ __version__ = "0.1.4"
14
+
15
+ __all__ = ["scan_file", "ScanResult", "render_text", "render_json", "__version__"]
@@ -0,0 +1,5 @@
1
+ import sys
2
+
3
+ from .cli import main
4
+
5
+ sys.exit(main())