Repository: astanin/python-tabulate

Issue:
tabulate prints "f i r s t r o w" as headers for empty data
I have a use case where i get data about errors received. In that, I keep the headers in the data itself, and use the `firstrow` feature to print. But there are times when there is no error, so the entire data is empty (even the headers are not added). In that case I get each word of "firstrow" printed as a header:

```python
>>> print(tabulate([], headers="firstrow"))
f    i    r    s    t    r    o    w
---  ---  ---  ---  ---  ---  ---  ---
>>>
```

Discussion:

Patch:
diff --git a/tabulate.py b/tabulate.py
index 0579fb3..0a23f3c 100644
--- a/tabulate.py
+++ b/tabulate.py
@@ -1189,6 +1189,8 @@ def _normalize_tabular_data(tabular_data, headers, showindex="default"):
             headers = rows[0]
         headers = list(map(_text_type, headers))  # headers should be strings
         rows = rows[1:]
+    elif headers == "firstrow":
+        headers = []
 
     headers = list(map(_text_type, headers))
     rows = list(map(list, rows))


Test patch:
diff --git a/test/test_output.py b/test/test_output.py
index eed4489..b751e5e 100644
--- a/test/test_output.py
+++ b/test/test_output.py
@@ -1412,6 +1412,13 @@ def test_empty_data_without_headers():
     assert_equal(expected, result)
 
 
+def test_empty_data_with_headers():
+    "Output: table with empty data and headers as firstrow"
+    expected = ""
+    result = tabulate([], headers="firstrow")
+    assert_equal(expected, result)
+
+
 def test_floatfmt():
     "Output: floating point format"
     result = tabulate([["1.23456789"], [1.0]], floatfmt=".3f", tablefmt="plain")