pandas/query-string
| Rule | query-string |
|---|---|
| Pack | pandas |
| Severity | info |
| Fix | none, edit by hand |
| Library versions | every version |
A query string hides column names from editors, type checkers and xpd. Write the condition as an expression, such as df.loc[pd.col("a") > 50].
selected = df.query("load > 50 and wind < 3")selected = df.loc[(pd.col("load") > 50) & (pd.col("wind") < 3)]What the rule reports
Section titled “What the rule reports”The rule reports df.query("a > 50 and b < 0"), because editors, type checkers and xpd can read the column names in pd.col("a") and not in a string. The rule leaves a string that reads like SQL alone, such as conn.query("SELECT ...").
How to fix it
Section titled “How to fix it”xpd has no automatic fix, so make the change by hand.
Message
Section titled “Message”xpd prints this message with the issue. A name that starts with $ stands for code from your file.
A query string hides column names from editors, type checkers and xpd. Write the condition as an expression, such as df.loc[(pd.col("a") > 50) & (pd.col("b") < 0)].Browse the other rules of the pandas pack.