question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ENH: add functions for aggregations

See original GitHub issue

The more I use Altair, the more the string aggregation shortcuts feel awkward to me.

I would propose we add an alternate syntax for creating aggregates based on top-level altair functions, and also add a top-level bin() function as a shortcut to binning.

For example, instead of

chart.encode(
    x=alt.X('x', bin=alt.Bin(maxbins=20)),
    y='mean(y):Q'
)

we could instead have a syntax like this:

chart.encode(
    x=alt.bin('x', maxbins=20),
    y=alt.mean('y', 'Q')
)

The downside is that this is another step away from the user directly touching the structure of the spec, and might encourage a wrong mental map that may lead to other confusions. To some degree, though, that is already an issue with the current string-based shortcuts.

The upside is that it is much more natural in Python to use actual functions for these functions rather than writing them out in strings.

@elisonbg @kanitw @domoritz I’d love to hear your thoughts on this. If they’re generally positive, I can work on an implementation (there will be a couple subtleties, but it shouldn’t be too bad).

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:23 (13 by maintainers)

github_iconTop GitHub Comments

1reaction
jakevdpcommented, Apr 19, 2018

Altair could use nominal by default for strings, ordinal for low cardinality integers, temporal for dates, and quantitative for high cardinality ints and floats. Then users only have to set the type when they want to override the default behavior.

This is already the case when data is passed as a dataframe

1reaction
jakevdpcommented, Apr 17, 2018

the second you want to add anything else to the channel (axes, scale, etc). it starts to look really weird

This is how I would see that. The old way:

alt.Chart(data).mark_point().encode(
   x='mean(x):Q',
   y=alt.Y('mean(y):Q', axis=Axis(...))
)

The new way:

alt.Chart(data).mark_point().encode(
   x=alt.mean('x', 'Q'),
   y=alt.Y(alt.mean('y', 'Q'), axis=Axis(...))
)

But since aggregations are almost always quantitative, it would actually be this:

alt.Chart(data).mark_point().encode(
   x=alt.mean('x'),
   y=alt.Y(alt.mean('y'), axis=Axis(...))
)

The alternative notation is not a conceptual break from the old notation… it just removes the need to embed function calls within strings.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Working with Aggregate Functions
An aggregate function is a special type of operator that returns a single value based on multiple rows of data. When your query...
Read more >
Aggregate Functions in Reports and Tables - MicroStation
Aggregate Functions in Reports and Tables. MicroStation CONNECT's reports and tables add useful capability to those wanting to harvest DGN data.
Read more >
Aggregate Functions in Tableau
This article introduces aggregate functions and their uses in Tableau. ... Note: You can use the function reference to find and add aggregate...
Read more >
Introduction to T-SQL Window Functions - Simple Talk
By adding the PARTITION BY, a subtotal is calculated for each customer. Any aggregate function can be used, and ORDER BY in the...
Read more >
12.20.1 Aggregate Function Descriptions
This section describes aggregate functions that operate on sets of values. ... To sort in reverse order, add the DESC (descending) keyword to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found