Now handling dictionaries with one key

This commit is contained in:
Celine Mercier
2021-03-10 16:50:30 +13:00
parent fbf0f7dfb6
commit ad1fd3c341
25 changed files with 115 additions and 64 deletions

View File

@ -115,7 +115,7 @@ def run(config):
v.close()
for coln in dict_cols:
Column.new_column(o_view, coln, dict_cols[coln]['obitype'],
nb_elements_per_line=dict_cols[coln]['nbelts'], elements_names=list(dict_cols[coln]['eltnames']))
nb_elements_per_line=dict_cols[coln]['nbelts'], elements_names=list(dict_cols[coln]['eltnames']), dict_column=True)
# Initialize the progress bar
if not config['obi']['noprogressbar']:

View File

@ -257,7 +257,8 @@ def run(config):
for tag in dict_dict:
dcols[tag] = (Column.new_column(view, tag, dict_dict[tag][1], \
nb_elements_per_line=len(dict_dict[tag][0]), \
elements_names=list(dict_dict[tag][0])), \
elements_names=list(dict_dict[tag][0]), \
dict_column=True), \
dict_dict[tag][1])
@ -328,10 +329,13 @@ def run(config):
value_type = type(value)
nb_elts = 1
value_obitype = OBI_VOID
dict_col = False
if value_type == dict or value_type == list :
nb_elts = len(value)
elt_names = list(value)
if value_type == dict :
dict_col = True
else :
nb_elts = 1
elt_names = None
@ -339,11 +343,9 @@ def run(config):
value_obitype = get_obitype(value)
if value_obitype != OBI_VOID :
dcols[tag] = (Column.new_column(view, tag, value_obitype, nb_elements_per_line=nb_elts, elements_names=elt_names), value_obitype)
dcols[tag] = (Column.new_column(view, tag, value_obitype, nb_elements_per_line=nb_elts, elements_names=elt_names, dict_column=dict_col), value_obitype)
# Fill value
if value_type == dict and nb_elts == 1: # special case that makes the OBI3 create a 1 elt/line column which won't read a dict value
value = value[list(value.keys())[0]] # The solution is to transform the value in a simple atomic one acceptable by the column
dcols[tag][0][i] = value
# TODO else log error?

View File

@ -302,12 +302,16 @@ def create_random_column(config, infos) :
alias = random.choice([b'', random_unique_name(infos)])
tuples = random.choice([True, False])
if not tuples :
dict_column = random.choice([True, False])
nb_elements_per_line=random.randint(1, config['test']['maxelts'])
if nb_elements_per_line > 1:
dict_column = True
elements_names = []
for i in range(nb_elements_per_line) :
elements_names.append(random_unique_element_name(config, infos))
elements_names = random.choice([None, elements_names])
else :
dict_column = False
nb_elements_per_line = 1
elements_names = None
name = random_unique_name(infos)
@ -318,6 +322,7 @@ def create_random_column(config, infos) :
data_type,
nb_elements_per_line=nb_elements_per_line,
elements_names=elements_names,
dict_column=dict_column,
tuples=tuples,
comments=random_comments(config),
alias=alias

View File

@ -378,6 +378,7 @@ cdef uniq_sequences(View_NUC_SEQS view, View_NUC_SEQS o_view, ProgressBar pb, di
OBI_INT,
nb_elements_per_line=merged_infos[merged_col_name]['nb_elts'],
elements_names=list(merged_infos[merged_col_name]['elt_names']),
dict_column=True,
comments=i_col.comments,
alias=merged_col_name
)
@ -400,6 +401,7 @@ cdef uniq_sequences(View_NUC_SEQS view, View_NUC_SEQS o_view, ProgressBar pb, di
OBI_INT,
nb_elements_per_line=len(view),
elements_names=[id for id in i_id_col],
dict_column=True,
alias=TAXID_DIST_COLUMN
)

View File

@ -31,6 +31,7 @@ cdef extern from "obidmscolumn.h" nogil:
const_char_p elements_names
OBIType_t returned_data_type
OBIType_t stored_data_type
bint dict_column
bint tuples
bint to_eval
time_t creation_date

View File

@ -95,6 +95,7 @@ cdef extern from "obiview.h" nogil:
index_t nb_elements_per_line,
char* elements_names,
bint elt_names_formatted,
bint dict_column,
bint tuples,
bint to_eval,
const_char_p indexer_name,

View File

