Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
simon-b opened this issue Jan 12, 2017 · 2 comments
Closed
Labels
Docs Indexing Related to indexing on series/frames, not to indexes themselves
Milestone

Comments

@simon-b
Copy link

simon-b commented Jan 12, 2017

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.

@jorisvandenbossche
Copy link
Member

jorisvandenbossche commented Jan 12, 2017

@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.

@jorisvandenbossche jorisvandenbossche added Docs Indexing Related to indexing on series/frames, not to indexes themselves labels Jan 12, 2017
@jreback
Copy link
Contributor

jreback commented Jan 12, 2017

yep i will remove this section as well

@jreback jreback added this to the 0.20.0 milestone Jan 12, 2017
jreback added a commit to jreback/pandas that referenced this issue Jan 12, 2017
jreback added a commit to jreback/pandas that referenced this issue Jan 12, 2017
jreback added a commit to jreback/pandas that referenced this issue Jan 12, 2017
jreback added a commit to jreback/pandas that referenced this issue Jan 17, 2017
jreback added a commit to jreback/pandas that referenced this issue Jan 18, 2017
AnkurDedania pushed a commit to AnkurDedania/pandas that referenced this issue Mar 21, 2017
closes pandas-dev#14218
closes pandas-dev#15116

Author: Jeff Reback <[email protected]>

Closes pandas-dev#15113 from jreback/ix and squashes the following commits:

1544f50 [Jeff Reback] DEPR: deprecate .ix in favor of .loc/.iloc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Docs Indexing Related to indexing on series/frames, not to indexes themselves
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants