Read Excel columns by name and skip blank rows (fixes #136) - #138
Open
KevinBamwisho wants to merge 1 commit into
Open
Read Excel columns by name and skip blank rows (fixes #136)#138KevinBamwisho wants to merge 1 commit into
KevinBamwisho wants to merge 1 commit into
Conversation
The Excel parser took column 0 as the question number, column 1 as the question and column 2 as the options, whatever the spreadsheet actually held. A sheet laid out as Questionnaire | Question # | Question text | Notes therefore ended up with the question number in question_text and the question itself in options, and blank rows used to separate one questionnaire from the next became questions with no text, which the schema rejects with a ValidationError. Look for a header row first and match the column names, falling back to the old positional reading when no header is recognised. A questionnaire column now splits a sheet into one instrument per questionnaire, and its name reaches both the instrument and its questions. A notes column is kept on the question, in place of the hardcoded "blah" intro.
KevinBamwisho
force-pushed
the
fix/excel-flexible-columns
branch
from
August 20, 2026 05:41
2a3451e to
4dcbfd1
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The Excel parser read columns by position: column 0 as the question number, column 1 as the question, column 2 as the options, whatever the sheet actually held.
The spreadsheet attached to #136 is laid out
Questionnaire | Question # | Question text | Notes, so on main it fails in two ways. The blank rows that separate one questionnaire from the next become questions with no text, and the schema rejects them:Delete those rows by hand and it parses, but everything is shifted one column over — the question number lands in
question_textand the question itself lands inoptions:With this change the same file, untouched, gives three instruments:
What it does:
Question,Question text,ItemandWordingare all recognised, as are question number, options, questionnaire and notes columns. Patterns match the whole cell so thatQuestion #is not mistaken forQuestion text.columns_by_position.question_intro, which was previously hardcoded to"blah".One decision worth your call: I put notes in
question_introbecause it is the only free text field onQuestionthat survives matching.topicslooked like the natural home butmatcher.pyoverwrites it (all_questions[idx].topics = q_topics), so anything from the spreadsheet would be thrown away. Happy to move it if you would rather it went elsewhere.No new dependencies, and one file changed plus one test file added.
Fixes #136
Type of change
Testing
New tests in
tests/test_convert_excel_fluid_format.pybuild real spreadsheets and cover: the layout from the issue, blank rows between questionnaires, the question text and question number columns being found, several instruments in one sheet, unique instrument ids, the instrument name reaching the questions, notes being kept, the name carrying down a block, alternative column names (Item,Response options), junk rows above the header, a sheet with no header falling back to positional reading, an empty sheet, and a header with no rows under it.Full test suite, run on this branch and on
mainfor comparison:mainat 098182cThe difference is exactly the 13 new tests. No existing test changed status.
Lint:
ruff check src testspasses.Harmony API: I checked out harmonyapi, pointed its
harmonysubmodule at this branch, started the API locally and rantests/local_tests: 19 passed, 7 failed. I then repeated it with the submodule back on unmodifiedmainand got the identical result, same 7 tests. Those 7 are the OpenAI, Azure OpenAI and Google Vertex cases, which need credentials I do not have, so they fail the same way with or without this change.I also POSTed the spreadsheet from #136 to
/text/parseon the running API and got HTTP 200 with the three instruments above, so the fix works through the API and not only in the library.Two unrelated things I hit while setting that up, in case they are useful. Not touched in this PR:
harmonyapi/requirements.txthas nogoogle-api-python-client, butwrapper_all_parsers.pyimportsgoogle_forms_parser, which needs it. With the submodule on currentmainthe API will not start until it is installed. The pinned submodule is older than Add Google Forms API integration for questionnaire import (closes #36) #126, which is why this is not showing up today.model_downloader.pyopens the models tarball withtarfile.open()and never closes it, then callsos.remove()on it. On Windows that raisesPermissionError: [WinError 32]. Linux allows unlinking an open file, so CI never sees it.Test Configuration
Checklist
requirements.txt,pyproject.tomland also in therequirements.txtin the API repo — none added here