Skip to content

Commit 85b9127

Browse files
author
Marco Gorelli
committed
Merge branch 'negative-header' of https://github.com/MarcoGorelli/pandas
2 parents e26fa2b + 115e14a commit 85b9127

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

pandas/io/common.py

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

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

129136
def _stringify_path(
130137
filepath_or_buffer: FilePathOrBuffer[AnyStr]

pandas/tests/io/parser/test_header.py

+14
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,20 @@ def test_bool_header_arg(all_parsers, header):
3939
parser.read_csv(StringIO(data), header=header)
4040

4141

42+
def test_negative_header(all_parsers):
43+
parser = all_parsers
44+
data = """1,2,3,4,5
45+
6,7,8,9,10
46+
11,12,13,14,15
47+
"""
48+
with pytest.raises(
49+
ValueError,
50+
match="Passing -1 to header is invalid. "
51+
"For no header, use header=None instead",
52+
):
53+
parser.read_csv(StringIO(data), header=-1)
54+
55+
4256
def test_no_header_prefix(all_parsers):
4357
parser = all_parsers
4458
data = """1,2,3,4,5

0 commit comments

Comments
 (0)