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

[python-package] fix type hints on ctypes array converters (#5446)

[python-package] fix type hints on cptr converters
parent 4162485d
...@@ -255,7 +255,7 @@ def _data_to_2d_numpy(data: Any, dtype: type = np.float32, name: str = 'list') - ...@@ -255,7 +255,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") "It should be list of lists, numpy 2-D array or pandas DataFrame")
def cfloat32_array_to_numpy(cptr: ctypes.POINTER, length: int) -> np.ndarray: def cfloat32_array_to_numpy(cptr: Any, length: int) -> np.ndarray:
"""Convert a ctypes float pointer array to a numpy array.""" """Convert a ctypes float pointer array to a numpy array."""
if isinstance(cptr, ctypes.POINTER(ctypes.c_float)): if isinstance(cptr, ctypes.POINTER(ctypes.c_float)):
return np.ctypeslib.as_array(cptr, shape=(length,)).copy() return np.ctypeslib.as_array(cptr, shape=(length,)).copy()
...@@ -263,7 +263,7 @@ def cfloat32_array_to_numpy(cptr: ctypes.POINTER, length: int) -> np.ndarray: ...@@ -263,7 +263,7 @@ def cfloat32_array_to_numpy(cptr: ctypes.POINTER, length: int) -> np.ndarray:
raise RuntimeError('Expected float pointer') raise RuntimeError('Expected float pointer')
def cfloat64_array_to_numpy(cptr: ctypes.POINTER, length: int) -> np.ndarray: def cfloat64_array_to_numpy(cptr: Any, length: int) -> np.ndarray:
"""Convert a ctypes double pointer array to a numpy array.""" """Convert a ctypes double pointer array to a numpy array."""
if isinstance(cptr, ctypes.POINTER(ctypes.c_double)): if isinstance(cptr, ctypes.POINTER(ctypes.c_double)):
return np.ctypeslib.as_array(cptr, shape=(length,)).copy() return np.ctypeslib.as_array(cptr, shape=(length,)).copy()
...@@ -271,7 +271,7 @@ def cfloat64_array_to_numpy(cptr: ctypes.POINTER, length: int) -> np.ndarray: ...@@ -271,7 +271,7 @@ def cfloat64_array_to_numpy(cptr: ctypes.POINTER, length: int) -> np.ndarray:
raise RuntimeError('Expected double pointer') raise RuntimeError('Expected double pointer')
def cint32_array_to_numpy(cptr: ctypes.POINTER, length: int) -> np.ndarray: def cint32_array_to_numpy(cptr: Any, length: int) -> np.ndarray:
"""Convert a ctypes int pointer array to a numpy array.""" """Convert a ctypes int pointer array to a numpy array."""
if isinstance(cptr, ctypes.POINTER(ctypes.c_int32)): if isinstance(cptr, ctypes.POINTER(ctypes.c_int32)):
return np.ctypeslib.as_array(cptr, shape=(length,)).copy() return np.ctypeslib.as_array(cptr, shape=(length,)).copy()
...@@ -279,7 +279,7 @@ def cint32_array_to_numpy(cptr: ctypes.POINTER, length: int) -> np.ndarray: ...@@ -279,7 +279,7 @@ def cint32_array_to_numpy(cptr: ctypes.POINTER, length: int) -> np.ndarray:
raise RuntimeError('Expected int32 pointer') raise RuntimeError('Expected int32 pointer')
def cint64_array_to_numpy(cptr: ctypes.POINTER, length: int) -> np.ndarray: def cint64_array_to_numpy(cptr: Any, length: int) -> np.ndarray:
"""Convert a ctypes int pointer array to a numpy array.""" """Convert a ctypes int pointer array to a numpy array."""
if isinstance(cptr, ctypes.POINTER(ctypes.c_int64)): if isinstance(cptr, ctypes.POINTER(ctypes.c_int64)):
return np.ctypeslib.as_array(cptr, shape=(length,)).copy() return np.ctypeslib.as_array(cptr, shape=(length,)).copy()
......
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