Skip to content

TST: Raise ValueError and suggestion to use header=None if header=-1 is pa… #27878

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 5 commits into from
Aug 15, 2019
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v0.25.1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ I/O
^^^

- Avoid calling ``S3File.s3`` when reading parquet, as this was removed in s3fs version 0.3.0 (:issue:`27756`)
-
- Better error message when a negative header is passed in :func:`pandas.read_csv` (:issue:`27779`)
-

Plotting
Expand Down
6 changes: 6 additions & 0 deletions pandas/io/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,12 @@ def _validate_header_arg(header) -> None:
"the row(s) making up the column names"
)

# In version 0.24, this would have worked.
if header == -1:
raise ValueError(
"Passing -1 to header is invalid. For no header, use header=None instead"
)


def _stringify_path(
filepath_or_buffer: FilePathOrBuffer[AnyStr]
Expand Down
15 changes: 15 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,21 @@ def test_read_with_bad_header(all_parsers):
parser.read_csv(s, header=[10])


def test_negative_header(all_parsers):
# see gh-27779
parser = all_parsers
data = """1,2,3,4,5
6,7,8,9,10
11,12,13,14,15
"""
with pytest.raises(
ValueError,
match="Passing -1 to header is invalid. "
"For no header, use header=None instead",
):
parser.read_csv(StringIO(data), header=-1)


@pytest.mark.parametrize("header", [True, False])
def test_bool_header_arg(all_parsers, header):
# see gh-6114
Expand Down