Skip to content

Commit 3902585

Browse files
DOC: trim error traceback in allows_duplicate_labels whatsnew entry (#38184)
1 parent 066a16c commit 3902585

File tree

1 file changed

+34
-16
lines changed

1 file changed

+34
-16
lines changed

doc/source/whatsnew/v1.2.0.rst

+34-16
Original file line numberDiff line numberDiff line change
@@ -24,27 +24,45 @@ prevent accidental introduction of duplicate labels, which can affect downstream
2424

2525
By default, duplicates continue to be allowed.
2626

27-
.. ipython:: python
27+
.. code-block:: ipython
2828
29-
pd.Series([1, 2], index=['a', 'a'])
29+
In [1]: pd.Series([1, 2], index=['a', 'a'])
30+
Out[1]:
31+
a 1
32+
a 2
33+
Length: 2, dtype: int64
3034
31-
.. ipython:: python
32-
:okexcept:
33-
34-
pd.Series([1, 2], index=['a', 'a']).set_flags(allows_duplicate_labels=False)
35+
In [2]: pd.Series([1, 2], index=['a', 'a']).set_flags(allows_duplicate_labels=False)
36+
...
37+
DuplicateLabelError: Index has duplicates.
38+
positions
39+
label
40+
a [0, 1]
3541
3642
pandas will propagate the ``allows_duplicate_labels`` property through many operations.
3743

38-
.. ipython:: python
39-
:okexcept:
40-
41-
a = (
42-
pd.Series([1, 2], index=['a', 'b'])
43-
.set_flags(allows_duplicate_labels=False)
44-
)
45-
a
46-
# An operation introducing duplicates
47-
a.reindex(['a', 'b', 'a'])
44+
.. code-block:: ipython
45+
46+
In [3]: a = (
47+
...: pd.Series([1, 2], index=['a', 'b'])
48+
...: .set_flags(allows_duplicate_labels=False)
49+
...: )
50+
51+
In [4]: a
52+
Out[4]:
53+
a 1
54+
b 2
55+
Length: 2, dtype: int64
56+
57+
# An operation introducing duplicates
58+
In [5]: a.reindex(['a', 'b', 'a'])
59+
...
60+
DuplicateLabelError: Index has duplicates.
61+
positions
62+
label
63+
a [0, 2]
64+
65+
[1 rows x 1 columns]
4866
4967
.. warning::
5068

0 commit comments

Comments
 (0)