Closed
Description
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 integers0
and1
.
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 commentedon 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.
jreback commentedon Jan 12, 2017
yep i will remove this section as well
DEPR: deprecate .ix in favor of .loc/.iloc
DEPR: deprecate .ix in favor of .loc/.iloc
DEPR: deprecate .ix in favor of .loc/.iloc
DEPR: deprecate .ix in favor of .loc/.iloc
DEPR: deprecate .ix in favor of .loc/.iloc
DEPR: deprecate .ix in favor of .loc/.iloc