Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: read_excel raising uncontrolled IndexError when header references non-existing rows #47399

Merged
merged 3 commits into from
Jun 21, 2022

Conversation

phofl
Copy link
Member

@phofl phofl commented Jun 17, 2022

@phofl phofl added Error Reporting Incorrect or improved errors from pandas IO Excel read_excel, to_excel labels Jun 17, 2022
@@ -774,6 +774,11 @@ def parse(
assert isinstance(skiprows, int)
row += skiprows

if row > len(data) - 1:
raise ValueError(
f"Header index {row} references non-existing rows.",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be helpful to report the number of rows? E.g.

f"header index {row} exceeds maximum index {len(data) - 1} of data.",

I also made the h lowercase to match the argument header to read_excel.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, changed

pandas/tests/io/excel/test_readers.py Show resolved Hide resolved
Copy link
Member

@rhshadrach rhshadrach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@mroeschke mroeschke added this to the 1.5 milestone Jun 21, 2022
@mroeschke mroeschke merged commit b022a3b into pandas-dev:main Jun 21, 2022
@mroeschke
Copy link
Member

Thanks @phofl

@phofl phofl deleted the 43134 branch June 21, 2022 21:58
yehoshuadimarsky pushed a commit to yehoshuadimarsky/pandas that referenced this pull request Jul 13, 2022
…s non-existing rows (pandas-dev#47399)

* BUG: read_excel raising uncontrolled IndexError when header references non-existing rows

* Fix issue number

* Change message
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Error Reporting Incorrect or improved errors from pandas IO Excel read_excel, to_excel
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: read_excel throws generic IndexError if header argument specifies non-existent rows
3 participants