Turi Create  4.0
turi::dataframe_row_iterator Class Reference

#include <core/storage/sframe_data/dataframe.hpp>

Public Member Functions

void swap_column_order (size_t a, size_t b)
 
dataframe_row_iteratoroperator++ ()
 pre-increments to the next entry of the dataframe row-wise
 
dataframe_row_iteratoroperator++ (int)
 post-increments to the next entry of the dataframe row-wise
 
size_t row () const
 Returns the index of the current row.
 
size_t column () const
 Returns the index of the current column.
 
size_t column_size () const
 Returns the number of columns.
 
size_t row_size () const
 Returns the number of rows.
 
const std::string & column_name () const
 Returns the name of the current column.
 
const std::string & column_name (size_t idx) const
 Returns the name of an arbitrary column.
 
const std::vector< std::string > & column_names () const
 Returns the list of all column names.
 
flex_type_enum column_type () const
 Returns the type of the current column.
 
flex_type_enum column_type (size_t idx) const
 Returns the type of an arbitrary column.
 
const std::vector< flex_type_enum > & column_types () const
 Returns the list of all column types.
 
void skip_rows (size_t num_rows_to_skip)
 
bool operator== (const dataframe_row_iterator &other)
 Returns true if both iterators are equal.
 
bool operator!= (const dataframe_row_iterator &other)
 Returns true if both iterators are not equal.
 
const flexible_typeoperator* ()
 Dereferences the iterator, returning a reference to the underlying flexible_type.
 
const flexible_typeoperator* () const
 Dereferences the iterator, returning a reference to the underlying flexible_type.
 
const flexible_typeoperator-> ()
 Dereferences the iterator, returning a reference to the underlying flexible_type.
 
const flexible_typeoperator-> () const
 Dereferences the iterator, returning a reference to the underlying flexible_type.
 

Static Public Member Functions

static dataframe_row_iterator begin (const dataframe_t &dt)
 Creates a begin iterator to the dataframe.
 
static dataframe_row_iterator end (const dataframe_t &dt)
 Creates an end iterator to the dataframe.
 

Detailed Description

The dataframe is a column-wise representation. This provides iteration over the dataframe in a row-wise representation. Incrementing the iterator advances the iterator element by element by across rows.

Usage:

// Performs a row-wise iteration over the entries of the dataframe
dataframe_row_iterator iter = dataframe_row_iterator::begin(df);
dataframe_row_iterator end = dataframe_row_iterator::end(df);
while (iter != end) {
// do stuff with (*iter). It is a flexible_type
++iter;
}
// Alternatively:
dataframe_row_iterator iter = dataframe_row_iterator::begin(df);
for (size_t row = 0; row < iter.row_size(); ++row) {
for (size_t col = 0; col < iter.col_size(); ++col) {
// do stuff with (*iter). It is a flexible_type
// pointing to the cell in column 'col' and row 'row'
++iter;
}
}

Definition at line 205 of file dataframe.hpp.

Member Function Documentation

◆ skip_rows()

void turi::dataframe_row_iterator::skip_rows ( size_t  num_rows_to_skip)

Advances the iterator by this number of rows. Current column does not change. If the number of rows to skip causes the iterator to go past the end of the dataframe, the resultant iterator is equivalent to the end iterator of the dataframe.

◆ swap_column_order()

void turi::dataframe_row_iterator::swap_column_order ( size_t  a,
size_t  b 
)
inline

Changes the column iterator ordering by swapping the indices of columns 'a' and columns 'b'. Should only be done on begin and end iterators. Iterators in the midst of iterating are not safe to be swapped.

Definition at line 248 of file dataframe.hpp.


The documentation for this class was generated from the following file: