pandas/inplace-result-assigned
| Pack | Severity | Fix | Versions |
|---|---|---|---|
| pandas | error | unsafe, with xpd check --fix --unsafe-fixes |
All versions |
A call with inplace=True returns None, so df = df.dropna(inplace=True) sets df to None. Drop inplace=True and keep the assignment.
df = df.dropna(inplace=True)df = df.dropna()What the rule reports
Section titled “What the rule reports”The rule reports df = df.dropna(inplace=True), which sets df to None.
How to fix it
Section titled “How to fix it”xpd check --fix --unsafe-fixes applies the fixes of this rule. Check the result, because an unsafe fix can change what the code does.
The unsafe fix writes df = df.dropna().
The fix drops comments between the arguments of the call.
Diagnostic message
Section titled “Diagnostic message”A call with inplace=True returns None, so $NAME is None after this line. Drop inplace=True and keep the assignment.See all rules in the pandas pack.