The answer is already provided in the comments by @mattdmo and @tdelaney:
NumPy 1.20 (release notes) deprecated numpy.float
, numpy.int
, and similar aliases, causing them to issue a deprecation warning
NumPy 1.24 (release notes) removed these aliases altogether, causing an error when they are used
In many cases you can simply replace the deprecated NumPy types by the equivalent Python built-in type, e.g., numpy.float
becomes a "plain" Python float
.
For detailed guidelines on how to deal with various deprecated types, have a closer look at the table and guideline in the release notes for 1.20:
...
To give a clear guideline for the vast majority of cases, for the types bool
, object
, str
(and unicode
) using the plain version is shorter and clear, and generally a good replacement. For float
and complex
you can use float64
and complex128
if you wish to be more explicit about the precision.
For np.int
a direct replacement with np.int_
or int
is also good and will not change behavior, but the precision will continue to depend on the computer and operating system. If you want to be more explicit and review the current use, you have the following alternatives:
np.int64
or np.int32
to specify the precision exactly. This ensures that results cannot depend on the computer or operating system.
np.int_
or int
(the default), but be aware that it depends on the computer and operating system.
- The C types:
np.cint
(int
), np.int_
(long
), np.longlong
.
np.intp
which is 32bit on 32bit machines 64bit on 64bit machines. This can be the best type to use for indexing.
...
If you have dependencies that use the deprecated types, a quick workaround would be to roll back your NumPy version to 1.24 or less (as suggested in some of the other answers), while waiting for the dependency to catch up. Alternatively, you could create a patch yourself and open a pull request, or monkey patch the dependency in your own code.
np.float
is a deprecated alias for the builtinfloat
. To silence this warning, usefloat
by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, usenp.float64
here. Deprecated in NumPy 1.20; for more details and guidance: numpy.org/devdocs/release/1.20.0-notes.html#deprecations – Alcinafloat
object, but as mentioned,numpy.float
has been deprecated... and removed in 1.24. You can either usefloat
or pick one of thenp.float32
,np.float64
,np.float128
(is that all of them?!). That second option seems reasonable to me. – Kelson