Created by: dannguyen
In csvstack, an error occurred when combining the --no-header-row flag with either --groups or --filenames.
For example:
$ csvstack --filenames -H examples/dummy.csv examples/dummy2.csv --verbose
The expected (if funky) output is:
group,a,b,c
dummy.csv,a,b,c
dummy.csv,1,2,3
dummy2.csv,a,b,c
dummy2.csv,1,2,3
However, this error occurs:
Traceback (most recent call last):
  File "/Users/dan/.pyenv/versions/3.8.5/bin/csvstack", line 11, in <module>
    load_entry_point('csvkit', 'console_scripts', 'csvstack')()
  File "/Users/dan/git/csvkit/csvkit/utilities/csvstack.py", line 100, in launch_new_instance
    utility.run()
  File "/Users/dan/git/csvkit/csvkit/cli.py", line 118, in run
    self.main()
  File "/Users/dan/git/csvkit/csvkit/utilities/csvstack.py", line 80, in main
    headers.insert(0, group_name)
AttributeError: 'tuple' object has no attribute 'insert'
The cause of this error seems to be what csvstack.py assumes when invoking make_default_headers(...) – make_default_headers returns a tuple, but csvstack attempts to do list#insert(), which is not possible with a tuple:
                headers = make_default_headers(len(row))
                if i == 0:
                    if has_groups:
                        headers.insert(0, group_name)
The fix is simple: cast the return value of make_default_headers() as a list:
                headers = make_default_headers(len(row))
This pull request also includes 3 tests related to the --no-header-row option in addition to the existing test_no_header_row_basic() test.