From 07cdef188ebef3801ed1d38b31ab4d7c9a4974d9 Mon Sep 17 00:00:00 2001 From: Micael Jarniac Date: Wed, 13 Jan 2021 20:49:32 -0300 Subject: [PATCH 1/5] DOC: Fix missing space --- pandas/_libs/parsers.pyx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/_libs/parsers.pyx b/pandas/_libs/parsers.pyx index a72a2ff8eaf28..def40b6f29926 100644 --- a/pandas/_libs/parsers.pyx +++ b/pandas/_libs/parsers.pyx @@ -1991,7 +1991,7 @@ def _concatenate_chunks(list chunks): if warning_columns: warning_names = ','.join(warning_columns) warning_message = " ".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) From 92e96dfe8dd7d7292b343a310bb51b3ec60505c0 Mon Sep 17 00:00:00 2001 From: Micael Jarniac Date: Mon, 8 Feb 2021 17:46:50 -0300 Subject: [PATCH 2/5] TST: Check if warning message matches pytest pandas/tests/io/parser/common/test_chunksize.py::test_warn_if_chunks_have_mismatched_type --- pandas/tests/io/parser/common/test_chunksize.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pandas/tests/io/parser/common/test_chunksize.py b/pandas/tests/io/parser/common/test_chunksize.py index 8c1475025b442..db57645db21b2 100644 --- a/pandas/tests/io/parser/common/test_chunksize.py +++ b/pandas/tests/io/parser/common/test_chunksize.py @@ -181,8 +181,14 @@ def test_warn_if_chunks_have_mismatched_type(all_parsers): if parser.engine == "c" and parser.low_memory: warning_type = DtypeWarning - with tm.assert_produces_warning(warning_type): + with tm.assert_produces_warning(warning_type) as record: df = parser.read_csv(StringIO(data)) + if record: + assert ( + str(record[0].message) + == "Columns (0) have mixed types. Specify dtype option on import or " + "set low_memory=False." + ) assert df.a.dtype == object From 54c205616ec86cc0b1c15d4203c0f4b33444a7a4 Mon Sep 17 00:00:00 2001 From: Micael Jarniac Date: Mon, 15 Mar 2021 13:26:17 -0300 Subject: [PATCH 3/5] TST: Split long message --- pandas/tests/io/parser/common/test_chunksize.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/tests/io/parser/common/test_chunksize.py b/pandas/tests/io/parser/common/test_chunksize.py index db57645db21b2..17948021820fc 100644 --- a/pandas/tests/io/parser/common/test_chunksize.py +++ b/pandas/tests/io/parser/common/test_chunksize.py @@ -184,11 +184,11 @@ def test_warn_if_chunks_have_mismatched_type(all_parsers): with tm.assert_produces_warning(warning_type) as record: df = parser.read_csv(StringIO(data)) if record: - assert ( - str(record[0].message) - == "Columns (0) have mixed types. Specify dtype option on import or " + expected = ( + "Columns (0) have mixed types. Specify dtype option on import or " "set low_memory=False." ) + assert str(record[0].message) == expected assert df.a.dtype == object From 83fb0473ecfcf779adebf5a6d49c4b593f2ed506 Mon Sep 17 00:00:00 2001 From: Micael Jarniac Date: Mon, 22 Mar 2021 13:27:08 -0300 Subject: [PATCH 4/5] TST: Use `match` argument Co-authored-by: Simon Hawkins --- pandas/tests/io/parser/common/test_chunksize.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/pandas/tests/io/parser/common/test_chunksize.py b/pandas/tests/io/parser/common/test_chunksize.py index 7b9d74212b3cc..66b79ae434531 100644 --- a/pandas/tests/io/parser/common/test_chunksize.py +++ b/pandas/tests/io/parser/common/test_chunksize.py @@ -190,14 +190,12 @@ def test_warn_if_chunks_have_mismatched_type(all_parsers, request): buf = StringIO(data) try: - with tm.assert_produces_warning(warning_type) as record: + 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) - if record: - expected = ( - "Columns (0) have mixed types. Specify dtype option on import or " - "set low_memory=False." - ) - assert str(record[0].message) == expected except AssertionError as err: # 2021-02-21 this occasionally fails on the CI with an unexpected # ResourceWarning that we have been unable to track down, From a7c3f5b7f74ad87eb6f0d64d0b9b5e3a247c837c Mon Sep 17 00:00:00 2001 From: Micael Jarniac Date: Mon, 22 Mar 2021 13:48:53 -0300 Subject: [PATCH 5/5] TST: Fix missing regex import --- pandas/tests/io/parser/common/test_chunksize.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pandas/tests/io/parser/common/test_chunksize.py b/pandas/tests/io/parser/common/test_chunksize.py index 66b79ae434531..303174d9dbd1a 100644 --- a/pandas/tests/io/parser/common/test_chunksize.py +++ b/pandas/tests/io/parser/common/test_chunksize.py @@ -6,6 +6,7 @@ import numpy as np import pytest +import regex as re from pandas.errors import DtypeWarning