Skip to content

Raise exception in read_csv when prefix is set, but not used because a header exists #27998

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

Closed
wants to merge 2 commits into from

Conversation

PraneethKhanna
Copy link

@PraneethKhanna PraneethKhanna commented Aug 18, 2019

Raised an error if argument prefix is set when there are headers present during pandas read_csv.

Raised an error if argument prefix is set when there are headers present during pandas read_csv.
Copy link
Member

@mroeschke mroeschke left a comment

Choose a reason for hiding this comment

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

Needs test and whatsnew entry in 1.0.0

@datapythonista datapythonista changed the title GH27394 Raise exception in read_csv when prefix is set, but not used because a header exists Aug 19, 2019
@datapythonista datapythonista added Error Reporting Incorrect or improved errors from pandas IO CSV read_csv, to_csv labels Aug 19, 2019
Copy link
Member

@datapythonista datapythonista left a comment

Choose a reason for hiding this comment

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

This change can break code, not sure if we should start by a warning and break later.

@@ -1930,6 +1930,9 @@ def __init__(self, src, **kwds):
]
else:
self.names = list(range(self._reader.table_width))
else:
if self.prefix:
Copy link
Member

Choose a reason for hiding this comment

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

probably worth using elif

Copy link
Author

Choose a reason for hiding this comment

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

yes, will change that

@@ -1930,6 +1930,9 @@ def __init__(self, src, **kwds):
]
else:
self.names = list(range(self._reader.table_width))
else:
if self.prefix:
raise ValueError("argument prefix must be None if header not None")
Copy link
Member

Choose a reason for hiding this comment

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

The error message is not 100% correct, since the header can be provided with names.

Raised the appropriate error message
@datapythonista
Copy link
Member

@PraneethKhanna do you have time to add the requested test and the note in the release notes (aka whatsnew)?

@WillAyd
Copy link
Member

WillAyd commented Sep 17, 2019

Looks like this is stale but @PraneethKhanna if you'd like to pick back up please ping!

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 CSV read_csv, to_csv
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pd.read_csv prefix parameter seems do not works
4 participants