Skip to content

BUG: Unexpected typecast in Series.add with integer fill_value #56096

Open
@davidkleiven

Description

@davidkleiven

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

def main():
    series1 = pd.Series([1, 2, 3])
    series2 = pd.Series([4, 5])
    print(series1.dtype)
    print(series2.dtype)

    summed_series = series1.add(series2, fill_value=0)
    print(summed_series.dtype)

main()

Issue Description

When summing two series with integers the resulting series get datatype float. The result of the print statements is

int64
int64
float64

Expected Behavior

Expect that the result of summing two integer series is an integer series.

Installed Versions

INSTALLED VERSIONS

commit : 2a953cf
python : 3.11.6.final.0
python-bits : 64
OS : Linux
OS-release : 5.15.133.1-microsoft-standard-WSL2
Version : #1 SMP Thu Oct 5 21:02:42 UTC 2023
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : nb_NO.UTF-8
LANG : nb_NO.UTF-8
LOCALE : nb_NO.UTF-8

pandas : 2.1.3
numpy : 1.26.2
pytz : 2023.3.post1
dateutil : 2.8.2
setuptools : 69.0.0
pip : 23.3.1
Cython : None
pytest : 7.4.3
hypothesis : 6.90.0
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : None
pandas_datareader : None
bs4 : None
bottleneck : 1.3.7
dataframe-api-compat: None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : None
numba : None
numexpr : 2.8.7
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.11.4
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
zstandard : None
tzdata : 2023.3
qtpy : None
pyqt5 : None

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugNeeds TriageIssue that has not been reviewed by a pandas team memberSeriesSeries data structure

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions