@@ -339,6 +339,7 @@ def test_multiindex_interval_datetimes(self, tmp_excel):
339
339
],
340
340
]
341
341
),
342
+ columns = Index ([0 ]),
342
343
)
343
344
tm .assert_frame_equal (result , expected )
344
345
@@ -384,7 +385,10 @@ def test_excel_sheet_size(self, tmp_excel):
384
385
col_df .to_excel (tmp_excel )
385
386
386
387
def test_excel_sheet_by_name_raise (self , tmp_excel ):
387
- gt = DataFrame (np .random .default_rng (2 ).standard_normal ((10 , 2 )))
388
+ gt = DataFrame (
389
+ np .random .default_rng (2 ).standard_normal ((10 , 2 )),
390
+ index = Index (list (range (10 ))),
391
+ )
388
392
gt .to_excel (tmp_excel )
389
393
390
394
with ExcelFile (tmp_excel ) as xl :
@@ -505,7 +509,9 @@ def test_int_types(self, np_type, tmp_excel):
505
509
# Test np.int values read come back as int
506
510
# (rather than float which is Excel's format).
507
511
df = DataFrame (
508
- np .random .default_rng (2 ).integers (- 10 , 10 , size = (10 , 2 )), dtype = np_type
512
+ np .random .default_rng (2 ).integers (- 10 , 10 , size = (10 , 2 )),
513
+ dtype = np_type ,
514
+ index = Index (list (range (10 ))),
509
515
)
510
516
df .to_excel (tmp_excel , sheet_name = "test1" )
511
517
@@ -521,7 +527,11 @@ def test_int_types(self, np_type, tmp_excel):
521
527
@pytest .mark .parametrize ("np_type" , [np .float16 , np .float32 , np .float64 ])
522
528
def test_float_types (self , np_type , tmp_excel ):
523
529
# Test np.float values read come back as float.
524
- df = DataFrame (np .random .default_rng (2 ).random (10 ), dtype = np_type )
530
+ df = DataFrame (
531
+ np .random .default_rng (2 ).random (10 ),
532
+ dtype = np_type ,
533
+ index = Index (list (range (10 ))),
534
+ )
525
535
df .to_excel (tmp_excel , sheet_name = "test1" )
526
536
527
537
with ExcelFile (tmp_excel ) as reader :
@@ -533,7 +543,7 @@ def test_float_types(self, np_type, tmp_excel):
533
543
534
544
def test_bool_types (self , tmp_excel ):
535
545
# Test np.bool_ values read come back as float.
536
- df = DataFrame ([1 , 0 , True , False ], dtype = np .bool_ )
546
+ df = DataFrame ([1 , 0 , True , False ], dtype = np .bool_ , index = Index ( list ( range ( 4 ))) )
537
547
df .to_excel (tmp_excel , sheet_name = "test1" )
538
548
539
549
with ExcelFile (tmp_excel ) as reader :
@@ -544,7 +554,7 @@ def test_bool_types(self, tmp_excel):
544
554
tm .assert_frame_equal (df , recons )
545
555
546
556
def test_inf_roundtrip (self , tmp_excel ):
547
- df = DataFrame ([(1 , np .inf ), (2 , 3 ), (5 , - np .inf )])
557
+ df = DataFrame ([(1 , np .inf ), (2 , 3 ), (5 , - np .inf )], index = Index ( list ( range ( 3 ))) )
548
558
df .to_excel (tmp_excel , sheet_name = "test1" )
549
559
550
560
with ExcelFile (tmp_excel ) as reader :
@@ -640,7 +650,13 @@ def test_roundtrip_indexlabels(self, merge_cells, frame, tmp_excel):
640
650
df .index .names = ["test" ]
641
651
assert df .index .names == recons .index .names
642
652
643
- df = DataFrame (np .random .default_rng (2 ).standard_normal ((10 , 2 ))) >= 0
653
+ df = (
654
+ DataFrame (
655
+ np .random .default_rng (2 ).standard_normal ((10 , 2 )),
656
+ index = Index (list (range (10 ))),
657
+ )
658
+ >= 0
659
+ )
644
660
df .to_excel (
645
661
tmp_excel , sheet_name = "test1" , index_label = "test" , merge_cells = merge_cells
646
662
)
0 commit comments