Skip to content

pandas.ewma doesn't handle empty inputs correctly #1900

@erg

Description

@erg
In [34]: pandas.ewma(np.array([]), 3)
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-34-dd4e4b00c97b> in <module>()
----> 1 pandas.ewma(np.array([]), 3)

/usr/lib/python2.7/site-packages/pandas-0.9.0.dev_c32cc6e-py2.7-linux-x86_64.egg/pandas/stats/moments.pyc in ewma(arg, com, span, min_periods, freq, time_rule, adjust)
    307 
    308     return_hook, values = _process_data_structure(arg)
--> 309     output = np.apply_along_axis(_ewma, 0, values)
    310     return return_hook(output)
    311 

/usr/lib/python2.7/site-packages/numpy/lib/shape_base.pyc in apply_along_axis(func1d, axis, arr, *args)
     78     outshape = asarray(arr.shape).take(indlist)
     79     i.put(indlist, ind)
---> 80     res = func1d(arr[tuple(i.tolist())],*args)
     81     #  if res is a number, then we have a smaller output array
     82     if isscalar(res):

/usr/lib/python2.7/site-packages/pandas-0.9.0.dev_c32cc6e-py2.7-linux-x86_64.egg/pandas/stats/moments.pyc in _ewma(v)
    301 
    302     def _ewma(v):
--> 303         result = lib.ewma(v, com, int(adjust))
    304         first_index = _first_valid_index(v)
    305         result[first_index : first_index + min_periods] = NaN

/usr/lib/python2.7/site-packages/pandas-0.9.0.dev_c32cc6e-py2.7-linux-x86_64.egg/pandas/lib.so in pandas.lib.ewma (pandas/src/tseries.c:74301)()

IndexError: Out of bounds on buffer access (axis 0)

I think it should output an empty array instead, like rolling_sum.

In [43]: pandas.rolling_sum(np.array([]), 3)
Out[43]: array([], dtype=float64)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions