Skip to content

Commit 878f550

Browse files
author
Marco Gorelli
committed
Make comment about previous version more specific
1 parent 5de4e55 commit 878f550

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

pandas/io/common.py

+6
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,12 @@ def _validate_header_arg(header) -> None:
125125
"the row(s) making up the column names"
126126
)
127127

128+
# In version 0.24, this would have worked.
129+
if header == -1:
130+
raise ValueError(
131+
"Passing -1 to header is invalid. For no header, use header=None instead"
132+
)
133+
128134

129135
def _stringify_path(
130136
filepath_or_buffer: FilePathOrBuffer[AnyStr]

pandas/tests/io/parser/test_header.py

+14
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,20 @@ def test_read_with_bad_header(all_parsers):
2424
parser.read_csv(s, header=[10])
2525

2626

27+
def test_negative_header(all_parsers):
28+
parser = all_parsers
29+
data = """1,2,3,4,5
30+
6,7,8,9,10
31+
11,12,13,14,15
32+
"""
33+
with pytest.raises(
34+
ValueError,
35+
match="Passing -1 to header is invalid. "
36+
"For no header, use header=None instead",
37+
):
38+
parser.read_csv(StringIO(data), header=-1)
39+
40+
2741
@pytest.mark.parametrize("header", [True, False])
2842
def test_bool_header_arg(all_parsers, header):
2943
# see gh-6114

0 commit comments

Comments
 (0)