Skip to content

Commit

Permalink
Merge pull request #21837 from seberg/note-objects-null
Browse files Browse the repository at this point in the history
DOC: Document expectation for object array initialization
  • Loading branch information
charris committed Jul 12, 2022
2 parents b906132 + 3163ae3 commit 3784656
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions doc/source/reference/c-api/array.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1323,6 +1323,29 @@ User-defined data types
Special functions for NPY_OBJECT
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. warning::
When working with arrays or buffers filled with objects NumPy tries to
ensure such buffers are filled with ``None`` before any data may be read.
However, code paths may existed where an array is only initialized to
``NULL``.
NumPy itself accepts ``NULL`` as an alias for ``None``, but may ``assert``
non-``NULL`` when compiled in debug mode.
Because NumPy is not yet consistent about initialization with None,
users **must** expect a value of ``NULL`` when working with buffers created
by NumPy. Users **should** also ensure to pass fully initialized buffers
to NumPy, since NumPy may make this a strong requirement in the future.
There is currently an intention to ensure that NumPy always initalizes
object arrays before they may be read. Any failure to do so will be
regarded as a bug.
In the future, users may be able to rely on non-NULL values when reading
from any array, although exceptions for writing to freshly created arrays
may remain (e.g. for output arrays in ufunc code). As of NumPy 1.23
known code paths exists where proper filling is not done.
.. c:function:: int PyArray_INCREF(PyArrayObject* op)
Used for an array, *op*, that contains any Python objects. It
Expand Down

0 comments on commit 3784656

Please sign in to comment.