From 1bd0e2cffdb8bc9e47114c45a44e5b6aa3c21c62 Mon Sep 17 00:00:00 2001 From: NovusEdge Date: Tue, 30 Mar 2021 21:54:00 +0530 Subject: [PATCH 01/10] added f-string to dask.py --- python-package/lightgbm/dask.py | 46 ++++++++++++++------------------- 1 file changed, 19 insertions(+), 27 deletions(-) diff --git a/python-package/lightgbm/dask.py b/python-package/lightgbm/dask.py index 2299ebaaf934..4c3ff9ad6195 100644 --- a/python-package/lightgbm/dask.py +++ b/python-package/lightgbm/dask.py @@ -67,7 +67,7 @@ def _concat(seq: List[_DaskPart]) -> _DaskPart: elif isinstance(seq[0], ss.spmatrix): return ss.vstack(seq, format='csr') 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( @@ -268,13 +268,13 @@ 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' if params['tree_learner'] not in {'data', 'data_parallel'}: _log_warning( - 'Support for tree_learner %s in lightgbm.dask is experimental and may break in a future release. \n' - 'Use "data" for a stable, well-tested interface.' % params['tree_learner'] + f'Support for tree_learner {params['tree_learner']} in lightgbm.dask is experimental and may break in a future release. \n' + 'Use "data" for a stable, well-tested interface.' ) # Some passed-in parameters can be removed: @@ -372,7 +372,7 @@ def _train( workers=list(worker_addresses) ) machines = ','.join([ - '%s:%d' % (urlparse(worker_address).hostname, port) + f'{urlparse(worker_address).hostname}:{port}' for worker_address, port in worker_address_to_port.items() ]) @@ -531,7 +531,7 @@ def _predict( drop_axis=1 ) 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: @@ -664,10 +664,10 @@ 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 + f"""{_before_kwargs}client : dask.distributed.Client or None, optional (default=None) + {' ' * 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. + {' ' * 8 } {_kwargs} {_after_kwargs}""" ) # the note on custom objective functions in LGBMModel.__init__ is not @@ -709,9 +709,7 @@ def fit( # 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' + f"{_base_doc[:_base_doc.find('callbacks :')]} **kwargs\n {' ' * 12} 'Other parameters passed through to ``LGBMClassifier.fit()``.\n'" ) def predict(self, X: _DaskMatrixLike, **kwargs: Any) -> dask_Array: @@ -818,10 +816,9 @@ 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 + f"""{_before_kwargs}client : dask.distributed.Client or None, optional (default=None) + {' ' * 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. + {' ' * 8} {_kwargs} + {_after_kwargs}""" ) # the note on custom objective functions in LGBMModel.__init__ is not @@ -863,9 +860,7 @@ def fit( # 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' + f"{_base_doc[:_base_doc.find('callbacks :')]} **kwargs\n{' ' * 12} Other parameters passed through to ``LGBMRegressor.fit()``.\n" ) def predict(self, X: _DaskMatrixLike, **kwargs) -> dask_Array: @@ -953,10 +948,9 @@ 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 + f"""{_before_kwargs} client : dask.distributed.Client or None, optional (default=None) + {' ' * 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 + {' ' * 8}{_kwargs}{_after_kwargs}""" ) # the note on custom objective functions in LGBMModel.__init__ is not @@ -1000,9 +994,7 @@ def fit( # 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' + f"{_base_doc[:_base_doc.find('callbacks :')]} **kwargs\n{' ' * 12}Other parameters passed through to ``LGBMRanker.fit()``.\n" ) def predict(self, X: _DaskMatrixLike, **kwargs: Any) -> dask_Array: From 0af6e62c77678e393bd9a40a747d3acb11e7ae40 Mon Sep 17 00:00:00 2001 From: NovusEdge <68768969+NovusEdge@users.noreply.github.com> Date: Sat, 10 Apr 2021 13:27:28 +0530 Subject: [PATCH 02/10] Update python-package/lightgbm/dask.py Co-authored-by: James Lamb --- python-package/lightgbm/dask.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python-package/lightgbm/dask.py b/python-package/lightgbm/dask.py index 4c3ff9ad6195..d72921800da5 100644 --- a/python-package/lightgbm/dask.py +++ b/python-package/lightgbm/dask.py @@ -273,7 +273,7 @@ def _train( if params['tree_learner'] not in {'data', 'data_parallel'}: _log_warning( - f'Support for tree_learner {params['tree_learner']} in lightgbm.dask is experimental and may break in a future release. \n' + f'Support for tree_learner {params["tree_learner'"} in lightgbm.dask is experimental and may break in a future release. \n' 'Use "data" for a stable, well-tested interface.' ) From c056e2355d67e6bb4ba68a23ff7d5eba621839c9 Mon Sep 17 00:00:00 2001 From: NovusEdge <68768969+NovusEdge@users.noreply.github.com> Date: Sat, 10 Apr 2021 13:27:40 +0530 Subject: [PATCH 03/10] Update python-package/lightgbm/dask.py Co-authored-by: James Lamb --- python-package/lightgbm/dask.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python-package/lightgbm/dask.py b/python-package/lightgbm/dask.py index d72921800da5..b4d6eedc49bc 100644 --- a/python-package/lightgbm/dask.py +++ b/python-package/lightgbm/dask.py @@ -268,7 +268,7 @@ def _train( 'voting_parallel' } if params["tree_learner"] not in allowed_tree_learners: - _log_warning(f'Parameter tree_learner set to {params['tree_learner']}, which is not allowed. Using "data" as default') + _log_warning(f'Parameter tree_learner set to {params["tree_learner"]}, which is not allowed. Using "data" as default') params['tree_learner'] = 'data' if params['tree_learner'] not in {'data', 'data_parallel'}: From 27e988ba0560ee0e08c4bbcd83af8660c0884e64 Mon Sep 17 00:00:00 2001 From: NovusEdge Date: Sat, 10 Apr 2021 13:36:31 +0530 Subject: [PATCH 04/10] Updated branch --- python-package/lightgbm/dask.py | 67 ++++++++++++++++++--------------- 1 file changed, 36 insertions(+), 31 deletions(-) diff --git a/python-package/lightgbm/dask.py b/python-package/lightgbm/dask.py index 4c3ff9ad6195..1d4c17d5688e 100644 --- a/python-package/lightgbm/dask.py +++ b/python-package/lightgbm/dask.py @@ -67,7 +67,7 @@ def _concat(seq: List[_DaskPart]) -> _DaskPart: elif isinstance(seq[0], ss.spmatrix): return ss.vstack(seq, format='csr') else: - raise TypeError(f'Data must be one of: numpy arrays, pandas dataframes, sparse matrices (from scipy). Got {type(seq[0])}.') + raise TypeError('Data must be one of: numpy arrays, pandas dataframes, sparse matrices (from scipy). Got %s.' % str(type(seq[0]))) def _train_part( @@ -268,13 +268,13 @@ def _train( 'voting_parallel' } if params["tree_learner"] not in allowed_tree_learners: - _log_warning(f'Parameter tree_learner set to {params['tree_learner']}, which is not allowed. Using "data" as default') + _log_warning('Parameter tree_learner set to %s, which is not allowed. Using "data" as default' % params['tree_learner']) params['tree_learner'] = 'data' if params['tree_learner'] not in {'data', 'data_parallel'}: _log_warning( - f'Support for tree_learner {params['tree_learner']} in lightgbm.dask is experimental and may break in a future release. \n' - 'Use "data" for a stable, well-tested interface.' + 'Support for tree_learner %s in lightgbm.dask is experimental and may break in a future release. \n' + 'Use "data" for a stable, well-tested interface.' % params['tree_learner'] ) # Some passed-in parameters can be removed: @@ -372,7 +372,7 @@ def _train( workers=list(worker_addresses) ) machines = ','.join([ - f'{urlparse(worker_address).hostname}:{port}' + '%s:%d' % (urlparse(worker_address).hostname, port) for worker_address, port in worker_address_to_port.items() ]) @@ -531,7 +531,7 @@ def _predict( drop_axis=1 ) else: - raise TypeError(f'Data must be either Dask Array or Dask DataFrame. Got {type(data)}.') + raise TypeError('Data must be either Dask Array or Dask DataFrame. Got %s.' % str(type(data))) class _DaskLGBMModel: @@ -663,12 +663,11 @@ def __init__( _base_doc = LGBMClassifier.__init__.__doc__ _before_kwargs, _kwargs, _after_kwargs = _base_doc.partition('**kwargs') - _base_doc = ( - f"""{_before_kwargs}client : dask.distributed.Client or None, optional (default=None) - {' ' * 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. - {' ' * 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 @@ -708,9 +707,10 @@ def fit( + _base_doc[_base_doc.find('verbose :'):]) # DaskLGBMClassifier support for callbacks and init_model is not tested - fit.__doc__ = ( - f"{_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 + Other parameters passed through to ``LGBMClassifier.fit()`` + """ def predict(self, X: _DaskMatrixLike, **kwargs: Any) -> dask_Array: """Docstring is inherited from the lightgbm.LGBMClassifier.predict.""" @@ -815,11 +815,11 @@ def __init__( _base_doc = LGBMRegressor.__init__.__doc__ _before_kwargs, _kwargs, _after_kwargs = _base_doc.partition('**kwargs') - _base_doc = ( - f"""{_before_kwargs}client : dask.distributed.Client or None, optional (default=None) - {' ' * 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. - {' ' * 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 @@ -855,12 +855,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()`` + """ # DaskLGBMRegressor support for callbacks and init_model is not tested fit.__doc__ = ( - f"{_base_doc[:_base_doc.find('callbacks :')]} **kwargs\n{' ' * 12} Other parameters passed through to ``LGBMRegressor.fit()``.\n" + _base_doc[:_base_doc.find('callbacks :')] + + '**kwargs\n' + + ' ' * 12 + 'Other parameters passed through to ``LGBMRegressor.fit()``.\n' ) def predict(self, X: _DaskMatrixLike, **kwargs) -> dask_Array: @@ -947,11 +951,11 @@ def __init__( _base_doc = LGBMRanker.__init__.__doc__ _before_kwargs, _kwargs, _after_kwargs = _base_doc.partition('**kwargs') - _base_doc = ( - f"""{_before_kwargs} client : dask.distributed.Client or None, optional (default=None) - {' ' * 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 - {' ' * 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 @@ -993,9 +997,10 @@ def fit( + _base_doc[_base_doc.find('verbose :'):]) # DaskLGBMRanker support for callbacks and init_model is not tested - fit.__doc__ = ( - f"{_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 + Other parameters passed through to ``LGBMRegressor.fit()`` + """ def predict(self, X: _DaskMatrixLike, **kwargs: Any) -> dask_Array: """Docstring is inherited from the lightgbm.LGBMRanker.predict.""" From ee77237cff210b916259c157a631f27cbfd22989 Mon Sep 17 00:00:00 2001 From: NovusEdge Date: Sun, 11 Apr 2021 12:17:33 +0530 Subject: [PATCH 05/10] Updated file as per specifications --- python-package/lightgbm/dask.py | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/python-package/lightgbm/dask.py b/python-package/lightgbm/dask.py index 94e5f68b05cb..bce045f2d742 100644 --- a/python-package/lightgbm/dask.py +++ b/python-package/lightgbm/dask.py @@ -705,10 +705,10 @@ def __init__( _base_doc = LGBMClassifier.__init__.__doc__ _before_kwargs, _kwargs, _after_kwargs = _base_doc.partition('**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} - """ + {_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 @@ -748,7 +748,7 @@ def fit( + _base_doc[_base_doc.find('verbose :'):]) # DaskLGBMClassifier support for callbacks and init_model is not tested - fit.__doc__ = f""" + fit.__doc__ = f""" {_base_doc[:_base_doc.find('callbacks :')]}**kwargs Other parameters passed through to ``LGBMClassifier.fit()`` """ @@ -856,12 +856,11 @@ def __init__( _base_doc = LGBMRegressor.__init__.__doc__ _before_kwargs, _kwargs, _after_kwargs = _base_doc.partition('**kwargs') - _base_doc = f""" + _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')] @@ -902,11 +901,10 @@ def fit( """ # 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 + Other parameters passed through to ``LGBMRegressor.fit()`` + """ def predict(self, X: _DaskMatrixLike, **kwargs) -> dask_Array: """Docstring is inherited from the lightgbm.LGBMRegressor.predict.""" @@ -992,7 +990,7 @@ def __init__( _base_doc = LGBMRanker.__init__.__doc__ _before_kwargs, _kwargs, _after_kwargs = _base_doc.partition('**kwargs') - _base_doc = f""" + _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} @@ -1038,11 +1036,11 @@ def fit( + _base_doc[_base_doc.find('verbose :'):]) # DaskLGBMRanker support for callbacks and init_model is not tested - fit.__doc__ = f""" + fit.__doc__ = f""" {_base_doc[:_base_doc.find('callbacks :')]}**kwargs Other parameters passed through to ``LGBMRegressor.fit()`` """ - + def predict(self, X: _DaskMatrixLike, **kwargs: Any) -> dask_Array: """Docstring is inherited from the lightgbm.LGBMRanker.predict.""" return _predict(self.to_local(), X, **kwargs) From f0581679957ad44d91d30e9af905ec2e12b03302 Mon Sep 17 00:00:00 2001 From: NovusEdge Date: Tue, 13 Apr 2021 05:50:18 +0530 Subject: [PATCH 06/10] Removed warning as per specification --- python-package/lightgbm/dask.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/python-package/lightgbm/dask.py b/python-package/lightgbm/dask.py index f478be55e5d2..05d397262edc 100644 --- a/python-package/lightgbm/dask.py +++ b/python-package/lightgbm/dask.py @@ -309,12 +309,6 @@ def _train( _log_warning(f'Parameter tree_learner set to {params["tree_learner"]}, which is not allowed. Using "data" as default') params['tree_learner'] = 'data' - if params['tree_learner'] not in {'data', 'data_parallel'}: - _log_warning( - f'Support for tree_learner {params["tree_learner'"} in lightgbm.dask is experimental and may break in a future release. \n' - 'Use "data" for a stable, well-tested interface.' - ) - # Some passed-in parameters can be removed: # * 'num_machines': set automatically from Dask worker list # * 'num_threads': overridden to match nthreads on each Dask process From 8f01b986cd6119b49e4c3a9c88a8b350cd1aeab1 Mon Sep 17 00:00:00 2001 From: James Lamb Date: Tue, 11 May 2021 13:28:19 -0500 Subject: [PATCH 07/10] update other places --- python-package/lightgbm/dask.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/python-package/lightgbm/dask.py b/python-package/lightgbm/dask.py index befcab9a1daa..6eded39eff11 100644 --- a/python-package/lightgbm/dask.py +++ b/python-package/lightgbm/dask.py @@ -67,7 +67,7 @@ def _concat(seq: List[_DaskPart]) -> _DaskPart: elif isinstance(seq[0], ss.spmatrix): return ss.vstack(seq, format='csr') 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 {str(type(seq[0]))}.') def _train_part( @@ -413,7 +413,7 @@ def _train( ) machines = ','.join([ - '%s:%d' % (urlparse(worker_address).hostname, port) + f'{urlparse(worker_address).hostname}:{port}' for worker_address, port in worker_address_to_port.items() ]) @@ -572,7 +572,7 @@ def _predict( drop_axis=1 ) 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 {str(type(data))}.') class _DaskLGBMModel: From 8c21be05ce1d1c3bb31d1c09157b552c323b345b Mon Sep 17 00:00:00 2001 From: James Lamb Date: Wed, 12 May 2021 17:10:33 -0500 Subject: [PATCH 08/10] Apply suggestions from code review Co-authored-by: Nikita Titov --- python-package/lightgbm/dask.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/python-package/lightgbm/dask.py b/python-package/lightgbm/dask.py index 6eded39eff11..c324aa2cf424 100644 --- a/python-package/lightgbm/dask.py +++ b/python-package/lightgbm/dask.py @@ -67,7 +67,7 @@ def _concat(seq: List[_DaskPart]) -> _DaskPart: elif isinstance(seq[0], ss.spmatrix): return ss.vstack(seq, format='csr') else: - raise TypeError(f'Data must be one of: numpy arrays, pandas dataframes, sparse matrices (from scipy). Got {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( @@ -572,7 +572,7 @@ def _predict( drop_axis=1 ) else: - raise TypeError(f'Data must be either Dask Array or Dask DataFrame. Got {str(type(data))}.') + raise TypeError(f'Data must be either Dask Array or Dask DataFrame. Got {type(data)}.') class _DaskLGBMModel: @@ -750,7 +750,7 @@ def fit( # DaskLGBMClassifier support for callbacks and init_model is not tested fit.__doc__ = f""" {_base_doc[:_base_doc.find('callbacks :')]}**kwargs - Other parameters passed through to ``LGBMClassifier.fit()`` + {' ':4}Other parameters passed through to ``LGBMClassifier.fit()`` """ def predict(self, X: _DaskMatrixLike, **kwargs: Any) -> dask_Array: @@ -903,7 +903,7 @@ def fit( # DaskLGBMRegressor support for callbacks and init_model is not tested fit.__doc__ = f""" {_base_doc[:_base_doc.find('callbacks :')]}**kwargs - Other parameters passed through to ``LGBMRegressor.fit()`` + {' ':4}Other parameters passed through to ``LGBMRegressor.fit()`` """ def predict(self, X: _DaskMatrixLike, **kwargs) -> dask_Array: @@ -1038,7 +1038,7 @@ def fit( # DaskLGBMRanker support for callbacks and init_model is not tested fit.__doc__ = f""" {_base_doc[:_base_doc.find('callbacks :')]}**kwargs - Other parameters passed through to ``LGBMRegressor.fit()`` + {' ':4}Other parameters passed through to ``LGBMRanker.fit()`` """ def predict(self, X: _DaskMatrixLike, **kwargs: Any) -> dask_Array: From 22c20eb35a41d0437e465e92275285f572f5bb09 Mon Sep 17 00:00:00 2001 From: James Lamb Date: Wed, 12 May 2021 22:09:44 -0500 Subject: [PATCH 09/10] revert unnecessary change --- python-package/lightgbm/dask.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/python-package/lightgbm/dask.py b/python-package/lightgbm/dask.py index 6eded39eff11..c6ec489c5e18 100644 --- a/python-package/lightgbm/dask.py +++ b/python-package/lightgbm/dask.py @@ -895,10 +895,8 @@ def fit( ) # DaskLGBMRegressor does not support evaluation data, or early stopping - fit.__doc__ = f""" - {_base_doc[:_base_doc.find('callbacks :')]}**kwargs - Other parameters passed through to ``LGBMRegressor.fit()`` - """ + _base_doc = (_base_doc[:_base_doc.find('group :')] + + _base_doc[_base_doc.find('verbose :'):]) # DaskLGBMRegressor support for callbacks and init_model is not tested fit.__doc__ = f""" From c032e56a1461c33b5e114789daea039f739b85f1 Mon Sep 17 00:00:00 2001 From: James Lamb Date: Thu, 13 May 2021 13:18:53 -0500 Subject: [PATCH 10/10] Apply suggestions from code review Co-authored-by: Nikita Titov --- python-package/lightgbm/dask.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/python-package/lightgbm/dask.py b/python-package/lightgbm/dask.py index 3050e7b789fb..8dd96e980161 100644 --- a/python-package/lightgbm/dask.py +++ b/python-package/lightgbm/dask.py @@ -748,9 +748,8 @@ def fit( + _base_doc[_base_doc.find('verbose :'):]) # DaskLGBMClassifier support for callbacks and init_model is not tested - fit.__doc__ = f""" - {_base_doc[:_base_doc.find('callbacks :')]}**kwargs - {' ':4}Other parameters passed through to ``LGBMClassifier.fit()`` + fit.__doc__ = f"""{_base_doc[:_base_doc.find('callbacks :')]}**kwargs + Other parameters passed through to ``LGBMClassifier.fit()``. """ def predict(self, X: _DaskMatrixLike, **kwargs: Any) -> dask_Array: @@ -899,9 +898,8 @@ def fit( + _base_doc[_base_doc.find('verbose :'):]) # DaskLGBMRegressor support for callbacks and init_model is not tested - fit.__doc__ = f""" - {_base_doc[:_base_doc.find('callbacks :')]}**kwargs - {' ':4}Other parameters passed through to ``LGBMRegressor.fit()`` + fit.__doc__ = f"""{_base_doc[:_base_doc.find('callbacks :')]}**kwargs + Other parameters passed through to ``LGBMRegressor.fit()``. """ def predict(self, X: _DaskMatrixLike, **kwargs) -> dask_Array: @@ -1034,9 +1032,8 @@ def fit( + _base_doc[_base_doc.find('verbose :'):]) # DaskLGBMRanker support for callbacks and init_model is not tested - fit.__doc__ = f""" - {_base_doc[:_base_doc.find('callbacks :')]}**kwargs - {' ':4}Other parameters passed through to ``LGBMRanker.fit()`` + fit.__doc__ = f"""{_base_doc[:_base_doc.find('callbacks :')]}**kwargs + Other parameters passed through to ``LGBMRanker.fit()``. """ def predict(self, X: _DaskMatrixLike, **kwargs: Any) -> dask_Array: