Skip to content

Series.drop() with boolean index: inconsistent behaviour #8530

Closed
@urraca

Description

@urraca

The behaviour below occurs in versions '0.15.0rc1-21-g32c5016' and '0.14.1'.

When the label passed to the drop method of a Series is not in the index:
(a) if the index is not all booleans then an error is raised
(b) if the index is all booleans and has length > 1 then no error is raised; the original series is returned
(c) if the index is all booleans and has length == 1 then an error is raised

I propose that:

  1. the difference between the behaviour in (a) and (b) should be documented
  2. the behaviour in (c) should be changed to match that in (b)

Examples of current behaviour:
(a)

>>> pd.Series([1, 1], index=['a', True]).drop(False)
ValueError: labels [False] not contained in axis

(b)

>>> pd.Series([1, 1], index=[True, True]).drop(False)
True    1
True    1
dtype: int64

(c)

>>> pd.Series([1], index=[True]).drop(False)
ValueError: labels [False] not contained in axis

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions