14
14
import numpy as np
15
15
from numpy .testing .decorators import slow
16
16
17
+ import pandas as pd
17
18
from pandas import DataFrame , Index , MultiIndex
18
19
from pandas .io .parsers import read_csv
19
20
from pandas .io .excel import (
@@ -416,7 +417,7 @@ def test_read_xlrd_Book(self):
416
417
@tm .network
417
418
def test_read_from_http_url (self ):
418
419
url = ('https://raw.github.com/pydata/pandas/master/'
419
- 'pandas/io/tests/data/test ' + self .ext )
420
+ 'pandas/io/tests/data/test1 ' + self .ext )
420
421
url_table = read_excel (url )
421
422
local_table = self .get_exceldf ('test1' )
422
423
tm .assert_frame_equal (url_table , local_table )
@@ -517,56 +518,54 @@ def test_reader_seconds(self):
517
518
518
519
def test_read_excel_multiindex (self ):
519
520
#GH 4679
520
- _skip_if_no_xlrd ()
521
521
mi = MultiIndex .from_product ([['foo' ,'bar' ],['a' ,'b' ]])
522
- for ext in ['.xls' , '.xlsx' ]:
523
- mi_file = os .path .join (self .dirpath , 'testmultiindex' + ext )
522
+ mi_file = os .path .join (self .dirpath , 'testmultiindex' + self .ext )
524
523
525
- expected = DataFrame ([[1 , 2.5 , pd .Timestamp ('2015-01-01' ), True ],
526
- [2 , 3.5 , pd .Timestamp ('2015-01-02' ), False ],
527
- [3 , 4.5 , pd .Timestamp ('2015-01-03' ), False ],
528
- [4 , 5.5 , pd .Timestamp ('2015-01-04' ), True ]],
529
- columns = mi )
524
+ expected = DataFrame ([[1 , 2.5 , pd .Timestamp ('2015-01-01' ), True ],
525
+ [2 , 3.5 , pd .Timestamp ('2015-01-02' ), False ],
526
+ [3 , 4.5 , pd .Timestamp ('2015-01-03' ), False ],
527
+ [4 , 5.5 , pd .Timestamp ('2015-01-04' ), True ]],
528
+ columns = mi )
530
529
531
- actual = read_excel (mi_file , 'mi_column' , header = [0 ,1 ])
532
- tm .assert_frame_equal (actual , expected )
533
- actual = read_excel (mi_file , 'mi_column' , header = [0 ,1 ], index_col = 0 )
534
- tm .assert_frame_equal (actual , expected )
530
+ actual = read_excel (mi_file , 'mi_column' , header = [0 ,1 ])
531
+ tm .assert_frame_equal (actual , expected )
532
+ actual = read_excel (mi_file , 'mi_column' , header = [0 ,1 ], index_col = 0 )
533
+ tm .assert_frame_equal (actual , expected )
535
534
536
- expected .columns = ['a' , 'b' , 'c' , 'd' ]
537
- expected .index = mi
538
- actual = read_excel (mi_file , 'mi_index' , index_col = [0 ,1 ])
539
- tm .assert_frame_equal (actual , expected , check_names = False )
535
+ expected .columns = ['a' , 'b' , 'c' , 'd' ]
536
+ expected .index = mi
537
+ actual = read_excel (mi_file , 'mi_index' , index_col = [0 ,1 ])
538
+ tm .assert_frame_equal (actual , expected , check_names = False )
540
539
541
- expected .columns = mi
542
- actual = read_excel (mi_file , 'both' , index_col = [0 ,1 ], header = [0 ,1 ])
543
- tm .assert_frame_equal (actual , expected , check_names = False )
540
+ expected .columns = mi
541
+ actual = read_excel (mi_file , 'both' , index_col = [0 ,1 ], header = [0 ,1 ])
542
+ tm .assert_frame_equal (actual , expected , check_names = False )
544
543
545
- expected .index = mi .set_names (['ilvl1' , 'ilvl2' ])
546
- expected .columns = ['a' , 'b' , 'c' , 'd' ]
547
- actual = read_excel (mi_file , 'mi_index_name' , index_col = [0 ,1 ])
548
- tm .assert_frame_equal (actual , expected )
544
+ expected .index = mi .set_names (['ilvl1' , 'ilvl2' ])
545
+ expected .columns = ['a' , 'b' , 'c' , 'd' ]
546
+ actual = read_excel (mi_file , 'mi_index_name' , index_col = [0 ,1 ])
547
+ tm .assert_frame_equal (actual , expected )
549
548
550
- expected .index = list (range (4 ))
551
- expected .columns = mi .set_names (['c1' , 'c2' ])
552
- actual = read_excel (mi_file , 'mi_column_name' , header = [0 ,1 ], index_col = 0 )
553
- tm .assert_frame_equal (actual , expected )
549
+ expected .index = list (range (4 ))
550
+ expected .columns = mi .set_names (['c1' , 'c2' ])
551
+ actual = read_excel (mi_file , 'mi_column_name' , header = [0 ,1 ], index_col = 0 )
552
+ tm .assert_frame_equal (actual , expected )
554
553
555
- expected .index = mi .set_names (['ilvl1' , 'ilvl2' ])
556
- actual = read_excel (mi_file , 'both_name' , index_col = [0 ,1 ], header = [0 ,1 ])
557
- tm .assert_frame_equal (actual , expected )
554
+ expected .index = mi .set_names (['ilvl1' , 'ilvl2' ])
555
+ actual = read_excel (mi_file , 'both_name' , index_col = [0 ,1 ], header = [0 ,1 ])
556
+ tm .assert_frame_equal (actual , expected )
558
557
559
- actual = read_excel (mi_file , 'both_name' , index_col = [0 ,1 ], header = [0 ,1 ])
560
- tm .assert_frame_equal (actual , expected )
558
+ actual = read_excel (mi_file , 'both_name' , index_col = [0 ,1 ], header = [0 ,1 ])
559
+ tm .assert_frame_equal (actual , expected )
561
560
562
- actual = read_excel (mi_file , 'both_name_skiprows' , index_col = [0 ,1 ],
563
- header = [0 ,1 ], skiprows = 2 )
564
- tm .assert_frame_equal (actual , expected )
561
+ actual = read_excel (mi_file , 'both_name_skiprows' , index_col = [0 ,1 ],
562
+ header = [0 ,1 ], skiprows = 2 )
563
+ tm .assert_frame_equal (actual , expected )
565
564
566
565
567
566
def test_excel_multindex_roundtrip (self ):
568
567
#GH 4679
569
- _skip_if_no_xlrd ()
568
+ _skip_if_no_xlsxwriter ()
570
569
with ensure_clean ('.xlsx' ) as pth :
571
570
for c_idx_names in [True , False ]:
572
571
for r_idx_names in [True , False ]:
@@ -603,7 +602,6 @@ def test_excel_multindex_roundtrip(self):
603
602
604
603
def test_excel_oldindex_format (self ):
605
604
#GH 4679
606
- _skip_if_no_xlrd ()
607
605
data = np .array ([['R0C0' , 'R0C1' , 'R0C2' , 'R0C3' , 'R0C4' ],
608
606
['R1C0' , 'R1C1' , 'R1C2' , 'R1C3' , 'R1C4' ],
609
607
['R2C0' , 'R2C1' , 'R2C2' , 'R2C3' , 'R2C4' ],
@@ -616,7 +614,7 @@ def test_excel_oldindex_format(self):
616
614
names = ['R0' , 'R1' ])
617
615
si = Index (['R_l0_g0' , 'R_l0_g1' , 'R_l0_g2' , 'R_l0_g3' , 'R_l0_g4' ], name = 'R0' )
618
616
619
- in_file = os .path .join (self .dirpath , 'test_index_name_pre17.xlsx' )
617
+ in_file = os .path .join (self .dirpath , 'test_index_name_pre17' + self . ext )
620
618
621
619
expected = pd .DataFrame (data , index = si , columns = columns )
622
620
with tm .assert_produces_warning (FutureWarning ):
0 commit comments