12
12
import pandas as pd
13
13
from pandas import DataFrame , Index , MultiIndex , get_option , set_option
14
14
import pandas .util .testing as tm
15
- from pandas .util .testing import ensure_clean , makeCustomDataframe as mkdf
16
15
17
16
from pandas .io .excel import (
18
17
ExcelFile ,
@@ -29,7 +28,7 @@ def path(ext):
29
28
"""
30
29
Fixture to open file for use in each test case.
31
30
"""
32
- with ensure_clean (ext ) as file_path :
31
+ with tm . ensure_clean (ext ) as file_path :
33
32
yield file_path
34
33
35
34
@@ -64,7 +63,7 @@ def test_read_one_empty_col_no_header(self, ext, header, expected):
64
63
filename = "no_header"
65
64
df = pd .DataFrame ([["" , 1 , 100 ], ["" , 2 , 200 ], ["" , 3 , 300 ], ["" , 4 , 400 ]])
66
65
67
- with ensure_clean (ext ) as path :
66
+ with tm . ensure_clean (ext ) as path :
68
67
df .to_excel (path , filename , index = False , header = False )
69
68
result = pd .read_excel (path , filename , usecols = [0 ], header = header )
70
69
@@ -80,7 +79,7 @@ def test_read_one_empty_col_with_header(self, ext, header, expected):
80
79
filename = "with_header"
81
80
df = pd .DataFrame ([["" , 1 , 100 ], ["" , 2 , 200 ], ["" , 3 , 300 ], ["" , 4 , 400 ]])
82
81
83
- with ensure_clean (ext ) as path :
82
+ with tm . ensure_clean (ext ) as path :
84
83
df .to_excel (path , "with_header" , index = False , header = True )
85
84
result = pd .read_excel (path , filename , usecols = [0 ], header = header )
86
85
@@ -93,7 +92,7 @@ def test_set_column_names_in_parameter(self, ext):
93
92
# keyword argument names
94
93
refdf = pd .DataFrame ([[1 , "foo" ], [2 , "bar" ], [3 , "baz" ]], columns = ["a" , "b" ])
95
94
96
- with ensure_clean (ext ) as pth :
95
+ with tm . ensure_clean (ext ) as pth :
97
96
with ExcelWriter (pth ) as writer :
98
97
refdf .to_excel (writer , "Data_no_head" , header = False , index = False )
99
98
refdf .to_excel (writer , "Data_with_head" , index = False )
@@ -127,7 +126,7 @@ def tdf(col_sheet_name):
127
126
dfs = [tdf (s ) for s in sheets ]
128
127
dfs = dict (zip (sheets , dfs ))
129
128
130
- with ensure_clean (ext ) as pth :
129
+ with tm . ensure_clean (ext ) as pth :
131
130
with ExcelWriter (pth ) as ew :
132
131
for sheetname , df in dfs .items ():
133
132
df .to_excel (ew , sheetname )
@@ -140,7 +139,7 @@ def tdf(col_sheet_name):
140
139
@td .skip_if_no ("xlsxwriter" )
141
140
def test_read_excel_multiindex_empty_level (self , ext ):
142
141
# see gh-12453
143
- with ensure_clean (ext ) as path :
142
+ with tm . ensure_clean (ext ) as path :
144
143
df = DataFrame (
145
144
{
146
145
("One" , "x" ): {0 : 1 },
@@ -194,7 +193,7 @@ def test_excel_multindex_roundtrip(
194
193
self , ext , c_idx_names , r_idx_names , c_idx_levels , r_idx_levels
195
194
):
196
195
# see gh-4679
197
- with ensure_clean (ext ) as pth :
196
+ with tm . ensure_clean (ext ) as pth :
198
197
if c_idx_levels == 1 and c_idx_names :
199
198
pytest .skip (
200
199
"Column index name cannot be serialized unless it's a MultiIndex"
@@ -204,7 +203,9 @@ def test_excel_multindex_roundtrip(
204
203
# unnamed levels, not Nones.
205
204
check_names = r_idx_names or r_idx_levels <= 1
206
205
207
- df = mkdf (5 , 5 , c_idx_names , r_idx_names , c_idx_levels , r_idx_levels )
206
+ df = tm .makeCustomDataframe (
207
+ 5 , 5 , c_idx_names , r_idx_names , c_idx_levels , r_idx_levels
208
+ )
208
209
df .to_excel (pth )
209
210
210
211
act = pd .read_excel (
@@ -243,7 +244,7 @@ def test_read_excel_parse_dates(self, ext):
243
244
df2 = df .copy ()
244
245
df2 ["date_strings" ] = df2 ["date_strings" ].dt .strftime ("%m/%d/%Y" )
245
246
246
- with ensure_clean (ext ) as pth :
247
+ with tm . ensure_clean (ext ) as pth :
247
248
df2 .to_excel (pth )
248
249
249
250
res = pd .read_excel (pth , index_col = 0 )
@@ -581,7 +582,7 @@ def test_excel_date_datetime_format(self, engine, ext, path):
581
582
columns = ["X" , "Y" ],
582
583
)
583
584
584
- with ensure_clean (ext ) as filename2 :
585
+ with tm . ensure_clean (ext ) as filename2 :
585
586
writer1 = ExcelWriter (path )
586
587
writer2 = ExcelWriter (
587
588
filename2 ,
@@ -778,13 +779,13 @@ def test_to_excel_output_encoding(self, ext):
778
779
columns = ["X\u0193 " , "Y" , "Z" ],
779
780
)
780
781
781
- with ensure_clean ("__tmp_to_excel_float_format__." + ext ) as filename :
782
+ with tm . ensure_clean ("__tmp_to_excel_float_format__." + ext ) as filename :
782
783
df .to_excel (filename , sheet_name = "TestSheet" , encoding = "utf8" )
783
784
result = pd .read_excel (filename , "TestSheet" , encoding = "utf8" , index_col = 0 )
784
785
tm .assert_frame_equal (result , df )
785
786
786
787
def test_to_excel_unicode_filename (self , ext , path ):
787
- with ensure_clean ("\u0192 u." + ext ) as filename :
788
+ with tm . ensure_clean ("\u0192 u." + ext ) as filename :
788
789
try :
789
790
f = open (filename , "wb" )
790
791
except UnicodeEncodeError :
@@ -932,12 +933,10 @@ def roundtrip(data, header=True, parser_hdr=0, index=True):
932
933
nrows = 5
933
934
ncols = 3
934
935
935
- from pandas .util .testing import makeCustomDataframe as mkdf
936
-
937
936
# ensure limited functionality in 0.10
938
937
# override of gh-2370 until sorted out in 0.11
939
938
940
- df = mkdf (
939
+ df = tm . makeCustomDataframe (
941
940
nrows , ncols , r_idx_nlevels = r_idx_nlevels , c_idx_nlevels = c_idx_nlevels
942
941
)
943
942
@@ -1216,7 +1215,7 @@ class TestExcelWriterEngineTests:
1216
1215
],
1217
1216
)
1218
1217
def test_ExcelWriter_dispatch (self , klass , ext ):
1219
- with ensure_clean (ext ) as path :
1218
+ with tm . ensure_clean (ext ) as path :
1220
1219
writer = ExcelWriter (path )
1221
1220
if ext == ".xlsx" and td .safe_import ("xlsxwriter" ):
1222
1221
# xlsxwriter has preference over openpyxl if both installed
0 commit comments