numpy/result-is-none
| Pack | Severity | Fix | Versions |
|---|---|---|---|
| NumPy | error | unsafe, with xpd check --fix --unsafe-fixes |
All versions |
Methods such as sort() and shuffle() change the array in place and return None, so x = x.sort() sets x to None. Call the method on its own line.
values = values.sort()values.sort()What the rule reports
Section titled “What the rule reports”The rule reports x = x.sort(), m = np.fill_diagonal(m, 0), y = rng.shuffle(y), w = w.fill(0) and return v.sort(). The calls change the array in place and return None, so the code gets None in place of the array.
The rule leaves a sort alone that has an argument other than an axis, such as xp.sort(x) in the array API, because such a sort returns a value.
How to fix it
Section titled “How to fix it”xpd check --fix --unsafe-fixes applies the fixes of this rule. Check the result, because an unsafe fix can change what the code does.
The unsafe fix writes x.sort(). A result assigned to another name, or returned, has no fix.
Diagnostic message
Section titled “Diagnostic message”sort() sorts in place and returns None, so $X is None after this line. Call $X.sort() on its own line.See all rules in the NumPy pack.