diff options
author | Charles Harris <charlesr.harris@gmail.com> | 2022-07-12 16:20:08 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-12 16:20:08 -0500 |
commit | 37846563156b3ed8287fc94d6a7d107a316c5ecf (patch) | |
tree | c559330630ad2e66111873df339d438ddc231ef8 /doc/source/reference | |
parent | b9061328b6c5c49b3f92b4e9793bb8c3ac11b544 (diff) | |
parent | 3163ae3d6ec2e791607df6c33dedeba311ed5c51 (diff) | |
download | numpy-37846563156b3ed8287fc94d6a7d107a316c5ecf.tar.gz |
Merge pull request #21837 from seberg/note-objects-null
DOC: Document expectation for object array initialization
Diffstat (limited to 'doc/source/reference')
-rw-r--r-- | doc/source/reference/c-api/array.rst | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/doc/source/reference/c-api/array.rst b/doc/source/reference/c-api/array.rst index f69c2bcb1..ccff2ae91 100644 --- a/doc/source/reference/c-api/array.rst +++ b/doc/source/reference/c-api/array.rst @@ -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 |