Skip to content

BUG: API Inconsistency between numeric_only and select_dtypes(["number"]) #58210

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
3 tasks done
WillAyd opened this issue Apr 10, 2024 · 2 comments
Open
3 tasks done
Labels
API - Consistency Internal Consistency of API/Behavior Bug

Comments

@WillAyd
Copy link
Member

WillAyd commented Apr 10, 2024

Pandas version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

In [25]: df = pd.DataFrame({"bool": [True, False, True], "int": [1, 2, 3]})

In [26]: df.sum(numeric_only=True)
Out[26]: 
bool    2
int     6
dtype: int64

In [27]: df.select_dtypes(include=["number"]).sum()
Out[27]: 
int    6
dtype: int64


### Issue Description

`numeric_only=True` includes boolean values, whereas `select_dtypes(include=["number"])` does not

### Expected Behavior

If judging by the NumPy type hierarchy the latter is more correct

https://numpy.org/doc/stable/reference/arrays.scalars.html

### Installed Versions

'3.0.0.dev0+681.g434fda08cf'
@WillAyd WillAyd added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Apr 10, 2024
@WillAyd
Copy link
Member Author

WillAyd commented Apr 10, 2024

This is also tangentially related to #41792

@WillAyd WillAyd added API - Consistency Internal Consistency of API/Behavior and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Apr 10, 2024
@sahilwahi7
Copy link

def _reduce_pyarrow in function is doing reduction /pandas/core/arrays/arrow/array.py for df.sum(numeric_only=True)

checking this further

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API - Consistency Internal Consistency of API/Behavior Bug
Projects
None yet
Development

No branches or pull requests

2 participants