pandas/no-inplace
| Rule | no-inplace |
|---|---|
| Pack | pandas |
| Severity | info, and warning with style = "strict". A rule of the house style |
| Fix | unsafe, with xpd check --fix --unsafe-fixes |
| Library versions | every version |
inplace=True gives no speedup and keeps the call out of a method chain. Assign the result instead.
df.dropna(inplace=True)df = df.dropna()What the rule reports
Section titled “What the rule reports”The rule reports any other inplace=True, which gives no speedup and keeps the call out of a method chain.
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 applies only to a call that stands alone as a statement, on a name, an attribute or a subscript. It drops comments between the arguments of the call.
Message
Section titled “Message”xpd prints this message with the issue. A name that starts with $ stands for code from your file.
inplace=True gives no speedup and blocks chaining. Reassign instead.Browse the other rules of the pandas pack.