BUG: np.where
called with ps.Series
returns np.array
instead of pd.Series
#58329
Labels
np.where
called with ps.Series
returns np.array
instead of pd.Series
#58329
Pandas version checks
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of pandas.
I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
Issue Description
res
in the example isnp.array
. Such behavior is inconsistent with other numpy functions such asnp.floor
ornp.arctan2
.Expected Behavior
res
should beSeries
instead (particularlypd.Series([-1, -2, 3], name='a')
in this case.As for the cases where
x
andy
(i.e., the two last params ofnp.where
) are of mixed types or names, we should probably keep consistency withnp.arctan2
, meaning:x
andy
ispd.Series
and the other isnp.array
we should returnpd.Series
with the same name as inputSeries
x
andy
arepd.Series
of the same name we should return apd.Series
with that namex
andy
arepd.Series
but with different names we should return unnamedpd.Series
Installed Versions
INSTALLED VERSIONS
commit : bdc79c1
python : 3.12.3.final.0
python-bits : 64
OS : Windows
OS-release : 11
Version : 10.0.22631
machine : AMD64
processor : AMD64 Family 25 Model 33 Stepping 2, AuthenticAMD
byteorder : little
LC_ALL : None
LANG : None
LOCALE : English_Germany.1252
pandas : 2.2.1
numpy : 1.26.4
pytz : 2024.1
dateutil : 2.9.0.post0
setuptools : None
pip : 23.3.2
Cython : None
pytest : 8.1.1
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : 8.23.0
pandas_datareader : None
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : None
bottleneck : None
dataframe-api-compat : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : None
numba : None
numexpr : 2.10.0
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyreadstat : None
python-calamine : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
zstandard : None
tzdata : 2024.1
qtpy : None
pyqt5 : None
The text was updated successfully, but these errors were encountered: