Repository navigation
[MRG + 1] Warn on 1D arrays, addresses #4511 - #5152
vighneshbirodkar wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
Surely this is appropriate iff ensure_2d is set?
There was a problem hiding this comment.
The check is redundant if ensure_2d is set.
There was a problem hiding this comment.
Oh. So what's wrong with 1d arrays if ensure_2d=False?
There was a problem hiding this comment.
I am a little confused myself now. Here is what I understand
- Warn against 1D arrays now and raise an error in later versions.
- If
ensure_2dis set, nothing to be done now. In later versionsensure_2dparameter is deprecated ?
There was a problem hiding this comment.
The problem is that the current ensure_2d does the wrong thing. I think we should change the behavior of ensure_2d from reshaping to warning / erroring.
There was a problem hiding this comment.
So should I go ahead with ensure_2d then ? It will warn now and throw an error in later versions
There was a problem hiding this comment.
Yes. this is only used internally and we can rename it later.
There was a problem hiding this comment.
If I remove the np.atleast_2d call I get 227 errors in the tests. It's my understanding that this PR should fix all of them ?
There was a problem hiding this comment.
They are probably many errors caused by the same underlying issues. But yes, indeed.
You should be able to just set the SingleDimensionWarning to "error" though (maybe at the top of the file if it is just for testing).
|
Mentioning #4511 for visibility (mentioning in the title will not show up there). |
|
@amueller Down to ~130 errors. I hope these little fixes are correct. |
There was a problem hiding this comment.
this seems odd. why does this need to be 2d? Y_norm_squared should be 1d.
There was a problem hiding this comment.
Many things were internally converted to 2D using the np.atleast2d call, without it, many tests are causing errors.
There was a problem hiding this comment.
but then this should probably be fixed in euclidean distances. the Y_norm_squared should be ok to be 1d.
There was a problem hiding this comment.
Okay, I have made a note of it.
There was a problem hiding this comment.
Can euclidian_distances check for 1d and do a conversion to 2d ?
|
@amueller The tests are passing now. There are 9 places where the new warning thrown, I will fix that soon. However, you also mentioned creating a common test for every estimator and ensure that a 1D input throws the new warning. But as far as I know, due to the 1D array, something most likely will fail later on. |
There was a problem hiding this comment.
This is mainly checking for sparse formats and finiteness. Since the _ensure_sparse_format is an internal function, I have kept the check_array call as it is.
|
@amueller |
There was a problem hiding this comment.
This needs a better message, like "Passing 1d arrays as data is deprecated and will be removed in 0.18. Reshape your data either using X.reshape(-1, 1) if your data has a single feature or X.reshape(1, -1) if it contains a single sample."
f52f1a7 to
492e364
Compare
|
ping @jnothman and @GaelVaroquaux who might be interested. |
|
Also maybe ping @ogrisel |
There was a problem hiding this comment.
Not related to this PR but this should be changed to dtype=np.float64 to be explicitly not platform dependent.
Passing 1D arrays to check_array, without setting `ensure_2d` to false now raises a deprecation warning before reshaping it. This will later throw an error. All Scaler classes also throw warnings when 1D arrays are passed. All unit tests/doctests are modified to ensure that no 1D arrays are passed, except in explicit 1D array tests where the warnings have been silenced. Additional tests are also included which check for different 1D array cases. 2D array tests with one samples and one features are also added and where they failed, `check_array` call has been modified to give a more useful error message
cda640d to
f760d27
Compare
There was a problem hiding this comment.
should we be consistent and also use [-1:] here?
|
LGTM apart from minor nitpicks |
|
@ogrisel wdyt? |
|
I will squash the commit, merge by rebase and document the change in |
|
Merged as 2f09933. Thanks @vighneshbirodkar! |
|
Thanks @vighneshbirodkar, this is really helpful. Thanks for the review @ogrisel. |
Just to reiterate the discussion I had with @amueller in person
I have put a check in
check_arrayand issued a warning. I will proceed to fix the tests now.