Skip to content

BUG: upcasting when assigning to an enlarged series does not produce a FutureWarning  #57853

@arnaudlegout

Description

@arnaudlegout

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
s = pd.Series([1, 2, 3], index=list('abc'), dtype='UInt8')
print(s.dtype)
# we upcast on enlargement
s.loc[4] = 'x'
print(s.dtype)

Issue Description

According to https://pandas.pydata.org/pdeps/0006-ban-upcasting.html
raising a FutureWarning on upcasting during enlargement is out of the scope of this pdep.

However, it is inconsistent with the new behavior. I expected to see an issue report discussing this problem, but I did not find one (searching for upcasting in the issue reports). I created one to either start the discussion, or be redirected to where it is discussed.

Expected Behavior

I would expect to have a FutureWarning in this case (and an error in the future).

Installed Versions

Details In [412]: pd.show_versions()

INSTALLED VERSIONS

commit : bdc79c1
python : 3.12.0.final.0
python-bits : 64
OS : Windows
OS-release : 11
Version : 10.0.22631
machine : AMD64
processor : Intel64 Family 6 Model 140 Stepping 1, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : fr_FR.cp1252

pandas : 2.2.1
numpy : 1.26.4
pytz : 2023.3.post1
dateutil : 2.8.2
setuptools : 68.2.2
pip : 23.3.1
Cython : 3.0.8
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.1.3
IPython : 8.20.0
pandas_datareader : None
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : 4.12.2
bottleneck : 1.3.7
dataframe-api-compat : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : 3.8.0
numba : 0.59.0
numexpr : 2.8.7
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 14.0.2
pyreadstat : None
python-calamine : None
pyxlsb : None
s3fs : None
scipy : 1.11.3
sqlalchemy : None
tables : None
tabulate : 0.9.0
xarray : None
xlrd : None
zstandard : None
tzdata : 2023.3
qtpy : 2.4.1
pyqt5 : None

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