Skip to content

Commit 431bf0a

Browse files
committed
Merge branch 'main' into 2.0-highlights
[skip actions] [skip azp] [skip cirrus]
2 parents b25ea3e + 030d72b commit 431bf0a

40 files changed

+402
-252
lines changed

.circleci/config.yml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,6 @@ jobs:
6868
towncrier build --version $VERSION --yes
6969
./tools/ci/test_all_newsfragments_used.py
7070
71-
- run:
72-
name: run doctests on documentation
73-
command: |
74-
. venv/bin/activate
75-
# Note: keep these two checks separate, because they seem to
76-
# influence each other through changing global state (e.g., via
77-
# `np.polynomial.set_default_printstyle`)
78-
python tools/refguide_check.py --rst
79-
python tools/refguide_check.py --doctests
80-
8171
- run:
8272
name: build devdocs w/ref warnings
8373
command: |
@@ -104,6 +94,16 @@ jobs:
10494
path: doc/neps/_build/html/
10595
# destination: neps
10696

97+
- run:
98+
name: run doctests on documentation
99+
command: |
100+
. venv/bin/activate
101+
# Note: keep these two checks separate, because they seem to
102+
# influence each other through changing global state (e.g., via
103+
# `np.polynomial.set_default_printstyle`)
104+
python tools/refguide_check.py --rst
105+
python tools/refguide_check.py --doctests
106+
107107
- persist_to_workspace:
108108
root: ~/repo
109109
paths:

.github/workflows/wheels.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ jobs:
159159
name: ${{ matrix.python }}-${{ matrix.buildplat[1] }}-${{ matrix.buildplat[2] }}
160160
path: ./wheelhouse/*.whl
161161

162-
- uses: mamba-org/setup-micromamba@v1
162+
- uses: mamba-org/setup-micromamba@422500192359a097648154e8db4e39bdb6c6eed7
163163
with:
164164
# for installation of anaconda-client, required for upload to
165165
# anaconda.org
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Modified representation for ``Polynomial``
2+
------------------------------------------
3+
The representation method for `numpy.polynomial.Polynomial` was updated to include the domain in the representation.
4+
The plain text and latex representations are now consistent.
5+
For example the output of ``str(np.polynomial.Polynomial([1, 1], domain=[.1, .2]))`` used to be ``1.0 + 1.0 x``, but
6+
now is ``1.0 + 1.0 (-3.0000000000000004 + 20.0 x)``.

doc/source/numpy_2_0_migration_guide.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ dtype/descriptor itself is attached to an array (e.g. ``arr->descr->elsize``)
117117
this is best replaced with ``PyArray_ITEMSIZE(arr)``.
118118

119119
Where not possible, new accessor functions are required:
120+
120121
* ``PyDataType_ELSIZE`` and ``PyDataType_SET_ELSIZE`` (note that the result
121122
is now ``npy_intp`` and not ``int``).
122123
* ``PyDataType_ALIGNENT``

doc/source/reference/c-api/array.rst

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,32 @@ and its sub-types).
3838
3939
Return the (builtin) typenumber for the elements of this array.
4040
41+
.. c:function:: int PyArray_Pack( \
42+
const PyArray_Descr *descr, void *item, const PyObject *value)
43+
44+
.. versionadded:: 2.0
45+
46+
Sets the memory location ``item`` of dtype ``descr`` to ``value``.
47+
48+
The function is equivalent to setting a single array element with a Python
49+
assignment. Returns 0 on success and -1 with an error set on failure.
50+
51+
.. note::
52+
If the ``descr`` has the :c:data:`NPY_NEEDS_INIT` flag set, the
53+
data must be valid or the memory zeroed.
54+
4155
.. c:function:: int PyArray_SETITEM( \
4256
PyArrayObject* arr, void* itemptr, PyObject* obj)
4357
4458
Convert obj and place it in the ndarray, *arr*, at the place
4559
pointed to by itemptr. Return -1 if an error occurs or 0 on
4660
success.
4761
62+
.. note::
63+
In general, prefer the use of :c:func:`PyArray_Pack` when
64+
handling arbitrary Python objects. Setitem is for example not able
65+
to handle arbitrary casts between different dtypes.
66+
4867
.. c:function:: void PyArray_ENABLEFLAGS(PyArrayObject* arr, int flags)
4968
5069
.. versionadded:: 1.7
@@ -762,7 +781,7 @@ cannot not be accessed directly.
762781
.. versionchanged:: 2.0
763782
Prior to NumPy 2.0 the ABI was different but unnecessary large for user
764783
DTypes. These accessors were all added in 2.0 and can be backported
765-
(see :ref:`_migration_c_descr`).
784+
(see :ref:`migration_c_descr`).
766785
767786
.. c:function:: npy_intp PyDataType_ELSIZE(PyArray_Descr *descr)
768787

doc/source/reference/c-api/types-and-structures.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ PyArrayDescr_Type and PyArray_Descr
290290
npy_intp alignment;
291291
NpyAuxData *c_metadata;
292292
npy_hash_t hash;
293-
void *reserved_null; // unused field, must be NULL.
293+
void *reserved_null[2]; // unused field, must be NULLed.
294294
} PyArray_Descr;
295295
296296
Some dtypes have additional members which are accessible through

doc/source/release/2.0.0-notes.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,12 @@ C API changes
467467

468468
(`gh-25789 <https://github.com/numpy/numpy/pull/25789>`__)
469469

470+
* NumPy now defines :c:function:`PyArray_Pack` to set an individual memory
471+
address. Unlike ``PyArray_SETITEM`` this function is equivalent to setting
472+
an individual array item and does not require a NumPy array input.
473+
474+
(`gh-25954 <https://github.com/numpy/numpy/pull/25954>`__)
475+
470476
* The ``->f`` slot has been removed from ``PyArray_Descr``.
471477
If you use this slot, replace accessing it with
472478
``PyDataType_GetArrFuncs`` (see its documentation and the

numpy/__init__.cython-30.pxd

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -289,14 +289,31 @@ cdef extern from "numpy/arrayobject.h":
289289
# directly accessing this field.
290290
cdef char byteorder
291291
cdef int type_num
292-
cdef int itemsize "elsize"
293-
cdef int alignment
294-
cdef object fields
295-
cdef tuple names
292+
293+
@property
294+
cdef inline npy_intp itemsize(self) nogil:
295+
return PyDataType_ELSIZE(self)
296+
297+
@property
298+
cdef inline npy_intp alignment(self) nogil:
299+
return PyDataType_ALIGNMENT(self)
300+
301+
# Use fields/names with care as they may be NULL. You must check
302+
# for this using PyDataType_HASFIELDS.
303+
@property
304+
cdef inline object fields(self):
305+
return <object>PyDataType_FIELDS(self)
306+
307+
@property
308+
cdef inline tuple names(self):
309+
return <tuple>PyDataType_NAMES(self)
310+
296311
# Use PyDataType_HASSUBARRAY to test whether this field is
297312
# valid (the pointer can be NULL). Most users should access
298313
# this field via the inline helper method PyDataType_SHAPE.
299-
cdef PyArray_ArrayDescr* subarray
314+
@property
315+
cdef inline PyArray_ArrayDescr* subarray(self) nogil:
316+
return PyDataType_SUBARRAY(self)
300317

301318
@property
302319
cdef inline npy_uint64 flags(self) nogil:
@@ -455,6 +472,13 @@ cdef extern from "numpy/arrayobject.h":
455472
bint PyTypeNum_ISEXTENDED(int) nogil
456473
bint PyTypeNum_ISOBJECT(int) nogil
457474

475+
npy_intp PyDataType_ELSIZE(dtype) nogil
476+
npy_intp PyDataType_ALIGNMENT(dtype) nogil
477+
PyObject* PyDataType_METADATA(dtype) nogil
478+
PyArray_ArrayDescr* PyDataType_SUBARRAY(dtype) nogil
479+
PyObject* PyDataType_NAMES(dtype) nogil
480+
PyObject* PyDataType_FIELDS(dtype) nogil
481+
458482
bint PyDataType_ISBOOL(dtype) nogil
459483
bint PyDataType_ISUNSIGNED(dtype) nogil
460484
bint PyDataType_ISSIGNED(dtype) nogil

numpy/__init__.pxd

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -286,14 +286,9 @@ cdef extern from "numpy/arrayobject.h":
286286
# Flags are not directly accessible on Cython <3. Use PyDataType_FLAGS.
287287
# cdef char flags
288288
cdef int type_num
289-
cdef int itemsize "elsize"
290-
cdef int alignment
291-
cdef object fields
292-
cdef tuple names
293-
# Use PyDataType_HASSUBARRAY to test whether this field is
294-
# valid (the pointer can be NULL). Most users should access
295-
# this field via the inline helper method PyDataType_SHAPE.
296-
cdef PyArray_ArrayDescr* subarray
289+
# itemsize/elsize, alignment, fields, names, and subarray must
290+
# use the `PyDataType_*` accessor macros. With Cython 3 you can
291+
# still use getter attributes `dtype.itemsize`
297292

298293
ctypedef class numpy.flatiter [object PyArrayIterObject, check_size ignore]:
299294
# Use through macros
@@ -375,6 +370,14 @@ cdef extern from "numpy/arrayobject.h":
375370
bint PyTypeNum_ISEXTENDED(int) nogil
376371
bint PyTypeNum_ISOBJECT(int) nogil
377372

373+
npy_intp PyDataType_ELSIZE(dtype) nogil
374+
void PyDataType_SET_ELSIZE(dtype, npy_intp) nogil
375+
npy_intp PyDataType_ALIGNMENT(dtype) nogil
376+
PyObject* PyDataType_METADATA(dtype) nogil
377+
PyArray_ArrayDescr* PyDataType_SUBARRAY(dtype) nogil
378+
PyObject* PyDataType_NAMES(dtype) nogil
379+
PyObject* PyDataType_FIELDS(dtype) nogil
380+
378381
bint PyDataType_ISBOOL(dtype) nogil
379382
bint PyDataType_ISUNSIGNED(dtype) nogil
380383
bint PyDataType_ISSIGNED(dtype) nogil

numpy/_core/_add_newdocs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1698,7 +1698,7 @@
16981698

16991699
add_newdoc('numpy._core.multiarray', 'arange',
17001700
"""
1701-
arange(start, / [, stop[, step,], dtype=None, *, device=None,, like=None)
1701+
arange([start,] stop[, step,], dtype=None, *, device=None, like=None)
17021702
17031703
Return evenly spaced values within a given interval.
17041704

0 commit comments

Comments
 (0)