Skip to content

fix(qa): preserve final CSV pair row number - #16433

Merged
wangq8 merged 15 commits into
infiniflow:mainfrom
Harsh23Kashyap:Harsh23Kashyap/fix/qa-csv-final-row
Jul 1, 2026
Merged

wangq8 merged 15 commits into
infiniflow:mainfrom
Harsh23Kashyap:Harsh23Kashyap/fix/qa-csv-final-row

Conversation

@Harsh23Kashyap

Copy link
Copy Markdown
Collaborator

What problem does this PR solve?

Fixes #16432.

The CSV branch of rag/app/qa.py appends the final Q&A pair after the csv.reader loop finishes. It currently uses len(list(reader)) for that final row number, but the reader is exhausted by then, so the final chunk gets top_int: [0].

This changes the final CSV append to use len(lines), matching the existing .txt branch.

Type of change

  • Bug Fix (non-breaking change which fixes an issue)

How has this been tested?

  • uv sync --group test
  • uv run pytest test/unit_test/rag/app/test_qa_csv.py -q
  • uvx ruff check rag/app/qa.py test/unit_test/rag/app/test_qa_csv.py

The new regression test fails before the fix with top_int == [0] for the final CSV pair and passes after the change.

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have added tests that prove my fix is effective or that my feature works

@dosubot dosubot Bot added size:XS This PR changes 0-9 lines, ignoring generated files. 🐞 bug Something isn't working, pull request that fix bug. 🧪 test Pull requests that update test cases. labels Jun 29, 2026
@coderabbitai

coderabbitai Bot commented Jun 29, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 40adc9d4-555f-4693-b4c4-8085526b6ea6

📥 Commits

Reviewing files that changed from the base of the PR and between 17a48cd and 3a8ff64.

📒 Files selected for processing (2)
  • rag/app/qa.py
  • test/unit_test/rag/app/test_qa_csv.py
🚧 Files skipped from review as they are similar to previous changes (2)
  • test/unit_test/rag/app/test_qa_csv.py
  • rag/app/qa.py

📝 Walkthrough

Walkthrough

In rag/app/qa.py, the CSV fallback append now uses len(lines) for the final pair’s row metadata. A new pytest module stubs tokenization and checks that two CSV rows produce chunks with top_int values [1] and [2].

Changes

CSV Q&A row number fix

Layer / File(s) Summary
CSV final pair row_num
rag/app/qa.py
The final CSV Q&A append now uses len(lines) instead of len(list(reader)) for row_num.
CSV chunking test
test/unit_test/rag/app/test_qa_csv.py
Adds a deterministic tokenizer fixture, a no-op callback, and a test asserting the final CSV chunk keeps the last line number.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~5 minutes

Poem

🐰 The CSV hare hopped through rows so neat,
The final pair now keeps its seat.
len(lines) counts the trail just right,
So top_int lands on line two.
Hoppity-hop, the numbers gleam! 🥕

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the fix to preserve the final CSV pair's row number.
Description check ✅ Passed The description covers the bug, fix, tests, and checklist, though it doesn't use the template's exact Summary heading.
Linked Issues check ✅ Passed The code and regression test directly address #16432 by using the original line count for the final CSV pair.
Out of Scope Changes check ✅ Passed The changes stay focused on the CSV row-number bug fix and its regression test.

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.

❤️ Share

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
test/unit_test/rag/app/test_qa_csv.py (1)

19-22: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Scope the pkg_resources warning suppression to the specific import path.

This runs during test-module import, so it mutates the process-wide warning filters for the rest of collection and can hide the same deprecation elsewhere in the suite. Please confine the suppression to the exact workaround instead of installing a global filter from one test module.

🤖 Prompt for 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.

In `@test/unit_test/rag/app/test_qa_csv.py` around lines 19 - 22, The warning
suppression in the test module is too broad because it installs a process-wide
filter at import time. Move the pkg_resources deprecation suppression to the
exact import workaround, using a local warnings context around the pkg_resources
import in test_qa_csv so the rest of collection is unaffected. Keep the fix
scoped to the import path and preserve the stabilization for the xgboost import.
🤖 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.

Nitpick comments:
In `@test/unit_test/rag/app/test_qa_csv.py`:
- Around line 19-22: The warning suppression in the test module is too broad
because it installs a process-wide filter at import time. Move the pkg_resources
deprecation suppression to the exact import workaround, using a local warnings
context around the pkg_resources import in test_qa_csv so the rest of collection
is unaffected. Keep the fix scoped to the import path and preserve the
stabilization for the xgboost import.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 1f94df06-c824-4f0e-b1c9-07df0cd668be

📥 Commits

Reviewing files that changed from the base of the PR and between 78db4e9 and 9b87c88.

📒 Files selected for processing (2)
  • rag/app/qa.py
  • test/unit_test/rag/app/test_qa_csv.py

@Harsh23Kashyap

Copy link
Copy Markdown
Collaborator Author

Could a maintainer please add the ci label when convenient? The fork workflows are skipped without it.

Local verification passed:

  • uv sync --group test
  • uv run pytest test/unit_test/rag/app/test_qa_csv.py -q
  • uvx ruff check rag/app/qa.py test/unit_test/rag/app/test_qa_csv.py

@Harsh23Kashyap
Harsh23Kashyap force-pushed the Harsh23Kashyap/fix/qa-csv-final-row branch from a6f504b to 17a48cd Compare June 30, 2026 04:49
@Harsh23Kashyap
Harsh23Kashyap force-pushed the Harsh23Kashyap/fix/qa-csv-final-row branch from 841b7a3 to 3a8ff64 Compare June 30, 2026 13:44
@Harsh23Kashyap

Copy link
Copy Markdown
Collaborator Author

Follow-up: branch is current with main (behind_by: 0). CodeRabbit passed; no unresolved review threads. Fork workflows are still skipped until a maintainer adds the ci label. Ready for review when you have a chance.

@wangq8 wangq8 added the ci Continue Integration label Jul 1, 2026
@codecov

codecov Bot commented Jul 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.16%. Comparing base (828c578) to head (4c07651).
⚠️ Report is 6 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #16433   +/-   ##
=======================================
  Coverage   93.16%   93.16%           
=======================================
  Files          10       10           
  Lines         717      717           
  Branches      118      118           
=======================================
  Hits          668      668           
  Misses         29       29           
  Partials       20       20           

☔ 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.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@wangq8
wangq8 merged commit b8e960e into infiniflow:main Jul 1, 2026
1 of 3 checks passed
@Harsh23Kashyap
Harsh23Kashyap deleted the Harsh23Kashyap/fix/qa-csv-final-row branch July 1, 2026 15:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐞 bug Something isn't working, pull request that fix bug. ci Continue Integration size:XS This PR changes 0-9 lines, ignoring generated files. 🧪 test Pull requests that update test cases.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Q&A CSV parser stores row 0 for the final pair

2 participants