Skip to content

Commit 6245b59

Browse files
committed
TST: Test unnamed columns with index_col for Excel
Closes gh-18792.
1 parent e5c90e5 commit 6245b59

File tree

4 files changed

+13
-0
lines changed

4 files changed

+13
-0
lines changed

pandas/tests/io/data/test1.xls

512 Bytes
Binary file not shown.

pandas/tests/io/data/test1.xlsm

895 Bytes
Binary file not shown.

pandas/tests/io/data/test1.xlsx

896 Bytes
Binary file not shown.

pandas/tests/io/test_excel.py

+13
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,19 @@ def test_index_col_empty(self, ext):
245245
names=["A", "B", "C"]))
246246
tm.assert_frame_equal(result, expected)
247247

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+
tm.assert_frame_equal(result, expected)
260+
248261
def test_usecols_pass_non_existent_column(self, ext):
249262
msg = ("Usecols do not match columns, "
250263
"columns expected but not found: " + r"\['E'\]")

0 commit comments

Comments
 (0)