You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
(Well, it applies to TSV files, too. So the help text could be improved.)
I reckon raising an error if --no-header is used without either --csv or --tsv would be good.
Furthermore, the options seem a bit messy to me. I mean, you could specify --csv, --tsv, and --fmt all at once. I'd suggest at least check that none of that is happening. And make it clear in the help text that --fmt is using the tabulate library. Don't try to hide it: that abstraction is leaking already.
@zellyn Which formats are you working with? I've not looked closely at the list of formats tabulate can write, and which have headers. Are you trying to skip headers from a format that sqlite-utils is delegating to tabulate for? Perhaps the tabulate library has an option for omitting a header: sqlite-utils could pass that (or arbitrary) options to tabulate.
Do bear in mind that if you're using a system that has the tail command, you can use tail -n +2 as a filter to remove the first line of a text stream:
The root cause is that the two tabulate.tabulate() call sites in cli.py (the tables command at line 240 and _execute_query at line 2142) always pass headers=headers regardless of the --no-headers flag. The flag is only checked in the CSV/TSV branch.
Rather than raising an error when --fmt and --no-headers are combined, I found that tabulate.tabulate(data, headers=()) cleanly suppresses headers while preserving the table format. This approach makes --no-headers work consistently across all output modes (CSV, TSV, and tabulate formats).
I have a fix with tests ready — would this be welcome as a PR?
Activity
simonw commentedon Jul 9, 2023
Thanks, looks like a bug.
simonw commentedon Jul 9, 2023
On consulting https://pypi.org/project/tabulate/ it looks like most of those formats don't actually makes sense without headers - so the right thing here might be to raise an error if
--fmtand--no-headersare used at the same time.tobych commentedon Apr 29, 2024
Seems to me that this is not a bug, and that @zellyn might be misunderstanding what
--no-headersis for.The help text for
--no-headersreads: "Omit CSV headers".(Well, it applies to TSV files, too. So the help text could be improved.)
I reckon raising an error if
--no-headeris used without either--csvor--tsvwould be good.Furthermore, the options seem a bit messy to me. I mean, you could specify
--csv,--tsv, and--fmtall at once. I'd suggest at least check that none of that is happening. And make it clear in the help text that--fmtis using the tabulate library. Don't try to hide it: that abstraction is leaking already.zellyn commentedon Apr 29, 2024
My use case for using
--no-headersis almost 100% “I'm about to pass this throughxargsor some other unix utility.But you're right that it doesn't make sense for most of the formats that are generating some kind of markup rendering.
tobych commentedon Apr 29, 2024
@zellyn Which formats are you working with? I've not looked closely at the list of formats
tabulatecan write, and which have headers. Are you trying to skip headers from a format thatsqlite-utilsis delegating totabulatefor? Perhaps thetabulatelibrary has an option for omitting a header:sqlite-utilscould pass that (or arbitrary) options totabulate.Do bear in mind that if you're using a system that has the
tailcommand, you can usetail -n +2as a filter to remove the first line of a text stream:zellyn commentedon Apr 30, 2024
Yeah, I've done the
tailthing for sure. I've mostly gotten around this now by usingtsvand only selecting one column, which basically isplain.CrepuscularIRIS commentedon Apr 15, 2026
Hi — I'd like to work on this.
The root cause is that the two
tabulate.tabulate()call sites incli.py(thetablescommand at line 240 and_execute_queryat line 2142) always passheaders=headersregardless of the--no-headersflag. The flag is only checked in the CSV/TSV branch.Rather than raising an error when
--fmtand--no-headersare combined, I found thattabulate.tabulate(data, headers=())cleanly suppresses headers while preserving the table format. This approach makes--no-headerswork consistently across all output modes (CSV, TSV, and tabulate formats).I have a fix with tests ready — would this be welcome as a PR?
fix(cli): honor --no-headers flag with --fmt/--table output
Honor --no-headers for --fmt and --table output (#566) (#751)
--no-headers fix in changelog, refs #566
Release 4.0rc4