Repository navigation
fix(filters): count missing text cells as zero words in WordNumberFilter - #563
Merged
SunnyHaze merged 1 commit intoOct 19, 2026
Conversation
WordNumberFilter guarded each cell with `if text:`. That guard is False for
None but True for NaN, so a single null cell raised
AttributeError: 'float' object has no attribute 'split'
and aborted the whole run. Null cells are routine here: an upstream generator
that returns nothing for a row, or a left join that does not match, both leave
NaN in the text column.
Count any non-string cell as zero words instead, which is the behaviour the
existing else-branch already implied, and factor the counting into a helper so
the contract is testable on its own.
Also align the get_desc() defaults with the constructor (20 / 100000, not
5 / 100).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
WordNumberFilterguards every cell withif text:. That guard isFalseforNone, butTrueforNaN, becausebool(float("nan"))isTrue. So a single null cell raisesand aborts the whole run.
Why this is reachable in normal use
A null cell in the text column is routine:
jsonlwritten from aNonefield and read back asNaN.The traceback points at the
tqdmloop, so the offending row is not obvious.Fix
Count any non-string cell as zero words. That is already what the
elsebranch intended (word_counts.append(0)) — the bug is only thatNaNnever reaches it. The counting is factored into_count_words()so the contract can be tested on its own, andrun()keeps the same behaviour for every string cell.While in the file I also aligned the
get_desc()defaults with the constructor: the docs saidmin_words=5 / max_words=100, the constructor uses20 / 100000.Tests
test/cpu_only/test_word_number_filter_missing_values.py— 10 cases, all passing:None/NaNcells are counted as0and the run completes,_count_wordsonNone,NaN,pd.NA,42,""," ","one","one two three".I confirmed the two integration cases fail on
mainwith theAttributeErrorabove and pass with the patch.Scope note
BlocklistFilter.run()and the ~19 loops inrule_based_filter.pyuse the sameif text:guard, so they fail the same way on aNaNcell. I kept this PR to one operator to keep review small — happy to send the same treatment as a follow-up, or to widen this one if you prefer a single sweep.One more thing I noticed but did not change, because it is a behaviour change rather than a crash:
min_wordsis inclusive (<=) whilemax_wordsis exclusive (<), somax_words=100drops a text with exactly 100 words. Worth aligning if you agree it is unintended.