-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Int64Index with dtype=float and slicing issues #9966
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
Comments
This is a bug (but not with the slicing, rather the index construction). This should be (I think the unary ops are ok, e.g. they will always be the same type, but could change that as well). These are not really tested all that well, so need a comprehensive test. Interested in doing a PR? |
@jreback I'm interested in doing a PR, but as I have never done any work on pandas before, I'm unsure if I will be able to. I hope it's ok for me to take a couple of days to look into it to see if I'm able to understand the code? Also, to make sure I understand correctly: We should fix the issue that Int64Index can sometimes contain floats by making sure we create a Float64Index where appropriate. As a consequence of that fix the slicing issues I found should go away, right? |
The issue is that certain numeric ops return the wrong index type; all else follows from there. |
I have stumbled onto problems with slicing a pandas DataFrame when an index that originally contained integers has been manipulated such that it contains floats. Consider the following example (somewhat contrived to make it stand on its own; in practice, data are loaded from file):
The final line raises this exception:
While it was relatively easy to work around this using an explicit cast along the lines of
it took me quite a while to figure out what was going on. What I expected to happen in the original code was that the index would become a Float64Index or something similar. When I first noticed the Int64Index with dtype=float I thought that was wierd. Is it a good idea to change this behaviour so that there is not this mismatch between index type and dtype?
My pandas version is 0.15.2. User EdChum at StackOverflow[1] has kindly tested this on 0.16, finding the same behaviour with the code above. Slicing with .ix works on 0.16 but not on 0.15.2; slicing with .loc works for both versions.
[1] http://stackoverflow.com/questions/29795225/pandas-int64index-with-dtype-float
The text was updated successfully, but these errors were encountered: