fixed bug in drop_features - #596
Conversation
solegalli
left a comment
There was a problem hiding this comment.
Hey @luismavs thank you so much!
This is very helpful.
Could I ask you a few small things?
First, we need to fix code style. Here the error:
feature_engine/selection/drop_features.py:8:89: E501 line too long (89 > 88 characters)
feature_engine/selection/drop_features.py:10:1: E302 expected 2 blank lines, found 1
In short, we need to shorten 1 line and add a blank line to the other.
And also, could you use the syntax that you have in your comment to create a new test?
So that we ensure that we do not incur accidentally in the same error if we modify the class at some point.
Thank you!!
|
|
||
| self.features_to_drop_ = self.features_to_drop | ||
| self.features_to_drop_ = _find_all_variables(X, variables=self.features_to_drop) | ||
| # self.features_to_drop_ = self.features_to_drop |
There was a problem hiding this comment.
could you please remove the commented line?
There was a problem hiding this comment.
Hi,
I´ve pushed a new commit with the formatting changes you asked for, and an expanded version of the test test_drop_1_variable(...) which demonstrates the fix ( len('Marks') = len(X.columns) which was triggering the bug).
|
Hey @luismavs Thanks! There are still some codestyle errors. Do you have installed a tool called black? If you do, you just need to execute To reproduce the errors locally, you need to install flake and then execute Check the docs here These are the errors if you want to resolve manually: |
Codecov Report
@@ Coverage Diff @@
## main #596 +/- ##
=======================================
Coverage 97.79% 97.79%
=======================================
Files 90 90
Lines 3496 3497 +1
Branches 684 684
=======================================
+ Hits 3419 3420 +1
Misses 29 29
Partials 48 48
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
|
Hey, code has now been properly formatted with black, looks like good to go. |
| pd.testing.assert_frame_equal(X, df) | ||
|
|
||
| # checking features_to_drop has been correctly cast to list of str internally | ||
| transformer = DropFeatures(features_to_drop='Marks') |
There was a problem hiding this comment.
Hi, this looks good, but it took me a while to understand what this test was about, and why it is different from that in line 8.
Could we, instead of making it part of the current test, have a different test, just for this issue, with a clear name of what is being tested, and also in a comment add a link to the issue or PR?
| assert X.shape == (4, 4) | ||
| assert transformer.features_to_drop == "Marks" | ||
| assert type(X) == pd.DataFrame | ||
|
|
There was a problem hiding this comment.
could we please add an assert to compare the result of the transformation with what we expect from it? see line 27
| variables: Union[None, int, str, List[Union[str, int]]] = None, | ||
| ignore_format: bool = False, | ||
| ) -> None: | ||
|
|
There was a problem hiding this comment.
this file was probably modified with black, but it is not really part of this PR. Could we try and remove it please?
|
Thank you @luismavs !! It's all done now. That was a nasty bug you found :) |
Hi,
I found a bug in the DropFeatures transformer, module drop_features.py. The check (number of columns) in the .fit() method may fail unintentionally if features_to_drop is a string.
To fix this, I´ve applied the conversion of features_to_drop using the _find_all_variables method.