pandas
pandas copied to clipboard
ENH: Support scalar condition in `Series.where` and `DataFrame.where`
Feature Type
- [x] 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.whereSeries.maskDataFrame.whereDataFrame.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.
Sure, seems reasonable to me.
@lithomas1 The PR has passed all tests. Currently I added to the changelog of 2.1.0, should I use 2.0.3 instead?
No, I don't think this should be backported, 2.1.0 seems fine to me (its gonna come out around in a month or so).