Skip to content

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

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
hickmanw opened this issue Jan 15, 2020 · 1 comment · Fixed by #35506
Closed

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

hickmanw opened this issue Jan 15, 2020 · 1 comment · Fixed by #35506
Labels
Docs Indexing Related to indexing on series/frames, not to indexes themselves
Milestone

Comments

@hickmanw
Copy link

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

@swasthikcnayak
Copy link

I would like to contribute to solving this issue.

@jbrockmendel jbrockmendel added Indexing Related to indexing on series/frames, not to indexes themselves Docs labels Feb 25, 2020
MJafarMashhadi added a commit to MJafarMashhadi/pandas that referenced this issue Aug 1, 2020
MJafarMashhadi added a commit to MJafarMashhadi/pandas that referenced this issue Aug 1, 2020
MJafarMashhadi added a commit to MJafarMashhadi/pandas that referenced this issue Aug 1, 2020
@simonjayhawkins simonjayhawkins added this to the 1.2 milestone Aug 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Docs Indexing Related to indexing on series/frames, not to indexes themselves
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants