question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

API: numeric_only in Series ops behavior

See original GitHub issue

Part 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:

  1. Ops raise NotImplementedError if numeric_only is truthy (the Series behavior)
  2. Ops ignore numeric_only when the dtype is numeric (the SeriesGroupBy behavior)
  3. 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:closed
  • Created a year ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
rhshadrachcommented, Jun 29, 2022

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.

0reactions
rhshadrachcommented, Jul 13, 2022

This was discussed in the July dev meeting and consensus was that raising in this situation for 1.5 is preferred.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found