@@ -347,13 +347,8 @@ def _get_param_names(cls) -> list[str]:
347347 # Extract and sort argument names excluding 'self'
348348 return sorted ([p .name for p in parameters ])
349349
350- def get_params (self , deep = True ) -> dict [str , Any ]:
351- """Get parameters for this estimator.
352-
353- Parameters
354- ----------
355- deep : bool, default=True
356- Has no effect, because steps cannot contain nested substeps.
350+ def _get_params (self ) -> dict [str , Any ]:
351+ """Get parameters for this step.
357352
358353 Returns
359354 -------
@@ -370,8 +365,8 @@ def get_params(self, deep=True) -> dict[str, Any]:
370365 """
371366 return {key : getattr (self , key ) for key in self ._get_param_names ()}
372367
373- def set_params (self , ** params ):
374- """Set the parameters of this estimator .
368+ def _set_params (self , ** params ):
369+ """Set the parameters of this step .
375370
376371 Parameters
377372 ----------
@@ -400,7 +395,7 @@ def set_params(self, **params):
400395 for key , value in params .items ():
401396 if key not in valid_params :
402397 raise ValueError (
403- f"Invalid parameter { key !r} for estimator { self } . "
398+ f"Invalid parameter { key !r} for step { self } . "
404399 f"Valid parameters are: { valid_params !r} ."
405400 )
406401
@@ -503,16 +498,16 @@ def output_format(self) -> Literal["default", "pandas", "pyarrow", "polars"]:
503498 return self ._output_format
504499
505500 def get_params (self , deep = True ) -> dict [str , Any ]:
506- """Get parameters for this estimator .
501+ """Get parameters for this recipe .
507502
508503 Returns the parameters given in the constructor as well as the
509- estimators contained within the `steps` of the `Recipe`.
504+ steps contained within the `steps` of the `Recipe`.
510505
511506 Parameters
512507 ----------
513508 deep : bool, default=True
514- If True, will return the parameters for this estimator and
515- contained subobjects that are estimators .
509+ If True, will return the parameters for this recipe and
510+ contained steps .
516511
517512 Returns
518513 -------
@@ -531,26 +526,25 @@ def get_params(self, deep=True) -> dict[str, Any]:
531526 if not deep :
532527 return out
533528
534- estimators = _name_estimators (self .steps )
535- out .update (estimators )
529+ steps = _name_estimators (self .steps )
530+ out .update (steps )
536531
537- for name , estimator in estimators :
538- if hasattr (estimator , "get_params" ):
539- for key , value in estimator .get_params (deep = True ).items ():
540- out [f"{ name } __{ key } " ] = value
532+ for name , step in steps :
533+ for key , value in step ._get_params ().items (): # noqa: SLF001
534+ out [f"{ name } __{ key } " ] = value
541535 return out
542536
543537 def set_params (self , ** params ):
544- """Set the parameters of this estimator .
538+ """Set the parameters of this recipe .
545539
546540 Valid parameter keys can be listed with ``get_params()``. Note that
547- you can directly set the parameters of the estimators contained in
541+ you can directly set the parameters of the steps contained in
548542 `steps`.
549543
550544 Parameters
551545 ----------
552546 **params : dict
553- Parameters of this estimator or parameters of estimators contained
547+ Parameters of this recipe or parameters of steps contained
554548 in `steps`. Parameters of the steps may be set using its name and
555549 the parameter name separated by a '__'.
556550
@@ -577,7 +571,7 @@ def set_params(self, **params):
577571 if "steps" in params :
578572 self .steps = params .pop ("steps" )
579573
580- # 2. Replace items with estimators in params
574+ # 2. Replace steps with steps in params
581575 estimator_name_indexes = {
582576 x : i for i , x in enumerate (name for name , _ in _name_estimators (self .steps ))
583577 }
@@ -593,14 +587,14 @@ def set_params(self, **params):
593587 key , sub_key = key .split ("__" , maxsplit = 1 )
594588 if key not in valid_params :
595589 raise ValueError (
596- f"Invalid parameter { key !r} for estimator { self } . "
590+ f"Invalid parameter { key !r} for recipe { self } . "
597591 f"Valid parameters are: ['steps']."
598592 )
599593
600594 nested_params [key ][sub_key ] = value
601595
602596 for key , sub_params in nested_params .items ():
603- valid_params [key ].set_params (** sub_params )
597+ valid_params [key ]._set_params (** sub_params ) # noqa: SLF001
604598
605599 return self
606600
0 commit comments