Code Sample, a copy-pastable example if possible
s1 = pd.Series({'v1': 1}, dtype='int64')
# >>> s1
# v1 1
# dtype: int64
s2 = pd.Series({'v2': 1}, dtype='int64')
# >>> s2
# v2 1
# dtype: int64
s1.add(s2, fill_value=0)
# v1 1.0
# v2 1.0
# dtype: float64
Problem description
Not sure if it is similar to #20070, Series
seems always infer dtype even dtype
is explicitly set
(int64
to float64
, datetime64
to int64
).
Expected Output
Keep to dtype
and don't infer it.
Output of pd.show_versions()
INSTALLED VERSIONS
------------------
commit: None
python: 3.6.4.final.0
python-bits: 64
OS: Darwin
OS-release: 17.4.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: None
LANG: zh_CN.UTF-8
LOCALE: zh_CN.UTF-8
pandas: 0.22.0
pytest: None
pip: 9.0.1
setuptools: 38.5.2
Cython: None
numpy: 1.14.1
scipy: 1.0.0
pyarrow: None
xarray: None
IPython: None
sphinx: None
patsy: None
dateutil: 2.6.1
pytz: 2018.3
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: 2.2.0
openpyxl: None
xlrd: 1.1.0
xlwt: None
xlsxwriter: 1.0.2
lxml: 4.1.1
bs4: 4.6.0
html5lib: None
sqlalchemy: None
pymysql: 0.7.11.None
psycopg2: None
jinja2: None
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None
Comment From: jreback
see the docs http://pandas.pydata.org/pandas-docs/stable/gotchas.html#support-for-integer-na
generally we won't cast floats back to ints, this can be a non-trivial operation and must be done explicity. since you are aligning, you are upcast to float64.
setting something 'explicity' is irrelevant here. The dtype is what it is. operations can and do change it. pandas makes best efforts to cast apporpriately but its not always possible.