Unverified Commit 3a657c8b authored by NovusEdge's avatar NovusEdge Committed by GitHub
Browse files

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



* added f-string to dask.py

* Update python-package/lightgbm/dask.py
Co-authored-by: default avatarJames Lamb <jaylamb20@gmail.com>

* Update python-package/lightgbm/dask.py
Co-authored-by: default avatarJames Lamb <jaylamb20@gmail.com>

* Updated branch

* Updated file as per specifications

* Removed warning as per specification

* update other places

* Apply suggestions from code review
Co-authored-by: default avatarNikita Titov <nekit94-08@mail.ru>

* revert unnecessary change

* Apply suggestions from code review
Co-authored-by: default avatarNikita Titov <nekit94-08@mail.ru>
Co-authored-by: default avatarJames Lamb <jaylamb20@gmail.com>
Co-authored-by: default avatarNikita Titov <nekit94-08@mail.ru>
parent c629cb0b
...@@ -67,7 +67,7 @@ def _concat(seq: List[_DaskPart]) -> _DaskPart: ...@@ -67,7 +67,7 @@ def _concat(seq: List[_DaskPart]) -> _DaskPart:
elif isinstance(seq[0], ss.spmatrix): elif isinstance(seq[0], ss.spmatrix):
return ss.vstack(seq, format='csr') return ss.vstack(seq, format='csr')
else: else:
raise TypeError('Data must be one of: numpy arrays, pandas dataframes, sparse matrices (from scipy). Got %s.' % str(type(seq[0]))) raise TypeError(f'Data must be one of: numpy arrays, pandas dataframes, sparse matrices (from scipy). Got {type(seq[0])}.')
def _train_part( def _train_part(
...@@ -306,7 +306,7 @@ def _train( ...@@ -306,7 +306,7 @@ def _train(
'voting_parallel' 'voting_parallel'
} }
if params["tree_learner"] not in allowed_tree_learners: 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' params['tree_learner'] = 'data'
# Some passed-in parameters can be removed: # Some passed-in parameters can be removed:
...@@ -413,7 +413,7 @@ def _train( ...@@ -413,7 +413,7 @@ def _train(
) )
machines = ','.join([ machines = ','.join([
'%s:%d' % (urlparse(worker_address).hostname, port) f'{urlparse(worker_address).hostname}:{port}'
for worker_address, port for worker_address, port
in worker_address_to_port.items() in worker_address_to_port.items()
]) ])
...@@ -572,7 +572,7 @@ def _predict( ...@@ -572,7 +572,7 @@ def _predict(
drop_axis=1 drop_axis=1
) )
else: else:
raise TypeError('Data must be either Dask Array or Dask DataFrame. Got %s.' % str(type(data))) raise TypeError(f'Data must be either Dask Array or Dask DataFrame. Got {type(data)}.')
class _DaskLGBMModel: class _DaskLGBMModel:
...@@ -704,12 +704,11 @@ class DaskLGBMClassifier(LGBMClassifier, _DaskLGBMModel): ...@@ -704,12 +704,11 @@ class DaskLGBMClassifier(LGBMClassifier, _DaskLGBMModel):
_base_doc = LGBMClassifier.__init__.__doc__ _base_doc = LGBMClassifier.__init__.__doc__
_before_kwargs, _kwargs, _after_kwargs = _base_doc.partition('**kwargs') _before_kwargs, _kwargs, _after_kwargs = _base_doc.partition('**kwargs')
_base_doc = ( _base_doc = f"""
_before_kwargs {_before_kwargs}client : dask.distributed.Client or None, optional (default=None)
+ 'client : dask.distributed.Client or None, optional (default=None)\n' {' ':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.
+ ' ' * 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' {_kwargs}{_after_kwargs}
+ ' ' * 8 + _kwargs + _after_kwargs """
)
# the note on custom objective functions in LGBMModel.__init__ is not # the note on custom objective functions in LGBMModel.__init__ is not
# currently relevant for the Dask estimators # currently relevant for the Dask estimators
...@@ -749,11 +748,9 @@ class DaskLGBMClassifier(LGBMClassifier, _DaskLGBMModel): ...@@ -749,11 +748,9 @@ class DaskLGBMClassifier(LGBMClassifier, _DaskLGBMModel):
+ _base_doc[_base_doc.find('verbose :'):]) + _base_doc[_base_doc.find('verbose :'):])
# DaskLGBMClassifier support for callbacks and init_model is not tested # DaskLGBMClassifier support for callbacks and init_model is not tested
fit.__doc__ = ( fit.__doc__ = f"""{_base_doc[:_base_doc.find('callbacks :')]}**kwargs
_base_doc[:_base_doc.find('callbacks :')] Other parameters passed through to ``LGBMClassifier.fit()``.
+ '**kwargs\n' """
+ ' ' * 12 + 'Other parameters passed through to ``LGBMClassifier.fit()``.\n'
)
def predict(self, X: _DaskMatrixLike, **kwargs: Any) -> dask_Array: def predict(self, X: _DaskMatrixLike, **kwargs: Any) -> dask_Array:
"""Docstring is inherited from the lightgbm.LGBMClassifier.predict.""" """Docstring is inherited from the lightgbm.LGBMClassifier.predict."""
...@@ -858,13 +855,11 @@ class DaskLGBMRegressor(LGBMRegressor, _DaskLGBMModel): ...@@ -858,13 +855,11 @@ class DaskLGBMRegressor(LGBMRegressor, _DaskLGBMModel):
_base_doc = LGBMRegressor.__init__.__doc__ _base_doc = LGBMRegressor.__init__.__doc__
_before_kwargs, _kwargs, _after_kwargs = _base_doc.partition('**kwargs') _before_kwargs, _kwargs, _after_kwargs = _base_doc.partition('**kwargs')
_base_doc = ( _base_doc = f"""
_before_kwargs {_before_kwargs}client : dask.distributed.Client or None, optional (default=None)
+ 'client : dask.distributed.Client or None, optional (default=None)\n' {' ':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.
+ ' ' * 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' {_kwargs}{_after_kwargs}
+ ' ' * 8 + _kwargs + _after_kwargs """
)
# the note on custom objective functions in LGBMModel.__init__ is not # the note on custom objective functions in LGBMModel.__init__ is not
# currently relevant for the Dask estimators # currently relevant for the Dask estimators
__init__.__doc__ = _base_doc[:_base_doc.find('Note\n')] __init__.__doc__ = _base_doc[:_base_doc.find('Note\n')]
...@@ -903,11 +898,9 @@ class DaskLGBMRegressor(LGBMRegressor, _DaskLGBMModel): ...@@ -903,11 +898,9 @@ class DaskLGBMRegressor(LGBMRegressor, _DaskLGBMModel):
+ _base_doc[_base_doc.find('verbose :'):]) + _base_doc[_base_doc.find('verbose :'):])
# DaskLGBMRegressor support for callbacks and init_model is not tested # DaskLGBMRegressor support for callbacks and init_model is not tested
fit.__doc__ = ( fit.__doc__ = f"""{_base_doc[:_base_doc.find('callbacks :')]}**kwargs
_base_doc[:_base_doc.find('callbacks :')] Other parameters passed through to ``LGBMRegressor.fit()``.
+ '**kwargs\n' """
+ ' ' * 12 + 'Other parameters passed through to ``LGBMRegressor.fit()``.\n'
)
def predict(self, X: _DaskMatrixLike, **kwargs) -> dask_Array: def predict(self, X: _DaskMatrixLike, **kwargs) -> dask_Array:
"""Docstring is inherited from the lightgbm.LGBMRegressor.predict.""" """Docstring is inherited from the lightgbm.LGBMRegressor.predict."""
...@@ -993,12 +986,11 @@ class DaskLGBMRanker(LGBMRanker, _DaskLGBMModel): ...@@ -993,12 +986,11 @@ class DaskLGBMRanker(LGBMRanker, _DaskLGBMModel):
_base_doc = LGBMRanker.__init__.__doc__ _base_doc = LGBMRanker.__init__.__doc__
_before_kwargs, _kwargs, _after_kwargs = _base_doc.partition('**kwargs') _before_kwargs, _kwargs, _after_kwargs = _base_doc.partition('**kwargs')
_base_doc = ( _base_doc = f"""
_before_kwargs {_before_kwargs}client : dask.distributed.Client or None, optional (default=None)
+ 'client : dask.distributed.Client or None, optional (default=None)\n' {' ':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.
+ ' ' * 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' {_kwargs}{_after_kwargs}
+ ' ' * 8 + _kwargs + _after_kwargs """
)
# the note on custom objective functions in LGBMModel.__init__ is not # the note on custom objective functions in LGBMModel.__init__ is not
# currently relevant for the Dask estimators # currently relevant for the Dask estimators
...@@ -1040,11 +1032,9 @@ class DaskLGBMRanker(LGBMRanker, _DaskLGBMModel): ...@@ -1040,11 +1032,9 @@ class DaskLGBMRanker(LGBMRanker, _DaskLGBMModel):
+ _base_doc[_base_doc.find('verbose :'):]) + _base_doc[_base_doc.find('verbose :'):])
# DaskLGBMRanker support for callbacks and init_model is not tested # DaskLGBMRanker support for callbacks and init_model is not tested
fit.__doc__ = ( fit.__doc__ = f"""{_base_doc[:_base_doc.find('callbacks :')]}**kwargs
_base_doc[:_base_doc.find('callbacks :')] Other parameters passed through to ``LGBMRanker.fit()``.
+ '**kwargs\n' """
+ ' ' * 12 + 'Other parameters passed through to ``LGBMRanker.fit()``.\n'
)
def predict(self, X: _DaskMatrixLike, **kwargs: Any) -> dask_Array: def predict(self, X: _DaskMatrixLike, **kwargs: Any) -> dask_Array:
"""Docstring is inherited from the lightgbm.LGBMRanker.predict.""" """Docstring is inherited from the lightgbm.LGBMRanker.predict."""
......
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