category_encoders/wrapper-fit-returns-none
| Rule | wrapper-fit-returns-none |
|---|---|
| Pack | Category Encoders |
| Severity | error |
| Fix | none, edit by hand |
| Library versions | every version |
fit of PolynomialWrapper and NestedCVWrapper returns None, so calling a method on its result raises AttributeError. Call fit on one line and the method on the next, or call fit_transform.
encoded = PolynomialWrapper(ce.TargetEncoder(cols=["city"])).fit(X, y).transform(X)wrapper = PolynomialWrapper(ce.TargetEncoder(cols=["city"]))wrapper.fit(X, y)encoded = wrapper.transform(X)What the rule reports
Section titled “What the rule reports”The rule reports a method call on the result of fit of a PolynomialWrapper or a
NestedCVWrapper, and a name assigned from that fit. Their fit has no return statement, so it
returns None where every scikit-learn estimator returns itself.
How to fix it
Section titled “How to fix it”xpd has no automatic fix, so make the change by hand.
The old form raised AttributeError: 'NoneType' object has no attribute 'transform' on both
wrappers. fit_transform returns the encoded frame on both and is left alone.
Message
Section titled “Message”xpd prints this message with the issue. A name that starts with $ stands for code from your file.
fit of $W returns None on category_encoders 2.11.2, so .$M on its result raises AttributeError. Call fit on one line and $M on the next, or call fit_transform.Browse the other rules of the Category Encoders pack.