Skip to content

BUG: .ix get and set behave differently #4544

Closed
@alefnula

Description

@alefnula

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.

Metadata

Metadata

Assignees

Labels

BugIndexingRelated to indexing on series/frames, not to indexes themselves

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions