Skip to content

Commit 379a2f1

Browse files
DOC improved documentation for MethodPair and RouterMappingPair (scikit-learn#29489)
1 parent b204dba commit 379a2f1

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

sklearn/utils/_metadata_requests.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
In order to better understand the components implemented in this file, one
55
needs to understand their relationship to one another.
66
7-
The only relevant public API for end users are the ``set_{method}_request``,
7+
The only relevant public API for end users are the ``set_{method}_request`` methods,
88
e.g. ``estimator.set_fit_request(sample_weight=True)``. However, third-party
99
developers and users who implement custom meta-estimators, need to deal with
1010
the objects implemented in this file.
@@ -59,10 +59,10 @@
5959
6060
To give the above representation some structure, we use the following objects:
6161
62-
- ``(caller, callee)`` is a namedtuple called ``MethodPair``
62+
- ``(caller=..., callee=...)`` is a namedtuple called ``MethodPair``
6363
64-
- The list of ``MethodPair`` stored in the ``mapping`` field is a
65-
``MethodMapping`` object
64+
- The list of ``MethodPair`` stored in the ``mapping`` field of a `RouterMappingPair` is
65+
a ``MethodMapping`` object
6666
6767
- ``(mapping=..., router=...)`` is a namedtuple called ``RouterMappingPair``
6868
@@ -686,25 +686,26 @@ def __str__(self):
686686
# This section includes all objects required for MetadataRouter which is used
687687
# in routers, returned by their ``get_metadata_routing``.
688688

689-
# This namedtuple is used to store a (mapping, routing) pair. Mapping is a
690-
# MethodMapping object, and routing is the output of `get_metadata_routing`.
691-
# MetadataRouter stores a collection of these namedtuples.
689+
# `RouterMappingPair` is used to store a (mapping, router) tuple where `mapping` is a
690+
# `MethodMapping` object and `router` is the output of `get_metadata_routing`.
691+
# `MetadataRouter` stores a collection of `RouterMappingPair` objects in its
692+
# `_route_mappings` attribute.
692693
RouterMappingPair = namedtuple("RouterMappingPair", ["mapping", "router"])
693694

694-
# A namedtuple storing a single method route. A collection of these namedtuples
695-
# is stored in a MetadataRouter.
695+
# `MethodPair` is used to store a single method routing. `MethodMapping` stores a list
696+
# of `MethodPair` objects in its `_routes` attribute.
696697
MethodPair = namedtuple("MethodPair", ["caller", "callee"])
697698

698699

699700
class MethodMapping:
700701
"""Stores the mapping between caller and callee methods for a router.
701702
702703
This class is primarily used in a ``get_metadata_routing()`` of a router
703-
object when defining the mapping between a sub-object (a sub-estimator or a
704-
scorer) to the router's methods. It stores a collection of namedtuples.
704+
object when defining the mapping between the router's methods and a sub-object (a
705+
sub-estimator or a scorer).
705706
706-
Iterating through an instance of this class will yield named
707-
``MethodPair(caller, callee)`` tuples.
707+
Iterating through an instance of this class yields
708+
``MethodPair(caller, callee)`` instances.
708709
709710
.. versionadded:: 1.3
710711
"""

0 commit comments

Comments
 (0)