Fix IndexError in get_most_frequent when column is all null#824
Open
TheChyeahhh wants to merge 1 commit into
Open
Fix IndexError in get_most_frequent when column is all null#824TheChyeahhh wants to merge 1 commit into
TheChyeahhh wants to merge 1 commit into
Conversation
When PreprocessingMissingValues._fit_na_fill is called on a column containing exclusively null values, x.value_counts() returns an empty Series. The subsequent sorted(...)[0] then raises: IndexError: list index out of range This adds an early return of None for the empty case, allowing the caller to proceed with a safe fallback fill value. Fixes mljar#770
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.
Description
Fixes #770
When
PreprocessingMissingValuesencounters a column containing exclusively null values,x.value_counts()returns an empty Series. The subsequentsorted(...)[0]raises anIndexError: list index out of range.Fix
Added an early return of
Nonewhenvalue_counts()is empty, allowing the caller to proceed with a safe fallback fill value.Testing
value_counts()on a non-null column → returns most frequent value (existing behavior preserved)value_counts()on an all-null column → returnsNone(previously crashed)Changes
supervised/preprocessing/preprocessing_utils.py— 2 lines added