Skip to content

ENH: Support reduction methods on Index(?) #50021

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

Open
1 of 3 tasks
mroeschke opened this issue Dec 2, 2022 · 6 comments
Open
1 of 3 tasks

ENH: Support reduction methods on Index(?) #50021

mroeschke opened this issue Dec 2, 2022 · 6 comments
Labels
Enhancement Index Related to the Index class or subclasses Needs Discussion Requires discussion from core team before further action Reduction Operations sum, mean, min, max, etc.

Comments

@mroeschke
Copy link
Member

Feature Type

  • Adding new functionality to pandas

  • Changing existing functionality in pandas

  • Removing existing functionality in pandas

Problem Description

In theory, a numeric Index could support reduction functions as a "1D list-like object" and closer align to Series in this way as well. Of course reduction functions might not make sense on some Index subclasses (MultiIndex, IntervalIndex, etc)

cuDF Index supports reduction functions and are considering deprecating them to align with the pandas Index API, but opening this issue to gauge whether pandas actually wants to support reduction functions on Index rapidsai/cudf#12284

Current reduction functions supported on Series:

pandas/pandas/conftest.py

Lines 1036 to 1048 in 36dcf51

_all_numeric_reductions = [
"count",
"sum",
"max",
"min",
"mean",
"prod",
"std",
"var",
"median",
"kurt",
"skew",
"sem",

Feature Description

Defining _reduce on Index which can dispatch to EA._reduce if an EA type or use a nanop method otherwise?

Alternative Solutions

index.to_series().<reduction_op>(...)

Additional Context

No response

@mroeschke mroeschke added Enhancement Needs Triage Issue that has not been reviewed by a pandas team member Needs Discussion Requires discussion from core team before further action Index Related to the Index class or subclasses Reduction Operations sum, mean, min, max, etc. and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Dec 2, 2022
@phofl
Copy link
Member

phofl commented Dec 2, 2022

I am not sure what I would use it for. Do you have any examples in mind where this would be helpful?

@mroeschke
Copy link
Member Author

Especially with to_series, I would also say the practical use case isn't that strong. There might be a subset of users who treat Index as an array-like object and might find it convenient to have reductions?

Additionally, Index objects already do support arithmetic and logical operations so there's some notion of Index supporting numeric array like operations.

@phofl
Copy link
Member

phofl commented Dec 2, 2022

Ok treating them as an array-like object makes sense. Just asking, because I never had a situation where this would have been helpful.

@jreback
Copy link
Contributor

jreback commented Dec 2, 2022

no objection as long as these dispatch

@jbrockmendel
Copy link
Member

+1 on making Index behave like Series where feasible

@jbrockmendel
Copy link
Member

xref #54566 moves closer to the pattern suggested here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement Index Related to the Index class or subclasses Needs Discussion Requires discussion from core team before further action Reduction Operations sum, mean, min, max, etc.
Projects
None yet
Development

No branches or pull requests

4 participants