diff --git a/python-package/lightgbm/basic.py b/python-package/lightgbm/basic.py index 5a1c9c7b9609..047a76fb6c34 100644 --- a/python-package/lightgbm/basic.py +++ b/python-package/lightgbm/basic.py @@ -237,7 +237,7 @@ def _data_to_2d_numpy(data: Any, dtype: type = np.float32, name: str = 'list') - "It should be list of lists, numpy 2-D array or pandas DataFrame") -def cfloat32_array_to_numpy(cptr, length): +def cfloat32_array_to_numpy(cptr: ctypes.POINTER, length: int) -> np.ndarray: """Convert a ctypes float pointer array to a numpy array.""" if isinstance(cptr, ctypes.POINTER(ctypes.c_float)): return np.ctypeslib.as_array(cptr, shape=(length,)).copy() @@ -245,7 +245,7 @@ def cfloat32_array_to_numpy(cptr, length): raise RuntimeError('Expected float pointer') -def cfloat64_array_to_numpy(cptr, length): +def cfloat64_array_to_numpy(cptr: ctypes.POINTER, length: int) -> np.ndarray: """Convert a ctypes double pointer array to a numpy array.""" if isinstance(cptr, ctypes.POINTER(ctypes.c_double)): return np.ctypeslib.as_array(cptr, shape=(length,)).copy() @@ -253,7 +253,7 @@ def cfloat64_array_to_numpy(cptr, length): raise RuntimeError('Expected double pointer') -def cint32_array_to_numpy(cptr, length): +def cint32_array_to_numpy(cptr: ctypes.POINTER, length: int) -> np.ndarray: """Convert a ctypes int pointer array to a numpy array.""" if isinstance(cptr, ctypes.POINTER(ctypes.c_int32)): return np.ctypeslib.as_array(cptr, shape=(length,)).copy() @@ -261,7 +261,7 @@ def cint32_array_to_numpy(cptr, length): raise RuntimeError('Expected int32 pointer') -def cint64_array_to_numpy(cptr, length): +def cint64_array_to_numpy(cptr: ctypes.POINTER, length: int) -> np.ndarray: """Convert a ctypes int pointer array to a numpy array.""" if isinstance(cptr, ctypes.POINTER(ctypes.c_int64)): return np.ctypeslib.as_array(cptr, shape=(length,)).copy() @@ -269,12 +269,12 @@ def cint64_array_to_numpy(cptr, length): raise RuntimeError('Expected int64 pointer') -def c_str(string): +def c_str(string: str) -> ctypes.c_char_p: """Convert a Python string to C string.""" return ctypes.c_char_p(string.encode('utf-8')) -def c_array(ctype, values): +def c_array(ctype: type, values: List[Any]) -> ctypes.Array: """Convert a Python array to C array.""" return (ctype * len(values))(*values)