# Buggy code
def _validate_input(self, X):
    allowed_strategies = ["mean", "median", "most_frequent", "constant"]
    if self.strategy not in allowed_strategies:
        raise ValueError(
            "Can only use these strategies: {0}  got strategy={1}".format(
                allowed_strategies, self.strategy
            )
        )

    if self.strategy in ("most_frequent", "constant"):
        dtype = None
    else:
        dtype = FLOAT_DTYPES

    if not is_scalar_nan(self.missing_values):
        force_all_finite = True
    else:
        force_all_finite = "allow-nan"

    try:
        X = check_array(
            X,
            accept_sparse="csc",
            dtype=dtype,
            force_all_finite=force_all_finite,
            copy=self.copy,
        )
    except ValueError as ve:
        if "could not convert" in str(ve):
            raise ValueError(
                "Cannot use {0} strategy with non-numeric "
                "data. Received datatype :{1}."
                "".format(self.strategy, X.dtype.kind)
            )
        else:
            raise ve

    if X.dtype.kind not in ("i", "u", "f", "O"):
        raise ValueError(
            "SimpleImputer does not support data with dtype "
            "{0}. Please provide either a numeric array (with"
            " a floating point or integer dtype) or "
            "categorical data represented either as an array "
            "with integer dtype or an array of string values "
            "with an object dtype.".format(X.dtype)
        )

    return X


# Traceback (TypeError)
/home/lemaitre/Documents/code/toolbox/scikit-learn/sklearn/impute.py:59: FutureWarning: elementwise comparison failed; returning scalar instead, but in the future will perform elementwise comparison
return np.equal(X, value_to_mask)
/home/lemaitre/Documents/code/toolbox/scikit-learn/sklearn/impute.py:59: FutureWarning: elementwise comparison failed; returning scalar instead, but in the future will perform elementwise comparison
return np.equal(X, value_to_mask)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
~/miniconda3/envs/dev/lib/python3.6/site-packages/numpy/core/fromnumeric.py in _wrapfunc(obj, method, *args, **kwds)
51     try:
---> 52         return getattr(obj, method)(*args, **kwds)
53

TypeError: int() argument must be a string, a bytes-like object or a number, not 'NotImplementedType'

During handling of the above exception, another exception occurred:

TypeError                                 Traceback (most recent call last)
<ipython-input-18-151141bb4b39> in <module>()
----> 1 trans.fit_transform(X)

~/Documents/code/toolbox/scikit-learn/sklearn/base.py in fit_transform(self, X, y, **fit_params)
457         if y is None:
458             # fit method of arity 1 (unsupervised transformation)
--> 459             return self.fit(X, **fit_params).transform(X)
460         else:
461             # fit method of arity 2 (supervised transformation)

~/Documents/code/toolbox/scikit-learn/sklearn/impute.py in transform(self, X)
417             mask = _get_mask(X, self.missing_values)
418             n_missing = np.sum(mask, axis=0)
--> 419             values = np.repeat(valid_statistics, n_missing)
420             coordinates = np.where(mask.transpose())[::-1]
421

~/miniconda3/envs/dev/lib/python3.6/site-packages/numpy/core/fromnumeric.py in repeat(a, repeats, axis)
421
422     """
--> 423     return _wrapfunc(a, 'repeat', repeats, axis=axis)
424
425

~/miniconda3/envs/dev/lib/python3.6/site-packages/numpy/core/fromnumeric.py in _wrapfunc(obj, method, *args, **kwds)
60     # a downstream library like 'pandas'.
61     except (AttributeError, TypeError):
---> 62         return _wrapit(obj, method, *args, **kwds)
63
64

~/miniconda3/envs/dev/lib/python3.6/site-packages/numpy/core/fromnumeric.py in _wrapit(obj, method, *args, **kwds)
40     except AttributeError:
41         wrap = None
---> 42     result = getattr(asarray(obj), method)(*args, **kwds)
43     if wrap:
44         if not isinstance(result, mu.ndarray):

TypeError: int() argument must be a string, a bytes-like object or a number, not 'NotImplementedType'

# Fixed code
def _validate_input(self, X):
    allowed_strategies = ["mean", "median", "most_frequent", "constant"]
    if self.strategy not in allowed_strategies:
        raise ValueError(
            "Can only use these strategies: {0}  got strategy={1}".format(
                allowed_strategies, self.strategy
            )
        )

    if self.strategy in ("most_frequent", "constant"):
        dtype = None
    else:
        dtype = FLOAT_DTYPES

    if not is_scalar_nan(self.missing_values):
        force_all_finite = True
    else:
        force_all_finite = "allow-nan"

    try:
        X = check_array(
            X,
            accept_sparse="csc",
            dtype=dtype,
            force_all_finite=force_all_finite,
            copy=self.copy,
        )
    except ValueError as ve:
        if "could not convert" in str(ve):
            raise ValueError(
                "Cannot use {0} strategy with non-numeric "
                "data. Received datatype :{1}."
                "".format(self.strategy, X.dtype.kind)
            )
        else:
            raise ve

    _check_inputs_dtype(X, self.missing_values)
    if X.dtype.kind not in ("i", "u", "f", "O"):
        raise ValueError(
            "SimpleImputer does not support data with dtype "
            "{0}. Please provide either a numeric array (with"
            " a floating point or integer dtype) or "
            "categorical data represented either as an array "
            "with integer dtype or an array of string values "
            "with an object dtype.".format(X.dtype)
        )

    return X