pcsv module

This module can be used to handle comma-separated values (CSV) files and do lightweight processing of their data with support for row and column filtering. In addition to basic read, write and data replacement, files can be concatenated, merged, and sorted

Examples

Read/write

# pcsv_example_1.py
import putil.misc, putil.pcsv

def main():
    with putil.misc.TmpFile() as fname:
        ref_data = [
            ['Item', 'Cost'],
            [1, 9.99],
            [2, 10000],
            [3, 0.10]
        ]
        # Write reference data to a file
        putil.pcsv.write(fname, ref_data, append=False)
        # Read the data back
        obj = putil.pcsv.CsvFile(fname)
    # After the object creation the I/O is done,
    # can safely remove file (exit context manager)
    # Check that data read is correct
    assert obj.header() == ref_data[0]
    assert obj.data() == ref_data[1:]
    # Add a simple row filter, only look at rows that have
    # values 1 and 3 in the "Items" column
    obj.rfilter = {'Item':[1, 3]}
    assert obj.data(filtered=True) == [ref_data[1], ref_data[3]]

if __name__ == '__main__':
    main()

Replace data

# pcsv_example_2.py
import putil.misc, putil.pcsv

def main():
    ctx = putil.misc.TmpFile
    with ctx() as fname1:
        with ctx() as fname2:
            with ctx() as ofname:
                # Create first (input) data file
                input_data = [
                    ['Item', 'Cost'],
                    [1, 9.99],
                    [2, 10000],
                    [3, 0.10]
                ]
                putil.pcsv.write(fname1, input_data, append=False)
                # Create second (replacement) data file
                replacement_data = [
                    ['Staff', 'Rate', 'Days'],
                    ['Joe', 10, 'Sunday'],
                    ['Sue', 20, 'Thursday'],
                    ['Pat', 15, 'Tuesday']
                ]
                putil.pcsv.write(fname2, replacement_data, append=False)
                # Replace "Cost" column of input file with "Rate" column
                # of replacement file for "Items" 2 and 3 with "Staff" data
                # from Joe and Pat. Save resulting data to another file
                putil.pcsv.replace(
                    fname1=fname1,
                    dfilter1=('Cost', {'Item':[1, 3]}),
                    fname2=fname2,
                    dfilter2=('Rate', {'Staff':['Joe', 'Pat']}),
                    ofname=ofname
                )
                # Verify that resulting file is correct
                ref_data = [
                    ['Item', 'Cost'],
                    [1, 10],
                    [2, 10000],
                    [3, 15]
                ]
                obj = putil.pcsv.CsvFile(ofname)
                assert obj.header() == ref_data[0]
                assert obj.data() == ref_data[1:]

if __name__ == '__main__':
    main()

Concatenate two files

# pcsv_example_3.py
import putil.misc, putil.pcsv

def main():
    ctx = putil.misc.TmpFile
    with ctx() as fname1:
        with ctx() as fname2:
            with ctx() as ofname:
                # Create first data file
                data1 = [
                    [1, 9.99],
                    [2, 10000],
                    [3, 0.10]
                ]
                putil.pcsv.write(fname1, data1, append=False)
                # Create second data file
                data2 = [
                    ['Joe', 10, 'Sunday'],
                    ['Sue', 20, 'Thursday'],
                    ['Pat', 15, 'Tuesday']
                ]
                putil.pcsv.write(fname2, data2, append=False)
                # Concatenate file1 and file2. Filter out
                # second column of file2
                putil.pcsv.concatenate(
                    fname1=fname1,
                    fname2=fname2,
                    has_header1=False,
                    has_header2=False,
                    dfilter2=[0, 2],
                    ofname=ofname,
                    ocols=['D1', 'D2']
                )
                # Verify that resulting file is correct
                ref_data = [
                    ['D1', 'D2'],
                    [1, 9.99],
                    [2, 10000],
                    [3, 0.10],
                    ['Joe', 'Sunday'],
                    ['Sue', 'Thursday'],
                    ['Pat', 'Tuesday']
                ]
                obj = putil.pcsv.CsvFile(ofname)
                assert obj.header() == ref_data[0]
                assert obj.data() == ref_data[1:]

