Skip to content

Commit 1832fad

Browse files
phoflyehoshuadimarsky
authored andcommitted
REGR: index_col False and header=None inferring index names in some cases (pandas-dev#47139)
1 parent 91ac5dd commit 1832fad

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

doc/source/whatsnew/v1.4.3.rst

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Fixed regressions
1919
- Fixed regression in :func:`read_fwf` raising ``ValueError`` when ``widths`` was specified with ``usecols`` (:issue:`46580`)
2020
- Fixed regression in :meth:`.Groupby.transform` and :meth:`.Groupby.agg` failing with ``engine="numba"`` when the index was a :class:`MultiIndex` (:issue:`46867`)
2121
- Fixed regression is :meth:`.Styler.to_latex` and :meth:`.Styler.to_html` where ``buf`` failed in combination with ``encoding`` (:issue:`47053`)
22+
- Fixed regression in :func:`read_csv` with ``index_col=False`` identifying first row as index names when ``header=None`` (:issue:`46955`)
2223
- Fixed regression in :meth:`.DataFrameGroupBy.agg` when used with list-likes or dict-likes and ``axis=1`` that would give incorrect results; now raises ``NotImplementedError`` (:issue:`46995`)
2324
- Fixed regression in :meth:`DataFrame.resample` and :meth:`DataFrame.rolling` when used with list-likes or dict-likes and ``axis=1`` that would raise an unintuitive error message; now raises ``NotImplementedError`` (:issue:`46904`)
2425

pandas/io/parsers/python_parser.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -933,7 +933,7 @@ def _get_index_name(
933933
implicit_first_cols = len(line) - self.num_original_columns
934934

935935
# Case 0
936-
if next_line is not None:
936+
if next_line is not None and self.header is not None:
937937
if len(next_line) == len(line) + self.num_original_columns:
938938
# column and index names on diff rows
939939
self.index_col = list(range(len(line)))

pandas/tests/io/parser/test_python_parser_only.py

+12
Original file line numberDiff line numberDiff line change
@@ -457,3 +457,15 @@ def test_on_bad_lines_index_col_inferred(python_parser_only):
457457
result = parser.read_csv(bad_sio, on_bad_lines=lambda x: ["99", "99"])
458458
expected = DataFrame({"a": [2, 5], "b": [3, 6]}, index=[1, 4])
459459
tm.assert_frame_equal(result, expected)
460+
461+
462+
def test_index_col_false_and_header_none(python_parser_only):
463+
# GH#46955
464+
parser = python_parser_only
465+
data = """
466+
0.5,0.03
467+
0.1,0.2,0.3,2
468+
"""
469+
result = parser.read_csv(StringIO(data), sep=",", header=None, index_col=False)
470+
expected = DataFrame({0: [0.5, 0.1], 1: [0.03, 0.2]})
471+
tm.assert_frame_equal(result, expected)

0 commit comments

Comments
 (0)