Skip to content
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

COMPAT: issues w.r.t. deprecating float indexers #12322

Closed
jreback opened this issue Feb 13, 2016 · 1 comment
Closed

COMPAT: issues w.r.t. deprecating float indexers #12322

jreback opened this issue Feb 13, 2016 · 1 comment
Labels
Compat pandas objects compatability with Numpy or Python functions
Milestone

Comments

@jreback
Copy link
Contributor

jreback commented Feb 13, 2016

from #12246

@jorisvandenbossche

Some after merge feedback:

I took a look and I also like the logic now as how you explained it in your last post (for label based indexing: if the label evaluates as equal, then it is interpreted as the existing label)

A few things:

  • The whatsnew needs to be updated (as it still says it raises now for all cases, as you started the PR)
maybe mention that it only is about positional indexing? Otherwise people could think FloatIndex is removed.
  • (minor) When using iloc with a float (so the case it still should raise an error), the error message is not fully correct:

    In [76]: s2 = s.copy()
    
    In [77]: s2.iloc[2.0] = 10
    TypeError: cannot do label indexing on <class 'pandas.indexes.range.RangeIndex'>
    with these indexers [2.0] of <type 'float'>
    

    This is not 'label' indexing, but 'integer' or 'positional' indexing

  • The behaviour of using a float indexer with ix on a non-numerical index has changed:

    In [78]: s3 = pd.Series(range(3), index=list('abc'))
    
    In [79]: s4 = s3.copy()
    
    In [80]: s4.ix[1.0] = 10
    
    In [81]: s4
    Out[81]:
    a       0
    b       1
    c       2
    1.0    10
    dtype: int64
    
    In [82]: s4.index
    Out[82]: Index([u'a', u'b', u'c', 1.0], dtype='object')
    
    In [83]: pd.__version__
    Out[83]: '0.17.1+350.g5f7c9e9'
    

    and with 0.16.2

    In [1]: pd.__version__
    Out[1]: '0.16.2'
    
    In [2]: s3 = pd.Series(range(3), index=list('abc'))
    
    In [3]: s4 = s3.copy()
    
    In [4]: s4.ix[1.0] = 10
    C:\Anaconda\lib\site-packages\pandas\core\index.py:805: FutureWarning: scalar i
    dexers for index type Index should be integers and not floating point
    type(self).__name__),FutureWarning)
    
    In [5]: s4
    Out[5]:
    a     0
    b    10
    c     2
    dtype: int64
    
    In [6]: s4.index
    Out[6]: Index([u'a', u'b', u'c'], dtype='object')
    
    

    The change is logical, as before the float was interpreted as a positional indexer (and for this the warning was raised). But now a float cannot be a positional indexer anymore, so it is interpreted as a new label.
    To be clear, I think this change is OK, but just wanted to point out a case where this change will not raise an error but alter your results (worth mentioning in the whatsnew docs?)

@jreback jreback added the Compat pandas objects compatability with Numpy or Python functions label Feb 13, 2016
@jreback jreback added this to the 0.18.0 milestone Feb 13, 2016
@jreback
Copy link
Contributor Author

jreback commented Feb 15, 2016

#12330 should take care of all of these points (I doced what .ix does a bit more)

@jorisvandenbossche

jreback added a commit to jreback/pandas that referenced this issue Feb 15, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Compat pandas objects compatability with Numpy or Python functions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant