Skip to content

COMPAT: warn on ambiguous .ix indexing #7187

Closed
@bjonen

Description

@bjonen
In []: df = pd.DataFrame(index=range(10),columns=['a','b',1])

In []: df
Out[]:
     a    b    1
0  NaN  NaN  NaN
1  NaN  NaN  NaN
2  NaN  NaN  NaN
3  NaN  NaN  NaN
4  NaN  NaN  NaN
5  NaN  NaN  NaN
6  NaN  NaN  NaN
7  NaN  NaN  NaN
8  NaN  NaN  NaN
9  NaN  NaN  NaN

In []: df.ix[:,[0]]
Out[]:
     1
0  NaN
1  NaN
2  NaN
3  NaN
4  NaN
5  NaN
6  NaN
7  NaN
8  NaN
9  NaN

In []: df.ix[:,[0,1,2]]
Out[]:
     1    1    1
0  NaN  NaN  NaN
1  NaN  NaN  NaN
2  NaN  NaN  NaN
3  NaN  NaN  NaN
4  NaN  NaN  NaN
5  NaN  NaN  NaN
6  NaN  NaN  NaN
7  NaN  NaN  NaN
8  NaN  NaN  NaN
9  NaN  NaN  NaN

I know in this case one should use iloc, It's not clear what ix should do in this case, but the df.ix[:,[0]] case is certainly not what is expected.

How about either

  • issuing a warning or
  • raising an Exception

when asked to ix an index like this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Compatpandas objects compatability with Numpy or Python functionsDeprecateFunctionality to remove in pandasIndexingRelated to indexing on series/frames, not to indexes themselves

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions