A value is compared with NaN using == or !=
What it finds
x == float("nan"), value != math.nan: NaN is unequal to every value, itself included, so == with it is always false and != always true. math.isnan or numpy.isnan test for it.
Recognized are float("nan") in any case, and math.nan, numpy.nan, numpy.NaN, numpy.NAN and torch.nan.
From the rule's source, nan_equality.rs.
import mathimport numpy as np def clean(value, values): if value == float("nan"):tx0 reports: a comparison with NaN using == or != is always false return None if value != math.nan:tx0 reports: is always true return value if np.nan == values[0]:tx0 reports: is always false return 0 if math.isnan(value) or value == float("inf"): return 1 Turn it on, off or suppress it
The rule runs in every tier. To turn it off for a project, set its level in tx0.toml:
[rules]
"tx0/python:nan-equality" = "off"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
# tx0: ignore[tx0/python:nan-equality] reason="..."tx0 explain tx0/python:nan-equality shows the same in the terminal. Found a false positive? Report it.