Skip to content

BUG: read_csv raising IndexError with multiple header cols, specified index_col and no data rows #38325

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

Merged
merged 7 commits into from
Dec 13, 2020

Conversation

phofl
Copy link
Member

@phofl phofl commented Dec 5, 2020

Parser returned an empty list instead of a list filled with None, which caused the IndexError.

@phofl phofl added the IO CSV read_csv, to_csv label Dec 6, 2020
@@ -729,6 +729,7 @@ I/O
- :meth:`read_fwf` was inferring compression with ``compression=None`` which was not consistent with the other :meth:``read_*`` functions (:issue:`37909`)
Copy link
Member

Choose a reason for hiding this comment

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

i think italics are messed up bc the "read*" should have single-ticks instead of double-ticks

Copy link
Member Author

Choose a reason for hiding this comment

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

Changed it

@@ -729,6 +729,7 @@ I/O
- :meth:`read_fwf` was inferring compression with ``compression=None`` which was not consistent with the other :meth:``read_*`` functions (:issue:`37909`)
- :meth:`DataFrame.to_html` was ignoring ``formatters`` argument for ``ExtensionDtype`` columns (:issue:`36525`)
- Bumped minimum xarray version to 0.12.3 to avoid reference to the removed ``Panel`` class (:issue:`27101`)
- Bug in :meth:`read_csv` raising ``IndexError`` with multiple header columns and ``index_col`` specified when file has no data rows (:issue:`38292`)
Copy link
Member

Choose a reason for hiding this comment

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

meth -> func

Copy link
Member Author

Choose a reason for hiding this comment

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

Thx, should we change the other too then?

Copy link
Member

Choose a reason for hiding this comment

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

might as well

Copy link
Member Author

Choose a reason for hiding this comment

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

Unforunately was a bit slow :(

@@ -726,9 +726,10 @@ I/O
- :meth:`DataFrame.to_excel`, :meth:`Series.to_excel`, :meth:`DataFrame.to_markdown`, and :meth:`Series.to_markdown` now support writing to fsspec URLs such as S3 and Google Cloud Storage (:issue:`33987`)
- Bug in :func:`read_fwf` with ``skip_blank_lines=True`` was not skipping blank lines (:issue:`37758`)
- Parse missing values using :func:`read_json` with ``dtype=False`` to ``NaN`` instead of ``None`` (:issue:`28501`)
- :meth:`read_fwf` was inferring compression with ``compression=None`` which was not consistent with the other :meth:``read_*`` functions (:issue:`37909`)
- :meth:`read_fwf` was inferring compression with ``compression=None`` which was not consistent with the other :meth:`read_*` functions (:issue:`37909`)
Copy link
Contributor

Choose a reason for hiding this comment

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

will need to move to 1.3 (avail shortly)

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

Copy link
Contributor

Choose a reason for hiding this comment

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

can you remove from 1.2 :->

Copy link
Member Author

Choose a reason for hiding this comment

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

Thx, done

# list of Nones GH#38292
index_names = [None] * len(ic)
else:
index_names, _, _ = _clean_index_names(
Copy link
Contributor

Choose a reason for hiding this comment

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

can you generate this in _clean_index_names instead?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

@@ -222,3 +222,18 @@ def test_index_col_large_csv(all_parsers):
result = parser.read_csv(path, index_col=[0])

tm.assert_frame_equal(result, df.set_index("a"))


def test_index_col_multiindex_columns_no_data(all_parsers):
Copy link
Contributor

Choose a reason for hiding this comment

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

can you add all the cases form the op (3 working & the non-working)

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

@jreback jreback added this to the 1.3 milestone Dec 10, 2020
@jreback jreback added the Bug label Dec 10, 2020
Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

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

doc change, ping on green.

@@ -726,9 +726,10 @@ I/O
- :meth:`DataFrame.to_excel`, :meth:`Series.to_excel`, :meth:`DataFrame.to_markdown`, and :meth:`Series.to_markdown` now support writing to fsspec URLs such as S3 and Google Cloud Storage (:issue:`33987`)
- Bug in :func:`read_fwf` with ``skip_blank_lines=True`` was not skipping blank lines (:issue:`37758`)
- Parse missing values using :func:`read_json` with ``dtype=False`` to ``NaN`` instead of ``None`` (:issue:`28501`)
- :meth:`read_fwf` was inferring compression with ``compression=None`` which was not consistent with the other :meth:``read_*`` functions (:issue:`37909`)
- :meth:`read_fwf` was inferring compression with ``compression=None`` which was not consistent with the other :meth:`read_*` functions (:issue:`37909`)
Copy link
Contributor

Choose a reason for hiding this comment

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

can you remove from 1.2 :->

@phofl
Copy link
Member Author

phofl commented Dec 11, 2020

@jreback green

@jreback
Copy link
Contributor

jreback commented Dec 12, 2020

lgtm, resolved conflict, though there is another PR that might conflict on whatsnew, but will see.

@phofl
Copy link
Member Author

phofl commented Dec 12, 2020

Yeah, thanks for merging. As soon as we got a few messages in there we can vary the order a bit to avoid this

@jreback jreback merged commit bd39ded into pandas-dev:master Dec 13, 2020
@jreback
Copy link
Contributor

jreback commented Dec 13, 2020

thanks

@phofl phofl deleted the 38292 branch December 13, 2020 20:02
luckyvs1 pushed a commit to luckyvs1/pandas that referenced this pull request Jan 20, 2021
… index_col and no data rows (pandas-dev#38325)

* BUG: read_csv raising IndexError with multiple header cols, specified index_col and no data rows

* Adress comments

* Add tests and move whatsnew

* Revert change

Co-authored-by: Jeff Reback <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug IO CSV read_csv, to_csv
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: read_csv raises IndexError when index_col is passed
3 participants