Delimited file

This class uses a local delimited file (e.g. CSV, TSV) as a database for parameter testing. Delimited files represent a table where the row is a line in the file, and each column is seporated by a delimiter. The delimiter is often a comma (comma-seporated file) or a tab (tab-seporated file). A CSV file might look like this:

id,start-time,end-time,status,a,b,c
t1,2019-09-06 17:23,2019-09-06 17:36,finished,2,4,6
t2,,,,10,10,
t3,,,,10,-10,

and represent a table that looks like this:

id start-time end-time status a b c
t1 2019-09-06 17:23 2019-09-06 17:36 finished 2 4 6
t2       10 10  
t3       10 -10  

Because these files are stored on the users computer, there is no way for a team to work on the parameter set distributively (without manually dividing the parameter sets up).

Delimited files can have a header which gives the columns names. The header is the first row of the table. Headers must be included with DAPT’s Delimited_file class.

DAPT provides a method named sample_db() which creates the sample CSV above. You can create this file by running that method and then use the Delimited_file class with it.

>>> db = dapt.tools.sample_db(file_name='sample_db.csv', delimiter=',')
>>> db.fields()
['id', 'start-time', 'end-time', 'status', 'a', 'b', 'c']

Config

Delimited file can accept a Config class. The values listed in the table below are the same attributes used to instantiate the class. These values should be placed inside a JSON object named delimited-file.

Fields Description
path (str) The path, from the execution directory, to the delimited file.
delimiter (str) How the columns of the file are seporated.

The default configuration looks like this:

Sample JSON configuration for Delimited_file
{
    "delimited-file" : {
        "path" : "parameters.csv",
        "delimiter" : ","
    }
}
class dapt.db.delimited_file.Delimited_file(*args, **kwargs)

Bases: dapt.db.base.Database

An interface for accessing and setting paramater set data.

Keyword Arguments:
 
  • path (str) – path to delimited file file
  • delimiter (str) – the delimiter of the CSV. , by default.
  • config (Config object) – an Config instance
connect()

The method used to connect to the database and log the user in. Some databases won’t need to use the connect method, but it should be called regardless to prevent problems.

Returns:True if the database connected successfully and False otherwise.
connected()

Check to see if the API is connected to the server and working.

Returns:True if the API is connected to the server and False otherwise.
fields()

Get the fields(attributes) of the parameter set

Returns:Array of strings with each element being a field (order is preserved if possible) or None if the file is empty.
get_row_index(column_key, row_value)

Get the row index given the column to look through and row value to match to.

Parameters:
  • column_key (str) – the column to use.
  • row_value (str) – the row value to match with in the file and determin the row index.
Returns:

The index or -1 if it could not be determined

get_table()

Get the table from the database.

Returns:An array with each element being a dictionary of the key-value pairs for the row in the database.
update_cell(row_index, field, value)

Update the cell specified by the row_id and field.

Parameters:
  • row_id (int) – the row id to replace
  • field (str) – the field of the value to replace
  • value (object) – the value to insert into the cell
Returns:

A boolean that is True if successfully inserted and False otherwise.

update_row(row_index, values)

Update the row at the row-index with the values given.

Parameters:
  • row_index (int) – the index of the row to replace
  • values (Dict) – the key-value pairs that should be inserted
Returns:

A boolean that is True if successfully inserted and False otherwise.