From e91cd917ca8ff75322b38042caece010066d14ff Mon Sep 17 00:00:00 2001 From: smij720 Date: Mon, 27 Nov 2023 22:16:39 -0800 Subject: [PATCH 1/4] Add doctest showing dtype changing --- pandas/core/frame.py | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 5d05983529fba..6d84a283eea09 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -8813,26 +8813,27 @@ def update( 1 b e 2 c f - For Series, its name attribute must be set. - >>> df = pd.DataFrame({'A': ['a', 'b', 'c'], ... 'B': ['x', 'y', 'z']}) - >>> new_column = pd.Series(['d', 'e'], name='B', index=[0, 2]) - >>> df.update(new_column) + >>> new_df = pd.DataFrame({'B': ['d', 'f']}, index=[0, 2]) + >>> df.update(new_df) >>> df A B 0 a d 1 b y - 2 c e + 2 c f + + For Series, its name attribute must be set. + >>> df = pd.DataFrame({'A': ['a', 'b', 'c'], ... 'B': ['x', 'y', 'z']}) - >>> new_df = pd.DataFrame({'B': ['d', 'e']}, index=[1, 2]) - >>> df.update(new_df) + >>> new_column = pd.Series(['d', 'e', 'f'], name='B') + >>> df.update(new_column) >>> df A B - 0 a x - 1 b d - 2 c e + 0 a d + 1 b e + 2 c f If `other` contains NaNs the corresponding values are not updated in the original dataframe. @@ -8846,6 +8847,16 @@ def update( 0 1 4 1 2 500 2 3 6 + + Updating a dataframe can modify its data types + + >>> df = pd.DataFrame({'A': [1, 2, 3]}) + >>> df['A'].dtype.name + int64 + >>> df_new = pd.DataFrame({'A': [True]}) + >>> df.update(df_new) + >>> df['A'].dtype.name + object """ if not PYPY and using_copy_on_write(): if sys.getrefcount(self) <= REF_COUNT: From 1c414e944ca58dd75d7b7a8db49a3286dc72c72a Mon Sep 17 00:00:00 2001 From: smij720 Date: Mon, 27 Nov 2023 22:33:58 -0800 Subject: [PATCH 2/4] Fix docstring results --- pandas/core/frame.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 6d84a283eea09..38e24993d7062 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -8852,11 +8852,11 @@ def update( >>> df = pd.DataFrame({'A': [1, 2, 3]}) >>> df['A'].dtype.name - int64 + 'int64' >>> df_new = pd.DataFrame({'A': [True]}) >>> df.update(df_new) >>> df['A'].dtype.name - object + 'object' """ if not PYPY and using_copy_on_write(): if sys.getrefcount(self) <= REF_COUNT: From 846ca2ea171262f60f1f812e9c0e99e32c9c004b Mon Sep 17 00:00:00 2001 From: smij720 Date: Mon, 27 Nov 2023 22:42:51 -0800 Subject: [PATCH 3/4] Tidy --- 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 38e24993d7062..5c6bdc02f9221 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -8848,7 +8848,7 @@ def update( 1 2 500 2 3 6 - Updating a dataframe can modify its data types + Updating a dataframe can modify its data types. >>> df = pd.DataFrame({'A': [1, 2, 3]}) >>> df['A'].dtype.name From e35d635751a3add4521398962bdede959d5a1cdc Mon Sep 17 00:00:00 2001 From: smij720 Date: Tue, 28 Nov 2023 17:56:38 -0800 Subject: [PATCH 4/4] Remove docs for changing dtype --- pandas/core/frame.py | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index ddc04b3f53b04..b6493614e05a0 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -8860,16 +8860,6 @@ def update( 0 1 4 1 2 500 2 3 6 - - Updating a dataframe can modify its data types. - - >>> df = pd.DataFrame({'A': [1, 2, 3]}) - >>> df['A'].dtype.name - 'int64' - >>> df_new = pd.DataFrame({'A': [True]}) - >>> df.update(df_new) - >>> df['A'].dtype.name - 'object' """ if not PYPY and using_copy_on_write(): if sys.getrefcount(self) <= REF_COUNT: