Skip to content
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

Cryptic error in imputers due to missing checking in _get_mask #11390

Closed
glemaitre opened this issue Jun 29, 2018 · 0 comments · Fixed by #11391
Closed

Cryptic error in imputers due to missing checking in _get_mask #11390

glemaitre opened this issue Jun 29, 2018 · 0 comments · Fixed by #11391
Assignees
Milestone

Comments

@glemaitre
Copy link
Member

By working on the MissingIndicator it seems that there is a missing checking between X and missing_values dtype:

import numpy as np
X = np.array([[1.6464405 , 2.145568  , 1.80829   , 1.6346495 , 1.2709644 ],
              [1.3127615 , 2.675319  , 2.8906 , 2.1489816 , 0.8682183 ],
              [0.5495741 , 1.7595388 , 0.06032264, 2.4868202 , 0.01408643]],
             dtype=np.float32)
from sklearn.impute import SimpleImputer
trans = SimpleImputer(missing_values="NaN")
trans.fit_transform(X)
/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'

In short, NotImplement is raised by equal in case of numeric and string mixed dtype. We should put a check in _get_mask which is shared across classes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant