Repository navigation
FIX check_transformer_data_not_an_array for ColumnTransformer - #29938
Merged
OmarManzoor merged 5 commits intoOct 7, 2024
Merged
Conversation
ogrisel
approved these changes
Sep 30, 2024
Member
There was a problem hiding this comment.
LGTM, thanks @mrastgoo!
For reference, here is the traceback one would get without the fix:
Details
__________________________________ test_estimators[ColumnTransformer(transformers=[('trans1',StandardScaler(),[0,1])])-check_transformer_data_not_an_array] __________________________________
estimator = ColumnTransformer(transformers=[('trans1', StandardScaler(), [0, 1])])
check = functools.partial(<function check_transformer_data_not_an_array at 0x123672de0>, 'ColumnTransformer')
request = <FixtureRequest for <Function test_estimators[ColumnTransformer(transformers=[('trans1',StandardScaler(),[0,1])])-check_transformer_data_not_an_array]>>
@parametrize_with_checks(list(_tested_estimators()))
def test_estimators(estimator, check, request):
# Common tests for estimator instances
with ignore_warnings(
category=(FutureWarning, ConvergenceWarning, UserWarning, LinAlgWarning)
):
> check(estimator)
sklearn/tests/test_common.py:120:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
sklearn/utils/_testing.py:140: in wrapper
return fn(*args, **kwargs)
sklearn/utils/estimator_checks.py:1594: in check_transformer_data_not_an_array
_check_transformer(name, transformer, this_X, this_y)
sklearn/utils/estimator_checks.py:1646: in _check_transformer
transformer.fit(X, y_)
sklearn/compose/_column_transformer.py:951: in fit
self.fit_transform(X, y=y, **params)
sklearn/utils/_set_output.py:319: in wrapped
data_to_wrap = f(self, X, *args, **kwargs)
sklearn/base.py:1244: in wrapper
return fit_method(estimator, *args, **kwargs)
sklearn/compose/_column_transformer.py:997: in fit_transform
self._validate_column_callables(X)
sklearn/compose/_column_transformer.py:551: in _validate_column_callables
transformer_to_input_indices[name] = _get_column_indices(X, columns)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
X = <sklearn.utils.estimator_checks._NotAnArray object at 0x123411e20>, key = [0, 1]
def _get_column_indices(X, key):
"""Get feature column indices for input data X and key.
For accepted values of `key`, see the docstring of
:func:`_safe_indexing`.
"""
key_dtype = _determine_key_type(key)
if _use_interchange_protocol(X):
return _get_column_indices_interchange(X.__dataframe__(), key, key_dtype)
> n_columns = X.shape[1]
E AttributeError: '_NotAnArray' object has no attribute 'shape'
sklearn/utils/_indexing.py:333: AttributeError
----------------------------------------------------------------------------------- Captured stdout setup ------------------------------------------------------------------------------------
I: Seeding RNGs with 1235426376
================================================================================== short test summary info ===================================================================================
FAILED sklearn/tests/test_common.py::test_estimators[ColumnTransformer(transformers=[('trans1',StandardScaler(),[0,1])])-check_transformer_data_not_an_array] - AttributeError: '_NotAnArray' object has no attribute 'shape'
OmarManzoor
approved these changes
Oct 7, 2024
OmarManzoor
left a comment
Contributor
There was a problem hiding this comment.
LGTM. Thanks @mrastgoo
BenJourdan
pushed a commit
to gregoryschwartzman/scikit-learn
that referenced
this pull request
Oct 11, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Reference Issues/PRs
What does this implement/fix? Explain your changes.
Removed the
_xfail.checksfromColumnTransformerfor the name of testcheck_transformer_data_not_an_arrayby adding if
hasattr(X, shape)to_check_X, after discussion with @glemaitre, @jeremiedbbAny other comments?