@@ -304,7 +304,10 @@ def test_to_json_append_orient(orient_):
304
304
# GH 35849
305
305
# Test ValueError when orient is not 'records'
306
306
df = DataFrame ({"col1" : [1 , 2 ], "col2" : ["a" , "b" ]})
307
- msg = r"mode='a' \(append\) is only supported when lines is True and orient is 'records'"
307
+ msg = (
308
+ r"mode='a' \(append\) is only supported when"
309
+ "lines is True and orient is 'records'"
310
+ )
308
311
with pytest .raises (ValueError , match = msg ):
309
312
df .to_json (mode = "a" , orient = orient_ )
310
313
@@ -313,17 +316,23 @@ def test_to_json_append_lines():
313
316
# GH 35849
314
317
# Test ValueError when lines is not True
315
318
df = DataFrame ({"col1" : [1 , 2 ], "col2" : ["a" , "b" ]})
316
- msg = r"mode='a' \(append\) is only supported when lines is True and orient is 'records'"
319
+ msg = (
320
+ r"mode='a' \(append\) is only supported when"
321
+ "lines is True and orient is 'records'"
322
+ )
317
323
with pytest .raises (ValueError , match = msg ):
318
324
df .to_json (mode = "a" , lines = False , orient = "records" )
319
325
320
326
321
- @pytest .mark .parametrize ("mode_" , ['r' , 'x' ])
322
- def test_to_json_append_lines (mode_ ):
327
+ @pytest .mark .parametrize ("mode_" , ["r" , "x" ])
328
+ def test_to_json_append_mode (mode_ ):
323
329
# GH 35849
324
330
# Test ValueError when mode is not supported option
325
331
df = DataFrame ({"col1" : [1 , 2 ], "col2" : ["a" , "b" ]})
326
- msg = f"mode={ mode_ !r} is not a valid option. Only 'w' and 'a' are currently supported."
332
+ msg = (
333
+ f"mode={ repr (mode_ )} is not a valid option."
334
+ "Only 'w' and 'a' are currently supported."
335
+ )
327
336
with pytest .raises (ValueError , match = msg ):
328
337
df .to_json (mode = mode_ , lines = False , orient = "records" )
329
338
@@ -344,10 +353,8 @@ def to_json_append_output():
344
353
df2 .to_json (path , mode = "a" , lines = True , orient = "records" )
345
354
346
355
# Read path file
347
- result_df = read_json (path , lines = True )
356
+ result = read_json (path , lines = True )
348
357
tm .assert_frame_equal (result , expected )
349
- del expected
350
- del result_df
351
358
352
359
# Test 2: df1, df2, df3, df4 (in that order)
353
360
expected = DataFrame (
@@ -366,18 +373,16 @@ def to_json_append_output():
366
373
df4 .to_json (path , mode = "a" , lines = True , orient = "records" )
367
374
368
375
# Read path file
369
- result_df = read_json (path , lines = True )
376
+ result = read_json (path , lines = True )
370
377
tm .assert_frame_equal (result , expected )
371
- del expected
372
- del result_df
373
378
374
379
# Test 3: df4, df3, df2, df1 (in that order)
375
380
expected = DataFrame (
376
381
{
377
382
"col4" : [True , False , None , None , None , None , None , None ],
378
383
"col2" : [None , None , "e" , "f" , "c" , "d" , "a" , "b" ],
379
384
"col3" : [None , None , "!" , "#" , None , None , None , None ],
380
- "col4 " : [None , None , None , None , 3 , 4 , 1 , 2 ],
385
+ "col1 " : [None , None , None , None , 3 , 4 , 1 , 2 ],
381
386
}
382
387
)
383
388
with tm .ensure_clean ("test.json" ) as path :
@@ -388,7 +393,5 @@ def to_json_append_output():
388
393
df1 .to_json (path , mode = "a" , lines = True , orient = "records" )
389
394
390
395
# Read path file
391
- result_df = read_json (path , lines = True )
396
+ result = read_json (path , lines = True )
392
397
tm .assert_frame_equal (result , expected )
393
- del expected
394
- del result_df
0 commit comments