Skip to content

Commit

Permalink
TST: Test unnamed columns with index_col for Excel
Browse files Browse the repository at this point in the history
  • Loading branch information
gfyoung committed Nov 25, 2018
1 parent 3117f78 commit 9238348
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v0.24.0.rst
Expand Up @@ -1396,7 +1396,7 @@ Notice how we now instead output ``np.nan`` itself instead of a stringified form
- Bug in :meth:`read_csv()` in which unnecessary warnings were being raised when the dialect's values conflicted with the default arguments (:issue:`23761`)
- Bug in :meth:`read_html()` in which the error message was not displaying the valid flavors when an invalid one was provided (:issue:`23549`)
- Bug in :meth:`read_excel()` in which extraneous header names were extracted, even though none were specified (:issue:`11733`)
- Bug in :meth:`read_excel()` in which ``index_col=None`` was not being respected and parsing index columns anyway (:issue:`20480`)
- Bug in :meth:`read_excel()` in which ``index_col=None`` was not being respected and parsing index columns anyway (:issue:`18792`, :issue:`20480`)
- Bug in :meth:`read_excel()` in which ``usecols`` was not being validated for proper column names when passed in as a string (:issue:`20480`)

Plotting
Expand Down
Binary file modified pandas/tests/io/data/test1.xls
Binary file not shown.
Binary file modified pandas/tests/io/data/test1.xlsm
Binary file not shown.
Binary file modified pandas/tests/io/data/test1.xlsx
Binary file not shown.
19 changes: 18 additions & 1 deletion pandas/tests/io/test_excel.py
Expand Up @@ -11,7 +11,7 @@
from numpy import nan
import pytest

from pandas.compat import PY36, BytesIO, iteritems, map, range, u
from pandas.compat import PY2, PY36, BytesIO, iteritems, map, range, u
import pandas.util._test_decorators as td

import pandas as pd
Expand Down Expand Up @@ -264,6 +264,23 @@ def test_index_col_empty(self, ext):
names=["A", "B", "C"]))
tm.assert_frame_equal(result, expected)

@pytest.mark.parametrize("index_col", [None, 2])
def test_index_col_with_unnamed(self, ext, index_col):
# see gh-18792
result = self.get_exceldf("test1", ext, "Sheet4",
index_col=index_col)
expected = DataFrame([["i1", "a", "x"], ["i2", "b", "y"]],
columns=["Unnamed: 0", "col1", "col2"])
if index_col:
expected = expected.set_index(expected.columns[index_col])

# Python 2.x somehow interprets column
# type as "mixed" instead of a string-type.

check_column_type = not PY2
tm.assert_frame_equal(result, expected,
check_column_type=check_column_type)

def test_usecols_pass_non_existent_column(self, ext):
msg = ("Usecols do not match columns, "
"columns expected but not found: " + r"\['E'\]")
Expand Down

0 comments on commit 9238348

Please sign in to comment.