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

Grouped density estimates are not computed/rendered correctly #381

Closed
joelostblom opened this issue Aug 31, 2023 · 6 comments
Closed

Grouped density estimates are not computed/rendered correctly #381

joelostblom opened this issue Aug 31, 2023 · 6 comments
Labels
bug Something isn't working

Comments

@joelostblom
Copy link

This chart works fine in altair:

import altair as alt
from vega_datasets import data

alt.Chart(data.movies.url).transform_filter(
    {"field": "Major_Genre", "oneOf": ["Action", "Drama"]}
).transform_density(
    'IMDB_Rating',
    groupby=['Major_Genre'],
    as_=['IMDB_Rating', 'density'],
).mark_area().encode(
    x="IMDB_Rating:Q",
    y='density:Q',
    color='Major_Genre:N'
)

image

But after enabling the vegafusion data transformer, the grouping is messed up:

image

The appearance of the issue is similar to what was reported in vega/vega-lite#8049, but setting steps explicitly does not seem to fix this bug.

@jonmmease
Copy link
Collaborator

woah, that's weird. Thanks for the report. VegaFusion doesn't perform the density transform itself yet, so I'm guessing it's messing up the order somewhere.

@jonmmease jonmmease added the bug Something isn't working label Aug 31, 2023
@jonmmease
Copy link
Collaborator

Huh, I'm actually seeing this behavior without VegaFusion as well. Here's the Vega-Lite spec that Altair 5.1.1 is producing:

Open the Chart in the Vega Editor

visualization

Could you share the Vega-Lite produced in the working case for you?

@jonmmease
Copy link
Collaborator

Reported, with proposed fix, in vega/vega-lite#9078. I think Vega-Lite needs to specify "resolve": "shared" in the kde Vega transform that Vega-Lite produces. It doesn't look like Vega-Lite accepts this parameter in the density transform, so I don't think there's anything we can do on the Altair (or VegaFusion) side unfortunately.

@joelostblom
Copy link
Author

joelostblom commented Sep 4, 2023

I was so perplexed initially by seeing that it didn't work in VL, but now I know what happened. The regression seem to have been introduced after VL 5.8, so it works fine in altair 5.0.1. Our docker container has 5.0.1 installed so I launched JupyterLab and ran it with this version first. Then realized I should use Altair 5.1.1, so I reinstalled it in the notebook and restarted the kernel but not the notebook itself, so all the specs were still evaluated using altair 5.0.1 and VL 5.8 when using the default renderer; it seems like the vegafusion renderer will correctly detect the updated altair and use the later version but the notebook will not hot reload the VL version. This leads to really confusing behavior as you can see in the video I posted here vega/editor#336 (comment)

Tracking that here vega/altair#3183 and I think we can close this issue as vegafusion has not part to play in this.

@mattijn
Copy link
Contributor

mattijn commented Sep 4, 2023

But new Python functionality does work? Like JupyterClass?

Really confusing..

I thought I find out in the previous time this issue was discussed that the newest version of Vega-Lite is loaded and then also will be used for defined altair visualizations in other open notebooks (within the same JupyterLab session).

But the behavior here seems different as the first cached JavaScript (?) package of Vega-lite is not renewed when a newer Vega-lite JS is referenced.

@joelostblom
Copy link
Author

I thought I find out in the previous time this issue was discussed that the newest version of Vega-Lite is loaded and then also will be used for defined altair visualizations in other open notebooks (within the same JupyterLab session).

Hmm, I don't think that is the case. I ran the notebook once with the old version, pip installed the new version in the notebook and restarted the kernel. See this video (I'm at a super slow internet right now which is why things take so long):

alt-vl-reload-2023-09-04_11.29.15.mp4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants