Skip to content

Commit cbaba3f

Browse files
committed
DOC: 2.0 migration guide cleanup; move ruff plugin section to the top
For many users, running `ruff` may be all they need to do - or it's very helpful at least - so don't hide it at the end of this very long page.
1 parent 4fb6ede commit cbaba3f

File tree

1 file changed

+36
-31
lines changed

1 file changed

+36
-31
lines changed

doc/source/numpy_2_0_migration_guide.rst

Lines changed: 36 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,25 @@ This document contains a set of instructions on how to update your code to
88
work with Numpy 2.0.
99

1010

11+
Ruff plugin
12+
===========
13+
14+
Many of the changes covered in the 2.0 release notes and in this migration
15+
guide can be automatically adapted to in downstream code with a dedicated
16+
`Ruff <https://docs.astral.sh/ruff/>`__ rule, namely rule
17+
`NPY201 <https://docs.astral.sh/ruff/rules/numpy2-deprecation/>`_.
18+
19+
You should install ``ruff>=0.2.0`` and add the ``NPY201`` rule to your
20+
``pyproject.toml``::
21+
22+
[tool.ruff.lint]
23+
select = ["NPY201"]
24+
25+
You can also apply the NumPy 2.0 rule directly from the command line::
26+
27+
$ ruff check path/to/code/ --select NPY201
28+
29+
1130
.. _migration_promotion_changes:
1231

1332
Changes to NumPy data type promotion
@@ -188,8 +207,8 @@ The underlying type remains a struct under C++ (all of the above still remains
188207
valid).
189208

190209

191-
Namespace changes
192-
=================
210+
Changes to namespaces
211+
=====================
193212

194213
In NumPy 2.0 certain functions, modules, and constants were moved or removed
195214
to make the NumPy namespace more user-friendly by removing unnecessary or
@@ -298,8 +317,8 @@ downstream libraries we don't provide any information on how to replace them:
298317
``MAY_SHARE_BOUNDS``]
299318

300319

301-
Lib namespace
302-
-------------
320+
numpy.lib namespace
321+
-------------------
303322

304323
Most of the functions available within ``np.lib`` are also present in the main
305324
namespace, which is their primary location. To make it unambiguous how to access each
@@ -321,10 +340,10 @@ the main namespace, then you're using a private member. You should either use th
321340
API or, in case it's infeasible, reach out to us with a request to restore the removed entry.
322341

323342

324-
Core namespace
325-
--------------
343+
numpy.core namespace
344+
--------------------
326345

327-
``np.core`` namespace is now officially private and has been renamed to ``np._core``.
346+
The ``np.core`` namespace is now officially private and has been renamed to ``np._core``.
328347
The user should never fetch members from the ``_core`` directly - instead the main
329348
namespace should be used to access the attribute in question. The layout of the ``_core``
330349
module might change in the future without notice, contrary to public modules which adhere
@@ -333,8 +352,8 @@ then you should either use the existing API or, in case it's infeasible, reach o
333352
with a request to restore the removed entry.
334353

335354

336-
ndarray and scalar namespace
337-
----------------------------
355+
ndarray and scalar methods
356+
--------------------------
338357

339358
A few methods from ``np.ndarray`` and ``np.generic`` scalar classes have been removed.
340359
The table below provides replacements for the removed members:
@@ -349,32 +368,18 @@ setitem Use ``arr[index] = value`` instead.
349368
====================== ========================================================
350369

351370

352-
Strings namespace
353-
-----------------
371+
numpy.strings namespace
372+
-----------------------
354373

355-
A new ``np.strings`` namespace has been created, where most of the string
356-
operations are implemented as ufuncs. The old ``np.char`` namespace still is
374+
A new `numpy.strings` namespace has been created, where most of the string
375+
operations are implemented as ufuncs. The old `numpy.char` namespace still is
357376
available, and, wherever possible, uses the new ufuncs for greater performance.
358-
We recommend using the ``np.strings`` methods going forward. The ``np.char``
359-
namespace may be deprecated in the future.
360-
361-
362-
Ruff plugin
363-
-----------
364-
365-
All the changes that we covered in the previous sections can be automatically applied
366-
to the codebase with the dedicated Ruff rule,
367-
`NPY201 <https://docs.astral.sh/ruff/rules/numpy2-deprecation/>`_.
377+
We recommend using the `~numpy.strings` function going forward. The
378+
`~numpy.char` namespace may be deprecated in the future.
368379

369-
You should install Ruff, version ``0.2.0`` or above, and add the ``NPY201`` rule to
370-
your ``pyproject.toml``::
371380

372-
[tool.ruff.lint]
373-
select = ["NPY201"]
374-
375-
You can run NumPy 2.0 rule also directly from the command line::
376-
377-
$ ruff check path/to/code/ --select NPY201
381+
Other changes
382+
=============
378383

379384

380385
Note about pickled files

0 commit comments

Comments
 (0)