MetadataRouter#
- class sklearn.utils.metadata_routing.MetadataRouter(owner)[source]#
Coordinates metadata routing for a router object.
This class is used by meta-estimators or functions that can route metadata, to handle their metadata routing. Routing information is stored in a dictionary-like structure of the form
{"object_name": RouterMappingPair(mapping, router)}, wheremappingis an instance ofMethodMappingandrouteris either aMetadataRequestor anotherMetadataRouterinstance.Added in version 1.3.
- Parameters:
- ownerobject
The object to which these requests belong.
- add(*, method_mapping, **objs)[source]#
Add consumers to the
MetadataRouter.The estimators that consume metadata are passed as named objects along with a method mapping, that defines how their methods relate to those of the router.
- Parameters:
- method_mappingMethodMapping
The mapping between the child (consumer) and the parent’s (router’s) methods.
- **objsdict
A dictionary of objects, whose requests are extracted by calling
get_routing_for_objecton them.
- Returns:
- selfMetadataRouter
Returns
self.
- add_self_request(obj)[source]#
Add
self(as a consumer) to theMetadataRouter.This method is used if the router is also a consumer, and hence the router itself needs to be included in the routing. The passed object can be an estimator or a
MetadataRequest.A router should add itself using this method instead of
addsince it should be treated differently than the other consumer objects to which metadata is routed by the router.- Parameters:
- objobject
This is typically the router instance, i.e.
selfin aget_metadata_routing()implementation. It can also be aMetadataRequestinstance.
- Returns:
- selfMetadataRouter
Returns
self.
- consumes(method, params)[source]#
Return params consumed as metadata in a router or its sub-estimators.
This method returns the subset of
paramsthat are consumed by themethod. Aparamis considered consumed if it is used in the specified method of the router itself or any of its sub-estimators (or their sub-estimators).Added in version 1.4.
- Parameters:
- methodstr
The name of the method for which to determine consumed parameters.
- paramsiterable of str
An iterable of parameter names to test for consumption.
- Returns:
- consumed_paramsset of str
A subset of parameters from
paramswhich are consumed by this method.
- route_params(*, caller, params)[source]#
Get the values of metadata requested by consumers.
Returns a
Bunchcontaining the metadata that this router’scallermethod needs to route, organized by each consumer and their corresponding methods.This can be used to pass the required metadata to corresponding methods in consumers.
- Parameters:
- Returns:
- paramsBunch
A
Bunchof the form{"object_name": {"method_name": {metadata: value}}}.