Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
35151cc
expand parametrize with tests to all current classes
solegalli Jan 15, 2025
9d145a3
reorder creation imports, remove estimator checks
solegalli Jan 16, 2025
e6531d6
reorder inheritance datetime module
solegalli Jan 16, 2025
bd08d78
makes module creation compatible with sklearn 1.6
solegalli Jan 17, 2025
684b8bc
improves code style
solegalli Jan 17, 2025
20eb5eb
add sklearn tag to dateimte transformer
solegalli Jan 17, 2025
7a57b8b
makes discretization compatible with sklearn 1.6
solegalli Jan 17, 2025
ef1c257
makes encoding module compatible with sklearn 1.6
solegalli Jan 17, 2025
62b8f06
make imputation module compatible
solegalli Jan 17, 2025
06bbb26
make outlier module compatible
solegalli Jan 17, 2025
a2f71fb
make provisory fix for prediction module
solegalli Jan 17, 2025
fcb1c72
make preprocessing module compatible
solegalli Jan 17, 2025
d1b5c9e
make transformation module compatible with sklearn_tags (#836)
ClaudioSalvatoreArcidiacono Jan 21, 2025
f9145d6
make time_series module compatible (#834)
ClaudioSalvatoreArcidiacono Jan 21, 2025
8cb2c21
make wrappers module compatible (#835)
ClaudioSalvatoreArcidiacono Jan 21, 2025
30c8126
make selection module compatible
solegalli Jan 21, 2025
0e57c9c
fix style in feature engine module
solegalli Jan 21, 2025
15b2530
fix style in tests module
solegalli Jan 21, 2025
4115c71
fix mypy check
solegalli Jan 21, 2025
3ef2c66
add tags to woe
solegalli Jan 21, 2025
2378098
fix style
solegalli Jan 21, 2025
3a4aa7f
add test for sklearn 1.5
solegalli Jan 21, 2025
9c35fd6
remove circleci update
solegalli Jan 21, 2025
969c008
make some rewording on tags
solegalli Jan 21, 2025
3b0156b
remove redundant tag, reorder inheritance
solegalli Jan 21, 2025
74a723c
fix style
solegalli Jan 21, 2025
9d8c73b
Update tests/test_creation/test_check_estimator_creation.py
solegalli Jan 21, 2025
dc10fa3
Update tests/test_discretisation/test_check_estimator_discretisers.py
solegalli Jan 21, 2025
3be01fc
Update tests/test_encoding/test_check_estimator_encoders.py
solegalli Jan 21, 2025
849f7d8
Update tests/test_imputation/test_check_estimator_imputers.py
solegalli Jan 21, 2025
e2f84d6
fix style:
solegalli Jan 21, 2025
feb43b8
refactor check creation
solegalli Jan 21, 2025
7fad366
add todo
solegalli Jan 21, 2025
f046eaa
refactor check estimator selection
solegalli Jan 21, 2025
bc66eef
remove woe from testing
solegalli Jan 21, 2025
7fa78ca
remove dup code
solegalli Jan 22, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion feature_engine/_base_transformers/base_numerical.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@


class BaseNumericalTransformer(
BaseEstimator, TransformerMixin, GetFeatureNamesOutMixin
TransformerMixin, BaseEstimator, GetFeatureNamesOutMixin
):
"""Shared set-up procedures across numerical transformers, i.e.,
variable transformers, discretisers, math combination.
Expand Down Expand Up @@ -122,3 +122,7 @@ def _more_tags(self):
tags_dict = _return_tags()
tags_dict["variables"] = "numerical"
return tags_dict

def __sklearn_tags__(self):
tags = super().__sklearn_tags__()
return tags
4 changes: 4 additions & 0 deletions feature_engine/_prediction/base_predictor.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,3 +298,7 @@ def _predict(self, X: pd.DataFrame) -> np.ndarray:

def _more_tags(self):
return _return_tags()

def __sklearn_tags__(self):
tags = super().__sklearn_tags__()
return tags
7 changes: 6 additions & 1 deletion feature_engine/_prediction/target_mean_classifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from feature_engine._prediction.base_predictor import BaseTargetMeanEstimator


class TargetMeanClassifier(BaseTargetMeanEstimator, ClassifierMixin):
class TargetMeanClassifier(ClassifierMixin, BaseTargetMeanEstimator):
"""
The TargetMeanClassifier() estimates target values based on the average of the mean
target value per category or bin of a group of categorical and numerical variables.
Expand Down Expand Up @@ -185,3 +185,8 @@ def predict(self, X: pd.DataFrame) -> np.ndarray:
"""
y_pred = np.where(self._predict(X) > 0.5, self.classes_[1], self.classes_[0])
return y_pred

def __sklearn_tags__(self):
tags = super().__sklearn_tags__()
tags.classifier_tags.multi_class = False
return tags
2 changes: 1 addition & 1 deletion feature_engine/_prediction/target_mean_regressor.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from feature_engine._prediction.base_predictor import BaseTargetMeanEstimator


class TargetMeanRegressor(BaseTargetMeanEstimator, RegressorMixin):
class TargetMeanRegressor(RegressorMixin, BaseTargetMeanEstimator):
"""
The TargetMeanRegressor() outputs a target estimation based on the mean target
value per category or bin, across a group of categorical or numerical variables.
Expand Down
7 changes: 6 additions & 1 deletion feature_engine/creation/base_creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
)


class BaseCreation(BaseEstimator, TransformerMixin, GetFeatureNamesOutMixin):
class BaseCreation(TransformerMixin, BaseEstimator, GetFeatureNamesOutMixin):
"""Shared set-up, checks and methods across creation transformers."""

def __init__(
Expand Down Expand Up @@ -128,3 +128,8 @@ def _more_tags(self):
] = "this transformer works with datasets that contain at least 2 variables. \
Otherwise, there is nothing to combine"
return tags_dict

def __sklearn_tags__(self):
tags = super().__sklearn_tags__()
tags.input_tags.allow_nan = True
return tags
6 changes: 5 additions & 1 deletion feature_engine/creation/decision_tree_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
transform=_transform_creation_docstring,
fit_transform=_fit_transform_docstring,
)
class DecisionTreeFeatures(BaseEstimator, TransformerMixin, GetFeatureNamesOutMixin):
class DecisionTreeFeatures(TransformerMixin, BaseEstimator, GetFeatureNamesOutMixin):
"""
`DecisionTreeFeatures()` adds new variables to the data that result of the output of
decision trees trained with one or more features.
Expand Down Expand Up @@ -471,3 +471,7 @@ def _more_tags(self):
tags_dict["requires_y"] = True
tags_dict["variables"] = "numerical"
return tags_dict

def __sklearn_tags__(self):
tags = super().__sklearn_tags__()
return tags
6 changes: 5 additions & 1 deletion feature_engine/datetime/datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
fit=_fit_not_learn_docstring,
fit_transform=_fit_transform_docstring,
)
class DatetimeFeatures(BaseEstimator, TransformerMixin, GetFeatureNamesOutMixin):
class DatetimeFeatures(TransformerMixin, BaseEstimator, GetFeatureNamesOutMixin):
"""
DatetimeFeatures extracts date and time features from datetime variables, adding
new columns to the dataset. DatetimeFeatures can extract datetime information from
Expand Down Expand Up @@ -394,3 +394,7 @@ def _check_index_contains_na(self, index: pd.Index):
def _more_tags(self):
tags_dict = {"variables": "datetime"}
return tags_dict

def __sklearn_tags__(self):
tags = super().__sklearn_tags__()
return tags
4 changes: 4 additions & 0 deletions feature_engine/discretisation/arbitrary.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,3 +208,7 @@ def _more_tags(self):
"check_parameters_default_constructible"
] = "transformer has 1 mandatory parameter"
return tags_dict

