From b94577d05cd08a6a9147bff16395d442866cb511 Mon Sep 17 00:00:00 2001 From: James Lamb Date: Mon, 29 Nov 2021 23:37:20 -0600 Subject: [PATCH 1/4] [python-package] fix mypy error about missing type hint in dask.py --- 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 247accb481d4..1b112320832f 100644 --- a/python-package/lightgbm/dask.py +++ b/python-package/lightgbm/dask.py @@ -930,7 +930,7 @@ def _extract(items: List[Any], i: int) -> Any: num_cols = model.n_features_ + 1 nrows_per_chunk = data.chunks[0] - out = [[] for _ in range(num_classes)] + out: List[dask_Array] = [[] for _ in range(num_classes)] # need to tell Dask the expected type and shape of individual preds pred_meta = data._meta From 006a271fe8b4d4352b751b385b0b8319a6357684 Mon Sep 17 00:00:00 2001 From: James Lamb Date: Tue, 30 Nov 2021 20:29:06 -0600 Subject: [PATCH 2/4] list of lists --- 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 803182b3397a..2401412a839a 100644 --- a/python-package/lightgbm/dask.py +++ b/python-package/lightgbm/dask.py @@ -930,7 +930,7 @@ def _extract(items: List[Any], i: int) -> Any: num_cols = model.n_features_ + 1 nrows_per_chunk = data.chunks[0] - out: List[dask_Array] = [[] for _ in range(num_classes)] + out: List[List[dask_Array]] = [[] for _ in range(num_classes)] # need to tell Dask the expected type and shape of individual preds pred_meta = data._meta From 32f40dec3dc7813ca5649459598bcac3c2150f7c Mon Sep 17 00:00:00 2001 From: James Lamb Date: Tue, 30 Nov 2021 20:57:08 -0600 Subject: [PATCH 3/4] use different variable --- python-package/lightgbm/dask.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/python-package/lightgbm/dask.py b/python-package/lightgbm/dask.py index 2401412a839a..a2b4c81fccfd 100644 --- a/python-package/lightgbm/dask.py +++ b/python-package/lightgbm/dask.py @@ -955,14 +955,15 @@ def _extract(items: List[Any], i: int) -> Any: # At this point, `out` is a list of lists of delayeds (each of which points to a matrix). # Concatenate them to return a list of Dask Arrays. + out_arrays: List[dask_Array] = [] for i in range(num_classes): - out[i] = dask_array_from_delayed( + out_arrays[i] = dask_array_from_delayed( value=delayed(concat_fn)(out[i]), shape=(data.shape[0], num_cols), meta=pred_meta ) - return out + return out_arrays data_row = client.compute(data[[0]]).result() predict_fn = partial( From f0f2c6cd917a46d39e5ae2e7096acb5936be3b8c Mon Sep 17 00:00:00 2001 From: James Lamb Date: Tue, 30 Nov 2021 22:46:52 -0600 Subject: [PATCH 4/4] use append() --- python-package/lightgbm/dask.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/python-package/lightgbm/dask.py b/python-package/lightgbm/dask.py index a2b4c81fccfd..0333bb1b85fd 100644 --- a/python-package/lightgbm/dask.py +++ b/python-package/lightgbm/dask.py @@ -957,10 +957,12 @@ def _extract(items: List[Any], i: int) -> Any: # Concatenate them to return a list of Dask Arrays. out_arrays: List[dask_Array] = [] for i in range(num_classes): - out_arrays[i] = dask_array_from_delayed( - value=delayed(concat_fn)(out[i]), - shape=(data.shape[0], num_cols), - meta=pred_meta + out_arrays.append( + dask_array_from_delayed( + value=delayed(concat_fn)(out[i]), + shape=(data.shape[0], num_cols), + meta=pred_meta + ) ) return out_arrays