spine_io.importers.csv_reader

Contains CSVConnector class and a help function.

author:
  1. Vennström (VTT)
date:

1.6.2019

Module Contents

spine_io.importers.csv_reader.select_csv_file(parent=None)[source]

Launches QFileDialog with no filter

class spine_io.importers.csv_reader.CSVConnector[source]

Bases: spine_io.io_api.SourceConnection

Template class to read data from another QThread

DISPLAY_NAME = Text/CSV[source]
OPTIONS[source]
SELECT_SOURCE_UI[source]
connect_to_source(self, source)[source]

saves filepath

Parameters:{str} -- filepath (source) –
disconnect(self)[source]

Disconnect from connected source.

get_tables(self)[source]

Method that should return a list of table names, list(str)

Raises:NotImplementedError – [description]
static parse_options(options)[source]

Parses options dict to dialect and quotechar options for csv.reader

Parameters:{dict} -- dict with options (options) – “delimiter”: file delimiter “quotechar”: file quotechar “has_header”: if first row should be treated as a header “skip”: how many rows should be skipped
Returns:
tuple(dict, bool, integer) – tuple dialect for csv.reader,
quotechar for csv.reader and number of rows to skip
file_iterator(self, options, max_rows)[source]

creates an iterator that reads max_rows number of rows from text file

Parameters:
  • {dict} -- dict with options (options) –
  • {integer} -- max number of rows to read, if -1 then read all rows (max_rows) –
Returns:

iterator – iterator of csv file

get_data_iterator(self, table, options, max_rows=-1)[source]

Creates a iterator for the file in self.filename

Parameters:
  • {string} -- ignored, used in abstract IOWorker class (table) –
  • {dict} -- dict with options (options) –
Keyword Arguments:
 

{int} -- how many rows of data to read, if -1 read all rows (default (max_rows) – {-1})

Returns:

[type] – [description]