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
# pandas Int64 column causes TypeError on describe
df = pd.DataFrame({"col": [1]}, dtype="Int64")
df.describe()
```python-traceback
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/rschmidtke/miniconda3/envs/pandas150/lib/python3.9/site-packages/pandas/core/generic.py", line 10947, in describe
return describe_ndframe(
File "/home/rschmidtke/miniconda3/envs/pandas150/lib/python3.9/site-packages/pandas/core/describe.py", line 99, in describe_ndframe
result = describer.describe(percentiles=percentiles)
File "/home/rschmidtke/miniconda3/envs/pandas150/lib/python3.9/site-packages/pandas/core/describe.py", line 179, in describe
ldesc.append(describe_func(series, percentiles))
File "/home/rschmidtke/miniconda3/envs/pandas150/lib/python3.9/site-packages/pandas/core/describe.py", line 246, in describe_numeric_1d
return Series(d, index=stat_index, name=series.name, dtype=dtype)
File "/home/rschmidtke/miniconda3/envs/pandas150/lib/python3.9/site-packages/pandas/core/series.py", line 471, in __init__
data = sanitize_array(data, index, dtype, copy)
File "/home/rschmidtke/miniconda3/envs/pandas150/lib/python3.9/site-packages/pandas/core/construction.py", line 623, in sanitize_array
subarr = _try_cast(data, dtype, copy, raise_cast_failure)
File "/home/rschmidtke/miniconda3/envs/pandas150/lib/python3.9/site-packages/pandas/core/construction.py", line 841, in _try_cast
subarr = np.array(arr, dtype=dtype, copy=copy)
TypeError: float() argument must be a string or a number, not 'NAType'
Issue Description
When describing a DataFrame
with an Int64
(or pd.Int64Dtype()
for that matter) column instead of an int64
column, a TypeError
is raised. There are several issues around TypeError
s for NA
-like values, but I believe the above is different, as both the dtype
as well as the data
are well defined.
Expected Behavior
import pandas as pd
# pandas Int64 should behave like numpy int64
df = pd.DataFrame({"col": [1]}, dtype="int64")
df.describe()
# col
# count 1.0
# mean 1.0
# std NaN
# min 1.0
# 25% 1.0
# 50% 1.0
# 75% 1.0
# max 1.0
Installed Versions
INSTALLED VERSIONS
commit : 87cfe4e
python : 3.9.13.final.0
python-bits : 64
OS : Linux
OS-release : 5.10.102.1-microsoft-standard-WSL2
Version : #1 SMP Wed Mar 2 00:30:59 UTC 2022
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : C.UTF-8
LOCALE : en_US.UTF-8
pandas : 1.5.0
numpy : 1.23.3
pytz : 2022.4
dateutil : 2.8.2
setuptools : 65.4.1
pip : 22.2.2
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
brotli : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : None
snappy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
zstandard : None
tzdata : None