Skip to content

FIX ColumnTransformer raise TypeError when remainder columns have incompatible dtype #20287

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

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion sklearn/compose/_column_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,13 @@ def _hstack(self, Xs):
return sparse.hstack(converted_Xs).tocsr()
else:
Xs = [f.toarray() if sparse.issparse(f) else f for f in Xs]
return np.hstack(Xs)

# convert to a common dtype explicitly before np.hstack
# detail see issue 20090
array_dtypes = [x.dtype if hasattr(x, 'dtype') else x.values.dtype
for x in Xs]
common_dtype = np.find_common_type(array_dtypes, [])
return np.hstack([x.astype(common_dtype) for x in Xs])

def _sk_visual_block_(self):
if isinstance(self.remainder, str) and self.remainder == 'drop':
Expand Down