Skip to content
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

Support format expression function #409

Closed
mattijn opened this issue Oct 24, 2023 · 1 comment · Fixed by #414
Closed

Support format expression function #409

mattijn opened this issue Oct 24, 2023 · 1 comment · Fixed by #414
Labels
enhancement New feature or request

Comments

@mattijn
Copy link
Contributor

mattijn commented Oct 24, 2023

The following spec renders fine:

import altair as alt
url = 'https://gist.githubusercontent.com/mattijn/73efd6796132c997ae2dcad45e8b7873/raw/41512de3da5bbc372ac40d9ae18519a46ac5426c/doy_thresholds.csv'
chart = alt.Chart(url, height=10).mark_area(interpolate='monotone').encode(
    x=alt.X('doy:O', sort='ascending').bin(maxbins=20),
    y=alt.Y('sum(value):Q').axis(None).scale(range=[10, -10]),
    row=alt.Row('variable:O').title(None).header(labelAngle=0, labelAlign='left')
).configure_facet(
    spacing=0
).configure_view(
    stroke=None
)
chart
image

But when trying to extract the transformed data it errors:

chart.transformed_data()
ValueError: Pre-transform error: Requested variable (Variable { name: "source_0", namespace: Data }, [])
 requires transforms or signal expressions that are not yet supported

When looking to the spec, I'm not sure which transform is being utilised that is not yet supported.

@jonmmease jonmmease changed the title cannot extract data, ValueError: Pre-transform error Support format expression function Oct 25, 2023
@jonmmease
Copy link
Collaborator

Looking at the generated Vega spec, there is this transform

        {
          "type": "formula",
          "expr": "!isValid(datum[\"bin_maxbins_20_doy\"]) || !isFinite(+datum[\"bin_maxbins_20_doy\"]) ? \"null\" : format(datum[\"bin_maxbins_20_doy\"], \"\") + \"\" + format(datum[\"bin_maxbins_20_doy_end\"], \"\")",
          "as": "bin_maxbins_20_doy_range"
        },

The issue is that the format expression function isn't implemented yet. I have an old Rust implementation of the Vega format function that I developed a while back for another project. I'll see if I can port that over to VegaFusion. Although, it may also be worth adding a special case for format(value, "") that just transforms this into toString(value), as this will be easier to support across SQL backends.

Also cross reference #336 for better error messages when something isn't supported.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants