mirror of
https://github.com/langgenius/dify-official-plugins.git
synced 2026-07-21 17:45:23 -04:00
[Bug] tools/qa_chunk: KeyError when accessing CSV rows with integer column index (header-present CSV) #965
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @Olemi-llm-apprentice on GitHub (Feb 9, 2026).
Self Checks
Dify version
1.12.x (Knowledge Pipeline feature)
Plugin version
qa_chunk latest (commit
45f3b7c, Sep 4, 2025)Cloud or Self Hosted
Self Hosted (Docker)
Steps to reproduce
Bug Description
The
qa_chunkplugin (tools/qa_chunk/tools/qa.py) raises aKeyError: 1when processing any CSV file that has a header row. This makes the QA Processor node in Knowledge Pipeline unusable for standard CSV files.Root Cause
In
qa.pylines 42-43, the code accesses pandas DataFrame rows using integer column indices:However,
pd.read_csv()reads the first row as column names (strings) by default. When iterating withdf.iterrows(), eachrowis a pandas Series indexed by column names (strings), not integers. Accessingrow[1](integer) raisesKeyError: 1because the integer key1does not exist in the Series index.Steps to Reproduce
question_column=0,answer_column=1Result:
KeyError: 1Error message:
Suggested Fix
Replace label-based indexing with positional indexing using
iloc:Or alternatively, resolve column names first:
✔️ Error log
The error originates from
tools/qa_chunk/tools/qa.py, line 43:@dosubot[bot] commented on GitHub (Feb 9, 2026):
Hi @Olemi-llm-apprentice! I'm Dosu and I’m helping the dify-official-plugins team.
The KeyError happens because the code in
qa_chunkaccesses DataFrame rows using integer indices (likerow[1]), but when a CSV has headers, pandas rows are indexed by column names (strings), not integers. This causes the KeyError when processing standard CSV files with headers. The fix is to use positional indexing with.iloc, for example:row.iloc[int(question_column)], or to resolve the column names first and use them as keys (e.g.,row[df.columns[int(question_column)]]). No merged pull requests or issues currently address this bug, and the problem appears isolated toqa_chunk—updating the code as described will resolve the error when handling headered CSVs. You can see the relevant code and context here.To reply, just mention @dosu.
How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other