Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve Pandas call and attribute detection (#1671)
This PR adds some guardrails to avoid common false positives in our `pandas-vet` rules. Specifically, we now avoid triggering `pandas-vet` rules if the target of the call or attribute (i.e., the `x` in `x.stack(...)`) is unbound, or bound to something that couldn't be a DataFrame (like an import that _isn't_ `pandas`, or a class definition). This lets us avoid common false positives like `np.stack(...)`. Resolves #1659.
- Loading branch information
1 parent
2464cf6
commit 04111da
Showing
4 changed files
with
272 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
use rustpython_ast::{Expr, ExprKind}; | ||
|
||
/// Return `true` if an `Expr` _could_ be a `DataFrame`. This rules out | ||
/// obviously-wrong cases, like constants and literals. | ||
pub fn is_dataframe_candidate(expr: &Expr) -> bool { | ||
!matches!( | ||
expr.node, | ||
ExprKind::Constant { .. } | ||
| ExprKind::Tuple { .. } | ||
| ExprKind::List { .. } | ||
| ExprKind::Set { .. } | ||
| ExprKind::Dict { .. } | ||
| ExprKind::SetComp { .. } | ||
| ExprKind::ListComp { .. } | ||
| ExprKind::DictComp { .. } | ||
| ExprKind::GeneratorExp { .. } | ||
) | ||
} |
Oops, something went wrong.