BUG: Fix read_excel w/parse_cols & empty dataset
State: closed

Closes #9208.


Labels:
name: Bug
name: IO Excel
description: read_excel, to_excel

Comments:
Hello @gfyoung! Thanks for submitting the PR.

 - There are no PEP8 issues in the file [`pandas/io/excel.py`](https://github.com/gfyoung/pandas/blob/13abef88b59ded1f7ad58d8ae5600b724c7f99b5/pandas/io/excel.py) !

 - There are no PEP8 issues in the file [`pandas/tests/io/test_excel.py`](https://github.com/gfyoung/pandas/blob/13abef88b59ded1f7ad58d8ae5600b724c7f99b5/pandas/tests/io/test_excel.py) !


# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/23661?src=pr&el=h1) Report
> Merging [#23661](https://codecov.io/gh/pandas-dev/pandas/pull/23661?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/20bdb3e4019afe2037b26524a447ac8913d6e325?src=pr&el=desc) will **not change** coverage.
> The diff coverage is `n/a`.

[![Impacted file tree graph](https://codecov.io/gh/pandas-dev/pandas/pull/23661/graphs/tree.svg?width=650&token=eZ4WkYLtcO&height=150&src=pr)](https://codecov.io/gh/pandas-dev/pandas/pull/23661?src=pr&el=tree)

```diff
@@           Coverage Diff           @@
##           master   #23661   +/-   ##
=======================================
  Coverage   92.24%   92.24%           
=======================================
  Files         161      161           
  Lines       51317    51317           
=======================================
  Hits        47338    47338           
  Misses       3979     3979
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.63% <ø> (ø)` | :arrow_up: |
| #single | `42.31% <ø> (ø)` | :arrow_up: |


------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/23661?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/23661?src=pr&el=footer). Last update [20bdb3e...13abef8](https://codecov.io/gh/pandas-dev/pandas/pull/23661?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

That's what I was hoping :) +1

On Tue, Nov 13, 2018 at 8:00 AM gfyoung <notifications@github.com> wrote:

> *@gfyoung* commented on this pull request.
> ------------------------------
>
> In pandas/io/excel.py
> <https://github.com/pandas-dev/pandas/pull/23661#discussion_r233047516>:
>
> > @@ -634,14 +634,17 @@ def _parse_cell(cell_contents, cell_typ):
>                  else:
>                      offset = 1 + max(header)
>
> -                for col in index_col:
> -                    last = data[offset][col]
> -
> -                    for row in range(offset + 1, len(data)):
> -                        if data[row][col] == '' or data[row][col] is None:
> -                            data[row][col] = last
> -                        else:
> -                            last = data[row][col]
> +                # Check if we have an empty dataset
> +                # before trying to collect data.
> +                if offset < len(data):
>
> What are the changes to the excel file?
>
> To add a test that addresses your question:
>
> Do we have a test where offset is equal to len(data)?
>
> Don't worry, I accounted for the off-by-one 😉
>
> —
> You are receiving this because you commented.
> Reply to this email directly, view it on GitHub
> <https://github.com/pandas-dev/pandas/pull/23661#discussion_r233047516>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/ABQHIkj7BfvgfE1ziQ8dXDqG8bhez2g0ks5uutBkgaJpZM4Ya6xX>
> .
>