-
-
Notifications
You must be signed in to change notification settings - Fork 10.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DOC: the recommended ruff rule for migration to numpy2 is missing many detections and fixes #26800
Comments
Ping @mtsokol in case any of this was done on purpose. |
Thank you for writing a thorough comparison! Changes that are not detected at allI think that most of these members were niche, and GitHub search showed none or small number of usages (like https://github.com/search?q=np.FLOATING_POINT_SUPPORT&type=code). Also the migration guide mentions all of them: https://numpy.org/doc/stable/numpy_2_0_migration_guide.html (I think Generally I think that most of them could be still added to the Ruff rule. Other comments: For Changes that are detected but no automatic fix is providedFor these points I think it's just a matter of figuring out how to achieve it in Rust. |
I think ruff Rule detects all of them. |
Will be partially fixed in astral-sh/ruff#12065. |
Hi! This PR updates `NPY201` rule to address #12034 and partially numpy/numpy#26800.
This commit includes the results of running `ruff check --select NPY201 --fix` on the code in this repo, plus the removal of `np.{dtype}0` aliases that currently aren't caught by the NPY201 ruff rule (see numpy/numpy#26800 where this is mentioned) plus removing the `numpy<2.0.0` pin from `requirements.txt`. After this commit, `import nptyping` succeeds in an environment with `numpy==2.0.0`. No additional testing has been done at this time, and additional changes could very well be necessary before nptyping is fully compatible with numpy2.0.0. But this should be a start!
PyTensor uses |
I'm a little confused - are you using the python |
The code was using both. For The code base is pretty uneven. (Pytensor is a fork of a fork of Theano... they're starting to move away from the C code but they still need to support it. Parts of the code essentially compile algebraic operations into CPython code, then compile it, and import the resulting python module.) This commit has the |
Issue with current documentation:
Hello, Numpy folks!
There is a ruff rule (
NPY201
) that is recommended for migration from numpy to numpy2. I did a thorough comparison between Python API removals and deprecations with what theNPY201
rule provides. There are many removals and deprecations that are in the documentation but the ruff rule does not consider.In many of the cases, a fix could be performed automatically.
Here is a summary of what is missing from the rule
NPY201
:Changes that are not detected at all
np.geterrobj
,np.seterrobj
and the related ufunc keyword argumentextobj=
have been removed. The preferred replacement for all of these is using the context managerwith np.errstate():
.ERR_*
,SHIFT_*
,np.kernel_version
,np.numarray
,np.oldnumeric
andnp.set_numeric_ops
.np.FLOATING_POINT_SUPPORT
,np.FPE_*
,np.CLIP
,np.WRAP
,np.RAISE
,np.BUFSIZE
,np.UFUNC_BUFSIZE_DEFAULT
,np.UFUNC_PYVALS_NAME
,np.ALLOW_THREADS
,np.MAXDIMS
,np.MAY_SHARE_EXACT
,np.MAY_SHARE_BOUNDS
.np.issctype
,np.maximum_sctype
,np.obj2sctype
,np.sctype2char
,np.sctypes
were all removed from the main namespace without replacement, as they where niche members.np.compare_chararrays
has been removed from the main namespace. Usenp.char.compare_chararrays
instead.charrarray
in the main namespace has been deprecated. It can be imported without a deprecation warning fromnp.char.chararray
for now, but we are planning to fully deprecate and removechararray
in the future.np.format_parser
has been removed from the main namespace. Usenp.rec.format_parser
instead.numpy.array_api
submodule has been removed. Use the main numpy namespace for regular usage instead, or the separatearray-api-strict
package for the compliance testing use case for whichnumpy.array_api
was mostly used.np.dtype
:int0
,uint0
,void0
,object0
,str0
,bytes0
andbool8
.np.trapz
has been deprecated. Usenp.trapezoid
or ascipy.integrate
function instead.np.in1d
has been deprecated. Usenp.isin
instead.np.cross
have been deprecated. Use arrays of 3-dimensional vectors instead.np.dtype("a")
alias fornp.dtype(np.bytes_)
was deprecated. Usenp.dtype("S")
alias instead.x
andy
with functionsassert_array_equal
andassert_array_almost_equal
has been deprecated. Pass the first two arguments as positional arguments instead.Changes that are detected but no automatic fix is provided
np.cast
has been removed. The literal replacement fornp.cast[dtype](arg)
isnp.asarray(arg, dtype=dtype)
.np.set_string_function
has been removed. Usenp.set_printoptions
instead with a formatter for custom printing of NumPy objects.np.recfromcsv
andrecfromtxt
are now only available fromnp.lib.npyio
.np.asfarray
has been removed. Usenp.asarray
with a properdtype
instead.np.find_common_type
has been removed. Usenumpy.promote_types
ornumpy.result_type
instead. To achieve semantics for thescalar_types
argument, usenumpy.result_type
and pass0
,0.0
, or0j
as a Python scalar instead.np.nbytes
has been removed. Usenp.dtype(<dtype>).itemsize
instead.Idea or request for content:
My suggestion is to add these changes to the ruff rule. Otherwise, it would be really helpful if the provided and not-provided changes were documented (either in the corresponding ruff rule page or the migration guide) so the users would know what they were getting (and not getting) by applying the rule.
The text was updated successfully, but these errors were encountered: