All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sonar.l10n.py.rules.python.S6725.html Maven / Gradle / Ivy

There is a newer version: 4.23.0.17664
Show newest version

This rule raises an issue when an equality check is made against numpy.nan.

Why is this an issue?

The numpy.nan is a floating point representation of Not a Number (NaN) used as a placeholder for undefined or missing values in numerical computations.

Equality checks of variables against numpy.nan in NumPy will always be False due to the special nature of numpy.nan. This can lead to unexpected and incorrect results.

Instead of standard comparison the numpy.isnan() function should be used.

Code examples

Noncompliant code example

import numpy as np

x = np.nan

if x == np.nan: # Noncompliant: always False
    ...

Compliant solution

import numpy as np

x = np.nan

if np.isnan(x):
   ...

Resources

Documentation





© 2015 - 2024 Weber Informatics LLC | Privacy Policy