Repository navigation
Fix QA Excel parser dropping rows whose answer is a zero value - #17902
Conversation
The Excel branch of the QA parser skipped any cell with a falsy value, so an answer of 0, 0.0 or False was treated as empty. The row then had no answer, failed the `q and a` check and was silently discarded from the index instead of being reported as content. Use the same explicit emptiness test that deepdoc/parser/excel_parser.py adopted in infiniflow#16287, which keeps zero-valued cells and only skips None or whitespace-only cells. rag/app/tag.py imports this Excel class, so the same rows were being dropped from tag parsing as well.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review. 📝 WalkthroughWalkthroughExcel Q&A extraction now skips cells with ChangesExcel filtering
Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: ⚪ Minimal · up to This localized fix preserves zero-valued QA answers without changing the intended parsing path; no actionable merge-blocking risk remains at the current head. Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
ebarkhordar
left a comment
There was a problem hiding this comment.
Since the description says the tests could not run locally, I ran the before/after myself: today's main (ec9c08d80, where rag/app/qa.py is byte-identical to your branch except for line 53) against your head 935fca12, in a clean python:3.12 container with openpyxl, one row per case.
| row written to the sheet | main | this PR |
|---|---|---|
("plain question", "plain answer") |
kept | kept |
("how many retries", 0) |
dropped | kept as ("how many retries", "0") |
("what is the delta", 0.0) |
dropped | kept |
("is it enabled", False) |
dropped | kept |
("count of rows", 7) |
kept | kept |
4/7 pairs before, 5/7 after, so the zero-value fix does what you say, and it still applies clean to main two weeks on.
One effect the description does not mention: str(cell.value).strip() == "" also changes whitespace-only cells, which were truthy before.
| row | main | this PR |
|---|---|---|
(" ", "answer under a blank question") |
kept as a pair with a blank question | dropped, counted in fails |
("question with a blank answer", " ") |
kept as a pair with a blank answer | dropped, counted in fails |
That looks like the right call to me, since a blank question is not a question and the row now shows up in the failure line rather than entering the index. It is a second behaviour change though, and "Text and non-zero numeric answers were unaffected either way" does not quite cover it, so it is worth a sentence in the body.
On your last-remaining-site claim: parsing every file under rag/, deepdoc/, api/ and agent/ with ast and collecting truthiness tests on any .value attribute returns exactly one, rag/app/qa.py:53. It holds.
|
Thanks for the fix — the root cause (falsy 1. No regression test 2. Behavioral edge case — leading zero-valued column
This is a narrow / arguably invalid layout, but it is a genuine behavior change vs. the old code (which "benefited" from the bug for zero-leading columns). Non-zero leading columns were already mis-parsed before, so this is a pre-existing design limitation rather than something introduced here — but please document/acknowledge this edge case so it isn't a surprise. 3. The CodeRabbit docstring-coverage warning is a false positive Minor suggestion (non-blocking): add a short inline comment next to the new condition explaining why it must test |
|
Done. Details per point. 1. Regression test Added
With the one-line fix reverted and the test kept: With the fix: One detail for the record: openpyxl reads 2. Leading zero-valued column Confirmed. It is now in the body under "Other behaviour changes". Measured against the real parser:
The second row is the control. Any leading ID column already broke the pair, so this is the pre-existing limit you describe and not a new one. The I did not add a test for it. A test would lock in 3. CodeRabbit docstring coverage Agreed, no action. Inline comment Added one line above the condition: # A 0, 0.0, or False answer is falsy but is real content. |
|
Thanks for running the before/after, and for the AST pass on the last-site claim. You are right that the description did not cover the whitespace-only cells. I reproduced both of your rows and added them to the body under "Other behaviour changes". I also replaced the sentence you quoted.
|
|
@xugangqiang could you add the Without it every job reports SKIPPED, so this PR has never had its suite run. The check names still show the unexpanded #18713 was in the same state until the label landed on it yesterday. It then ran green across Both review points from 2026-08-19 are answered. The fix is still needed on current main: Nothing is pending from my side. |
|
LGTM @devYRPauli Thank you for this. Could you please check if go side has the same issue? |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #17902 +/- ##
==========================================
- Coverage 94.56% 91.34% -3.22%
==========================================
Files 10 10
Lines 717 716 -1
Branches 118 117 -1
==========================================
- Hits 678 654 -24
- Misses 25 36 +11
- Partials 14 26 +12 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
I checked the Go side. It does not have the same bug. The Go path turns each cell into a string before the check:
A I did find a different problem in the same function. I would like your view before I open a PR.
The reach differs by file type:
One limit on this check: I read the code only. I have no Go toolchain on this machine, so I did not run the Go tests. Shall I open a PR for the CSV column case? |
|
@devYRPauli please help to raise issue - and if possible, please help to fix. Thank you. |
|
Raised it as #19006. One correction to my earlier comment. I wrote that XLSX does not reach That changes the fix, not the report. Python holds two different rules:
Go serves both formats from one function. A strict two-field rule for CSV would also change XLSX, where the Go behavior is correct today. The issue sets out the two options. Tell me which contract you want and I will send that PR. I have no Go toolchain on this machine. I read the Go code and ran only the Python side. |
What problem does this PR solve?
The Excel branch of the QA parser drops any row whose answer is a zero value.
rag/app/qa.pyskipped cells withif not cell.value, which is falsy for0,0.0andFalseas well as for genuinely empty cells. When the answer column held one of those,astayed empty, the row failed theq and acheck and was appended tofails- so it was silently discarded from the index rather than surfaced as content.Reproduced with a 5-row sheet (openpyxl, unmodified parser loop):
The three lost rows had answers
0(int),0.0(float) andFalse(bool). Text and non-zero numeric answers give the same result before and after, which is why this is easy to miss. The new condition changes two other cases. See "Other behaviour changes" below.deepdoc/parser/excel_parser.pyalready hit this exact problem and fixed it in #16287 ("keep zero-valued cells when building Excel text chunks"). This ports the same test to the QA parser, which was the only remainingif not cell.valueinrag/app/ordeepdoc/.rag/app/tag.pydoesfrom rag.app.qa import Exceland instantiates it, so tag parsing was dropping the same rows.Other behaviour changes
The new condition tests for
Noneand for an empty string afterstrip(). This changes two more cases. I measured both against the real parser.1. Whitespace-only cells are now skipped. A cell that holds only spaces was truthy before, so it became a question or an answer.
(" ", "answer under a blank question")fails("question with a blank answer", " ")failsA blank question is not a question. The row now shows in the failure line instead of the index.
test_excel_drops_whitespace_only_cellslocks this in.2. A leading zero-valued column changes the pair. The parser takes the first two non-empty cells as the question and the answer.
[0, "Q", "A"]("Q", "A")("0", "Q")[5, "Q", "A"]("5", "Q")("5", "Q")The second row is the control. Any leading ID column already broke the pair, so this limit is not new. The
0case was correct before only because the bug skipped the cell. I did not add a test for this case. A test would lock in("0", "Q"), which is not the output we want. A correct fix needs a header row or a column count, and that is out of scope here.Test
test/unit_test/rag/app/test_qa_excel.pyis new. It follows the conventions of the siblingtest/unit_test/rag/app/test_qa_csv.py. It builds the sheet with openpyxl and callsqa.chunkwith a.xlsxname, so it drives the real parser path.With the one-line fix reverted and the test kept:
With the fix:
test_qa_csv.pystill gives 4 passed.ruff checkpasses on both changed files.Note for a local run:
pytest test/unit_test/rag/app/fails to collect four files, including the pre-existingtest_one.pyandtest_qa_csv.py, withImportError: cannot import name 'PlainParser' from 'deepdoc.parser.pdf_parser'. This comes from the stub intest/unit_test/rag/conftest.pyand is not related to this change. I ran the tests with--noconftest.Type of change