@@ -204,22 +204,20 @@ def test_readjson_chunks_from_file(request, engine, temp_file):
204204 )
205205 request .applymarker (pytest .mark .xfail (reason = reason , raises = ValueError ))
206206
207- path = str (temp_file )
208207 df = DataFrame ({"A" : [1 , 2 , 3 ], "B" : [4 , 5 , 6 ]})
209- df .to_json (path , lines = True , orient = "records" )
210- with read_json (path , lines = True , chunksize = 1 , engine = engine ) as reader :
208+ df .to_json (temp_file , lines = True , orient = "records" )
209+ with read_json (temp_file , lines = True , chunksize = 1 , engine = engine ) as reader :
211210 chunked = pd .concat (reader )
212- unchunked = read_json (path , lines = True , engine = engine )
211+ unchunked = read_json (temp_file , lines = True , engine = engine )
213212 tm .assert_frame_equal (unchunked , chunked )
214213
215214
216215@pytest .mark .parametrize ("chunksize" , [None , 1 ])
217216def test_readjson_chunks_closes (chunksize , temp_file ):
218- path = str (temp_file )
219217 df = DataFrame ({"A" : [1 , 2 , 3 ], "B" : [4 , 5 , 6 ]})
220- df .to_json (path , lines = True , orient = "records" )
218+ df .to_json (temp_file , lines = True , orient = "records" )
221219 reader = JsonReader (
222- path ,
220+ temp_file ,
223221 orient = None ,
224222 typ = "frame" ,
225223 dtype = True ,
@@ -287,12 +285,11 @@ def test_readjson_unicode(request, monkeypatch, engine, temp_file):
287285 )
288286 request .applymarker (pytest .mark .xfail (reason = reason , raises = ValueError ))
289287
290- path = str (temp_file )
291288 monkeypatch .setattr ("locale.getpreferredencoding" , lambda do_setlocale : "cp949" )
292- with open (path , "w" , encoding = "utf-8" ) as f :
289+ with open (temp_file , "w" , encoding = "utf-8" ) as f :
293290 f .write ('{"£©µÀÆÖÞßéöÿ":["АБВГДабвгд가"]}' )
294291
295- result = read_json (path , engine = engine )
292+ result = read_json (temp_file , engine = engine )
296293 expected = DataFrame ({"£©µÀÆÖÞßéöÿ" : ["АБВГДабвгд가" ]})
297294 tm .assert_frame_equal (result , expected )
298295
@@ -449,13 +446,12 @@ def test_to_json_append_output_consistent_columns(temp_file):
449446 df2 = DataFrame ({"col1" : [3 , 4 ], "col2" : ["c" , "d" ]})
450447
451448 expected = DataFrame ({"col1" : [1 , 2 , 3 , 4 ], "col2" : ["a" , "b" , "c" , "d" ]})
452- path = str (temp_file )
453449 # Save dataframes to the same file
454- df1 .to_json (path , lines = True , orient = "records" )
455- df2 .to_json (path , mode = "a" , lines = True , orient = "records" )
450+ df1 .to_json (temp_file , lines = True , orient = "records" )
451+ df2 .to_json (temp_file , mode = "a" , lines = True , orient = "records" )
456452
457453 # Read path file
458- result = read_json (path , lines = True )
454+ result = read_json (temp_file , lines = True )
459455 tm .assert_frame_equal (result , expected )
460456
461457
@@ -473,13 +469,12 @@ def test_to_json_append_output_inconsistent_columns(temp_file):
473469 "col3" : [np .nan , np .nan , "!" , "#" ],
474470 }
475471 )
476- path = str (temp_file )
477472 # Save dataframes to the same file
478- df1 .to_json (path , mode = "a" , lines = True , orient = "records" )
479- df3 .to_json (path , mode = "a" , lines = True , orient = "records" )
473+ df1 .to_json (temp_file , mode = "a" , lines = True , orient = "records" )
474+ df3 .to_json (temp_file , mode = "a" , lines = True , orient = "records" )
480475
481476 # Read path file
482- result = read_json (path , lines = True )
477+ result = read_json (temp_file , lines = True )
483478 tm .assert_frame_equal (result , expected )
484479
485480
@@ -500,15 +495,14 @@ def test_to_json_append_output_different_columns(temp_file):
500495 "col4" : [None , None , None , None , None , None , True , False ],
501496 }
502497 ).astype ({"col4" : "float" })
503- path = str (temp_file )
504498 # Save dataframes to the same file
505- df1 .to_json (path , mode = "a" , lines = True , orient = "records" )
506- df2 .to_json (path , mode = "a" , lines = True , orient = "records" )
507- df3 .to_json (path , mode = "a" , lines = True , orient = "records" )
508- df4 .to_json (path , mode = "a" , lines = True , orient = "records" )
499+ df1 .to_json (temp_file , mode = "a" , lines = True , orient = "records" )
500+ df2 .to_json (temp_file , mode = "a" , lines = True , orient = "records" )
501+ df3 .to_json (temp_file , mode = "a" , lines = True , orient = "records" )
502+ df4 .to_json (temp_file , mode = "a" , lines = True , orient = "records" )
509503
510504 # Read path file
511- result = read_json (path , lines = True )
505+ result = read_json (temp_file , lines = True )
512506 tm .assert_frame_equal (result , expected )
513507
514508
@@ -530,13 +524,12 @@ def test_to_json_append_output_different_columns_reordered(temp_file):
530524 "col1" : [None , None , None , None , 3 , 4 , 1 , 2 ],
531525 }
532526 ).astype ({"col4" : "float" })
533- path = str (temp_file )
534527 # Save dataframes to the same file
535- df4 .to_json (path , mode = "a" , lines = True , orient = "records" )
536- df3 .to_json (path , mode = "a" , lines = True , orient = "records" )
537- df2 .to_json (path , mode = "a" , lines = True , orient = "records" )
538- df1 .to_json (path , mode = "a" , lines = True , orient = "records" )
528+ df4 .to_json (temp_file , mode = "a" , lines = True , orient = "records" )
529+ df3 .to_json (temp_file , mode = "a" , lines = True , orient = "records" )
530+ df2 .to_json (temp_file , mode = "a" , lines = True , orient = "records" )
531+ df1 .to_json (temp_file , mode = "a" , lines = True , orient = "records" )
539532
540533 # Read path file
541- result = read_json (path , lines = True )
534+ result = read_json (temp_file , lines = True )
542535 tm .assert_frame_equal (result , expected )
0 commit comments