Repository navigation
resample.agg - #3202
resample.agg#3202
Conversation
mrocklin
left a comment
There was a problem hiding this comment.
I'm glad to see changes like this. I suspect that @TomAugspurger might want to take a look.
It would be useful to add a test or two first though to ensure correctness into the future.
| return Series(dsk, name, meta, outdivs) | ||
|
|
||
| @derived_from(pd_Resampler) | ||
| def agg(self, *args): |
There was a problem hiding this comment.
I notice that the pandas version of this also supports **kwargs. Should we do the same here?
There was a problem hiding this comment.
Yeah. These keywords are passed through to the aggfunc, so .agg('std', ddof=0)
|
|
||
| Core | ||
| ++++ | ||
|
|
There was a problem hiding this comment.
Thank you for setting this up! My bad on omitting it when doing the last release.
| DataFrame | ||
| +++++++++ | ||
|
|
||
| - Add ``dd.tseries.Resampler.agg`` (:pr:`3202`) `Richard Postelnik`_ |
There was a problem hiding this comment.
You'll also want to add your name and a website to the bottom of this document.
| self._kwargs = kwargs | ||
|
|
||
| def _agg(self, how, meta=None, fill_value=np.nan): | ||
| def _agg(self, how, meta=None, fill_value=np.nan, how_args=[]): |
There was a problem hiding this comment.
Mind changing this to a tuple so that it's immutable? Just in case the function is refactored in the future.
| return Series(dsk, name, meta, outdivs) | ||
|
|
||
| @derived_from(pd_Resampler) | ||
| def agg(self, *args): |
There was a problem hiding this comment.
Yeah. These keywords are passed through to the aggfunc, so .agg('std', ddof=0)
|
Ok made the changes, @TomAugspurger need some advice for the kwargs test, see comment. |
| ds = dd.from_pandas(ps, npartitions=2) | ||
| def foo(series, *args, bar=1): | ||
| return [bar] * len(series) | ||
| res = ds.resample('10min').agg(foo, bar=2) |
There was a problem hiding this comment.
@TomAugspurger can't get this mock test to work. Not sure the correct syntax for an aggregate function. Tried a variety of signatures.
There was a problem hiding this comment.
I would avoid functions that return sequences. Does it work if you just apply a function like `len(x) * bar
And does it fail on the dask side or the pandas side?
There was a problem hiding this comment.
I get a dask error if i try to compute:
TypeError: foo() missing 1 required positional argument: 'series'
The odd part is that it gets past the step where it tries to determine the meta here: https://github.com/dask/dask/pull/3202/files#diff-394a2aeb5f331b788b4adb6242f9091aR125
There was a problem hiding this comment.
This is because having the tuple (foo,) in the task graph gets evaluated as foo(). I've changed this to [foo] and pushed.
There was a problem hiding this comment.
I've also screwed with the test a bit. Things fail around the midpoint of the resample.
There was a problem hiding this comment.
@mrocklin thanks, with your fix and choosing a proper sample freq the test passes.
This gets evaluated eagerly. Convert to list instead. Also a couple of minor style changes.
|
Note, this fails with syntax errors in Python 2. Check travis-ci. |
|
@mrocklin fixed tests |
TomAugspurger
left a comment
There was a problem hiding this comment.
Looks good to me. Will merge tomorrow unless @mrocklin has any further thoughts.
|
Merged. Thanks for your work here @postelrich ! |
This PR adds in
resample.aggthat allows for something likedf['col'].resample('1min').agg(['mean', 'min']). Seems like a trivial add but useful feature so adding it.flake8 daskdocs/source/changelog.rstfor all changesand one of the
docs/source/*-api.rstfiles for new API