Major update: obiarrays with columns containing indices referring to

character strings.
This commit is contained in:
Celine Mercier
2015-11-06 17:55:15 +01:00
parent 456551ffeb
commit 9b066f4327
35 changed files with 632 additions and 532 deletions

View File

@ -9,42 +9,24 @@ from .capi.obidmscolumn cimport obi_close_column,\
from .capi.obierrno cimport obi_errno
from .capi.obitypes cimport OBIIdx_NA, const_char_p
from libc.string cimport strlen
from obitools3.utils cimport str2bytes, bytes2str
from cpython.int cimport PyInt_FromSsize_t
cdef class OBIDMS_column_str(OBIDMS_column):
cpdef object get_line(self, size_t line_nb):
cdef const_char_p cvalue
cpdef object get_line(self, index_t line_nb):
cdef bytes value
cdef object result
cvalue = obi_column_get_obistr_with_elt_idx(self.pointer, line_nb, 0)
print('test 1')
print(hex(<int> cvalue))
print(strlen(cvalue))
print("test")
value = <bytes> cvalue
print(value)
value = <bytes> obi_column_get_obistr_with_elt_idx(self.pointer, line_nb, 0)
if obi_errno > 0 :
raise IndexError(line_nb)
if value == OBIIdx_NA :
result = None
else :
print(value)
result = bytes2str(value)
return result
cpdef set_line(self, size_t line_nb, object value):
cpdef set_line(self, index_t line_nb, object value):
raise Exception("Column is read-only")
cpdef close(self):
@ -54,7 +36,7 @@ cdef class OBIDMS_column_str(OBIDMS_column):
cdef class OBIDMS_column_str_writable(OBIDMS_column_str):
cpdef set_line(self, size_t line_nb, object value):
cpdef set_line(self, index_t line_nb, object value):
if obi_column_set_obistr_with_elt_idx(self.pointer, line_nb, 0, str2bytes(value)) < 0:
raise Exception("Problem setting a value in a column")
@ -65,10 +47,10 @@ cdef class OBIDMS_column_str_writable(OBIDMS_column_str):
cdef class OBIDMS_column_str_multi_elts(OBIDMS_column_str):
cpdef object get_item(self, size_t line_nb, str element_name):
cpdef object get_item(self, index_t line_nb, str element_name):
cdef bytes value
cdef object result
value = obi_column_get_obistr_with_elt_name(self.pointer, line_nb, str2bytes(element_name))
value = <bytes> obi_column_get_obistr_with_elt_name(self.pointer, line_nb, str2bytes(element_name))
if obi_errno > 0 :
raise IndexError(line_nb, element_name)
if value == OBIIdx_NA :
@ -77,15 +59,15 @@ cdef class OBIDMS_column_str_multi_elts(OBIDMS_column_str):
result = bytes2str(value)
return result
cpdef object get_line(self, size_t line_nb) :
cpdef object get_line(self, index_t line_nb) :
cdef bytes value
cdef object result
cdef size_t i
cdef index_t i
cdef bint all_NA
result = {}
all_NA = True
for i in range(self.nb_elements_per_line) :
value = obi_column_get_obistr_with_elt_idx(self.pointer, line_nb, i)
value = <bytes> obi_column_get_obistr_with_elt_idx(self.pointer, line_nb, i)
if obi_errno > 0 :
raise IndexError(line_nb)
result[self.elements_names[i]] = bytes2str(value)
@ -95,20 +77,20 @@ cdef class OBIDMS_column_str_multi_elts(OBIDMS_column_str):
result = None
return result
cpdef set_item(self, size_t line_nb, str element_name, str value):
cpdef set_item(self, index_t line_nb, str element_name, str value):
raise Exception("Column is read-only")
cpdef set_line(self, size_t line_nb, object values):
cpdef set_line(self, index_t line_nb, object values):
raise Exception("Column is read-only")
cdef class OBIDMS_column_str_multi_elts_writable(OBIDMS_column_str_multi_elts):
cpdef set_item(self, size_t line_nb, str element_name, str value):
cpdef set_item(self, index_t line_nb, str element_name, str value):
if obi_column_set_obistr_with_elt_name(self.pointer, line_nb, str2bytes(element_name), str2bytes(value)) < 0:
raise Exception("Problem setting a value in a column")
cpdef set_line(self, size_t line_nb, object values):
cpdef set_line(self, index_t line_nb, object values):
cdef str value
for element_name in values :
value = values[element_name]