Skip to content

Commit 4fb6ede

Browse files
committed
DOC: add note on copy keyword to the 2.0 migration guide
1 parent 1f46066 commit 4fb6ede

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

doc/source/numpy_2_0_migration_guide.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,3 +383,23 @@ Note about pickled files
383383
NumPy 2.0 is designed to load pickle files created with NumPy 1.26,
384384
and vice versa. For versions 1.25 and earlier loading NumPy 2.0
385385
pickle file will throw an exception.
386+
387+
388+
Adapting to changes in the ``copy`` keyword
389+
-------------------------------------------
390+
391+
The :ref:`copy keyword behavior changes <copy-keyword-changes-2.0>` in
392+
`~numpy.asarray`, `~numpy.array` and `ndarray.__array__
393+
<numpy.ndarray.__array__>` may require these changes:
394+
395+
1. Code using ``np.array(..., copy=False)`` can in most cases be changed to
396+
``np.asarray(...)``. Older code tended to use ``np.array`` like this because
397+
it had less overhead than the default ``np.asarray`` copy-if-needed
398+
behavior. This is no longer true, and ``np.asarray`` is the preferred function.
399+
2. For code that explicitly needs to pass ``None/False`` meaning "copy if
400+
needed" in a way that's compatible with NumPy 1.x and 2.x, see
401+
`scipy#20172 <https://github.com/scipy/scipy/pull/20172>`__ for an example
402+
of how to do so.
403+
3. For any ``__array__`` method on a non-NumPy array-like object, a
404+
``copy=None`` keyword can be added to the signature - this will work with
405+
older NumPy versions as well.

doc/source/release/2.0.0-notes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,6 +1253,8 @@ Any out of bound axis value will now error, make sure to use
12531253

12541254
(`gh-25149 <https://github.com/numpy/numpy/pull/25149>`__)
12551255

1256+
.. _copy-keyword-changes-2.0:
1257+
12561258
New ``copy`` keyword meaning for ``array`` and ``asarray`` constructors
12571259
-----------------------------------------------------------------------
12581260

0 commit comments

Comments
 (0)