You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
TargetEncoder.fit_transform raises KeyError: 'groups' when metadata routing is enabled and no groups are passed #35139
Dear all,
I am a professor of applied math at École polytechnique, very close to the Turing build, so important for the scikit-learn community. I use scikit-learn mainly for teaching, as the ones doing the hard jobs are now my students.
Describe the bug and give evidence about its user-facing impact
With enable_metadata_routing=True, TargetEncoder.fit_transform(X, y) raises KeyError: 'groups' when it is called without groups. This is the common case. It also happens inside a ColumnTransformer or a Pipeline, so any pipeline that contains a TargetEncoder fails as soon as routing is switched on globally. The bug does not depend on the CV splitter: the default cv=5 and StratifiedKFold(...) both fail.
The cause is in sklearn/preprocessing/_target_encoder.py (line 366 in 1.9.1, unchanged on main):
if_routing_enabled():
ifparams["groups"] isnotNone:
X, y, params["groups"] =indexable(X, y, params["groups"])
routed_params=process_routing(self, "fit_transform", **params)
params only contains the metadata that were actually passed, so params["groups"] fails when no groups are given.
Thanks for reporting the issue, @lepennec. I confirm this is a bug and needs fixing.
I'll be happy to review your bugfix PR. (Feel free to ping me on it, so I cannot miss it.) Your suggested solution looks fine. Please also add a changelog entry and a non-regression test (reusing your reproducible for this will suffice).
No pressure, but FYI, if we manage to merge this by November 2nd it will go into next release.
No pressure, but FYI, if we manage to merge this by November 2nd it will go into next release.
Adding to this 😅: now that we have #35144 that @ogrisel suggested to have in the next release, we really need to ship this bugfix as well. Did you have any time to work on this @lepennec? You really already have everything you need: the fix is the one-liner you suggested and the test is a simple smoke test derived from your reproducible. You can also make a start and we finish.
Activity
lesteve commentedon Oct 13, 2026
Thanks for the clear issue and your interest in fixing the bug, really appreciate it 🙏!
It does seem like a bug indeed, ccing @StefanieSenger who will have a more informed opinion than me about the fix you propose.
StefanieSenger commentedon Oct 14, 2026
Thanks for reporting the issue, @lepennec. I confirm this is a bug and needs fixing.
I'll be happy to review your bugfix PR. (Feel free to ping me on it, so I cannot miss it.) Your suggested solution looks fine. Please also add a changelog entry and a non-regression test (reusing your reproducible for this will suffice).
No pressure, but FYI, if we manage to merge this by November 2nd it will go into next release.
faizanfatmi commentedon Oct 15, 2026
faizanfatmi commentedon Oct 15, 2026
lesteve commentedon Oct 15, 2026
@faizanfatmi the original poster said he was interested to work on this 2 days ago, I suggest you find another issue to work on.
Glad to see you are interested to contribute to scikit-learn 🙏!
Please have a look at our contributing doc and in particular the section Issues for new contributors.
There is also GitHub's How to contribute to Open-Source guide, which gives a good generic overview about how open-source works.
StefanieSenger commentedon Oct 20, 2026
Adding to this 😅: now that we have #35144 that @ogrisel suggested to have in the next release, we really need to ship this bugfix as well. Did you have any time to work on this @lepennec? You really already have everything you need: the fix is the one-liner you suggested and the test is a simple smoke test derived from your reproducible. You can also make a start and we finish.
lepennec commentedon Oct 20, 2026