Skip to content

Commit 010393c

Browse files
committed
ENH: expose Int64VectorData in hashtable.pxd
1 parent dda3c42 commit 010393c

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

pandas/hashtable.pxd

+14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from khash cimport (kh_int64_t, kh_uint64_t, kh_float64_t, kh_pymap_t,
22
kh_str_t, uint64_t, int64_t, float64_t)
3+
from numpy cimport ndarray
34

45
# prototypes for sharing
56

@@ -35,3 +36,16 @@ cdef class StringHashTable(HashTable):
3536

3637
cpdef get_item(self, object val)
3738
cpdef set_item(self, object key, Py_ssize_t val)
39+
40+
cdef struct Int64VectorData:
41+
int64_t *data
42+
size_t n, m
43+
44+
cdef class Int64Vector:
45+
cdef Int64VectorData *data
46+
cdef ndarray ao
47+
48+
cdef resize(self)
49+
cpdef to_array(self)
50+
cdef inline void append(self, int64_t x)
51+
cdef extend(self, int64_t[:] x)

pandas/src/hashtable_class_helper.pxi.in

+11-1
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,14 @@ dtypes = [('Float64', 'float64', 'float64_t'),
2424
{{for name, dtype, arg in dtypes}}
2525

2626

27+
{{if dtype != 'int64'}}
28+
2729
ctypedef struct {{name}}VectorData:
2830
{{arg}} *data
2931
size_t n, m
3032

33+
{{endif}}
34+
3135

3236
@cython.wraparound(False)
3337
@cython.boundscheck(False)
@@ -65,9 +69,11 @@ dtypes = [('Float64', 'float64', 'float64_t', 'np.float64'),
6569

6670
cdef class {{name}}Vector:
6771

72+
{{if dtype != 'int64'}}
6873
cdef:
6974
{{name}}VectorData *data
7075
ndarray ao
76+
{{endif}}
7177

7278
def __cinit__(self):
7379
self.data = <{{name}}VectorData *>PyMem_Malloc(
@@ -92,7 +98,7 @@ cdef class {{name}}Vector:
9298
def __len__(self):
9399
return self.data.n
94100

95-
def to_array(self):
101+
cpdef to_array(self):
96102
self.ao.resize(self.data.n)
97103
self.data.m = self.data.n
98104
return self.ao
@@ -104,6 +110,10 @@ cdef class {{name}}Vector:
104110

105111
append_data_{{dtype}}(self.data, x)
106112

113+
cdef extend(self, {{arg}}[:] x):
114+
for i in range(len(x)):
115+
self.append(x[i])
116+
107117
{{endfor}}
108118

109119
cdef class StringVector:

0 commit comments

Comments
 (0)