1
- # pylint: disable=E1101
2
- import os
3
- import warnings
4
- from datetime import datetime , date , time , timedelta
1
+ from collections import OrderedDict
2
+ import contextlib
3
+ from datetime import date , datetime , time , timedelta
5
4
from distutils .version import LooseVersion
6
5
from functools import partial
6
+ import os
7
+ import warnings
7
8
from warnings import catch_warnings
8
- from collections import OrderedDict
9
9
10
10
import numpy as np
11
- import pytest
12
11
from numpy import nan
12
+ import pytest
13
13
14
- import pandas as pd
15
- import pandas .util .testing as tm
14
+ from pandas .compat import PY36 , BytesIO , iteritems , map , range , u
16
15
import pandas .util ._test_decorators as td
16
+
17
+ import pandas as pd
17
18
from pandas import DataFrame , Index , MultiIndex , Series
18
- from pandas .compat import u , range , map , BytesIO , iteritems , PY36
19
- from pandas .core .config import set_option , get_option
19
+ from pandas .core .config import get_option , set_option
20
+ import pandas .util .testing as tm
21
+ from pandas .util .testing import ensure_clean , makeCustomDataframe as mkdf
22
+
20
23
from pandas .io .common import URLError
21
24
from pandas .io .excel import (
22
- ExcelFile , ExcelWriter , read_excel , _XlwtWriter , _OpenpyxlWriter ,
23
- register_writer , _XlsxWriter
24
- )
25
+ ExcelFile , ExcelWriter , _OpenpyxlWriter , _XlsxWriter , _XlwtWriter ,
26
+ read_excel , register_writer )
25
27
from pandas .io .formats .excel import ExcelFormatter
26
28
from pandas .io .parsers import read_csv
27
- from pandas .util .testing import ensure_clean , makeCustomDataframe as mkdf
28
-
29
29
30
30
_seriesd = tm .getSeriesData ()
31
31
_tsd = tm .getTimeSeriesData ()
36
36
_mixed_frame ['foo' ] = 'bar'
37
37
38
38
39
+ @contextlib .contextmanager
40
+ def ignore_xlrd_time_clock_warning ():
41
+ """
42
+ Context manager to ignore warnings raised by the xlrd library,
43
+ regarding the deprecation of `time.clock` in Python 3.7.
44
+ """
45
+ with warnings .catch_warnings ():
46
+ warnings .filterwarnings (
47
+ action = 'ignore' ,
48
+ message = 'time.clock has been deprecated' ,
49
+ category = DeprecationWarning )
50
+ yield
51
+
52
+
39
53
@td .skip_if_no ('xlrd' , '1.0.0' )
40
54
class SharedItems (object ):
41
55
@@ -114,20 +128,23 @@ def test_usecols_int(self, ext):
114
128
# usecols as int
115
129
with tm .assert_produces_warning (FutureWarning ,
116
130
check_stacklevel = False ):
117
- df1 = self .get_exceldf ("test1" , ext , "Sheet1" ,
118
- index_col = 0 , usecols = 3 )
131
+ with ignore_xlrd_time_clock_warning ():
132
+ df1 = self .get_exceldf ("test1" , ext , "Sheet1" ,
133
+ index_col = 0 , usecols = 3 )
119
134
120
135
# usecols as int
121
136
with tm .assert_produces_warning (FutureWarning ,
122
137
check_stacklevel = False ):
123
- df2 = self .get_exceldf ("test1" , ext , "Sheet2" , skiprows = [1 ],
124
- index_col = 0 , usecols = 3 )
138
+ with ignore_xlrd_time_clock_warning ():
139
+ df2 = self .get_exceldf ("test1" , ext , "Sheet2" , skiprows = [1 ],
140
+ index_col = 0 , usecols = 3 )
125
141
126
142
# parse_cols instead of usecols, usecols as int
127
143
with tm .assert_produces_warning (FutureWarning ,
128
144
check_stacklevel = False ):
129
- df3 = self .get_exceldf ("test1" , ext , "Sheet2" , skiprows = [1 ],
130
- index_col = 0 , parse_cols = 3 )
145
+ with ignore_xlrd_time_clock_warning ():
146
+ df3 = self .get_exceldf ("test1" , ext , "Sheet2" , skiprows = [1 ],
147
+ index_col = 0 , parse_cols = 3 )
131
148
132
149
# TODO add index to xls file)
133
150
tm .assert_frame_equal (df1 , df_ref , check_names = False )
@@ -145,8 +162,9 @@ def test_usecols_list(self, ext):
145
162
index_col = 0 , usecols = [0 , 2 , 3 ])
146
163
147
164
with tm .assert_produces_warning (FutureWarning ):
148
- df3 = self .get_exceldf ('test1' , ext , 'Sheet2' , skiprows = [1 ],
149
- index_col = 0 , parse_cols = [0 , 2 , 3 ])
165
+ with ignore_xlrd_time_clock_warning ():
166
+ df3 = self .get_exceldf ('test1' , ext , 'Sheet2' , skiprows = [1 ],
167
+ index_col = 0 , parse_cols = [0 , 2 , 3 ])
150
168
151
169
# TODO add index to xls file)
152
170
tm .assert_frame_equal (df1 , dfref , check_names = False )
@@ -165,8 +183,9 @@ def test_usecols_str(self, ext):
165
183
index_col = 0 , usecols = 'A:D' )
166
184
167
185
with tm .assert_produces_warning (FutureWarning ):
168
- df4 = self .get_exceldf ('test1' , ext , 'Sheet2' , skiprows = [1 ],
169
- index_col = 0 , parse_cols = 'A:D' )
186
+ with ignore_xlrd_time_clock_warning ():
187
+ df4 = self .get_exceldf ('test1' , ext , 'Sheet2' , skiprows = [1 ],
188
+ index_col = 0 , parse_cols = 'A:D' )
170
189
171
190
# TODO add index to xls, read xls ignores index name ?
172
191
tm .assert_frame_equal (df2 , df1 , check_names = False )
@@ -618,8 +637,9 @@ def test_sheet_name_and_sheetname(self, ext):
618
637
df1 = self .get_exceldf (filename , ext ,
619
638
sheet_name = sheet_name , index_col = 0 ) # doc
620
639
with tm .assert_produces_warning (FutureWarning , check_stacklevel = False ):
621
- df2 = self .get_exceldf (filename , ext , index_col = 0 ,
622
- sheetname = sheet_name ) # backward compat
640
+ with ignore_xlrd_time_clock_warning ():
641
+ df2 = self .get_exceldf (filename , ext , index_col = 0 ,
642
+ sheetname = sheet_name ) # backward compat
623
643
624
644
excel = self .get_excelfile (filename , ext )
625
645
df1_parse = excel .parse (sheet_name = sheet_name , index_col = 0 ) # doc
0 commit comments