Skip to content

ENH: Support scalar condition in Series.where and DataFrame.where #53903

Open
@randolf-scholz

Description

@randolf-scholz

Feature Type

  • Changing existing functionality in pandas

Problem Description

For compatibility reasons with numpy.where it would be nice to allow scalar booleans as a condition to Series.where and DataFrame.where. Currently

import pandas as pd
s = pd.Series([1,2])
s.where(True)

raises ValueError: Array conditional must be same shape as self

Feature Description

Allow scalar boolean as input to

  • Series.where
  • Series.mask
  • DataFrame.where
  • DataFrame.mask

Alternative Solutions

idk.

Additional Context

Regarding documentation, I am not sure anything needs to be updated since both Series.where and DataFrame.where specify array-like as a valid input type, and scalars are considered array-like.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions