dfply icon indicating copy to clipboard operation
dfply copied to clipboard

group_by fails to raise exception for missing key

Open ghost opened this issue 6 years ago • 0 comments

A missing group_by column does not raise an exception.

                                                                                                                                                                                                                                                       
In [15]: pd.DataFrame({'a': [1,2,2], 'b': [4,5,6]}) >> group_by('c')                                                                                                                                                                                       
Out[15]:                                                                                                                                                                                                                                                   
   a  b                                                                                                                                                                                                                                                       
0  1  4                                                                                                                                                                                                                                                       
1  2  5                                                                                                                                                                                                                                                       
2  2  6                                                                                                                                                                                                                                                      
                                      

In dplyr, the equivalent situation raises an error:

library(tidyverse)
> data.frame(a=c(1,2,2), b=c(4,5,6)) %>% group_by(c)
Error in grouped_df_impl(data, unname(vars), drop) : 
  Column `c` is unknown

My preference would be for this error to raise an exception instead of passing silently.

ghost avatar Jan 31 '19 22:01 ghost