Skip to content

sklego/selector-without-feature-names

Rule selector-without-feature-names
Pack scikit-lego
Severity error
Fix none, edit by hand
Library versions every version

ColumnSelector, ColumnDropper and TypeSelector have no set_output and no get_feature_names_out, so calling either on a pipeline that holds them raises. Select columns with a ColumnTransformer and "passthrough".

pipeline = make_pipeline(ColumnSelector(["age", "fare"]), StandardScaler())
pipeline = make_pipeline(ColumnTransformer([("keep", "passthrough", ["age", "fare"])]), StandardScaler())
pipeline.set_output(transform="pandas")

The rule reports set_output(...) and get_feature_names_out() on a pipeline that holds ColumnSelector, ColumnDropper or TypeSelector, called on the pipeline itself or on a name the file assigns it to. The three classes have get_feature_names and neither of the two scikit-learn methods.

xpd has no automatic fix, so make the change by hand.

For each of the three classes, set_output raised ValueError "Unable to configure output for ColumnSelector(...) because set_output is not available.", and get_feature_names_out raised AttributeError "Estimator columnselector does not provide get_feature_names_out". The ColumnTransformer form did both, and it names the columns keep__age and keep__fare.

xpd prints this message with the issue. A name that starts with $ stands for code from your file.

$C has no set_output and no get_feature_names_out, so this call on a pipeline that holds it raises ValueError or AttributeError. Select the columns with a ColumnTransformer and "passthrough", which has both.

Browse the other rules of the scikit-lego pack.