pandas/range-mask
| Rule | range-mask |
|---|---|
| Pack | pandas |
| Severity | warning |
| Fix | unsafe, with xpd check --fix --unsafe-fixes |
| Library versions | every version |
Two comparisons joined with & state one range twice. Call between(low, high) instead.
inside = (df["load"] >= 10) & (df["load"] <= 20)inside = df["load"].between(10, 20)What the rule reports
Section titled “What the rule reports”The rule reports (df["a"] >= 10) & (df["a"] <= 20). The fix is unsafe, because the value can be a NumPy array, which has no between.
The rule leaves comparisons alone on df.index, df.index.hour, df.columns,
df["load"].values and df["load"].array, because an index or an array has no between.
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["a"].between(10, 20).
Message
Section titled “Message”xpd prints this message with the issue. A name that starts with $ stands for code from your file.
between() states the range once. Write $S.between($LO, $HI).Browse the other rules of the pandas pack.