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)}
, wheremapping
is an instance ofMethodMapping
androuter
is either aMetadataRequest
or anotherMetadataRouter
instance.Added in version 1.3.
- Parameters:
- ownerstr
The name of 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_object
on 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
add
since 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.
self
in aget_metadata_routing()
implementation. It can also be aMetadataRequest
instance.
- Returns:
- selfMetadataRouter
Returns
self
.
- consumes(method, params)[source]#
Check whether the given metadata is consumed by the given method.
Added in version 1.4.
- Parameters:
- methodstr
The name of the method to check.
- paramsiterable of str
An iterable of parameters to check.
- Returns:
- consumedset of str
A set of parameters which are consumed by the given method.
- route_params(*, caller, params)[source]#
Get the values of metadata requested by consumers.
Returns a
Bunch
containing the metadata that this router’scaller
method 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
Bunch
of the form{"object_name": {"method_name": {metadata: value}}}
.