-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
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
Conversation
There was a problem hiding this 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
There was a problem hiding this 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.
pandas/io/parsers.py
Outdated
@@ -1930,6 +1930,9 @@ def __init__(self, src, **kwds): | |||
] | |||
else: | |||
self.names = list(range(self._reader.table_width)) | |||
else: | |||
if self.prefix: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably worth using elif
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, will change that
pandas/io/parsers.py
Outdated
@@ -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") |
There was a problem hiding this comment.
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
.
@PraneethKhanna do you have time to add the requested test and the note in the release notes (aka whatsnew)? |
Looks like this is stale but @PraneethKhanna if you'd like to pick back up please ping! |
Raised an error if argument prefix is set when there are headers present during pandas read_csv.
black pandas
git diff upstream/master -u -- "*.py" | flake8 --diff