Repository navigation
[MRG] FIX: raise error with inconsistent dtype X and missing_values - #11391
Conversation
| not isinstance(missing_values, numbers.Real)): | ||
| raise TypeError("The data type of 'missing_values' and 'X' are " | ||
| "not compatible. 'missing_values' data type is " | ||
| "{} and 'X' is {}." |
There was a problem hiding this comment.
In the rest of the code, we raise a ValueError for this kind of error, there is a discussion in #11211.
| # for X and missing_values was not raising a proper error. | ||
| X = np.random.randn(1000, 10) | ||
| X[0, 0] = X_missing_value | ||
|
|
There was a problem hiding this comment.
not sure 1000 is necessary here :)
| [SimpleImputer, ChainedImputer]) | ||
| @pytest.mark.parametrize( | ||
| "missing_values, X_missing_value, err_msg", | ||
| [("NaN", np.nan, "contains"), |
There was a problem hiding this comment.
Can you give more context for the contains error message? I don't know what the expected error is.
There was a problem hiding this comment.
It's the error raised by check_array when X contains NaN or inf and `force_all_finite=True:
Input contains NaN, infinity or a value too large for dtype('float64').
There was a problem hiding this comment.
right. would be easier to follow if it was "Input contains NaN" ...
jnothman
left a comment
There was a problem hiding this comment.
But aren't we still supporting missing_values='NaN'?
|
No, in |
|
Oh, yes, I'd forgotten that we resolved that...
|
|
@qinhanmin2014 @jnothman DO you have some remarks in order to move on on the MissingIndicator |
rth
left a comment
There was a problem hiding this comment.
LGTM apart for a few minor comments.
|
|
||
| def _check_inputs_dtype(X, missing_values): | ||
| """Check that the dtype of X is in accordance with the one of | ||
| missing_values.""" |
There was a problem hiding this comment.
I would phrase this in the other order
"""
Check that the type of missing_values is in accordance with the dtype of X.
"""
as that's what's we are checking right? I mean when we get this error, the user should change the value of missing_value not the other way around, right?
| def _check_inputs_dtype(X, missing_values): | ||
| """Check that the dtype of X is in accordance with the one of | ||
| missing_values.""" | ||
| if (X.dtype.kind in ("f", "i", "u") and |
| err_msg): | ||
| # regression test for issue #11390. Comparison between incoherent dtype | ||
| # for X and missing_values was not raising a proper error. | ||
| X = np.random.randn(10, 10) |
There was a problem hiding this comment.
Maybe use a random state (even if we don't care about the actual values)
|
|
||
|
|
||
| def _check_inputs_dtype(X, missing_values): | ||
| """Check that the type of missing_values is in accordance with the |
There was a problem hiding this comment.
I would remove this docstring, doesn't add much information or document it fully if you insist this function needs to be documented.
| """ | ||
| if (X.dtype.kind in ("f", "i", "u") and | ||
| not isinstance(missing_values, numbers.Real)): | ||
| raise ValueError("The data type of 'missing_values' and 'X' are " |
There was a problem hiding this comment.
Can you add what is expected? In general it's better when the error message says something like: "this is what was expected. Got this instead."
| @pytest.mark.parametrize("imputer_constructor", | ||
| [SimpleImputer, ChainedImputer]) | ||
| @pytest.mark.parametrize( | ||
| "missing_values, X_missing_value, err_msg", |
There was a problem hiding this comment.
X_missing_value may not be a great name since it seems to be a number
|
thx @glemaitre |
…cking in _get_mask Pin 526aede6a762ac6646211057d00a13304fb115b6 and its regression selectors for reproducible runs. Source: scikit-learn/scikit-learn#11391
closes #11390
Implement an additional check to avoid raising
NotImplementedfromnp.equalwhen the dtype ofXandmissing_valuesare inconsistent for a comparison.