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

[python] added f-strings to python-package/lightgbm/dask.py #4144

Merged
merged 17 commits into from
May 15, 2021
Merged
Changes from 10 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
69 changes: 32 additions & 37 deletions python-package/lightgbm/dask.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ def _train(
'voting_parallel'
}
if params["tree_learner"] not in allowed_tree_learners:
_log_warning('Parameter tree_learner set to %s, which is not allowed. Using "data" as default' % params['tree_learner'])
_log_warning(f'Parameter tree_learner set to {params["tree_learner"]}, which is not allowed. Using "data" as default')
params['tree_learner'] = 'data'

# Some passed-in parameters can be removed:
Expand Down Expand Up @@ -704,12 +704,11 @@ def __init__(

_base_doc = LGBMClassifier.__init__.__doc__
_before_kwargs, _kwargs, _after_kwargs = _base_doc.partition('**kwargs')
_base_doc = (
_before_kwargs
+ 'client : dask.distributed.Client or None, optional (default=None)\n'
+ ' ' * 12 + 'Dask client. If ``None``, ``distributed.default_client()`` will be used at runtime. The Dask client used by this class will not be saved if the model object is pickled.\n'
+ ' ' * 8 + _kwargs + _after_kwargs
)
_base_doc = f"""
{_before_kwargs}client : dask.distributed.Client or None, optional (default=None)
{' ':4}Dask client. If ``None``, ``distributed.default_client()`` will be used at runtime. The Dask client used by this class will not be saved if the model object is pickled.
{_kwargs}{_after_kwargs}
"""

# the note on custom objective functions in LGBMModel.__init__ is not
# currently relevant for the Dask estimators
Expand Down Expand Up @@ -749,11 +748,10 @@ def fit(
+ _base_doc[_base_doc.find('verbose :'):])

# DaskLGBMClassifier support for callbacks and init_model is not tested
fit.__doc__ = (
_base_doc[:_base_doc.find('callbacks :')]
+ '**kwargs\n'
+ ' ' * 12 + 'Other parameters passed through to ``LGBMClassifier.fit()``.\n'
)
fit.__doc__ = f"""
{_base_doc[:_base_doc.find('callbacks :')]}**kwargs
jameslamb marked this conversation as resolved.
Show resolved Hide resolved
Other parameters passed through to ``LGBMClassifier.fit()``
jameslamb marked this conversation as resolved.
Show resolved Hide resolved
"""

def predict(self, X: _DaskMatrixLike, **kwargs: Any) -> dask_Array:
"""Docstring is inherited from the lightgbm.LGBMClassifier.predict."""
Expand Down Expand Up @@ -858,13 +856,11 @@ def __init__(

_base_doc = LGBMRegressor.__init__.__doc__
_before_kwargs, _kwargs, _after_kwargs = _base_doc.partition('**kwargs')
_base_doc = (
_before_kwargs
+ 'client : dask.distributed.Client or None, optional (default=None)\n'
+ ' ' * 12 + 'Dask client. If ``None``, ``distributed.default_client()`` will be used at runtime. The Dask client used by this class will not be saved if the model object is pickled.\n'
+ ' ' * 8 + _kwargs + _after_kwargs
)

_base_doc = f"""
{_before_kwargs}client : dask.distributed.Client or None, optional (default=None)
{' ':4}Dask client. If ``None``, ``distributed.default_client()`` will be used at runtime. The Dask client used by this class will not be saved if the model object is pickled.
{_kwargs}{_after_kwargs}
"""
# the note on custom objective functions in LGBMModel.__init__ is not
# currently relevant for the Dask estimators
__init__.__doc__ = _base_doc[:_base_doc.find('Note\n')]
Expand Down Expand Up @@ -899,15 +895,16 @@ def fit(
)

# DaskLGBMRegressor does not support evaluation data, or early stopping
_base_doc = (_base_doc[:_base_doc.find('group :')]
+ _base_doc[_base_doc.find('verbose :'):])
fit.__doc__ = f"""
{_base_doc[:_base_doc.find('callbacks :')]}**kwargs
Other parameters passed through to ``LGBMRegressor.fit()``
"""
StrikerRUS marked this conversation as resolved.
Show resolved Hide resolved

# DaskLGBMRegressor support for callbacks and init_model is not tested
fit.__doc__ = (
_base_doc[:_base_doc.find('callbacks :')]
+ '**kwargs\n'
+ ' ' * 12 + 'Other parameters passed through to ``LGBMRegressor.fit()``.\n'
)
fit.__doc__ = f"""
{_base_doc[:_base_doc.find('callbacks :')]}**kwargs
jameslamb marked this conversation as resolved.
Show resolved Hide resolved
Other parameters passed through to ``LGBMRegressor.fit()``
jameslamb marked this conversation as resolved.
Show resolved Hide resolved
"""

def predict(self, X: _DaskMatrixLike, **kwargs) -> dask_Array:
"""Docstring is inherited from the lightgbm.LGBMRegressor.predict."""
Expand Down Expand Up @@ -993,12 +990,11 @@ def __init__(

_base_doc = LGBMRanker.__init__.__doc__
_before_kwargs, _kwargs, _after_kwargs = _base_doc.partition('**kwargs')
_base_doc = (
_before_kwargs
+ 'client : dask.distributed.Client or None, optional (default=None)\n'
+ ' ' * 12 + 'Dask client. If ``None``, ``distributed.default_client()`` will be used at runtime. The Dask client used by this class will not be saved if the model object is pickled.\n'
+ ' ' * 8 + _kwargs + _after_kwargs
)
_base_doc = f"""
{_before_kwargs}client : dask.distributed.Client or None, optional (default=None)
{' ':4}Dask client. If ``None``, ``distributed.default_client()`` will be used at runtime. The Dask client used by this class will not be saved if the model object is pickled.
{_kwargs}{_after_kwargs}
"""

# the note on custom objective functions in LGBMModel.__init__ is not
# currently relevant for the Dask estimators
Expand Down Expand Up @@ -1040,11 +1036,10 @@ def fit(
+ _base_doc[_base_doc.find('verbose :'):])

# DaskLGBMRanker support for callbacks and init_model is not tested
fit.__doc__ = (
_base_doc[:_base_doc.find('callbacks :')]
+ '**kwargs\n'
+ ' ' * 12 + 'Other parameters passed through to ``LGBMRanker.fit()``.\n'
)
fit.__doc__ = f"""
{_base_doc[:_base_doc.find('callbacks :')]}**kwargs
jameslamb marked this conversation as resolved.
Show resolved Hide resolved
Other parameters passed through to ``LGBMRegressor.fit()``
jameslamb marked this conversation as resolved.
Show resolved Hide resolved
"""

def predict(self, X: _DaskMatrixLike, **kwargs: Any) -> dask_Array:
"""Docstring is inherited from the lightgbm.LGBMRanker.predict."""
Expand Down