Commit 9b066f43 by Celine Mercier

Major update: obiarrays with columns containing indices referring to

character strings.
parent 456551ff
......@@ -2,7 +2,7 @@
from .capi.obidms cimport OBIDMS_p
from .capi.obidmscolumn cimport OBIDMS_column_p
from .capi.obitypes cimport obiversion_t, OBIType_t
from .capi.obitypes cimport obiversion_t, OBIType_t, index_t
cdef class OBIDMS_column
......@@ -21,8 +21,8 @@ cdef class OBIDMS:
bint clone=*, bint clone_data=*,
obiversion_t version_number=*,
OBIType_t data_type=*,
size_t nb_lines=*,
size_t nb_elements_per_line=*,
index_t nb_lines=*,
index_t nb_elements_per_line=*,
list elements_names=*,
str array_name=*)
......@@ -34,14 +34,14 @@ cdef class OBIDMS_column:
cdef str data_type # TODO keep as OBIType_t? both?
cdef str dms_name
cdef str column_name
cdef size_t nb_elements_per_line
cdef index_t nb_elements_per_line
cdef list elements_names
# cpdef object get_item(self, size_t line_nb, str element_name) TODO can't declare because not the same in all subclasses
# cpdef set_item(self, size_t line_nb, str element_name, object value) TODO can't declare because object value
cpdef list get_elements_names(self)
cpdef str get_data_type(self)
cpdef size_t get_nb_lines_used(self)
cpdef str get_creation_date(self)
cpdef close(self)
# cpdef object get_item(self, index_t line_nb, str element_name) TODO can't declare because not the same in all subclasses
# cpdef set_item(self, index_t line_nb, str element_name, object value) TODO can't declare because object value
cpdef list get_elements_names(self)
cpdef str get_data_type(self)
cpdef index_t get_nb_lines_used(self)
cpdef str get_creation_date(self)
cpdef close(self)
......@@ -80,7 +80,7 @@ cdef class OBIDMS :
cdef str data_type
cdef str creation_date
cdef obiversion_t latest_version
cdef size_t line_count
cdef index_t line_count
cdef OBIDMS_column_header_p header
p = Path(self.dms_name+'.obidms')
......@@ -117,8 +117,8 @@ cdef class OBIDMS :
bint clone=False, bint clone_data=True,
obiversion_t version_number=-1,
OBIType_t data_type= <OBIType_t> 0,
size_t nb_lines=0,
size_t nb_elements_per_line=0,
index_t nb_lines=0,
index_t nb_elements_per_line=0,
list elements_names=None,
str array_name="default_obiarray"):
......@@ -222,7 +222,7 @@ cdef class OBIDMS :
version_number, data_type,
nb_lines, nb_elements_per_line,
elements_names, array_name)
return column
......@@ -237,8 +237,8 @@ cdef class OBIDMS_column :
bint clone, bint clone_data,
obiversion_t version_number,
OBIType_t type,
size_t nb_lines,
size_t nb_elements_per_line,
index_t nb_lines,
index_t nb_elements_per_line,
list elements_names,
str array_name):
......@@ -279,8 +279,8 @@ cdef class OBIDMS_column :
def __iter__(self):
# Declarations
cdef size_t lines_used
cdef size_t line_nb
cdef index_t lines_used
cdef index_t line_nb
# Yield each line
lines_used = self.pointer.header.lines_used
......@@ -288,19 +288,19 @@ cdef class OBIDMS_column :
yield self.get_line(line_nb)
def __setitem__(self, size_t line_nb, object value):
def __setitem__(self, index_t line_nb, object value):
self.set_line(line_nb, value)
def __getitem__(self, size_t line_nb):
def __getitem__(self, index_t line_nb):
return self.get_line(line_nb)
# cpdef object get_item(self, size_t line_nb, str element_name): TODO
# cpdef object get_item(self, index_t line_nb, str element_name): TODO
# raise NotImplementedError
# cpdef set_item(self, size_t line_nb, str element_name, object value): TODO
# cpdef set_item(self, index_t line_nb, str element_name, object value): TODO
# raise NotImplementedError
......@@ -312,7 +312,7 @@ cdef class OBIDMS_column :
return self.data_type
cpdef size_t get_nb_lines_used(self):
cpdef index_t get_nb_lines_used(self):
return self.pointer.header.lines_used
......
#cython: language_level=3
from .capi.obitypes cimport obibool_t
from .capi.obitypes cimport obibool_t, index_t
from ._obidms cimport OBIDMS_column
cdef class OBIDMS_column_bool(OBIDMS_column):
cpdef object get_line(self, size_t line_nb)
cpdef set_line(self, size_t line_nb, object value)
cpdef object get_line(self, index_t line_nb)
cpdef set_line(self, index_t line_nb, object value)
cpdef close(self)
cdef class OBIDMS_column_bool_writable(OBIDMS_column_bool):
cpdef set_line(self, size_t line_nb, object value)
cpdef set_line(self, index_t line_nb, object value)
cpdef close(self)
cdef class OBIDMS_column_bool_multi_elts(OBIDMS_column_bool):
cpdef object get_item(self, size_t line_nb, str element_name)
cpdef object get_line(self, size_t line_nb)
cpdef set_item(self, size_t line_nb, str element_name, obibool_t value)
cpdef set_line(self, size_t line_nb, object values)
cpdef object get_item(self, index_t line_nb, str element_name)
cpdef object get_line(self, index_t line_nb)
cpdef set_item(self, index_t line_nb, str element_name, obibool_t value)
cpdef set_line(self, index_t line_nb, object values)
cdef class OBIDMS_column_bool_multi_elts_writable(OBIDMS_column_bool_multi_elts):
cpdef set_item(self, size_t line_nb, str element_name, obibool_t value)
cpdef set_line(self, size_t line_nb, object values)
cpdef set_item(self, index_t line_nb, str element_name, obibool_t value)
cpdef set_line(self, index_t line_nb, object values)
cpdef close(self)
......@@ -16,7 +16,7 @@ from cpython.bool cimport PyBool_FromLong
cdef class OBIDMS_column_bool(OBIDMS_column):
cpdef object get_line(self, size_t line_nb):
cpdef object get_line(self, index_t line_nb):
cdef obibool_t value
cdef object result
value = obi_column_get_obibool_with_elt_idx(self.pointer, line_nb, 0)
......@@ -28,7 +28,7 @@ cdef class OBIDMS_column_bool(OBIDMS_column):
result = PyBool_FromLong(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):
......@@ -38,7 +38,7 @@ cdef class OBIDMS_column_bool(OBIDMS_column):
cdef class OBIDMS_column_bool_writable(OBIDMS_column_bool):
cpdef set_line(self, size_t line_nb, object value):
cpdef set_line(self, index_t line_nb, object value):
if obi_column_set_obibool_with_elt_idx(self.pointer, line_nb, 0, <obibool_t> value) < 0:
raise Exception("Problem setting a value in a column")
......@@ -49,7 +49,7 @@ cdef class OBIDMS_column_bool_writable(OBIDMS_column_bool):
cdef class OBIDMS_column_bool_multi_elts(OBIDMS_column_bool):
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 obibool_t value
cdef object result
value = obi_column_get_obibool_with_elt_name(self.pointer, line_nb, str2bytes(element_name))
......@@ -61,10 +61,10 @@ cdef class OBIDMS_column_bool_multi_elts(OBIDMS_column_bool):
result = PyBool_FromLong(value)
return result
cpdef object get_line(self, size_t line_nb) :
cpdef object get_line(self, index_t line_nb) :
cdef obibool_t value
cdef object result
cdef size_t i
cdef index_t i
cdef bint all_NA
result = {}
all_NA = True
......@@ -79,20 +79,20 @@ cdef class OBIDMS_column_bool_multi_elts(OBIDMS_column_bool):
result = None
return result
cpdef set_item(self, size_t line_nb, str element_name, obibool_t value):
cpdef set_item(self, index_t line_nb, str element_name, obibool_t 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_bool_multi_elts_writable(OBIDMS_column_bool_multi_elts):
cpdef set_item(self, size_t line_nb, str element_name, obibool_t value):
cpdef set_item(self, index_t line_nb, str element_name, obibool_t value):
if obi_column_set_obibool_with_elt_name(self.pointer, line_nb, str2bytes(element_name), 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 obibool_t value
for element_name in values :
value = <obibool_t> values[element_name]
......
#cython: language_level=3
from .capi.obitypes cimport obichar_t
from .capi.obitypes cimport obichar_t, index_t
from ._obidms cimport OBIDMS_column
cdef class OBIDMS_column_char(OBIDMS_column):
cpdef object get_line(self, size_t line_nb)
cpdef set_line(self, size_t line_nb, object value)
cpdef object get_line(self, index_t line_nb)
cpdef set_line(self, index_t line_nb, object value)
cpdef close(self)
cdef class OBIDMS_column_char_writable(OBIDMS_column_char):
cpdef set_line(self, size_t line_nb, object value)
cpdef set_line(self, index_t line_nb, object value)
cpdef close(self)
cdef class OBIDMS_column_char_multi_elts(OBIDMS_column_char):
cpdef object get_item(self, size_t line_nb, str element_name)
cpdef object get_line(self, size_t line_nb)
cpdef set_item(self, size_t line_nb, str element_name, bytes value)
cpdef set_line(self, size_t line_nb, object values)
cpdef object get_item(self, index_t line_nb, str element_name)
cpdef object get_line(self, index_t line_nb)
cpdef set_item(self, index_t line_nb, str element_name, bytes value)
cpdef set_line(self, index_t line_nb, object values)
cdef class OBIDMS_column_char_multi_elts_writable(OBIDMS_column_char_multi_elts):
cpdef set_item(self, size_t line_nb, str element_name, bytes value)
cpdef set_line(self, size_t line_nb, object values)
cpdef set_item(self, index_t line_nb, str element_name, bytes value)
cpdef set_line(self, index_t line_nb, object values)
cpdef close(self)
......@@ -14,7 +14,7 @@ from obitools3.utils cimport str2bytes
cdef class OBIDMS_column_char(OBIDMS_column):
cpdef object get_line(self, size_t line_nb):
cpdef object get_line(self, index_t line_nb):
cdef obichar_t value
cdef object result
value = obi_column_get_obichar_with_elt_idx(self.pointer, line_nb, 0)
......@@ -26,7 +26,7 @@ cdef class OBIDMS_column_char(OBIDMS_column):
result = <bytes> 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):
......@@ -36,7 +36,7 @@ cdef class OBIDMS_column_char(OBIDMS_column):
cdef class OBIDMS_column_char_writable(OBIDMS_column_char):
cpdef set_line(self, size_t line_nb, object value):
cpdef set_line(self, index_t line_nb, object value):
if obi_column_set_obichar_with_elt_idx(self.pointer, line_nb, 0, <bytes> value[0]) < 0:
raise Exception("Problem setting a value in a column")
......@@ -47,7 +47,7 @@ cdef class OBIDMS_column_char_writable(OBIDMS_column_char):
cdef class OBIDMS_column_char_multi_elts(OBIDMS_column_char):
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 obichar_t value
cdef object result
value = obi_column_get_obichar_with_elt_name(self.pointer, line_nb, str2bytes(element_name))
......@@ -59,10 +59,10 @@ cdef class OBIDMS_column_char_multi_elts(OBIDMS_column_char):
result = <bytes> value
return result
cpdef object get_line(self, size_t line_nb) :
cpdef object get_line(self, index_t line_nb) :
cdef obichar_t value
cdef object result
cdef size_t i
cdef index_t i
cdef bint all_NA
result = {}
all_NA = True
......@@ -77,20 +77,20 @@ cdef class OBIDMS_column_char_multi_elts(OBIDMS_column_char):
result = None
return result
cpdef set_item(self, size_t line_nb, str element_name, bytes value):
cpdef set_item(self, index_t line_nb, str element_name, bytes 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_char_multi_elts_writable(OBIDMS_column_char_multi_elts):
cpdef set_item(self, size_t line_nb, str element_name, bytes value):
cpdef set_item(self, index_t line_nb, str element_name, bytes value):
if obi_column_set_obichar_with_elt_name(self.pointer, line_nb, str2bytes(element_name), value[0]) < 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 bytes value
for element_name in values :
value = <bytes> values[element_name]
......@@ -106,7 +106,7 @@ cdef class OBIDMS_column_char_multi_elts_writable(OBIDMS_column_char_multi_elts)
# cdef class OBIDMS_column_char(OBIDMS_column) :
#
# 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 char value
# cdef object result
# value = obi_column_get_obichar_with_elt_name(self.pointer, line_nb, str2bytes(element_name))
......@@ -118,7 +118,7 @@ cdef class OBIDMS_column_char_multi_elts_writable(OBIDMS_column_char_multi_elts)
# result = <bytes> value
# return result
#
# cpdef set_item(self, size_t line_nb, str element_name, bytes value):
# cpdef set_item(self, index_t line_nb, str element_name, bytes value):
# raise Exception("Column is read-only")
#
# cpdef close(self):
......@@ -128,7 +128,7 @@ cdef class OBIDMS_column_char_multi_elts_writable(OBIDMS_column_char_multi_elts)
#
# cdef class OBIDMS_column_char_writable(OBIDMS_column_char) :
#
# cpdef set_item(self, size_t line_nb, str element_name, bytes value):
# cpdef set_item(self, index_t line_nb, str element_name, bytes value):
# if obi_column_set_obichar_with_elt_name(self.pointer, line_nb, str2bytes(element_name), value[0]) < 0:
# raise Exception("Problem setting a value in a column")
#
......
#cython: language_level=3
from .capi.obitypes cimport obifloat_t
from .capi.obitypes cimport obifloat_t, index_t
from ._obidms cimport OBIDMS_column
cdef class OBIDMS_column_float(OBIDMS_column):
cpdef object get_line(self, size_t line_nb)
cpdef set_line(self, size_t line_nb, object value)
cpdef object get_line(self, index_t line_nb)
cpdef set_line(self, index_t line_nb, object value)
cpdef close(self)
cdef class OBIDMS_column_float_writable(OBIDMS_column_float):
cpdef set_line(self, size_t line_nb, object value)
cpdef set_line(self, index_t line_nb, object value)
cpdef close(self)
cdef class OBIDMS_column_float_multi_elts(OBIDMS_column_float):
cpdef object get_item(self, size_t line_nb, str element_name)
cpdef object get_line(self, size_t line_nb)
cpdef set_item(self, size_t line_nb, str element_name, obifloat_t value)
cpdef set_line(self, size_t line_nb, object values)
cpdef object get_item(self, index_t line_nb, str element_name)
cpdef object get_line(self, index_t line_nb)
cpdef set_item(self, index_t line_nb, str element_name, obifloat_t value)
cpdef set_line(self, index_t line_nb, object values)
cdef class OBIDMS_column_float_multi_elts_writable(OBIDMS_column_float_multi_elts):
cpdef set_item(self, size_t line_nb, str element_name, obifloat_t value)
cpdef set_line(self, size_t line_nb, object values)
cpdef set_item(self, index_t line_nb, str element_name, obifloat_t value)
cpdef set_line(self, index_t line_nb, object values)
cpdef close(self)
......@@ -14,7 +14,7 @@ from obitools3.utils cimport str2bytes
cdef class OBIDMS_column_float(OBIDMS_column):
cpdef object get_line(self, size_t line_nb):
cpdef object get_line(self, index_t line_nb):
cdef obifloat_t value
cdef object result
value = obi_column_get_obifloat_with_elt_idx(self.pointer, line_nb, 0)
......@@ -26,7 +26,7 @@ cdef class OBIDMS_column_float(OBIDMS_column):
result = <double> 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):
......@@ -36,7 +36,7 @@ cdef class OBIDMS_column_float(OBIDMS_column):
cdef class OBIDMS_column_float_writable(OBIDMS_column_float):
cpdef set_line(self, size_t line_nb, object value):
cpdef set_line(self, index_t line_nb, object value):
if obi_column_set_obifloat_with_elt_idx(self.pointer, line_nb, 0, <obifloat_t> value) < 0:
raise Exception("Problem setting a value in a column")
......@@ -47,7 +47,7 @@ cdef class OBIDMS_column_float_writable(OBIDMS_column_float):
cdef class OBIDMS_column_float_multi_elts(OBIDMS_column_float):
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 obifloat_t value
cdef object result
value = obi_column_get_obifloat_with_elt_name(self.pointer, line_nb, str2bytes(element_name))
......@@ -59,10 +59,10 @@ cdef class OBIDMS_column_float_multi_elts(OBIDMS_column_float):
result = <double> value
return result
cpdef object get_line(self, size_t line_nb) :
cpdef object get_line(self, index_t line_nb) :
cdef obifloat_t value
cdef object result
cdef size_t i
cdef index_t i
cdef bint all_NA
result = {}
all_NA = True
......@@ -77,20 +77,20 @@ cdef class OBIDMS_column_float_multi_elts(OBIDMS_column_float):
result = None
return result
cpdef set_item(self, size_t line_nb, str element_name, obifloat_t value):
cpdef set_item(self, index_t line_nb, str element_name, obifloat_t 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_float_multi_elts_writable(OBIDMS_column_float_multi_elts):
cpdef set_item(self, size_t line_nb, str element_name, obifloat_t value):
cpdef set_item(self, index_t line_nb, str element_name, obifloat_t value):
if obi_column_set_obifloat_with_elt_name(self.pointer, line_nb, str2bytes(element_name), 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 obifloat_t value
for element_name in values :
value = <obifloat_t> values[element_name]
......
#cython: language_level=3
from .capi.obitypes cimport obiint_t
from .capi.obitypes cimport obiint_t, index_t
from ._obidms cimport OBIDMS_column
cdef class OBIDMS_column_int(OBIDMS_column):
cpdef object get_line(self, size_t line_nb)
cpdef set_line(self, size_t line_nb, object value)
cpdef object get_line(self, index_t line_nb)
cpdef set_line(self, index_t line_nb, object value)
cpdef close(self)
cdef class OBIDMS_column_int_writable(OBIDMS_column_int):
cpdef set_line(self, size_t line_nb, object value)
cpdef set_line(self, index_t line_nb, object value)
cpdef close(self)
cdef class OBIDMS_column_int_multi_elts(OBIDMS_column_int):
cpdef object get_item(self, size_t line_nb, str element_name)
cpdef object get_line(self, size_t line_nb)
cpdef set_item(self, size_t line_nb, str element_name, obiint_t value)
cpdef set_line(self, size_t line_nb, object values)
cpdef object get_item(self, index_t line_nb, str element_name)
cpdef object get_line(self, index_t line_nb)
cpdef set_item(self, index_t line_nb, str element_name, obiint_t value)
cpdef set_line(self, index_t line_nb, object values)
cdef class OBIDMS_column_int_multi_elts_writable(OBIDMS_column_int_multi_elts):
cpdef set_item(self, size_t line_nb, str element_name, obiint_t value)
cpdef set_line(self, size_t line_nb, object values)
cpdef set_item(self, index_t line_nb, str element_name, obiint_t value)
cpdef set_line(self, index_t line_nb, object values)
cpdef close(self)
......@@ -16,7 +16,7 @@ from cpython.int cimport PyInt_FromLong
cdef class OBIDMS_column_int(OBIDMS_column):
cpdef object get_line(self, size_t line_nb):
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)
......@@ -28,7 +28,7 @@ cdef class OBIDMS_column_int(OBIDMS_column):
result = PyInt_FromLong(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):
......@@ -38,7 +38,7 @@ cdef class OBIDMS_column_int(OBIDMS_column):
cdef class OBIDMS_column_int_writable(OBIDMS_column_int):
cpdef set_line(self, size_t line_nb, object value):
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:
raise Exception("Problem setting a value in a column")
......@@ -49,7 +49,7 @@ cdef class OBIDMS_column_int_writable(OBIDMS_column_int):
cdef class OBIDMS_column_int_multi_elts(OBIDMS_column_int):
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 obiint_t value
cdef object result
value = obi_column_get_obiint_with_elt_name(self.pointer, line_nb, str2bytes(element_name))
......@@ -61,10 +61,10 @@ cdef class OBIDMS_column_int_multi_elts(OBIDMS_column_int):
result = PyInt_FromLong(value)
return result
cpdef object get_line(self, size_t line_nb) :
cpdef object get_line(self, index_t line_nb) :
cdef obiint_t value
cdef object result
cdef size_t i
cdef index_t i
cdef bint all_NA
result = {}
all_NA = True
......@@ -79,20 +79,20 @@ cdef class OBIDMS_column_int_multi_elts(OBIDMS_column_int):
result = None
return result
cpdef set_item(self, size_t line_nb, str element_name, obiint_t value):
cpdef set_item(self, index_t line_nb, str element_name, obiint_t 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_int_multi_elts_writable(OBIDMS_column_int_multi_elts):
cpdef set_item(self, size_t line_nb, str element_name, obiint_t value):
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:
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 obiint_t value
for element_name in values :
value = <obiint_t> values[element_name]
......
#cython: language_level=3
from .capi.obitypes cimport index_t
from ._obidms cimport OBIDMS_column
cdef class OBIDMS_column_str(OBIDMS_column):
cpdef object get_line(self, size_t line_nb)
cpdef set_line(self, size_t line_nb, object value)
cpdef object get_line(self, index_t line_nb)
cpdef set_line(self, index_t line_nb, object value)
cpdef close(self)
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)
cpdef close(self)
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_line(self, size_t line_nb)
cpdef set_item(self, size_t line_nb, str element_name, str value)
cpdef set_line(self, size_t line_nb, object values)
cpdef object get_item(self, index_t line_nb, str element_name)
cpdef object get_line(self, index_t line_nb)
cpdef set_item(self, index_t line_nb, str element_name, str value)
cpdef set_line(self, index_t line_nb, object values)
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_line(self, size_t line_nb, object values)
cpdef set_item(self, index_t line_nb, str element_name, str value)
cpdef set_line(self, index_t line_nb, object values)
cpdef close(self)
......@@ -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]
......
......@@ -8,6 +8,7 @@ from ..capi.obitypes cimport const_char_p, \
obibool_t, \
obichar_t, \
obifloat_t, \
index_t, \
time_t
......@@ -16,9 +17,9 @@ cdef extern from "obidmscolumn.h" nogil:
struct OBIDMS_column_header_t:
bint little_endian
int header_size
size_t line_count
size_t lines_used
size_t nb_elements_per_line
index_t line_count
index_t lines_used
index_t nb_elements_per_line