@@ -1129,48 +1129,49 @@ def test_basics_with_nan(self, merge_cells, engine, ext):
1129
1129
self .frame .to_excel (path , 'test1' , header = False )
1130
1130
self .frame .to_excel (path , 'test1' , index = False )
1131
1131
1132
- def test_int_types (self , merge_cells , engine , ext ):
1133
- for np_type in (np .int8 , np .int16 , np .int32 , np .int64 ):
1132
+ @pytest .mark .parametrize ("np_type" , [
1133
+ np .int8 , np .int16 , np .int32 , np .int64 ])
1134
+ def test_int_types (self , merge_cells , engine , ext , np_type ):
1135
+ with ensure_clean (ext ) as path :
1136
+ # Test np.int values read come back as int (rather than float
1137
+ # which is Excel's format).
1138
+ frame = DataFrame (np .random .randint (- 10 , 10 , size = (10 , 2 )),
1139
+ dtype = np_type )
1140
+ frame .to_excel (path , 'test1' )
1141
+ reader = ExcelFile (path )
1142
+ recons = read_excel (reader , 'test1' )
1143
+ int_frame = frame .astype (np .int64 )
1144
+ tm .assert_frame_equal (int_frame , recons )
1145
+ recons2 = read_excel (path , 'test1' )
1146
+ tm .assert_frame_equal (int_frame , recons2 )
1147
+
1148
+ # test with convert_float=False comes back as float
1149
+ float_frame = frame .astype (float )
1150
+ recons = read_excel (path , 'test1' , convert_float = False )
1151
+ tm .assert_frame_equal (recons , float_frame ,
1152
+ check_index_type = False ,
1153
+ check_column_type = False )
1154
+
1155
+ @pytest .mark .parametrize ("np_type" , [
1156
+ np .float16 , np .float32 , np .float64 ])
1157
+ def test_float_types (self , merge_cells , engine , ext , np_type ):
1158
+ with ensure_clean (ext ) as path :
1159
+ # Test np.float values read come back as float.
1160
+ frame = DataFrame (np .random .random_sample (10 ), dtype = np_type )
1161
+ frame .to_excel (path , 'test1' )
1162
+ reader = ExcelFile (path )
1163
+ recons = read_excel (reader , 'test1' ).astype (np_type )
1164
+ tm .assert_frame_equal (frame , recons , check_dtype = False )
1134
1165
1135
- with ensure_clean (ext ) as path :
1136
- # Test np.int values read come back as int (rather than float
1137
- # which is Excel's format).
1138
- frame = DataFrame (np .random .randint (- 10 , 10 , size = (10 , 2 )),
1139
- dtype = np_type )
1140
- frame .to_excel (path , 'test1' )
1141
- reader = ExcelFile (path )
1142
- recons = read_excel (reader , 'test1' )
1143
- int_frame = frame .astype (np .int64 )
1144
- tm .assert_frame_equal (int_frame , recons )
1145
- recons2 = read_excel (path , 'test1' )
1146
- tm .assert_frame_equal (int_frame , recons2 )
1147
-
1148
- # test with convert_float=False comes back as float
1149
- float_frame = frame .astype (float )
1150
- recons = read_excel (path , 'test1' , convert_float = False )
1151
- tm .assert_frame_equal (recons , float_frame ,
1152
- check_index_type = False ,
1153
- check_column_type = False )
1154
-
1155
- def test_float_types (self , merge_cells , engine , ext ):
1156
- for np_type in (np .float16 , np .float32 , np .float64 ):
1157
- with ensure_clean (ext ) as path :
1158
- # Test np.float values read come back as float.
1159
- frame = DataFrame (np .random .random_sample (10 ), dtype = np_type )
1160
- frame .to_excel (path , 'test1' )
1161
- reader = ExcelFile (path )
1162
- recons = read_excel (reader , 'test1' ).astype (np_type )
1163
- tm .assert_frame_equal (frame , recons , check_dtype = False )
1164
-
1165
- def test_bool_types (self , merge_cells , engine , ext ):
1166
- for np_type in (np .bool8 , np .bool_ ):
1167
- with ensure_clean (ext ) as path :
1168
- # Test np.bool values read come back as float.
1169
- frame = (DataFrame ([1 , 0 , True , False ], dtype = np_type ))
1170
- frame .to_excel (path , 'test1' )
1171
- reader = ExcelFile (path )
1172
- recons = read_excel (reader , 'test1' ).astype (np_type )
1173
- tm .assert_frame_equal (frame , recons )
1166
+ @pytest .mark .parametrize ("np_type" , [np .bool8 , np .bool_ ])
1167
+ def test_bool_types (self , merge_cells , engine , ext , np_type ):
1168
+ with ensure_clean (ext ) as path :
1169
+ # Test np.bool values read come back as float.
1170
+ frame = (DataFrame ([1 , 0 , True , False ], dtype = np_type ))
1171
+ frame .to_excel (path , 'test1' )
1172
+ reader = ExcelFile (path )
1173
+ recons = read_excel (reader , 'test1' ).astype (np_type )
1174
+ tm .assert_frame_equal (frame , recons )
1174
1175
1175
1176
def test_inf_roundtrip (self , merge_cells , engine , ext ):
1176
1177
frame = DataFrame ([(1 , np .inf ), (2 , 3 ), (5 , - np .inf )])
0 commit comments