summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorSebastian Berg <sebastian@sipsolutions.net>2022-01-05 07:38:57 -0800
committerGitHub <noreply@github.com>2022-01-05 17:38:57 +0200
commit6a4e4a2ee2dbf6555b3ece09b3a4d84443c1b8cb (patch)
treecc7ddd5b201575289da21b9af464c6fdcfdcd971 /numpy
parentbb5c5eea76b70744dbadc66b54936b6930e3cf3b (diff)
downloadnumpy-6a4e4a2ee2dbf6555b3ece09b3a4d84443c1b8cb.tar.gz
DOC: Document that dtype, strides, shape attributes should not be set (#20730)
* DOC: Document that dtype, strides, shape attributes should not be set This adds a `warning` directive and makes sure that `view` is mentioned. (assignment to data is already deprecated, so not indcluding it here.) * Update numpy/core/_add_newdocs.py Co-authored-by: Matti Picus <matti.picus@gmail.com> Co-authored-by: Matti Picus <matti.picus@gmail.com>
Diffstat (limited to 'numpy')
-rw-r--r--numpy/core/_add_newdocs.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/numpy/core/_add_newdocs.py b/numpy/core/_add_newdocs.py
index 759801ccc..dcec768f0 100644
--- a/numpy/core/_add_newdocs.py
+++ b/numpy/core/_add_newdocs.py
@@ -2392,6 +2392,12 @@ add_newdoc('numpy.core.multiarray', 'ndarray', ('dtype',
"""
Data-type of the array's elements.
+ .. warning::
+
+ Setting ``arr.dtype`` is discouraged and may be deprecated in the
+ future. Setting will replace the ``dtype`` without modifying the
+ memory (see also `ndarray.view` and `ndarray.astype`).
+
Parameters
----------
None
@@ -2402,6 +2408,8 @@ add_newdoc('numpy.core.multiarray', 'ndarray', ('dtype',
See Also
--------
+ ndarray.astype : Cast the values contained in the array to a new data-type.
+ ndarray.view : Create a view of the same data but a different data-type.
numpy.dtype
Examples
@@ -2627,6 +2635,11 @@ add_newdoc('numpy.core.multiarray', 'ndarray', ('shape',
the array and the remaining dimensions. Reshaping an array in-place will
fail if a copy is required.
+ .. warning::
+
+ Setting ``arr.shape`` is discouraged and may be deprecated in the
+ future. Using `ndarray.reshape` is the preferred approach.
+
Examples
--------
>>> x = np.array([1, 2, 3, 4])
@@ -2697,6 +2710,12 @@ add_newdoc('numpy.core.multiarray', 'ndarray', ('strides',
A more detailed explanation of strides can be found in the
"ndarray.rst" file in the NumPy reference guide.
+ .. warning::
+
+ Setting ``arr.strides`` is discouraged and may be deprecated in the
+ future. `numpy.lib.stride_tricks.as_strided` should be preferred
+ to create a new view of the same data in a safer way.
+
Notes
-----
Imagine an array of 32-bit integers (each 4 bytes)::