Turi Create  4.0
turi::csv_writer Class Reference

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

Public Types

enum  csv_quote_level { csv_quote_level::QUOTE_MINIMAL , csv_quote_level::QUOTE_NONNUMERIC, csv_quote_level::QUOTE_NONE }
 

Public Member Functions

void write_verbatim (std::ostream &out, const std::vector< std::string > &row)
 
void write (std::ostream &out, const std::vector< flexible_type > &row)
 
void csv_print (std::ostream &out, const flexible_type &val, bool allow_empty_output=true)
 

Public Attributes

std::string delimiter = ","
 
char escape_char = '\\'
 
bool use_escape_char = true
 
bool double_quote = true
 
char quote_char = '\"'
 
std::string line_terminator = "\n"
 
bool header = true
 
csv_quote_level quote_level = csv_quote_level::QUOTE_NONNUMERIC
 
std::string na_value = ""
 

Detailed Description

CSV Writer

Definition at line 24 of file csv_writer.hpp.

Member Enumeration Documentation

◆ csv_quote_level

Enumerator
QUOTE_MINIMAL 

NOT IMPLEMENTED. Equivalent to QUOTE_NONNUMERIC.

QUOTE_NONNUMERIC 

Quotes all fields.

Equivalent to python csv.QUOTE_NONNUMERIC. Numbers are not quoted

QUOTE_NONE 

Equivalent to python csv.QUOTE_NONE. No quoting is performed.

Definition at line 29 of file csv_writer.hpp.

Member Function Documentation

◆ csv_print()

void turi::csv_writer::csv_print ( std::ostream &  out,
const flexible_type val,
bool  allow_empty_output = true 
)

Converts one value to a string.

Parameters
outThe stream to write to
valThe value of emit
allow_empty_outputThis parameter is a little tricky to interpret. If this flag is set to true (default), some inputs may result in completely empty outputs. (For instance empty string, or missing value where na_value is the empty string). This can cause issues in some situations. For instance, in a csv file with only a single columns, some parsers may skip empty lines. If this flag is set to false, the complete empty output will never be emitted and instead out << quote_char << quote_char will be generated.

◆ write()

void turi::csv_writer::write ( std::ostream &  out,
const std::vector< flexible_type > &  row 
)

Writes an array of values as a row, making the appropriate formatting changes. Not safe to use in parallel.

◆ write_verbatim()

void turi::csv_writer::write_verbatim ( std::ostream &  out,
const std::vector< std::string > &  row 
)

Writes an array of strings as a row, verbatim without escaping / modifications. (only inserting delimiter characters). Not safe to use in parallel.

Member Data Documentation

◆ delimiter

std::string turi::csv_writer::delimiter = ","

The delimiter character to use to separate fields (Default ',')

Definition at line 39 of file csv_writer.hpp.

◆ double_quote

bool turi::csv_writer::double_quote = true

If set to true, pairs of quote characters in a quoted string are interpreted as a single quote (Default false). For instance, if set to true, the 2nd field of the 2nd line is read as "hello "world""

* user, message
* 123, "hello ""world"""
* 

Definition at line 66 of file csv_writer.hpp.

◆ escape_char

char turi::csv_writer::escape_char = '\\'

The character to use to identify the beginning of a C escape sequence (Defualt '\'). i.e. "\n" will be converted to the '
' character, "\\" will be converted to "\", etc. Note that only the single character escapes are converted. unicode (), octal (), hexadecimal () are not interpreted.

Definition at line 48 of file csv_writer.hpp.

◆ header

bool turi::csv_writer::header = true

Whether the header is written

Definition at line 81 of file csv_writer.hpp.

◆ line_terminator

std::string turi::csv_writer::line_terminator = "\n"

new line terminator. Defaults to "\n"

Definition at line 76 of file csv_writer.hpp.

◆ na_value

std::string turi::csv_writer::na_value = ""

String to emit for missing values

Definition at line 91 of file csv_writer.hpp.

◆ quote_char

char turi::csv_writer::quote_char = '\"'

The quote character to use (Default '"')

Definition at line 71 of file csv_writer.hpp.

◆ quote_level

csv_quote_level turi::csv_writer::quote_level = csv_quote_level::QUOTE_NONNUMERIC

The quoting level. Defaults to quoting everything except for numbers

Definition at line 86 of file csv_writer.hpp.

◆ use_escape_char

bool turi::csv_writer::use_escape_char = true

If true, escape characters will not be used at all. Note that enabling this may result in non-parseable CSVs.

Definition at line 54 of file csv_writer.hpp.


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