Skip to content

Indexing Series with DataFrame should throw an exception #8444

Closed
@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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Error ReportingIncorrect or improved errors from pandas

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions