Skip to content

Commit

Permalink
Fixed edge case, added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
texodus committed Aug 9, 2018
1 parent 7c9e992 commit 0038f53
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/perspective/src/js/perspective.js
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ view.prototype.schema = async function() {
} else if (types[col_name] === 12) {
new_schema[col_name] = "date";
}
if (this.sides() > 0) {
if (this.sides() > 0 && this.config.row_pivot.length > 0) {
new_schema[col_name] = map_aggregate_types(col_name, new_schema[col_name], this.config.aggregate);
}
}
Expand Down
30 changes: 30 additions & 0 deletions packages/perspective/test/js/pivots.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,36 @@ module.exports = (perspective) => {
expect(result2).toEqual(meta);
});

it("['x'] translates type `string` to `integer` when pivoted by row", async function () {
var table = perspective.table(data);
var view = table.view({
row_pivot: ['x'],
aggregate: [{column: 'y', op: 'distinct count'}]
});
let result2 = await view.schema();
expect(result2).toEqual({y: 'integer'});
});

it("['x'] translates type `integer` to `float` when pivoted by row", async function () {
var table = perspective.table(data);
var view = table.view({
row_pivot: ['y'],
aggregate: [{column: 'x', op: 'avg'}]
});
let result2 = await view.schema();
expect(result2).toEqual({x: 'float'});
});

it("['x'] does not translate type when only pivoted by column", async function () {
var table = perspective.table(data);
var view = table.view({
col_pivot: ['y'],
aggregate: [{column: 'x', op: 'avg'}]
});
let result2 = await view.schema();
expect(result2).toEqual({x: 'integer'});
});

it("['x'] has the correct # of rows", async function () {
var table = perspective.table(data);
var view = table.view({
Expand Down

0 comments on commit 0038f53

Please sign in to comment.