Skip to content
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

bug fixed: Unexpected Dropping of columns #263

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

namanmistry
Copy link

The bug was indicated in the Unexpected Dropping of columns issue where the user there was no effect of passing the drop_cols argument in the DataFrameMapper and the output columns were also wrong.

I have modified the _build(self, X=None): function inside DataFrameMapper class and added code to filter the columns based on self.drop_cols variable.

Previous build function:

 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
            ]
        else:
            self.built_features = _build_feature(*self.features, X=X)
        self.built_default = _build_transformer(self.default)

The modified function:

 def _build(self, X=None):
        """
        Build attributes built_features and built_default.
        """

        if isinstance(self.features, list):
 
            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)

This will filter the columns based on the self.drop_cols variable and will get the filtered columns. I am a beginner in open source contribution and this is my first pull request. Please feel free to give me any suggestions.

@namanmistry namanmistry marked this pull request as draft May 14, 2023 08:15
@namanmistry namanmistry marked this pull request as ready for review May 14, 2023 08:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant