Repository: astanin/python-tabulate

Issue:
Shift headers wrongly when do tabulate(headers="keys", showindex=False) with pandas.DataFrame with named index
```python
import pandas as pd
from tabulate import tabulate
df = pd.DataFrame({"a": [0,1,2]}, index=pd.Index([1,2,3], name="b"))
print(tabulate(df, headers="keys", showindex=False))
```

Expected result is:
```
  a
---
  0 
  1
  2
```

but got (index name is wrongly used as a header):
```
  b
---
  0
  1
  2
```


Discussion:

Patch:
diff --git a/tabulate.py b/tabulate.py
index 5d57167..d611dc1 100755
--- a/tabulate.py
+++ b/tabulate.py
@@ -1022,7 +1022,7 @@ def _normalize_tabular_data(tabular_data, headers, showindex="default"):
         elif hasattr(tabular_data, "index"):
             # values is a property, has .index => it's likely a pandas.DataFrame (pandas 0.11.0)
             keys = list(tabular_data)
-            if tabular_data.index.name is not None:
+            if showindex in ["default", "always", True] and tabular_data.index.name is not None:
                 if isinstance(tabular_data.index.name, list):
                     keys[:0] = tabular_data.index.name
                 else:


Test patch:
diff --git a/test/test_output.py b/test/test_output.py
index 0e72c71..061d302 100644
--- a/test/test_output.py
+++ b/test/test_output.py
@@ -1363,7 +1363,8 @@ def test_pandas_without_index():
         import pandas
 
         df = pandas.DataFrame(
-            [["one", 1], ["two", None]], columns=["string", "number"], index=["a", "b"]
+            [["one", 1], ["two", None]], columns=["string", "number"],
+            index=pandas.Index(["a", "b"], name="index")
         )
         expected = "\n".join(
             [