Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 34 additions & 16 deletions doc/source/whatsnew/v1.2.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,45 @@ prevent accidental introduction of duplicate labels, which can affect downstream

By default, duplicates continue to be allowed.

.. ipython:: python
.. code-block:: ipython

pd.Series([1, 2], index=['a', 'a'])
In [1]: pd.Series([1, 2], index=['a', 'a'])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

technically you don't need to change the block on data creation, but nbd

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By keeping it in a single directive, it gives a consistent code block (not 2 different code blocks with different look or inconsistent number), so in this case nicer I think.

Out[1]:
a 1
a 2
Length: 2, dtype: int64

.. ipython:: python
:okexcept:

pd.Series([1, 2], index=['a', 'a']).set_flags(allows_duplicate_labels=False)
In [2]: pd.Series([1, 2], index=['a', 'a']).set_flags(allows_duplicate_labels=False)
...
DuplicateLabelError: Index has duplicates.
positions
label
a [0, 1]

pandas will propagate the ``allows_duplicate_labels`` property through many operations.

.. ipython:: python
:okexcept:

a = (
pd.Series([1, 2], index=['a', 'b'])
.set_flags(allows_duplicate_labels=False)
)
a
# An operation introducing duplicates
a.reindex(['a', 'b', 'a'])
.. code-block:: ipython

In [3]: a = (
...: pd.Series([1, 2], index=['a', 'b'])
...: .set_flags(allows_duplicate_labels=False)
...: )

In [4]: a
Out[4]:
a 1
b 2
Length: 2, dtype: int64

# An operation introducing duplicates
In [5]: a.reindex(['a', 'b', 'a'])
...
DuplicateLabelError: Index has duplicates.
positions
label
a [0, 2]

[1 rows x 1 columns]

.. warning::

Expand Down