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

DataFrame.ix[n] for numerical (float) indices has an error #707

Closed
james18 opened this issue Jan 27, 2012 · 5 comments
Closed

DataFrame.ix[n] for numerical (float) indices has an error #707

james18 opened this issue Jan 27, 2012 · 5 comments
Labels
Milestone

Comments

@james18
Copy link

james18 commented Jan 27, 2012

So my understanding for a DataFrame with numerical indices, DataFrame.ix[i] indexes to the position where index=i, and not the ith row of the DataFrame. Although I find this to be confusing, i accept that this was the decision that was made.

However, the getting and setting with .ix is not consistent

from pandas import DataFrame
df = DataFrame(['a','b','c'],index=[0,0.5,1])
df.ix[1] = 'zoo'
print df.ix[1]

Current:
'b'

Expected:
'zoo'

Basically, df.ix[1] returns 'b', of index 0.5, instead of 'zoo' of index 1

@adamklein
Copy link
Contributor

I'm not confident this is bug, just a very confusing circumstance.

The index is of type float. You are indexing by an integer, however.

So df.ix[1] is taking the integer index (offset 1). You really want df.ix[1.], which is the label index (offset 2).

In [12]: df.ix[1.]
Out[12]:
0 zoo
Name: 1.0

@adamklein adamklein reopened this Jan 28, 2012
@adamklein
Copy link
Contributor

I'll leave open to see what Wes has to say. This could be either be a nasty gotcha we should document, or could maybe be something we'd want to disallow (ie, integer indexing in float-based index)

@james18
Copy link
Author

james18 commented Jan 28, 2012

I think the bug is that it gets and sets different locations in the DataFrame. Why wouldn't it be consistent?

On Jan 27, 2012, at 8:24 PM, Adam Kleinreply@reply.github.com wrote:

I'll leave open to see what Wes has to say. This could be either be a nasty gotcha we should document, or could maybe be something we'd want to disallow (ie, integer indexing in float-based index)


Reply to this email directly or view it on GitHub:
https://github.com/wesm/pandas/issues/707#issuecomment-3697230

@adamklein
Copy link
Contributor

Ah yes, this seems like a bug, the inconsistency of how it treats the .ix integer parameter on getting vs setting (in the context of a float index).

@ghost ghost assigned adamklein Jan 29, 2012
@adamklein
Copy link
Contributor

latest commit should fix. great catch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants