Remove type: ignore hints (#9197)
This commit is contained in:
parent
053aababd4
commit
c5677a2b2c
@ -82,9 +82,10 @@ def from_pystr_to_cstr(data: Union[str, List[str]]) -> Union[bytes, ctypes.Array
|
|||||||
if isinstance(data, str):
|
if isinstance(data, str):
|
||||||
return bytes(data, "utf-8")
|
return bytes(data, "utf-8")
|
||||||
if isinstance(data, list):
|
if isinstance(data, list):
|
||||||
pointers: ctypes.Array[ctypes.c_char_p] = (ctypes.c_char_p * len(data))()
|
data_as_bytes: List[bytes] = [bytes(d, "utf-8") for d in data]
|
||||||
data_as_bytes = [bytes(d, "utf-8") for d in data]
|
pointers: ctypes.Array[ctypes.c_char_p] = (
|
||||||
pointers[:] = data_as_bytes # type: ignore
|
ctypes.c_char_p * len(data_as_bytes)
|
||||||
|
)(*data_as_bytes)
|
||||||
return pointers
|
return pointers
|
||||||
raise TypeError()
|
raise TypeError()
|
||||||
|
|
||||||
@ -319,7 +320,7 @@ def _cuda_array_interface(data: DataType) -> bytes:
|
|||||||
def ctypes2numpy(cptr: CNumericPtr, length: int, dtype: Type[np.number]) -> np.ndarray:
|
def ctypes2numpy(cptr: CNumericPtr, length: int, dtype: Type[np.number]) -> np.ndarray:
|
||||||
"""Convert a ctypes pointer array to a numpy array."""
|
"""Convert a ctypes pointer array to a numpy array."""
|
||||||
ctype: Type[CNumeric] = _numpy2ctypes_type(dtype)
|
ctype: Type[CNumeric] = _numpy2ctypes_type(dtype)
|
||||||
if not isinstance(cptr, ctypes.POINTER(ctype)): # type: ignore
|
if not isinstance(cptr, ctypes.POINTER(ctype)):
|
||||||
raise RuntimeError(f"expected {ctype} pointer")
|
raise RuntimeError(f"expected {ctype} pointer")
|
||||||
res = np.zeros(length, dtype=dtype)
|
res = np.zeros(length, dtype=dtype)
|
||||||
if not ctypes.memmove(res.ctypes.data, cptr, length * res.strides[0]):
|
if not ctypes.memmove(res.ctypes.data, cptr, length * res.strides[0]):
|
||||||
@ -2460,9 +2461,9 @@ class Booster:
|
|||||||
raise TypeError("Unknown file type: ", fname)
|
raise TypeError("Unknown file type: ", fname)
|
||||||
|
|
||||||
if self.attr("best_iteration") is not None:
|
if self.attr("best_iteration") is not None:
|
||||||
self.best_iteration = int(self.attr("best_iteration")) # type: ignore
|
self.best_iteration = int(cast(int, self.attr("best_iteration")))
|
||||||
if self.attr("best_score") is not None:
|
if self.attr("best_score") is not None:
|
||||||
self.best_score = float(self.attr("best_score")) # type: ignore
|
self.best_score = float(cast(float, self.attr("best_score")))
|
||||||
|
|
||||||
def num_boosted_rounds(self) -> int:
|
def num_boosted_rounds(self) -> int:
|
||||||
"""Get number of boosted rounds. For gblinear this is reset to 0 after
|
"""Get number of boosted rounds. For gblinear this is reset to 0 after
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user