Skip to content

Preserve original mapping keys when deriving CSV columns - #622

Merged
fabiocaccamo merged 2 commits into
fabiocaccamo:mainfrom
fhgffy:fix-csv-column-keys
Oct 11, 2026
Merged

fabiocaccamo merged 2 commits into
fabiocaccamo:mainfrom
fhgffy:fix-csv-column-keys

Conversation

@fhgffy

@fhgffy fhgffy commented Oct 10, 2026

Copy link
Copy Markdown
Contributor

Describe your changes
When no CSV columns are supplied, to_csv() converts the first row's keys to strings before looking up row values. Integer keys therefore produce empty cells: {1: "first", 2: "second"} is exported as 1,2\n,\n.

Keep the original keys for lookup and sort them by their string representation. Inferred headers keep their string labels, including None, while explicit columns keep their existing writer behavior. Regression cases cover integer keys, mixed string/integer keys, None keys, explicit None columns, and output without a header row.

Related issue
Found while checking serializer round trips; no existing issue found for this case.

Checklist before requesting a review

  • I have performed a self-review of my code.
  • I have added tests for the proposed changes.
  • I have run the tests and there are not errors.

Validation on Python 3.14: four regression cases fail on the original source; related tests pass (18 tests); the full suite passes (928 tests, 1 skipped); all pre-commit hooks including Ruff/mypy pass; wheel and sdist builds pass.

@codecov

codecov Bot commented Oct 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.51%. Comparing base (8c3371f) to head (686eb62).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #622   +/-   ##
=======================================
  Coverage   98.51%   98.51%           
=======================================
  Files          64       64           
  Lines        2430     2431    +1     
=======================================
+ Hits         2394     2395    +1     
  Misses         36       36           
Flag Coverage Δ
unittests 98.51% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@fabiocaccamo
fabiocaccamo merged commit c31b4c1 into fabiocaccamo:main Oct 11, 2026
18 checks passed
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.

2 participants