Resample doesn't work with non-numeric types?

940 views
Skip to first unread message

Dave Hirschfeld

unread,
Mar 18, 2013, 12:33:58 PM3/18/13
to pyd...@googlegroups.com
I have a timeseries which should be at a daily frequency but has some missing samples. I would like to simply forward-fill any missing values.

Using `resample` with `fill_method='ffill'` works fine for numeric data but fails for non-numeric data (see example below).

Since I'm not asking to do e.g. a linear interpolation there seems no need for this restriction. It is of course possible to create a DatetimeIndex spanning
the range and reindex the series with `method='ffill'` but this seems a bit cumbersome (and inefficient?) and makes it harder to write generic code.

Is there a better way to do what I'm after? If not I'll file an enhancement issue if it's considered appropriate.

Thanks,
Dave


In [1]: dates = pd.date_range('01-Jan-2014','05-Jan-2014', freq='D')
   ...: series = pd.TimeSeries(['a','b','c','d','e'], index=dates)
   ...: series[[0,1,3,4]].resample('D', fill_method='ffill')
   ...: 
Traceback (most recent call last):

  File "<ipython-input-1-7640cf6639de>", line 3, in <module>
    series[[0,1,3,4]].resample('D', fill_method='ffill')

  File "C:\dev\bin\Python27\lib\site-packages\pandas\core\generic.py", line 189, in resample
    return sampler.resample(self)

  File "C:\dev\bin\Python27\lib\site-packages\pandas\tseries\resample.py", line 68, in resample
    rs = self._resample_timestamps(obj)

  File "C:\dev\bin\Python27\lib\site-packages\pandas\tseries\resample.py", line 197, in _resample_timestamps
    result = grouped.aggregate(self._agg_method)

  File "C:\dev\bin\Python27\lib\site-packages\pandas\core\groupby.py", line 1258, in aggregate
    return getattr(self, func_or_funcs)(*args, **kwargs)

  File "C:\dev\bin\Python27\lib\site-packages\pandas\core\groupby.py", line 297, in mean
    return self._cython_agg_general('mean')

  File "C:\dev\bin\Python27\lib\site-packages\pandas\core\groupby.py", line 385, in _cython_agg_general
    raise DataError('No numeric types to aggregate')

DataError: No numeric types to aggregate


Jeff Reback

unread,
Mar 18, 2013, 1:11:29 PM3/18/13
to pyd...@googlegroups.com
what pandas version
this should work in 0.11-dev otherwise a bug

--
You received this message because you are subscribed to the Google Groups "PyData" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pydata+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Dave Hirschfeld

unread,
Mar 18, 2013, 4:37:41 PM3/18/13
to pyd...@googlegroups.com


On Monday, March 18, 2013 5:11:29 PM UTC, Jeff wrote:
what pandas version
this should work in 0.11-dev otherwise a bug


This is with the latest GitHub source. I'll file a proper bug report tomorrow if no one beats me to it...

Thanks,
Dave

In [4]: pd.__version__
Out[4]: '0.11.0.dev-308beb1'

In [5]: dates = pd.date_range('01-Jan-2014','05-Jan-2014', freq='D')
   ...: series = pd.TimeSeries(['a','b','c','d','e'], index=dates)
   ...: series[[0,1,3,4]].resample('D', fill_method='ffill')
Traceback (most recent call last):

  File "<ipython-input-5-0aa16d46e7bc>", line 3, in <module>
    series[[0,1,3,4]].resample('D', fill_method='ffill')

  File "C:\dev\bin\Python27\lib\site-packages\pandas\core\generic.py", line 254, in resample
    return sampler.resample(self)

  File "C:\dev\bin\Python27\lib\site-packages\pandas\tseries\resample.py", line 83, in resample
    rs = self._resample_timestamps(obj)

  File "C:\dev\bin\Python27\lib\site-packages\pandas\tseries\resample.py", line 223, in _resample_timestamps
    result = grouped.aggregate(self._agg_method)

  File "C:\dev\bin\Python27\lib\site-packages\pandas\core\groupby.py", line 1415, in aggregate
    return getattr(self, func_or_funcs)(*args, **kwargs)

  File "C:\dev\bin\Python27\lib\site-packages\pandas\core\groupby.py", line 352, in mean
    return self._cython_agg_general('mean')

  File "C:\dev\bin\Python27\lib\site-packages\pandas\core\groupby.py", line 474, in _cython_agg_general

Jeff Reback

unread,
Mar 18, 2013, 4:39:48 PM3/18/13
to pyd...@googlegroups.com
pls do

Dave Hirschfeld

unread,
Mar 19, 2013, 6:44:59 AM3/19/13
to pyd...@googlegroups.com


On Monday, March 18, 2013 8:39:48 PM UTC, Jeff wrote:
pls do


On Mar 18, 2013, at 4:37 PM, Dave Hirschfeld <nov...@gmail.com> wrote:



On Monday, March 18, 2013 5:11:29 PM UTC, Jeff wrote:
what pandas version
this should work in 0.11-dev otherwise a bug


This is with the latest GitHub source. I'll file a proper bug report tomorrow if no one beats me to it...

Thanks,
Dave


Opened issue #3087


-Dave
Reply all
Reply to author
Forward
0 new messages