Commit 8a9ba8b0 by Celine Mercier

Cython: Added Column line methods to get a Column line as a str or

bytes, and elements (keys, values) with None values are not returned
parent 135d3b6e
......@@ -43,7 +43,11 @@ cdef class Column_line:
cdef Column _column
cdef index_t _index
cpdef list keys(self)
cpdef list items(self)
cpdef dict dict(self)
cpdef bytes bytes(self)
cpdef update(self, object data)
......@@ -543,15 +543,51 @@ cdef class Column_line :
def __iter__(self) :
cdef list elements_names
cdef bytes element_name
elements_names = self._column._elements_names
for element_name in elements_names :
for element_name in self._column.get_line(self._index) :
yield element_name
def keys(self): # TODO Discuss if keys with None values should be returned too
return self._column._elements_names
cpdef list keys(self):
# TODO just returning all element names of the column would be faster but
# potentially lots of keys associated with None values on that given line.
# get_line() methods don't return None values
return [element_name for element_name in self._column.get_line(self._index)]
cpdef list items(self):
return [(k, self[k]) for k in self.keys()]
cpdef dict dict(self):
cdef dict d
d = {}
for k,v in self.items():
d[k] = v
return d
def __str__(self):
cdef dict d
cdef str s
d = {}
for k,v in self.items():
if type(v) == bytes:
value = bytes2str(v)
value = v
d[bytes2str(k)] = value
s = str(d)
return s
cpdef bytes bytes(self):
cdef str s
cdef bytes b
s = self.__str__()
b = str2bytes(s)
return b
# column property getter
def column(self):
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment