no-isnull

Try in Playground
python-pandasBest PracticeInformational

0

pandas

No CWE or CVE

While isnull and isna are doing the same thing, it is a good practice to use isna since Pandas DataFrame are based on R DataFrame.

More information in this article.

Ast Rule: function call


no-isnull

How to write a rule
function visit(node, filename, code) {
  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 === "isnull") {
    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 isna", [edit]);
      addError(error.addFix(fix));
    }
  }
}

no-import.py

Expected test result: no error

df.isnull()

isna.py

Expected test result: has error

import pandas as pd

df.isnull()
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.