Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup booster param types. #8756

Merged
merged 1 commit into from
Feb 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion python-package/xgboost/_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
FeatureInfo = Sequence[str]
FeatureNames = FeatureInfo
FeatureTypes = FeatureInfo
BoosterParam = Union[List, Dict] # better be sequence
BoosterParam = Union[List, Dict[str, Any]] # better be sequence

ArrayLike = Any
PathLike = Union[str, os.PathLike]
Expand Down
33 changes: 12 additions & 21 deletions python-package/xgboost/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1655,27 +1655,18 @@ def _transform_interaction_constraints(

def _configure_constraints(self, params: BoosterParam) -> BoosterParam:
if isinstance(params, dict):
value = params.get("monotone_constraints")
if value is not None:
params["monotone_constraints"] = self._transform_monotone_constrains(
value
)

value = params.get("interaction_constraints")
if value is not None:
params[
"interaction_constraints"
] = self._transform_interaction_constraints(value)
elif isinstance(params, list):
for idx, param in enumerate(params):
name, value = param
if not value:
continue

if name == "monotone_constraints":
params[idx] = (name, self._transform_monotone_constrains(value))
elif name == "interaction_constraints":
params[idx] = (name, self._transform_interaction_constraints(value))
# we must use list in the internal code as there can be multiple metrics
# with the same parameter name `eval_metric` (same key for dictionary).
params = list(params.items())
for idx, param in enumerate(params):
name, value = param
if value is None:
continue

if name == "monotone_constraints":
params[idx] = (name, self._transform_monotone_constrains(value))
elif name == "interaction_constraints":
params[idx] = (name, self._transform_interaction_constraints(value))

return params

Expand Down