0
次のコードを実行すると、FloatingPointErrorが返されます。これはPandasのバグですか? FloatingPointError on ewm()。std()
import traceback
import warnings
import sys
import pandas as pd
import numpy as np
np.seterr(all='raise')
def warn_with_traceback(message, category, filename, lineno, file=None, line=None):
traceback.print_stack()
log = file if hasattr(file,'write') else sys.stderr
log.write(warnings.formatwarning(message, category, filename, lineno, line))
warnings.showwarning = warn_with_traceback
pd.Series(np.random.randn(50)).pct_change().ewm(span=35, min_periods=35).std()
私は次のエラーを取得する:
FloatingPointErrorTraceback (most recent call last)
<ipython-input-2-3db1ff4816cf> in <module>()
----> 1 pd.Series(np.random.randn(50)).pct_change().ewm(span=35, min_periods=35).std()
/projects/anaconda3/lib/python3.5/site-packages/pandas/core/window.py in std(self, bias, **kwargs)
1285 def std(self, bias=False, **kwargs):
1286 """exponential weighted moving stddev"""
-> 1287 return _zsqrt(self.var(bias=bias, **kwargs))
1288
1289 vol = std
/projects/anaconda3/lib/python3.5/site-packages/pandas/core/window.py in _zsqrt(x)
1487 def _zsqrt(x):
1488 result = np.sqrt(x)
-> 1489 mask = x < 0
1490
1491 from pandas import DataFrame
/projects/anaconda3/lib/python3.5/site-packages/pandas/core/ops.py in wrapper(self, other, axis)
761 other = np.asarray(other)
762
--> 763 res = na_op(values, other)
764 if isscalar(res):
765 raise TypeError('Could not compare %s type with Series' %
/projects/anaconda3/lib/python3.5/site-packages/pandas/core/ops.py in na_op(x, y)
714
715 try:
--> 716 result = getattr(x, name)(y)
717 if result is NotImplemented:
718 raise TypeError("invalid type comparison")
FloatingPointError: invalid value encountered in less
は、なぜ私はこれらの警告を取得していますか?これはパンダのバグですか?私の計算が正しいことをどのように確認できますか?