From 670b24b32707029d1123b9c82ae43ff50e5cd9d1 Mon Sep 17 00:00:00 2001 From: Matthew Zeitlin Date: Mon, 21 Jun 2021 15:08:02 -0400 Subject: [PATCH 1/2] TST/CI: speed up chunksize test --- pandas/tests/io/parser/common/test_chunksize.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pandas/tests/io/parser/common/test_chunksize.py b/pandas/tests/io/parser/common/test_chunksize.py index 5b7df02603b74..c6d1525681d4a 100644 --- a/pandas/tests/io/parser/common/test_chunksize.py +++ b/pandas/tests/io/parser/common/test_chunksize.py @@ -177,13 +177,16 @@ def test_chunks_have_consistent_numerical_type(all_parsers): def test_warn_if_chunks_have_mismatched_type(all_parsers, request): warning_type = None parser = all_parsers - integers = [str(i) for i in range(499999)] - data = "a\n" + "\n".join(integers + ["a", "b"] + integers) + size = 10000 # see gh-3866: if chunks are different types and can't # be coerced using numerical types, then issue warning. if parser.engine == "c" and parser.low_memory: warning_type = DtypeWarning + size = 499999 + + integers = [str(i) for i in range(size)] + data = "a\n" + "\n".join(integers + ["a", "b"] + integers) buf = StringIO(data) From 95913b7b9a61d09a83d98308be6bcb8fd9754299 Mon Sep 17 00:00:00 2001 From: Matthew Zeitlin Date: Mon, 21 Jun 2021 15:12:40 -0400 Subject: [PATCH 2/2] Remove resource warning handling --- .../tests/io/parser/common/test_chunksize.py | 21 +++---------------- 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/pandas/tests/io/parser/common/test_chunksize.py b/pandas/tests/io/parser/common/test_chunksize.py index c6d1525681d4a..e78448a2c32d3 100644 --- a/pandas/tests/io/parser/common/test_chunksize.py +++ b/pandas/tests/io/parser/common/test_chunksize.py @@ -183,6 +183,7 @@ def test_warn_if_chunks_have_mismatched_type(all_parsers, request): # be coerced using numerical types, then issue warning. if parser.engine == "c" and parser.low_memory: warning_type = DtypeWarning + # Use larger size to hit warning path size = 499999 integers = [str(i) for i in range(size)] @@ -190,24 +191,8 @@ def test_warn_if_chunks_have_mismatched_type(all_parsers, request): buf = StringIO(data) - try: - with tm.assert_produces_warning(warning_type): - df = parser.read_csv(buf) - 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, - # see GH#38630 - if "ResourceWarning" not in str(err) or parser.engine != "python": - raise - - # Check the main assertion of the test before re-raising - assert df.a.dtype == object - - mark = pytest.mark.xfail( - reason="ResourceWarning for unclosed SSL Socket, GH#38630" - ) - request.node.add_marker(mark) - raise + with tm.assert_produces_warning(warning_type): + df = parser.read_csv(buf) assert df.a.dtype == object