Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Pivot Operation #13

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use foreach instead of while in pivot
* Using foreach as the number of iterations can be found beforehand
Kriyszig committed Sep 13, 2019
commit 4cd40cb64f27dd2f39386a2db884426c425759b8
14 changes: 3 additions & 11 deletions source/magpie/dataframe.d
Original file line number Diff line number Diff line change
@@ -1833,7 +1833,7 @@ public:
auto pivot(size_t col_size)(int[] index, int[] columns, int[] values)
{
import std.conv: to;
import std.algorithm: countUntil;
import std.algorithm: countUntil, max;

DataFrame!(suitableType!RowType, col_size) ret;
Index inx;
@@ -1897,17 +1897,9 @@ public:
dfval = to!(toArr!(ret.RowType[0]))(data[j]);
}

size_t start;
while((start < dfval.length) && (start / level_size < ret.rows))
foreach(j; 0 .. max(dfval.length, ret.rows * level_size))
{
foreach(j; 0 .. level_size)
{
if(start > dfval.length - 1)
break;

ret.data[i * level_size + j][start / level_size] = dfval[start];
++start;
}
ret.data[(i * level_size) + (j % level_size)][j / level_size] = dfval[j];
}
}