avoid-notnull

Try in Playground
python-pandasBest PracticeInformational

0

pandas

No CWE or CVE

Do not use .notnull and instead use .notna. Both functions have the same functionality, .notna .

However, it is a good practice to use .notna since pandas dataframe are based on R dataframe.

See more information here.

Ast Rule: function call


avoid-notnull

How to write a rule
function visit(node, filename, code) {
  node.context.imports.forEach(i => console.log(i.astType));
  const usePandas = node.context.imports.filter(i => i.astType === "importstatement" && i.packages.filter(p => p.name && p.name.value && p.name.value === "pandas").length > 0).length > 0;

  if (!usePandas) {
    return;
  }
  if (node.functionName && node.functionName.value && node.functionName.value === "notnull") {
    if (node.moduleOrObject) {
      const error = buildError(node.functionName.start.line, node.functionName.start.col, node.functionName.end.line, node.functionName.end.col,
        "do not use isnull", "INFO", "BEST_PRACTICE");
      const edit = buildEditUpdate(node.functionName.start.line, node.functionName.start.col,
        node.functionName.end.line, node.functionName.end.col,
        "isna");
      const fix = buildFix("use notna", [edit]);
      addError(error.addFix(fix));
    }
  }
}

no-import.py

Expected test result: no error

pd.notnull()

error.py

Expected test result: has error

import pandas as pd

pd.notnull()
Add comment

Log in to add a comment


    Be the first one to leave a comment!

Codiga Logo
Codiga Hub
  • Rulesets
  • Playground
  • Snippets
  • Cookbooks
soc-2 icon

We are SOC-2 Compliance Certified

G2 high performer medal

Codiga – All rights reserved 2022.