Indexing Series with DataFrame should throw an exception · Issue #8444 · pandas-dev/pandas (original) (raw)

Skip to content

Provide feedback

Saved searches

Use saved searches to filter your results more quickly

Sign up

Appearance settings

@rockg

Description

@rockg

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