pandas/inplace-on-column
| Rule | inplace-on-column |
|---|---|
| Pack | pandas |
| Severity | error |
| Fix | unsafe, with xpd check --fix --unsafe-fixes |
| Library versions | every version |
Under copy-on-write, an inplace=True call on a selected column changes a copy, so the frame keeps its old values. Assign the result back to the column instead.
df["load"].fillna(0, inplace=True)df["load"] = df["load"].fillna(0)What the rule reports
Section titled “What the rule reports”The rule reports df["b"].fillna(0, inplace=True), which changes a copy, so the frame keeps its old values. It also reports df[column].fillna(0, inplace=True), where a variable names the column.
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["b"] = df["b"].fillna(0).
The fix is unsafe, because xpd cannot tell a column from a value in a dict. The fix 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.
An inplace call on a selected column changes a copy under copy-on-write, so the frame keeps its old values. Assign the result back, as in $OBJ = $OBJ.$M(...).Browse the other rules of the pandas pack.