API: SeriesGroupBy.product with numeric_only and empty non-numeric data · Issue #41291 · pandas-dev/pandas (original) (raw)

Skip to content

Provide feedback

Saved searches

Use saved searches to filter your results more quickly

Sign up

Appearance settings

@jbrockmendel

Description

@jbrockmendel

By default numeric_only=True. But when there are no numeric columns and we raise DataError, the fallback ignores numeric_only. So we end up getting wonky results.

Below I think that gb1 raising is correct, gb3 should raise, gb2 and gb4 should return empty DataFrames. cc @jreback @jorisvandenbossche @TomAugspurger @WillAyd

dti = pd.date_range("2016-01-01", periods=3)
ser = pd.Series(dti)
df = ser.to_frame()

gb1 = ser.groupby([0, 0, 0])
gb2 = df.groupby(gb1.grouper)
gb3 = ser[:0].groupby([])
gb4 = df[:0].groupby([])

>>> gb1.prod()
TypeError: 'DatetimeArray' does not implement reduction 'prod'

>>> gb2.prod()  # <-float64
    0
0 NaN

>>> gb3.prod()
Series([], dtype: datetime64[ns])

>>> gb4.prod()  # <- dt64
Empty DataFrame
Columns: [0]
Index: []