Skip to content

Commit 75ad64b

Browse files
committed
mend
1 parent f43b3e2 commit 75ad64b

File tree

3 files changed

+5
-11
lines changed

3 files changed

+5
-11
lines changed

doc/source/whatsnew/v3.0.0.rst

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -814,10 +814,7 @@ I/O
814814
- Bug in :meth:`set_option` where setting the pandas option ``display.html.use_mathjax`` to ``False`` has no effect (:issue:`59884`)
815815
- Bug in :meth:`to_csv` where ``quotechar``` is not escaped when ``escapechar`` is not None (:issue:`61407`)
816816
- Bug in :meth:`to_excel` where :class:`MultiIndex` columns would be merged to a single row when ``merge_cells=False`` is passed (:issue:`60274`)
817-
- Bug in :func:`read_csv` with ``engine="python"`` and callable ``on_bad_lines``
818-
where a ``ParserWarning`` for extra fields returned by the callable was only
819-
raised when ``index_col`` was ``None``. Now the warning is consistently raised
820-
regardless of ``index_col`` (:issue:`#61837`)
817+
- Bug in :func:`read_csv` with ``engine="python"`` and callable ``on_bad_lines`` where a ``ParserWarning`` for extra fields returned by the callable was only raised when ``index_col`` was ``None``. Now the warning is consistently raised regardless of ``index_col`` (:issue:`#61837`)
821818

822819
Period
823820
^^^^^^

pandas/io/parsers/base_parser.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -614,11 +614,7 @@ def _check_data_length(
614614
columns: list of column names
615615
data: list of array-likes containing the data column-wise.
616616
"""
617-
if not self.index_col and len(columns) != len(data) and columns:
618-
# error: No overload variant of "__ror__" of "ndarray" matches
619-
# argument type "ExtensionArray"
620-
if len(data) > len(columns) :
621-
return
617+
if columns and len(data)!=len(columns):
622618
warnings.warn(
623619
f"Length of header or names ({len(columns)}) does not match number of "
624620
f"fields in line ({len(data)}). Extra field will be dropped.",

pandas/tests/io/parser/test_python_parser_only.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,11 +332,12 @@ def test_on_bad_lines_extra_fields_warns(python_parser_only):
332332

333333
def line_fixer(_line):
334334
return ["1", "2", "3", "4", "5"]
335+
335336
for index_col in [None, 0]:
336337
with tm.assert_produces_warning(ParserWarning):
337338
parser.read_csv(
338-
StringIO(data), on_bad_lines=line_fixer, index_col=index_col
339-
)
339+
StringIO(data), on_bad_lines=line_fixer, index_col=index_col
340+
)
340341

341342

342343
def test_python_engine_file_no_next(python_parser_only):

0 commit comments

Comments
 (0)