2016-06-29 8 views
0

다음을 실행하면 FloatingPointError가 발생합니다.팬더에 버그가 있습니까? FloatingPointError on ewm(). 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 

가 왜 이러한 경고를 받고 오전 :

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() 

나는 다음과 같은 오류가? 팬더스의 버그 야? 계산이 정확한지 어떻게 확신 할 수 있습니까?

답변

0

np.seterr(all='raise')이 문제의 원인입니다.

에 체크를 아웃 : np.seterr(all='raise')없이 pd.Series(np.random.randn(50)).pct_change().ewm(span=35, min_periods=35).std()의 출력은

입니다 pandas: FloatingPointError with np.seterr(all='raise') and missing data :

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 
관련 문제