@@ -342,6 +342,31 @@ C API changes
342
342
343
343
(`gh-25789 <https://github.com/numpy/numpy/pull/25789 >`__)
344
344
345
+ * The ``->f `` slot has been removed from ``PyArray_Descr ``.
346
+ If you use this slot, replace accessing it with
347
+ ``PyDataType_GetArrFuncs `` (see its documentation and the
348
+ :ref: `numpy-2-migration-guide `). In some cases using other functions like
349
+ ``PyArray_GETITEM `` may be an alternatives.
350
+ * ``PyArray_GETITEM `` and ``PyArray_SETITEM `` now require the import of the
351
+ NumPy API table to be used and are no longer defined in ``ndarraytypes.h ``.
352
+
353
+ (`gh-25812 <https://github.com/numpy/numpy/pull/25812 >`__)
354
+
355
+ * Due to runtime dependencies, the definition for functionality accessing
356
+ the dtype flags was moved from ``numpy/ndarraytypes.h `` and is only available
357
+ after including ``numpy/ndarrayobject.h `` as it requires ``import_array() ``.
358
+ This includes ``PyDataType_FLAGCHK ``, ``PyDataType_REFCHK `` and
359
+ ``NPY_BEGIN_THREADS_DESCR ``.
360
+ * The dtype flags on ``PyArray_Descr `` must now be accessed through the
361
+ ``PyDataType_FLAGS `` inline function to be compatible with both 1.x and 2.x.
362
+ This function is defined in ``npy_2_compat.h `` to allow backporting.
363
+ Most or all users should use ``PyDataType_FLAGCHK `` which is available on
364
+ 1.x and does not require backporting.
365
+ Cython users should use Cython 3. Otherwise access will go through Python
366
+ unless they use ``PyDataType_FLAGCHK `` instead.
367
+
368
+ (`gh-25816 <https://github.com/numpy/numpy/pull/25816 >`__)
369
+
345
370
Datetime functionality exposed in the C API and Cython bindings
346
371
---------------------------------------------------------------
347
372
@@ -357,6 +382,7 @@ external libraries.
357
382
358
383
Const correctness for the generalized ufunc C API
359
<
6D40
/td>384
-------------------------------------------------
385
+
360
386
The NumPy C API's functions for constructing generalized ufuncs
361
387
(``PyUFunc_FromFuncAndData ``, ``PyUFunc_FromFuncAndDataAndSignature ``,
362
388
``PyUFunc_FromFuncAndDataAndSignatureAndIdentity ``) take ``types `` and ``data ``
@@ -384,6 +410,7 @@ replaced with ``NPY_RAVEL_AXIS``. See also :ref:`migration_maxdims`.
384
410
385
411
``NPY_MAXARGS `` not constant and ``PyArrayMultiIterObject `` size change
386
412
-----------------------------------------------------------------------
413
+
387
414
Since ``NPY_MAXARGS `` was increased, it is now a runtime constant and not
388
415
compile-time constant anymore.
389
416
We expect almost no users to notice this. But if used for stack allocations
@@ -398,14 +425,50 @@ to avoid issues with Cython.
398
425
399
426
Required changes for custom legacy user dtypes
400
427
----------------------------------------------
428
+
401
429
In order to improve our DTypes it is unfortunately necessary
402
- to break with A
9E88
BI, which requires some changes for dtypes registered
403
- with `PyArray_RegisterDataType `.
404
- Please see the documentation of `PyArray_RegisterDataType ` for how
430
+ to break the ABI, which requires some changes for dtypes registered
431
+ with `` PyArray_RegisterDataType ` `.
432
+ Please see the documentation of `` PyArray_RegisterDataType ` ` for how
405
433
to adapt your code and achieve compatibility with both 1.x and 2.x.
406
434
407
435
(`gh-25792 <https://github.com/numpy/numpy/pull/25792 >`__)
408
436
437
+ New Public DType API
438
+ --------------------
439
+
440
+ The C implementation of the NEP 42 DType API is now public. While the DType API
441
+ has shipped in NumPy for a few versions, it was only usable in sessions with a
442
+ special environment variable set. It is now possible to write custom DTypes
443
+ outside of NumPy using the new DType API and the normal ``import_array() ``
444
+ mechanism for importing the numpy C API.
445
+
446
+ See :ref: `dtype-api ` for more details about the API. As always with a new
447
+ feature, please report any bugs you run into implementing or using a new
448
+ DType. It is likely that downstream C code that works with dtypes will need to
449
+ be updated to work correctly with new DTypes.
450
+
451
+ (`gh-25754 <https://github.com/numpy/numpy/pull/25754 >`__)
452
+
453
+ New C-API import functions
454
+ --------------------------
455
+
456
+ We have now added ``PyArray_ImportNumPyAPI `` and ``PyUFunc_ImportUFuncAPI ``
457
+ as static inline functions to import the NumPy C-API tables.
458
+ The new functions have two advantages over ``import_array `` and
459
+ ``import_ufunc ``:
460
+
461
+ - They check whether the import was already performed and are light-weight
462
+ if not, allowing to add them judiciously (although this is not preferable
463
+ in most cases).
464
+ - The old mechanisms were macros rather than functions which included a
465
+ ``return `` statement.
466
+
467
+ The ``PyArray_ImportNumPyAPI() `` function is included in ``npy_2_compat.h ``
468
+ for simpler backporting.
469
+
470
+ (`gh-25866 <https://github.com/numpy/numpy/pull/25866 >`__)
471
+
409
472
410
473
NumPy 2.0 C API removals
411
474
========================
@@ -983,6 +1046,14 @@ Changes
983
1046
984
1047
(`gh-25080 <https://github.com/numpy/numpy/pull/25080 >`__)
985
1048
1049
+ * The ``dtype.flags `` value was previously usually stored as a signed integer.
1050
+ This means that the aligned dtype struct flag lead to negative flags being
1051
+ set (-128 rather than 128). This flag is now stored unsigned (positive). Code
1052
+ which checks flags manually may need to adapt. This may include code
1053
+ compiled with Cython 0.29.x.
1054
+
1055
+ (`gh-25816 <https://github.com/numpy/numpy/pull/25816 >`__)
1056
+
986
1057
Representation of NumPy scalars changed
987
1058
---------------------------------------
988
1059
As per :ref: `NEP 51 <NEP51 >`, the scalar representation has been
@@ -1127,6 +1198,32 @@ Any out of bound axis value will now error, make sure to use
1127
1198
1128
1199
(`gh-25149 <https://github.com/numpy/numpy/pull/25149 >`__)
1129
1200
1201
+ New ``copy `` keyword meaning for `numpy.array ` and `numpy.asarray `
1202
+ ------------------------------------------------------------------
1203
+ Now `numpy.array ` and `numpy.asarray ` support three values for ``copy `` parameter:
1204
+
1205
+ * ``None `` - A copy will only be made if it is necessary.
1206
+ * ``True `` - Always make a copy.
1207
+ * ``False `` - Never make a copy. If a copy is required a ``ValueError `` is raised.
1208
+
1209
+ The meaning of ``False `` changed as it now raises an exception if a copy is needed.
1210
+
1211
+ (`gh-25168 <https://github.com/numpy/numpy/pull/25168 >`__)
1212
+
1213
+ The ``__array__ `` special method now takes a ``copy `` keyword argument.
1214
+ -----------------------------------------------------------------------
1215
+
1216
+ NumPy will pass ``copy `` to the ``__array__ `` special method in situations where
1217
+ it would be set to a non-default value (e.g. in a call to
1218
+ ``np.asarray(some_object, copy=False) ``). Currently, if an
1219
+ unexpected keyword argument error is raised after this, NumPy will print a
1220
+ warning and re-try without the ``copy `` keyword argument. Implementations of
1221
+ objects implementing the ``__array__ `` protocol should accept a ``copy `` keyword
1222
+ argument with the same meaning as when passed to `numpy.array ` or
1223
+ `numpy.asarray `.
1224
+
1225
+ (`gh-25168 <https://github.com/numpy/numpy/pull/25168 >`__)
1226
+
1130
1227
Cleanup of initialization of ``numpy.dtype `` with strings with commas
1131
1228
---------------------------------------------------------------------
1132
1229
The interpretation of strings with commas is changed slightly, in that a
0 commit comments