Skip to content

BUG: .ix get and set behave differently #4544

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
alefnula opened this issue Aug 12, 2013 · 2 comments · Fixed by #5064
Closed

BUG: .ix get and set behave differently #4544

alefnula opened this issue Aug 12, 2013 · 2 comments · Fixed by #5064
Assignees
Labels
Bug Indexing Related to indexing on series/frames, not to indexes themselves
Milestone

Comments

@alefnula
Copy link
Contributor

I'm really sorry if this is a duplicate issue of #2997, but it seems to me that this is a little bit different. Here the .ix when getting a value interprets the integer as label, and when setting a value it interprets it as a positional index.

>>> import numpy as np
>>> import pandas as pd
>>> df = pd.DataFrame(np.arange(16).reshape((4, 4)),
                      columns=['a', 'b', 8, 'c'],
                      index=['e', 7, 'f', 'g'])
>>> df
    a   b   8   c
e   0   1   2   3
7   4   5   6   7
f   8   9  10  11
g  12  13  14  15
>>> df.ix['e', 8]
2
>>> df.ix['e', 8] = 42
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "pandas/core/indexing.py", line 90, in __setitem__
    self._setitem_with_indexer(indexer, value)
  File "pandas/core/indexing.py", line 190, in _setitem_with_indexer
    values[indexer] = value
IndexError: index 8 is out of bounds for axis 1 with size 4
>>> df.loc['e', 8] = 42
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "pandas/core/indexing.py", line 90, in __setitem__
    self._setitem_with_indexer(indexer, value)
  File "pandas/core/indexing.py", line 190, in _setitem_with_indexer
    values[indexer] = value
IndexError: index 8 is out of bounds for axis 1 with size 4

I see this issue with the 0.12 version and also with the latest git checkout.

Update: @jreback noticed that the .loc is not working either.

@jreback
Copy link
Contributor

jreback commented Aug 12, 2013

breaks .loc too, which is very odd (as it doesn't have all of the crazy logic as .ix)....marking as a bug

@jreback
Copy link
Contributor

jreback commented Aug 12, 2013

@alefnula not directly related to this, but could you have a look at #4515 and comment if you'd like?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Indexing Related to indexing on series/frames, not to indexes themselves
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants