Skip to content

Reindex versus ix gotchas documentation text does not match example code #15116

Closed
@simon-b

Description

@simon-b

In the gotchas documentation, in the section "Reindex versus ix gotchas", there is the following example:

In [28]: s = pd.Series([1, 2, 3], index=['a', 0, 1])

In [29]: s
Out[29]: 
a    1
0    2
1    3
dtype: int64

In [30]: s.ix[[0, 1]]
Out[30]: 
0    2
1    3
dtype: int64

In [31]: s.reindex([0, 1])
Out[31]: 
0    2
1    3
dtype: int64

The example shows both ix and reindex behaving the same. The subsequent text, however, states that they are expected to give different results:

Because the index in this case does not contain solely integers, ix falls back on integer indexing. By contrast, reindex only looks for the values passed in the index, thus finding the integers 0 and 1.

I am not sure if the indexing behaviour is correct and the documentation is wrong, or vice versa. It appears that in this case ix does not fall back on integer indexing while the text states that it does.

Activity

jorisvandenbossche

jorisvandenbossche commented on Jan 12, 2017

@jorisvandenbossche
Member

@simon-b Thanks for the catch!

Once this was correct, see eg the old docs of pandas 0.8 with this example: http://pandas.pydata.org/pandas-docs/version/0.8.0/gotchas.html#reindex-versus-ix-gotchas, but apparently that behaviour was changed (the docs of 0.9.0 already show the current behaviour) but the docs never updated.

Personally, I would expect ix to fallback to integer indexing in this case (certainly given the explanation in the docs on ix http://pandas.pydata.org/pandas-docs/stable/indexing.html#different-choices-for-indexing, which is actually also wrong). But the complexity and unpredictability of .ix is one of the reasons we are going to deprecate it (see #14218).
Given that, we should probably just remove this whole section.

jreback

jreback commented on Jan 12, 2017

@jreback
Contributor

yep i will remove this section as well

added this to the 0.20.0 milestone on Jan 12, 2017
added 5 commits that reference this issue on Jan 12, 2017
3cf48d3
823b975
eaf57e2
0bf5cb5
1544f50
added a commit that references this issue on Mar 21, 2017
f795d81
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    DocsIndexingRelated to indexing on series/frames, not to indexes themselves

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      Participants

      @jreback@simon-b@jorisvandenbossche

      Issue actions

        Reindex versus ix gotchas documentation text does not match example code · Issue #15116 · pandas-dev/pandas