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)}, where mapping
is an instance of and
is either a
or another
instance.
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_mapping : MethodMapping
The mapping between the child (consumer) and the parent’s
(router’s) methods.
**objs : dict
A dictionary of objects, whose requests are extracted by calling
get_routing_for_object on them.
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:
obj : object
This is typically the router instance, i.e. self in a
get_metadata_routing() implementation. It can also be a
MetadataRequest instance.
Returns:
self : MetadataRouter
Returns self.
consumes(method, params)
Return params consumed as metadata in a router or its sub-estimators.
This method returns the subset of params that are consumed by the
method. A param is considered consumed if it is used in the specified
method of the router itself or any of its sub-estimators (or their
sub-estimators).
Parameters:
method : str
The name of the method for which to determine consumed parameters.
params : iterable of str
An iterable of parameter names to test for consumption.
Returns:
consumed_params : set of str
A subset of parameters from params which are consumed by this method.
route_params(*, caller, params)
Get the values of metadata requested by consumers.
Returns a Bunch containing the metadata that this
router’s caller 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:
caller : str
The name of the router’s method through which the metadata is
routed. For example, if called inside the fit method of a router,
this would be "fit".
params : dict
A dictionary of provided metadata.
Returns:
params : Bunch
A Bunch of the form
{"object_name":{"method_name":{metadata:value}}}.
validate_metadata(*, method, params)
Validate given metadata for a method.
This raises a TypeError if some of the passed metadata are not
understood by child objects.
Parameters:
method : str
The name of the router’s method through which the metadata is
routed. For example, if called inside the fit method of a router,
this would be "fit".