Skip to content

BUG: Concatenation of None with numerical values no longer converts None to Nan. #46922

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
joelostblom opened this issue May 2, 2022 · 2 comments
Closed
2 of 3 tasks
Labels
Bug Duplicate Report Duplicate issue or pull request

Comments

@joelostblom
Copy link
Contributor

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

df = pd.concat([
    pd.DataFrame({'A': [None], 'B': [12.34]}),
    pd.DataFrame({'A': [12.34], 'B': [12.34]})
])
df
# pandas 1.3.3
#       A      B
#0   NaN  12.34
#0  12.34  12.34

# pandas 1.4.2
#       A      B
#0   None  12.34
#0  12.34  12.34

df.round(1)  # Works as expected on both 1.3.3 and 1.4.2
df['A'].round(1)  # Fails on 1.4.2 with the error below (or sometimes hangs indefinitely)
# TypeError: unsupported operand type(s) for *: 'NoneType' and 'float'

Issue Description

When trying to convert a column containing None values, I get the TypeError above. Notably this seems to be a regression in pandas 1.4+ (tested with 1.4.2) and works as expected in pandas 1.3.3. This is an issue since you might have a dataframe containing both None and numerical values to round as in the example above. I didn't see this listed in the release notes, but I might just have missed it, so I am not sure whether it is intentional or not. Similar to #46332

Expected Behavior

It seems to make sense to convert None to NaN so that it can be used in operations like round() etc (like was the case in pandas 1.3.3).

Installed Versions

INSTALLED VERSIONS

commit : 73c6825
python : 3.9.7.final.0
python-bits : 64
OS : Linux
OS-release : 5.16.15-76051615-generic
Version : #202203161444164796402721.10~e706226 SMP PREEMPT Tue Mar 22 17
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 1.3.3
numpy : 1.21.2
pytz : 2021.1
dateutil : 2.8.2
pip : 21.2.4
setuptools : 58.0.4
Cython : None
pytest : None
hypothesis : None
sphinx : 3.5.4
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.6.3
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.0.1
IPython : 7.28.0
pandas_datareader: None
bs4 : 4.10.0
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : 3.4.3
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 6.0.1
pyxlsb : None
s3fs : None
scipy : 1.8.0
sqlalchemy : 1.3.23
tables : None
tabulate : 0.8.9
xarray : None
xlrd : None
xlwt : None
numba : None

@joelostblom joelostblom added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels May 2, 2022
simonjayhawkins added a commit to simonjayhawkins/pandas that referenced this issue May 3, 2022
@ghost
Copy link

ghost commented May 3, 2022

take

@github-actions github-actions bot assigned ghost May 3, 2022
@simonjayhawkins
Copy link
Member

Thanks @joelostblom for the report.

This was an intended change, see https://pandas.pydata.org/pandas-docs/stable/whatsnew/v1.4.0.html#ignoring-dtypes-in-concat-with-empty-or-all-na-columns

but there is also some discussion that this should not have been introduced without first deprecating the old behavior.

closing as duplicate of #45637

@simonjayhawkins simonjayhawkins added Duplicate Report Duplicate issue or pull request and removed Needs Triage Issue that has not been reviewed by a pandas team member labels May 3, 2022
@ghost ghost removed their assignment May 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Duplicate Report Duplicate issue or pull request
Projects
None yet
Development

No branches or pull requests

2 participants