Skip to content

DOC: intended series.loc behavior undocumented for boolean series #31054

Closed
@hickmanw

Description

@hickmanw

series.loc when passed a boolean series

How will series.loc behave when passed a boolean series whose index contains the same values, but in a different order, than the focal series' index?

s1 = pd.Series(list('ab'))
mask = [True, False]
s2 = pd.Series(mask, pd.Index([1,0]))

print(s1.loc[mask])
print(s1.loc[s2])

0 a
dtype: object
1 b
dtype: object

Problem description

I expected the index of s2 to be ignored, in effect treating s2 as a boolean array input, but I was wrong.

The documentation on master doesn't list a (boolean) series as an allowed input, hence doesn't provide guidance on which behavior should be expected/is intended.

What is the intended behavior? If given guidance, I'll update the documentation.

Output of pd.show_versions()

[paste the output of pd.show_versions() here below this line]
INSTALLED VERSIONS

commit : None
python : 3.6.6.final.0
python-bits : 64
OS : Linux
OS-release : 4.14.152-127.182.amzn2.x86_64
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : en_US.UTF-8
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 0.25.3
numpy : 1.17.3
pytz : 2019.3
dateutil : 2.7.4
pip : 19.3.1
setuptools : 40.4.3
Cython : 0.29.14
pytest : 5.3.2
hypothesis : None
sphinx : 2.3.0
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.10
IPython : 7.0.1
pandas_datareader: None
bs4 : 4.8.1
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : None
matplotlib : 3.1.1
numexpr : 2.7.0
odfpy : None
openpyxl : 3.0.3
pandas_gbq : None
pyarrow : None
pytables : None
s3fs : None
scipy : 1.4.0.dev0+4dcf606
sqlalchemy : 1.3.11
tables : None
xarray : 0.14.1
xlrd : 1.2.0
xlwt : None
xlsxwriter : None

Metadata

Metadata

Assignees

No one assigned

    Labels

    DocsIndexingRelated 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