Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
jorisvandenbossche opened this issue Oct 7, 2020 · 4 comments · Fixed by #37198
Labels
Apply Apply, Aggregate, Transform, Map Regression Functionality that used to work in a prior pandas version Resample resample method
Milestone

Comments

@jorisvandenbossche
Copy link
Member

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

@jorisvandenbossche jorisvandenbossche added Regression Functionality that used to work in a prior pandas version Resample resample method Apply Apply, Aggregate, Transform, Map labels Oct 7, 2020
@jorisvandenbossche jorisvandenbossche added this to the 1.1.4 milestone Oct 7, 2020
@jbrockmendel
Copy link
Member

i dont think this was intentional

@simonjayhawkins
Copy link
Member

The PR to fix this issues fails on the backport. #37305

since this regression is from 0.25.3 to 1.0.0, we could decide not to backport.

the issue is the index frequency is None on 1.1.x here...

result = grouped.apply(how, *args, **kwargs)

@jbrockmendel any ideas where changes in master could have corrected this?

@simonjayhawkins
Copy link
Member

Note: the regression reported here is probably due to #29077

@simonjayhawkins
Copy link
Member

maybe #35563 is related but that still fails on master

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Apply Apply, Aggregate, Transform, Map Regression Functionality that used to work in a prior pandas version Resample resample method
Projects
None yet
3 participants