From 2139bfc74885823a333cdc4fd4109f745d24df90 Mon Sep 17 00:00:00 2001 From: Eric Coissac Date: Mon, 2 Jan 2017 13:05:22 +0100 Subject: [PATCH] refactoring... --- python/obitools3/dms/column/column.pxd | 8 ++--- python/obitools3/dms/column/column.pyx | 45 ++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 4 deletions(-) diff --git a/python/obitools3/dms/column/column.pxd b/python/obitools3/dms/column/column.pxd index cbdd86b..b3f1751 100644 --- a/python/obitools3/dms/column/column.pxd +++ b/python/obitools3/dms/column/column.pxd @@ -1,10 +1,10 @@ #cython: language_level=3 -from .capi.obitypes cimport index_t, \ - obitype_t -from .capi.obidmscolumn cimport OBIDMS_column_p +from ..capi.obitypes cimport index_t, \ + obitype_t +from ..capi.obidmscolumn cimport OBIDMS_column_p -from .view cimport View +from ..view cimport View cdef class Column: diff --git a/python/obitools3/dms/column/column.pyx b/python/obitools3/dms/column/column.pyx index 77205ff..dfb57c2 100644 --- a/python/obitools3/dms/column/column.pyx +++ b/python/obitools3/dms/column/column.pyx @@ -45,6 +45,51 @@ cdef class Column : self._pointer = NULL self._view = view + @staticmethod + def new(OBIView view, + object column_name, + index_t nb_elements_per_line=1, + object elements_names=None, + object comments=b""): + + cdef bytes column_name_b = tobytes(column_name) + cdef bytes comments_b + cdef bytes elements_names_b + cdef char* elements_names_p + cdef OBIDMS_column new_column + + if comments is not None: + comments_b = tobytes(comments) + else: + comments_b = b'' + + if elements_names is not None: + elements_names_b = b''.join([tobytes(x) for x in elements_names]) + elements_names_p = elements_names_b + else: + elements_names_p = NULL + + if (obi_view_add_column(view = view._pointer, + column_name = column_name_b, + version_number = -1, + alias = NULL, + data_type = self.pointer.header.returned_data_type, + nb_lines = len(view), + nb_elements_per_line = nb_elements_per_line, + elements_names = elements_names_p, + indexer_name = NULL, + associated_column_name = NULL, + associated_column_version = -1, + comments = comments_b, + create = True)<0): + raise RuntimeError("Cannot create column %s in view %s" % (bytes2str(column_name), + bytes2str(view.name))) + + view.__init_columns__() + new_column = self._columns[column_name] + + return new_column + def __len__(self): ''' implements the len() function for the Column class