Skip to content

Commit 0c54c6e

Browse files
authored
Merge pull request numpy#25937 from rgommers/2.0-highlights
DOC: 2.0 release highlights and compat notes changes
2 parents b0d317b + ad4d6ee commit 0c54c6e

File tree

7 files changed

+237
-45
lines changed

7 files changed

+237
-45
lines changed

doc/release/upcoming_changes/21760.compatibility.rst

Lines changed: 0 additions & 6 deletions
This file was deleted.

doc/source/dev/depending_on_numpy.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@ alongside other, newer packages
175175
`here for SciPy <https://github.com/MacPython/scipy-wheels>`__.
176176

177177

178+
.. _numpy-2-abi-handling:
179+
178180
NumPy 2.0-specific advice
179181
~~~~~~~~~~~~~~~~~~~~~~~~~
180182

doc/source/numpy_2_0_migration_guide.rst

Lines changed: 64 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,33 @@ NumPy 2.0 migration guide
55
*************************
66

77
This document contains a set of instructions on how to update your code to
8-
work with Numpy 2.0.
8+
work with NumPy 2.0. It covers changes in NumPy's Python and C APIs.
9+
10+
.. note::
11+
12+
Note that NumPy 2.0 also breaks binary compatibility - if you are
13+
distributing binaries for a Python package that depends on NumPy's C API,
14+
please see :ref:`numpy-2-abi-handling`.
15+
16+
17+
18+
Ruff plugin
19+
===========
20+
21+
Many of the changes covered in the 2.0 release notes and in this migration
22+
guide can be automatically adapted to in downstream code with a dedicated
23+
`Ruff <https://docs.astral.sh/ruff/>`__ rule, namely rule
24+
`NPY201 <https://docs.astral.sh/ruff/rules/numpy2-deprecation/>`__.
25+
26+
You should install ``ruff>=0.2.0`` and add the ``NPY201`` rule to your
27+
``pyproject.toml``::
28+
29+
[tool.ruff.lint]
30+
select = ["NPY201"]
31+
32+
You can also apply the NumPy 2.0 rule directly from the command line::
33+
34+
$ ruff check path/to/code/ --select NPY201
935

1036

1137
.. _migration_promotion_changes:
@@ -189,8 +215,8 @@ The underlying type remains a struct under C++ (all of the above still remains
189215
valid).
190216

191217

192-
Namespace changes
193-
=================
218+
Changes to namespaces
219+
=====================
194220

195221
In NumPy 2.0 certain functions, modules, and constants were moved or removed
196222
to make the NumPy namespace more user-friendly by removing unnecessary or
@@ -299,8 +325,8 @@ downstream libraries we don't provide any information on how to replace them:
299325
``MAY_SHARE_BOUNDS``]
300326

301327

302-
Lib namespace
303-
-------------
328+
numpy.lib namespace
329+
-------------------
304330

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

324350

325-
Core namespace
326-
--------------
351+
numpy.core namespace
352+
--------------------
327353

328-
``np.core`` namespace is now officially private and has been renamed to ``np._core``.
354+
The ``np.core`` namespace is now officially private and has been renamed to ``np._core``.
329355
The user should never fetch members from the ``_core`` directly - instead the main
330356
namespace should be used to access the attribute in question. The layout of the ``_core``
331357
module might change in the future without notice, contrary to public modules which adhere
@@ -334,8 +360,8 @@ then you should either use the existing API or, in case it's infeasible, reach o
334360
with a request to restore the removed entry.
335361

336362

337-
ndarray and scalar namespace
338-
----------------------------
363+
ndarray and scalar methods
364+
--------------------------
339365

340366
A few methods from ``np.ndarray`` and ``np.generic`` scalar classes have been removed.
341367
The table below provides replacements for the removed members:
@@ -350,32 +376,18 @@ setitem Use ``arr[index] = value`` instead.
350376
====================== ========================================================
351377

352378

353-
Strings namespace
354-
-----------------
379+
numpy.strings namespace
380+
-----------------------
355381

356-
A new ``np.strings`` namespace has been created, where most of the string
357-
operations are implemented as ufuncs. The old ``np.char`` namespace still is
382+
A new `numpy.strings` namespace has been created, where most of the string
383+
operations are implemented as ufuncs. The old `numpy.char` namespace still is
358384
available, and, wherever possible, uses the new ufuncs for greater performance.
359-
We recommend using the ``np.strings`` methods going forward. The ``np.char``
360-
namespace may be deprecated in the future.
361-
362-
363-
Ruff plugin
364-
-----------
385+
We recommend using the `~numpy.strings` functions going forward. The
386+
`~numpy.char` namespace may be deprecated in the future.
365387

366-
All the changes that we covered in the previous sections can be automatically applied
367-
to the codebase with the dedicated Ruff rule,
368-
`NPY201 <https://docs.astral.sh/ruff/rules/numpy2-deprecation/>`_.
369388

370-
You should install Ruff, version ``0.2.0`` or above, and add the ``NPY201`` rule to
371-
your ``pyproject.toml``::
372-
373-
[tool.ruff.lint]
374-
select = ["NPY201"]
375-
376-
You can run NumPy 2.0 rule also directly from the command line::
377-
378-
$ ruff check path/to/code/ --select NPY201
389+
Other changes
390+
=============
379391

380392

381393
Note about pickled files
@@ -384,3 +396,23 @@ Note about pickled files
384396
NumPy 2.0 is designed to load pickle files created with NumPy 1.26,
385397
and vice versa. For versions 1.25 and earlier loading NumPy 2.0
386398
pickle file will throw an exception.
399+
400+
401+
Adapting to changes in the ``copy`` keyword
402+
-------------------------------------------
403+
404+
The :ref:`copy keyword behavior changes <copy-keyword-changes-2.0>` in
405+
`~numpy.asarray`, `~numpy.array` and `ndarray.__array__
406+
<numpy.ndarray.__array__>` may require these changes:
407+
408+
1. Code using ``np.array(..., copy=False)`` can in most cases be changed to
409+
``np.asarray(...)``. Older code tended to use ``np.array`` like this because
410+
it had less overhead than the default ``np.asarray`` copy-if-needed
411+
behavior. This is no longer true, and ``np.asarray`` is the preferred function.
412+
2. For code that explicitly needs to pass ``None``/``False`` meaning "copy if
413+
needed" in a way that's compatible with NumPy 1.x and 2.x, see
414+
`scipy#20172 <https://github.com/scipy/scipy/pull/20172>`__ for an example
415+
of how to do so.
416+
3. For any ``__array__`` method on a non-NumPy array-like object, a
417+
``copy=None`` keyword can be added to the signature - this will work with
418+
older NumPy versions as well.

doc/source/reference/module_structure.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
.. _module-structure:
2+
13
************************
24
NumPy's module structure
35
************************

doc/source/reference/routines.linalg.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ Matrix and vector products
5757
linalg.multi_dot
5858
vdot
5959
vecdot
60+
linalg.vecdot
6061
inner
6162
outer
6263
matmul

0 commit comments

Comments
 (0)