Get pointer of int numpy array / list.
(data)
| 283 | |
| 284 | |
| 285 | def c_int_array(data): |
| 286 | """Get pointer of int numpy array / list.""" |
| 287 | if is_1d_list(data): |
| 288 | data = np.array(data, copy=False) |
| 289 | if is_numpy_1d_array(data): |
| 290 | data = convert_from_sliced_object(data) |
| 291 | assert data.flags.c_contiguous |
| 292 | if data.dtype == np.int32: |
| 293 | ptr_data = data.ctypes.data_as(ctypes.POINTER(ctypes.c_int32)) |
| 294 | type_data = C_API_DTYPE_INT32 |
| 295 | elif data.dtype == np.int64: |
| 296 | ptr_data = data.ctypes.data_as(ctypes.POINTER(ctypes.c_int64)) |
| 297 | type_data = C_API_DTYPE_INT64 |
| 298 | else: |
| 299 | raise TypeError("Expected np.int32 or np.int64, met type({})" |
| 300 | .format(data.dtype)) |
| 301 | else: |
| 302 | raise TypeError("Unknown type({})".format(type(data).__name__)) |
| 303 | return (ptr_data, type_data, data) # return `data` to avoid the temporary copy is freed |
| 304 | |
| 305 | |
| 306 | def _get_bad_pandas_dtypes(dtypes): |
no test coverage detected