Cython API: fixed conversion bugs when setting and getting values
(especially NA values) in OBI_CHAR, OBI_STR and OBI_SEQ columns
This commit is contained in:
@ -31,7 +31,6 @@ cdef class Column_char(Column):
|
|||||||
elements_names=elements_names,
|
elements_names=elements_names,
|
||||||
comments=comments)
|
comments=comments)
|
||||||
|
|
||||||
|
|
||||||
cpdef object get_line(self, index_t line_nb):
|
cpdef object get_line(self, index_t line_nb):
|
||||||
cdef obichar_t value
|
cdef obichar_t value
|
||||||
cdef object result
|
cdef object result
|
||||||
@ -43,14 +42,16 @@ cdef class Column_char(Column):
|
|||||||
if value == OBIChar_NA :
|
if value == OBIChar_NA :
|
||||||
result = None
|
result = None
|
||||||
else :
|
else :
|
||||||
result = value # TODO return bytes or str?
|
result = <bytes>value # TODO return bytes or str?
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
cpdef set_line(self, index_t line_nb, object value):
|
cpdef set_line(self, index_t line_nb, object value):
|
||||||
|
cdef obichar_t value_b
|
||||||
if value is None :
|
if value is None :
|
||||||
value = OBIChar_NA
|
value_b = OBIChar_NA
|
||||||
if obi_set_char_with_elt_idx_and_col_p_in_view(self._view.pointer(), self.pointer(), line_nb, 0, <obichar_t> tobytes(value)[0]) < 0:
|
else :
|
||||||
|
value_b = <obichar_t> tobytes(value)[0]
|
||||||
|
if obi_set_char_with_elt_idx_and_col_p_in_view(self._view.pointer(), self.pointer(), line_nb, 0, value_b) < 0:
|
||||||
raise Exception("Problem setting a value in a column")
|
raise Exception("Problem setting a value in a column")
|
||||||
|
|
||||||
|
|
||||||
@ -70,7 +71,7 @@ cdef class Column_multi_elts_char(Column_multi_elts):
|
|||||||
if value == OBIChar_NA :
|
if value == OBIChar_NA :
|
||||||
result = None
|
result = None
|
||||||
else :
|
else :
|
||||||
result = value # TODO return bytes or str?
|
result = <bytes>value # TODO return bytes or str?
|
||||||
return result
|
return result
|
||||||
|
|
||||||
cpdef object get_line(self, index_t line_nb) :
|
cpdef object get_line(self, index_t line_nb) :
|
||||||
@ -88,7 +89,7 @@ cdef class Column_multi_elts_char(Column_multi_elts):
|
|||||||
if value == OBIChar_NA :
|
if value == OBIChar_NA :
|
||||||
value_in_result = None
|
value_in_result = None
|
||||||
else :
|
else :
|
||||||
value_in_result = value # TODO return bytes or str?
|
value_in_result = <bytes>value # TODO return bytes or str?
|
||||||
result[self.elements_names[i]] = value_in_result
|
result[self.elements_names[i]] = value_in_result
|
||||||
if all_NA and (value_in_result is not None) :
|
if all_NA and (value_in_result is not None) :
|
||||||
all_NA = False
|
all_NA = False
|
||||||
@ -98,14 +99,17 @@ cdef class Column_multi_elts_char(Column_multi_elts):
|
|||||||
|
|
||||||
cpdef set_item(self, index_t line_nb, object elt_id, object value) :
|
cpdef set_item(self, index_t line_nb, object elt_id, object value) :
|
||||||
cdef bytes elt_name
|
cdef bytes elt_name
|
||||||
|
cdef obichar_t value_b
|
||||||
if value is None :
|
if value is None :
|
||||||
value = OBIChar_NA
|
value_b = OBIChar_NA
|
||||||
|
else :
|
||||||
|
value_b = <obichar_t> tobytes(value)[0]
|
||||||
if type(elt_id) == int :
|
if type(elt_id) == int :
|
||||||
if obi_set_char_with_elt_idx_and_col_p_in_view(self._view.pointer(), self.pointer(), line_nb, elt_id, <obichar_t> tobytes(value)[0]) < 0 :
|
if obi_set_char_with_elt_idx_and_col_p_in_view(self._view.pointer(), self.pointer(), line_nb, elt_id, value_b) < 0 :
|
||||||
raise Exception("Problem setting a value in a column")
|
raise Exception("Problem setting a value in a column")
|
||||||
else :
|
else :
|
||||||
elt_name = tobytes(elt_id)
|
elt_name = tobytes(elt_id)
|
||||||
if obi_set_char_with_elt_name_and_col_p_in_view(self._view.pointer(), self.pointer(), line_nb, elt_name, <obichar_t> tobytes(value)[0]) < 0 :
|
if obi_set_char_with_elt_name_and_col_p_in_view(self._view.pointer(), self.pointer(), line_nb, elt_name, value_b) < 0 :
|
||||||
raise Exception("Problem setting a value in a column")
|
raise Exception("Problem setting a value in a column")
|
||||||
|
|
||||||
|
|
||||||
|
@ -51,11 +51,15 @@ cdef class Column_seq(Column):
|
|||||||
|
|
||||||
|
|
||||||
cpdef set_line(self, index_t line_nb, object value):
|
cpdef set_line(self, index_t line_nb, object value):
|
||||||
cdef bytes value_b
|
cdef char* value_b
|
||||||
|
cdef bytes value_bytes
|
||||||
|
|
||||||
if value is None :
|
if value is None :
|
||||||
value_b = OBISeq_NA
|
value_b = <char*>OBISeq_NA
|
||||||
else :
|
else :
|
||||||
value_b = tobytes(value)
|
value_bytes = tobytes(value)
|
||||||
|
value_b = <char*>value_bytes
|
||||||
|
|
||||||
if obi_set_seq_with_elt_idx_and_col_p_in_view(self._view.pointer(), self.pointer(), line_nb, 0, value_b) < 0:
|
if obi_set_seq_with_elt_idx_and_col_p_in_view(self._view.pointer(), self.pointer(), line_nb, 0, value_b) < 0:
|
||||||
raise Exception("Problem setting a value in a column")
|
raise Exception("Problem setting a value in a column")
|
||||||
|
|
||||||
@ -112,15 +116,21 @@ cdef class Column_multi_elts_seq(Column_multi_elts):
|
|||||||
|
|
||||||
|
|
||||||
cpdef set_item(self, index_t line_nb, object elt_id, object value):
|
cpdef set_item(self, index_t line_nb, object elt_id, object value):
|
||||||
cdef bytes value_b
|
|
||||||
cdef bytes elt_name
|
cdef bytes elt_name
|
||||||
|
cdef char* value_b
|
||||||
|
cdef bytes value_bytes
|
||||||
|
|
||||||
if value is None :
|
if value is None :
|
||||||
value_b = OBISeq_NA
|
value_b = <char*>OBISeq_NA
|
||||||
else :
|
else :
|
||||||
value_b = tobytes(value)
|
value_bytes = tobytes(value)
|
||||||
|
value_b = <char*>value_bytes
|
||||||
|
|
||||||
if type(elt_id) == int :
|
if type(elt_id) == int :
|
||||||
if obi_set_seq_with_elt_idx_and_col_p_in_view(self._view.pointer(), self.pointer(), line_nb, elt_id, value_b) < 0:
|
if obi_set_seq_with_elt_idx_and_col_p_in_view(self._view.pointer(), self.pointer(), line_nb, elt_id, value_b) < 0:
|
||||||
raise Exception("Problem setting a value in a column")
|
raise Exception("Problem setting a value in a column")
|
||||||
|
|
||||||
else :
|
else :
|
||||||
elt_name = tobytes(elt_id)
|
elt_name = tobytes(elt_id)
|
||||||
if obi_set_seq_with_elt_name_and_col_p_in_view(self._view.pointer(), self.pointer(), line_nb, elt_name, value_b) < 0:
|
if obi_set_seq_with_elt_name_and_col_p_in_view(self._view.pointer(), self.pointer(), line_nb, elt_name, value_b) < 0:
|
||||||
|
@ -38,6 +38,7 @@ cdef class Column_str(Column):
|
|||||||
value = obi_get_str_with_elt_idx_and_col_p_in_view(self._view.pointer(), self.pointer(), line_nb, 0)
|
value = obi_get_str_with_elt_idx_and_col_p_in_view(self._view.pointer(), self.pointer(), line_nb, 0)
|
||||||
if obi_errno > 0 :
|
if obi_errno > 0 :
|
||||||
raise IndexError(line_nb)
|
raise IndexError(line_nb)
|
||||||
|
print(value == NULL)
|
||||||
if value == OBIStr_NA :
|
if value == OBIStr_NA :
|
||||||
result = None
|
result = None
|
||||||
else :
|
else :
|
||||||
@ -46,11 +47,15 @@ cdef class Column_str(Column):
|
|||||||
|
|
||||||
|
|
||||||
cpdef set_line(self, index_t line_nb, object value):
|
cpdef set_line(self, index_t line_nb, object value):
|
||||||
cdef bytes value_b
|
cdef char* value_b
|
||||||
|
cdef bytes value_bytes
|
||||||
|
|
||||||
if value is None :
|
if value is None :
|
||||||
value_b = OBIStr_NA
|
value_b = <char*>OBIStr_NA
|
||||||
else :
|
else :
|
||||||
value_b = tobytes(value)
|
value_bytes = tobytes(value)
|
||||||
|
value_b = <char*>value_bytes
|
||||||
|
|
||||||
if obi_set_str_with_elt_idx_and_col_p_in_view(self._view.pointer(), self.pointer(), line_nb, 0, value_b) < 0:
|
if obi_set_str_with_elt_idx_and_col_p_in_view(self._view.pointer(), self.pointer(), line_nb, 0, value_b) < 0:
|
||||||
raise Exception("Problem setting a value in a column")
|
raise Exception("Problem setting a value in a column")
|
||||||
|
|
||||||
@ -66,6 +71,7 @@ cdef class Column_multi_elts_str(Column_multi_elts):
|
|||||||
else :
|
else :
|
||||||
elt_name = tobytes(elt_id)
|
elt_name = tobytes(elt_id)
|
||||||
value = obi_get_str_with_elt_name_and_col_p_in_view(self._view.pointer(), self.pointer(), line_nb, elt_name)
|
value = obi_get_str_with_elt_name_and_col_p_in_view(self._view.pointer(), self.pointer(), line_nb, elt_name)
|
||||||
|
print(value == NULL)
|
||||||
if obi_errno > 0 :
|
if obi_errno > 0 :
|
||||||
raise IndexError(line_nb, elt_id)
|
raise IndexError(line_nb, elt_id)
|
||||||
if value == OBIStr_NA :
|
if value == OBIStr_NA :
|
||||||
@ -86,6 +92,7 @@ cdef class Column_multi_elts_str(Column_multi_elts):
|
|||||||
all_NA = True
|
all_NA = True
|
||||||
for i in range(self.nb_elements_per_line) :
|
for i in range(self.nb_elements_per_line) :
|
||||||
value = obi_get_str_with_elt_idx_and_col_p_in_view(self._view.pointer(), self.pointer(), line_nb, i)
|
value = obi_get_str_with_elt_idx_and_col_p_in_view(self._view.pointer(), self.pointer(), line_nb, i)
|
||||||
|
print(value == NULL)
|
||||||
if obi_errno > 0 :
|
if obi_errno > 0 :
|
||||||
raise IndexError(line_nb)
|
raise IndexError(line_nb)
|
||||||
if value == OBIStr_NA :
|
if value == OBIStr_NA :
|
||||||
@ -101,18 +108,22 @@ cdef class Column_multi_elts_str(Column_multi_elts):
|
|||||||
|
|
||||||
|
|
||||||
cpdef set_item(self, index_t line_nb, object elt_id, object value):
|
cpdef set_item(self, index_t line_nb, object elt_id, object value):
|
||||||
cdef bytes value_b
|
|
||||||
cdef bytes elt_name
|
cdef bytes elt_name
|
||||||
|
cdef char* value_b
|
||||||
|
cdef bytes value_bytes
|
||||||
|
|
||||||
if value is None :
|
if value is None :
|
||||||
value_b = OBIStr_NA
|
value_b = <char*>OBIStr_NA
|
||||||
else :
|
else :
|
||||||
value_b = tobytes(value)
|
value_bytes = tobytes(value)
|
||||||
|
value_b = <char*>value_bytes
|
||||||
|
|
||||||
if type(elt_id) == int :
|
if type(elt_id) == int :
|
||||||
if obi_set_str_with_elt_idx_and_col_p_in_view(self._view.pointer(), self.pointer(), line_nb, elt_id, value_b) < 0:
|
if obi_set_str_with_elt_idx_and_col_p_in_view(self._view.pointer(), self.pointer(), line_nb, elt_id, <char*>value_b) < 0:
|
||||||
raise Exception("Problem setting a value in a column")
|
raise Exception("Problem setting a value in a column")
|
||||||
else :
|
else :
|
||||||
elt_name = tobytes(elt_id)
|
elt_name = tobytes(elt_id)
|
||||||
if obi_set_str_with_elt_name_and_col_p_in_view(self._view.pointer(), self.pointer(), line_nb, elt_name, value_b) < 0:
|
if obi_set_str_with_elt_name_and_col_p_in_view(self._view.pointer(), self.pointer(), line_nb, elt_name, <char*>value_b) < 0:
|
||||||
raise Exception("Problem setting a value in a column")
|
raise Exception("Problem setting a value in a column")
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user