aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/python/clickhouse-connect/clickhouse_connect/driverc/npconv.pyx
blob: 87f49813929f9bd7e54944f1756b1ecee508c938 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
import cython

import numpy as np

from .buffer cimport ResponseBuffer

@cython.boundscheck(False)
@cython.wraparound(False)
def read_numpy_array(ResponseBuffer buffer, np_type: str, unsigned long long num_rows):
    dtype = np.dtype(np_type)
    cdef sz = dtype.itemsize * num_rows
    cdef char * source = buffer.read_bytes_c(dtype.itemsize * num_rows)
    return np.frombuffer(source[:sz], dtype, num_rows)