Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: rolling functions raise ValueError on float32 data #12373

Closed
jennolsen84 opened this issue Feb 17, 2016 · 1 comment

Comments

Projects
None yet
2 participants
@jennolsen84
Copy link
Contributor

commented Feb 17, 2016

pd version: v0.18.0rc1

minimal example:

import pandas as pd
import numpy as np
pd.DataFrame(np.arange(5, dtype=np.float32)).rolling(window=3).max()

stack trace:

<ipython-input-25-795ba6485799> in <module>()
----> 1 pd.DataFrame(np.arange(5, dtype=np.float32)).rolling(window=3).max()

/venv/lib/python3.4/site-packages/pandas/core/window.py in max(self, **kwargs)
    767     @Appender(_shared_docs['max'])
    768     def max(self, **kwargs):
--> 769         return super(Rolling, self).max(**kwargs)
    770 
    771     @Substitution(name='rolling')

/venv/lib/python3.4/site-packages/pandas/core/window.py in max(self, how, **kwargs)
    541         if self.freq is not None and how is None:
    542             how = 'max'
--> 543         return self._apply('roll_max', how=how, **kwargs)
    544 
    545     _shared_docs['min'] = dedent("""

/venv/lib/python3.4/site-packages/pandas/core/window.py in _apply(self, func, window, center, check_minp, how, **kwargs)
    474 
    475             if values.ndim > 1:
--> 476                 result = np.apply_along_axis(calc, self.axis, values)
    477             else:
    478                 result = calc(values)

/venv/lib/python3.4/site-packages/numpy/lib/shape_base.py in apply_along_axis(func1d, axis, arr, *args, **kwargs)
     89     outshape = asarray(arr.shape).take(indlist)
     90     i.put(indlist, ind)
---> 91     res = func1d(arr[tuple(i.tolist())], *args, **kwargs)
     92     #  if res is a number, then we have a smaller output array
     93     if isscalar(res):

/venv/lib/python3.4/site-packages/pandas/core/window.py in calc(x)
    471 
    472                 def calc(x):
--> 473                     return func(x, window, min_periods=self.min_periods)
    474 
    475             if values.ndim > 1:

/venv/lib/python3.4/site-packages/pandas/core/window.py in func(arg, window, min_periods)
    458                 def func(arg, window, min_periods=None):
    459                     minp = check_minp(min_periods, window)
--> 460                     return cfunc(arg, window, minp, **kwargs)
    461 
    462             # calculation function

pandas/algos.pyx in pandas.algos.roll_max (pandas/algos.c:37363)()

ValueError: Buffer dtype mismatch, expected 'float64_t' but got 'float'

@jennolsen84 jennolsen84 changed the title BUG: rolling functions raises ValueError float32 data BUG: rolling functions raise ValueError float32 data Feb 17, 2016

@jennolsen84 jennolsen84 changed the title BUG: rolling functions raise ValueError float32 data BUG: rolling functions raise ValueError on float32 data Feb 17, 2016

@jreback jreback added this to the 0.18.0 milestone Feb 18, 2016

@jreback

This comment has been minimized.

Copy link
Contributor

commented Feb 18, 2016

I think I forgot the casting (these should really have dtype specific functions, e.g. float32/float64), but that's your other issue.

> /Users/jreback/pandas/pandas/core/window.py(460)func()
    458                 def func(arg, window, min_periods=None):
    459                     minp = check_minp(min_periods, window)
--> 460                     return cfunc(arg, window, minp, **kwargs)
    461 
    462             # calculation function

ipdb> p arg
array([ 0.,  1.,  2.,  3.,  4.], dtype=float32)
ipdb> p cfunc
<built-in function roll_max>
ipdb> p cfunc(com._ensure_float64(arg), window, minp, **kwargs)
array([ nan,  nan,   2.,   3.,   4.])

want to do a PR to fix?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.