Skip to content

Commit 1c5c8f0

Browse files
adrinjalaliOmarManzoorStefanieSenger
authored
MNT refactoring in routing _MetadataRequester (#31534)
Co-authored-by: Omar Salman <omar.salman2007@gmail.com> Co-authored-by: Stefanie Senger <91849487+StefanieSenger@users.noreply.github.com>
1 parent 91d5640 commit 1c5c8f0

29 files changed

+174
-158
lines changed

examples/miscellaneous/plot_metadata_routing.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ def get_metadata_routing(self):
167167
# This method defines the routing for this meta-estimator.
168168
# In order to do so, a `MetadataRouter` instance is created, and the
169169
# routing is added to it. More explanations follow below.
170-
router = MetadataRouter(owner=self.__class__.__name__).add(
170+
router = MetadataRouter(owner=self).add(
171171
estimator=self.estimator,
172172
method_mapping=MethodMapping()
173173
.add(caller="fit", callee="fit")
@@ -352,7 +352,7 @@ def __init__(self, estimator):
352352

353353
def get_metadata_routing(self):
354354
router = (
355-
MetadataRouter(owner=self.__class__.__name__)
355+
MetadataRouter(owner=self)
356356
# defining metadata routing request values for usage in the meta-estimator
357357
.add_self_request(self)
358358
# defining metadata routing request values for usage in the sub-estimator
@@ -483,7 +483,7 @@ def __init__(self, transformer, classifier):
483483

484484
def get_metadata_routing(self):
485485
router = (
486-
MetadataRouter(owner=self.__class__.__name__)
486+
MetadataRouter(owner=self)
487487
# We add the routing for the transformer.
488488
.add(
489489
transformer=self.transformer,
@@ -613,7 +613,7 @@ def fit(self, X, y, **fit_params):
613613
self.estimator_ = clone(self.estimator).fit(X, y, **routed_params.estimator.fit)
614614

615615
def get_metadata_routing(self):
616-
router = MetadataRouter(owner=self.__class__.__name__).add(
616+
router = MetadataRouter(owner=self).add(
617617
estimator=self.estimator,
618618
method_mapping=MethodMapping().add(caller="fit", callee="fit"),
619619
)
@@ -650,7 +650,7 @@ def fit(self, X, y, sample_weight=None, **fit_params):
650650

651651
def get_metadata_routing(self):
652652
router = (
653-
MetadataRouter(owner=self.__class__.__name__)
653+
MetadataRouter(owner=self)
654654
.add_self_request(self)
655655
.add(
656656
estimator=self.estimator,

sklearn/calibration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ def get_metadata_routing(self):
578578
routing information.
579579
"""
580580
router = (
581-
MetadataRouter(owner=self.__class__.__name__)
581+
MetadataRouter(owner=self)
582582
.add_self_request(self)
583583
.add(
584584
estimator=self._get_estimator(),

sklearn/compose/_column_transformer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1289,7 +1289,7 @@ def get_metadata_routing(self):
12891289
A :class:`~sklearn.utils.metadata_routing.MetadataRouter` encapsulating
12901290
routing information.
12911291
"""
1292-
router = MetadataRouter(owner=self.__class__.__name__)
1292+
router = MetadataRouter(owner=self)
12931293
# Here we don't care about which columns are used for which
12941294
# transformers, and whether or not a transformer is used at all, which
12951295
# might happen if no columns are selected for that transformer. We

sklearn/compose/_target.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ def get_metadata_routing(self):
382382
A :class:`~sklearn.utils.metadata_routing.MetadataRouter` encapsulating
383383
routing information.
384384
"""
385-
router = MetadataRouter(owner=self.__class__.__name__).add(
385+
router = MetadataRouter(owner=self).add(
386386
regressor=self._get_regressor(),
387387
method_mapping=MethodMapping()
388388
.add(caller="fit", callee="fit")

sklearn/covariance/_graph_lasso.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1138,7 +1138,7 @@ def get_metadata_routing(self):
11381138
A :class:`~sklearn.utils.metadata_routing.MetadataRouter` encapsulating
11391139
routing information.
11401140
"""
1141-
router = MetadataRouter(owner=self.__class__.__name__).add(
1141+
router = MetadataRouter(owner=self).add(
11421142
splitter=check_cv(self.cv),
11431143
method_mapping=MethodMapping().add(callee="split", caller="fit"),
11441144
)

sklearn/ensemble/_bagging.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ def get_metadata_routing(self):
636636
A :class:`~sklearn.utils.metadata_routing.MetadataRouter` encapsulating
637637
routing information.
638638
"""
639-
router = MetadataRouter(owner=self.__class__.__name__)
639+
router = MetadataRouter(owner=self)
640640

641641
method_mapping = MethodMapping()
642642
method_mapping.add(caller="fit", callee="fit").add(

sklearn/ensemble/_stacking.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ def get_metadata_routing(self):
397397
A :class:`~sklearn.utils.metadata_routing.MetadataRouter` encapsulating
398398
routing information.
399399
"""
400-
router = MetadataRouter(owner=self.__class__.__name__)
400+
router = MetadataRouter(owner=self)
401401

402402
# `self.estimators` is a list of (name, est) tuples
403403
for name, estimator in self.estimators:

sklearn/ensemble/_voting.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ def get_metadata_routing(self):
180180
A :class:`~sklearn.utils.metadata_routing.MetadataRouter` encapsulating
181181
routing information.
182182
"""
183-
router = MetadataRouter(owner=self.__class__.__name__)
183+
router = MetadataRouter(owner=self)
184184

185185
# `self.estimators` is a list of (name, est) tuples
186186
for name, estimator in self.estimators:

sklearn/feature_selection/_from_model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ def get_metadata_routing(self):
498498
A :class:`~sklearn.utils.metadata_routing.MetadataRouter` encapsulating
499499
routing information.
500500
"""
501-
router = MetadataRouter(owner=self.__class__.__name__).add(
501+
router = MetadataRouter(owner=self).add(
502502
estimator=self.estimator,
503503
method_mapping=MethodMapping()
504504
.add(caller="partial_fit", callee="partial_fit")

sklearn/feature_selection/_rfe.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ def get_metadata_routing(self):
551551
A :class:`~sklearn.utils.metadata_routing.MetadataRouter` encapsulating
552552
routing information.
553553
"""
554-
router = MetadataRouter(owner=self.__class__.__name__).add(
554+
router = MetadataRouter(owner=self).add(
555555
estimator=self.estimator,
556556
method_mapping=MethodMapping()
557557
.add(caller="fit", callee="fit")
@@ -1002,7 +1002,7 @@ def get_metadata_routing(self):
10021002
A :class:`~sklearn.utils.metadata_routing.MetadataRouter` encapsulating
10031003
routing information.
10041004
"""
1005-
router = MetadataRouter(owner=self.__class__.__name__)
1005+
router = MetadataRouter(owner=self)
10061006
router.add(
10071007
estimator=self.estimator,
10081008
method_mapping=MethodMapping().add(caller="fit", callee="fit"),

0 commit comments

Comments
 (0)