Skip to content

DOC: Is the behaviour of setitem with repeated keys defined? #53996

Open
@wence-

Description

@wence-

Pandas version checks

  • I have checked that the issue still exists on the latest versions of the docs on main here

Location of the documentation

https://pandas.pydata.org/docs/user_guide/indexing.html

(and loc/iloc docstrings)

Documentation problem

Suppose that I do this:

import pandas as pd

s = pd.Series([1, 2, 3, 4])

s.iloc[[0, 0]] = [7, 8]
# Or, similarly with `loc`

This is in some sense a nonsense thing to do, but is it therefore "undefined behaviour" (in the standardese sense) and pandas might do anything. Or is it defined that "last index wins"? Or is it an implementation detail?

Suggested fix for documentation

Clarifying what is/is not allowed when setting values would be useful. My guess here is that the fact that the last value wins out is an implementation detail which probably should not be relied on.

Metadata

Metadata

Assignees

Labels

DocsIndexRelated to the Index class or subclasses

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions