-
-
Notifications
You must be signed in to change notification settings - Fork 25.9k
FIX Error for sparse matrix in OrdinalEncoder.inverse_transform #19879
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
FIX Error for sparse matrix in OrdinalEncoder.inverse_transform #19879
Conversation
shouldn't the inverse transform support sparse matrices since the transform method can return a sparse matrix ? |
How to trigger this behaviour? I was not able to. When fitting on dense encoder.inverse_transform(sparse.csr_matrix(X_tr))
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
/tmp/xxx.py in
----> 32 encoder.inverse_transform(sparse.csr_matrix(X_tr))
~/Documents/packages/scikit-learn/sklearn/preprocessing/_encoders.py in inverse_transform(self, X)
882 found_unknown[i] = unknown_labels
883 else:
--> 884 X_tr[:, i] = self.categories_[i][labels]
885
886 # insert None values for unknown values
IndexError: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boolean arrays are valid indices but it might be because I am not able to trigger a sparse |
And I assume that |
transform can't return a sparse matrix indeed. The docstring is wrong. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm. Thanks @glemaitre !
Yes, I might solve it in the previous PR :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
closes #19878
OrdinalEncoder.inverse_transform
should not support sparse matrix. It was already failing but with an obscure message.This PR adds a non-regression test to check for the error message.