-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add aggregate parameters to vega-transform, and exponential moving average #3686
Conversation
Is there any interest in this? |
Thanks for the pull request. I just approved the test run again. |
If/when this is merged, #3577 could be made more general by passing the requested quantiles as a parameter. |
Hey @Xitian9 thanks for the effort! Can it be used to smooth a linear plot or does it calculate a single number? @domoritz are there any blockers left to merge this? (maybe we can also join and help). Also, if this is merged will it become available automatically in vega-lite? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks reasonable to me. The API question I have is whether it makes sense for the parameter to be a separate property or somehow part of the ops. I guess this is consistent with the rest of the API.
@jheer needs to make a final pass and merge
@@ -11,6 +11,7 @@ import {accessorFields, accessorName, array, error, inherits} from 'vega-util'; | |||
* @param {Array<function(object): *>} [params.groupby] - An array of accessors to groupby. | |||
* @param {Array<function(object): *>} [params.fields] - An array of accessors to aggregate. | |||
* @param {Array<string>} [params.ops] - An array of strings indicating aggregation operations. | |||
* @param {Array<object>} [params.aggregate_params=[null]] - An optional array of parameters for aggregation operations. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to repeat the name aggregate
here or is it already obvious because of the context of the aggregate?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was going by the naming agreed upon in vega/vega-lite#4439. We cannot just call it params.params, as this would conflict with the params argument in windowing functions. Anytime you would want to apply an aggregate with parameter over a window with parameter, you would run into problems.
The aggregate in itself produces a single number (which is why I call it
I don't believe it would automatically be available in vega-lite, and that would need to be updated as well. |
@jheer sorry for bothering you, anything we can do (help with) here to unblock this and move forward? Please let me know. |
Is there any appetite for this? If not I'll delete the PR. |
@Xitian9 please keep it for a while :) We definitely need this! I can't make decisions here and / or review, but please keep it possible. I hope folks will get some time to merge it. Thanks for your work. |
Hey folks, @jheer , any chance we can move it forward? Could we at least identify what is blocking this PR atm? |
Thanks for the PR, sorry for the delay in reviewing! I checked with @jonmmease and expanding aggregates this way does not have negative downstream consequences for VegaFusion (other than that weighted exponential aggregates will not be optimized by VegaFusion at the moment). |
Hello, I'm working on adding I tried a couple different field variations but |
@@ -45,6 +46,7 @@ Aggregate.Definition = { | |||
'params': [ | |||
{ 'name': 'groupby', 'type': 'field', 'array': true }, | |||
{ 'name': 'ops', 'type': 'enum', 'array': true, 'values': ValidAggregateOps }, | |||
{ 'name': 'aggregate_params', 'type': 'field', 'null': true, 'array': true, 'default': [null] }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't look right. In the docs, we say object
and then here the type is field
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@julieg18 hmm, yeah, something is wrong here. The types look wrong to me. I think the aggregate parameter is just a value, not a field judging from the code but maybe I'm missing something: Open the Chart in the Vega Editor (still fails because of some error somewhere). @Xitian9 @shcheklein can you post an example you used to test this feature? Also, could you send a follow up pull request to add docs. |
@@ -37,6 +38,7 @@ Window.Definition = { | |||
{ 'name': 'groupby', 'type': 'field', 'array': true }, | |||
{ 'name': 'ops', 'type': 'enum', 'array': true, 'values': ValidWindowOps.concat(ValidAggregateOps) }, | |||
{ 'name': 'params', 'type': 'number', 'null': true, 'array': true }, | |||
{ 'name': 'aggregate_params', 'type': 'field', 'null': true, 'array': true, 'default': [null] }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the default correct here? There may be more than two ops.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code will pad aggregate_params with nulls as necessary to match the number of ops.
@@ -11,6 +11,7 @@ import {accessorFields, accessorName, array, error, inherits} from 'vega-util'; | |||
* @param {Array<function(object): *>} [params.groupby] - An array of accessors to groupby. | |||
* @param {Array<function(object): *>} [params.fields] - An array of accessors to aggregate. | |||
* @param {Array<string>} [params.ops] - An array of strings indicating aggregation operations. | |||
* @param {Array<object>} [params.aggregate_params=[null]] - An optional array of parameters for aggregation operations. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be [params.aggregate_params]
since we cannot assume a single op?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code will pad aggregate_params with nulls as necessary to match the number of ops.
Test code is here: https://github.com/vega/vega/blob/main/packages/vega-transforms/test/aggregate-test.js |
"exponential" takes a number as an argument, and you have provided the string "param_value". Do you still get NaN if you supply a double? |
I'm not a javascript programmer, so I could definitely believe I got the types wrong. The type needs to be generic enough to accept any sort of value, as different ops will have different argument types. For "exponential" that's a number, but for other as-yet-unimplemented ops it could be something of arbitrary complexity. |
Makes sense, thanks! As previously mentioned, I can only provide strings since currently the type is set to fields.
Apologies, I'm not sure what you mean by double? Do you mean something like this: I would still get |
The editor will only warn you. Numbers are still passed to Vega. |
|
Types are now fixed thanks to #3846, but as expected, we are still hitting the Looking at the error locally, it's possibly happening inside of
@Xitian9, are you able to get a working example of |
Actually, I tested Not sure why I was getting the error previously, but unless it shows up again, I'll get back to vega/vega-lite#9200 |
Awesome. Thanks for the update. I'm glad it's working now. |
This adds exponential moving averages, fixing #3341. In order to do this, it enables supplying parameters to aggregation functions. This addresses the block on vega/vega-lite#4439.
As I'm not a javascript programmer, feedback will be gratefully taken on board.