BUG: Erratic behavior of rolling().std() #53289
Labels
Bug
Duplicate Report
Duplicate issue or pull request
Reduction Operations
sum, mean, min, max, etc.
Window
rolling, ewma, expanding
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
Issue Description
Using .std() on a rolling window on a data set with a "large" range of magnitudes (ie 1e1 to 1e-10) seems to produce erratic results. Comparing to numpy.std shows the expected behavior. The problem seems to be convolved with the range of the data set and the size (1xn) of the data set. Changing just the size of the array in the example above give very different behavior, all incorrect and unexpected:
Array Size R*W, R = 30, W=50

Array Size R*W, R = 17, W=50

Array Size R*W, R = 14, W=50

Expected Behavior
df.rolling(window=W).std() == df.rolling(window=W).apply(np.std)
Installed Versions
INSTALLED VERSIONS
commit : 37ea63d
python : 3.10.10.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.19045
machine : AMD64
processor : Intel64 Family 6 Model 158 Stepping 13, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : English_United States.1252
pandas : 2.0.1
numpy : 1.24.3
pytz : 2023.3
dateutil : 2.8.2
setuptools : 65.5.0
pip : 23.1.2
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.9.2
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.1.2
IPython : 8.11.0
pandas_datareader: None
bs4 : 4.11.2
bottleneck : None
brotli : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : 3.7.1
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.10.1
snappy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
zstandard : None
tzdata : 2023.3
qtpy : None
pyqt5 : None
The text was updated successfully, but these errors were encountered: