Description
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