if __name__ == '__main__':
    main()

Merge two files

# pcsv_example_4.py
import putil.misc, putil.pcsv

def main():
    ctx = putil.misc.TmpFile
    with ctx() as fname1:
        with ctx() as fname2:
            with ctx() as ofname:
                # Create first data file
                data1 = [
                    [1, 9.99],
                    [2, 10000],
                    [3, 0.10]
                ]
                putil.pcsv.write(fname1, data1, append=False)
                # Create second data file
                data2 = [
                    ['Joe', 10, 'Sunday'],
                    ['Sue', 20, 'Thursday'],
                    ['Pat', 15, 'Tuesday']
                ]
                putil.pcsv.write(fname2, data2, append=False)
                # Merge file1 and file2
                putil.pcsv.merge(
                    fname1=fname1,
                    has_header1=False,
                    fname2=fname2,
                    has_header2=False,
                    ofname=ofname
                )
                # Verify that resulting file is correct
                ref_data = [
                    [1, 9.99, 'Joe', 10, 'Sunday'],
                    [2, 10000, 'Sue', 20, 'Thursday'],
                    [3, 0.10, 'Pat', 15, 'Tuesday'],
                ]
                obj = putil.pcsv.CsvFile(ofname, has_header=False)
                assert obj.header() == list(range(0, 5))
                assert obj.data() == ref_data

if __name__ == '__main__':
    main()

Sort a file

# pcsv_example_5.py
import putil.misc, putil.pcsv

def main():
    ctx = putil.misc.TmpFile
    with ctx() as ifname:
        with ctx() as ofname:
            # Create first data file
            data = [
                ['Ctrl', 'Ref', 'Result'],
                [1, 3, 10],
                [1, 4, 20],
                [2, 4, 30],
                [2, 5, 40],
                [3, 5, 50]
            ]
            putil.pcsv.write(ifname, data, append=False)
            # Sort
            putil.pcsv.dsort(
                fname=ifname,
                order=[{'Ctrl':'D'}, {'Ref':'A'}],
                has_header=True,
                ofname=ofname
            )
            # Verify that resulting file is correct
            ref_data = [
                [3, 5, 50],
                [2, 4, 30],
                [2, 5, 40],
                [1, 3, 10],
                [1, 4, 20]
            ]
            obj = putil.pcsv.CsvFile(ofname, has_header=True)
            assert obj.header() == ['Ctrl', 'Ref', 'Result']
            assert obj.data() == ref_data

if __name__ == '__main__':
    main()

Identifying (filtering) columns

Several class methods and functions in this module allow column and row filtering of the CSV file data. It is necessary to identify columns for both of these operations and how these columns can be identified depends on whether the file has or does not have a header as indicated by the has_header boolean constructor argument:

  • If has_header is True the first line of the file is taken as the header. Columns can be identified by name (a string that has to match a column value in the file header) or by number (an integer representing the column number with column zero being the leftmost column)
  • If has_header is False columns can only be identified by number (an integer representing the column number with column zero being the leftmost column)

For example, if a file myfile.csv has the following data:

Ctrl Ref Result
1 3 10
1 4 20
2 4 30
2 5 40
3 5 50

Then when the file is loaded with putil.pcsv.CsvFile('myfile.csv', has_header=True) the columns can be referred to as 'Ctrl' or 0, 'Ref' or 1, or 'Result' or 2. However if the file is loaded with putil.pcsv.CsvFile('myfile.csv', has_header=False) the columns can be referred only as 0, 1 or 2.

Filtering rows

Several class methods and functions of this module allow row filtering of the CSV file data. The row filter is described in the CsvRowFilter pseudo-type

