Skip to content

bcftbx/TabFile: inconsistency when appending columns to TabFile with empty header #179

Description

@pjbriggs

There appears to be a problem when appending columns to a TabFile which contains data but which doesn't already have any column names assigned.

Example: create a new (empty) TabFile with no header and add a line of data - it reports the number of columns as zero and the header as an empty list:

>>> from bcftbx.TabFile import TabFile
>>> t = TabFile()
>>> t.append(data=[1,2,3])
1	2	3
>>> t.nColumns()
0
>>> t.header()
[]

Now append a new column - only the new column is reported:

>>> t.appendColumn('extra')
>>> t
1	2	3	
>>> t.header()
['extra']

Output the data to stdout:

>>> import sys
>>> t.write(fp=sys.stdout,include_header=True)
#extra
1	2	3	

Add data to the extra column and output to stdout again - now the first column is overwritten:

>>> t[0]['extra'] = 4
>>> t.write(fp=sys.stdout,include_header=True)
#extra
4	2	3	

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions