category_encoders/cols-left-to-dtype
| Rule | cols-left-to-dtype |
|---|---|
| Pack | Category Encoders |
| Severity | info |
| Fix | none, edit by hand |
| Library versions | Category Encoders 2.10 and later |
A category_encoders encoder without cols encodes only text and category columns, so a numeric column that a ColumnTransformer hands it passes through unchanged. Pass cols="all" to encode every column it gets.
columns = make_column_transformer((ce.BinaryEncoder(), ["zip_code"]), remainder="passthrough")columns = make_column_transformer((ce.BinaryEncoder(cols="all"), ["zip_code"]), remainder="passthrough")What the rule reports
Section titled “What the rule reports”The rule reports an encoder built without cols inside a ColumnTransformer or
make_column_transformer. Without cols, an encoder encodes the columns of the object, category
and string dtypes and passes every other column through.
How to fix it
Section titled “How to fix it”xpd has no automatic fix, so make the change by hand.
Inside a ColumnTransformer the columns are already chosen, so a numeric column that was chosen
on purpose comes back as it went in. On a whole-number column of 5 values, the steps gave the following output:
| Step | Output |
|---|---|
(ce.OneHotEncoder(), ["zip"]) |
1 column, equal to the input, and Warning: No categorical columns found printed with print, where a warning would be raised |
(ce.OneHotEncoder(cols="all"), ["zip"]) |
5 columns |
ce.TargetEncoder() |
the column unchanged |
cols="all" was added in category_encoders 2.10, so the rule carries since: "2.10". The rule
can't see the dtype of the chosen columns, and on text columns the old form is right. The rule is
therefore info. For OneHotEncoder, OrdinalEncoder and TargetEncoder the message also names the
scikit-learn class, which encodes every column it is given.
Message
Section titled “Message”xpd prints this message with the issue. A name that starts with $ stands for code from your file.
$C() without cols encodes only text and category columns, so a numeric column that this ColumnTransformer hands it passes through as it is. A whole-number column of 5 values came back as 1 column. Pass cols="all" to encode every column it is given.Browse the other rules of the Category Encoders pack.