Swapping or inserting columns

The column filter not only filters columns but also determines the order in which the columns are stored internally in an putil.pcsv.CsvFile object. This means that the column filter can be used to reorder and/or duplicate columns. For example:

# pcsv_example_6.py
import putil.misc, putil.pcsv

def main():
    ctx = putil.misc.TmpFile
    with ctx() as ifname:
        with ctx() as ofname:
            # Create input data file
            data = [
                ['Ctrl', 'Ref', 'Result'],
                [1, 3, 10],
                [1, 4, 20],
                [2, 4, 30],
                [2, 5, 40],
                [3, 5, 50]
            ]
            putil.pcsv.write(ifname, data, append=False)
            # Swap 'Ctrl' and 'Result' columns, duplicate
            # 'Ref' column at the end
            obj = putil.pcsv.CsvFile(
                fname=ifname,
                dfilter=['Result', 'Ref', 'Ctrl', 1],
            )
            assert obj.header(filtered=False) == ['Ctrl', 'Ref', 'Result']
            assert (
                obj.header(filtered=True)
                ==
                ['Result', 'Ref', 'Ctrl', 'Ref']
            )
            obj.write(
                ofname,
                header=['Result', 'Ref', 'Ctrl', 'Ref2'],
                filtered=True,
                append=False
            )
            # Verify that resulting file is correct
            ref_data = [
                [10, 3, 1, 3],
                [20, 4, 1, 4],
                [30, 4, 2, 4],
                [40, 5, 2, 5],
                [50, 5, 3, 5]
            ]
            obj = putil.pcsv.CsvFile(ofname, has_header=True)
            assert obj.header() == ['Result', 'Ref', 'Ctrl', 'Ref2']
            assert obj.data() == ref_data

if __name__ == '__main__':
    main()

Empty columns

When a file has empty columns they are read as None. Conversely any column value that is None is written as an empty column. Empty columns are ones that have either an empty string ('') or literally no information between the column delimiters (,)

For example, if a file myfile2.csv has the following data:

Ctrl Ref Result
1 4 20
2   30
2 5  
  5 50

The corresponding read array is:

[
    ['Ctrl', 'Ref', 'Result'],
    [1, 4, 20],
    [2, None, 30],
    [2, 5, None],
    [None, 5, 50]
]

Functions

putil.pcsv.concatenate(fname1, fname2, dfilter1=None, dfilter2=None, has_header1=True, has_header2=True, frow1=0, frow2=0, ofname=None, ocols=None)

Concatenates two comma-separated values file. Data rows from the second file are appended at the end of the data rows from the first file

Parameters:
  • fname1 (FileNameExists) – Name of the first comma-separated values file, the file whose data appears first in the output file
  • fname2 (FileNameExists) – Name of the second comma-separated values file, the file whose data appears last in the output file
  • dfilter1 (CsvDataFilter or None) – Row and/or column filter for the first file. If None no data filtering is done on the file
  • dfilter2 (CsvDataFilter or None) – Row and/or column filter for the second file. If None no data filtering is done on the file
  • has_header1 (boolean) – Flag that indicates whether the first comma-separated values file has column headers in its first line (True) or not (False)
  • has_header2 (boolean) – Flag that indicates whether the second comma-separated values file has column headers in its first line (True) or not (False)
  • frow1 (NonNegativeInteger) – First comma-separated values file first data row (starting from 1). If 0 the row where data starts is auto-detected as the first row that has a number (integer of float) in at least one of its columns
  • frow2 (NonNegativeInteger) – Second comma-separated values file first data row (starting from 1). If 0 the row where data starts is auto-detected as the first row that has a number (integer of float) in at least one of its columns
  • ofname (FileName or None) – Name of the output comma-separated values file, the file that will contain the data from the first and second files. If None the first file is replaced “in place”
  • ocols (list or None) – Column names of the output comma-separated values file. If None the column names in the first file are used if has_header1 is True or the column names in the second files are used if has_header1 is False and has_header2 is True, otherwise no header is used
