@@ -514,12 +514,13 @@ def test_column_transformer_invalid_columns(remainder):
514
514
ct = ColumnTransformer ([('trans' , Trans (), col )], remainder = remainder )
515
515
ct .fit (X_array )
516
516
X_array_more = np .array ([[0 , 1 , 2 ], [2 , 4 , 6 ], [3 , 6 , 9 ]]).T
517
- msg = ("Given feature/column names or counts do not match the ones for "
518
- "the data given during fit ." )
519
- with pytest .warns ( FutureWarning , match = msg ):
520
- ct .transform (X_array_more ) # Should accept added columns, for now
517
+ msg = ("X has 3 features, but ColumnTransformer is expecting 2 features "
518
+ "as input ." )
519
+ with pytest .raises ( ValueError , match = msg ):
520
+ ct .transform (X_array_more )
521
521
X_array_fewer = np .array ([[0 , 1 , 2 ], ]).T
522
- err_msg = 'Number of features'
522
+ err_msg = ("X has 1 features, but ColumnTransformer is expecting 2 "
523
+ "features as input." )
523
524
with pytest .raises (ValueError , match = err_msg ):
524
525
ct .transform (X_array_fewer )
525
526
@@ -1186,17 +1187,18 @@ def test_column_transformer_reordered_column_names_remainder(explicit_colname):
1186
1187
remainder = Trans ())
1187
1188
1188
1189
tf .fit (X_fit_df )
1189
- err_msg = 'Column ordering must be equal'
1190
- warn_msg = ("Given feature/column names or counts do not match the ones "
1191
- "for the data given during fit." )
1192
- with pytest .raises (ValueError , match = err_msg ):
1190
+ err_msg = ("Given feature/column names do not match the ones for the "
1191
+ "data given during fit." )
1192
+ with pytest .raises (RuntimeError , match = err_msg ):
1193
1193
tf .transform (X_trans_df )
1194
1194
1195
- # No error for added columns if ordering is identical
1195
+ # ValueError for added columns
1196
1196
X_extended_df = X_fit_df .copy ()
1197
1197
X_extended_df ['third' ] = [3 , 6 , 9 ]
1198
- with pytest .warns (FutureWarning , match = warn_msg ):
1199
- tf .transform (X_extended_df ) # No error should be raised, for now
1198
+ err_msg = ("X has 3 features, but ColumnTransformer is expecting 2 "
1199
+ "features as input." )
1200
+ with pytest .raises (ValueError , match = err_msg ):
1201
+ tf .transform (X_extended_df )
1200
1202
1201
1203
# No 'columns' AttributeError when transform input is a numpy array
1202
1204
X_array = X_fit_array .copy ()
@@ -1218,15 +1220,15 @@ def test_feature_name_validation():
1218
1220
tf = ColumnTransformer ([('bycol' , Trans (), ['a' , 'b' ])])
1219
1221
tf .fit (df )
1220
1222
1221
- msg = ("Given feature/column names or counts do not match the ones for "
1222
- "the data given during fit ." )
1223
- with pytest .warns ( FutureWarning , match = msg ):
1223
+ msg = ("X has 3 features, but ColumnTransformer is expecting 2 features "
1224
+ "as input ." )
1225
+ with pytest .raises ( ValueError , match = msg ):
1224
1226
tf .transform (df_extra )
1225
1227
1226
1228
tf = ColumnTransformer ([('bycol' , Trans (), [0 ])])
1227
1229
tf .fit (df )
1228
1230
1229
- with pytest .warns ( FutureWarning , match = msg ):
1231
+ with pytest .raises ( ValueError , match = msg ):
1230
1232
tf .transform (X_extra )
1231
1233
1232
1234
with warnings .catch_warnings (record = True ) as warns :
@@ -1236,24 +1238,9 @@ def test_feature_name_validation():
1236
1238
tf = ColumnTransformer ([('bycol' , Trans (), ['a' ])],
1237
1239
remainder = Trans ())
1238
1240
tf .fit (df )
1239
- with pytest .warns (FutureWarning , match = msg ):
1240
- tf .transform (df_extra )
1241
-
1242
- tf = ColumnTransformer ([('bycol' , Trans (), [0 , - 1 ])])
1243
- tf .fit (df )
1244
- msg = "At least one negative column was used to"
1245
- with pytest .raises (RuntimeError , match = msg ):
1246
- tf .transform (df_extra )
1247
-
1248
- tf = ColumnTransformer ([('bycol' , Trans (), slice (- 1 , - 3 , - 1 ))])
1249
- tf .fit (df )
1250
- with pytest .raises (RuntimeError , match = msg ):
1241
+ with pytest .raises (ValueError , match = msg ):
1251
1242
tf .transform (df_extra )
1252
1243
1253
- with warnings .catch_warnings (record = True ) as warns :
1254
- tf .transform (df )
1255
- assert not warns
1256
-
1257
1244
1258
1245
@pytest .mark .parametrize ("array_type" , [np .asarray , sparse .csr_matrix ])
1259
1246
def test_column_transformer_mask_indexing (array_type ):
0 commit comments