Unverified Commit df14e607 authored by James Lamb's avatar James Lamb Committed by GitHub
Browse files

[python-package] add more type hints in basic.py (#5330)

parent b6deb9a8
...@@ -22,7 +22,7 @@ from .libpath import find_lib_path ...@@ -22,7 +22,7 @@ from .libpath import find_lib_path
ZERO_THRESHOLD = 1e-35 ZERO_THRESHOLD = 1e-35
def _get_sample_count(total_nrow: int, params: str): def _get_sample_count(total_nrow: int, params: str) -> int:
sample_cnt = ctypes.c_int(0) sample_cnt = ctypes.c_int(0)
_safe_call(_LIB.LGBM_GetSampleCount( _safe_call(_LIB.LGBM_GetSampleCount(
ctypes.c_int32(total_nrow), ctypes.c_int32(total_nrow),
...@@ -108,7 +108,7 @@ def _log_callback(msg: bytes) -> None: ...@@ -108,7 +108,7 @@ def _log_callback(msg: bytes) -> None:
_log_native(str(msg.decode('utf-8'))) _log_native(str(msg.decode('utf-8')))
def _load_lib(): def _load_lib() -> Optional[ctypes.CDLL]:
"""Load LightGBM library.""" """Load LightGBM library."""
lib_path = find_lib_path() lib_path = find_lib_path()
if len(lib_path) == 0: if len(lib_path) == 0:
...@@ -141,7 +141,7 @@ def _safe_call(ret: int) -> None: ...@@ -141,7 +141,7 @@ def _safe_call(ret: int) -> None:
raise LightGBMError(_LIB.LGBM_GetLastError().decode('utf-8')) raise LightGBMError(_LIB.LGBM_GetLastError().decode('utf-8'))
def is_numeric(obj): def is_numeric(obj: Any) -> bool:
"""Check whether object is a number or not, include numpy number, etc.""" """Check whether object is a number or not, include numpy number, etc."""
try: try:
float(obj) float(obj)
...@@ -289,7 +289,7 @@ def json_default_with_numpy(obj): ...@@ -289,7 +289,7 @@ def json_default_with_numpy(obj):
return obj return obj
def param_dict_to_str(data): def param_dict_to_str(data: Optional[Dict[str, Any]]) -> str:
"""Convert Python dictionary to string, which is passed to C API.""" """Convert Python dictionary to string, which is passed to C API."""
if data is None or not data: if data is None or not data:
return "" return ""
......
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