Raises:
  • OSError (File [fname] could not be found)
  • RuntimeError (Argument `dfilter1` is not valid)
  • RuntimeError (Argument `dfilter2` is not valid)
  • RuntimeError (Argument `fname1` is not valid)
  • RuntimeError (Argument `fname2` is not valid)
  • RuntimeError (Argument `frow1` is not valid)
  • RuntimeError (Argument `frow2` is not valid)
  • RuntimeError (Argument `ocols` is not valid)
  • RuntimeError (Argument `ofname` is not valid)
  • RuntimeError (Column headers are not unique in file [fname])
  • RuntimeError (File [fname] has no valid data)
  • RuntimeError (File [fname] is empty)
  • RuntimeError (Files have different number of columns)
  • RuntimeError (Invalid column specification)
  • RuntimeError (Number of columns in data files and output columns are different)
  • ValueError (Column [column_identifier] not found)
putil.pcsv.dsort(fname, order, has_header=True, frow=0, ofname=None)

Sorts file data

Parameters:
  • fname (FileNameExists) – Name of the comma-separated values file to sort
  • order (CsvColFilter) – Sort order
  • has_header (boolean) – Flag that indicates whether the comma-separated values file to sort has column headers in its first line (True) or not (False)
  • frow (NonNegativeInteger) – First data row (starting from 1). If 0 the row where data starts is auto-detected as the first row that has a number (integer of float) in at least one of its columns
  • ofname (FileName or None) – Name of the output comma-separated values file, the file that will contain the sorted data. If None the sorting is done “in place”
Raises:
  • OSError (File [fname] could not be found)
  • RuntimeError (Argument `fname` is not valid)
  • RuntimeError (Argument `frow` is not valid)
  • RuntimeError (Argument `has_header` is not valid)
  • RuntimeError (Argument `ofname` is not valid)
  • RuntimeError (Argument `order` is not valid)
  • RuntimeError (Column headers are not unique in file [fname])
  • RuntimeError (File [fname] has no valid data)
  • RuntimeError (File [fname] is empty)
  • RuntimeError (Invalid column specification)
  • ValueError (Column [column_identifier] not found)
putil.pcsv.merge(fname1, fname2, dfilter1=None, dfilter2=None, has_header1=True, has_header2=True, frow1=0, frow2=0, ofname=None, ocols=None)

Merges two comma-separated values files. Data columns from the second file are appended after data columns from the first file. Empty values in columns are used if the files have different number of rows

Parameters:
  • fname1 (FileNameExists) – Name of the first comma-separated values file, the file whose columns appear first in the output file
  • fname2 (FileNameExists) – Name of the second comma-separated values file, the file whose columns appear last in the output file
  • dfilter1 (CsvDataFilter or None) – Row and/or column filter for the first file. If None no data filtering is done on the file
  • dfilter2 (CsvDataFilter or None) – Row and/or column filter for the second file. If None no data filtering is done on the file
  • has_header1 (boolean) – Flag that indicates whether the first comma-separated values file has column headers in its first line (True) or not (False)
  • has_header2 (boolean) – Flag that indicates whether the second comma-separated values file has column headers in its first line (True) or not (False)
  • frow1 (NonNegativeInteger) – First comma-separated values file first data row (starting from 1). If 0 the row where data starts is auto-detected as the first row that has a number (integer of float) in at least one of its columns
  • frow2 (NonNegativeInteger) – Second comma-separated values file first data row (starting from 1). If 0 the row where data starts is auto-detected as the first row that has a number (integer of float) in at least one of its columns
  • ofname (FileName or None) – Name of the output comma-separated values file, the file that will contain the data from the first and second files. If None the first file is replaced “in place”
  • ocols (list or None) – Column names of the output comma-separated values file. If None the column names in the first and second files are used if has_header1 and/or has_header2 are True. The column labels 'Column [column_number]' are used when one of the two files does not have a header, where [column_number] is an integer representing the column number (column 0 is the leftmost column). No header is used if has_header1 and has_header2 are False
