Skip to content

pandas/no-inplace

Pack Severity Fix Versions
pandas info, and warning with style = "strict". A rule of the house style unsafe, with xpd check --fix --unsafe-fixes All versions

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()

The rule reports any other inplace=True, which gives no speedup and keeps the call out of a method chain.

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.

Other names bound to the receiver no longer see the change after the fix.

inplace=True gives no speedup and blocks chaining. Reassign instead.

See all rules in the pandas pack.