python - Is this a bug in Pandas? FloatingPointError on ewm().std() -
when execute following, floatingpointerror.
import traceback import warnings import sys import pandas pd import numpy 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()
i following error:
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 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 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 notimplemented: 718 raise typeerror("invalid type comparison") floatingpointerror: invalid value encountered in less
why getting these warnings? bug in pandas? how can sure calculations correct?
np.seterr(all='raise')
causing issue.
check out: pandas: floatingpointerror np.seterr(all='raise') , missing data
the output of pd.series(np.random.randn(50)).pct_change().ewm(span=35, min_periods=35).std()
without np.seterr(all='raise')
is:
0 nan 1 nan 2 nan 3 nan 4 nan 5 nan 6 nan 7 nan 8 nan 9 nan 10 nan 11 nan 12 nan 13 nan 14 nan 15 nan 16 nan 17 nan 18 nan 19 nan 20 nan 21 nan 22 nan 23 nan 24 nan 25 nan 26 nan 27 nan 28 nan 29 nan 30 nan 31 nan 32 nan 33 nan 34 nan 35 9.927862 36 9.636469 37 9.360825 38 9.061078 39 8.792150 40 8.549347 41 8.284875 42 8.026411 43 7.779943 44 7.563633 45 7.331553 46 7.114672 47 6.898717 48 6.716513 49 6.514064 dtype: float64
Comments
Post a Comment