Raises:
  • OSError (File [fname] could not be found)
  • RuntimeError (Argument `dfilter1` is not valid)
  • RuntimeError (Argument `dfilter2` is not valid)
  • RuntimeError (Argument `fname1` is not valid)
  • RuntimeError (Argument `fname2` is not valid)
  • RuntimeError (Argument `frow1` is not valid)
  • RuntimeError (Argument `frow2` is not valid)
  • RuntimeError (Argument `ocols` is not valid)
  • RuntimeError (Argument `ofname` is not valid)
  • RuntimeError (Column headers are not unique in file [fname])
  • RuntimeError (Combined columns in data files and output columns are different)
  • RuntimeError (File [fname] has no valid data)
  • RuntimeError (File [fname] is empty)
  • RuntimeError (Invalid column specification)
  • ValueError (Column [column_identifier] not found)
putil.pcsv.replace(fname1, fname2, dfilter1, dfilter2, has_header1=True, has_header2=True, frow1=0, frow2=0, ofname=None, ocols=None)

Replaces data in one file with data from another file

Parameters:
  • fname1 (FileNameExists) – Name of the input comma-separated values file, the file that contains the columns to be replaced
  • fname2 (FileNameExists) – Name of the replacement comma-separated values file, the file that contains the replacement data
  • dfilter1 (CsvDataFilter) – Row and/or column filter for the input file
  • dfilter2 (CsvDataFilter) – Row and/or column filter for the replacement file
  • has_header1 (boolean) – Flag that indicates whether the input comma-separated values file has column headers in its first line (True) or not (False)
  • has_header2 (boolean) – Flag that indicates whether the replacement comma-separated values file has column headers in its first line (True) or not (False)
  • frow1 (NonNegativeInteger) – Input comma-separated values file first data row (starting from 1). If 0 the row where data starts is auto-detected as the first row that has a number (integer of float) in at least one of its columns
  • frow2 (NonNegativeInteger) – Replacement comma-separated values file first data row (starting from 1). If 0 the row where data starts is auto-detected as the first row that has a number (integer of float) in at least one of its columns
  • ofname (FileName or None) – Name of the output comma-separated values file, the file that will contain the input file data but with some columns replaced with data from the replacement file. If None the input file is replaced “in place”
  • ocols (list or None) – Names of the replaced columns in the output comma-separated values file. If None the column names in the input file are used if has_header1 is True, otherwise no header is used
Raises:
  • OSError (File [fname] could not be found)
  • RuntimeError (Argument `dfilter1` is not valid)
  • RuntimeError (Argument `dfilter2` is not valid)
  • RuntimeError (Argument `fname1` is not valid)
  • RuntimeError (Argument `fname2` is not valid)
  • RuntimeError (Argument `frow1` is not valid)
  • RuntimeError (Argument `frow2` is not valid)
  • RuntimeError (Argument `ocols` is not valid)
  • RuntimeError (Argument `ofname` is not valid)
  • RuntimeError (Column headers are not unique in file [fname])
  • RuntimeError (File [fname] has no valid data)
  • RuntimeError (File [fname] is empty)
  • RuntimeError (Invalid column specification)
  • RuntimeError (Number of input and output columns are different)
  • RuntimeError (Number of input and replacement columns are different)
  • ValueError (Column [column_identifier] not found)
  • ValueError (Number of rows mismatch between input and replacement data)
putil.pcsv.write(fname, data, append=True)

Writes data to a specified comma-separated values (CSV) file

Parameters:
  • fname (FileName) – Name of the comma-separated values file to be written
  • data (list) – Data to write to the file. Each item in this argument should contain a sub-list corresponding to a row of data; each item in the sub-lists should contain data corresponding to a particular column
  • append (boolean) – Flag that indicates whether data is added to an existing file (or a new file is created if it does not exist) (True), or whether data overwrites the file contents (if the file exists) or creates a new file if the file does not exists (False)
Raises:
  • OSError (File [fname] could not be created: [reason])
  • RuntimeError (Argument `append` is not valid)
  • RuntimeError (Argument `data` is not valid)
  • RuntimeError (Argument `fname` is not valid)
  • ValueError (There is no data to save to file)

Classes

class putil.pcsv.CsvFile(fname, dfilter=None, has_header=True, frow=0)

Bases: object

Processes comma-separated values (CSV) files

Parameters:
  • fname (FileNameExists) – Name of the comma-separated values file to read
  • dfilter (CsvDataFilter or None) – Row and/or column filter. If None no data filtering is done
  • has_header (boolean) – Flag that indicates whether the comma-separated values file has column headers in its first line (True) o not (False)
  • frow (NonNegativeInteger) – First data row (starting from 1). If 0 the row where data starts is auto-detected as the first row that has a number (integer of float) in at least one of its columns
Return type:

putil.pcsv.CsvFile object

Raises:
  • OSError (File [fname] could not be found)
  • RuntimeError (Argument `dfilter` is not valid)
  • RuntimeError (Argument `fname` is not valid)
  • RuntimeError (Argument `frow` is not valid)
  • RuntimeError (Argument `has_header` is not valid)
  • RuntimeError (Column headers are not unique in file [fname])
  • RuntimeError (File [fname] has no valid data)
  • RuntimeError (File [fname] is empty)
  • RuntimeError (Invalid column specification)
  • ValueError (Column [column_identifier] not found)
__eq__(other)

Tests object equality. For example:

>>> import putil.misc, putil.pcsv
>>> with putil.misc.TmpFile() as fname:
...     putil.pcsv.write(fname, [['a'], [1]], append=False)
...     obj1 = putil.pcsv.CsvFile(fname, dfilter='a')
...     obj2 = putil.pcsv.CsvFile(fname, dfilter='a')
...
>>> with putil.misc.TmpFile() as fname:
...     putil.pcsv.write(fname, [['a'], [2]], append=False)
...     obj3 = putil.pcsv.CsvFile(fname, dfilter='a')
...
>>> obj1 == obj2
True
>>> obj1 == obj3
False
>>> 5 == obj3
False
__repr__()

Returns a string with the expression needed to re-create the object. For example:

>>> import putil.misc, putil.pcsv
>>> with putil.misc.TmpFile() as fname:
...     putil.pcsv.write(fname, [['a'], [1]], append=False)
...     obj1 = putil.pcsv.CsvFile(fname, dfilter='a')
...     exec("obj2="+repr(obj1))
>>> obj1 == obj2
True
>>> repr(obj1)
"putil.pcsv.CsvFile(fname=r'...', dfilter=['a'])"
add_dfilter(dfilter)

Adds more row(s) or column(s) to the existing data filter. Duplicate filter values are eliminated

Parameters:dfilter (CsvDataFilter) – Row and/or column filter
Raises:
  • RuntimeError (Argument `dfilter` is not valid)
  • RuntimeError (Invalid column specification)
  • ValueError (Column [column_identifier] not found)
cols(filtered=False)

Returns the number of data columns

Parameters:filtered (boolean) – Flag that indicates whether the raw (input) data should be used (False) or whether filtered data should be used (True)
Raises:RuntimeError (Argument `filtered` is not valid)
data(filtered=False, no_empty=False)
Returns (filtered) file data. The returned object is a list, each item is a sub-list corresponding to a row of data; each item in the sub-lists contains data corresponding to a particular column
Parameters:
  • filtered (CsvFiltered) – Filtering type
  • no_empty (bool) – Flag that indicates whether rows with empty columns should be filtered out (True) or not (False)
Return type:

list

Raises:
  • RuntimeError (Argument `filtered` is not valid)
  • RuntimeError (Argument `no_empty` is not valid)
dsort(order)

Sorts rows

Parameters:order (CsvColFilter) – Sort order
Raises:
  • RuntimeError (Argument `order` is not valid)
  • RuntimeError (Invalid column specification)
  • ValueError (Column [column_identifier] not found)
header(filtered=False)

Returns the data header. When the raw (input) data is used the data header is a list of the comma-separated values file header if the file is loaded with header (each list item is a column header) or a list of column numbers if the file is loaded without header (column zero is the leftmost column). When filtered data is used the data header is the active column filter, if any, otherwise it is the same as the raw (input) data header

Parameters:filtered (boolean) – Flag that indicates whether the raw (input) data should be used (False) or whether filtered data should be used (True)
Return type:list of strings or integers
Raises:RuntimeError (Argument `filtered` is not valid)
replace(rdata, filtered=False)

Replaces data

Parameters:
  • rdata (list of lists) – Replacement data
  • filtered (CsvFiltered) – Filtering type
Raises:
  • RuntimeError (Argument `filtered` is not valid)
  • RuntimeError (Argument `rdata` is not valid)
  • ValueError (Number of columns mismatch between input and replacement data)
  • ValueError (Number of rows mismatch between input and replacement data)
reset_dfilter(ftype=True)

Reset (clears) the data filter

Parameters:ftype (CsvFiltered) – Filter type
Raises:RuntimeError (Argument `ftype` is not valid)
rows(filtered=False)

Returns the number of data rows

Parameters:filtered (boolean) – Flag that indicates whether the raw (input) data should be used (False) or whether filtered data should be used (True)
Raises:RuntimeError (Argument `filtered` is not valid)
write(fname=None, filtered=False, header=True, append=False)

Writes (processed) data to a specified comma-separated values (CSV) file

Parameters:
  • fname (FileName) – Name of the comma-separated values file to be written. If None the file from which the data originated is overwritten
  • filtered (CsvFiltered) – Filtering type
  • header (string, list of strings or boolean) – If a list, column headers to use in the file. If boolean, flag that indicates whether the input column headers should be written (True) or not (False)
  • append (boolean) – Flag that indicates whether data is added to an existing file (or a new file is created if it does not exist) (True), or whether data overwrites the file contents (if the file exists) or creates a new file if the file does not exists (False)
Raises:
  • OSError (File [fname] could not be created: [reason])
  • RuntimeError (Argument `append` is not valid)
  • RuntimeError (Argument `filtered` is not valid)
  • RuntimeError (Argument `fname` is not valid)
  • RuntimeError (Argument `header` is not valid)
  • RuntimeError (Argument `no_empty` is not valid)
  • ValueError (There is no data to save to file)
cfilter

Sets or returns the column filter

Type:CsvColFilter or None. If None no column filtering is done
Return type:CsvColFilter or None
Raises:

(when assigned)

  • RuntimeError (Argument `cfilter` is not valid)
  • RuntimeError (Invalid column specification)
  • ValueError (Column [column_identifier] not found)
dfilter

Sets or returns the data (row and/or column) filter. The first tuple item is the row filter and the second tuple item is the column filter

Type:CsvDataFilter or None. If None no data filtering is done
Return type:CsvDataFilter or None
Raises:

(when assigned)

  • RuntimeError (Argument `dfilter` is not valid)
  • RuntimeError (Invalid column specification)
  • ValueError (Column [column_identifier] not found)
rfilter

Sets or returns the row filter

Type:CsvRowFilter or None. If None no row filtering is done
Return type:CsvRowFilter or None
Raises:

(when assigned)

  • RuntimeError (Argument `rfilter` is not valid)
  • RuntimeError (Invalid column specification)
  • ValueError (Argument `rfilter` is empty)
  • ValueError (Column [column_identifier] not found)