![]() |
Inviwo 0.9.12-pre
Inviwo documentation
|
A reader for comma separated value (CSV) files with customizable delimiters and filters. The default delimiter is ',' and headers are included. Floating point values are stored as float32 unless double precision is enabled. More...
#include <inviwo/dataframe/io/csvreader.h>
Public Types | |
| enum class | EmptyField { Throw , EmptyOrZero , NanOrZero } |
Public Member Functions | |
| virtual CSVReader * | clone () const override |
| CSVReader (const CSVReader &)=default | |
| CSVReader (CSVReader &&) noexcept=default | |
| CSVReader (std::string_view delimiters=defaultDelimiters, bool hasHeader=defaultFirstRowHeader, bool doublePrecision=defaultDoublePrecision) | |
| const std::string & | getDelimiters () const |
| const csvfilters::Filters & | getFilters () const |
| EmptyField | getHandleEmptyFields () const |
| const std::string & | getLocale () const |
| size_t | getNumberOfExamplesRows () const |
| virtual std::any | getOption (std::string_view key) override |
| bool | getStripQuotes () const |
| const std::string & | getUnitRegexp () const |
| bool | hasDoublePrecision () const |
| bool | hasFirstColIndices () const |
| bool | hasFirstRowHeader () const |
| bool | hasUnitsInHeaders () const |
| CSVReader & | operator= (const CSVReader &)=default |
| CSVReader & | operator= (CSVReader &&) noexcept=default |
| virtual std::shared_ptr< DataFrame > | readData (const std::filesystem::path &fileName) override |
| std::shared_ptr< DataFrame > | readData (std::istream &stream) const |
| CSVReader & | setDelimiters (const std::string &delim) |
| CSVReader & | setEnableDoublePrecision (bool useDoublePrecision) |
| CSVReader & | setFilters (const csvfilters::Filters &filters) |
| CSVReader & | setFirstColIndices (bool hasIndices) |
| CSVReader & | setFirstRowHeader (bool hasHeader) |
| CSVReader & | setHandleEmptyFields (EmptyField emptyField) |
| CSVReader & | setLocale (std::string_view loc) |
| CSVReader & | setNumberOfExampleRows (size_t rows) |
| virtual bool | setOption (std::string_view key, std::any value) override |
| CSVReader & | setStripQuotes (bool stripQuotes) |
| CSVReader & | setUnitRegexp (std::string_view regexp) |
| CSVReader & | setUnitsInHeaders (bool unitInHeaders) |
| Public Member Functions inherited from inviwo::DataReaderType< DataFrame > | |
| DataReaderType & | operator= (const DataReaderType &that)=default |
| Public Member Functions inherited from inviwo::DataReader | |
| void | addExtension (FileExtension ext) |
| DataReader (const DataReader &rhs)=default | |
| DataReader (DataReader &&rhs) noexcept=default | |
| const std::vector< FileExtension > & | getExtensions () const |
| DataReader & | operator= (const DataReader &that)=default |
| DataReader & | operator= (DataReader &&that) noexcept=default |
| template<typename T> | |
| bool | readsType () const |
Static Public Attributes | |
| static constexpr std::string_view | defaultDelimiters = "," |
| static constexpr bool | defaultDoublePrecision = false |
| static constexpr EmptyField | defaultEmptyField = EmptyField::NanOrZero |
| static constexpr bool | defaultFirstColIndices = false |
| static constexpr bool | defaultFirstRowHeader = true |
| static constexpr std::string_view | defaultLocale = "C" |
| static constexpr size_t | defaultNumberOfExampleRows = 50 |
| static constexpr bool | defaultStripQuotes = true |
| static constexpr bool | defaultUnitInHeaders = true |
| static constexpr std::string_view | defaultUnitRegexp = R"((.*)\[(.*)\])" |
Additional Inherited Members | |
| Protected Member Functions inherited from inviwo::DataReaderType< DataFrame > | |
| virtual bool | canRead (const std::type_index &index) const override |
| Static Protected Member Functions inherited from inviwo::DataReader | |
| static void | checkExists (const std::filesystem::path &path) |
| static std::filesystem::path | downloadAndCacheIfUrl (const std::filesystem::path &url) |
| static std::ifstream | open (const std::filesystem::path &path, std::ios_base::openmode mode=std::ios_base::in) |
| static std::ifstream | openAndCacheIfUrl (const std::filesystem::path &path, std::ios_base::openmode mode=std::ios_base::in) |
| static std::string | readFileContents (const std::filesystem::path &path) |
| Protected Attributes inherited from inviwo::DataReader | |
| std::vector< FileExtension > | extensions_ |
A reader for comma separated value (CSV) files with customizable delimiters and filters. The default delimiter is ',' and headers are included. Floating point values are stored as float32 unless double precision is enabled.
|
strong |
How to handle missing / empty data
| Enumerator | |
|---|---|
| Throw | Throw a DataReaderException. |
| EmptyOrZero | "" for categorical and 0 for numerical values |
| NanOrZero | "" for categorical, NaN for floating point, and 0 for integer values |
|
overridevirtual |
Implements inviwo::DataReaderType< DataFrame >.
|
overridevirtual |
Get any of the settings supported by the reader, supported keys:
Reimplemented from inviwo::DataReader.
|
overridevirtual |
read a CSV file from a file
| fileName | name of the input CSV file |
| FileException | if the file cannot be accessed |
| DataReaderException | if the file contains no data, the first row should hold column headers, but they cannot be found, or if there are unmatched quotes at the end of the file |
Implements inviwo::DataReaderType< DataFrame >.
| std::shared_ptr< DataFrame > inviwo::CSVReader::readData | ( | std::istream & | stream | ) | const |
read a CSV file from a input stream, e.g. a std::ifstream. In case file streams are used, the file must have be opened prior calling this function.
| stream | input stream with the CSV data |
| DataReaderException | if the given stream is in a bad state, the stream contains no data, the first row should hold column headers, but they cannot be found, or if there are unmatched quotes at the end of the stream |
| CSVReader & inviwo::CSVReader::setDelimiters | ( | const std::string & | delim | ) |
| CSVReader & inviwo::CSVReader::setEnableDoublePrecision | ( | bool | useDoublePrecision | ) |
Sets the precision for columns containing floating point values. If useDoublePrecision is true, values are stored as double (64 bits), otherwise float (32 bits) is used.
| CSVReader & inviwo::CSVReader::setFilters | ( | const csvfilters::Filters & | filters | ) |
Sets row and column filters.
| CSVReader & inviwo::CSVReader::setFirstColIndices | ( | bool | hasIndices | ) |
| CSVReader & inviwo::CSVReader::setFirstRowHeader | ( | bool | hasHeader | ) |
| CSVReader & inviwo::CSVReader::setHandleEmptyFields | ( | EmptyField | emptyField | ) |
| CSVReader & inviwo::CSVReader::setLocale | ( | std::string_view | loc | ) |
| CSVReader & inviwo::CSVReader::setNumberOfExampleRows | ( | size_t | rows | ) |
|
overridevirtual |
Set any of the settings supported by the reader, supported keys:
Reimplemented from inviwo::DataReader.
| CSVReader & inviwo::CSVReader::setStripQuotes | ( | bool | stripQuotes | ) |
| CSVReader & inviwo::CSVReader::setUnitRegexp | ( | std::string_view | regexp | ) |
| CSVReader & inviwo::CSVReader::setUnitsInHeaders | ( | bool | unitInHeaders | ) |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |