Skip to content

REGR: 1.3.0rc behavior change with concatenating boolean and numeric columns #42092

Closed
@tamargrey

Description

@tamargrey
  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • (optional) I have confirmed this bug exists on the master branch of pandas.


Code Sample, a copy-pastable example

df1 = pd.DataFrame(pd.Series([True, False, True, True], dtype='bool'))
df2 = pd.DataFrame(pd.Series([1,0,1], dtype='int64'))

new_df = pd.concat([df1,df2]) # dtype changed from int64 to object
assert new_df[0].dtype == 'object'

Problem description

Previously, the concat call would produce a series with dtype int64, converting the bools to 1s and 0s. Now, all the values are maintained, so the dtype is object.

Expected Output

I'm not sure if this behavior change is expected or not, but I didn't see anything in the release notes that made me think it was expected, so I'd expect the result to allow assert new_df[0].dtype == 'int64'

Output of pd.show_versions()

INSTALLED VERSIONS

commit : 2dd9e9b
python : 3.8.2.final.0
python-bits : 64
OS : Darwin
OS-release : 19.6.0
Version : Darwin Kernel Version 19.6.0: Sun Jul 5 00:43:10 PDT 2020; root:xnu-6153.141.1~9/RELEASE_X86_64
machine : x86_64
processor : i386
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 1.3.0rc1
numpy : 1.20.3
pytz : 2021.1
dateutil : 2.8.1
pip : 21.1.2
setuptools : 41.2.0
Cython : None
pytest : 6.0.1
hypothesis : None
sphinx : 3.2.1
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.11.3
IPython : 7.18.1
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : 2021.06.0
fastparquet : 0.5.0
gcsfs : None
matplotlib : 3.2.2
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 4.0.1
pyxlsb : None
s3fs : None
scipy : 1.6.3
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : 0.53.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugDtype ConversionsUnexpected or buggy dtype conversionsRegressionFunctionality that used to work in a prior pandas versionReshapingConcat, Merge/Join, Stack/Unstack, Explode

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions