Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
tianlh
LightGBM-DCU
Commits
a5b2e049
Unverified
Commit
a5b2e049
authored
Jul 07, 2022
by
James Lamb
Committed by
GitHub
Jul 07, 2022
Browse files
[python-package] add more type hints on basic.py (#5356)
parent
6ab58edc
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
6 deletions
+6
-6
python-package/lightgbm/basic.py
python-package/lightgbm/basic.py
+6
-6
No files found.
python-package/lightgbm/basic.py
View file @
a5b2e049
...
@@ -152,12 +152,12 @@ def is_numeric(obj: Any) -> bool:
...
@@ -152,12 +152,12 @@ def is_numeric(obj: Any) -> bool:
return
False
return
False
def
is_numpy_1d_array
(
data
)
:
def
is_numpy_1d_array
(
data
:
Any
)
->
bool
:
"""Check whether data is a numpy 1-D array."""
"""Check whether data is a numpy 1-D array."""
return
isinstance
(
data
,
np
.
ndarray
)
and
len
(
data
.
shape
)
==
1
return
isinstance
(
data
,
np
.
ndarray
)
and
len
(
data
.
shape
)
==
1
def
is_numpy_column_array
(
data
)
:
def
is_numpy_column_array
(
data
:
Any
)
->
bool
:
"""Check whether data is a column numpy array."""
"""Check whether data is a column numpy array."""
if
not
isinstance
(
data
,
np
.
ndarray
):
if
not
isinstance
(
data
,
np
.
ndarray
):
return
False
return
False
...
@@ -172,7 +172,7 @@ def cast_numpy_array_to_dtype(array, dtype):
...
@@ -172,7 +172,7 @@ def cast_numpy_array_to_dtype(array, dtype):
return
array
.
astype
(
dtype
=
dtype
,
copy
=
False
)
return
array
.
astype
(
dtype
=
dtype
,
copy
=
False
)
def
is_1d_list
(
data
)
:
def
is_1d_list
(
data
:
Any
)
->
bool
:
"""Check whether data is a 1-D list."""
"""Check whether data is a 1-D list."""
return
isinstance
(
data
,
list
)
and
(
not
data
or
is_numeric
(
data
[
0
]))
return
isinstance
(
data
,
list
)
and
(
not
data
or
is_numeric
(
data
[
0
]))
...
@@ -279,7 +279,7 @@ def c_array(ctype, values):
...
@@ -279,7 +279,7 @@ def c_array(ctype, values):
return
(
ctype
*
len
(
values
))(
*
values
)
return
(
ctype
*
len
(
values
))(
*
values
)
def
json_default_with_numpy
(
obj
)
:
def
json_default_with_numpy
(
obj
:
Any
)
->
Any
:
"""Convert numpy classes to JSON serializable objects."""
"""Convert numpy classes to JSON serializable objects."""
if
isinstance
(
obj
,
(
np
.
integer
,
np
.
floating
,
np
.
bool_
)):
if
isinstance
(
obj
,
(
np
.
integer
,
np
.
floating
,
np
.
bool_
)):
return
obj
.
item
()
return
obj
.
item
()
...
@@ -744,7 +744,7 @@ class _InnerPredictor:
...
@@ -744,7 +744,7 @@ class _InnerPredictor:
pred_parameter
=
{}
if
pred_parameter
is
None
else
pred_parameter
pred_parameter
=
{}
if
pred_parameter
is
None
else
pred_parameter
self
.
pred_parameter
=
param_dict_to_str
(
pred_parameter
)
self
.
pred_parameter
=
param_dict_to_str
(
pred_parameter
)
def
__del__
(
self
):
def
__del__
(
self
)
->
None
:
try
:
try
:
if
self
.
__is_manage_handle
:
if
self
.
__is_manage_handle
:
_safe_call
(
_LIB
.
LGBM_BoosterFree
(
self
.
handle
))
_safe_call
(
_LIB
.
LGBM_BoosterFree
(
self
.
handle
))
...
@@ -1145,7 +1145,7 @@ class _InnerPredictor:
...
@@ -1145,7 +1145,7 @@ class _InnerPredictor:
raise
ValueError
(
"Wrong length for predict results"
)
raise
ValueError
(
"Wrong length for predict results"
)
return
preds
,
nrow
return
preds
,
nrow
def
current_iteration
(
self
):
def
current_iteration
(
self
)
->
int
:
"""Get the index of the current iteration.
"""Get the index of the current iteration.
Returns
Returns
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment