REGR: resample apply fails with KeyError/AttributeError for function that works on DataFrame but fails on Series · Issue #36951 · pandas-dev/pandas (original) (raw)

@jorisvandenbossche

A resample apply accessing a column of the subsetted dataframe fails (bubbling up the error from first trying the function on a single column, i.e. a Series):

In [25]: df = pd.DataFrame({"col": range(10)}, index=pd.date_range("2012-01-01", periods=10, freq="20min"))  

In [26]: df.resample("H").apply(lambda group: len(group['col'].unique()))   
...
KeyError: 'col'

In [27]: df.resample("H").apply(lambda group: len(group.col.unique())) 
...
AttributeError: 'Series' object has no attribute 'col'

This seems a regression, or was there a deliberate change in apply to only apply it on the columns and no longer on the full DataFrame ?
cc @jbrockmendel