@ -90,6 +90,7 @@ cdef class Column(OBIWrapper) :
obitype_t data_type,
index_t nb_elements_per_line=1,
list elements_names=None,
bint dict_column=False,
bint tuples=False,
bint to_eval=False,
object associated_column_name=b"",
@ -152,6 +153,7 @@ cdef class Column(OBIWrapper) :
nb_elements_per_line = nb_elements_per_line,
elements_names = elements_names_p,
elt_names_formatted = False,
dict_column = dict_column,
tuples = tuples,
to_eval = to_eval,
indexer_name = NULL,
@ -200,7 +202,7 @@ cdef class Column(OBIWrapper) :
column_p = column_pp[0]
column_type = column_p.header.returned_data_type
column_class = Column.get_column_class(column_type, (column_p.header.nb_elements_per_line > 1), column_p.header.tuples)
column_class = Column.get_column_class(column_type, (column_p.header.nb_elements_per_line > 1 or column_p.header.dict_column == True), column_p.header.tuples)
column = OBIWrapper.new_wrapper(column_class, column_pp)
column._view = view
@ -236,6 +238,7 @@ cdef class Column(OBIWrapper) :
nb_elements_per_line = -1,
elements_names = NULL,
elt_names_formatted = False,
dict_column = False,
tuples = False,
to_eval = False,
indexer_name = NULL,
@ -374,6 +377,13 @@ cdef class Column(OBIWrapper) :
raise OBIDeactivatedInstanceError()
return self.pointer().header.nb_elements_per_line
# dict_column property getter
@property
def dict_column(self):
if not self.active() :
raise OBIDeactivatedInstanceError()
return self.pointer().header.dict_column
# data_type property getter
@property
def data_type(self):

View File

@ -38,11 +38,13 @@ cdef class Column_bool(Column):
object column_name,
index_t nb_elements_per_line=1,
object elements_names=None,
bint dict_column=False,
bint tuples=False,
object comments={}):
return Column.new_column(view, column_name, OBI_BOOL,
nb_elements_per_line=nb_elements_per_line,
elements_names=elements_names,
elements_names=elements_names,
dict_column=dict_column,
tuples=tuples,
comments=comments)

View File

@ -36,12 +36,14 @@ cdef class Column_char(Column):
object column_name,
index_t nb_elements_per_line=1,
object elements_names=None,
bint dict_column=False,
bint tuples=False,
object comments={}):
return Column.new_column(view, column_name, OBI_CHAR,
nb_elements_per_line=nb_elements_per_line,
elements_names=elements_names,
dict_column=dict_column,
tuples=tuples,
comments=comments)

View File

@ -36,12 +36,14 @@ cdef class Column_float(Column):
object column_name,
index_t nb_elements_per_line=1,
object elements_names=None,
bint dict_column=False,
bint tuples=False,
object comments={}):
return Column.new_column(view, column_name, OBI_FLOAT,
nb_elements_per_line=nb_elements_per_line,
elements_names=elements_names,
dict_column=dict_column,
tuples=tuples,
comments=comments)

View File

@ -38,12 +38,14 @@ cdef class Column_int(Column):
object column_name,
index_t nb_elements_per_line=1,
object elements_names=None,
bint dict_column=False,
bint tuples=False,
object comments={}):
return Column.new_column(view, column_name, OBI_INT,
nb_elements_per_line=nb_elements_per_line,
elements_names=elements_names,
dict_column=dict_column,
tuples=tuples,
comments=comments)

View File

@ -38,6 +38,7 @@ cdef class Column_qual(Column_idx):
object column_name,
index_t nb_elements_per_line=1,
object elements_names=None,
bint dict_column=False,
object associated_column_name=b"",
int associated_column_version=-1,
object comments={}):
@ -45,6 +46,7 @@ cdef class Column_qual(Column_idx):
return Column.new_column(view, column_name, OBI_QUAL,
nb_elements_per_line=nb_elements_per_line,
elements_names=elements_names,
dict_column=dict_column,
tuples=False,
associated_column_name=associated_column_name,
associated_column_version=associated_column_name,

View File

@ -39,12 +39,14 @@ cdef class Column_seq(Column_idx):
object column_name,
index_t nb_elements_per_line=1,
object elements_names=None,
bint dict_column=False,
bint tuples=False,
object comments={}):
return Column.new_column(view, column_name, OBI_SEQ,
nb_elements_per_line=nb_elements_per_line,
elements_names=elements_names,
dict_column=dict_column,
tuples=tuples,
comments=comments)

View File

@ -38,12 +38,14 @@ cdef class Column_str(Column_idx):
object column_name,
index_t nb_elements_per_line=1,
object elements_names=None,
bint dict_column=False,
bint tuples=False,
object comments={}):
return Column.new_column(view, column_name, OBI_STR,
nb_elements_per_line=nb_elements_per_line,
elements_names=elements_names,
dict_column=dict_column,
tuples=tuples,
comments=comments)

View File

@ -343,7 +343,7 @@ cdef class View(OBIWrapper) :
new_column = Column.new_column(self, old_column.pointer().header.name, new_data_type,
nb_elements_per_line=new_nb_elements_per_line, elements_names=new_elements_names,
comments=old_column.comments, alias=column_name_b+tobytes('___new___'))
dict_column=(new_nb_elements_per_line>1), comments=old_column.comments, alias=column_name_b+tobytes('___new___'))
switch_to_dict = old_column.nb_elements_per_line == 1 and new_nb_elements_per_line > 1
ori_key = old_column._elements_names[0]
@ -404,6 +404,7 @@ cdef class View(OBIWrapper) :
col.data_type_int,
nb_elements_per_line = col.nb_elements_per_line,
elements_names = col._elements_names,
dict_column = col.dict_column,
tuples = col.tuples,
to_eval = col.to_eval,
comments = col.comments,