Aggregation on empty groups fails because of LoadMaps
danielpcox opened this issue · comments
Daniel Cox commented
If I do an Aggregate_SUM
on a Group
from a DataFrame
with no rows, instead of returning 0 like I would expect, it fails at the top of LoadMaps
. This is because Aggregation
calls LoadMaps
at the end to build the resulting DataFrame
, but an empty map slice is an error for LoadMaps
.
In this case, I think it would be best for Aggregate
to never call LoadMaps
with an empty map slice, but rather insert the zero value appropriate for whatever AggregationType
the user picked for all empty groups.
To reproduce:
import(
"fmt"
"github.com/go-gota/gota/dataframe"
"github.com/go-gota/gota/series"
)
df := dataframe.New(
series.New([]string{"e", "Pi", "Phi", "Sqrt2", "Ln2"}, series.String, "Strings"),
series.New([]float64{2.718, 3.142, 1.618, 1.414, 0.693}, series.Float, "Floats"),
)
agg := df.
Filter(dataframe.F{0, "Strings", "==", "DNE"}).
GroupBy("Strings").
Aggregation([]dataframe.AggregationType{dataframe.Aggregation_SUM}, []string{"Floats"})
fmt.Println(agg)
// DataFrame error: load maps: empty array
Martyn commented
just been bitten by this bug, anyone working on a fix?