@@ -229,17 +229,21 @@ def test_chunks_have_consistent_numerical_type(all_parsers, monkeypatch):
229229 assert result .a .dtype == float
230230
231231
232- def test_warn_if_chunks_have_mismatched_type (all_parsers , using_infer_string ):
232+ def test_warn_if_chunks_have_mismatched_type (
233+ all_parsers , using_infer_string , monkeypatch
234+ ):
233235 warning_type = None
234236 parser = all_parsers
235- size = 10000
237+ heuristic = 2 ** 3
238+ size = 10
236239
237240 # see gh-3866: if chunks are different types and can't
238241 # be coerced using numerical types, then issue warning.
239242 if parser .engine == "c" and parser .low_memory :
240243 warning_type = DtypeWarning
241- # Use larger size to hit warning path
242- size = 499999
244+ # Use a size to hit warning path dictated by DEFAULT_BUFFER_HEURISTIC
245+ # monkeypatched below
246+ size = heuristic - 1
243247
244248 integers = [str (i ) for i in range (size )]
245249 data = "a\n " + "\n " .join (integers + ["a" , "b" ] + integers )
@@ -251,12 +255,14 @@ def test_warn_if_chunks_have_mismatched_type(all_parsers, using_infer_string):
251255 buf ,
252256 )
253257 else :
254- df = parser .read_csv_check_warnings (
255- warning_type ,
256- r"Columns \(0: a\) have mixed types. "
257- "Specify dtype option on import or set low_memory=False." ,
258- buf ,
259- )
258+ with monkeypatch .context () as m :
259+ m .setattr (libparsers , "DEFAULT_BUFFER_HEURISTIC" , heuristic )
260+ df = parser .read_csv_check_warnings (
261+ warning_type ,
262+ r"Columns \(0: a\) have mixed types. "
263+ "Specify dtype option on import or set low_memory=False." ,
264+ buf ,
265+ )
260266 if parser .engine == "c" and parser .low_memory :
261267 assert df .a .dtype == object
262268 elif using_infer_string :
@@ -295,30 +301,6 @@ def test_empty_with_nrows_chunksize(all_parsers, iterator):
295301 tm .assert_frame_equal (result , expected )
296302
297303
298- def test_read_csv_memory_growth_chunksize (temp_file , all_parsers ):
299- # see gh-24805
300- #
301- # Let's just make sure that we don't crash
302- # as we iteratively process all chunks.
303- parser = all_parsers
304-
305- with open (temp_file , "w" , encoding = "utf-8" ) as f :
306- for i in range (1000 ):
307- f .write (str (i ) + "\n " )
308-
309- if parser .engine == "pyarrow" :
310- msg = "The 'chunksize' option is not supported with the 'pyarrow' engine"
311- with pytest .raises (ValueError , match = msg ):
312- with parser .read_csv (temp_file , chunksize = 20 ) as result :
313- for _ in result :
314- pass
315- return
316-
317- with parser .read_csv (temp_file , chunksize = 20 ) as result :
318- for _ in result :
319- pass
320-
321-
322304def test_chunksize_with_usecols_second_block_shorter (all_parsers ):
323305 # GH#21211
324306 parser = all_parsers
0 commit comments