Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • C csvkit
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 61
    • Issues 61
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 4
    • Merge requests 4
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • wireservice
  • csvkit
  • Merge requests
  • !1096

Fixed error when --no-header-row is combined with --groups/--filenames

  • Review changes

  • Download
  • Email patches
  • Plain diff
Merged Administrator requested to merge github/fork/dannguyen/csvstack-no-header-row-fix into master Oct 29, 2020
  • Overview 3
  • Commits 1
  • Pipelines 0
  • Changes 2

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.

Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: github/fork/dannguyen/csvstack-no-header-row-fix