From 5d6d9a3263d7d75c7df51504980f9e99ebf01285 Mon Sep 17 00:00:00 2001 From: Sebastian Berg Date: Sun, 12 Jun 2022 13:58:49 -0700 Subject: [PATCH] DOC: Add example assigning an array using fill and tweak release note --- .../upcoming_changes/20924.compatibility.rst | 4 +++- numpy/core/_add_newdocs.py | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/doc/release/upcoming_changes/20924.compatibility.rst b/doc/release/upcoming_changes/20924.compatibility.rst index 0446b714fe9..02f3e9fdbac 100644 --- a/doc/release/upcoming_changes/20924.compatibility.rst +++ b/doc/release/upcoming_changes/20924.compatibility.rst @@ -8,4 +8,6 @@ now due to the fact that the logic is aligned with item assignment:: # is now identical to: arr[0] = scalar -Previously casting may have produced slightly different answers when using values that could not be represented in the target `dtype` or when using `object`s. +Previously casting may have produced slightly different answers when using +values that could not be represented in the target ``dtype`` or when the +target had ``object`` dtype. diff --git a/numpy/core/_add_newdocs.py b/numpy/core/_add_newdocs.py index fb9c30d9308..8ee48d24645 100644 --- a/numpy/core/_add_newdocs.py +++ b/numpy/core/_add_newdocs.py @@ -3437,6 +3437,24 @@ >>> a array([1., 1.]) + Fill expects a scalar value and always behaves the same as assigning + to a single array element. The following is a rare example where this + distinction is important: + + >>> a = np.array([None, None], dtype=object) + >>> a[0] = np.array(3) + >>> a + array([array(3), None], dtype=object) + >>> a.fill(np.array(3)) + >>> a + array([array(3), array(3)], dtype=object) + + Where other forms of assignments will array being assigned: + + >>> a[...] = np.array(3) + >>> a + array([3, 3], dtype=object) + """))