Skip to content

REGR: resample apply fails with KeyError/AttributeError for function that works on DataFrame but fails on Series #36951

Closed
@jorisvandenbossche

Description

@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

Metadata

Metadata

Assignees

No one assigned

    Labels

    ApplyApply, Aggregate, Transform, MapRegressionFunctionality that used to work in a prior pandas versionResampleresample method

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions