From ff581eac5326eea6e1ef8371d978c82bed8926f2 Mon Sep 17 00:00:00 2001 From: Naman Mistry Date: Sun, 14 May 2023 13:10:01 +0530 Subject: [PATCH] bug fixed:Unexpected Dropping of columns --- sklearn_pandas/dataframe_mapper.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/sklearn_pandas/dataframe_mapper.py b/sklearn_pandas/dataframe_mapper.py index ca4568e..04d83ef 100644 --- a/sklearn_pandas/dataframe_mapper.py +++ b/sklearn_pandas/dataframe_mapper.py @@ -124,10 +124,22 @@ def _build(self, X=None): """ Build attributes built_features and built_default. """ + if isinstance(self.features, list): - self.built_features = [ - _build_feature(*f, X=X) for f in self.features - ] + + filtered_list = [] + for obj in self.features: + if isinstance(obj[0], list): + new_cols = [col for col in obj[0] if col not in self.drop_cols] + + new_tuple = tuple([new_cols] + list(obj[1:])) + filtered_list.append(new_tuple) + else: + if obj[0] not in self.drop_cols: + filtered_list.append(obj) + self.features = filtered_list + + self.built_features = [_build_feature(*f, X=X) for f in self.features] else: self.built_features = _build_feature(*self.features, X=X) self.built_default = _build_transformer(self.default) @@ -322,6 +334,7 @@ def _transform(self, X, y=None, do_fit=False): Avoids code duplication for implementation of transform and fit_transform. """ + if do_fit: self._build(X=X)