Skip to content

BUG: RuntimeWarning on describe for a single element Series of dtype Float64 #52515

Closed
@arnaudlegout

Description

@arnaudlegout

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
import numpy as np

# here we have a regular behavior for the dtype np.float64
>>> s = pd.Series([0.0], index=[0], dtype=np.float64)
>>> s.describe()
count    1.0
mean     0.0
std      NaN
min      0.0
25%      0.0
50%      0.0
75%      0.0
max      0.0
dtype: float64

# with the dtype Float64, the result is still correct, but there is a strange warning raised
>>> s = pd.Series([0.0], index=[0], dtype='Float64')
>>> s.describe()
C:\Users\alegout\AppData\Local\miniconda3\envs\py3.11\Lib\site-packages\numpy\core\_methods.py:265: RuntimeWarning: Degrees of freedom <= 0 for slice
  ret = _var(a, axis=axis, dtype=dtype, out=out, ddof=ddof,
C:\Users\alegout\AppData\Local\miniconda3\envs\py3.11\Lib\site-packages\numpy\core\_methods.py:257: RuntimeWarning: invalid value encountered in double_scalars
  ret = ret.dtype.type(ret / rcount)
count     1.0
mean      0.0
std      <NA>
min       0.0
25%       0.0
50%       0.0
75%       0.0
max       0.0
dtype: Float64

Issue Description

computing a describe on a single element Series should work without any working. When the dtype is Float64, there is a RuntimeWarning that is not raised with the dtype np.float64.

Expected Behavior

I expect no warning with the extended dtype

Installed Versions

INSTALLED VERSIONS

commit : 478d340
python : 3.11.2.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.19044
machine : AMD64
processor : Intel64 Family 6 Model 140 Stepping 1, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : fr_FR.cp1252

pandas : 2.0.0
numpy : 1.23.5
pytz : 2022.7
dateutil : 2.8.2
setuptools : 65.6.3
pip : 23.0.1
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.9.1
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.1.2
IPython : 8.10.0
pandas_datareader: None
bs4 : 4.12.0
bottleneck : 1.3.5
brotli :
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : 3.7.1
numba : None
numexpr : 2.8.4
odfpy : None
openpyxl : 3.0.10
pandas_gbq : None
pyarrow : 10.0.1
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.10.0
snappy : None
sqlalchemy : None
tables : None
tabulate : 0.8.10
xarray : None
xlrd : None
zstandard : None
tzdata : 2023.3
qtpy : 2.2.0
pyqt5 : None

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugNA - MaskedArraysRelated to pd.NA and nullable extension arraysReduction Operationssum, mean, min, max, etc.RegressionFunctionality that used to work in a prior pandas version

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions