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

Allow passing of positional arguments in apply for Groupby objects #2413

Merged
merged 11 commits into from
Dec 24, 2018

Conversation

maaleske
Copy link
Contributor

@maaleske maaleske commented Sep 12, 2018

  • Closes Inconsistent signature of apply #2412
  • Tests added (for all bug fixes or enhancements)
  • Tests passed (for all non-documentation changes)
  • Fully documented, including whats-new.rst for all changes and api.rst for new API

@shoyer
Copy link
Member

shoyer commented Sep 12, 2018

Looks good to me, thanks!

For consistency, can you update the apply method on the classes in xarray/core/resample.py as well?

@shoyer
Copy link
Member

shoyer commented Sep 16, 2018

This still needs tests, to verify that this argument works.

@maaleske
Copy link
Contributor Author

I added tests for groupby. I haven't used resampling so I'm struggling a bit to make a sensible dataset/array for a similar test of the resample method.

@spencerkclark
Copy link
Member

Thanks @maaleske -- following the style of your groupby tests, you could do something like this, e.g. for the DataArray case:

def test_da_resample_func_args():

    def func(arg1, arg2, arg3=0.):
        return arg1.mean('time') + arg2 + arg3

    times = pd.date_range('2000', periods=3, freq='D')
    da = xr.DataArray([1., 1., 1.], coords=[times], dims=['time'])
    expected = xr.DataArray([3., 3., 3.], coords=[times], dims=['time'])
    actual = da.resample(time='D').apply(func, args=(1,), arg3=1)
    assert_identical(actual, expected)

@maaleske
Copy link
Contributor Author

Thanks @spencerkclark, I had almost the exact same code already written but couldn't figure out the return value resample.apply needs from func to work. I added the tests to test_dataarray and test_dataset, since there doesn't appear to be a separate file for resample (as there is for groupby).

@dcherian dcherian mentioned this pull request Oct 24, 2018
5 tasks
@dcherian
Copy link
Contributor

lgtm

@pep8speaks
Copy link

pep8speaks commented Dec 19, 2018

Hello @maaleske! Thanks for updating the PR.

Cheers ! There are no PEP8 issues in this Pull Request. 🍻

Comment last updated on December 24, 2018 at 17:50 Hours UTC

@dcherian dcherian mentioned this pull request Dec 24, 2018
@shoyer shoyer merged commit d8d87d2 into pydata:master Dec 24, 2018
@shoyer
Copy link
Member

shoyer commented Dec 24, 2018

Thanks!

dcherian pushed a commit to yohai/xarray that referenced this pull request Jan 2, 2019
* master:
  DEP: drop python 2 support and associated ci mods (pydata#2637)
  TST: silence warnings from bottleneck (pydata#2638)
  revert to dev version
  DOC: fix docstrings and doc build for 0.11.1
  Source encoding always set when opening datasets (pydata#2626)
  Add flake check to travis (pydata#2632)
  Fix dayofweek and dayofyear attributes from dates generated by cftime_range (pydata#2633)
  silence import warning (pydata#2635)
  fill_value in shift (pydata#2470)
  Flake fixed (pydata#2629)
  Allow passing of positional arguments in `apply` for Groupby objects (pydata#2413)
  Fix failure in time encoding for pandas < 0.21.1 (pydata#2630)
  Fix multiindex selection (pydata#2621)
  Close files when CachingFileManager is garbage collected (pydata#2595)
  added some logic to deal with rasterio objects in addition to filepaths (pydata#2589)
  Get 0d slices of ndarrays directly from indexing (pydata#2625)
  FIX Don't raise a deprecation warning for xarray.ufuncs.{angle,iscomplex} (pydata#2615)
  CF: also decode time bounds when available (pydata#2571)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Inconsistent signature of apply
5 participants