Skip to content

ERR: improve error message with unalignable label indexing #14491

Closed
@bluenote10

Description

@bluenote10

A small, complete example of the issue

Using a boolean index in a pandas.Series on a data frame with an string index fails with Unalignable boolean Series key provided:

import pandas as pd

# DF without string index
df = pd.DataFrame({"A": [0, 1, 2]})
df.loc[[True, True, True], :]               # works
df.loc[pd.Series([True, True, True]), :]    # works

# DF with string index
df = pd.DataFrame({"A": [0, 1, 2]}, index=["a", "b", "c"])
df.loc[[True, True, True], :]               # works
df.loc[pd.Series([True, True, True]), :]    # fails

Expected Output

Boolean indexing should work with a pandas.Series like it does with regular Python lists and boolean numpy arrays.

Output of pd.show_versions()

## INSTALLED VERSIONS

commit: None
python: 2.7.6.final.0
python-bits: 64
OS: Linux
OS-release: 3.13.0-98-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8

pandas: 0.18.1
nose: None
pip: 8.1.2
setuptools: 27.2.0
Cython: 0.24.1
numpy: 1.11.1
scipy: 0.18.0
statsmodels: None
xarray: None
IPython: 5.1.0
sphinx: None
patsy: None
dateutil: 2.5.3
pytz: 2016.6.1
blosc: None
bottleneck: 1.1.0
tables: None
numexpr: 2.6.1
matplotlib: 1.5.3
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: None
httplib2: None
apiclient: None
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: None
boto: None
pandas_datareader: None

Metadata

Metadata

Assignees

No one assigned

    Labels

    Error ReportingIncorrect or improved errors from pandasIndexingRelated to indexing on series/frames, not to indexes themselves

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions