nan-comparison / W0177ΒΆ

Message emitted:

Comparison %s should be %s

Description:

Used when an expression is compared to NaN values like math.nan, numpy.nan or float('nan').

Problematic code:

import math

import numpy as np


def both_unknown(apple, banana) -> bool:
    # Nothing equals NaN, not even NaN itself, so this is always False
    return apple == math.nan and banana == np.nan  # [nan-comparison, nan-comparison]

Correct code:

import math

import numpy as np


def both_unknown(apple, banana) -> bool:
    return math.isnan(apple) and np.isnan(banana)

Created by the basic checker.