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

DOC: pandas.DataFrame.aggregate return value #60645

Closed
1 task done
sa42bme opened this issue Jan 2, 2025 · 1 comment
Closed
1 task done

DOC: pandas.DataFrame.aggregate return value #60645

sa42bme opened this issue Jan 2, 2025 · 1 comment
Labels
Docs Duplicate Report Duplicate issue or pull request

Comments

@sa42bme
Copy link

sa42bme commented Jan 2, 2025

Pandas version checks

  • I have checked that the issue still exists on the latest versions of the docs on main here

Location of the documentation

https://pandas.pydata.org/docs/dev/reference/api/pandas.DataFrame.aggregate.html#pandas.DataFrame.aggregate

Documentation problem

The documentation of pandas.DataFrame.aggregate() method says:

The return can be:

* scalar : when Series.agg is called with single function
* Series : when DataFrame.agg is called with a single function
* DataFrame : when DataFrame.agg is called with several functions

But
df = pd.DataFrame([[1]]) ; type(df.agg(lambda x: 3*x))
returns pandas.core.frame.DataFrame even though .agg() was called with a single function

Suggested fix for documentation

I'd love to offer a fix, but the reason I was looking up the docs was that I'd like to know what .agg() does exactly...

@sa42bme sa42bme added Docs Needs Triage Issue that has not been reviewed by a pandas team member labels Jan 2, 2025
@rhshadrach
Copy link
Member

Thanks for the report. This is #35725.

Ideally users would only pass aggregating functions to .agg. I think the current result here is incorrect, and it should be Series([Series([3])]) instead. Unfortunately it is not so easy to fix because the implementation is intertwined with apply. We made some progress on it in the 2.x development, but need to wait until 3.x to make more.

We could document this in the meantime, but I don't think we should document buggy behavior.

@rhshadrach rhshadrach added Duplicate Report Duplicate issue or pull request and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Jan 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Docs Duplicate Report Duplicate issue or pull request
Projects
None yet
Development

No branches or pull requests

2 participants