From 0e3345c68d50a0346138dd11d42775702a62e66c Mon Sep 17 00:00:00 2001 From: Richard Shadrach Date: Fri, 12 Nov 2021 18:02:51 -0500 Subject: [PATCH 1/3] DOC: whatsnew for the improvement to warning messages --- doc/source/whatsnew/v1.4.0.rst | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/doc/source/whatsnew/v1.4.0.rst b/doc/source/whatsnew/v1.4.0.rst index 8db9be21ca4ef..3ff465b9365a1 100644 --- a/doc/source/whatsnew/v1.4.0.rst +++ b/doc/source/whatsnew/v1.4.0.rst @@ -15,6 +15,31 @@ including other versions of pandas. Enhancements ~~~~~~~~~~~~ +Improved warning messages +^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. _whatsnew_140.enhancements.warning_lineno: + +Previously, warning messages may have pointed to lines with the pandas library. Running the script ``setting_with_copy_warning.py`` + +.. code-block:: python + + import pandas as pd + + df = pd.DataFrame({'a': [1, 2, 3]}) + df[:2].loc[:, 'a'] = 5 + +with pandas 1.3 resulted in:: + + .../site-packages/pandas/core/indexing.py:1951: SettingWithCopyWarning: + A value is trying to be set on a copy of a slice from a DataFrame. + +This made it difficult to determine where the warning was being generated from. Now pandas will inspect the call stack, reporting the first line outside of the pandas library that gave rise to the warning. The output of the above script is now:: + + setting_with_copy_warning.py:4: SettingWithCopyWarning: + A value is trying to be set on a copy of a slice from a DataFrame. + + .. _whatsnew_140.enhancements.numeric_index: More flexible numeric dtypes for indexes From 743631251ac9961c46f915a022d28f0770f90d7a Mon Sep 17 00:00:00 2001 From: Richard Shadrach Date: Fri, 12 Nov 2021 18:09:38 -0500 Subject: [PATCH 2/3] fixup --- doc/source/whatsnew/v1.4.0.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/source/whatsnew/v1.4.0.rst b/doc/source/whatsnew/v1.4.0.rst index 3ff465b9365a1..7bd3286fb9707 100644 --- a/doc/source/whatsnew/v1.4.0.rst +++ b/doc/source/whatsnew/v1.4.0.rst @@ -15,11 +15,11 @@ including other versions of pandas. Enhancements ~~~~~~~~~~~~ +.. _whatsnew_140.enhancements.warning_lineno: + Improved warning messages ^^^^^^^^^^^^^^^^^^^^^^^^^ -.. _whatsnew_140.enhancements.warning_lineno: - Previously, warning messages may have pointed to lines with the pandas library. Running the script ``setting_with_copy_warning.py`` .. code-block:: python From 365d15b21d3e0b2ecef845e3274e99ad87a0c4cb Mon Sep 17 00:00:00 2001 From: Richard Shadrach Date: Fri, 12 Nov 2021 18:11:24 -0500 Subject: [PATCH 3/3] fixup --- doc/source/whatsnew/v1.4.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v1.4.0.rst b/doc/source/whatsnew/v1.4.0.rst index 7bd3286fb9707..94606e049018e 100644 --- a/doc/source/whatsnew/v1.4.0.rst +++ b/doc/source/whatsnew/v1.4.0.rst @@ -20,7 +20,7 @@ Enhancements Improved warning messages ^^^^^^^^^^^^^^^^^^^^^^^^^ -Previously, warning messages may have pointed to lines with the pandas library. Running the script ``setting_with_copy_warning.py`` +Previously, warning messages may have pointed to lines within the pandas library. Running the script ``setting_with_copy_warning.py`` .. code-block:: python