From 19f891cec0c846a68036ef6f3e32477c37d61136 Mon Sep 17 00:00:00 2001 From: Charles Gregory Date: Wed, 9 Sep 2020 03:11:39 -0400 Subject: [PATCH] allow filtering records based on a bool array of indices to extract --- source/koalas/dataframe.d | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/source/koalas/dataframe.d b/source/koalas/dataframe.d index 387880a..5d60083 100644 --- a/source/koalas/dataframe.d +++ b/source/koalas/dataframe.d @@ -31,6 +31,7 @@ struct Dataframe(RT){ static assert(member.stringof != "head"); static assert(member.stringof != "toString"); static assert(member.stringof != "unique"); + static assert(member.stringof != "records"); mixin("alias "~member.stringof~" = getCol!\""~member.stringof~"\";"); } @@ -331,6 +332,20 @@ struct Dataframe(RT){ return result; } + + auto opIndex(bool[] indexes){ + RT[] newRecords; + ulong[] newIndexes; + foreach (i,idx; indexes) + { + if(idx) newIndexes ~= i; + } + foreach (ulong key; newIndexes) + { + newRecords ~= records[key]; + } + return Dataframe!RT(newRecords); + } } @@ -386,6 +401,8 @@ unittest{ foreach(ref rec;sub){ writeln(rec); } + auto index = sub.apply!("a > 5","pos"); + assert(sub[index].pos == [6,7,6,7]); } unittest{