def __sklearn_tags__(self):
tags = super().__sklearn_tags__()
return tags
4 changes: 4 additions & 0 deletions feature_engine/discretisation/decision_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,3 +345,7 @@ def _more_tags(self):
tags_dict["variables"] = "numerical"
tags_dict["requires_y"] = True
return tags_dict

def __sklearn_tags__(self):
tags = super().__sklearn_tags__()
return tags
6 changes: 5 additions & 1 deletion feature_engine/encoding/base_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def __init__(
self.missing_values = missing_values


class CategoricalMethodsMixin(BaseEstimator, TransformerMixin, GetFeatureNamesOutMixin):
class CategoricalMethodsMixin(TransformerMixin, BaseEstimator, GetFeatureNamesOutMixin):
"""Shared methods across categorical transformers.

- BaseEstimator brings methods get_params() and set_params().
Expand Down Expand Up @@ -299,3 +299,7 @@ def _more_tags(self):
# so we need to leave without this test
tags_dict["_xfail_checks"]["check_estimators_nan_inf"] = "transformer allows NA"
return tags_dict

def __sklearn_tags__(self):
tags = super().__sklearn_tags__()
return tags
2 changes: 1 addition & 1 deletion feature_engine/encoding/count_frequency.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
transform=_transform_encoders_docstring,
inverse_transform=_inverse_transform_docstring,
)
class CountFrequencyEncoder(CategoricalInitMixinNA, CategoricalMethodsMixin):
class CountFrequencyEncoder(CategoricalMethodsMixin, CategoricalInitMixinNA):
"""
The CountFrequencyEncoder() replaces categories by either the count or the
percentage of observations per category.
Expand Down
2 changes: 1 addition & 1 deletion feature_engine/encoding/decision_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
fit_transform=_fit_transform_docstring,
inverse_transform=_inverse_transform_docstring,
)
class DecisionTreeEncoder(CategoricalInitMixin, CategoricalMethodsMixin):
class DecisionTreeEncoder(CategoricalMethodsMixin, CategoricalInitMixin):
"""
The DecisionTreeEncoder() encodes categorical variables with the predictions
of a decision tree.
Expand Down
6 changes: 5 additions & 1 deletion feature_engine/encoding/mean_encoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
transform=_transform_encoders_docstring,
inverse_transform=_inverse_transform_docstring,
)
class MeanEncoder(CategoricalInitMixinNA, CategoricalMethodsMixin):
class MeanEncoder(CategoricalMethodsMixin, CategoricalInitMixinNA):
"""
The MeanEncoder() replaces categories by the mean value of the target for each
category.
Expand Down Expand Up @@ -266,3 +266,7 @@ def _more_tags(self):
tags_dict = super()._more_tags()
tags_dict["requires_y"] = True
return tags_dict

