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

Resample nearest #17496

shoyer opened this Issue Sep 11, 2017 · 0 comments


None yet
2 participants

shoyer commented Sep 11, 2017

pandas supports "pad" (forward fill) and "backfill" upsampling, but not "nearest" upsampling. This could be a nice feature to have, and should be pretty easy, too, as the underlying Index.get_indexer method already supports method='nearest'.

Possibly this would be as easy as adding only a few lines to the Resampler class in pandas/core/ Just monkey-patching this one-liner method seems to work:

In [47]: def nearest(self, limit=None):
    ...:     return self._upsample('nearest', limit=limit)

In [48]: pd.core.resample.Resampler.nearest = nearest

In [49]: index = pd.date_range('1/1/2000', periods=9, freq='T')

In [50]: series = pd.Series(range(9), index=index)

In [51]: series.resample('20s').nearest()[:5]
2000-01-01 00:00:00    0
2000-01-01 00:00:20    0
2000-01-01 00:00:40    1
2000-01-01 00:01:00    1
2000-01-01 00:01:20    1
Freq: 20S, dtype: int64

Obviously this needs tests and documentation. Potetially this could be a good project for a new contributor.

This came up in pydata/xarray#1272 where we are copying the new pandas resample() API to xarray.

@ab320012 ab320012 referenced this issue Sep 11, 2017


added nearest to resample + test #17498

4 of 4 tasks complete

@shoyer shoyer referenced this issue Sep 13, 2017


Groupby-like API for resampling #1272

9 of 9 tasks complete

@jreback jreback added this to the 0.21.0 milestone Sep 15, 2017

@jreback jreback added the Enhancement label Sep 15, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment