Skip to content

fix(preprocessors): stop CSVDocumentSplitter recursing forever on multi-block CSVs (#12190) - #12191

Draft
Anai-Guo wants to merge 1 commit into
deepset-ai:mainfrom
Anai-Guo:fix-csv-splitter-recursionerror
Draft

fix(preprocessors): stop CSVDocumentSplitter recursing forever on multi-block CSVs (#12190)#12191
Anai-Guo wants to merge 1 commit into
deepset-ai:mainfrom
Anai-Guo:fix-csv-splitter-recursionerror

Conversation

@Anai-Guo

Copy link
Copy Markdown

Related Issues

Fixes #12190

Proposed Changes

CSVDocumentSplitter.run() could raise RecursionError when both row_split_threshold and column_split_threshold are set and a later row block still needs a column split.

Root cause: _find_split_indices reports empty rows/columns using pandas index/column labels, while _split_dataframe removes them with positional .iloc slicing. For the top-level DataFrame the labels happen to equal the positions (a RangeIndex), 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 label 6 sits at position 1 in a 3-row sub-table. df.iloc[0:6] then returns the whole table unchanged, the empty row is never removed, and _recursive_split keeps re-detecting it and recurses until the interpreter's recursion limit is hit.

The fix detects empty rows/columns by position (enumerate over the boolean mask) so the split points stay consistent with the positional .iloc slicing. Sub-table index/column labels are left untouched, so the row_idx_start / col_idx_start metadata (read from split_df.index[0] / split_df.columns[0]) is unchanged. For the top-level DataFrame, positions equal labels, so existing behavior — including the _find_split_indices unit tests — is preserved.

How did you test it?

  • Added a regression test (test_recursive_split_later_block_needs_column_split) using the exact CSV from the issue; it previously hit RecursionError and now returns 4 sub-tables with the correct content and metadata.
  • Verified the existing TestFindSplitIndices, test_recursive_split_one_level, and test_recursive_split_two_levels cases still produce identical results.

Checklist

🤖 Generated with Claude Code

…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
Anai-Guo requested a review from a team as a code owner July 29, 2026 22:11
@Anai-Guo
Anai-Guo requested review from davidsbatista and removed request for a team July 29, 2026 22:11
@vercel

vercel Bot commented Jul 29, 2026

Copy link
Copy Markdown

@Anai-Guo is attempting to deploy a commit to the deepset Team on Vercel.

A member of the Team first needs to authorize it.

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@HaystackBot

Copy link
Copy Markdown
Contributor

Hi @Anai-Guo, thanks a lot for your contribution! 🙏

We noticed that the Contributor License Agreement (CLA) check (license/cla) hasn't passed yet, so we've temporarily moved this PR to draft and paused the review assignment.

To get your PR reviewed, please sign the CLA via the link in the license/cla check below (or in the CLA bot comment). As soon as the check turns green, this PR will automatically be marked ready for review again and a reviewer will be re-assigned.

@HaystackBot
HaystackBot removed the request for review from davidsbatista July 29, 2026 23:39
@HaystackBot HaystackBot added the cla-pending PR is in draft until the contributor signs the CLA label Jul 29, 2026
@HaystackBot
HaystackBot marked this pull request as draft July 29, 2026 23:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-pending PR is in draft until the contributor signs the CLA topic:tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CSVDocumentSplitter._recursive_split raises RecursionError on some multi-block CSVs with row and column thresholds set

3 participants