Skip to content

Add rename_identical_headers option to get_all_records - #1602

Open
ChrisJr404 wants to merge 1 commit into
burnash:masterfrom
ChrisJr404:feature/rename-identical-headers
Open

Add rename_identical_headers option to get_all_records#1602
ChrisJr404 wants to merge 1 commit into
burnash:masterfrom
ChrisJr404:feature/rename-identical-headers

Conversation

@ChrisJr404

Copy link
Copy Markdown

Implements #1436.

get_all_records() raises when the header row has duplicate or blank entries, since they can't all be dictionary keys. This adds an opt-in rename_identical_headers flag so those headers are made unique instead, similar to how pandas reads a sheet like that:

# header row: A1, faff, C3, faff
records = worksheet.get_all_records(rename_identical_headers=True)
# keys become: A1, faff, C3, faff_1

The renaming itself lives in a new utils.make_headers_unique() helper (as suggested in the issue), so it's also usable on its own alongside to_records(). Blank headers get named after their column position, duplicates get a numbered suffix, and both patterns are overridable via a str.format template.

Default is False, so existing behavior is unchanged. Added unit tests for the helper and an integration test for the new flag, plus a note in the user guide.

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.

1 participant