API: numeric_only in Series ops behavior
See original GitHub issuePart of #46560
For Series and SeriesGroupBy ops (and perhaps others like resample, rolling, window, expanding, ewm), there is an inconsistency when numeric_only is passed to ops that have it as an argument:
ser = pd.Series([1, 2, 3])
print(ser.mean(numeric_only=True))
# Raises `NotImplementedError: Series.mean does not implement numeric_only.`
print(ser.mean(numeric_only=False))
# 2.0
print(ser.groupby([0, 0, 1]).mean(numeric_only=True))
# 0 1.5
# 1 3.0
# dtype: float64
print(ser.groupby([0, 0, 1]).mean(numeric_only=False))
# 0 1.5
# 1 3.0
# dtype: float64
I see three possible options:
- Ops raise NotImplementedError if numeric_only is truthy (the Series behavior)
- Ops ignore numeric_only when the dtype is numeric (the SeriesGroupBy behavior)
- Ops raise if anything is passed (I don’t know of any ops that act like this currently)
I am in favor of 1 - I view passing in numeric_only=True
as erroneous; it doesn’t make sense to request this from a Series even if it is a no-op. On the other hand, I view passing in numeric_only=False
as “requesting nothing”, though perhaps it is slightly odd. Option 1 would also allow the default to be False across all ops (in pandas 2.0).
Issue Analytics
- State:
- Created a year ago
- Comments:7 (7 by maintainers)
Top Results From Across the Web
Component API Reference - Pipedream
The name of the component, a string which identifies components deployed to users' accounts. This name will show up in the Pipedream UI,...
Read more >Tezos API Reference | TzStats
The TzStats Tezos API supports different kinds of endpoints: explorer detailed on-chain data objects like blocks, accounts, operations, votes; table for bulk ...
Read more >What's new in 1.3.0 (July 2, 2021) - Pandas
sum ) on a DataFrame with numeric_only=None (the default), columns where the reduction raises a TypeError are silently ignored and dropped from the...
Read more >React Native TextInput that only accepts numeric characters
I am using keyboardType='numeric' prop in TextInput to only show Numeric Keyboard (duh) ... OP specifically mentions that as a non-solution in the...
Read more >Stripe API reference – curl
Complete reference documentation for the Stripe API. Includes code snippets and ... The outcome of a series of EMV functions performed by the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
That makes sense. Allowing
numeric_only=True
to work on Series with numeric dtype also allows a user to have an op that will raise if a dtype is non-numeric, which perhaps could be useful. ALso, it’s a smaller (and easier) change. I’m going to go with your suggestion.This was discussed in the July dev meeting and consensus was that raising in this situation for 1.5 is preferred.