Skip to content

renames transform method in base classes to check_transform_input_and_state - #677

Merged
solegalli merged 5 commits into
mainfrom
fix_set_output_for_creation
Jun 7, 2023
Merged

renames transform method in base classes to check_transform_input_and_state#677
solegalli merged 5 commits into
mainfrom
fix_set_output_for_creation

Conversation

@solegalli

Copy link
Copy Markdown
Collaborator

fixes #670

@solegalli

Copy link
Copy Markdown
Collaborator Author

@ClaudioSalvatoreArcidiacono FYI

Would you like to have a look? All I did is rename the method in the base classes.

@codecov

codecov Bot commented Jun 6, 2023

Copy link
Copy Markdown

Codecov Report

Merging #677 (03a2b1a) into main (e73772d) will increase coverage by 0.07%.
The diff coverage is 99.32%.

@@            Coverage Diff             @@
##             main     #677      +/-   ##
==========================================
+ Coverage   97.91%   97.98%   +0.07%     
==========================================
  Files         100      100              
  Lines        3748     3829      +81     
  Branches      726      751      +25     
==========================================
+ Hits         3670     3752      +82     
+ Misses         29       28       -1     
  Partials       49       49              
Impacted Files Coverage Δ
feature_engine/datetime/datetime_subtraction.py 94.66% <ø> (ø)
feature_engine/tags.py 100.00% <ø> (ø)
feature_engine/selection/drop_psi_features.py 99.40% <98.55%> (+1.08%) ⬆️
...eature_engine/_base_transformers/base_numerical.py 100.00% <100.00%> (ø)
feature_engine/creation/base_creation.py 93.75% <100.00%> (ø)
feature_engine/creation/cyclical_features.py 100.00% <100.00%> (ø)
feature_engine/creation/math_features.py 97.77% <100.00%> (ø)
feature_engine/creation/relative_features.py 100.00% <100.00%> (ø)
feature_engine/discretisation/base_discretiser.py 100.00% <100.00%> (ø)
feature_engine/discretisation/decision_tree.py 100.00% <100.00%> (ø)
... and 17 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@ClaudioSalvatoreArcidiacono

Copy link
Copy Markdown
Contributor

Hey @solegalli, it would be a pleasure to help reviewing this PR!

@ClaudioSalvatoreArcidiacono

ClaudioSalvatoreArcidiacono commented Jun 6, 2023

Copy link
Copy Markdown
Contributor

Mh... I see that there are still some base classes that have not been updated, namely:

# 6 results - 6 files

# feature_engine/discretisation/base_discretiser.py:
  43:     def transform(self, X: pd.DataFrame) -> pd.DataFrame:

# feature_engine/encoding/base_encoder.py:
  192:     def transform(self, X: pd.DataFrame) -> pd.DataFrame:

# feature_engine/imputation/base_imputer.py:
  45:     def transform(self, X: pd.DataFrame) -> pd.DataFrame:

# feature_engine/outliers/base_outlier.py:
  66:     def transform(self, X: pd.DataFrame) -> pd.DataFrame:

# feature_engine/selection/base_selector.py:
  67:     def transform(self, X: pd.DataFrame) -> pd.DataFrame:

# feature_engine/timeseries/forecasting/base_forecast_transformers.py:
  168:     def transform(self, X: pd.DataFrame) -> pd.DataFrame:

is it intentional?

For BaseDiscretizer it is not needed as it extends BaseNumericalTransformer but I think others like CategoricalMethodsMixin should be updated

@ClaudioSalvatoreArcidiacono

Copy link
Copy Markdown
Contributor

I was wondering if there was a better way of solving this problem... like, why does scikit-learn need to re-convert the output of the transformer to pandas if it is already in pandas? Is it maybe needed to set something in the transformer to tell scikit-learn that the output of the transformer is always pandas? perhaps some output configs settings?

@ClaudioSalvatoreArcidiacono

Copy link
Copy Markdown
Contributor

I was wondering if there was a better way of solving this problem... like, why does scikit-learn need to re-convert the output of the transformer to pandas if it is already in pandas? Is it maybe needed to set something in the transformer to tell scikit-learn that the output of the transformer is always pandas? perhaps some output configs settings?

I see that this is not possible, sometimes columns in sklearn pipelines are renamed with the <step_name>.<col_name> convention, so even if the output of the estimator is a data frame, sklearn still needs to rename the columns of the data frame.

@solegalli

Copy link
Copy Markdown
Collaborator Author

Yeah, I looked at their source code and I also got the impression that it couldn't be done.

@solegalli

Copy link
Copy Markdown
Collaborator Author

Mh... I see that there are still some base classes that have not been updated, namely:

# 6 results - 6 files

# feature_engine/discretisation/base_discretiser.py:
  43:     def transform(self, X: pd.DataFrame) -> pd.DataFrame:

# feature_engine/encoding/base_encoder.py:
  192:     def transform(self, X: pd.DataFrame) -> pd.DataFrame:

# feature_engine/imputation/base_imputer.py:
  45:     def transform(self, X: pd.DataFrame) -> pd.DataFrame:

# feature_engine/outliers/base_outlier.py:
  66:     def transform(self, X: pd.DataFrame) -> pd.DataFrame:

# feature_engine/selection/base_selector.py:
  67:     def transform(self, X: pd.DataFrame) -> pd.DataFrame:

# feature_engine/timeseries/forecasting/base_forecast_transformers.py:
  168:     def transform(self, X: pd.DataFrame) -> pd.DataFrame:

is it intentional?

For BaseDiscretizer it is not needed as it extends BaseNumericalTransformer but I think others like CategoricalMethodsMixin should be updated

Thanks. I added tests for all transformers now, and changed the methods in the forecasting classes. Should be OK now.

I just missed them, there are too many, lol.

Thanks for flagging this.

@solegalli

Copy link
Copy Markdown
Collaborator Author

If test passes, I didn't change the class. Some, like BaseOutlier, the transform method IS the transform method. Not an intermediary step like in the other base classes.

@@ -1,5 +1,6 @@
import numpy as np
import pandas as pd

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change



@pytest.mark.parametrize("transformer", _estimators)
def test_transformers_in_pipeline_with_set_output_pandas(transformer):

@ClaudioSalvatoreArcidiacono ClaudioSalvatoreArcidiacono Jun 7, 2023

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This test will fail when

transformer = Winsorizer(add_indicators=True)

I would suggest to propagate the change also to the BaseOutlier Class

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Thank you! I missed it.

I had to make a workaround that doesn't make me happy to modify the BaseOutlier.

I need to look at class inheritance at some point. It's getting out of hand.

Thanks a lot for flagging this one!

@ClaudioSalvatoreArcidiacono

Copy link
Copy Markdown
Contributor

Hey @solegalli, I think I am done reviewing :)

I have left a couple of comments.

Again, thanks a lot for all of the passion you put in this library!

@solegalli

Copy link
Copy Markdown
Collaborator Author

Thanks a lot for the review @ClaudioSalvatoreArcidiacono I really appreciate it!!!

@solegalli
solegalli merged commit bbb0e0d into main Jun 7, 2023
@solegalli
solegalli deleted the fix_set_output_for_creation branch June 7, 2023 14:21
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.

Pipelines using pandas transform output do not work with feature creation

2 participants