Skip to content

Commit

Permalink
allow filtering records based on a bool array of indices to extract
Browse files Browse the repository at this point in the history
  • Loading branch information
charlesgregory committed Sep 9, 2020
1 parent 7da0ae5 commit 19f891c
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions source/koalas/dataframe.d
Original file line number Diff line number Diff line change
Expand Up @@ -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~"\";");
}

Expand Down Expand Up @@ -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);
}
}


Expand Down Expand Up @@ -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{
Expand Down

0 comments on commit 19f891c

Please sign in to comment.