1
+ import warnings
2
+
1
3
import pytest
2
4
3
5
import pandas as pd
@@ -26,7 +28,6 @@ def test_read_xlrd_book(read_ext, frame):
26
28
with tm .ensure_clean (read_ext ) as pth :
27
29
df .to_excel (pth , sheet_name )
28
30
book = xlrd .open_workbook (pth )
29
-
30
31
with ExcelFile (book , engine = engine ) as xl :
31
32
result = pd .read_excel (xl , sheet_name = sheet_name , index_col = 0 )
32
33
tm .assert_frame_equal (df , result )
@@ -38,20 +39,24 @@ def test_read_xlrd_book(read_ext, frame):
38
39
# TODO: test for openpyxl as well
39
40
def test_excel_table_sheet_by_index (datapath , read_ext ):
40
41
path = datapath ("io" , "data" , "excel" , f"test1{ read_ext } " )
41
- with pd .ExcelFile (path ) as excel :
42
- with pytest .raises (xlrd .XLRDError ):
43
- pd .read_excel (excel , sheet_name = "asdf" )
42
+ with warnings .catch_warnings ():
43
+ warnings .simplefilter ("ignore" )
44
+ with pd .ExcelFile (path ) as excel :
45
+ with pytest .raises (xlrd .XLRDError ):
46
+ pd .read_excel (excel , sheet_name = "asdf" )
44
47
45
48
46
49
# See issue #29375
47
50
def test_excel_file_warning_with_default_engine (datapath ):
48
- path = datapath ("io" , "data" , "test1.xls" )
49
- with tm . assert_produces_warning ( FutureWarning ) :
51
+ path = datapath ("io" , "data" , "excel" , " test1.xls" )
52
+ with warnings . catch_warnings ( record = True ) as w :
50
53
pd .ExcelFile (path )
54
+ assert "default to \" openpyxl\" in the future." in str (w [- 1 ].message )
51
55
52
56
53
57
# See issue #29375
54
58
def test_read_excel_warning_with_default_engine (tmpdir , datapath ):
55
- path = datapath ("io" , "data" , "test1.xls" )
56
- with tm .assert_produces_warning (FutureWarning ):
57
- pd .read_excel (path , sheet_name = "Sheet1" )
59
+ path = datapath ("io" , "data" , "excel" , "test1.xls" )
60
+ with warnings .catch_warnings (record = True ) as w :
61
+ pd .read_excel (path , "Sheet1" )
62
+ assert "default to \" openpyxl\" in the future." in str (w [- 1 ].message )
0 commit comments