Skip to content

Commit 302f68d

Browse files
committed
2 parents cd4a99c + ea7aaf7 commit 302f68d

6 files changed

Lines changed: 68 additions & 80 deletions

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
.editorconfig
1+
.editorconfig
2+
node_modules

danfojs-browser/lib/bundle.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

danfojs-browser/lib/bundle.js.LICENSE.txt

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -146,23 +146,6 @@
146146
* =============================================================================
147147
*/
148148

149-
/**
150-
* @license
151-
* Copyright 2021 Google LLC. All Rights Reserved.
152-
* Licensed under the Apache License, Version 2.0 (the "License");
153-
* you may not use this file except in compliance with the License.
154-
* You may obtain a copy of the License at
155-
*
156-
* http://www.apache.org/licenses/LICENSE-2.0
157-
*
158-
* Unless required by applicable law or agreed to in writing, software
159-
* distributed under the License is distributed on an "AS IS" BASIS,
160-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
161-
* See the License for the specific language governing permissions and
162-
* limitations under the License.
163-
* =============================================================================
164-
*/
165-
166149
/**
167150
* @license Complex.js v2.0.11 11/02/2016
168151
*

danfojs-browser/lib/bundle.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

danfojs-browser/src/core/groupby.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,6 @@ export class GroupBy {
102102
*/
103103
col(col_names){
104104

105-
// if(!this.column_name.includes(col_name)){
106-
// throw new Error(`Column ${col_name} does not exist in groups`)
107-
// }
108-
109105
if (Array.isArray(col_names)){
110106

111107
for (let i = 0; i < col_names.length; i++){
@@ -179,7 +175,11 @@ export class GroupBy {
179175
"cummin" : "cummin().values"
180176
};
181177
let is_array = false;
182-
178+
//the local variable to store variables to be used in eval
179+
// this seems not to be needed in Node version, since local
180+
//variable are easily accessed in the eval function
181+
let local = null;
182+
183183
if (Array.isArray(operation)){
184184
is_array = true;
185185
}
@@ -201,10 +201,12 @@ export class GroupBy {
201201
if (!ops_name.includes(op)){
202202
throw new Error("operation does not exist");
203203
}
204-
data = eval(`this.group_col[key1][key2][i].${ops_map[op]}`);
204+
local = this.group_col[key1][key2][i];
205+
data = eval(`local.${ops_map[op]}`);
205206

206207
} else {
207-
data = eval(`this.group_col[key1][key2][i].${operation}`);
208+
local = this.group_col[key1][key2][i];
209+
data = eval(`local.${operation}`);
208210
}
209211
count_group[key1][key2].push(data);
210212

@@ -227,10 +229,12 @@ export class GroupBy {
227229
if (!ops_name.includes(op)){
228230
throw new Error("operation does not exist");
229231
}
230-
data = eval(`this.group_col[key1][i].${ops_map[op]}`);
232+
local = this.group_col[key1][i];
233+
data = eval(`local.${ops_map[op]}`);
231234

232235
} else {
233-
data = eval(`this.group_col[key1][i].${operation}`);
236+
local = this.group_col[key1][i];
237+
data = eval(`local.${operation}`);
234238
}
235239

236240
count_group[key1].push(data);

danfojs-browser/tests/core/groupby.js

Lines changed: 51 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ describe("groupby", function () {
6565
[ 20, 30, 1 ],
6666
[ 39, 89, 1 ]
6767
];
68-
68+
6969
assert.deepEqual(group_df.col([ "C" ]).count().values, new_data);
7070
});
7171
it("sum column element in group", function () {
@@ -130,38 +130,38 @@ describe("groupby", function () {
130130

131131
assert.deepEqual(group_df.col([ "B", "C" ]).cumsum().values, new_data);
132132
});
133-
// it("cummulative max for groupby", function () {
134-
135-
// let data = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 20, 30, 40 ], [ 39, 89, 78 ] ];
136-
// let cols = [ "A", "B", "C" ];
137-
// let df = new dfd.DataFrame(data, { columns: cols });
138-
// let group_df = df.groupby([ "A" ]);
139-
// let new_data = [ [ 1, 3 ], [ 4, 6 ], [ 20, 40 ], [ 39, 78 ] ];
133+
it("cummulative max for groupby", function () {
140134

135+
let data = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 20, 30, 40 ], [ 39, 89, 78 ] ];
136+
let cols = [ "A", "B", "C" ];
137+
let df = new dfd.DataFrame(data, { columns: cols });
138+
let group_df = df.groupby([ "A" ]);
139+
let new_data = [ [ 1, 3 ], [ 4, 6 ], [ 20, 40 ], [ 39, 78 ] ];
140+
141141

142-
// assert.deepEqual(group_df.col([ "C" ]).cummax().values, new_data);
143-
// });
144-
// it("cummulative min for groupby", function () {
142+
assert.deepEqual(group_df.col([ "C" ]).cummax().values, new_data);
143+
});
144+
it("cummulative min for groupby", function () {
145145

146-
// let data = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 20, 30, 40 ], [ 39, 89, 78 ] ];
147-
// let cols = [ "A", "B", "C" ];
148-
// let df = new dfd.DataFrame(data, { columns: cols });
149-
// let group_df = df.groupby([ "A" ]);
150-
// let new_data = [ [ 1, 3 ], [ 4, 6 ], [ 20, 40 ], [ 39, 78 ] ];
146+
let data = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 20, 30, 40 ], [ 39, 89, 78 ] ];
147+
let cols = [ "A", "B", "C" ];
148+
let df = new dfd.DataFrame(data, { columns: cols });
149+
let group_df = df.groupby([ "A" ]);
150+
let new_data = [ [ 1, 3 ], [ 4, 6 ], [ 20, 40 ], [ 39, 78 ] ];
151151

152-
// assert.deepEqual(group_df.col([ "C" ]).cummin().values, new_data);
153-
// });
152+
assert.deepEqual(group_df.col([ "C" ]).cummin().values, new_data);
153+
});
154154

