question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue
  • 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 : 2dd9e9ba9009a40191c0c0b96262fa3939d609f0 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

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
jrebackcommented, Jun 17, 2021

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

0reactions
jbrockmendelcommented, Jul 19, 2021

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Migration Guide: SQL, Datasets and DataFrame - Apache Spark
It computes based on user-given group-by expressions plus grouping set columns. To restore the behavior before 3.3.1 and 3.2.3, you can set spark.sql.legacy ......
Read more >
IO tools (text, CSV, HDF5, …) — pandas 1.5.2 documentation
Row number(s) to use as the column names, and the start of the data. Default behavior is to infer the column names: if...
Read more >
Boolean values are turned into floats when appending two ...
python - Boolean values are turned into floats when appending two pandas dataframes - Stack Overflow. Stack Overflow for Teams – Start ...
Read more >
Collibra Data Quality
The error message for Failed Merging Schema now has extra logging to clarify ... The Behavior tab now has a new column, Delta...
Read more >
docs/sql-programming-guide.md ... - GitLab
A DataFrame is a Dataset organized into named columns. ... Spark SQL can convert an RDD of Row objects to a DataFrame, inferring...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found