Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
tianlh
LightGBM-DCU
Commits
a1fdeb1f
Unverified
Commit
a1fdeb1f
authored
Nov 23, 2021
by
Nikita Titov
Committed by
GitHub
Nov 23, 2021
Browse files
[python] add type hints to `_compare_params_for_warning()` and make it reusable (#4824)
parent
2caf945f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
7 deletions
+23
-7
python-package/lightgbm/basic.py
python-package/lightgbm/basic.py
+23
-7
No files found.
python-package/lightgbm/basic.py
View file @
a1fdeb1f
...
@@ -1756,17 +1756,29 @@ class Dataset:
...
@@ -1756,17 +1756,29 @@ class Dataset:
return
self
return
self
@
staticmethod
@
staticmethod
def
_compare_params_for_warning
(
params
,
other_params
):
def
_compare_params_for_warning
(
"""Compare params.
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
Returns
-------
-------
compare_result: bool
compare_result
: bool
If they are equal, return True; Otherwise, return False
.
Returns whether two dictionaries with params are equal
.
"""
"""
ignore_keys
=
_ConfigAliases
.
get
(
"categorical_feature"
)
if
params
is
None
:
if
params
is
None
:
params
=
{}
params
=
{}
if
other_params
is
None
:
if
other_params
is
None
:
...
@@ -1794,7 +1806,11 @@ class Dataset:
...
@@ -1794,7 +1806,11 @@ class Dataset:
reference_params
=
self
.
reference
.
get_params
()
reference_params
=
self
.
reference
.
get_params
()
params
=
self
.
get_params
()
params
=
self
.
get_params
()
if
params
!=
reference_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.'
)
_log_warning
(
'Overriding the parameters from Reference Dataset.'
)
self
.
_update_params
(
reference_params
)
self
.
_update_params
(
reference_params
)
if
self
.
used_indices
is
None
:
if
self
.
used_indices
is
None
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment