arquero icon indicating copy to clipboard operation
arquero copied to clipboard

TypeScript error: op.sum is restricted to string parameters only

Open leibatt opened this issue 3 years ago • 0 comments

Arquero is awesome! I've been using it a lot in one of my ongoing research projects. But today I ran into an issue using op.sum. In the code comments, I see that Arquero's sum operator is restricted to strings only:

/**                                                                                                  
* Aggregate function to sum values.                                                                 
* @param {string} field The data field.                                                             
* @return {number} The sum of the values.                                                           
*/                                                                                                  
sum: (field) => op('sum', field),  

For me, this leads to errors in TypeScript when trying to pass functions instead of the field name. For example, when trying to adapt the percentage calculation from the Arquero cookbook, I get an error because d.c is not a string:

p: (d: Record<string, number>) => d.c / op.sum(d.c)

I see that the other operators do not have this restriction, but I wasn't sure where in the code this could be fixed since I think some of it is generated automatically.

leibatt avatar Feb 25 '22 01:02 leibatt