mirror of https://github.com/astral-sh/ruff
Skip panda rules if panda module hasn't been seen (#14671)
This commit is contained in:
parent
f3d8c023d3
commit
90487b8cbd
|
|
@ -1,6 +1,7 @@
|
|||
use ruff_diagnostics::{Diagnostic, Violation};
|
||||
use ruff_macros::{derive_message_formats, ViolationMetadata};
|
||||
use ruff_python_ast::{self as ast, Expr};
|
||||
use ruff_python_semantic::Modules;
|
||||
use ruff_text_size::Ranged;
|
||||
|
||||
use crate::checkers::ast::Checker;
|
||||
|
|
@ -44,6 +45,10 @@ impl Violation for PandasUseOfDotValues {
|
|||
|
||||
/// PD011
|
||||
pub(crate) fn attr(checker: &mut Checker, attribute: &ast::ExprAttribute) {
|
||||
if !checker.semantic().seen_module(Modules::PANDAS) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Avoid, e.g., `x.values = y`.
|
||||
if !attribute.ctx.is_load() {
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ use ruff_python_ast::{self as ast, Expr};
|
|||
use ruff_diagnostics::Violation;
|
||||
use ruff_diagnostics::{Diagnostic, DiagnosticKind};
|
||||
use ruff_macros::{derive_message_formats, ViolationMetadata};
|
||||
use ruff_python_semantic::Modules;
|
||||
use ruff_text_size::Ranged;
|
||||
|
||||
use crate::checkers::ast::Checker;
|
||||
|
|
@ -163,6 +164,10 @@ impl Violation for PandasUseOfDotStack {
|
|||
}
|
||||
|
||||
pub(crate) fn call(checker: &mut Checker, func: &Expr) {
|
||||
if !checker.semantic().seen_module(Modules::PANDAS) {
|
||||
return;
|
||||
}
|
||||
|
||||
let Expr::Attribute(ast::ExprAttribute { value, attr, .. }) = func else {
|
||||
return;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ use ruff_diagnostics::Diagnostic;
|
|||
use ruff_diagnostics::Violation;
|
||||
use ruff_macros::{derive_message_formats, ViolationMetadata};
|
||||
use ruff_python_ast::{self as ast, CmpOp, Expr, Int};
|
||||
use ruff_python_semantic::Modules;
|
||||
use ruff_text_size::Ranged;
|
||||
|
||||
use crate::checkers::ast::Checker;
|
||||
|
|
@ -68,6 +69,10 @@ pub(crate) fn nunique_constant_series_check(
|
|||
ops: &[CmpOp],
|
||||
comparators: &[Expr],
|
||||
) {
|
||||
if !checker.semantic().seen_module(Modules::PANDAS) {
|
||||
return;
|
||||
}
|
||||
|
||||
let ([op], [right]) = (ops, comparators) else {
|
||||
return;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ use ruff_python_ast::{self as ast, Expr};
|
|||
use crate::checkers::ast::Checker;
|
||||
use ruff_diagnostics::{Diagnostic, Violation};
|
||||
use ruff_macros::{derive_message_formats, ViolationMetadata};
|
||||
use ruff_python_semantic::Modules;
|
||||
use ruff_text_size::Ranged;
|
||||
|
||||
/// ## What it does
|
||||
|
|
@ -55,6 +56,10 @@ impl Violation for PandasUseOfPdMerge {
|
|||
|
||||
/// PD015
|
||||
pub(crate) fn use_of_pd_merge(checker: &mut Checker, func: &Expr) {
|
||||
if !checker.semantic().seen_module(Modules::PANDAS) {
|
||||
return;
|
||||
}
|
||||
|
||||
if let Expr::Attribute(ast::ExprAttribute { attr, value, .. }) = func {
|
||||
if let Expr::Name(ast::ExprName { id, .. }) = value.as_ref() {
|
||||
if id == "pd" && attr == "merge" {
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ use ruff_python_ast::{self as ast, Expr};
|
|||
use ruff_diagnostics::Violation;
|
||||
use ruff_diagnostics::{Diagnostic, DiagnosticKind};
|
||||
use ruff_macros::{derive_message_formats, ViolationMetadata};
|
||||
use ruff_python_semantic::Modules;
|
||||
use ruff_text_size::Ranged;
|
||||
|
||||
use crate::checkers::ast::Checker;
|
||||
|
|
@ -143,6 +144,10 @@ impl Violation for PandasUseOfDotIat {
|
|||
}
|
||||
|
||||
pub(crate) fn subscript(checker: &mut Checker, value: &Expr, expr: &Expr) {
|
||||
if !checker.semantic().seen_module(Modules::PANDAS) {
|
||||
return;
|
||||
}
|
||||
|
||||
let Expr::Attribute(ast::ExprAttribute { attr, value, .. }) = value else {
|
||||
return;
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue