Skip to content

Raise error in read_csv when arguments header and prefix both are not None #31383

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 17 commits into from
Feb 3, 2020
Merged
4 changes: 4 additions & 0 deletions pandas/io/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1908,6 +1908,10 @@ def __init__(self, src, **kwds):
]
else:
self.names = list(range(self._reader.table_width))
elif self.prefix:
raise ValueError(
"Argument prefix must be None if argument header is not None"
)

# gh-9755
#
Expand Down
8 changes: 8 additions & 0 deletions pandas/tests/io/parser/test_header.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ def test_read_with_bad_header(all_parsers):
parser.read_csv(s, header=[10])


def test_read_raises_on_header_prefix(all_parsers):
parser = all_parsers
msg = "Argument prefix must be None if argument header is not None"
with pytest.raises(ValueError, match=msg):
s = StringIO("0,1\n2,3")
parser.read_csv(s, header=0, prefix="_X")


def test_negative_header(all_parsers):
# see gh-27779
parser = all_parsers
Expand Down