Skip to content

Add: Docstring return empty#938

Merged
solegalli merged 7 commits into
feature-engine:variable-handling-extensionfrom
miriam-mendez:docstring-return_empty
Jul 18, 2026
Merged

Add: Docstring return empty#938
solegalli merged 7 commits into
feature-engine:variable-handling-extensionfrom
miriam-mendez:docstring-return_empty

Conversation

@miriam-mendez

Copy link
Copy Markdown
Contributor

No description provided.

@solegalli
solegalli merged commit fd360cd into feature-engine:variable-handling-extension Jul 18, 2026
2 of 13 checks passed
solegalli added a commit that referenced this pull request Jul 20, 2026
* add return_empty attr to base_numerical.py (#937)

* add return_empty attr to base_numerical

* Apply suggestion from @solegalli

* Apply suggestion from @solegalli

* code-style

---------

Co-authored-by: Soledad Galli <solegalli@protonmail.com>

* Add: Docstring return empty (#938)

* add: return_empty docstring

* chore: minor fix for tests

* push str to the next line

* expand substitute

* minor fix for flake8

---------

Co-authored-by: Soledad Galli <solegalli@protonmail.com>

* fix mypy error on categorical imputer (#939)

* add return_empty on creation fix typo in module name (#942)

* add return_empty on creation

* typo

* adding _check_return_empty_is_bool

* add return_empty to discretisers (#943)

* adding return_empty attr

* codestyle

* more codestyle

* add return_empty in imputation (#945)

* add: return_empty in imputation

* minor-fix: flake8 style

* clearn deprecation, future and other warnings (#944)

* clearn deprecation warnings

* fix warnings in pipeline tests

* remove more warnings in tests

* more changes

* revert changes

* add return_false to encoder + fix mock (#947)

* add return_empty to transformation, scaling, outliers, datetime, time… (#948)

* add return_empty to transformation, scaling, outliers, datetime, timeseries and wrapper transformers

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* remove missplaced tests

---------

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>

* fix return_empty exposure in discretisers (#949)

* fix return_empty exposure in discretisers and add tests for existing return_empty transformers

EqualFrequencyDiscretiser, EqualWidthDiscretiser and GeometricWidthDiscretiser
advertised return_empty in their docstrings but did not accept it in __init__,
so users could not enable it. ArbitraryDiscretiser selects variables from
binning_dict and does not support the parameter, so the unused docstring
wiring is removed.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* remove missplaced tests

---------

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>

* [WIP] first changes towards deprecation warning (#950)

* add return_empty tests via shared estimator_checks (#951)

* add return_empty tests via shared estimator check, plus family-specific tests

Adds check_return_empty to fit_functionality_checks.py and wires it into
check_feature_engine_estimator, so it runs automatically for every transformer
that already goes through that shared pipeline (transformation, discretisation,
encoding, imputation, outliers, most of creation, forecasting).

For transformers not fed through check_feature_engine_estimator, tests are
added directly in their existing per-class test files, following the file's
established conventions: DecisionTreeFeatures, DatetimeSubtraction,
MeanNormalizationScaler and SklearnTransformerWrapper.

DatetimeOrdinal needs a clone-free test, since its __init__ never stores
self.start_date, which breaks sklearn's get_params()/clone() for this class
independently of return_empty.

DecisionTreeEncoder's return_empty=True path is documented as currently
raising ValueError (a real bug: it builds a nested OrdinalEncoder(variables=[])
whose constructor rejects the explicit empty list), rather than silently
asserting the intended contract.

AddMissingIndicator, DropMissingData and RandomSampleImputer (variables="all")
and SklearnTransformerWrapper wrapping an "all-types" transformer are not
testable this way: find_all_variables only raises on a zero-column dataframe,
which check_X rejects before variable selection ever runs.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* remove unnecessary filter

* remove return_empty from shared base classes where subclasses don't need it

BaseCreation, BaseDiscretiser and CategoricalInitMixinNA each set
self.return_empty unconditionally, even though some of their subclasses never
read it: MathFeatures and RelativeFeatures (variables is mandatory, never
None), and ArbitraryDiscretiser (fit() is fully overridden, selecting
variables from binning_dict instead of find_numerical_variables). Those
classes ended up with a dead return_empty attribute that isn't a real,
settable constructor parameter (hasattr is True, get_params() is False),
which also meant the test gate had to use the less obvious get_params()
check instead of the hasattr() pattern used by every other check.

return_empty is removed from BaseCreation and BaseDiscretiser; the
subclasses that genuinely need it (DatetimeSubtraction; EqualFrequencyDiscretiser,
EqualWidthDiscretiser, GeometricWidthDiscretiser) now validate and store it
directly, the same way DecisionTreeDiscretiser already did.

CategoricalInitMixinNA is different: MatchCategories (feature_engine.preprocessing)
was the only user not exposing return_empty, but it does exercise the
return_empty-consuming code path (auto-detects categorical variables via the
same shared _check_or_select_variables used by its sibling encoders), so
removing the leaked attribute broke it outright. Rather than special-case it
to a hardcoded False, return_empty is added as a proper, documented parameter
to MatchCategories, matching OrdinalEncoder, RareLabelEncoder,
CountFrequencyEncoder and MeanEncoder.

The shared test gate in check_feature_engine_estimator now uses
hasattr(estimator, "return_empty"), consistent with the other init-parameter
checks (cv, missing_values, drop_original), instead of the get_params()-based
gate needed to route around the leaks.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* replace try/except probing in check_return_empty with tag-based lookup

Instead of trying each of 3 candidate dataframes against the transformer and
catching whichever one raises TypeError, look up the right "no variables of
this type" dataframe directly from the transformer's own `variables` tag
(numerical/categorical/datetime), the same tag the other variable-selection
checks already use.

Two transformers don't carry a usable tag for unrelated reasons: LogTransformer's
_more_tags() doesn't set "variables" at all (a pre-existing gap), and
DatetimeSubtraction inherits BaseCreation's "skip" tag (meant to opt out of the
*generic* variable-assignment checks, not a statement about its variable type).
Both are handled with a small, explicit, named override instead of silently
falling back to trial and error.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* final changes to tests

* tities test and fixes transform tests

* expands docstring test

* fix and expand test for datetime ordinal

* remove comment

* fix test to sklearn wrapper and updates implementation

* remove comment

* fix code style

* add error text matching to tests

---------

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>

* Add test for get feature names out within return empty tests (#954)

* reposition return_empty to after variables (#955)

---------

Co-authored-by: Jordi Pastor <37837678+PastorJordi@users.noreply.github.com>
Co-authored-by: Míriam Méndez <60411598+miriam-mendez@users.noreply.github.com>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
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.

2 participants