SonarSource Rules
  • Products

    In-IDE

    Code Quality and Security in your IDE with SonarQube Ide

    IDE extension that lets you fix coding issues before they exist!

    Discover SonarQube for IDE

    SaaS

    Code Quality and Security in the cloud with SonarQube Cloud

    Setup is effortless and analysis is automatic for most languages

    Discover SonarQube Cloud

    Self-Hosted

    Code Quality and Security Self-Hosted with SonarQube Server

    Fast, accurate analysis; enterprise scalability

    Discover SonarQube Server
  • SecretsSecrets
  • ABAPABAP
  • AnsibleAnsible
  • ApexApex
  • AzureResourceManagerAzureResourceManager
  • CC
  • C#C#
  • C++C++
  • CloudFormationCloudFormation
  • COBOLCOBOL
  • CSSCSS
  • DartDart
  • DockerDocker
  • FlexFlex
  • GitHub ActionsGitHub Actions
  • GoGo
  • GroovyGroovy
  • HTMLHTML
  • JavaJava
  • JavaScriptJavaScript
  • JSONJSON
  • JCLJCL
  • KotlinKotlin
  • KubernetesKubernetes
  • Objective CObjective C
  • PHPPHP
  • PL/IPL/I
  • PL/SQLPL/SQL
  • PythonPython
  • RPGRPG
  • RubyRuby
  • RustRust
  • ScalaScala
  • ShellShell
  • SwiftSwift
  • TerraformTerraform
  • TextText
  • TypeScriptTypeScript
  • T-SQLT-SQL
  • VB.NETVB.NET
  • VB6VB6
  • XMLXML
  • YAMLYAML
Python

Python static code analysis

Unique rules to find Bugs, Vulnerabilities, Security Hotspots, and Code Smells in your PYTHON code

  • All rules 414
  • Vulnerability45
  • Bug104
  • Security Hotspot50
  • Code Smell215

  • Quick Fix 33
Filtered: 24 rules found
data-science
    Impact
      Clean code attribute
        1. "master" and "appName" should be set when constructing PySpark "SparkContext"s and "SparkSession"s

           Code Smell
        2. PySpark's "RDD.groupByKey", when used in conjunction with "RDD.mapValues" with a commutative and associative operation, should be replaced by "RDD.reduceByKey"

           Code Smell
        3. PySpark's "DataFrame" column names should be unique

           Code Smell
        4. PySpark "dropDuplicates" subset argument should not be provided with an empty list

           Code Smell
        5. Complex logic provided to PySpark "withColumn", "filter" and "when" methods should be refactored into separate expressions

           Code Smell
        6. PySpark lit(None) should be used when populating empty columns

           Code Smell
        7. PySpark DataFrame toPandas function should be avoided

           Code Smell
        8. The "how" parameter should be specified when joining two PySpark DataFrames

           Code Smell
        9. "withColumns" method should be preferred over "withColumn" when multiple columns are specified

           Code Smell
        10. PySpark DataFrames used multiple times should be cached or persisted

           Code Smell
        11. PySpark Pandas DataFrame columns should not use a reserved name

           Code Smell
        12. The "subset" argument should be provided when using PySpark DataFrame "dropDuplicates" method

           Code Smell
        13. PySpark Window functions should always specify a frame

           Code Smell
        14. pandas.pipe method should be preferred over long chains of instructions

           Code Smell
        15. The "pandas.DataFrame.to_numpy()" method should be preferred to the "pandas.DataFrame.values" attribute

           Code Smell
        16. 'dtype' parameter should be provided when using 'pandas.read_csv' or 'pandas.read_table'

           Code Smell
        17. When using pandas.merge or pandas.join, the parameters on, how and validate should be provided

           Code Smell
        18. inplace=True should not be used when modifying a Pandas DataFrame

           Code Smell
        19. Deprecated NumPy aliases of built-in types should not be used

           Code Smell
        20. np.nonzero should be preferred over np.where when only the condition parameter is set

           Code Smell
        21. Passing a list to np.array should be preferred over passing a generator

           Code Smell
        22. numpy.random.Generator should be preferred to numpy.random.RandomState

           Code Smell
        23. Results that depend on random number generation should be reproducible

           Code Smell
        24. Floating point numbers should not be tested for equality

           Bug

        Passing a list to np.array should be preferred over passing a generator

        intentionality - logical
        maintainability
        reliability
        Code Smell
        • numpy
        • data-science

        This rule raises an issue when a generator is passed to np.array.

        Why is this an issue?

        How can I fix it?

        More Info

        The creation of a NumPy array can be done in several ways, for example by passing a Python list to the np.array function. Another way would be to pass a generator to the np.array function, but doing so creates a 0-dimensional array of objects and may not be the intended goal. This NumPy array will have a have a data type (dtype) of object and could hold any Python objects.

        One of the characteristics of NumPy arrays is homogeneity, meaning all its elements are of the same type. Creating an array of objects allows the user to create heterogeneous array without raising any errors and creating such an array can lead to bugs further in the program.

        arr = np.array(x**2 for x in range(10))
        
        arr.reshape(1)
        arr.resize(2)
        arr.put(indices=1, values=3) # No issues raised.
        

        The NumPy array arr shown above now holds 2 values: a generator and the number 3.

          Available In:
        • SonarQube IdeCatch issues on the fly,
          in your IDE
        • SonarQube CloudDetect issues in your GitHub, Azure DevOps Services, Bitbucket Cloud, GitLab repositories
        • SonarQube Community BuildAnalyze code in your
          on-premise CI
          Available Since
          10.3
        • SonarQube ServerAnalyze code in your
          on-premise CI
          Developer Edition
          Available Since
          10.3

        © 2026 SonarSource Sàrl. All rights reserved.

        Privacy Policy | Cookie Policy | Terms of Use