Skip to content

Commit 33daff1

Browse files
authored
DOC: whatsnew for the improvement to warning messages (#44419)
1 parent 63a9d13 commit 33daff1

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

doc/source/whatsnew/v1.4.0.rst

+25
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,31 @@ including other versions of pandas.
1515
Enhancements
1616
~~~~~~~~~~~~
1717

18+
.. _whatsnew_140.enhancements.warning_lineno:
19+
20+
Improved warning messages
21+
^^^^^^^^^^^^^^^^^^^^^^^^^
22+
23+
Previously, warning messages may have pointed to lines within the pandas library. Running the script ``setting_with_copy_warning.py``
24+
25+
.. code-block:: python
26+
27+
import pandas as pd
28+
29+
df = pd.DataFrame({'a': [1, 2, 3]})
30+
df[:2].loc[:, 'a'] = 5
31+
32+
with pandas 1.3 resulted in::
33+
34+
.../site-packages/pandas/core/indexing.py:1951: SettingWithCopyWarning:
35+
A value is trying to be set on a copy of a slice from a DataFrame.
36+
37+
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::
38+
39+
setting_with_copy_warning.py:4: SettingWithCopyWarning:
40+
A value is trying to be set on a copy of a slice from a DataFrame.
41+
42+
1843
.. _whatsnew_140.enhancements.numeric_index:
1944

2045
More flexible numeric dtypes for indexes

0 commit comments

Comments
 (0)