Skip to content

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)

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.

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.

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.