astral-sh / ruff

An extremely fast Python linter and code formatter, written in Rust.
https://docs.astral.sh/ruff
MIT License
31.99k stars 1.07k forks source link

NPY201 does not catch `ptp` updates for numpy v2 #11909

Open jvavrek opened 4 months ago

jvavrek commented 4 months ago

ruff does not catch the arr.ptp() --> np.ptp(arr) updates necessary in numpy>=2

MWE:

# tmp.py
import numpy as np

x = np.arange(10)
print(x.ptp())
ruff check tmp.py --select NPY201 --isolated  # (same without the --isolated flag)
# All checks passed!
ruff --version
# ruff 0.4.9
dhruvmanila commented 4 months ago

Thank you for highlighting this! I think this is difficult with the current semantic model as it requires Ruff to understand that the type of the variable x is a NumPy array. Related to https://github.com/astral-sh/ruff/issues/6432, if Ruff were to just check for the .ptp method, it would raise false positives if the variable is not a Numpy array.