@@ -2113,36 +2113,34 @@ def get_feature_names_out(self, input_features=None):
21132113 return _check_feature_names_in (self , input_features )
21142114
21152115
2116- def test_check_feature_names_in ():
2116+ @pytest .mark .parametrize (
2117+ ["constructor_name" , "feature_names" , "msg" ],
2118+ [
2119+ ("array" , ["x0" , "x1" , "x2" ], "input_features should have length equal to" ),
2120+ ("pandas" , ["a" , "b" , "c" ], "input_features is not equal to" ),
2121+ ("polars" , ["a" , "b" , "c" ], "input_features is not equal to" ),
2122+ ],
2123+ )
2124+ def test_check_feature_names_in (constructor_name , feature_names , msg ):
21172125 """Check behavior of check_feature_names_in for arrays."""
21182126 X = np .array ([[0.0 , 1.0 , 2.0 ]])
2127+ X = _convert_container (X , constructor_name , column_names = ["a" , "b" , "c" ])
21192128 est = PassthroughTransformer ().fit (X )
21202129
21212130 names = est .get_feature_names_out ()
2122- assert_array_equal (names , [ "x0" , "x1" , "x2" ] )
2131+ assert_array_equal (names , feature_names )
21232132
2124- incorrect_len_names = [ "x10" , "x1" ]
2125- with pytest .raises (ValueError , match = "input_features should have length equal to" ):
2133+ incorrect_len_names = feature_names [: 2 ]
2134+ with pytest .raises (ValueError , match = msg ):
21262135 est .get_feature_names_out (incorrect_len_names )
21272136
21282137 # remove n_feature_in_
21292138 del est .n_features_in_
2130- with pytest .raises (ValueError , match = "Unable to generate feature names" ):
2131- est .get_feature_names_out ()
2132-
2133-
2134- def test_check_feature_names_in_pandas ():
2135- """Check behavior of check_feature_names_in for pandas dataframes."""
2136- pd = pytest .importorskip ("pandas" )
2137- names = ["a" , "b" , "c" ]
2138- df = pd .DataFrame ([[0.0 , 1.0 , 2.0 ]], columns = names )
2139- est = PassthroughTransformer ().fit (df )
2140-
2141- names = est .get_feature_names_out ()
2142- assert_array_equal (names , ["a" , "b" , "c" ])
2143-
2144- with pytest .raises (ValueError , match = "input_features is not equal to" ):
2145- est .get_feature_names_out (["x1" , "x2" , "x3" ])
2139+ if constructor_name == "array" :
2140+ with pytest .raises (ValueError , match = "Unable to generate feature names" ):
2141+ est .get_feature_names_out ()
2142+ else :
2143+ assert_array_equal (est .get_feature_names_out (), feature_names )
21462144
21472145
21482146def test_check_response_method_unknown_method ():
0 commit comments