From cf281d2afe9baf63f8149e6b4b4959caae82bf23 Mon Sep 17 00:00:00 2001 From: Elliot Williams Date: Fri, 29 May 2026 18:54:32 +0000 Subject: [PATCH] Fix IndexError in get_most_frequent when value_counts is empty 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 #770 --- supervised/preprocessing/preprocessing_utils.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/supervised/preprocessing/preprocessing_utils.py b/supervised/preprocessing/preprocessing_utils.py index f4896919..c314e4d3 100644 --- a/supervised/preprocessing/preprocessing_utils.py +++ b/supervised/preprocessing/preprocessing_utils.py @@ -111,6 +111,8 @@ def is_na(x): @staticmethod def get_most_frequent(x): a = x.value_counts() + if a.empty: + return None first = sorted(dict(a).items(), key=lambda x: -x[1])[0] return first[0]