@@ -76,7 +76,7 @@ class VLenUTF8(Codec):
7676 @ cython.boundscheck (False )
7777 def encode (self , buf ):
7878 cdef:
79- Py_ssize_t i, l, n_items, data_length, total_length
79+ Py_ssize_t i, l, n_items, data_length
8080 ndarray[object , ndim= 1 ] input_values
8181 object [:] encoded_values
8282 int [:] encoded_lengths
@@ -97,7 +97,7 @@ class VLenUTF8(Codec):
9797 encoded_lengths = np.empty(n_items, dtype = np.intc)
9898
9999 # first iteration to convert to bytes
100- data_length = 0
100+ data_length = HEADER_LENGTH
101101 for i in range (n_items):
102102 o = input_values[i]
103103 # replace missing value and coerce to typed data
@@ -109,8 +109,7 @@ class VLenUTF8(Codec):
109109 encoded_lengths[i] = l
110110
111111 # setup output
112- total_length = HEADER_LENGTH + data_length
113- out = PyByteArray_FromStringAndSize(NULL , total_length)
112+ out = PyByteArray_FromStringAndSize(NULL , data_length)
114113
115114 # write header
116115 data = out
@@ -208,7 +207,7 @@ class VLenBytes(Codec):
208207 @ cython.boundscheck (False )
209208 def encode (self , buf ):
210209 cdef:
211- Py_ssize_t i, l, n_items, data_length, total_length
210+ Py_ssize_t i, l, n_items, data_length
212211 object [:] values
213212 object [:] normed_values
214213 int [:] lengths
@@ -228,7 +227,7 @@ class VLenBytes(Codec):
228227 lengths = np.empty(n_items, dtype = np.intc)
229228
230229 # first iteration to find lengths
231- data_length = 0
230+ data_length = HEADER_LENGTH
232231 for i in range (n_items):
233232 o = values[i]
234233 # replace missing value and coerce to typed data
@@ -239,8 +238,7 @@ class VLenBytes(Codec):
239238 lengths[i] = l
240239
241240 # setup output
242- total_length = HEADER_LENGTH + data_length
243- out = PyByteArray_FromStringAndSize(NULL , total_length)
241+ out = PyByteArray_FromStringAndSize(NULL , data_length)
244242
245243 # write header
246244 data = out
@@ -351,7 +349,7 @@ class VLenArray(Codec):
351349 @ cython.boundscheck (False )
352350 def encode (self , buf ):
353351 cdef:
354- Py_ssize_t i, l, n_items, data_length, total_length
352+ Py_ssize_t i, l, n_items, data_length
355353 object [:] values
356354 object [:] normed_values
357355 int [:] lengths
@@ -373,7 +371,7 @@ class VLenArray(Codec):
373371 lengths = np.empty(n_items, dtype = np.intc)
374372
375373 # first iteration to convert to bytes
376- data_length = 0
374+ data_length = HEADER_LENGTH
377375 for i in range (n_items):
378376 o = values[i]
379377 # replace missing value and coerce to typed data
@@ -390,8 +388,7 @@ class VLenArray(Codec):
390388 lengths[i] = l
391389
392390 # setup output
393- total_length = HEADER_LENGTH + data_length
394- out = PyByteArray_FromStringAndSize(NULL , total_length)
391+ out = PyByteArray_FromStringAndSize(NULL , data_length)
395392
396393 # write header
397394 data = out
0 commit comments