cellproof 0.5.0__tar.gz → 0.6.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.
- {cellproof-0.5.0 → cellproof-0.6.0}/CHANGELOG.md +12 -0
- {cellproof-0.5.0 → cellproof-0.6.0}/PKG-INFO +10 -9
- {cellproof-0.5.0 → cellproof-0.6.0}/PROGRESS.md +1 -1
- {cellproof-0.5.0 → cellproof-0.6.0}/README.md +9 -8
- {cellproof-0.5.0 → cellproof-0.6.0}/pyproject.toml +1 -1
- cellproof-0.6.0/src/cellproof/__init__.py +1 -0
- {cellproof-0.5.0 → cellproof-0.6.0}/src/cellproof/cli.py +10 -6
- {cellproof-0.5.0 → cellproof-0.6.0}/src/cellproof/compiler.py +4 -3
- {cellproof-0.5.0 → cellproof-0.6.0}/src/cellproof/fn/finance.py +63 -0
- {cellproof-0.5.0 → cellproof-0.6.0}/src/cellproof/fn/logic.py +70 -2
- {cellproof-0.5.0 → cellproof-0.6.0}/src/cellproof/fn/text.py +35 -1
- {cellproof-0.5.0 → cellproof-0.6.0}/src/cellproof/regions.py +2 -1
- {cellproof-0.5.0 → cellproof-0.6.0}/src/cellproof/verifier.py +25 -2
- {cellproof-0.5.0 → cellproof-0.6.0}/tests/test_cli.py +42 -0
- {cellproof-0.5.0 → cellproof-0.6.0}/tests/test_emitter.py +1 -1
- {cellproof-0.5.0 → cellproof-0.6.0}/tests/test_finance_stats.py +28 -0
- cellproof-0.6.0/tests/test_functions.py +81 -0
- {cellproof-0.5.0 → cellproof-0.6.0}/tests/test_region.py +1 -1
- {cellproof-0.5.0 → cellproof-0.6.0}/tests/test_spill.py +11 -0
- cellproof-0.5.0/src/cellproof/__init__.py +0 -1
- cellproof-0.5.0/tests/test_functions.py +0 -52
- {cellproof-0.5.0 → cellproof-0.6.0}/.github/workflows/ci.yml +0 -0
- {cellproof-0.5.0 → cellproof-0.6.0}/.github/workflows/publish.yml +0 -0
- {cellproof-0.5.0 → cellproof-0.6.0}/.gitignore +0 -0
- {cellproof-0.5.0 → cellproof-0.6.0}/AGENTS.md +0 -0
- {cellproof-0.5.0 → cellproof-0.6.0}/DESIGN.md +0 -0
- {cellproof-0.5.0 → cellproof-0.6.0}/INFO.md +0 -0
- {cellproof-0.5.0 → cellproof-0.6.0}/LICENSE +0 -0
- {cellproof-0.5.0 → cellproof-0.6.0}/PLAN-2a.md +0 -0
- {cellproof-0.5.0 → cellproof-0.6.0}/PLAN-2b.md +0 -0
- {cellproof-0.5.0 → cellproof-0.6.0}/PLAN.md +0 -0
- {cellproof-0.5.0 → cellproof-0.6.0}/SECURITY.md +0 -0
- {cellproof-0.5.0 → cellproof-0.6.0}/docs/JOURNEY.md +0 -0
- {cellproof-0.5.0 → cellproof-0.6.0}/docs/superpowers/plans/2026-10-14-plan-2c-speed.md +0 -0
- {cellproof-0.5.0 → cellproof-0.6.0}/docs/superpowers/plans/2026-10-14-plan-2d-table-mode.md +0 -0
- {cellproof-0.5.0 → cellproof-0.6.0}/docs/superpowers/specs/2026-10-14-plan-2c-speed-design.md +0 -0
- {cellproof-0.5.0 → cellproof-0.6.0}/docs/superpowers/specs/2026-10-14-plan-2d-table-mode-design.md +0 -0
- {cellproof-0.5.0 → cellproof-0.6.0}/docs/superpowers/specs/2026-10-18-running-totals-design.md +0 -0
- {cellproof-0.5.0 → cellproof-0.6.0}/docs/superpowers/specs/2026-10-19-lookups-row-wise-design.md +0 -0
- {cellproof-0.5.0 → cellproof-0.6.0}/examples/commission.xlsx +0 -0
- {cellproof-0.5.0 → cellproof-0.6.0}/examples/errors.xlsx +0 -0
- {cellproof-0.5.0 → cellproof-0.6.0}/examples/functions.xlsx +0 -0
- {cellproof-0.5.0 → cellproof-0.6.0}/examples/functions_unsaved.xlsx +0 -0
- {cellproof-0.5.0 → cellproof-0.6.0}/examples/make_commission.py +0 -0
- {cellproof-0.5.0 → cellproof-0.6.0}/examples/make_errors.py +0 -0
- {cellproof-0.5.0 → cellproof-0.6.0}/examples/make_functions.py +0 -0
- {cellproof-0.5.0 → cellproof-0.6.0}/src/cellproof/__main__.py +0 -0
- {cellproof-0.5.0 → cellproof-0.6.0}/src/cellproof/compute.py +0 -0
- {cellproof-0.5.0 → cellproof-0.6.0}/src/cellproof/emitter.py +0 -0
- {cellproof-0.5.0 → cellproof-0.6.0}/src/cellproof/expr.py +0 -0
- {cellproof-0.5.0 → cellproof-0.6.0}/src/cellproof/fenwick.py +0 -0
- {cellproof-0.5.0 → cellproof-0.6.0}/src/cellproof/fn/__init__.py +0 -0
- {cellproof-0.5.0 → cellproof-0.6.0}/src/cellproof/fn/aggregate.py +0 -0
- {cellproof-0.5.0 → cellproof-0.6.0}/src/cellproof/fn/criteria.py +0 -0
- {cellproof-0.5.0 → cellproof-0.6.0}/src/cellproof/fn/dates.py +0 -0
- {cellproof-0.5.0 → cellproof-0.6.0}/src/cellproof/fn/dynamic.py +0 -0
- {cellproof-0.5.0 → cellproof-0.6.0}/src/cellproof/fn/lookup.py +0 -0
- {cellproof-0.5.0 → cellproof-0.6.0}/src/cellproof/fn/maths.py +0 -0
- {cellproof-0.5.0 → cellproof-0.6.0}/src/cellproof/fn/stats.py +0 -0
- {cellproof-0.5.0 → cellproof-0.6.0}/src/cellproof/functions.py +0 -0
- {cellproof-0.5.0 → cellproof-0.6.0}/src/cellproof/graph.py +0 -0
- {cellproof-0.5.0 → cellproof-0.6.0}/src/cellproof/impact.py +0 -0
- {cellproof-0.5.0 → cellproof-0.6.0}/src/cellproof/model.py +0 -0
- {cellproof-0.5.0 → cellproof-0.6.0}/src/cellproof/parser.py +0 -0
- {cellproof-0.5.0 → cellproof-0.6.0}/src/cellproof/r1c1.py +0 -0
- {cellproof-0.5.0 → cellproof-0.6.0}/src/cellproof/rangeindex.py +0 -0
- {cellproof-0.5.0 → cellproof-0.6.0}/src/cellproof/reader.py +0 -0
- {cellproof-0.5.0 → cellproof-0.6.0}/src/cellproof/refs.py +0 -0
- {cellproof-0.5.0 → cellproof-0.6.0}/src/cellproof/region.py +0 -0
- {cellproof-0.5.0 → cellproof-0.6.0}/src/cellproof/report.py +0 -0
- {cellproof-0.5.0 → cellproof-0.6.0}/src/cellproof/tables.py +0 -0
- {cellproof-0.5.0 → cellproof-0.6.0}/tests/bench_shapes.py +0 -0
- {cellproof-0.5.0 → cellproof-0.6.0}/tests/corpus.py +0 -0
- {cellproof-0.5.0 → cellproof-0.6.0}/tests/test_aggregate.py +0 -0
- {cellproof-0.5.0 → cellproof-0.6.0}/tests/test_arrays.py +0 -0
- {cellproof-0.5.0 → cellproof-0.6.0}/tests/test_batches.py +0 -0
- {cellproof-0.5.0 → cellproof-0.6.0}/tests/test_compiler.py +0 -0
- {cellproof-0.5.0 → cellproof-0.6.0}/tests/test_compute.py +0 -0
- {cellproof-0.5.0 → cellproof-0.6.0}/tests/test_corpus_findings.py +0 -0
- {cellproof-0.5.0 → cellproof-0.6.0}/tests/test_criteria.py +0 -0
- {cellproof-0.5.0 → cellproof-0.6.0}/tests/test_dates.py +0 -0
- {cellproof-0.5.0 → cellproof-0.6.0}/tests/test_dynamic.py +0 -0
- {cellproof-0.5.0 → cellproof-0.6.0}/tests/test_errors.py +0 -0
- {cellproof-0.5.0 → cellproof-0.6.0}/tests/test_excel_findings.py +0 -0
- {cellproof-0.5.0 → cellproof-0.6.0}/tests/test_excel_saved.py +0 -0
- {cellproof-0.5.0 → cellproof-0.6.0}/tests/test_fenwick.py +0 -0
- {cellproof-0.5.0 → cellproof-0.6.0}/tests/test_graph.py +0 -0
- {cellproof-0.5.0 → cellproof-0.6.0}/tests/test_impact.py +0 -0
- {cellproof-0.5.0 → cellproof-0.6.0}/tests/test_implicit.py +0 -0
- {cellproof-0.5.0 → cellproof-0.6.0}/tests/test_index.py +0 -0
- {cellproof-0.5.0 → cellproof-0.6.0}/tests/test_lexed.py +0 -0
- {cellproof-0.5.0 → cellproof-0.6.0}/tests/test_limits.py +0 -0
- {cellproof-0.5.0 → cellproof-0.6.0}/tests/test_logic.py +0 -0
- {cellproof-0.5.0 → cellproof-0.6.0}/tests/test_lookup.py +0 -0
- {cellproof-0.5.0 → cellproof-0.6.0}/tests/test_lookups.py +0 -0
- {cellproof-0.5.0 → cellproof-0.6.0}/tests/test_maths.py +0 -0
- {cellproof-0.5.0 → cellproof-0.6.0}/tests/test_parser.py +0 -0
- {cellproof-0.5.0 → cellproof-0.6.0}/tests/test_perf.py +0 -0
- {cellproof-0.5.0 → cellproof-0.6.0}/tests/test_r1c1.py +0 -0
- {cellproof-0.5.0 → cellproof-0.6.0}/tests/test_rangeindex.py +0 -0
- {cellproof-0.5.0 → cellproof-0.6.0}/tests/test_reader.py +0 -0
- {cellproof-0.5.0 → cellproof-0.6.0}/tests/test_refs.py +0 -0
- {cellproof-0.5.0 → cellproof-0.6.0}/tests/test_regions.py +0 -0
- {cellproof-0.5.0 → cellproof-0.6.0}/tests/test_regions_differential.py +0 -0
- {cellproof-0.5.0 → cellproof-0.6.0}/tests/test_regions_split.py +0 -0
- {cellproof-0.5.0 → cellproof-0.6.0}/tests/test_report.py +0 -0
- {cellproof-0.5.0 → cellproof-0.6.0}/tests/test_review_regressions.py +0 -0
- {cellproof-0.5.0 → cellproof-0.6.0}/tests/test_running.py +0 -0
- {cellproof-0.5.0 → cellproof-0.6.0}/tests/test_shapes.py +0 -0
- {cellproof-0.5.0 → cellproof-0.6.0}/tests/test_tables.py +0 -0
- {cellproof-0.5.0 → cellproof-0.6.0}/tests/test_text.py +0 -0
- {cellproof-0.5.0 → cellproof-0.6.0}/tests/test_types.py +0 -0
- {cellproof-0.5.0 → cellproof-0.6.0}/tests/test_verifier.py +0 -0
- {cellproof-0.5.0 → cellproof-0.6.0}/tests/xlsxkit.py +0 -0
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.6.0 (2026-10-31)
|
|
4
|
+
|
|
5
|
+
- **A batch DuckDB rejects no longer stops the run:** its cells are UNRESOLVED with DuckDB's message, the book is
|
|
6
|
+
compiled again so every cell reading them is UNRESOLVED too (none can read a missing value), and the report is
|
|
7
|
+
written. The exit code is still 3: it is a bug in cellproof, please report it.
|
|
8
|
+
- **ROW, COLUMN** (of the formula's cell, of a cell, and in an array formula of a range: one column of row numbers,
|
|
9
|
+
one row of column numbers - real Excel), **CODE** (Windows-1252, CHAR's inverse; a character outside it, or above
|
|
10
|
+
127 in a file Excel for Mac calculated, is UNRESOLVED), **UNICODE, UNICHAR, N** (of a range in an array formula:
|
|
11
|
+
its first cell), **ISODD, ISEVEN** (no ranges in an array formula: #VALUE!, like EDATE).
|
|
12
|
+
- **IRR and RATE** by Newton's method in SQL (a recursive CTE). Not guessed: cash flows with several sign changes
|
|
13
|
+
(several roots), an error among IRR's cells, a RATE whose answer is 0, nper not a positive whole number.
|
|
14
|
+
|
|
3
15
|
## 0.5.0 (2026-10-31)
|
|
4
16
|
|
|
5
17
|
- **FILTER, SORT, UNIQUE inside other calculations:** `SUM(FILTER(...))`, `COUNTA(UNIQUE(...))`, AVERAGE, MIN, MAX,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: cellproof
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.6.0
|
|
4
4
|
Summary: Turn an Excel workbook into SQL (a dbt project on DuckDB) and prove every number matches.
|
|
5
5
|
Project-URL: Homepage, https://github.com/Nikhil414/cellproof
|
|
6
6
|
Project-URL: Issues, https://github.com/Nikhil414/cellproof/issues
|
|
@@ -111,14 +111,15 @@ reader -> regions -> dependency graph -> compiler -> verifier -> dbt emitter ->
|
|
|
111
111
|
code.
|
|
112
112
|
6. **Emit** the dbt project and the report.
|
|
113
113
|
|
|
114
|
-
|
|
115
|
-
COUNT, COUNTA, COUNTBLANK, COUNTIF(S), DATE, DATEDIF, DAY, DAYS, DAYS360, EDATE,
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
114
|
+
140 Excel functions are supported: @ (SINGLE), ABS, AND, AVERAGE, AVERAGEIF(S), CEILING, CHAR, CHOOSE, CLEAN, CODE,
|
|
115
|
+
COLUMN, COLUMNS, CONCAT(ENATE), COUNT, COUNTA, COUNTBLANK, COUNTIF(S), DATE, DATEDIF, DAY, DAYS, DAYS360, EDATE,
|
|
116
|
+
EOMONTH, EXACT, EXP, FILTER, FIND, FLOOR, FV, HLOOKUP, IF, IFERROR, IFNA, IFS, INDEX, INT, IRR, IS* (BLANK, ERR,
|
|
117
|
+
ERROR, LOGICAL, NA, NUMBER, TEXT), ISEVEN, ISODD, LARGE, LEFT, LEN, LET, LN, LOG, LOG10, LOOKUP, LOWER, MATCH, MAX,
|
|
118
|
+
MAXIFS, MEDIAN, MID, MIN, MINIFS, MOD, MODE, MONTH, MROUND, N, NA, NETWORKDAYS, NOT, NPER, NPV, OR, PERCENTILE(.INC),
|
|
119
|
+
PI, PMT, POWER, PRODUCT, PROPER, PV, QUARTILE(.INC), RANK(.EQ), RATE, REPLACE, REPT, RIGHT, ROUND(UP/DOWN), ROW, ROWS,
|
|
120
|
+
SEARCH, SEQUENCE, SIGN, SMALL, SORT, SORTBY, SQRT, STDEV(.S/.P/P), SUBSTITUTE, SUBTOTAL, SUM, SUMIF(S), SUMPRODUCT,
|
|
121
|
+
SWITCH, TEXT, TEXTJOIN, TRIM, TRUE/FALSE, TRUNC, UNICHAR, UNICODE, UNIQUE, UPPER, VALUE, VAR(.S/.P/P), VLOOKUP,
|
|
122
|
+
WEEKDAY, WORKDAY, XLOOKUP, XMATCH, XOR, YEAR, YEARFRAC.
|
|
122
123
|
|
|
123
124
|
**Excel tables:** structured references (`Sales[Amount]`, `Sales[@Qty]`, `Sales[[#This Row],[Qty]]`, `Sales[#Totals]`,
|
|
124
125
|
`Sales[[Rep]:[Amount]]`) are rewritten to plain references when the file is read, so a calculated table column
|
|
@@ -29,7 +29,7 @@ Everything below is on `main`, built test-first, each piece reviewed by a fresh
|
|
|
29
29
|
| Open source | MIT license, README with limits, SECURITY.md, CI on Windows/macOS/Linux x Python 3.10-3.13 |
|
|
30
30
|
|
|
31
31
|
Tests: 492 (+10 skipped without dbt/Excel files), plus 3 workbooks saved by real Excel that all PASS (4 cells UNRESOLVED on
|
|
32
|
-
purpose). Public on GitHub (one-commit history start). 0.1.0 was released as `unexcel`; 0.2.x, 0.3.0, 0.3.1, 0.4.0 and 0.
|
|
32
|
+
purpose). Public on GitHub (one-commit history start). 0.1.0 was released as `unexcel`; 0.2.x, 0.3.0, 0.3.1, 0.4.0, 0.5.0 and 0.6.0 (2026-10-31) are on PyPI as `cellproof` (see CHANGELOG.md).
|
|
33
33
|
A user's practice workbook: 3 PASS / 47 UNRESOLVED -> 48 PASS / 0 FAIL / 2 UNRESOLVED.
|
|
34
34
|
|
|
35
35
|
## Public test workbooks (2026-10-31)
|
|
@@ -77,14 +77,15 @@ reader -> regions -> dependency graph -> compiler -> verifier -> dbt emitter ->
|
|
|
77
77
|
code.
|
|
78
78
|
6. **Emit** the dbt project and the report.
|
|
79
79
|
|
|
80
|
-
|
|
81
|
-
COUNT, COUNTA, COUNTBLANK, COUNTIF(S), DATE, DATEDIF, DAY, DAYS, DAYS360, EDATE,
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
80
|
+
140 Excel functions are supported: @ (SINGLE), ABS, AND, AVERAGE, AVERAGEIF(S), CEILING, CHAR, CHOOSE, CLEAN, CODE,
|
|
81
|
+
COLUMN, COLUMNS, CONCAT(ENATE), COUNT, COUNTA, COUNTBLANK, COUNTIF(S), DATE, DATEDIF, DAY, DAYS, DAYS360, EDATE,
|
|
82
|
+
EOMONTH, EXACT, EXP, FILTER, FIND, FLOOR, FV, HLOOKUP, IF, IFERROR, IFNA, IFS, INDEX, INT, IRR, IS* (BLANK, ERR,
|
|
83
|
+
ERROR, LOGICAL, NA, NUMBER, TEXT), ISEVEN, ISODD, LARGE, LEFT, LEN, LET, LN, LOG, LOG10, LOOKUP, LOWER, MATCH, MAX,
|
|
84
|
+
MAXIFS, MEDIAN, MID, MIN, MINIFS, MOD, MODE, MONTH, MROUND, N, NA, NETWORKDAYS, NOT, NPER, NPV, OR, PERCENTILE(.INC),
|
|
85
|
+
PI, PMT, POWER, PRODUCT, PROPER, PV, QUARTILE(.INC), RANK(.EQ), RATE, REPLACE, REPT, RIGHT, ROUND(UP/DOWN), ROW, ROWS,
|
|
86
|
+
SEARCH, SEQUENCE, SIGN, SMALL, SORT, SORTBY, SQRT, STDEV(.S/.P/P), SUBSTITUTE, SUBTOTAL, SUM, SUMIF(S), SUMPRODUCT,
|
|
87
|
+
SWITCH, TEXT, TEXTJOIN, TRIM, TRUE/FALSE, TRUNC, UNICHAR, UNICODE, UNIQUE, UPPER, VALUE, VAR(.S/.P/P), VLOOKUP,
|
|
88
|
+
WEEKDAY, WORKDAY, XLOOKUP, XMATCH, XOR, YEAR, YEARFRAC.
|
|
88
89
|
|
|
89
90
|
**Excel tables:** structured references (`Sales[Amount]`, `Sales[@Qty]`, `Sales[[#This Row],[Qty]]`, `Sales[#Totals]`,
|
|
90
91
|
`Sales[[Rep]:[Amount]]`) are rewritten to plain references when the file is read, so a calculated table column
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.6.0"
|
|
@@ -10,7 +10,7 @@ from cellproof.compute import fill_missing
|
|
|
10
10
|
from cellproof.emitter import run_dbt, write_project
|
|
11
11
|
from cellproof.reader import UnreadableWorkbook, load
|
|
12
12
|
from cellproof.report import write_report
|
|
13
|
-
from cellproof.verifier import SqlFailed,
|
|
13
|
+
from cellproof.verifier import SqlFailed, verify_book
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
def main(argv: list[str] | None = None) -> int:
|
|
@@ -31,14 +31,18 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
31
31
|
print(f"error: {err}", file=sys.stderr)
|
|
32
32
|
return 2
|
|
33
33
|
book, computed, why = fill_missing(book, args.workbook)
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
def compile_fn(b):
|
|
35
|
+
compiled = compile_book(b)
|
|
36
|
+
if why:
|
|
37
|
+
compiled.unresolved.update({k: f"{r} ({why})" for k, r in compiled.unresolved.items() if r == NO_VALUE})
|
|
38
|
+
return compiled
|
|
37
39
|
try:
|
|
38
|
-
verdicts =
|
|
40
|
+
compiled, verdicts, failures = verify_book(book, compile_fn)
|
|
39
41
|
except SqlFailed as err:
|
|
40
42
|
print(f"error: {err}", file=sys.stderr)
|
|
41
43
|
return 3
|
|
44
|
+
for failure in failures: # those cells are UNRESOLVED in the report; the run goes on
|
|
45
|
+
print(f"error: {failure}", file=sys.stderr)
|
|
42
46
|
out = args.out or args.workbook.with_name(args.workbook.stem + "_dbt")
|
|
43
47
|
write_project(book, compiled, out, args.workbook.stem)
|
|
44
48
|
counts = write_report(verdicts, compiled.findings, out, args.workbook.name, computed, compiled.notes,
|
|
@@ -46,7 +50,7 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
46
50
|
if computed:
|
|
47
51
|
print(f"{len(computed)} expected values computed by the formulas library (the file had none saved)")
|
|
48
52
|
print(f"{counts['PASS']} pass, {counts['FAIL']} fail, {counts['UNRESOLVED']} unresolved -> {out / 'REPORT.md'}")
|
|
49
|
-
code = 1 if counts["FAIL"] else 0
|
|
53
|
+
code = 3 if failures else 1 if counts["FAIL"] else 0
|
|
50
54
|
if args.dbt:
|
|
51
55
|
ok, log = run_dbt(out)
|
|
52
56
|
print("dbt build: ok" if ok else f"dbt build failed:\n{log}")
|
|
@@ -106,8 +106,9 @@ class Keys:
|
|
|
106
106
|
|
|
107
107
|
|
|
108
108
|
# Analysis ToolPak functions do not take an array where one value is expected: {arguments that are one value}
|
|
109
|
-
NO_LIFT = {"EDATE": 2, "EOMONTH": 2, "MROUND": 2, "YEARFRAC": 3, "NETWORKDAYS": 2, "WORKDAY": 2
|
|
110
|
-
|
|
109
|
+
NO_LIFT = {"EDATE": 2, "EOMONTH": 2, "MROUND": 2, "YEARFRAC": 3, "NETWORKDAYS": 2, "WORKDAY": 2, "ISEVEN": 1,
|
|
110
|
+
"ISODD": 1}
|
|
111
|
+
NO_LIFT_CHECKED = {"EDATE", "EOMONTH", "MROUND", "YEARFRAC", "ISEVEN", "ISODD"} # #VALUE!: formulas' test.xlsx
|
|
111
112
|
|
|
112
113
|
|
|
113
114
|
class Compiler:
|
|
@@ -412,7 +413,7 @@ def compile_book(book: Book, regions: bool = True) -> Compiled:
|
|
|
412
413
|
def add_spill(cell) -> bool:
|
|
413
414
|
"""FILTER/SORT/UNIQUE/... spilled into a block: one batch for the whole block (fn/dynamic.spill_batch)."""
|
|
414
415
|
nonlocal weight
|
|
415
|
-
if not cell.array:
|
|
416
|
+
if not cell.array or cell.key in book.unread: # compile_cell gives the reason
|
|
416
417
|
return False
|
|
417
418
|
try:
|
|
418
419
|
tree = parse(cell.formula)
|
|
@@ -101,3 +101,66 @@ def npv(c, args, sheet):
|
|
|
101
101
|
sql = (f"(SELECT COALESCE(SUM(num / POWER(1 + {r.sql}, p)), CAST(0 AS DOUBLE)) FROM ({periods}) npv_periods)")
|
|
102
102
|
return Expr(sql, "num", errs(r.err, *(v.err for v in typed), *(g.err(c) for g in ranges),
|
|
103
103
|
_unchecked(f"{r.sql} = -1")))
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
NEWTON_STEPS = 100
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def _newton(ctes: str, f: str, fp: str, guess: str) -> tuple[str, str]:
|
|
110
|
+
"""(root SQL, converged SQL) of Newton's method from guess; f and fp are SQL of the column r (and the CTEs).
|
|
111
|
+
Excel stops at 0.00001 percent; this runs to the last digits, which differ from Excel's last iterate by far less
|
|
112
|
+
than the verifier's 1e-9. Not converging, or leaving r > -1, is #NUM!, as in Excel."""
|
|
113
|
+
it = (f"WITH RECURSIVE {ctes}, it(n, r, d) AS (SELECT 0, CAST({guess} AS DOUBLE), CAST(NULL AS DOUBLE) "
|
|
114
|
+
f"UNION ALL SELECT n + 1, r - fv / fpv, fv / fpv FROM (SELECT it.n, it.r, {f} AS fv, {fp} AS fpv FROM it, "
|
|
115
|
+
f"args WHERE it.n < {NEWTON_STEPS} AND it.r > -1 AND (it.d IS NULL OR abs(it.d) > 1e-13 * greatest(1, "
|
|
116
|
+
f"abs(it.r)))) s) SELECT {{}} FROM it ORDER BY n DESC LIMIT 1")
|
|
117
|
+
ok = "(d IS NOT NULL AND isfinite(r) AND r > -1 AND abs(d) <= 1e-10 * greatest(1, abs(r)))"
|
|
118
|
+
return f"({it.format('CASE WHEN ' + ok + ' THEN r END')})", f"({it.format(ok)})"
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
@register("IRR")
|
|
122
|
+
def irr(c, args, sheet):
|
|
123
|
+
"""IRR(values, [guess]): the rate where the NPV of the values (the first one now) is 0. Text, TRUE/FALSE and empty
|
|
124
|
+
cells are skipped. Several sign changes can have several roots, and which one Excel's iteration lands on was
|
|
125
|
+
not checked: UNCHECKED."""
|
|
126
|
+
arity("IRR", args, 1, 2)
|
|
127
|
+
if not isinstance(args[0], RefNode):
|
|
128
|
+
raise Unsupported("IRR of values typed into the formula not supported yet")
|
|
129
|
+
rng = _rng(c, args[0], sheet)
|
|
130
|
+
guess = num(c.expr(args[1], sheet)) if len(args) == 2 and args[1] is not None else Expr("CAST(0.1 AS DOUBLE)", "num")
|
|
131
|
+
where = f"FROM {CELLS} WHERE {rng.where()} AND kind = 'n'"
|
|
132
|
+
ctes = f"args AS (SELECT list(num ORDER BY row_num, col_num) AS v {where})"
|
|
133
|
+
f = "list_sum(list_transform(v, lambda x, i: x / pow(1 + it.r, i - 1)))"
|
|
134
|
+
fp = "list_sum(list_transform(v, lambda x, i: -(i - 1) * x / pow(1 + it.r, i)))"
|
|
135
|
+
root, ok = _newton(ctes, f, fp, guess.sql)
|
|
136
|
+
signs = f"(SELECT COUNT(*) FILTER (WHERE num > 0) > 0 AND COUNT(*) FILTER (WHERE num < 0) > 0 {where})"
|
|
137
|
+
flips = (f"(SELECT COUNT(*) FROM (SELECT sign(num) AS s, lag(sign(num)) OVER (ORDER BY row_num, col_num) AS p "
|
|
138
|
+
f"{where} AND num <> 0) irr_signs WHERE s <> p)")
|
|
139
|
+
# real Excel (formulas' test.xlsx): an error in an array constant is #VALUE!; in cells, not checked
|
|
140
|
+
error_in = rng.err(c)
|
|
141
|
+
if error_in != "NULL":
|
|
142
|
+
error_in = (f"(CASE WHEN {error_in} IS NOT NULL THEN "
|
|
143
|
+
f"'{'#VALUE!' if rng.area.sheet in c.book.arrays else UNCHECKED}' END)")
|
|
144
|
+
return Expr(root, "num", errs(error_in, guess.err, f"(CASE WHEN NOT {signs} THEN '#NUM!' END)",
|
|
145
|
+
_unchecked(f"{flips} > 1"), f"(CASE WHEN NOT {ok} THEN '#NUM!' END)"))
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
@register("RATE")
|
|
149
|
+
def rate(c, args, sheet):
|
|
150
|
+
"""RATE(nper, pmt, pv, [fv], [type], [guess]): the rate solving PMT's equation, by Newton's method."""
|
|
151
|
+
arity("RATE", args, 3, 6)
|
|
152
|
+
a = _args(c, args[:5], sheet, "RATE", 3, 5)
|
|
153
|
+
n, pmt, pv, fv, t = (x.sql for x in a)
|
|
154
|
+
guess = num(c.expr(args[5], sheet)) if len(args) == 6 and args[5] is not None else Expr("CAST(0.1 AS DOUBLE)", "num")
|
|
155
|
+
ctes = f"args AS (SELECT {n} AS n_, {pmt} AS pmt, {pv} AS pv, {fv} AS fv, {t} AS t)"
|
|
156
|
+
g, gp = "pow(1 + it.r, n_)", "(n_ * pow(1 + it.r, n_ - 1))"
|
|
157
|
+
f = f"(pv * {g} + pmt * (1 + it.r * t) * ({g} - 1) / it.r + fv)"
|
|
158
|
+
fp = (f"(pv * {gp} + pmt * (t * ({g} - 1) / it.r + (1 + it.r * t) * ({gp} * it.r - ({g} - 1)) / "
|
|
159
|
+
f"(it.r * it.r)))")
|
|
160
|
+
root, ok = _newton(ctes, f, fp, guess.sql)
|
|
161
|
+
return Expr(root, "num", errs(*(x.err for x in a), guess.err, _type(a[4]),
|
|
162
|
+
# a rate of 0 solves it (the payments only repay): Excel's answer there unchecked
|
|
163
|
+
_unchecked(f"{n} <= 0 OR {n} <> floor({n}) OR abs({pv} + {pmt} * {n} + {fv}) "
|
|
164
|
+
f"<= 1e-9 * greatest(abs({pv}), abs({pmt} * {n}), abs({fv}), 1) "
|
|
165
|
+
f"OR abs({root}) < 1e-9"),
|
|
166
|
+
f"(CASE WHEN NOT {ok} THEN '#NUM!' END)"))
|
|
@@ -4,9 +4,9 @@ The IS functions look at a value without failing: an error in their argument is
|
|
|
4
4
|
"""
|
|
5
5
|
from __future__ import annotations
|
|
6
6
|
|
|
7
|
-
from cellproof.expr import NO_ERR, Expr, as_bool, compare, error, errs, keep_locale, pick, unify, unify_all
|
|
7
|
+
from cellproof.expr import NO_ERR, ZERO, Expr, as_bool, compare, error, errs, keep_locale, num, num_strict, pick, unify, unify_all
|
|
8
8
|
from cellproof.functions import arity, logical_args, register
|
|
9
|
-
from cellproof.model import Unsupported
|
|
9
|
+
from cellproof.model import Unsupported, a1
|
|
10
10
|
from cellproof.parser import Binary, Call, Postfix, RefNode, Unary
|
|
11
11
|
from cellproof.refs import resolve
|
|
12
12
|
|
|
@@ -205,3 +205,71 @@ def single(c, args, sheet):
|
|
|
205
205
|
finally:
|
|
206
206
|
c.spill = spill
|
|
207
207
|
return c.expr(a, sheet)
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
def _position(name: str, which: int):
|
|
211
|
+
"""ROW/COLUMN: of the formula's own cell, of one cell, or - in an array formula - of this cell's element."""
|
|
212
|
+
def fn(c, args, sheet):
|
|
213
|
+
arity(name, args, 0, 1)
|
|
214
|
+
if not args or args[0] is None:
|
|
215
|
+
if c.at is None:
|
|
216
|
+
raise Unsupported(f"{name}() in a block of rows not supported yet (stays row by row)")
|
|
217
|
+
return Expr(f"CAST({c.at[which]} AS DOUBLE)", "num")
|
|
218
|
+
a = args[0]
|
|
219
|
+
if not isinstance(a, RefNode):
|
|
220
|
+
raise Unsupported(f"{name} of something other than a reference")
|
|
221
|
+
if c.rowrefs is not None and a.text in c.rowrefs:
|
|
222
|
+
raise Unsupported(f"{name} of a reference that moves with the row not supported yet")
|
|
223
|
+
from cellproof.refs import resolve
|
|
224
|
+
area = resolve(a.text, sheet, c.book)
|
|
225
|
+
if area.is_single:
|
|
226
|
+
return Expr(f"CAST({area.key[which]} AS DOUBLE)", "num")
|
|
227
|
+
if c.spill is None: # legacy Excel takes the first row/column, modern Excel spills: not checked
|
|
228
|
+
raise Unsupported(f"{name} of a range outside an array formula not supported yet")
|
|
229
|
+
# real Excel (formulas' test.xlsx): ROW of a range is one column of its row numbers, COLUMN one row of its
|
|
230
|
+
# column numbers, so they repeat across (down) the block
|
|
231
|
+
first, count = (area.r1, area.r2 - area.r1 + 1) if which == 1 else (area.c1, area.c2 - area.c1 + 1)
|
|
232
|
+
at = c.spill[0] if which == 1 else c.spill[1]
|
|
233
|
+
c.spill_dims.append((count, 1) if which == 1 else (1, count))
|
|
234
|
+
at = 0 if count == 1 else at
|
|
235
|
+
return error("#N/A") if at >= count else Expr(f"CAST({first + at} AS DOUBLE)", "num")
|
|
236
|
+
register(name)(fn)
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
_position("ROW", 1)
|
|
240
|
+
_position("COLUMN", 2)
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
@register("N")
|
|
244
|
+
def n_(c, args, sheet):
|
|
245
|
+
"""A number (dates are numbers) is itself, TRUE 1, FALSE 0, text 0, an error that error."""
|
|
246
|
+
arity("N", args, 1, 1)
|
|
247
|
+
a = args[0]
|
|
248
|
+
if isinstance(a, RefNode):
|
|
249
|
+
from cellproof.refs import resolve
|
|
250
|
+
area = resolve(a.text, sheet, c.book)
|
|
251
|
+
if not area.is_single:
|
|
252
|
+
if c.spill is None:
|
|
253
|
+
raise Unsupported("N of a range outside an array formula not supported yet")
|
|
254
|
+
# real Excel (formulas' test.xlsx): N of a range is N of its first cell, in every cell of the block
|
|
255
|
+
a = RefNode(f"'{area.sheet.replace(chr(39), chr(39) * 2)}'!{a1((area.sheet, area.r1, area.c1)).split('!')[-1]}")
|
|
256
|
+
x = c.expr(a, sheet)
|
|
257
|
+
if x.type in ("num", "blank"):
|
|
258
|
+
return num(x)
|
|
259
|
+
if x.type == "bool":
|
|
260
|
+
return Expr(f"CAST({x.sql} AS DOUBLE)", "num", x.err)
|
|
261
|
+
if x.type in ("txt", "err"):
|
|
262
|
+
return Expr("CAST(0 AS DOUBLE)", "num", x.err)
|
|
263
|
+
return Expr(f"(CASE WHEN {x.kind} = 's' THEN CAST(0 AS DOUBLE) ELSE {x.sql} END)", "num", x.err)
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
def _parity(name: str, odd: bool):
|
|
267
|
+
def fn(c, args, sheet):
|
|
268
|
+
arity(name, args, 1, 1)
|
|
269
|
+
x = num_strict(c.expr(args[0], sheet)) # an Analysis ToolPak function: TRUE/FALSE is #VALUE!
|
|
270
|
+
return Expr(f"(abs(trunc({x.sql})) % 2 {'=' if odd else '<>'} 1)", "bool", x.err)
|
|
271
|
+
register(name)(fn)
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
_parity("ISODD", True)
|
|
275
|
+
_parity("ISEVEN", False)
|
|
@@ -7,7 +7,7 @@ date formats to FORMATS.
|
|
|
7
7
|
"""
|
|
8
8
|
from __future__ import annotations
|
|
9
9
|
|
|
10
|
-
from cellproof.expr import BLANK, CELLS, NO_ERR, PLATFORM, Expr, errs, num, num_strict, num_text, txt, where_area
|
|
10
|
+
from cellproof.expr import BLANK, CELLS, NO_ERR, PLATFORM, UNCHECKED, Expr, errs, num, num_strict, num_text, txt, where_area
|
|
11
11
|
from cellproof.functions import arity, register
|
|
12
12
|
from cellproof.model import Unsupported
|
|
13
13
|
from cellproof.parser import Bool, RefNode, Str
|
|
@@ -264,3 +264,37 @@ def text(c, args, sheet):
|
|
|
264
264
|
return x
|
|
265
265
|
x = num(x)
|
|
266
266
|
return Expr(fmt(x.sql), "txt", x.err)
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
@register("CODE")
|
|
270
|
+
def code(c, args, sheet):
|
|
271
|
+
"""The Windows-1252 code of the first character (CHAR's inverse). A character outside Windows-1252 is
|
|
272
|
+
UNCHECKED; above 127 in a file Excel for Mac calculated, PLATFORM (Mac Roman differs)."""
|
|
273
|
+
arity("CODE", args, 1, 1)
|
|
274
|
+
t = _t(c, args[0], sheet)
|
|
275
|
+
first = f"substr({t.sql}, 1, 1)"
|
|
276
|
+
u = f"unicode({first})"
|
|
277
|
+
table = "'" + CP1252.replace("'", "''") + "'"
|
|
278
|
+
k = f"(CASE WHEN {u} < 128 OR {u} BETWEEN 160 AND 255 THEN {u} WHEN strpos({table}, {first}) > 0 THEN 127 + strpos({table}, {first}) END)"
|
|
279
|
+
mac = f"(CASE WHEN {k} > 127 THEN '{PLATFORM}' END)" if "Macintosh" in c.book.app else NO_ERR
|
|
280
|
+
odd = f"(CASE WHEN {t.sql} <> '' AND {k} IS NULL THEN '{UNCHECKED}' END)"
|
|
281
|
+
return Expr(f"CAST({k} AS DOUBLE)", "num", errs(t.err, _bad(f"{t.sql} = ''"), odd, mac))
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
@register("UNICODE")
|
|
285
|
+
def unicode_(c, args, sheet):
|
|
286
|
+
arity("UNICODE", args, 1, 1)
|
|
287
|
+
t = _t(c, args[0], sheet)
|
|
288
|
+
return Expr(f"CAST(unicode(substr({t.sql}, 1, 1)) AS DOUBLE)", "num", errs(t.err, _bad(f"{t.sql} = ''")))
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
@register("UNICHAR")
|
|
292
|
+
def unichar(c, args, sheet):
|
|
293
|
+
"""chr of the truncated number; 0 or beyond 1114111 is #VALUE!; a surrogate (55296-57343) is UNCHECKED."""
|
|
294
|
+
arity("UNICHAR", args, 1, 1)
|
|
295
|
+
n = _n(c, args[0], sheet)
|
|
296
|
+
k = f"TRY_CAST(trunc({n.sql}) AS BIGINT)"
|
|
297
|
+
bad = f"COALESCE({k} < 1 OR {k} > 1114111, TRUE)"
|
|
298
|
+
odd = f"(CASE WHEN {k} BETWEEN 55296 AND 57343 THEN '{UNCHECKED}' END)"
|
|
299
|
+
return Expr(f"(CASE WHEN NOT ({bad}) AND {k} NOT BETWEEN 55296 AND 57343 THEN chr(CAST({k} AS INTEGER)) END)",
|
|
300
|
+
"txt", errs(n.err, _bad(bad), odd))
|
|
@@ -64,7 +64,8 @@ def _runs(book: Book):
|
|
|
64
64
|
run, key0 = [], None
|
|
65
65
|
for row in rows + [None]:
|
|
66
66
|
cell = book.cells[(sheet, row, col)] if row is not None else None
|
|
67
|
-
ok = cell is not None and cell.formula is not None and not cell.array and cell.kind != "blank"
|
|
67
|
+
ok = (cell is not None and cell.formula is not None and not cell.array and cell.kind != "blank"
|
|
68
|
+
and cell.key not in book.unread) # not read, or DuckDB rejected it once: cell mode says why
|
|
68
69
|
shape = lex[(sheet, row, col)][0] if ok else None
|
|
69
70
|
ok, key = shape is not None, shape.key if shape is not None else None
|
|
70
71
|
if ok and run and row == run[-1] + 1 and key == key0:
|
|
@@ -15,6 +15,29 @@ from cellproof.model import Book, Cell, Key, Verdict, a1
|
|
|
15
15
|
class SqlFailed(Exception):
|
|
16
16
|
"""DuckDB rejected SQL that cellproof generated (a bug: every supported formula must run)."""
|
|
17
17
|
|
|
18
|
+
def __init__(self, message: str, keys: list):
|
|
19
|
+
super().__init__(message)
|
|
20
|
+
self.keys = keys # the cells of the batch DuckDB rejected
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
MAX_RECOMPILES = 50
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def verify_book(book: Book, compile_fn) -> tuple:
|
|
27
|
+
"""(compiled, verdicts, failures): verify; when DuckDB rejects a batch, its cells become UNRESOLVED with the reason
|
|
28
|
+
and the book is compiled again, so every cell reading them is "depends on unresolved cell" - none can read a
|
|
29
|
+
missing value. Each round removes a batch."""
|
|
30
|
+
failures = []
|
|
31
|
+
for _ in range(MAX_RECOMPILES):
|
|
32
|
+
compiled = compile_fn(book)
|
|
33
|
+
try:
|
|
34
|
+
return compiled, verify(book, compiled), failures
|
|
35
|
+
except SqlFailed as err:
|
|
36
|
+
failures.append(str(err))
|
|
37
|
+
for key in err.keys:
|
|
38
|
+
book.unread[key] = f"DuckDB could not run the SQL cellproof generated ({str(err).split('(', 1)[-1]}"
|
|
39
|
+
raise SqlFailed(f"DuckDB rejected SQL in {MAX_RECOMPILES} rounds; giving up", [])
|
|
40
|
+
|
|
18
41
|
|
|
19
42
|
def execute(book: Book, compiled: Compiled) -> dict[Key, tuple]:
|
|
20
43
|
"""The same row SQL as the dbt project: the seed, then each batch appended in place. Returns formula cells only."""
|
|
@@ -27,9 +50,9 @@ def execute(book: Book, compiled: Compiled) -> dict[Key, tuple]:
|
|
|
27
50
|
try:
|
|
28
51
|
con.execute(f"INSERT INTO cells {batch_rows(batch, 'cells')}")
|
|
29
52
|
except duckdb.Error as err:
|
|
30
|
-
# ponytail: the run stops; marking just this batch's cells (and their dependents) UNRESOLVED needs a recompile
|
|
31
53
|
raise SqlFailed(f"DuckDB could not run the SQL for {a1(batch[0].key)} and {len(batch) - 1} cells after it "
|
|
32
|
-
f"({str(err).splitlines()[0]}). This is a bug in cellproof; please report it."
|
|
54
|
+
f"({str(err).splitlines()[0]}). This is a bug in cellproof; please report it.",
|
|
55
|
+
[s.key for s in batch]) from err
|
|
33
56
|
wanted = {s.key for s in compiled.steps}
|
|
34
57
|
rows = con.execute("SELECT * FROM cells").fetchall()
|
|
35
58
|
return {(s, r, c): (k, n, t) for s, r, c, k, n, t in rows if (s, r, c) in wanted}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import io
|
|
2
|
+
import json
|
|
2
3
|
import sys
|
|
3
4
|
|
|
4
5
|
from xlsxkit import SALES, write_xlsx
|
|
@@ -90,3 +91,44 @@ def test_sql_that_duckdb_rejects_exits_3_with_the_cell(tmp_path, capsys, monkeyp
|
|
|
90
91
|
monkeypatch.setattr(verifier, "batch_rows", lambda batch, prev: "SELECT no_such_column")
|
|
91
92
|
assert main(["convert", str(wb), "--out", str(tmp_path / "out")]) == 3
|
|
92
93
|
assert "S!B1" in capsys.readouterr().err
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def test_sql_duckdb_rejects_makes_its_cells_and_their_readers_unresolved_not_the_run(tmp_path, monkeypatch, capsys):
|
|
97
|
+
# a bug in generated SQL (like 0.3.1's SUBSTITUTE on DuckDB 2.0) used to stop the whole run with no report
|
|
98
|
+
import cellproof.compiler as compiler
|
|
99
|
+
import cellproof.verifier as verifier
|
|
100
|
+
from xlsxkit import write_xlsx
|
|
101
|
+
monkeypatch.setattr(compiler, "BATCH", 1) # one cell per batch: B1's batch fails alone
|
|
102
|
+
wb = tmp_path / "b.xlsx"
|
|
103
|
+
write_xlsx(wb, {"S": {"A1": 2.0, "B1": ("=A1*3", 6.0), "C1": ("=B1+1", 7.0), "D1": ("=A1+10", 12.0)}})
|
|
104
|
+
real = verifier.batch_rows
|
|
105
|
+
|
|
106
|
+
def broken(batch, prev):
|
|
107
|
+
sql = real(batch, prev)
|
|
108
|
+
return sql.replace("* CAST(3.0 AS DOUBLE)", "* no_such_column") # only the batch holding B1 breaks
|
|
109
|
+
monkeypatch.setattr(verifier, "batch_rows", broken)
|
|
110
|
+
out = tmp_path / "out"
|
|
111
|
+
assert main(["convert", str(wb), "--out", str(out)]) == 3 # still says: this is a cellproof bug
|
|
112
|
+
report = json.loads((out / "report.json").read_text(encoding="utf-8"))
|
|
113
|
+
status = {c["cell"]: (c["status"], c["reason"]) for c in report["cells"]}
|
|
114
|
+
assert status["S!B1"][0] == "UNRESOLVED" and "DuckDB could not run" in status["S!B1"][1]
|
|
115
|
+
assert status["S!C1"][0] == "UNRESOLVED" and status["S!D1"] == ("PASS", "")
|
|
116
|
+
assert "please report" in capsys.readouterr().err
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def test_a_rejected_region_or_spill_is_not_rebuilt_forever(tmp_path, monkeypatch):
|
|
120
|
+
import cellproof.verifier as verifier
|
|
121
|
+
from test_dynamic import DATA, spill
|
|
122
|
+
from xlsxkit import write_xlsx
|
|
123
|
+
s = {f"A{r}": float(r) for r in range(1, 30)}
|
|
124
|
+
s.update({f"B{r}": (f"=A{r}*7", 7.0 * r) for r in range(1, 30)}) # a region
|
|
125
|
+
s.update(spill("D1", "_xlfn._xlws.SORT(A1:A3)", [[1.0], [2.0], [3.0]]))
|
|
126
|
+
wb = tmp_path / "b.xlsx"
|
|
127
|
+
write_xlsx(wb, {"S": s})
|
|
128
|
+
real = verifier.batch_rows
|
|
129
|
+
monkeypatch.setattr(verifier, "batch_rows", lambda b, p: real(b, p).replace("CAST(7.0 AS DOUBLE)", "nope")
|
|
130
|
+
.replace("ORDER BY", "ORDER BY nope,", 1))
|
|
131
|
+
out = tmp_path / "out"
|
|
132
|
+
assert main(["convert", str(wb), "--out", str(out)]) == 3
|
|
133
|
+
report = json.loads((out / "report.json").read_text(encoding="utf-8"))
|
|
134
|
+
assert {c["status"] for c in report["cells"]} == {"UNRESOLVED"}
|
|
@@ -248,7 +248,7 @@ def _spill_book(tmp_path):
|
|
|
248
248
|
write_xlsx(wb, {"S": {**DATA, **spill("J1", "_xlfn._xlws.SORT(_xlfn.UNIQUE(B2:B5))", [["East"], ["North"], ["West"]]),
|
|
249
249
|
**spill("K1", "_xlfn._xlws.FILTER(A2:C5,C2:C5>50)", [["Asha", "West", 80.0],
|
|
250
250
|
["Mina", "west", 60.0]]),
|
|
251
|
-
"
|
|
251
|
+
"O1": ("=J2&K2", "NorthMina")}}) # a cell reading spilled cells (outside K1:M2)
|
|
252
252
|
return wb, load(wb)
|
|
253
253
|
|
|
254
254
|
|
|
@@ -21,6 +21,8 @@ DATA = { # STDEV example column, the RANK example, the PERCENTILE/QUARTILE exam
|
|
|
21
21
|
**{f"E{i}": v for i, v in enumerate([3, 5, 3, 5, 4, 4, 2, 4, 6, 7], 1)},
|
|
22
22
|
"F1": 41235, "F2": 41247, "F3": 41295, "G1": 39778, "G2": 39786, "G3": 39834,
|
|
23
23
|
"H1": -10000, "H2": 3000, "H3": 4200, "H4": 6800, "H5": "note", "H7": "#N/A",
|
|
24
|
+
**{f"I{i}": v for i, v in enumerate([-70000, 12000, 15000, 18000, 21000, 26000], 1)},
|
|
25
|
+
"J1": -100.0, "J2": 230.0, "J3": -132.0, "J4": 0.0,
|
|
24
26
|
}
|
|
25
27
|
|
|
26
28
|
|
|
@@ -133,3 +135,29 @@ def test_workday_over_a_huge_holiday_range_stays_small():
|
|
|
133
135
|
t = time.time()
|
|
134
136
|
run([("=WORKDAY(39722,151,D!I1:XFD1048576)", 39933), ("=WORKDAY(39722,151,D!G1:G1048576)", 39938)])
|
|
135
137
|
assert time.time() - t < 10
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def _root(f, lo, hi):
|
|
141
|
+
from fractions import Fraction # an exact bisection, independent of the SQL
|
|
142
|
+
lo, hi = Fraction(lo), Fraction(hi)
|
|
143
|
+
for _ in range(200):
|
|
144
|
+
mid = (lo + hi) / 2
|
|
145
|
+
if (f(lo) < 0) == (f(mid) < 0):
|
|
146
|
+
lo = mid
|
|
147
|
+
else:
|
|
148
|
+
hi = mid
|
|
149
|
+
return float(lo)
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
def test_irr_and_rate_match_microsofts_examples_and_an_exact_root():
|
|
153
|
+
flows = [-70000, 12000, 15000, 18000, 21000, 26000]
|
|
154
|
+
npv = lambda vals: (lambda r: sum(v / (1 + r) ** k for k, v in enumerate(vals))) # noqa: E731
|
|
155
|
+
run([("=IRR(D!I1:I6)", _root(npv(flows), 0, 1)), ("=IRR(D!I1:I6)", (0.087, 3)),
|
|
156
|
+
("=IRR(D!I1:I5)", _root(npv(flows[:5]), -0.5, 0)), ("=IRR(D!I1:I5)", (-0.021, 3)),
|
|
157
|
+
("=IRR(D!I1:I3,-0.1)", _root(npv(flows[:3]), -0.9, -0.1)), ("=IRR(D!I1:I3,-0.1)", (-0.444, 3)),
|
|
158
|
+
("=IRR(D!I2:I4)", "#NUM!"), ("=IRR(D!J1:J4)", UNCHECKED), # all positive; two sign changes
|
|
159
|
+
("=RATE(4*12,-200,8000)", (0.0077, 4)), ("=RATE(4*12,-200,8000)*12", (0.0924, 4)),
|
|
160
|
+
("=RATE(10,-120,1000,0,0)", _root(lambda r: 1000 * (1 + r) ** 10 - 120 * ((1 + r) ** 10 - 1) / r,
|
|
161
|
+
"0.0001", "0.5")),
|
|
162
|
+
("=RATE(10,-100,1000)", UNCHECKED), # payments that only repay: rate 0, where Newton's step divides by 0
|
|
163
|
+
("=RATE(0,-100,1000)", UNCHECKED)])
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
from xlsxkit import book_of
|
|
3
|
+
|
|
4
|
+
from cellproof.compiler import compile_book
|
|
5
|
+
from cellproof.verifier import execute
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def run(sheets):
|
|
9
|
+
book = book_of(sheets)
|
|
10
|
+
compiled = compile_book(book)
|
|
11
|
+
return execute(book, compiled), compiled
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def test_sum_mixes_ranges_scalars_and_formula_cells():
|
|
15
|
+
got, c = run({"S": {"A1": 1, "A2": 2, "A3": "note", "A4": True, "A5": ("=A1*10", 10),
|
|
16
|
+
"B1": ("=SUM(A1:A5, 100)", 113)}})
|
|
17
|
+
assert c.unresolved == {} and got[("S", 1, 2)] == ("n", 113.0, None)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def test_sum_propagates_errors_and_handles_empty_ranges():
|
|
21
|
+
got, _ = run({"S": {"A1": ("=1/0", "#DIV/0!"), "B1": ("=SUM(A1:A2)", "#DIV/0!"), "C1": ("=SUM(Z1:Z9)", 0)}})
|
|
22
|
+
assert got[("S", 1, 2)] == ("e", None, "#DIV/0!")
|
|
23
|
+
assert got[("S", 1, 3)] == ("n", 0.0, None)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def test_sum_reports_numbers_stored_as_text():
|
|
27
|
+
got, c = run({"S": {"A1": 5, "A2": "15,000", "A3": ("=SUM(A1:A2)", 5)}})
|
|
28
|
+
assert got[("S", 3, 1)] == ("n", 5.0, None)
|
|
29
|
+
assert c.findings == ["S!A2: number stored as text ('15,000') is skipped by Excel"]
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def test_if_round_and_or_iferror():
|
|
33
|
+
got, c = run({"S": {
|
|
34
|
+
"A1": 120000, "A2": 2.675,
|
|
35
|
+
"B1": ("=IF(A1>100000, A1*5%, A1*2%)", 6000),
|
|
36
|
+
"B2": ("=ROUND(A2, 2)", 2.68),
|
|
37
|
+
"B3": ("=AND(A1>0, OR(A2<0, TRUE))", True),
|
|
38
|
+
"B4": ("=IFERROR(A1/0, -1)", -1),
|
|
39
|
+
"B5": ('=IF(A1>0, "big", "small")', "big"),
|
|
40
|
+
}})
|
|
41
|
+
assert c.unresolved == {}
|
|
42
|
+
assert got[("S", 1, 2)][1] == pytest.approx(6000)
|
|
43
|
+
assert got[("S", 2, 2)][1] == pytest.approx(2.68)
|
|
44
|
+
assert got[("S", 3, 2)] == ("b", 1.0, None)
|
|
45
|
+
assert got[("S", 4, 2)] == ("n", -1.0, None)
|
|
46
|
+
assert got[("S", 5, 2)] == ("s", None, "big")
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def test_if_with_wrong_argument_count_is_unresolved():
|
|
50
|
+
_, c = run({"S": {"A1": 1, "B1": ('=IF(A1>0, "yes", 0)', "yes"), "B2": ("=IF(A1)", 0)}})
|
|
51
|
+
assert ("S", 1, 2) not in c.unresolved # mixed branch types are fine since Plan 2b
|
|
52
|
+
assert c.unresolved[("S", 2, 2)] == "IF needs 2-3 arguments, got 1"
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def test_row_column_code_unicode_n_parity():
|
|
56
|
+
from cellproof.compiler import compile_book
|
|
57
|
+
from cellproof.verifier import execute
|
|
58
|
+
from xlsxkit import book_of
|
|
59
|
+
s = {"A1": "Apple", "A2": "€ uro", "A3": "Ā", "A4": True, "A5": 45000.0, "A6": "#DIV/0!",
|
|
60
|
+
"B1": ("=ROW()", 1.0), "B2": ("=COLUMN()", 2.0), "B3": ("=ROW(D7)", 7.0), "B4": ("=COLUMN(F1)", 6.0),
|
|
61
|
+
"B5": ("=ROW(A1:A3)", 1.0), # a range outside an array formula
|
|
62
|
+
"C1": ("=CODE(A1)", 65.0), "C2": ("=CODE(A2)", 128.0), "C3": ('=CODE("")', "#VALUE!"),
|
|
63
|
+
"C4": ("=CODE(A3)", 0.0), # not in Windows-1252: not guessed
|
|
64
|
+
"C5": ("=_xlfn.UNICODE(A2)", 8364.0), "C6": ("=_xlfn.UNICHAR(8364)", "€"),
|
|
65
|
+
"C7": ("=_xlfn.UNICHAR(0)", "#VALUE!"), "C8": ("=_xlfn.UNICHAR(55296)", "#N/A"),
|
|
66
|
+
"D1": ("=N(A5)", 45000.0), "D2": ("=N(A4)", 1.0), "D3": ("=N(A1)", 0.0), "D4": ("=N(A6)", "#DIV/0!"),
|
|
67
|
+
"D5": ("=ISODD(-3.7)", True), "D6": ("=ISEVEN(0)", True), "D7": ("=ISEVEN(A4)", "#VALUE!"),
|
|
68
|
+
"D8": ("=ISODD(B3)", True)}
|
|
69
|
+
book = book_of({"S": s})
|
|
70
|
+
compiled = compile_book(book)
|
|
71
|
+
got = execute(book, compiled)
|
|
72
|
+
assert set(compiled.unresolved) == {("S", 5, 2)}
|
|
73
|
+
want = {(1, 2): 1.0, (2, 2): 2.0, (3, 2): 7.0, (4, 2): 6.0, (1, 3): 65.0, (2, 3): 128.0, (5, 3): 8364.0,
|
|
74
|
+
(1, 4): 45000.0, (2, 4): 1.0, (3, 4): 0.0}
|
|
75
|
+
for (r, col), v in want.items():
|
|
76
|
+
assert got[("S", r, col)] == ("n", v, None), (r, col)
|
|
77
|
+
assert got[("S", 3, 3)] == ("e", None, "#VALUE!") and got[("S", 4, 3)] == ("e", None, "#UNCHECKED")
|
|
78
|
+
assert got[("S", 6, 3)] == ("s", None, "€") and got[("S", 7, 3)] == ("e", None, "#VALUE!")
|
|
79
|
+
assert got[("S", 8, 3)] == ("e", None, "#UNCHECKED") and got[("S", 4, 4)] == ("e", None, "#DIV/0!")
|
|
80
|
+
assert [got[("S", r, 4)] for r in (5, 6, 7, 8)] == [("b", 1.0, None), ("b", 1.0, None),
|
|
81
|
+
("e", None, "#VALUE!"), ("b", 1.0, None)]
|
|
@@ -179,7 +179,7 @@ def test_a_row_dependent_function_never_yields_a_region_value():
|
|
|
179
179
|
book = book_of({"S": spec})
|
|
180
180
|
scan = find_regions(book)
|
|
181
181
|
batch, rejected = compile_region(Compiler(book), scan.regions[0])
|
|
182
|
-
assert rejected == {2: "
|
|
182
|
+
assert rejected == {2: "ROW() in a block of rows not supported yet (stays row by row)"}
|
|
183
183
|
assert all(s.key[2] != 2 for s in batch)
|
|
184
184
|
|
|
185
185
|
|
|
@@ -98,3 +98,14 @@ def test_a_block_never_overwrites_another_formula_nor_builds_cells_the_file_lack
|
|
|
98
98
|
assert verdicts[("S", 3, 3)].status == "PASS" # C3 keeps its own formula
|
|
99
99
|
assert "overlaps" in bad[("S", 1, 3)][3] and ("S", 2, 3) not in verdicts # the block is not read
|
|
100
100
|
assert verdicts[("S", 2, 5)].status == "PASS" and ("S", 3, 5) not in verdicts # only the cells the file has
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def test_row_and_column_of_a_range_in_an_array_formula(tmp_path):
|
|
104
|
+
# formulas' test.xlsx (Excel-saved): ROW of a range is one column of row numbers (it repeats across), COLUMN
|
|
105
|
+
# one row; N of a range is N of its first cell; ISODD/ISEVEN do not take a range there (#VALUE!)
|
|
106
|
+
_, bad = check(tmp_path, {"P1": ("{=ROW(A1:A3)*10}", 10.0, "P1:P3"), "P2": 20.0, "P3": 30.0,
|
|
107
|
+
"Q1": ("{=COLUMN(E1:G1)}", 5.0, "Q1:S1"), "R1": 6.0, "S1": 7.0,
|
|
108
|
+
"P5": ("{=ROW(E1:G1)}", 1.0, "P5:R6"), "Q5": 1.0, "R5": 1.0, "P6": 1.0, "Q6": 1.0,
|
|
109
|
+
"R6": 1.0, "P8": ("{=N(A1:A3)}", 1.0, "P8:Q8"), "Q8": 1.0,
|
|
110
|
+
"P9": ("{=ISODD(A1:A3)}", "#VALUE!", "P9:P10"), "P10": "#VALUE!"})
|
|
111
|
+
assert bad == {}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "0.5.0"
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import pytest
|
|
2
|
-
from xlsxkit import book_of
|
|
3
|
-
|
|
4
|
-
from cellproof.compiler import compile_book
|
|
5
|
-
from cellproof.verifier import execute
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
def run(sheets):
|
|
9
|
-
book = book_of(sheets)
|
|
10
|
-
compiled = compile_book(book)
|
|
11
|
-
return execute(book, compiled), compiled
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
def test_sum_mixes_ranges_scalars_and_formula_cells():
|
|
15
|
-
got, c = run({"S": {"A1": 1, "A2": 2, "A3": "note", "A4": True, "A5": ("=A1*10", 10),
|
|
16
|
-
"B1": ("=SUM(A1:A5, 100)", 113)}})
|
|
17
|
-
assert c.unresolved == {} and got[("S", 1, 2)] == ("n", 113.0, None)
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
def test_sum_propagates_errors_and_handles_empty_ranges():
|
|
21
|
-
got, _ = run({"S": {"A1": ("=1/0", "#DIV/0!"), "B1": ("=SUM(A1:A2)", "#DIV/0!"), "C1": ("=SUM(Z1:Z9)", 0)}})
|
|
22
|
-
assert got[("S", 1, 2)] == ("e", None, "#DIV/0!")
|
|
23
|
-
assert got[("S", 1, 3)] == ("n", 0.0, None)
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
def test_sum_reports_numbers_stored_as_text():
|
|
27
|
-
got, c = run({"S": {"A1": 5, "A2": "15,000", "A3": ("=SUM(A1:A2)", 5)}})
|
|
28
|
-
assert got[("S", 3, 1)] == ("n", 5.0, None)
|
|
29
|
-
assert c.findings == ["S!A2: number stored as text ('15,000') is skipped by Excel"]
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
def test_if_round_and_or_iferror():
|
|
33
|
-
got, c = run({"S": {
|
|
34
|
-
"A1": 120000, "A2": 2.675,
|
|
35
|
-
"B1": ("=IF(A1>100000, A1*5%, A1*2%)", 6000),
|
|
36
|
-
"B2": ("=ROUND(A2, 2)", 2.68),
|
|
37
|
-
"B3": ("=AND(A1>0, OR(A2<0, TRUE))", True),
|
|
38
|
-
"B4": ("=IFERROR(A1/0, -1)", -1),
|
|
39
|
-
"B5": ('=IF(A1>0, "big", "small")', "big"),
|
|
40
|
-
}})
|
|
41
|
-
assert c.unresolved == {}
|
|
42
|
-
assert got[("S", 1, 2)][1] == pytest.approx(6000)
|
|
43
|
-
assert got[("S", 2, 2)][1] == pytest.approx(2.68)
|
|
44
|
-
assert got[("S", 3, 2)] == ("b", 1.0, None)
|
|
45
|
-
assert got[("S", 4, 2)] == ("n", -1.0, None)
|
|
46
|
-
assert got[("S", 5, 2)] == ("s", None, "big")
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
def test_if_with_wrong_argument_count_is_unresolved():
|
|
50
|
-
_, c = run({"S": {"A1": 1, "B1": ('=IF(A1>0, "yes", 0)', "yes"), "B2": ("=IF(A1)", 0)}})
|
|
51
|
-
assert ("S", 1, 2) not in c.unresolved # mixed branch types are fine since Plan 2b
|
|
52
|
-
assert c.unresolved[("S", 2, 2)] == "IF needs 2-3 arguments, got 1"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{cellproof-0.5.0 → cellproof-0.6.0}/docs/superpowers/specs/2026-10-14-plan-2c-speed-design.md
RENAMED
|
File without changes
|
{cellproof-0.5.0 → cellproof-0.6.0}/docs/superpowers/specs/2026-10-14-plan-2d-table-mode-design.md
RENAMED
|
File without changes
|
{cellproof-0.5.0 → cellproof-0.6.0}/docs/superpowers/specs/2026-10-18-running-totals-design.md
RENAMED
|
File without changes
|
{cellproof-0.5.0 → cellproof-0.6.0}/docs/superpowers/specs/2026-10-19-lookups-row-wise-design.md
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|