numpy/nan-to-int
| Rule | nan-to-int |
|---|---|
| Pack | NumPy |
| Severity | warning |
| Fix | none, edit by hand |
| Library versions | every version |
Casting an array that holds NaN to an int type turns each NaN into -9223372036854775808. Keep the float array, or replace NaN with a whole number before the cast.
counts = np.where(seen, totals, np.nan).astype(int)counts = np.where(seen, totals, 0).astype(int)What the rule reports
Section titled “What the rule reports”The rule reports np.where(m, x, np.nan).astype(int), which turns each NaN into -9223372036854775808.
How to fix it
Section titled “How to fix it”xpd has no automatic fix, so make the change by hand.
Message
Section titled “Message”xpd prints this message with the issue. A name that starts with $ stands for code from your file.
This casts an array that holds np.nan to $T, and NaN becomes -9223372036854775808. Keep the float array, or replace NaN with a whole number before the cast.Browse the other rules of the NumPy pack.