def __sklearn_tags__(self):
tags = super().__sklearn_tags__()
return tags
2 changes: 1 addition & 1 deletion feature_engine/encoding/one_hot.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
n_features_in_=_n_features_in_docstring,
fit_transform=_fit_transform_docstring,
)
class OneHotEncoder(CategoricalInitMixin, CategoricalMethodsMixin):
class OneHotEncoder(CategoricalMethodsMixin, CategoricalInitMixin):
"""
The OneHotEncoder() replaces categorical variables by a set of binary variables
representing each one of the unique categories in the variable.
Expand Down
2 changes: 1 addition & 1 deletion feature_engine/encoding/ordinal.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
transform=_transform_encoders_docstring,
inverse_transform=_inverse_transform_docstring,
)
class OrdinalEncoder(CategoricalInitMixinNA, CategoricalMethodsMixin):
class OrdinalEncoder(CategoricalMethodsMixin, CategoricalInitMixinNA):
"""
The OrdinalEncoder() replaces categories by ordinal numbers
(0, 1, 2, 3, etc). The numbers can be ordered based on the mean of the target
Expand Down
2 changes: 1 addition & 1 deletion feature_engine/encoding/rare_label.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
n_features_in_=_n_features_in_docstring,
fit_transform=_fit_transform_docstring,
)
class RareLabelEncoder(CategoricalInitMixinNA, CategoricalMethodsMixin):
class RareLabelEncoder(CategoricalMethodsMixin, CategoricalInitMixinNA):
"""
The RareLabelEncoder() groups rare or infrequent categories in
a new category called "Rare", or any other name entered by the user.
Expand Down
2 changes: 1 addition & 1 deletion feature_engine/encoding/similarity_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def _gpm_fast(x1: str, x2: str) -> float:
n_features_in_=_n_features_in_docstring,
fit_transform=_fit_transform_docstring,
)
class StringSimilarityEncoder(CategoricalInitMixin, CategoricalMethodsMixin):
class StringSimilarityEncoder(CategoricalMethodsMixin, CategoricalInitMixin):
"""
The StringSimilarityEncoder() replaces categorical variables with a set of float
variables that capture the similarity between the category names. The new variables
Expand Down
8 changes: 6 additions & 2 deletions feature_engine/encoding/woe.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def _calculate_woe(
transform=_transform_encoders_docstring,
inverse_transform=_inverse_transform_docstring,
)
class WoEEncoder(CategoricalInitMixin, CategoricalMethodsMixin, WoE):
class WoEEncoder(CategoricalMethodsMixin, CategoricalInitMixin, WoE):
"""
The WoEEncoder() replaces categories by the weight of evidence
(WoE). The WoE was used primarily in the financial sector to create credit risk
Expand Down Expand Up @@ -284,8 +284,12 @@ def _more_tags(self):
# in the current format, the tests are performed using continuous np.arrays
# this means that when we encode some of the values, the denominator is 0
# and this the transformer raises an error, and the test fails.
# For this reason, most sklearn transformers will fail. And it has nothing to
# For this reason, most sklearn tests will fail. And it has nothing to
# do with the class not being compatible, it is just that the inputs passed
# are not suitable
tags_dict["_skip_test"] = True
return tags_dict

def __sklearn_tags__(self):
tags = super().__sklearn_tags__()
return tags
7 changes: 6 additions & 1 deletion feature_engine/imputation/base_imputer.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from feature_engine.tags import _return_tags


class BaseImputer(BaseEstimator, TransformerMixin, GetFeatureNamesOutMixin):
class BaseImputer(TransformerMixin, BaseEstimator, GetFeatureNamesOutMixin):
"""shared set-up checks and methods across imputers"""

def _transform(self, X: pd.DataFrame) -> pd.DataFrame:
Expand Down Expand Up @@ -78,3 +78,8 @@ def _more_tags(self):
tags_dict["allow_nan"] = True
tags_dict["variables"] = "numerical"
return tags_dict

def __sklearn_tags__(self):
tags = super().__sklearn_tags__()
tags.input_tags.allow_nan = True
return tags
5 changes: 5 additions & 0 deletions feature_engine/imputation/categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,3 +257,8 @@ def _more_tags(self):
tags_dict["allow_nan"] = True
tags_dict["variables"] = "categorical"
return tags_dict

def __sklearn_tags__(self):
tags = super().__sklearn_tags__()
tags.input_tags.allow_nan = True
return tags
5 changes: 5 additions & 0 deletions feature_engine/imputation/drop_missing_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,3 +223,8 @@ def _more_tags(self):
tags_dict["allow_nan"] = True
tags_dict["variables"] = "all"
return tags_dict

def __sklearn_tags__(self):
tags = super().__sklearn_tags__()
tags.input_tags.allow_nan = True
return tags
5 changes: 5 additions & 0 deletions feature_engine/imputation/missing_indicator.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,8 @@ def _more_tags(self):
tags_dict["allow_nan"] = True
tags_dict["variables"] = "all"
return tags_dict

def __sklearn_tags__(self):
tags = super().__sklearn_tags__()
tags.input_tags.allow_nan = True
return tags
5 changes: 5 additions & 0 deletions feature_engine/imputation/random_sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,3 +275,8 @@ def _more_tags(self):
tags_dict["allow_nan"] = True
tags_dict["variables"] = "all"
return tags_dict

def __sklearn_tags__(self):
tags = super().__sklearn_tags__()
tags.input_tags.allow_nan = True
return tags
4 changes: 4 additions & 0 deletions feature_engine/outliers/artbitrary.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,3 +204,7 @@ def _more_tags(self):
"check_parameters_default_constructible"
] = "transformer has 1 mandatory parameter"
return tags_dict

def __sklearn_tags__(self):
tags = super().__sklearn_tags__()
return tags
12 changes: 10 additions & 2 deletions feature_engine/outliers/base_outlier.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
)


class BaseOutlier(BaseEstimator, TransformerMixin, GetFeatureNamesOutMixin):
class BaseOutlier(TransformerMixin, BaseEstimator, GetFeatureNamesOutMixin):
"""shared set-up checks and methods across outlier transformers"""

def _check_transform_input_and_state(self, X: pd.DataFrame) -> pd.DataFrame:
Expand Down Expand Up @@ -96,6 +96,10 @@ def _more_tags(self):
tags_dict["variables"] = "numerical"
return tags_dict

def __sklearn_tags__(self):
tags = super().__sklearn_tags__()
return tags


class WinsorizerBase(BaseOutlier):

Expand Down Expand Up @@ -289,7 +293,7 @@ def _more_tags(self):
tags_dict = _return_tags()
tags_dict["variables"] = "numerical"
# ======= this tests fail because the transformers throw an error
# when variance of the any input feature is 0.
# when variance of any input feature is 0.
# Nothing to do with the test itself but
# mostly with the data created and used in the test
msg = (
Expand All @@ -298,3 +302,7 @@ def _more_tags(self):
)
tags_dict["_xfail_checks"]["check_fit2d_1sample"] = msg
return tags_dict

def __sklearn_tags__(self):
tags = super().__sklearn_tags__()
return tags
2 changes: 1 addition & 1 deletion feature_engine/preprocessing/match_categories.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
n_features_in_=_n_features_in_docstring,
)
class MatchCategories(
CategoricalInitMixinNA, CategoricalMethodsMixin, GetFeatureNamesOutMixin
CategoricalMethodsMixin, CategoricalInitMixinNA, GetFeatureNamesOutMixin
):
"""
MatchCategories() ensures that categorical variables are encoded as pandas
Expand Down
6 changes: 5 additions & 1 deletion feature_engine/preprocessing/match_columns.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from feature_engine.tags import _return_tags


