Handling of single char columns
This commit is contained in:
@ -12,7 +12,7 @@ cdef extern from "obitypes.h" nogil:
|
||||
ctypedef OBIBool obibool_t
|
||||
ctypedef int32_t obiint_t
|
||||
ctypedef double obifloat_t
|
||||
ctypedef bytes obichar_t
|
||||
ctypedef char obichar_t
|
||||
ctypedef size_t obiidx_t
|
||||
|
||||
char* name_data_type(int data_type)
|
||||
|
@ -3,5 +3,5 @@ from obitools3.obidms.obidmscolumn.capidmscolumn cimport *
|
||||
|
||||
cdef extern from "obidmscolumn_char.h" nogil:
|
||||
|
||||
int obi_column_set_obichar_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name, obichar_t* value)
|
||||
obichar_t* obi_column_get_obichar_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name)
|
||||
int obi_column_set_obichar_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name, obichar_t value)
|
||||
obichar_t obi_column_get_obichar_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name)
|
||||
|
@ -6,10 +6,10 @@ from .capidmscolumn_char cimport *
|
||||
cdef class OBIDMS_column_char(OBIDMS_column) :
|
||||
|
||||
def get_item(self, line_nb, element_name):
|
||||
value = (obi_column_get_obichar_with_elt_name(self.pointer, line_nb, element_name.encode('utf-8'))).decode(encoding='utf-8')[:1]
|
||||
cdef char value = obi_column_get_obichar_with_elt_name(self.pointer, line_nb, element_name.encode('utf-8'))
|
||||
if obi_errno > 0 :
|
||||
raise IndexError(line_nb, element_name)
|
||||
return value
|
||||
return <bytes> value
|
||||
|
||||
|
||||
cdef class OBIDMS_column_char_read(OBIDMS_column_char) :
|
||||
@ -17,19 +17,17 @@ cdef class OBIDMS_column_char_read(OBIDMS_column_char) :
|
||||
def set_item(self, line_nb, element_name, value):
|
||||
raise Exception('Column is read-only')
|
||||
|
||||
def close(self):
|
||||
cpdef close(self):
|
||||
if obi_close_column(self.pointer) < 0 :
|
||||
raise Exception("Problem closing a column")
|
||||
|
||||
|
||||
cdef class OBIDMS_column_char_writable(OBIDMS_column_char) :
|
||||
|
||||
def set_item(self, line_nb, element_name, value):
|
||||
return obi_column_set_obichar_with_elt_name(self.pointer, line_nb, element_name.encode('utf-8'), value.encode('utf-8'))
|
||||
def set_item(self, line_nb, element_name, bytes value):
|
||||
return obi_column_set_obichar_with_elt_name(self.pointer, line_nb, element_name.encode('utf-8'), value[0])
|
||||
|
||||
def close(self):
|
||||
if obi_truncate_and_close_column(self.pointer) < 0 :
|
||||
raise Exception("Problem closing a column")
|
||||
|
||||
|
||||
|
@ -65,6 +65,7 @@ obichar_t obi_column_get_obichar_with_elt_idx(OBIDMS_column_p column, size_t lin
|
||||
obidebug(1, "\nError trying to get a value that is beyond the current number of lines used");
|
||||
return OBIChar_NA;
|
||||
}
|
||||
|
||||
return *(((obichar_t*) (column->data)) + (line_nb * ((column->header)->nb_elements_per_line)) + element_idx);
|
||||
}
|
||||
|
||||
|
@ -78,7 +78,7 @@ obichar_t* obi_column_get_obichar_with_elt_idx(OBIDMS_column_p column, size_t li
|
||||
* @since August 2015
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
int obi_column_set_obichar_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name, obichar_t* value);
|
||||
int obi_column_set_obichar_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name, obichar_t value);
|
||||
|
||||
|
||||
/**
|
||||
@ -97,5 +97,5 @@ int obi_column_set_obichar_with_elt_name(OBIDMS_column_p column, size_t line_nb,
|
||||
* @since August 2015
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
obichar_t* obi_column_get_obichar_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name);
|
||||
obichar_t obi_column_get_obichar_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name);
|
||||
|
||||
|
Reference in New Issue
Block a user