Skip to content

ERR: Fix missing space in warning message #39159

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pandas/_libs/parsers.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1924,7 +1924,7 @@ def _concatenate_chunks(list chunks):
if warning_columns:
warning_names = ','.join(warning_columns)
warning_message = " ".join([
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does removing the join here work instead and just use fstring literal concatenation

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't see why that wouldn't work. Technically, the join wasn't even being used anyways, because the strings were getting concatenated inside of the list, so yeah, "officially" removing the join and manually adding the space between the strings sounds perfectly fine I think.
I'll poke around to see how other similar warnings are created, though, because keeping it consistent between them might be a valid reason as to whether or not to have the join.

f"Columns ({warning_names}) have mixed types."
f"Columns ({warning_names}) have mixed types.",
f"Specify dtype option on import or set low_memory=False."
])
warnings.warn(warning_message, DtypeWarning, stacklevel=8)
Expand Down
7 changes: 6 additions & 1 deletion pandas/tests/io/parser/common/test_chunksize.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import numpy as np
import pytest
import regex as re

from pandas.errors import DtypeWarning

Expand Down Expand Up @@ -190,7 +191,11 @@ def test_warn_if_chunks_have_mismatched_type(all_parsers, request):
buf = StringIO(data)

try:
with tm.assert_produces_warning(warning_type):
msg = (
"Columns (0) have mixed types. Specify dtype option on import or "
"set low_memory=False."
)
with tm.assert_produces_warning(warning_type, match=re.escape(msg)):
df = parser.read_csv(buf)
except AssertionError as err:
# 2021-02-21 this occasionally fails on the CI with an unexpected
Expand Down