8000 Improve SimpleImputer error message for incompatible fill_value types by Waknis · Pull Request #30828 · scikit-learn/scikit-learn · GitHub
[go: up one dir, main page]

Skip to content

Improve SimpleImputer error message for incompatible fill_value types #30828

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 6, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions sklearn/impute/_base.py
84F7
Original file line number Diff line number Diff line change
Expand Up @@ -391,16 +391,18 @@ def _validate_input(self, X, in_fit):
fill_value_dtype = type(self.fill_value)
err_msg = (
f"fill_value={self.fill_value!r} (of type {fill_value_dtype!r}) "
f"cannot be cast to the input data that is {X.dtype!r}. Make sure "
"that both dtypes are of the same kind."
f"cannot be cast to the input data that is {X.dtype!r}. "
"If fill_value is a Python scalar, instead pass a numpy scalar "
"(e.g. fill_value=np.uint8(0) if your data is of type np.uint8). "
"Make sure that both dtypes are of the same kind."
)
elif not in_fit:
fill_value_dtype = self.statistics_.dtype
err_msg = (
f"The dtype of the filling value (i.e. {fill_value_dtype!r}) "
f"cannot be cast to the input data that is {X.dtype!r}. Make sure "
"that the dtypes of the input data is of the same kind between "
"fit and transform."
f"cannot be cast to the input data that is {X.dtype!r}. "
"Make sure that the dtypes of the input data are of the same kind "
"between fit and transform."
)
else:
# By default, fill_value=None, and the replacement is always
Expand Down
0