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

ERR: Raise a better message when mixing positional and label indexing in loc/iloc #25753

Closed
LucaPaterlini opened this issue Mar 17, 2019 · 4 comments

Comments

@LucaPaterlini
Copy link

commented Mar 17, 2019

Code Sample, a copy-pastable example if possible

import numpy as np

data = DataFrame(np.arange(16).reshape((4, 4)),
    index=['Ohio', 'Colorado', 'Utah', 'New York'],
    columns=['one', 'two', 'three', 'four'])

data[data < 5] = 0


print(data.iloc[['Colorado', 'Utah'], [3, 0, 1]])
# .ix is deprecated. Please use
# .loc for label based indexing or
# .iloc for positional indexing


print(data.iloc[['Colorado', 'Utah'], [3, 0, 1]])
#TypeError: cannot perform reduce with flexible type

print(data.loc[['Colorado', 'Utah'], [3, 0, 1]])
#KeyError: "None of [Int64Index([3, 0, 1], dtype='int64')] are in the [columns]"

Problem description

I followed the suggesion to move the ix to iloc and this is what I have got
I have used python 3.7.2 on an elemntary os 18.04

@mroeschke

This comment has been minimized.

Copy link
Member

commented Mar 17, 2019

Mixing positional and label based indexing is not allowed in loc or iloc.

So either data.iloc[[1, 2], [3, 0, 1]] or data.loc[['Colorado', 'Utah'], ['four', 'one', 'two]]

@mroeschke mroeschke closed this Mar 17, 2019

@mroeschke mroeschke added this to the No action milestone Mar 17, 2019

@simonjayhawkins

This comment has been minimized.

Copy link
Member

commented Mar 17, 2019

@mroeschke : the error message TypeError: cannot perform reduce with flexible type does not appear helpful. perhaps this should be raised as a seperate issue.

@LucaPaterlini

This comment has been minimized.

Copy link
Author

commented Mar 17, 2019

I am happy with the answer provided.
Just unhappy for this decision becouse It would potentially break old code as soon as ix will be fully deprecated.

The example cames from data analysis with python book and can be easily reproduced.

@mroeschke

This comment has been minimized.

Copy link
Member

commented Mar 17, 2019

Fair. iloc and loc could have a better error messages with mixed positional/label indexing.

The decision to deprecate ix was made was because its indexing operation was too flexible and not explicit compared to the other multitude of indexers.

@mroeschke mroeschke reopened this Mar 17, 2019

@mroeschke mroeschke changed the title .ix to .iloc update ERR: Raise a better message when mixing positional and label indexing in loc/iloc Mar 17, 2019

@jreback jreback modified the milestones: Contributions Welcome, 0.25.0 Mar 19, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.