Skip to content

Test Excel workbooks with format: xlsx - #1720

Open
nicolehazel wants to merge 7 commits into
datacontract:mainfrom
nicolehazel:feat/xlsx-test-format
Open

nicolehazel wants to merge 7 commits into
datacontract:mainfrom
nicolehazel:feat/xlsx-test-format

Conversation

@nicolehazel

Copy link
Copy Markdown

Closes #1717

Adds format: xlsx to datacontract test, read through DuckDB's excel extension, with one sheet per schema named by its physicalName.

Each sheet is read twice and the reads are lined up row by row: once typed, so Excel dates (numbers with a date format) arrive as dates, and once as text, so a cell of the wrong type is still seen. A type check per column counts the cells that have a value but not the contract's type.

Possible follow-up: show the offending cells under --include-failed-samples, which today samples only missing, invalid and duplicate counts.

  • Tests pass (uv run pytest)
  • Code formatted (uv run ruff check --fix && uv run ruff format)
  • Docs updated (if relevant)
  • CHANGELOG.md entry added

Co-authored by a human (@nicolehazel) and Claude Code.

Read each sheet through DuckDB's excel extension, one sheet per schema
named by its physicalName. The sheet is read typed and as text, lined up
row by row, so Excel dates arrive as dates and a cell of the wrong type
fails its column's type check.

Closes datacontract#1717

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@nicolehazel
nicolehazel marked this pull request as ready for review October 10, 2026 20:26
nicolehazel and others added 4 commits October 13, 2026 09:37
Resolve conflicts with datacontract#1719 (per-path nested type checks) and the
v1.2.5/v1.2.6 releases: keep the xlsx type check ahead of the new
own_type block, take the new schema.md paragraph, and move the
changelog entry to Unreleased.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
The error for models that share a workbook without a physicalName now says "The model(s) ...", so it no longer reads as plural when only one model is missing its sheet name.
The installation table now labels the excel extra as import/export, next to xlsx for testing, and the Excel workbooks section notes that a sheet is cropped at its first empty header column.

@jschoedl jschoedl left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Hi, thank you for the PR. One small suggestion, apart from that LGTM!

"""
sheet = schema_obj.physicalName
view = sheet or schema_obj.name
options = f"'{_sql_literal(model_path)}', header=true"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

read_xlsx stops at the first empty row by default, so rows below a blank spacer row are never checked and the test still passes.

Could you pass stop_at_empty=false and skip the rows that are empty in every column? I think this should not be a big change, but would avoid confusion if a part of the table is silently thrown away

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks for the feedback!

Done in 173910c:

  • sheet is read with stop_at_empty=false, rows that are empty in every column are skipped
  • test_rows_below_an_empty_row_are_checked puts a blank row in the middle of the sheet and a wrong-typed value below it

nicolehazel and others added 2 commits October 16, 2026 18:41
Keep the xlsx changelog entry under Unreleased, above the v1.2.7 release.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
read_xlsx stops at the first empty row by default, so rows below a
blank spacer row went unchecked. Read the whole sheet and skip the rows
that are empty in every column.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support format: xlsx in datacontract test (DuckDB excel extension)

2 participants