Skip to content

Added AllowFieldCountMismatch property to CsvConfiguration - #985

Draft
michelebastione wants to merge 2 commits into
mini-software:masterfrom
michelebastione:csv-jagged-rows
Draft

Added AllowFieldCountMismatch property to CsvConfiguration#985
michelebastione wants to merge 2 commits into
mini-software:masterfrom
michelebastione:csv-jagged-rows

Conversation

@michelebastione

@michelebastione michelebastione commented Jul 19, 2026

Copy link
Copy Markdown
Collaborator

The implementation of this property makes jagged rows being returned as they are instead of having an exception being thrown when a mismatched number of fields is found.

Resolves #979

Summary by CodeRabbit

  • New Features

    • Added an option to interpret empty CSV fields as default values.
    • Added support for reading rows with varying numbers of fields when field-count mismatches are allowed.
    • Improved handling of missing and additional columns during CSV import.
  • Bug Fixes

    • Corrected reported column names for missing-column errors.
  • Deprecation

    • Replaced the previous empty-string handling option with the new configuration setting.

@coderabbitai

coderabbitai Bot commented Jul 19, 2026

Copy link
Copy Markdown

Review Change Stack

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 03f9e4e4-a2cf-4c9c-a9eb-87f33d34dc8f

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

CsvReader.QueryAsync now handles empty fields and variable-width rows through the new ReadEmptyFieldsAsDefault option and existing mismatch configuration. Tests cover headered, headerless, and mapped jagged CSV rows.

Changes

CSV jagged-row handling

Layer / File(s) Summary
Empty-field configuration contract
src/MiniExcel.Csv/CsvConfiguration.cs
Adds ReadEmptyFieldsAsDefault and makes obsolete ReadEmptyStringAsNull delegate to it.
Row parsing and result mapping
src/MiniExcel.Csv/CsvReader.cs
Refactors row parsing, mismatch validation, synthetic columns, filler fields, and empty-field conversion for headered and headerless CSV data.
Jagged-row and exception coverage
tests/MiniExcel.Csv.Tests/Main/MiniExcelCsvAsyncTests.cs, tests/MiniExcel.Csv.Tests/Main/MiniExcelCsvTests.cs, tests/MiniExcel.Csv.Tests/Main/Models.cs
Adds jagged-row tests and DTO fields, and updates column-name and dictionary assertions.

Estimated code review effort: 3 (Moderate) | ~20 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly names the main change: adding CsvConfiguration support for mismatched CSV field counts.
Linked Issues check ✅ Passed The changes add AllowFieldCountMismatch, update CSV parsing to tolerate jagged rows, and add tests matching issue #979.
Out of Scope Changes check ✅ Passed The extra CSV empty-field and test/model updates appear to support the same jagged-row parsing feature and are not unrelated.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/MiniExcel.Csv/CsvReader.cs`:
- Around line 67-133: Update the invalid-row check before the header and
headerless branches to reject any field-count mismatch when
AllowFieldCountMismatch is false, not only rows where fields.Length is less than
headerRow.Count. Preserve the existing ColumnNotFoundException construction and
ensure both hasHeaderRow paths exit through this check before assigning fields.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: f567c7b8-2687-4a1f-bf0f-0c366b9d374b

📥 Commits

Reviewing files that changed from the base of the PR and between 3266e8b and 87445aa.

📒 Files selected for processing (5)
  • src/MiniExcel.Csv/CsvConfiguration.cs
  • src/MiniExcel.Csv/CsvReader.cs
  • tests/MiniExcel.Csv.Tests/Main/MiniExcelCsvAsyncTests.cs
  • tests/MiniExcel.Csv.Tests/Main/MiniExcelCsvTests.cs
  • tests/MiniExcel.Csv.Tests/Main/Models.cs

Comment thread src/MiniExcel.Csv/CsvReader.cs
@michelebastione
michelebastione marked this pull request as draft July 19, 2026 16:01
@michelebastione
michelebastione force-pushed the csv-jagged-rows branch 3 times, most recently from 077f1e6 to 6d1fa3e Compare July 22, 2026 22:00
The implementation of this property makes jagged rows being returned as they are instead of having an exception being thrown when a mismatched number of fields is found.
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.

[BUG] - Csv read error: Column 32 not found in Row 2

1 participant