"R-package/tests/vscode:/vscode.git/clone" did not exist on "7dcbb8cd11d4fb9d5d5a0d95c49e250338b112c5"
Unverified Commit b1facf50 authored by Zhiyuan He's avatar Zhiyuan He Committed by GitHub
Browse files

Suppress categorical warning (fixes #3379)

parent 858cc0a7
......@@ -1510,6 +1510,8 @@ class Dataset:
if categorical_indices:
for cat_alias in _ConfigAliases.get("categorical_feature"):
if cat_alias in params:
# If the params[cat_alias] is equal to categorical_indices, do not report the warning.
if not(isinstance(params[cat_alias], list) and set(params[cat_alias]) == categorical_indices):
_log_warning(f'{cat_alias} in param dict is overridden.')
params.pop(cat_alias, None)
params['categorical_column'] = sorted(categorical_indices)
......@@ -1765,6 +1767,32 @@ class Dataset:
ctypes.byref(self.handle)))
return self
@staticmethod
def _compare_params_for_warning(params, other_params):
"""Compare params.
It is only for the warning purpose. Thus some keys are ignored.
Returns
-------
compare_result: bool
If they are equal, return True; Otherwise, return False.
"""
ignore_keys = _ConfigAliases.get("categorical_feature")
if params is None:
params = {}
if other_params is None:
other_params = {}
for k in other_params:
if k not in ignore_keys:
if k not in params or params[k] != other_params[k]:
return False
for k in params:
if k not in ignore_keys:
if k not in other_params or params[k] != other_params[k]:
return False
return True
def construct(self):
"""Lazy init.
......@@ -1776,7 +1804,9 @@ class Dataset:
if self.handle is None:
if self.reference is not None:
reference_params = self.reference.get_params()
if self.get_params() != reference_params:
params = self.get_params()
if params != reference_params:
if self._compare_params_for_warning(params, reference_params) is False:
_log_warning('Overriding the parameters from Reference Dataset.')
self._update_params(reference_params)
if self.used_indices is None:
......@@ -2062,9 +2092,9 @@ class Dataset:
self.categorical_feature = categorical_feature
return self._free_handle()
elif categorical_feature == 'auto':
_log_warning('Using categorical_feature in Dataset.')
return self
else:
if self.categorical_feature != 'auto':
_log_warning('categorical_feature in Dataset is overridden.\n'
f'New categorical_feature is {sorted(list(categorical_feature))}')
self.categorical_feature = categorical_feature
......
......@@ -43,8 +43,6 @@ def test_register_logger(tmp_path):
lgb.plot_metric(eval_records)
expected_log = r"""
WARNING | categorical_feature in Dataset is overridden.
New categorical_feature is [1]
INFO | [LightGBM] [Warning] There are no meaningful features, as all feature values are constant.
INFO | [LightGBM] [Info] Number of positive: 2, number of negative: 2
INFO | [LightGBM] [Info] Total Bins 0
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment