Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
2 of 3 tasks
tamargrey opened this issue Jun 17, 2021 · 8 comments · Fixed by #42541
Closed
2 of 3 tasks

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

tamargrey opened this issue Jun 17, 2021 · 8 comments · Fixed by #42541
Labels
Bug Dtype Conversions Unexpected or buggy dtype conversions Regression Functionality that used to work in a prior pandas version Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Milestone

Comments

@tamargrey
Copy link

  • 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

@tamargrey tamargrey added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Jun 17, 2021
@jreback
Copy link
Contributor

jreback commented Jun 17, 2021

the result is correct; you should be doing an .astype(int) on the bools

simonjayhawkins added a commit to simonjayhawkins/pandas that referenced this issue Jun 18, 2021
@simonjayhawkins
Copy link
Member

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

Indeed, there was no release note with the PR that introduced this change. @jbrockmendel

first bad commit: [4554635] REF: remove DatetimeBlock, TimeDeltaBlock (#40614)

will reopen for now.

the result is correct

This change looks unintentional, we should add something to the release notes in the API breaking section and probably needs some additional tests for this new behavior (or revert to existing behavior till 2.0)

@simonjayhawkins simonjayhawkins added Dtype Conversions Unexpected or buggy dtype conversions Regression Functionality that used to work in a prior pandas version Reshaping Concat, Merge/Join, Stack/Unstack, Explode and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Jun 18, 2021
@simonjayhawkins simonjayhawkins added this to the 1.3 milestone Jun 18, 2021
@simonjayhawkins simonjayhawkins changed the title BUG?: 1.3.0rc behavior change with concatenating boolean and numeric columns REGR: 1.3.0rc behavior change with concatenating boolean and numeric columns Jun 25, 2021
@simonjayhawkins simonjayhawkins modified the milestones: 1.3, 1.3.1 Jun 30, 2021
@simonjayhawkins
Copy link
Member

@jbrockmendel thoughts here?

@jbrockmendel
Copy link
Member

This change looks unintentional, we should add something to the release notes in the API breaking section and probably needs some additional tests for this new behavior (or revert to existing behavior till 2.0)

Yah, AFAICT it was caused by adding a is_dtype_equal check in internals.concat, which was aimed at dt64 vs td64, but will also catch int vs bool

@simonjayhawkins
Copy link
Member

@jbrockmendel will you get a chance to fix for 1.3.1? (scheduled for end of next week)

@jbrockmendel
Copy link
Member

i think so, yes

@simonjayhawkins
Copy link
Member

Thanks @jbrockmendel

@jbrockmendel
Copy link
Member

we also need #42576 to get the analogous ArrayManager behavior fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Dtype Conversions Unexpected or buggy dtype conversions Regression Functionality that used to work in a prior pandas version Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants