Skip to content

Indexing Series with DataFrame should throw an exception #8444

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
rockg opened this issue Oct 2, 2014 · 2 comments · Fixed by #8472
Closed

Indexing Series with DataFrame should throw an exception #8444

rockg opened this issue Oct 2, 2014 · 2 comments · Fixed by #8472
Labels
Error Reporting Incorrect or improved errors from pandas
Milestone

Comments

@rockg
Copy link
Contributor

rockg commented Oct 2, 2014

I came across this today when being a little bit careless when using a boolean array to index into a Series. The result was not what I expected which turned out to be because I was using a boolean index in a DataFrame to index a Series. Either we should make this work or throw an error that you cannot index a Series with a DataFrame.

import pandas as pd
series = pd.Series(10, index=range(10))
df = pd.DataFrame(range(10), index=range(10))
series[df > 5]
Out[9]: 
0    10
dtype: int64
# What is really meant is this:
series[df[0] > 5]
Out[11]: 
6    10
7    10
8    10
9    10
dtype: int64

This is on 0.14.1

@rockg rockg changed the title Indexing Series with Dataframe should throw an exception Indexing Series with DataFrame should throw an exception Oct 2, 2014
@jreback
Copy link
Contributor

jreback commented Oct 2, 2014

this is checked for in .loc but not getitem ([]). yes I would agree. would you like to submit a PR?

@jreback jreback added the Error Reporting Incorrect or improved errors from pandas label Oct 2, 2014
@jreback jreback added this to the 0.15.1 milestone Oct 2, 2014
@rockg
Copy link
Contributor Author

rockg commented Oct 2, 2014

Sure, seems straightforward.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Error Reporting Incorrect or improved errors from pandas
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants