Major update : views
This commit is contained in:
@ -1,13 +1,12 @@
|
||||
#cython: language_level=3
|
||||
|
||||
from .capi.obidmscolumn cimport obi_close_column,\
|
||||
obi_truncate_and_close_column, \
|
||||
obi_column_get_obiint_with_elt_name, \
|
||||
obi_column_get_obiint_with_elt_idx, \
|
||||
obi_column_set_obiint_with_elt_name, \
|
||||
obi_column_set_obiint_with_elt_idx
|
||||
from .capi.obidmscolumn cimport obi_truncate_and_close_column, \
|
||||
obi_column_get_obiint_with_elt_name_in_view, \
|
||||
obi_column_get_obiint_with_elt_idx_in_view, \
|
||||
obi_column_set_obiint_with_elt_name_in_view, \
|
||||
obi_column_set_obiint_with_elt_idx_in_view
|
||||
from .capi.obierrno cimport obi_errno
|
||||
from .capi.obitypes cimport OBIInt_NA
|
||||
from .capi.obitypes cimport OBIInt_NA, obiint_t
|
||||
|
||||
from obitools3.utils cimport str2bytes
|
||||
|
||||
@ -19,7 +18,7 @@ cdef class OBIDMS_column_int(OBIDMS_column):
|
||||
cpdef object get_line(self, index_t line_nb):
|
||||
cdef obiint_t value
|
||||
cdef object result
|
||||
value = obi_column_get_obiint_with_elt_idx(self.pointer, line_nb, 0)
|
||||
value = obi_column_get_obiint_with_elt_idx_in_view(self.view, (self.pointer)[0], line_nb, 0)
|
||||
if obi_errno > 0 :
|
||||
raise IndexError(line_nb)
|
||||
if value == OBIInt_NA :
|
||||
@ -27,32 +26,20 @@ cdef class OBIDMS_column_int(OBIDMS_column):
|
||||
else :
|
||||
result = PyInt_FromLong(value)
|
||||
return result
|
||||
|
||||
|
||||
cpdef set_line(self, index_t line_nb, object value):
|
||||
raise Exception("Column is read-only")
|
||||
|
||||
cpdef close(self):
|
||||
if obi_close_column(self.pointer) < 0 :
|
||||
raise Exception("Problem closing a column")
|
||||
|
||||
|
||||
cdef class OBIDMS_column_int_writable(OBIDMS_column_int):
|
||||
|
||||
cpdef set_line(self, index_t line_nb, object value):
|
||||
if obi_column_set_obiint_with_elt_idx(self.pointer, line_nb, 0, <obiint_t> value) < 0:
|
||||
if value is None :
|
||||
value = OBIInt_NA
|
||||
if obi_column_set_obiint_with_elt_idx_in_view(self.view, (self.pointer)[0], line_nb, 0, <obiint_t> value) < 0:
|
||||
raise Exception("Problem setting a value in a column")
|
||||
|
||||
cpdef close(self):
|
||||
if obi_truncate_and_close_column(self.pointer) < 0 :
|
||||
raise Exception("Problem closing a column")
|
||||
|
||||
|
||||
cdef class OBIDMS_column_int_multi_elts(OBIDMS_column_int):
|
||||
cdef class OBIDMS_column_multi_elts_int(OBIDMS_column_multi_elts):
|
||||
|
||||
cpdef object get_item(self, index_t line_nb, str element_name):
|
||||
cdef obiint_t value
|
||||
cdef object result
|
||||
value = obi_column_get_obiint_with_elt_name(self.pointer, line_nb, str2bytes(element_name))
|
||||
value = obi_column_get_obiint_with_elt_name_in_view(self.view, (self.pointer)[0], line_nb, str2bytes(element_name))
|
||||
if obi_errno > 0 :
|
||||
raise IndexError(line_nb, element_name)
|
||||
if value == OBIInt_NA :
|
||||
@ -63,42 +50,30 @@ cdef class OBIDMS_column_int_multi_elts(OBIDMS_column_int):
|
||||
|
||||
cpdef object get_line(self, index_t line_nb) :
|
||||
cdef obiint_t value
|
||||
cdef object result
|
||||
cdef object value_in_result
|
||||
cdef dict result
|
||||
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_obiint_with_elt_idx(self.pointer, line_nb, i)
|
||||
value = obi_column_get_obiint_with_elt_idx_in_view(self.view, (self.pointer)[0], line_nb, i)
|
||||
if obi_errno > 0 :
|
||||
raise IndexError(line_nb)
|
||||
result[self.elements_names[i]] = PyInt_FromLong(value)
|
||||
if all_NA and (value != OBIInt_NA) :
|
||||
raise IndexError(line_nb)
|
||||
if value == OBIInt_NA :
|
||||
value_in_result = None
|
||||
else :
|
||||
value_in_result = PyInt_FromLong(value)
|
||||
result[self.elements_names[i]] = value_in_result
|
||||
if all_NA and (value_in_result is not None) :
|
||||
all_NA = False
|
||||
if all_NA :
|
||||
result = None
|
||||
result = None # TODO discuss
|
||||
return result
|
||||
|
||||
cpdef set_item(self, index_t line_nb, str element_name, obiint_t value):
|
||||
raise Exception("Column is read-only")
|
||||
|
||||
cpdef set_line(self, index_t line_nb, object values):
|
||||
raise Exception("Column is read-only")
|
||||
|
||||
|
||||
cdef class OBIDMS_column_int_multi_elts_writable(OBIDMS_column_int_multi_elts):
|
||||
|
||||
cpdef set_item(self, index_t line_nb, str element_name, obiint_t value):
|
||||
if obi_column_set_obiint_with_elt_name(self.pointer, line_nb, str2bytes(element_name), value) < 0:
|
||||
cpdef set_item(self, index_t line_nb, str element_name, object value):
|
||||
if value is None :
|
||||
value = OBIInt_NA
|
||||
if obi_column_set_obiint_with_elt_name_in_view(self.view, (self.pointer)[0], line_nb, str2bytes(element_name), <obiint_t> value) < 0:
|
||||
raise Exception("Problem setting a value in a column")
|
||||
|
||||
cpdef set_line(self, index_t line_nb, object values):
|
||||
cdef obiint_t value
|
||||
for element_name in values :
|
||||
value = <obiint_t> values[element_name]
|
||||
self.set_item(line_nb, element_name, value)
|
||||
|
||||
cpdef close(self):
|
||||
if obi_truncate_and_close_column(self.pointer) < 0 :
|
||||
raise Exception("Problem closing a column")
|
||||
|
||||
|
Reference in New Issue
Block a user