Added alias property to OBIDMS_column cython class
This commit is contained in:
@ -149,7 +149,7 @@ def test_col_alias(config, infos):
|
|||||||
if col_name in SPECIAL_COLUMNS :
|
if col_name in SPECIAL_COLUMNS :
|
||||||
print_test(config, "-")
|
print_test(config, "-")
|
||||||
return
|
return
|
||||||
infos['view'].change_column_alias(col_name, random_unique_name(infos))
|
infos['view'][col_name].alias = random_unique_name(infos)
|
||||||
print_test(config, ">>> Changing column alias test OK")
|
print_test(config, ">>> Changing column alias test OK")
|
||||||
|
|
||||||
|
|
||||||
|
@ -9,12 +9,13 @@ from ._obitaxo cimport OBI_Taxonomy
|
|||||||
|
|
||||||
cdef class OBIDMS_column:
|
cdef class OBIDMS_column:
|
||||||
|
|
||||||
|
cdef str column_name
|
||||||
|
cdef str column_alias
|
||||||
cdef OBIDMS_column_p* pointer
|
cdef OBIDMS_column_p* pointer
|
||||||
cdef OBIDMS dms
|
cdef OBIDMS dms
|
||||||
cdef OBIView view
|
cdef OBIView view
|
||||||
cdef str data_type
|
cdef str data_type
|
||||||
cdef str dms_name
|
cdef str dms_name
|
||||||
cdef str column_name
|
|
||||||
cdef index_t nb_elements_per_line
|
cdef index_t nb_elements_per_line
|
||||||
cdef list elements_names
|
cdef list elements_names
|
||||||
|
|
||||||
|
@ -84,12 +84,12 @@ from cpython.pycapsule cimport PyCapsule_New, PyCapsule_GetPointer
|
|||||||
cdef class OBIDMS_column :
|
cdef class OBIDMS_column :
|
||||||
|
|
||||||
# Should only be initialized through a subclass
|
# Should only be initialized through a subclass
|
||||||
def __init__(self, OBIView view, str column_name):
|
def __init__(self, OBIView view, str column_alias):
|
||||||
|
|
||||||
cdef OBIDMS_column_p column_p
|
cdef OBIDMS_column_p column_p
|
||||||
cdef OBIDMS_column_p* column_pp
|
cdef OBIDMS_column_p* column_pp
|
||||||
|
|
||||||
column_pp = obi_view_get_pointer_on_column_in_view(view.pointer, str2bytes(column_name))
|
column_pp = obi_view_get_pointer_on_column_in_view(view.pointer, str2bytes(column_alias))
|
||||||
column_p = column_pp[0] # TODO ugly cython dereferencing but can't find better
|
column_p = column_pp[0] # TODO ugly cython dereferencing but can't find better
|
||||||
|
|
||||||
# Fill structure
|
# Fill structure
|
||||||
@ -98,6 +98,7 @@ cdef class OBIDMS_column :
|
|||||||
self.view = view
|
self.view = view
|
||||||
self.data_type = bytes2str(name_data_type((column_p.header).returned_data_type))
|
self.data_type = bytes2str(name_data_type((column_p.header).returned_data_type))
|
||||||
self.column_name = bytes2str((column_p.header).name)
|
self.column_name = bytes2str((column_p.header).name)
|
||||||
|
self.column_alias = column_alias
|
||||||
self.nb_elements_per_line = (column_p.header).nb_elements_per_line
|
self.nb_elements_per_line = (column_p.header).nb_elements_per_line
|
||||||
self.elements_names = (bytes2str((column_p.header).elements_names)).split(';')
|
self.elements_names = (bytes2str((column_p.header).elements_names)).split(';')
|
||||||
|
|
||||||
@ -159,6 +160,13 @@ cdef class OBIDMS_column :
|
|||||||
if obi_close_column((self.pointer)[0]) < 0 :
|
if obi_close_column((self.pointer)[0]) < 0 :
|
||||||
raise Exception("Problem closing a column")
|
raise Exception("Problem closing a column")
|
||||||
|
|
||||||
|
# Column alias property getter and setter
|
||||||
|
@property
|
||||||
|
def alias(self):
|
||||||
|
return self.column_alias
|
||||||
|
@alias.setter
|
||||||
|
def alias(self, new_alias):
|
||||||
|
self.view.change_column_alias(self.column_alias, new_alias)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
cdef object get_subclass_type(OBIDMS_column_p column_p) :
|
cdef object get_subclass_type(OBIDMS_column_p column_p) :
|
||||||
@ -392,10 +400,13 @@ cdef class OBIView :
|
|||||||
|
|
||||||
|
|
||||||
cpdef change_column_alias(self, str current_alias, str new_alias):
|
cpdef change_column_alias(self, str current_alias, str new_alias):
|
||||||
|
cdef OBIDMS_column column
|
||||||
if (obi_view_create_column_alias(self.pointer, str2bytes(current_alias), str2bytes(new_alias)) < 0) :
|
if (obi_view_create_column_alias(self.pointer, str2bytes(current_alias), str2bytes(new_alias)) < 0) :
|
||||||
raise Exception("Problem changing a column alias")
|
raise Exception("Problem changing a column alias")
|
||||||
# Update the dictionaries of column column objects
|
# Update the dictionaries of column objects
|
||||||
self.columns[new_alias] = self.columns[current_alias]
|
self.columns[new_alias] = self.columns[current_alias]
|
||||||
|
column = self.columns[new_alias]
|
||||||
|
column.column_alias = new_alias
|
||||||
(self.columns).pop(current_alias)
|
(self.columns).pop(current_alias)
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user