Skip to content

Commit 5a8a574

Browse files
authored
MNT SLEP006 cleanup and doc improvement (scikit-learn#26591)
1 parent ceec2fa commit 5a8a574

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

sklearn/tests/test_metadata_routing.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -681,9 +681,7 @@ def fit(self, X, y, **kwargs):
681681
def test_method_metadata_request():
682682
mmr = MethodMetadataRequest(owner="test", method="fit")
683683

684-
with pytest.raises(
685-
ValueError, match="alias should be either a valid identifier or"
686-
):
684+
with pytest.raises(ValueError, match="The alias you're setting for"):
687685
mmr.add_request(param="foo", alias=1.4)
688686

689687
mmr.add_request(param="foo", alias=None)

sklearn/utils/_metadata_requests.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,9 @@ def _routing_enabled():
152152
def request_is_alias(item):
153153
"""Check if an item is a valid alias.
154154
155+
Values in ``VALID_REQUEST_VALUES`` are not considered aliases in this
156+
context. Only a string which is a valid identifier is.
157+
155158
Parameters
156159
----------
157160
item : object
@@ -247,8 +250,9 @@ def add_request(
247250
"""
248251
if not request_is_alias(alias) and not request_is_valid(alias):
249252
raise ValueError(
250-
"alias should be either a valid identifier or one of "
251-
"{None, True, False}."
253+
f"The alias you're setting for `{param}` should be either a "
254+
"valid identifier or one of {None, True, False}, but given "
255+
f"value is: `{alias}`"
252256
)
253257

254258
if alias == param:
@@ -659,9 +663,10 @@ class MetadataRouter:
659663

660664
def __init__(self, owner):
661665
self._route_mappings = dict()
662-
# `_self` is used if the router is also a consumer. _self, (added using
663-
# `add_self_request()`) is treated differently from the other objects
664-
# which are stored in _route_mappings.
666+
# `_self_request` is used if the router is also a consumer.
667+
# _self_request, (added using `add_self_request()`) is treated
668+
# differently from the other objects which are stored in
669+
# _route_mappings.
665670
self._self_request = None
666671
self.owner = owner
667672

@@ -1182,8 +1187,8 @@ def _build_request_for_signature(cls, router, method):
11821187
"""Build the `MethodMetadataRequest` for a method using its signature.
11831188
11841189
This method takes all arguments from the method signature and uses
1185-
``None`` as their default request value, except ``X``, ``y``,
1186-
``*args``, and ``**kwargs``.
1190+
``None`` as their default request value, except ``X``, ``y``, ``Y``,
1191+
``Xt``, ``yt``, ``*args``, and ``**kwargs``.
11871192
11881193
Parameters
11891194
----------
@@ -1219,7 +1224,7 @@ def _build_request_for_signature(cls, router, method):
12191224
def _get_default_requests(cls):
12201225
"""Collect default request values.
12211226
1222-
This method combines the information present in ``metadata_request__*``
1227+
This method combines the information present in ``__metadata_request__*``
12231228
class attributes, as well as determining request keys from method
12241229
signatures.
12251230
"""

0 commit comments

Comments
 (0)