fix(preprocessors): stop CSVDocumentSplitter recursing forever on multi-block CSVs (#12190) - #12191
fix(preprocessors): stop CSVDocumentSplitter recursing forever on multi-block CSVs (#12190)#12191Anai-Guo wants to merge 1 commit into
Conversation
…ti-block CSVs `CSVDocumentSplitter._find_split_indices` returned pandas index/column *labels*, but `_split_dataframe` consumes them with positional `.iloc` slicing. On a sub-table produced by an earlier split, labels no longer match positions, so the `.iloc` slice failed to remove the detected empty row/column. `_recursive_split` then kept re-detecting the same empty section and recursed until RecursionError. Detect empty rows/columns by position so the split points stay consistent with the positional slicing. Sub-table index/column labels are still preserved, so the `row_idx_start`/`col_idx_start` metadata is unchanged. Fixes deepset-ai#12190
|
@Anai-Guo is attempting to deploy a commit to the deepset Team on Vercel. A member of the Team first needs to authorize it. |
|
|
|
Hi @Anai-Guo, thanks a lot for your contribution! 🙏 We noticed that the Contributor License Agreement (CLA) check ( To get your PR reviewed, please sign the CLA via the link in the |
|
Hi @Anai-Guo, just a friendly reminder: this PR is still in draft because the Contributor License Agreement (CLA) hasn't been signed yet. We'd love to review your contribution! Please sign the CLA via the link in the |
Related Issues
Fixes #12190
Proposed Changes
CSVDocumentSplitter.run()could raiseRecursionErrorwhen bothrow_split_thresholdandcolumn_split_thresholdare set and a later row block still needs a column split.Root cause:
_find_split_indicesreports empty rows/columns using pandas index/column labels, while_split_dataframeremoves them with positional.ilocslicing. For the top-level DataFrame the labels happen to equal the positions (aRangeIndex), so it works. But on a sub-table produced by an earlier split, the labels no longer match positions — e.g. an empty row at label6sits at position1in a 3-row sub-table.df.iloc[0:6]then returns the whole table unchanged, the empty row is never removed, and_recursive_splitkeeps re-detecting it and recurses until the interpreter's recursion limit is hit.The fix detects empty rows/columns by position (
enumerateover the boolean mask) so the split points stay consistent with the positional.ilocslicing. Sub-table index/column labels are left untouched, so therow_idx_start/col_idx_startmetadata (read fromsplit_df.index[0]/split_df.columns[0]) is unchanged. For the top-level DataFrame, positions equal labels, so existing behavior — including the_find_split_indicesunit tests — is preserved.How did you test it?
test_recursive_split_later_block_needs_column_split) using the exact CSV from the issue; it previously hitRecursionErrorand now returns 4 sub-tables with the correct content and metadata.TestFindSplitIndices,test_recursive_split_one_level, andtest_recursive_split_two_levelscases still produce identical results.Checklist
🤖 Generated with Claude Code