-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
[python] add more type hints in basic.py #5255
Conversation
python-package/lightgbm/basic.py
Outdated
@@ -3953,7 +3957,7 @@ def __get_eval_info(self): | |||
name.startswith(('auc', 'ndcg@', 'map@', 'average_precision')) for name in self.__name_inner_eval | |||
] | |||
|
|||
def attr(self, key): | |||
def attr(self, key: str) -> Any: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def attr(self, key: str) -> Any: | |
def attr(self, key: str) -> Optional[str]: |
LightGBM/python-package/lightgbm/basic.py
Lines 3987 to 3989 in 65b3db1
if value is not None: | |
if not isinstance(value, str): | |
raise ValueError("Only string values are accepted") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh interesting, I didn't realize this could only be set by Booster.set_attr()
.
Can you help me understand the purpose of these methods? It seems they were added back in 2016 (eba6d20#diff-5e0fb2a7b1ec4988ccde5e74a6c4b609841c1143f281da2afc85e8c464d37b3b) and today are only used in one place, a test.
git grep -E '\.attr\('
assert gbm.booster_.attr('attr_set_inside_callback') == '40' |
git grep -E '\.set_attr\('
env.model.set_attr(attr_set_inside_callback=str(env.iteration * 10)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree either way about the type hint so I don't think this conversation needs to block this PR. But I'm wondering if there's an opportunity here to remove these methods and the internal object Booster.__attr
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you help me understand the purpose of these methods?
I'm sorry, I can't.
I guess it's a legacy code that was initially borrowed from XGBoost. In XGBoost those methods are used for distributed training with Rabit: dmlc/xgboost@ecb3a27.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have no objection to remove set_attr()
and attr()
methods in a separate PR to make LightGBM codebase clearer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok thanks! I'll make a separate PR that proposes removing them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
created #5272
Co-authored-by: Nikita Titov <nekit94-08@mail.ru>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
This pull request has been automatically locked since there has not been any recent activity since it was closed. To start a new related discussion, open a new issue at https://github.com/microsoft/LightGBM/issues including a reference to this. |
Contributes to #3756.
Proposes adding a few more hints in
basic.py
. Just quickly scanned through this file tonight and chose a few hints that looked easy to determine just from looking at the code and docstrings, trying to slowly make progress on #3756 as I have time.