155-
// it("cummulative prod for groupby", function () {
155+
it("cummulative prod for groupby", function () {
156156

157-
// let data = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 20, 30, 40 ], [ 39, 89, 78 ] ];
158-
// let cols = [ "A", "B", "C" ];
159-
// let df = new dfd.DataFrame(data, { columns: cols });
160-
// let group_df = df.groupby([ "A" ]);
161-
// let new_data = [ [ 1, 3 ], [ 4, 6 ], [ 20, 40 ], [ 39, 78 ] ];
157+
let data = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 20, 30, 40 ], [ 39, 89, 78 ] ];
158+
let cols = [ "A", "B", "C" ];
159+
let df = new dfd.DataFrame(data, { columns: cols });
160+
let group_df = df.groupby([ "A" ]);
161+
let new_data = [ [ 1, 3 ], [ 4, 6 ], [ 20, 40 ], [ 39, 78 ] ];
162162

163-
// assert.deepEqual(group_df.col([ "C" ]).cumprod().values, new_data);
164-
// });
163+
assert.deepEqual(group_df.col([ "C" ]).cumprod().values, new_data);
164+
});
165165
it("mean for groupby", function () {
166166

167167
let data = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 20, 30, 40 ], [ 39, 89, 78 ] ];
@@ -178,31 +178,31 @@ describe("groupby", function () {
178178
assert.deepEqual(group_df.col([ "B", "C" ]).mean().values, new_data);
179179
});
180180

181-
// it("printing multiindex table, example with cumsum operation for dataframe group by one column", function(){
182-
// let data = { 'A': [ 'foo', 'bar', 'foo', 'bar',
183-
// 'foo', 'bar', 'foo', 'foo' ],
184-
// 'B': [ 'one', 'one', 'two', 'three',
185-
// 'two', 'two', 'one', 'three' ],
186-
// 'C': [ 1, 3, 2, 4, 5, 2, 6, 7 ],
187-
// 'D': [ 3, 2, 4, 1, 5, 6, 7, 8 ] };
188-
189-
190-
// let df = new dfd.DataFrame(data);
191-
192-
// let grp = df.groupby([ "A" ]);
193-
// let rslt = [
194-
// [ 'foo', 1 ],
195-
// [ 'foo', 3 ],
196-
// [ 'foo', 8 ],
197-
// [ 'foo', 14 ],
198-
// [ 'foo', 21 ],
199-
// [ 'bar', 3 ],
200-
// [ 'bar', 7 ],
201-
// [ 'bar', 9 ]
202-
// ];
203-
// assert.deepEqual(grp.col([ "C" ]).cumsum().values, rslt);
204-
205-
// });
181+
it("printing multiindex table, example with cumsum operation for dataframe group by one column", function(){
182+
let data = { 'A': [ 'foo', 'bar', 'foo', 'bar',
183+
'foo', 'bar', 'foo', 'foo' ],
184+
'B': [ 'one', 'one', 'two', 'three',
185+
'two', 'two', 'one', 'three' ],
186+
'C': [ 1, 3, 2, 4, 5, 2, 6, 7 ],
187+
'D': [ 3, 2, 4, 1, 5, 6, 7, 8 ] };
188+
189+
190+
let df = new dfd.DataFrame(data);
191+
192+
let grp = df.groupby([ "A" ]);
193+
let rslt = [
194+
[ 'foo', 1 ],
195+
[ 'foo', 3 ],
196+
[ 'foo', 8 ],
197+
[ 'foo', 14 ],
198+
[ 'foo', 21 ],
199+
[ 'bar', 3 ],
200+
[ 'bar', 7 ],
201+
[ 'bar', 9 ]
202+
];
203+
assert.deepEqual(grp.col([ "C" ]).cumsum().values, rslt);
204+
205+
});
206206
it("printing multiindex table, example with cumsum operation for dataframe group by one column", function(){
207207
let data = { 'A': [ 'foo', 'bar', 'foo', 'bar',
208208
'foo', 'bar', 'foo', 'foo' ],

0 commit comments

Comments
 (0)