class MatchVariables(BaseEstimator, TransformerMixin, GetFeatureNamesOutMixin):
class MatchVariables(TransformerMixin, BaseEstimator, GetFeatureNamesOutMixin):
"""
MatchVariables() ensures that the same variables observed in the train set
are present in the test set. If the dataset to transform contains variables that
Expand Down Expand Up @@ -297,3 +297,7 @@ def _more_tags(self):
tags_dict["_xfail_checks"]["check_estimators_nan_inf"] = msg

return tags_dict

def __sklearn_tags__(self):
tags = super().__sklearn_tags__()
return tags
4 changes: 4 additions & 0 deletions feature_engine/selection/base_recursive_selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,3 +209,7 @@ def _more_tags(self):
tags_dict["_xfail_checks"]["check_fit2d_1feature"] = msg

return tags_dict

def __sklearn_tags__(self):
tags = super().__sklearn_tags__()
return tags
6 changes: 5 additions & 1 deletion feature_engine/selection/base_selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from feature_engine.tags import _return_tags


class BaseSelector(BaseEstimator, TransformerMixin, GetFeatureNamesOutMixin):
class BaseSelector(TransformerMixin, BaseEstimator, GetFeatureNamesOutMixin):
"""
Shared set-up checks and methods across selectors.

Expand Down Expand Up @@ -124,3 +124,7 @@ def _more_tags(self):
tags_dict["_xfail_checks"]["check_fit2d_1feature"] = msg

return tags_dict

def __sklearn_tags__(self):
tags = super().__sklearn_tags__()
return tags
5 changes: 5 additions & 0 deletions feature_engine/selection/drop_constant_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,3 +228,8 @@ def _more_tags(self):
"check_fit2d_1sample"
] = "the transformer raises an error when dropping all columns, ok to fail"
return tags_dict

def __sklearn_tags__(self):
tags = super().__sklearn_tags__()
tags.input_tags.allow_nan = True
return tags
5 changes: 5 additions & 0 deletions feature_engine/selection/drop_duplicate_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,3 +187,8 @@ def _more_tags(self):
tags_dict["_xfail_checks"]["check_fit2d_1feature"] = msg

return tags_dict

def __sklearn_tags__(self):
tags = super().__sklearn_tags__()
tags.input_tags.allow_nan = True
return tags
Loading