Cython API, Views: guessing an obitype from a python value is now done
through the corresponding functions in utils
This commit is contained in:
@ -27,7 +27,8 @@ from obitools3.utils cimport tobytes, \
|
|||||||
tostr, \
|
tostr, \
|
||||||
bytes2str_object, \
|
bytes2str_object, \
|
||||||
str2bytes_object, \
|
str2bytes_object, \
|
||||||
clean_empty_values_from_object
|
clean_empty_values_from_object, \
|
||||||
|
get_obitype
|
||||||
|
|
||||||
from ..object cimport OBIDeactivatedInstanceError
|
from ..object cimport OBIDeactivatedInstanceError
|
||||||
|
|
||||||
@ -262,6 +263,7 @@ cdef class View(OBIWrapper) :
|
|||||||
|
|
||||||
|
|
||||||
# TODO warning, not multithreading compliant
|
# TODO warning, not multithreading compliant
|
||||||
|
# TODO there is a bug when rewriting a partial line with None values
|
||||||
cpdef Column rewrite_column_with_diff_attributes(self,
|
cpdef Column rewrite_column_with_diff_attributes(self,
|
||||||
object column_name,
|
object column_name,
|
||||||
obitype_t new_data_type=<obitype_t>OBI_VOID,
|
obitype_t new_data_type=<obitype_t>OBI_VOID,
|
||||||
@ -719,25 +721,8 @@ cdef class Line :
|
|||||||
if value is None :
|
if value is None :
|
||||||
return # TODO discuss. This means that columns aren't created until an identifiable type is found
|
return # TODO discuss. This means that columns aren't created until an identifiable type is found
|
||||||
#raise RollbackException("Trying to create a column from a None value (can't guess type)", self)
|
#raise RollbackException("Trying to create a column from a None value (can't guess type)", self)
|
||||||
value_type = type(value)
|
value_obitype = get_obitype(value)
|
||||||
if value_type == int :
|
if value_obitype == OBI_VOID :
|
||||||
value_obitype = OBI_INT
|
|
||||||
elif value_type == float :
|
|
||||||
value_obitype = OBI_FLOAT
|
|
||||||
elif value_type == bool :
|
|
||||||
value_obitype = OBI_BOOL
|
|
||||||
elif value_type == str or value_type == bytes :
|
|
||||||
if value_type == str :
|
|
||||||
value_b = str2bytes(value)
|
|
||||||
else :
|
|
||||||
value_b = value
|
|
||||||
if is_a_DNA_seq(value_b) :
|
|
||||||
value_obitype = OBI_SEQ
|
|
||||||
elif len(value) == 1 :
|
|
||||||
value_obitype = OBI_CHAR
|
|
||||||
elif (len(value) > 1) :
|
|
||||||
value_obitype = OBI_STR
|
|
||||||
else :
|
|
||||||
raise CantGuessTypeException(value)
|
raise CantGuessTypeException(value)
|
||||||
#raise RollbackException("Could not guess the type of a value to create a new column", self._view)
|
#raise RollbackException("Could not guess the type of a value to create a new column", self._view)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user