Skip to content

Commit 20717d5

Browse files
author
Brian Hulette
committed
Fixed countBy(string)
1 parent 7244887 commit 20717d5

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

js/perf/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ function createDataFrameCountByTest(table, column) {
180180
async: true,
181181
name: `name: '${column}', length: ${table.length}, type: ${table.columns[colidx].type}`,
182182
fn() {
183-
table.countBy(col(column));
183+
table.countBy(column);
184184
}
185185
};
186186
}

js/src/table.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ export class Table implements DataFrame {
115115
return this.lengths.reduce((acc, val) => acc + val);
116116
}
117117
countBy(count_by: (Col|string)): CountByResult {
118-
if (count_by instanceof String) {
118+
if (!(count_by instanceof Col)) {
119119
count_by = new Col(count_by);
120120
}
121121

@@ -216,7 +216,7 @@ class FilteredDataFrame implements DataFrame {
216216
}
217217

218218
countBy(count_by: (Col|string)): CountByResult {
219-
if (count_by instanceof String) {
219+
if (!(count_by instanceof Col)) {
220220
count_by = new Col(count_by);
221221
}
222222

js/test/unit/table-tests.ts

+15-1
Original file line numberDiff line numberDiff line change
@@ -159,14 +159,21 @@ describe(`Table`, () => {
159159
expect(table.filter(col('dictionary').eq('a')).count()).toEqual(3);
160160
});
161161
test(`countBy on dictionary returns the correct counts`, () => {
162+
// Make sure countBy works both with and without the Col wrapper
163+
// class
162164
expect(table.countBy(col('dictionary')).asJSON()).toEqual({
163165
'a': 3,
164166
'b': 2,
165167
'c': 2,
166168
});
169+
expect(table.countBy('dictionary').asJSON()).toEqual({
170+
'a': 3,
171+
'b': 2,
172+
'c': 2,
173+
});
167174
});
168175
test(`countBy on dictionary with filter returns the correct counts`, () => {
169-
expect(table.filter(col('i32').eq(1)).countBy(col('dictionary')).asJSON()).toEqual({
176+
expect(table.filter(col('i32').eq(1)).countBy('dictionary').asJSON()).toEqual({
170177
'a': 1,
171178
'b': 1,
172179
'c': 1,
@@ -354,11 +361,18 @@ describe(`Table`, () => {
354361
expect(table.filter(col('dictionary').eq('a')).count()).toEqual(3);
355362
});
356363
test(`countBy on dictionary returns the correct counts`, () => {
364+
// Make sure countBy works both with and without the Col wrapper
365+
// class
357366
expect(table.countBy(col('dictionary')).asJSON()).toEqual({
358367
'a': 3,
359368
'b': 3,
360369
'c': 3,
361370
});
371+
expect(table.countBy('dictionary').asJSON()).toEqual({
372+
'a': 3,
373+
'b': 3,
374+
'c': 3,
375+
});
362376
});
363377
test(`countBy on dictionary with filter returns the correct counts`, () => {
364378
expect(table.filter(col('i32').eq(1)).countBy(col('dictionary')).asJSON()).toEqual({

0 commit comments

Comments
 (0)