pandas/write-through-values
| Pack | Severity | Fix | Versions |
|---|---|---|---|
| pandas | error | unsafe, with xpd check --fix --unsafe-fixes |
All versions |
Under copy-on-write, the array behind a column is read-only, so writing through .values raises ValueError. Assign with .loc instead.
df["load"].values[0] = valuedf.loc[df.index[0], "load"] = valueWhat the rule reports
Section titled “What the rule reports”The rule reports df["a"].values[0] = 9, which raises ValueError, because the array is read-only under copy-on-write.
How to fix it
Section titled “How to fix it”xpd check --fix --unsafe-fixes rewrites single-index column writes (df["a"].values[i] or df["a"].to_numpy()[i]) to df.loc[df.index[i], "a"]. Slices, masks, and non-column expressions remain manual.
Diagnostic message
Section titled “Diagnostic message”The array behind a column is read-only under copy-on-write, so this write raises ValueError. Assign with .loc instead, as in df.loc[df.index[0], "a"] = value.See all rules in the pandas pack.