Skip to content

BUG: assigment of list with boolean mask scrambles values #30988

Closed
@jorisvandenbossche

Description

@jorisvandenbossche

From gitter (didn't see it reported in an issue):

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

gives:

0    None
1    None
2    None
3       3
4       4
5       0
6       1
7       2
8    None
9    None
dtype: object

For some reason, the assigned values are not in the correct order.

With an array, it works fine (but I think we support list as well?):

In [4]: x[y] = np.array(list(range(5)))

In [5]: x
Out[5]: 
0    None
1    None
2    None
3       0
4       1
5       2
6       3
7       4
8    None
9    None
dtype: object

Tested on pandas master, and also on pandas 0.25 it is buggy (eg in pandas 0.18 it worked fine).

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugIndexingRelated to indexing on series/frames, not to indexes themselves

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions