read-table

Try in Playground
python-pandasBest PracticeInformational

0

pandas

No CWE or CVE

Use read_csv instead of read_table as this is more obvious what the code is doing (e.g. read from a CSV file).

Ast Rule: function call


read-table

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 === "read_table") {
    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 read_table", "INFO", "BEST_PRACTICE");
      const edit = buildEditUpdate(node.functionName.start.line, node.functionName.start.col,
        node.functionName.end.line, node.functionName.end.col,
        "read_csv");
      const fix = buildFix("use read_csv", [edit]);
      addError(error.addFix(fix));
    }
  }
}

read-table.py

Expected test result: has error

import pandas as pd
  
pd.read_table('nba.csv',delimiter=',')
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.