@@ -24,27 +24,45 @@ prevent accidental introduction of duplicate labels, which can affect downstream
24
24
25
25
By default, duplicates continue to be allowed.
26
26
27
- .. ipython :: python
27
+ .. code-block :: ipython
28
28
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
30
34
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]
35
41
36
42
pandas will propagate the ``allows_duplicate_labels `` property through many operations.
37
43
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]
48
66
49
67
.. warning ::
50
68
0 commit comments