Skip to content

BUG: rolling_count() and expanding_*() return error for empty Series #8056

Closed
@seth-p

Description

@seth-p

This probably should have been caught in #7766, but wasn't.

In [1]: from pandas import Series, rolling_count, expanding_count, expanding_mean

In [2]: expanding_count(Series([]))
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-2-16cb9f6736f0> in <module>()
----> 1 expanding_count(Series([]))

C:\Python34\lib\site-packages\pandas\stats\moments.py in expanding_count(arg, freq, center)
    872     of :meth:`~pandas.Series.resample` (i.e. using the `mean`).
    873     """
--> 874     return rolling_count(arg, len(arg), freq=freq, center=center)
    875
    876

C:\Python34\lib\site-packages\pandas\stats\moments.py in rolling_count(arg, window, freq, center, how)
    188     converted = np.isfinite(values).astype(float)
    189     result = rolling_sum(converted, window, min_periods=1,
--> 190                          center=center)  # already converted
    191
    192     # putmask here?

C:\Python34\lib\site-packages\pandas\stats\moments.py in f(arg, window, min_periods, freq, center, how, **kwargs)
    593             return func(arg, window, minp, **kwds)
    594         return _rolling_moment(arg, window, call_cython, min_periods, freq=freq,
--> 595                                center=center, how=how, **kwargs)
    596
    597     return f

C:\Python34\lib\site-packages\pandas\stats\moments.py in _rolling_moment(arg, window, func, minp, axis, freq, center, how, args, kwa
rgs, **kwds)
    345         result = np.apply_along_axis(calc, axis, values)
    346     else:
--> 347         result = calc(values)
    348
    349     rs = return_hook(result)

C:\Python34\lib\site-packages\pandas\stats\moments.py in <lambda>(x)
    339     arg = _conv_timerule(arg, freq, how)
    340     calc = lambda x: func(x, window, minp=minp, args=args, kwargs=kwargs,
--> 341                           **kwds)
    342     return_hook, values = _process_data_structure(arg)
    343     # actually calculate the moment. Faster way to do this?

C:\Python34\lib\site-packages\pandas\stats\moments.py in call_cython(arg, window, minp, args, kwargs, **kwds)
    591         def call_cython(arg, window, minp, args=(), kwargs={}, **kwds):
    592             minp = check_minp(minp, window)
--> 593             return func(arg, window, minp, **kwds)
    594         return _rolling_moment(arg, window, call_cython, min_periods, freq=freq,
    595                                center=center, how=how, **kwargs)

C:\Python34\lib\site-packages\pandas\algos.pyd in pandas.algos.roll_sum (pandas\algos.c:25271)()

C:\Python34\lib\site-packages\pandas\algos.pyd in pandas.algos._check_minp (pandas\algos.c:16394)()

ValueError: min_periods (1) must be <= window (0)

In [3]: rolling_count(Series([]), window=3)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-3-040797e90b09> in <module>()
----> 1 rolling_count(Series([]), window=3)

C:\Python34\lib\site-packages\pandas\stats\moments.py in rolling_count(arg, window, freq, center, how)
    188     converted = np.isfinite(values).astype(float)
    189     result = rolling_sum(converted, window, min_periods=1,
--> 190                          center=center)  # already converted
    191
    192     # putmask here?

C:\Python34\lib\site-packages\pandas\stats\moments.py in f(arg, window, min_periods, freq, center, how, **kwargs)
    593             return func(arg, window, minp, **kwds)
    594         return _rolling_moment(arg, window, call_cython, min_periods, freq=freq,
--> 595                                center=center, how=how, **kwargs)
    596
    597     return f

C:\Python34\lib\site-packages\pandas\stats\moments.py in _rolling_moment(arg, window, func, minp, axis, freq, center, how, args, kwa
rgs, **kwds)
    345         result = np.apply_along_axis(calc, axis, values)
    346     else:
--> 347         result = calc(values)
    348
    349     rs = return_hook(result)

C:\Python34\lib\site-packages\pandas\stats\moments.py in <lambda>(x)
    339     arg = _conv_timerule(arg, freq, how)
    340     calc = lambda x: func(x, window, minp=minp, args=args, kwargs=kwargs,
--> 341                           **kwds)
    342     return_hook, values = _process_data_structure(arg)
    343     # actually calculate the moment. Faster way to do this?

C:\Python34\lib\site-packages\pandas\stats\moments.py in call_cython(arg, window, minp, args, kwargs, **kwds)
    591         def call_cython(arg, window, minp, args=(), kwargs={}, **kwds):
    592             minp = check_minp(minp, window)
--> 593             return func(arg, window, minp, **kwds)
    594         return _rolling_moment(arg, window, call_cython, min_periods, freq=freq,
    595                                center=center, how=how, **kwargs)

C:\Python34\lib\site-packages\pandas\algos.pyd in pandas.algos.roll_sum (pandas\algos.c:25271)()

C:\Python34\lib\site-packages\pandas\algos.pyd in pandas.algos._check_minp (pandas\algos.c:16394)()

ValueError: min_periods (1) must be <= window (0)

In [5]: expanding_mean(Series([]))
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-5-b131e71cc033> in <module>()
----> 1 expanding_mean(Series([]))

C:\Python34\lib\site-packages\pandas\stats\moments.py in f(arg, min_periods, freq, center, **kwargs)
    825             return func(arg, window, minp, **kwds)
    826         return _rolling_moment(arg, window, call_cython, min_periods, freq=freq,
--> 827                                center=center, **kwargs)
    828
    829     return f

C:\Python34\lib\site-packages\pandas\stats\moments.py in _rolling_moment(arg, window, func, minp, axis, freq, center, how, args, kwa
rgs, **kwds)
    345         result = np.apply_along_axis(calc, axis, values)
    346     else:
--> 347         result = calc(values)
    348
    349     rs = return_hook(result)

C:\Python34\lib\site-packages\pandas\stats\moments.py in <lambda>(x)
    339     arg = _conv_timerule(arg, freq, how)
    340     calc = lambda x: func(x, window, minp=minp, args=args, kwargs=kwargs,
--> 341                           **kwds)
    342     return_hook, values = _process_data_structure(arg)
    343     # actually calculate the moment. Faster way to do this?

C:\Python34\lib\site-packages\pandas\stats\moments.py in call_cython(arg, window, minp, args, kwargs, **kwds)
    823         def call_cython(arg, window, minp, args=(), kwargs={}, **kwds):
    824             minp = check_minp(minp, window)
--> 825             return func(arg, window, minp, **kwds)
    826         return _rolling_moment(arg, window, call_cython, min_periods, freq=freq,
    827                                center=center, **kwargs)

C:\Python34\lib\site-packages\pandas\algos.pyd in pandas.algos.roll_mean (pandas\algos.c:25815)()

C:\Python34\lib\site-packages\pandas\algos.pyd in pandas.algos._check_minp (pandas\algos.c:16394)()

ValueError: min_periods (1) must be <= window (0)

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugNumeric OperationsArithmetic, Comparison, and Logical operations

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions