@@ -221,7 +221,6 @@ def test_excel_table_sheet_by_index(self):
221
221
(self .xlsx1 , self .csv1 )]:
222
222
self .check_excel_table_sheet_by_index (filename , csvfile )
223
223
224
-
225
224
def test_excel_table (self ):
226
225
_skip_if_no_xlrd ()
227
226
@@ -405,7 +404,6 @@ def test_mixed(self):
405
404
recons = reader .parse ('test1' , index_col = 0 )
406
405
tm .assert_frame_equal (self .mixed_frame , recons )
407
406
408
-
409
407
def test_tsframe (self ):
410
408
_skip_if_no_xlrd ()
411
409
ext = self .ext
@@ -419,45 +417,70 @@ def test_tsframe(self):
419
417
recons = reader .parse ('test1' )
420
418
tm .assert_frame_equal (df , recons )
421
419
422
- def test_int64 (self ):
420
+ def test_int_types (self ):
423
421
_skip_if_no_xlrd ()
424
422
ext = self .ext
425
- path = '__tmp_to_excel_from_excel_int64__.' + ext
426
-
427
- with ensure_clean (path ) as path :
428
- self .frame ['A' ][:5 ] = nan
429
-
430
- self .frame .to_excel (path , 'test1' )
431
- self .frame .to_excel (path , 'test1' , cols = ['A' , 'B' ])
432
- self .frame .to_excel (path , 'test1' , header = False )
433
- self .frame .to_excel (path , 'test1' , index = False )
423
+ path = '__tmp_to_excel_from_excel_int_types__.' + ext
434
424
435
- # Test np.int64, values read come back as float
436
- frame = DataFrame (np .random .randint (- 10 , 10 , size = (10 , 2 )), dtype = np .int64 )
437
- frame .to_excel (path , 'test1' )
438
- reader = ExcelFile (path )
439
- recons = reader .parse ('test1' ).astype (np .int64 )
440
- tm .assert_frame_equal (frame , recons , check_dtype = False )
425
+ for np_type in (np .int8 , np .int16 , np .int32 , np .int64 ):
441
426
442
- def test_bool (self ):
427
+ with ensure_clean (path ) as path :
428
+ self .frame ['A' ][:5 ] = nan
429
+
430
+ self .frame .to_excel (path , 'test1' )
431
+ self .frame .to_excel (path , 'test1' , cols = ['A' , 'B' ])
432
+ self .frame .to_excel (path , 'test1' , header = False )
433
+ self .frame .to_excel (path , 'test1' , index = False )
434
+
435
+ # Test np.int values read come back as float.
436
+ frame = DataFrame (np .random .randint (- 10 , 10 , size = (10 , 2 )),
437
+ dtype = np_type )
438
+ frame .to_excel (path , 'test1' )
439
+ reader = ExcelFile (path )
440
+ recons = reader .parse ('test1' ).astype (np_type )
441
+ tm .assert_frame_equal (frame , recons , check_dtype = False )
442
+
443
+ def test_float_types (self ):
443
444
_skip_if_no_xlrd ()
444
445
ext = self .ext
445
- path = '__tmp_to_excel_from_excel_bool__ .' + ext
446
+ path = '__tmp_to_excel_from_excel_float_types__ .' + ext
446
447
447
- with ensure_clean (path ) as path :
448
- self .frame ['A' ][:5 ] = nan
448
+ for np_type in (np .float16 , np .float32 , np .float64 ):
449
+ with ensure_clean (path ) as path :
450
+ self .frame ['A' ][:5 ] = nan
449
451
450
- self .frame .to_excel (path , 'test1' )
451
- self .frame .to_excel (path , 'test1' , cols = ['A' , 'B' ])
452
- self .frame .to_excel (path , 'test1' , header = False )
453
- self .frame .to_excel (path , 'test1' , index = False )
452
+ self .frame .to_excel (path , 'test1' )
453
+ self .frame .to_excel (path , 'test1' , cols = ['A' , 'B' ])
454
+ self .frame .to_excel (path , 'test1' , header = False )
455
+ self .frame .to_excel (path , 'test1' , index = False )
454
456
455
- # Test reading/writing np.bool8, roundtrip only works for xlsx
456
- frame = (DataFrame (np .random .randn (10 , 2 )) >= 0 )
457
- frame .to_excel (path , 'test1' )
458
- reader = ExcelFile (path )
459
- recons = reader .parse ('test1' ).astype (np .bool8 )
460
- tm .assert_frame_equal (frame , recons )
457
+ # Test np.float values read come back as float.
458
+ frame = DataFrame (np .random .random_sample (10 ), dtype = np_type )
459
+ frame .to_excel (path , 'test1' )
460
+ reader = ExcelFile (path )
461
+ recons = reader .parse ('test1' ).astype (np_type )
462
+ tm .assert_frame_equal (frame , recons , check_dtype = False )
463
+
464
+ def test_bool_types (self ):
465
+ _skip_if_no_xlrd ()
466
+ ext = self .ext
467
+ path = '__tmp_to_excel_from_excel_bool_types__.' + ext
468
+
469
+ for np_type in (np .bool8 , np .bool_ ):
470
+ with ensure_clean (path ) as path :
471
+ self .frame ['A' ][:5 ] = nan
472
+
473
+ self .frame .to_excel (path , 'test1' )
474
+ self .frame .to_excel (path , 'test1' , cols = ['A' , 'B' ])
475
+ self .frame .to_excel (path , 'test1' , header = False )
476
+ self .frame .to_excel (path , 'test1' , index = False )
477
+
478
+ # Test np.bool values read come back as float.
479
+ frame = (DataFrame ([1 , 0 , True , False ], dtype = np_type ))
480
+ frame .to_excel (path , 'test1' )
481
+ reader = ExcelFile (path )
482
+ recons = reader .parse ('test1' ).astype (np_type )
483
+ tm .assert_frame_equal (frame , recons )
461
484
462
485
def test_sheets (self ):
463
486
_skip_if_no_xlrd ()
0 commit comments