Skip to content

Commit

Permalink
[python] add type hints to _compare_params_for_warning() and make i…
Browse files Browse the repository at this point in the history
…t reusable (#4824)
  • Loading branch information
StrikerRUS authored Nov 23, 2021
1 parent 2caf945 commit a1fdeb1
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions python-package/lightgbm/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1756,17 +1756,29 @@ def __init_from_csc(self, csc, params_str, ref_dataset):
return self

@staticmethod
def _compare_params_for_warning(params, other_params):
"""Compare params.
def _compare_params_for_warning(
params: Optional[Dict[str, Any]],
other_params: Optional[Dict[str, Any]],
ignore_keys: Set[str]
) -> bool:
"""Compare two dictionaries with params ignoring some keys.
It is only for the warning purpose. Thus some keys are ignored.
It is only for the warning purpose.
Parameters
----------
params : dict or None
One dictionary with parameters to compare.
other_params : dict or None
Another dictionary with parameters to compare.
ignore_keys : set
Keys that should be ignored during comparing two dictionaries.
Returns
-------
compare_result: bool
If they are equal, return True; Otherwise, return False.
compare_result : bool
Returns whether two dictionaries with params are equal.
"""
ignore_keys = _ConfigAliases.get("categorical_feature")
if params is None:
params = {}
if other_params is None:
Expand Down Expand Up @@ -1794,7 +1806,11 @@ def construct(self):
reference_params = self.reference.get_params()
params = self.get_params()
if params != reference_params:
if self._compare_params_for_warning(params, reference_params) is False:
if not self._compare_params_for_warning(
params=params,
other_params=reference_params,
ignore_keys=_ConfigAliases.get("categorical_feature")
):
_log_warning('Overriding the parameters from Reference Dataset.')
self._update_params(reference_params)
if self.used_indices is None:
Expand Down

0 comments on commit a1fdeb1

Please sign in to comment.