API: add numeric_only support to groupby agg
State: closed

Currently in early phase seeking prelim feedback.

- [x] partially addresses #56946, relevant to #50538
- [ ] [Tests added and passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#writing-tests) if fixing a bug or adding a new feature
- [ ] All [code checks passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#pre-commit).
- [ ] Added [type annotations](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#type-hints) to new arguments/methods/functions.
- [ ] Added an entry in the latest `doc/source/whatsnew/vX.X.X.rst` file if fixing a bug or adding a new feature.


Labels:
name: Stale

Comments:
Currently still not operating on the right numbers on test case `numeric_only True - 1_grouper_str - numpy_mean`.

Need to add test cases with expected data.
> Currently still not operating on the right numbers on test case `numeric_only True - 1_grouper_str - numpy_mean`.
> 
> Need to add test cases with expected data.

Failing may be an existing bug - documented here: https://github.com/pandas-dev/pandas/issues/58146

Also mangled up the ResamplerApply - need to rethink strategy
> Thanks for the PR! It looks like you are using `**kwargs` to pass `numeric_only` in the call to `agg`. These `kwargs` are meant for the user to pass through to the function and I do not think we should be allowing "built-in" arguments into them. Instead, `numeric_only` should be added to the signature of `agg`.
> 
> ~In addition, it appears that there are various paths through `agg` that do not respect `numeric_only`, e.g. `df.groupby(...).agg("sum", numeric_only=True)`.~ because `**kwargs` is passed through, this was wrong!

Thank you for this note, I had assumed that we did not want to explicitly take `numeric_only` as a `kwarg` based on this comment:
https://github.com/pandas-dev/pandas/issues/49352#issuecomment-1304799900

If taking `numeric_only` as an arguement is the preferred method, this would probably greatly simplify things. One of my big struggles was the paths changing with and without `kwargs` but that can be more easily managed if we aren't feeding through `kwargs`.

Note that this was a half-cooked draft PR because I ran into #39169 bug, and had submitted PR #58132, but you mentioned we will be deprecating before doing a more complete fix.
> Thank you for this note, I had assumed that we did not want to explicitly take `numeric_only` as a `kwarg` based on this comment:
> [#49352 (comment)](https://github.com/pandas-dev/pandas/issues/49352#issuecomment-1304799900)

That was if we were to fix it in a patch version (1.5.2). For 3.0, I think we should prefer a new argument.

> If taking `numeric_only` as an arguement is the preferred method, this would probably greatly simplify things.

It would also be more straightforward for users!

> Note that this was a half-cooked draft PR because I ran into #39169 bug

Yes - I think I failed to notice it was in draft status when I first reviewed. My bad.

This pull request is stale because it has been open for thirty days with no activity. Please [update](https://pandas.pydata.org/pandas-docs/stable/development/contributing.html#updating-your-pull-request) and respond to this comment if you're still interested in working on this.
Closing as much of this will be addressed with a different PR, a fundamental misunderstanding of whether `numeric_only` should be its own kwarg, and the changes here being breaking changes that require more performance assessment.

Thank you to @rhshadrach for your time and your feedback on this PR. Will keep the above in mind for any future contributions I make.