Skip to content

BUG: Incorrect casting of int to float when np.nan assigned to Series with nullable boolean index #60439

@DhruvBShetty

Description

@DhruvBShetty

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

import pandas as pd
import numpy as np

abc=pd.Series([1,2,3],index=np.array([False,True,pd.NA], dtype=pd.BooleanDtype),dtype="int64")
abc
Out[1]:
False    1
True     2
<NA>     3
dtype: int64

abc.loc[[True,False,False]]=np.NaN
abc
Out[2]:
False    NaN
True     2.0
<NA>     3.0
dtype: float64

Issue Description

A Series with Nullable Boolean dtype index casts the entire series to float64 when it's originally int64.

Expected Behavior

Everything else remains the same besides NaN.

import pandas as pd
import numpy as np

abc=pd.Series([1,2,3],index=np.array([False,True,pd.NA], dtype=pd.BooleanDtype),dtype="int64")
abc
Out[1]:
False    1
True     2
<NA>     3
dtype: int64

abc.loc[[True,False,False]]=np.NaN
abc
Out[2]:
False    NaN
True     2
<NA>     3
dtype: int64

Installed Versions

INSTALLED VERSIONS

commit : 0691c5c
python : 3.10.5
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.19045
machine : AMD64
processor : Intel64 Family 6 Model 165 Stepping 2, GenuineIntel
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : English_United States.1252

pandas : 2.2.3
numpy : 1.24.3
pytz : 2023.3
dateutil : 2.8.2
pip : 22.1.2
Cython : None
sphinx : None
IPython : 8.13.2
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : 4.12.2
blosc : None
bottleneck : None
dataframe-api-compat : None
fastparquet : None
fsspec : 2024.6.0
html5lib : None
hypothesis : None
gcsfs : None
jinja2 : 3.1.2
lxml.etree : None
matplotlib : 3.8.2
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
psycopg2 : None
pymysql : None
pyarrow : None
pyreadstat : None
pytest : None
python-calamine : None
pyxlsb : None
s3fs : None
scipy : 1.11.4
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlsxwriter : None
zstandard : None
tzdata : 2023.3
qtpy : None
pyqt5 : None

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugClosing CandidateMay be closeable, needs more eyeballsNeeds TriageIssue that has not been reviewed by a pandas team member

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions