Skip to content

Boolean indexing into a series with assignment #30567

Closed
@IvanUkhov

Description

@IvanUkhov

I am curious if the following is the intended behavior:

x = pd.Series([None] * 10)
y = [False] * 3 + [True] * 5 + [False] * 2
x[y] = range(5)
x

# 0     None
# 1     None
# 2     None
# 3        3
# 4        4
# 5        0
# 6        1
# 7        2
# 8     None
# 9     None

The expectation was that it would work as with x.loc[y] = range(5):

# 0    None
# 1    None
# 2    None
# 3       0
# 4       1
# 5       2
# 6       3
# 7       4
# 8    None
# 9    None

If so, where can one read about the logic behind?

LANG : en_US.UTF-8 LOCALE : en_US.UTF-8

pandas : 0.25.3
numpy : 1.17.4
pytz : 2018.4
dateutil : 2.5.0
pip : 19.2.3
setuptools : 41.2.0
Cython : None
pytest : 5.1.2
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 3.8.0
html5lib : 1.0.1
pymysql : None
psycopg2 : None
jinja2 : 2.8
IPython : 6.5.0
pandas_datareader: None
xlsxwriter : None
pandas_gbq : None
pyarrow : 0.15.1
bs4 : 4.7.1
numexpr : None
xarray : None
fastparquet : None
tables : None
s3fs : None
odfpy : None
pytables : None
xlrd : None
gcsfs : None
xlwt : None
sqlalchemy : 1.3.4
scipy : 1.3.1
openpyxl : None
lxml.etree : 3.8.0
matplotlib : 3.0.3
bottleneck : None

Metadata

Metadata

Assignees

Labels

BugIndexingRelated 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