Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

resolving conflicts + lint + merge with master

  • Loading branch information...
commit ea8b173e7e67a7d2c2d6094be0a3a9f7e43bd91a 2 parents 2fbd87d + 039e9af
@iros iros authored
Showing with 62 additions and 18 deletions.
  1. +30 −10 src/derived.js
  2. +32 −8 test/unit/derived.js
View
40 src/derived.js
@@ -201,21 +201,40 @@
options = options || {};
- var d = new Miso.Derived({
+ //default to rejecting NaNs, nulls & undefined
+ console.log('opt', options);
+ if ( _.isUndefined(options.rejectNA) ) {
+ options.rejectNA = true;
+ }
- // save a reference to parent dataset
- parent : this,
-
- // default method is addition
- method : options.method || function(data) {
+ // default method is addition
+ var method = options.method || _.sum;
+
+ //wrap method to reject values unless specifed
+ //not to.
+ if ( options.rejectNA ) {
+ options.method = function(data) {
data = _.reject(data, function(d) {
if ( d === null ) { return true; }
if ( _.isUndefined(d) ) { return true; }
if ( _.isNaN(d) ) { return true; }
return false;
});
- return _.sum(data);
- },
+ return method(data);
+ };
+ } else {
+ options.method = method;
+ }
+
+
+ var d = new Miso.Derived({
+
+ // save a reference to parent dataset
+ parent : this,
+
+ rejectNA : options.rejectNA,
+
+ method : options.method,
// save current arguments
args : arguments
@@ -263,9 +282,9 @@
} else {
category = originalByColumn.data[i];
}
-
+
if (_.isUndefined(categoryPositions[category])) {
-
+
// this is a new value, we haven't seen yet so cache
// its position for lookup of row vals
categoryPositions[category] = categoryCount;
@@ -304,6 +323,7 @@
var column = this.column(colName);
_.each(column.data, function(bin, binPos) {
+ console.log('b', bin);
if (_.isArray(bin)) {
// save the original ids that created this group by?
View
40 test/unit/derived.js
@@ -174,7 +174,7 @@
{
name : "count",
type : "number",
- data : [1,2,3,4,5,6,NaN,null, undefined]
+ data : [1,2,3,4,5,6,NaN,null,undefined]
},
{
name : "anothercount",
@@ -223,6 +223,37 @@
});
});
+ test("base group by with rejectNA off", function() {
+
+ var foundNull = 0;
+
+ var ds = new Miso.Dataset({
+ data : getData(),
+ strict : true
+ });
+
+ _.when(ds.fetch()).then(function(){
+ var groupedData = ds.groupBy("state", ["count", "anothercount"], {
+ rejectNA : false,
+ method : function(data) {
+ _.reject(data, function(d) {
+ if ( _.isNull(d) ) {
+ foundNull += 1;
+ return true;
+ }
+ return false;
+ });
+ return _.sum(data);
+ }
+ });
+
+ equals(foundNull, 3);
+ ok(_.isEqual(groupedData._columns[2].data, ["AZ", "MA"]), "states correct");
+ ok(_.isEqual(groupedData._columns[3].data, [6,15]), "counts correct");
+ ok(_.isEqual(groupedData._columns[4].data, [60,150]), "anothercounts correct");
+ });
+ });
+
test("base group by syncable update", function() {
var ds = new Miso.Dataset({
@@ -317,13 +348,6 @@
var groupedData = ds.groupBy("state",
["count", "anothercount"], {
method : function(array) {
- array = _.reject(array, function(d) {
- if ( d === null ) { return true; }
- if ( _.isUndefined(d) ) { return true; }
- if ( _.isNaN(d) ) { return true; }
- return false;
- });
-
return _.reduce(array, function(memo, num){
return memo * num;
}, 1);
Please sign in to comment.
Something went wrong with that request. Please try again.