From 3a597f4bcaa93d1975f696012cb17818458c0abf Mon Sep 17 00:00:00 2001 From: Loic Diridollou Date: Sat, 11 Feb 2023 09:49:17 -0800 Subject: [PATCH 1/6] DOC: clarify inplace-ness of DataFrame.setitem --- pandas/core/frame.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 2650090a3f61a..7151fd6a76603 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -3867,23 +3867,26 @@ def _get_value(self, index, col, takeable: bool = False) -> Scalar: def isetitem(self, loc, value) -> None: """ - Set the given value in the column with position 'loc'. + Set the given value in the column with position `loc`. - This is a positional analogue to __setitem__. + This is a positional analogue to `__setitem__`. Parameters ---------- loc : int or sequence of ints + Index position for the column. value : scalar or arraylike + Value(s) for the column. Notes ----- - Unlike `frame.iloc[:, i] = value`, `frame.isetitem(loc, value)` will - _never_ try to set the values in place, but will always insert a new - array. + ``frame.isetimtem(loc, value)`` is an in-place method as it will + modify the frame in place (not returning a new object) but it will + not update the values of the column itself, it will instead insert + a new array. - In cases where `frame.columns` is unique, this is equivalent to - `frame[frame.columns[i]] = value`. + In cases where ``frame.columns`` is unique, this is equivalent to + ``frame[frame.columns[i]] = value``. """ if isinstance(value, DataFrame): if is_scalar(loc): From ec260fc0116f9c3833c961fee17cf8cda880fb88 Mon Sep 17 00:00:00 2001 From: Loic Diridollou Date: Mon, 13 Feb 2023 14:05:02 -0800 Subject: [PATCH 2/6] Update pandas/core/frame.py Co-authored-by: Joris Van den Bossche --- pandas/core/frame.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 7151fd6a76603..00f73d6d5ba0c 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -3869,7 +3869,7 @@ def isetitem(self, loc, value) -> None: """ Set the given value in the column with position `loc`. - This is a positional analogue to `__setitem__`. + This is a positional analogue to ``__setitem__``. Parameters ---------- From bfda14c12bc74fdc2e62c18aa3a51aed6aaa805e Mon Sep 17 00:00:00 2001 From: Loic Diridollou Date: Mon, 13 Feb 2023 14:05:09 -0800 Subject: [PATCH 3/6] Update pandas/core/frame.py Co-authored-by: Joris Van den Bossche --- pandas/core/frame.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 00f73d6d5ba0c..a7644bb6b13eb 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -3881,7 +3881,7 @@ def isetitem(self, loc, value) -> None: Notes ----- ``frame.isetimtem(loc, value)`` is an in-place method as it will - modify the frame in place (not returning a new object) but it will + modify the DataFrame in place (not returning a new object) but it will not update the values of the column itself, it will instead insert a new array. From 87b454db7208a0ea6d802d5b1ba672f07e0a7e9e Mon Sep 17 00:00:00 2001 From: Loic Diridollou Date: Mon, 13 Feb 2023 14:05:21 -0800 Subject: [PATCH 4/6] Update pandas/core/frame.py Co-authored-by: Joris Van den Bossche --- pandas/core/frame.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index a7644bb6b13eb..4139c8d33f106 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -3882,7 +3882,7 @@ def isetitem(self, loc, value) -> None: ----- ``frame.isetimtem(loc, value)`` is an in-place method as it will modify the DataFrame in place (not returning a new object) but it will - not update the values of the column itself, it will instead insert + not update the values of the column itself in place, it will instead insert a new array. In cases where ``frame.columns`` is unique, this is equivalent to From 85b9a770e148b8a28a7ac597fa173e953bd3b1bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Diridollou?= Date: Mon, 13 Feb 2023 14:20:48 -0800 Subject: [PATCH 5/6] Updating docstring of pandas/core/frame.py::isetitem with feedback. --- pandas/core/frame.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 3f7b7ac3fdd15..6c52dd3bbb53c 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -3882,10 +3882,11 @@ def isetitem(self, loc, value) -> None: Notes ----- - ``frame.isetimtem(loc, value)`` is an in-place method as it will - modify the DataFrame in place (not returning a new object) but it will - not update the values of the column itself in place, it will instead insert - a new array. + ``frame.isetitem(loc, value)`` is an in-place method as it will + modify the DataFrame in place (not returning a new object). In contrast to + ``frame.iloc[:, i] = value`` which will try to update the existing values in + place, ``frame.isetitem(loc, value)`` will not update the values of the column + itself in place, it will instead insert a new array. In cases where ``frame.columns`` is unique, this is equivalent to ``frame[frame.columns[i]] = value``. From 8805f78c16f3819f06d632b65e9565a9d48f953a Mon Sep 17 00:00:00 2001 From: Joris Van den Bossche Date: Fri, 17 Feb 2023 18:01:34 +0100 Subject: [PATCH 6/6] Update pandas/core/frame.py --- pandas/core/frame.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 6c52dd3bbb53c..59ebf9f55e558 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -3883,7 +3883,7 @@ def isetitem(self, loc, value) -> None: Notes ----- ``frame.isetitem(loc, value)`` is an in-place method as it will - modify the DataFrame in place (not returning a new object). In contrast to + modify the DataFrame in place (not returning a new object). In contrast to ``frame.iloc[:, i] = value`` which will try to update the existing values in place, ``frame.isetitem(loc, value)`` will not update the values of the column itself in place, it will instead insert a new array.