@@ -1339,8 +1339,8 @@ def test_compact_ints_use_unsigned(self):
1339
1339
'b' : np .array ([9 ], dtype = np .int64 ),
1340
1340
'c' : np .array ([258 ], dtype = np .int64 ),
1341
1341
})
1342
- out = self .read_csv (StringIO (data ))
1343
- tm .assert_frame_equal (out , expected )
1342
+ result = self .read_csv (StringIO (data ))
1343
+ tm .assert_frame_equal (result , expected )
1344
1344
1345
1345
expected = DataFrame ({
1346
1346
'a' : np .array ([1 ], dtype = np .int8 ),
@@ -1351,14 +1351,14 @@ def test_compact_ints_use_unsigned(self):
1351
1351
# default behaviour for 'use_unsigned'
1352
1352
with tm .assert_produces_warning (
1353
1353
FutureWarning , check_stacklevel = False ):
1354
- out = self .read_csv (StringIO (data ), compact_ints = True )
1355
- tm .assert_frame_equal (out , expected )
1354
+ result = self .read_csv (StringIO (data ), compact_ints = True )
1355
+ tm .assert_frame_equal (result , expected )
1356
1356
1357
1357
with tm .assert_produces_warning (
1358
1358
FutureWarning , check_stacklevel = False ):
1359
- out = self .read_csv (StringIO (data ), compact_ints = True ,
1359
+ result = self .read_csv (StringIO (data ), compact_ints = True ,
1360
1360
use_unsigned = False )
1361
- tm .assert_frame_equal (out , expected )
1361
+ tm .assert_frame_equal (result , expected )
1362
1362
1363
1363
expected = DataFrame ({
1364
1364
'a' : np .array ([1 ], dtype = np .uint8 ),
@@ -1368,9 +1368,9 @@ def test_compact_ints_use_unsigned(self):
1368
1368
1369
1369
with tm .assert_produces_warning (
1370
1370
FutureWarning , check_stacklevel = False ):
1371
- out = self .read_csv (StringIO (data ), compact_ints = True ,
1371
+ result = self .read_csv (StringIO (data ), compact_ints = True ,
1372
1372
use_unsigned = True )
1373
- tm .assert_frame_equal (out , expected )
1373
+ tm .assert_frame_equal (result , expected )
1374
1374
1375
1375
def test_compact_ints_as_recarray (self ):
1376
1376
data = ('0,1,0,0\n '
@@ -1399,27 +1399,27 @@ def test_as_recarray(self):
1399
1399
data = 'a,b\n 1,a\n 2,b'
1400
1400
expected = np .array ([(1 , 'a' ), (2 , 'b' )],
1401
1401
dtype = [('a' , '<i8' ), ('b' , 'O' )])
1402
- out = self .read_csv (StringIO (data ), as_recarray = True )
1403
- tm .assert_numpy_array_equal (out , expected )
1402
+ result = self .read_csv (StringIO (data ), as_recarray = True )
1403
+ tm .assert_numpy_array_equal (result , expected )
1404
1404
1405
1405
# index_col ignored
1406
1406
with tm .assert_produces_warning (
1407
1407
FutureWarning , check_stacklevel = False ):
1408
1408
data = 'a,b\n 1,a\n 2,b'
1409
1409
expected = np .array ([(1 , 'a' ), (2 , 'b' )],
1410
1410
dtype = [('a' , '<i8' ), ('b' , 'O' )])
1411
- out = self .read_csv (StringIO (data ), as_recarray = True , index_col = 0 )
1412
- tm .assert_numpy_array_equal (out , expected )
1411
+ result = self .read_csv (StringIO (data ), as_recarray = True , index_col = 0 )
1412
+ tm .assert_numpy_array_equal (result , expected )
1413
1413
1414
1414
# respects names
1415
1415
with tm .assert_produces_warning (
1416
1416
FutureWarning , check_stacklevel = False ):
1417
1417
data = '1,a\n 2,b'
1418
1418
expected = np .array ([(1 , 'a' ), (2 , 'b' )],
1419
1419
dtype = [('a' , '<i8' ), ('b' , 'O' )])
1420
- out = self .read_csv (StringIO (data ), names = ['a' , 'b' ],
1420
+ result = self .read_csv (StringIO (data ), names = ['a' , 'b' ],
1421
1421
header = None , as_recarray = True )
1422
- tm .assert_numpy_array_equal (out , expected )
1422
+ tm .assert_numpy_array_equal (result , expected )
1423
1423
1424
1424
# header order is respected even though it conflicts
1425
1425
# with the natural ordering of the column names
@@ -1428,16 +1428,16 @@ def test_as_recarray(self):
1428
1428
data = 'b,a\n 1,a\n 2,b'
1429
1429
expected = np .array ([(1 , 'a' ), (2 , 'b' )],
1430
1430
dtype = [('b' , '<i8' ), ('a' , 'O' )])
1431
- out = self .read_csv (StringIO (data ), as_recarray = True )
1432
- tm .assert_numpy_array_equal (out , expected )
1431
+ result = self .read_csv (StringIO (data ), as_recarray = True )
1432
+ tm .assert_numpy_array_equal (result , expected )
1433
1433
1434
1434
# overrides the squeeze parameter
1435
1435
with tm .assert_produces_warning (
1436
1436
FutureWarning , check_stacklevel = False ):
1437
1437
data = 'a\n 1'
1438
1438
expected = np .array ([(1 ,)], dtype = [('a' , '<i8' )])
1439
- out = self .read_csv (StringIO (data ), as_recarray = True , squeeze = True )
1440
- tm .assert_numpy_array_equal (out , expected )
1439
+ result = self .read_csv (StringIO (data ), as_recarray = True , squeeze = True )
1440
+ tm .assert_numpy_array_equal (result , expected )
1441
1441
1442
1442
# does data conversions before doing recarray conversion
1443
1443
with tm .assert_produces_warning (
@@ -1446,18 +1446,18 @@ def test_as_recarray(self):
1446
1446
conv = lambda x : int (x ) + 1
1447
1447
expected = np .array ([(2 , 'a' ), (3 , 'b' )],
1448
1448
dtype = [('a' , '<i8' ), ('b' , 'O' )])
1449
- out = self .read_csv (StringIO (data ), as_recarray = True ,
1449
+ result = self .read_csv (StringIO (data ), as_recarray = True ,
1450
1450
converters = {'a' : conv })
1451
- tm .assert_numpy_array_equal (out , expected )
1451
+ tm .assert_numpy_array_equal (result , expected )
1452
1452
1453
1453
# filters by usecols before doing recarray conversion
1454
1454
with tm .assert_produces_warning (
1455
1455
FutureWarning , check_stacklevel = False ):
1456
1456
data = 'a,b\n 1,a\n 2,b'
1457
1457
expected = np .array ([(1 ,), (2 ,)], dtype = [('a' , '<i8' )])
1458
- out = self .read_csv (StringIO (data ), as_recarray = True ,
1458
+ result = self .read_csv (StringIO (data ), as_recarray = True ,
1459
1459
usecols = ['a' ])
1460
- tm .assert_numpy_array_equal (out , expected )
1460
+ tm .assert_numpy_array_equal (result , expected )
1461
1461
1462
1462
def test_memory_map (self ):
1463
1463
mmap_file = os .path .join (self .dirpath , 'test_mmap.csv' )
@@ -1467,25 +1467,23 @@ def test_memory_map(self):
1467
1467
'c' : ['I' , 'II' , 'III' ]
1468
1468
})
1469
1469
1470
- out = self .read_csv (mmap_file , memory_map = True )
1471
- tm .assert_frame_equal (out , expected )
1470
+ result = self .read_csv (mmap_file , memory_map = True )
1471
+ tm .assert_frame_equal (result , expected )
1472
1472
1473
1473
def test_read_csv_utf_aliases (self ):
1474
1474
# see gh issue 13549
1475
1475
path = 'test.csv'
1476
1476
expected = DataFrame ({'A' : [0 , 1 ], 'B' : [2 , 3 ],
1477
1477
'multibyte_test' : ['testing123' , 'bananabis' ],
1478
1478
'mb_nums' : [154.868 , 457.8798 ]})
1479
-
1480
- for byte in [8 , 16 ]:
1481
- expected .to_csv (path , encoding = 'utf-' + str (byte ), index = False )
1482
- for fmt in ['utf-{0}' , 'utf_{0}' , 'UTF-{0}' , 'UTF_{0}' ]:
1483
- encoding = fmt .format (byte )
1484
- for engine in ['c' , 'python' , None ]:
1485
- out = self .read_csv (
1486
- path ,
1487
- engine = engine ,
1488
- encoding = encoding )
1489
- tm .assert_frame_equal (out , expected )
1490
-
1491
- os .remove ("test.csv" )
1479
+ with tm .ensure_clean (path ) as path :
1480
+ for byte in [8 , 16 ]:
1481
+ expected .to_csv (path , encoding = 'utf-' + str (byte ), index = False )
1482
+ for fmt in ['utf-{0}' , 'utf_{0}' , 'UTF-{0}' , 'UTF_{0}' ]:
1483
+ encoding = fmt .format (byte )
1484
+ for engine in ['c' , 'python' , None ]:
1485
+ result = self .read_csv (
1486
+ path ,
1487
+ engine = engine ,
1488
+ encoding = encoding )
1489
+ tm .assert_frame_equal (result , expected )
0 commit comments