Skip to content

Fix where skipping wrangles when all rows are filtered ou - #1007

Merged
ebhills merged 12 commits into
mainfrom
1005-bug-where-passes-empty-dataframe
Jul 2, 2026
Merged

Fix where skipping wrangles when all rows are filtered ou#1007
ebhills merged 12 commits into
mainfrom
1005-bug-where-passes-empty-dataframe

Conversation

@mborodii-prog

Copy link
Copy Markdown
Contributor

Fix: where skips wrangles when all rows are filtered out

Problem

When a where clause matched no rows, the resulting empty DataFrame was still passed into the wrangle for execution. This became an issue for chained wrangles where an earlier step creates a column that a later step depends on — because on an empty DataFrame no new columns are ever produced.

Failing example:

wrangles:
  - recipe:
      where: successful_search == True   # all False → empty DataFrame
      wrangles:
        - split.dictionary:
            input: scored_results        # runs but creates no columns (empty df)
        - split.dictionary:
            input: summary               # KeyError: column 'summary' does not exist

With input data:

scored_results successful_search
{} False

Error produced:

KeyError: 'ERROR IN WRANGLE #1 recipe - "ERROR IN WRANGLE #2 split.dictionary - \'Column summary does not exist\'"'

Fix

In wrangles/recipe.py, after _filter_dataframe(), added a four-line guard — if where produces an empty DataFrame, restore the original and continue to the next wrangle without executing:

df = _filter_dataframe(df, where=params.get('where'), ...)

# If where filters out all rows, skip the wrangle entirely
if len(df) == 0:
    df = df_original
    continue

Behaviour after fix

All rows filtered out → wrangle skipped, data unchanged:

scored_results successful_search
{} False

No error, no spurious columns added.

Partial match → still works correctly:

scored_results successful_search summary other key
{'summary': 'this is a summary', 'other key': '...'} True this is a summary ...
{} False `` ``

Only the matching row is processed; unmatched rows are merged back unchanged.

@mborodii-prog mborodii-prog linked an issue Jun 9, 2026 that may be closed by this pull request
2 tasks
@mborodii-prog
mborodii-prog requested a review from thomasstvr June 9, 2026 15:48
@mborodii-prog
mborodii-prog force-pushed the 1005-bug-where-passes-empty-dataframe branch from b876306 to 82640b9 Compare July 1, 2026 10:13
* enable package build on main branch
* Create Column should NOT error if column exists
* Add n parameter to lookup for multi-match retrieval
* convert.from_json and convert.from_yaml accept default as a list when input is also a list

* 985-enhancement-allow-list-of-onemultiple-defaults

@ebhills ebhills left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

There a column shift bug. I am running this recipe w batch size = 1:

wrangles:
  - convert.case:
      input: Desc
      output: output_column_name
      case: upper
      where: WC = "A"
Image

@mborodii-prog

Copy link
Copy Markdown
Contributor Author

@ebhills now it must be working fine (batch_size = 1)
image

@mborodii-prog
mborodii-prog requested a review from ebhills July 2, 2026 09:13
@ebhills
ebhills merged commit 673b076 into main Jul 2, 2026
19 checks passed
@ebhills
ebhills deleted the 1005-bug-where-passes-empty-dataframe branch July 2, 2026 19:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Where passes empty dataframe

2 participants