The following is the problematic code: ``` if is_max: ex_vals = groups[ex_field].idxmax() elif is_min: ex_vals = groups[ex_field].idxmin() ex_rows = df.loc[ex_vals] ``` If the index of `df` is not unique, then the `loc` line can match multiple rows per group.