|
15 | 15 | import pandas.util.testing as tm
|
16 | 16 | import pandas.util._test_decorators as td
|
17 | 17 | from pandas import DataFrame, Index, MultiIndex, Series
|
18 |
| -from pandas.compat import u, range, map, BytesIO, iteritems, PY36 |
| 18 | +from pandas.compat import u, range, map, BytesIO, iteritems, PY2, PY36 |
19 | 19 | from pandas.core.config import set_option, get_option
|
20 | 20 | from pandas.io.common import URLError
|
21 | 21 | from pandas.io.excel import (
|
@@ -245,6 +245,23 @@ def test_index_col_empty(self, ext):
|
245 | 245 | names=["A", "B", "C"]))
|
246 | 246 | tm.assert_frame_equal(result, expected)
|
247 | 247 |
|
| 248 | + @pytest.mark.parametrize("index_col", [None, 2]) |
| 249 | + def test_index_col_with_unnamed(self, ext, index_col): |
| 250 | + # see gh-18792 |
| 251 | + result = self.get_exceldf("test1", ext, "Sheet4", |
| 252 | + index_col=index_col) |
| 253 | + expected = DataFrame([["i1", "a", "x"], ["i2", "b", "y"]], |
| 254 | + columns=["Unnamed: 0", "col1", "col2"]) |
| 255 | + |
| 256 | + if index_col: |
| 257 | + expected = expected.set_index(expected.columns[index_col]) |
| 258 | + |
| 259 | + # Python 2.x somehow interprets column |
| 260 | + # type as "mixed" instead of a string-type. |
| 261 | + check_column_type = not PY2 |
| 262 | + tm.assert_frame_equal(result, expected, |
| 263 | + check_column_type=check_column_type) |
| 264 | + |
248 | 265 | def test_usecols_pass_non_existent_column(self, ext):
|
249 | 266 | msg = ("Usecols do not match columns, "
|
250 | 267 | "columns expected but not found: " + r"\['E'\]")
|
|
0 commit comments