8000 ENH Improve SimpleImputer error message for incompatible fill_value t… · scikit-learn/scikit-learn@7cf4e42 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7cf4e42

Browse files
Waknisadrinjalali
andauthored
ENH Improve SimpleImputer error message for incompatible fill_value types (#30828)
Co-authored-by: Adrin Jalali <adrin.jalali@gmail.com>
1 parent 2d78745 commit 7cf4e42

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

sklearn/impute/_base.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -391,16 +391,18 @@ def _validate_input(self, X, in_fit):
391391
fill_value_dtype = type(self.fill_value)
392392
err_msg = (
393393
f"fill_value={self.fill_value!r} (of type {fill_value_dtype!r}) "
394-
f"cannot be cast to the input data that is {X.dtype!r}. Make sure "
395-
"that both dtypes are of the same kind."
394+
f"cannot be cast to the input data that is {X.dtype!r}. "
395+
"If fill_value is a Python scalar, instead pass a numpy scalar "
396+
"(e.g. fill_value=np.uint8(0) if your data is of type np.uint8). "
397+
"Make sure that both dtypes are of the same kind."
396398
)
397399
elif not in_fit:
398400
fill_value_dtype = self.statistics_.dtype
399401
err_msg = (
400402
f"The dtype of the filling value (i.e. {fill_value_dtype!r}) "
401-
f"cannot be cast to the input data that is {X.dtype!r}. Make sure "
402-
"that the dtypes of the input data is of the same kind between "
403-
"fit and transform."
403+
f"cannot be cast to the input data that is {X.dtype!r}. "
404+
"Make sure that the dtypes of the input data are of the same kind "
405+
"between fit and transform."
404406
)
405407
else:
406408
# By default, fill_value=None, and the replacement is always

0 commit comments

Comments
 (0)
0