Skip to content

Commit b613a16

Browse files
committed
Fix bug read_csv with pyarrow engine cannot handle single-line CSV files
1 parent 10102e6 commit b613a16

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

pandas/io/parsers/arrow_parser_wrapper.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ def handle_warning(invalid_row) -> str:
140140
]
141141

142142
self.read_options = {
143+
"column_names": [] if self.header is None else self.kwds["names"],
143144
"autogenerate_column_names": self.header is None,
144145
"skip_rows": self.header
145146
if self.header is not None

pandas/tests/io/parser/common/test_common_basic.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,17 @@ def test_csv_mixed_type(all_parsers):
119119
tm.assert_frame_equal(result, expected)
120120

121121

122+
def test_read_csv_single_line(all_parsers):
123+
# GH62635
124+
parser = all_parsers
125+
table = parser.read_csv(
126+
StringIO("1,2,3\n"),
127+
names=["col1", "col2", "col3"],
128+
)
129+
expected = DataFrame({"col1": [1], "col2": [2], "col3": [3]})
130+
tm.assert_frame_equal(table, expected)
131+
132+
122133
def test_read_csv_low_memory_no_rows_with_index(all_parsers):
123134
# see gh-21141
124135
parser = all_parsers

0 commit comments

Comments
 (0)