Skip to content

Fix DropFeatures fail when features_to_drop is string, fixes issue 406 - #407

Merged
solegalli merged 6 commits into
feature-engine:mainfrom
noahjgreen295:fix_issue_406
Apr 6, 2022
Merged

Fix DropFeatures fail when features_to_drop is string, fixes issue 406#407
solegalli merged 6 commits into
feature-engine:mainfrom
noahjgreen295:fix_issue_406

Conversation

@noahjgreen295

Copy link
Copy Markdown
Contributor

Fix to issue #406 , where DropFeatures raises exception when instantiating with features_to_drop as string, even though docs and type hinting says string is supported.

"you wish to drop from the dataframe."
)

if isinstance(features_to_drop, str):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To follow sklearn conventions, we must not re-assign user' entered values in the init parameters.

Here, we need to let feature_to_drop be a string, and make it a list when we create features_to_drop_ in the fit method.

I am surprised that the check_estimator from sklearn did not pick this up. I was expecting the test to fail :_(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am wondering... if in this line we take 0 out of the list, so that DropFeatures(features_to_drop="0"), would then the error be raised with the current logic?

Would you check?

raise ValueError(
"features_to_drop should be a list with the name of the variables"
"features_to_drop should be a list with the name of the variables "
"you wish to drop from the dataframe."

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since we are working on this class... can we add f"Got {features_to_drop} instead." to the error message?

Thank you!

@solegalli solegalli left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @noahjgreen295 !!

A tiny change requested, to follow conventions...

@solegalli solegalli linked an issue Apr 4, 2022 that may be closed by this pull request
@noahjgreen295

Copy link
Copy Markdown
Contributor Author

OK made both changes!

  • Undid reassignment of string to list
  • Addition to exception message

@solegalli
solegalli merged commit cca7b4d into feature-engine:main Apr 6, 2022
@solegalli

Copy link
Copy Markdown
Collaborator

Thank you!!!

@noahjgreen295
noahjgreen295 deleted the fix_issue_406 branch April 6, 2022 21:38
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.

DropFeatures fails when features_to_drop is a string

2 participants