-
Notifications
You must be signed in to change notification settings - Fork 794
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
WIP: update to Vega-Lite 5.2 #2528
Conversation
Duplicated the vegalite/v4 folder, and changed some occurrences of "4" to "5". Ran generate_schema_wrapper. As is the library will not work, because for example v5/api.py refers to definitions that no longer exist within the Vega-Lite schema, such as core.SelectionDef.
This looks really good. I like the |
Thank you @mattijn! I haven't succeeded in finding the comments yet. I clicked on "Files Changed" above for this PR and scrolled through the |
My bad, didn't submit review. |
And replaced v4 with v5 in some files.
Replaced dict key "selection" with "param" to match the Vega-Lite v5 schema.
Thanks @mattijn I made those and a few other small updates, including changing the I'll maybe try writing some drafts of documentation for parameters, but I'm open to suggestions if there's something else that would be more helpful. (I don't think I can contribute anything useful on the JupyterLab front.) |
Here is a nice small error I'm getting with the tests for this
If I instead just display the chart instead of trying to save it, it works fine. Or if I comment out the The error that displays for me is
and the traceback is
Is it obvious what kind of error this is? The possibilities I see:
|
It looks like you're saving via node-js, and I suspect node-js does not have the correct package versions installed. |
Great, thank you! That has me down from about 35 tests failing to 8 tests failing. I'm not sure how ill-advised this was, but I got the right versions installed by using |
Updates related to UnitSpec not having e.g. a "height" property.
One observation about the current syntax in this PR is that you make a variable parameter using Some alternatives I can think of:
But maybe nobody would ever use those alternatives? What do you think? There's a balancing act between staying faithful to the Vega-Lite syntax on one hand, and having more concise code on the other hand (and not breaking the existing Altair syntax). |
I would follow Vega Lite API in here, see https://vega.github.io/vega-lite-api/api/#parameters and https://github.com/vega/vega-lite-api/blob/master/api/api.js#L124-L130. Basically meaning that the low-level SelectionConfig syntax cannot be created anymore using Altair. Its still allowed within Vega-Lite, to remain backward compatibility, but its on the list to be deprecated in the future. |
Thanks @mattijn. The vega-lite api approach seems very similar to what we currently have (e.g., Please let me know if you come across anything you think should be changed! |
I've gotten myself a little confused about what's the right way to add parameters to a multiview chart. Something like this works, where we add the parameter to the first chart and then refer to it in the second chart. An analogue also appears in the Vega-Lite documentation:
But something like this does not work. Again we add a parameter to the first chart and refer to it in the second:
If we instead add the parameter to the layer chart, then it works:
Do you see what the difference is between these two cases? Does this seem to be working as expected? |
It matters on which level the parameter are placed. I've experience in Vega-Lite that I had to add parameters in a nested concat chart, where it was not allowed to be defined on the top level. Will add an example soon. I'm not sure if this intended behaviour of VL5. |
The example I got is a bit more complex (Google Colab URL here): import altair as alt
from vega_datasets import data
stocks = data.stocks.url
hover_1 = alt.selection_point(name="hover", nearest=True, on="mouseover", encodings=["x"])
hover_2 = alt.selection_point(name="hover", on="mouseover", encodings=["x"])
highlight = alt.selection_point(name="highlight", on="mouseover", clear="mouseout")
input_dropdown = alt.binding_select(options=[[0,300], [0,600]], name='fill domain')
param_domain = alt.param(value=[0, 600], bind=input_dropdown)
line = alt.Chart(height=150).mark_line(point=True).encode(
x=alt.X("date:N", timeUnit="year"),
y=alt.Y("mean(price):Q"),
color="symbol:N"
)
rule = alt.Chart().mark_rule(tooltip=True).encode(
x=alt.X("date:N", timeUnit="year"),
color=alt.condition(hover_1, alt.value("black"), alt.value("transparent"),
empty=False)
).add_params(hover_1)
rect = alt.Chart().mark_rect(strokeWidth=1.2, tooltip=True).encode(
x=alt.X("date:T", timeUnit="year"),
y=alt.Y("symbol:N"),
fill=alt.Y("mean(price):Q", scale=alt.Scale(domain=param_domain)),
stroke=alt.condition(highlight, alt.value("black"), alt.value(None),
empty=False)
).add_params(hover_2, highlight)
alt.concat(
(line + rule), rect, data=stocks, columns=1
).resolve_scale(
fill='independent',
color='independent',
x='shared'
).add_params(
param_domain,
).configure_scale(bandPaddingInner=0.0, bandPaddingOuter=0.07) If I move the Javascript Error: Duplicate signal name: "highlight_tuple" Why is this not allowed? But if I remove the When looking to the Vega-Lite definitions I observe that the behaviour of Wrong VL-editor spec: Open the Chart in the Vega Editor | updated Right VL-editor spec: Open the Chart in the Vega Editor |
I'm not sure, but it seems suspicious that you have two parameters with the same name ( |
Apologies, the VL-spec didn't reflect the text, I updated the spec (Open the Chart in the Vega Editor). There is just a single It seems that for concatenated views some of the parameters cannot be defined globally/top-level/low-level. There are also two nested All in all, I think I observe the following behaviour:
|
I'm wrong. Predicates can be defined top-level and still be used in layers within concatenated views, Open the Chart in the Vega Editor. |
Yeah, we should bump the version to 5.0.0 at some point before we release, but that doesn't have to happen now. Also, we could probably delete all the I'm also thinking of deleting the More examples and documentation would also be very welcome! That could all be done after we merge this, though. |
Thanks @jakevdp, that all sounds good. I'll watch for the merge! |
Super excited to see this being on its way to a merge! @jakevdp What do you think about including the autocomplete change I suggested in #2528 (comment) to hide the deprecated methods as @mattijn originally brought up in #2528 (comment) (and the two following comments). This is minor and I by no means want it to hold back a merge, but I thought I would mention it to double check since I agree that seeing the deprecated methods in the completion is somewhat confusing. |
My only hesitation with #2528 (comment) is that the module is referencing itself in a partially-imported state, and I don't know if there are potentially problematic edge-cases there. |
Thanks @joelostblom for the reminder and @jakevdp for the comment. My vote would be to not include this autocomplete change for now and maybe consider it again if things seem to be working. |
Thanks both! Erring on the side of caution sounds appropriate to me as well, so let's consider the modified tab completion for later if needed. I saw that you added the deprecation warnings @ChristopherDavisUCI so that still clearly communicates the deprecated state of these functions. |
Hey @ChristopherDavisUCI, I'm stuck here. I've the feeling when an import altair as alt
data_wind = [
{'winddirection': 0, 'label': 'North'},
{'winddirection': 90, 'label': 'East'},
{'winddirection': 180, 'label': 'South'},
{'winddirection': 270, 'label': 'West'},
]
# off-topic: I wish I could define names for data sources easier
source_wind = alt.DataSource(alt.InlineData(values=data_wind, name='source_wind'))
theta_shift = alt.parameter(expr="-PI/length(data('source_wind'))")
chart = alt.Chart(source_wind).mark_arc(
tooltip=True,
thetaOffset=theta_shift
).encode(
theta='winddirection:N',
color='label:N'
).add_parameter(theta_shift)
chart chart_dict = chart.to_dict()
chart_dict
chart_dict['mark']['thetaOffset']['expr'] = 'parameter027'
alt.Chart.from_dict(chart_dict) |
Thanks @mattijn! I'm swamped with meetings today but will check this out and get back to you Friday. |
Perfect! Funny enough, if I do: |
@mattijn, can I ask, how do you decide what the "correct" serialization should be? Do you plug it into the Vega-Lite editor and see if it gives any warnings or errors? Do you look at the Vega-Lite docs? Do you look at the typescript source code? Do you look at the json schema? Something else? For most cases I use the Vega-Lite docs, but for edge cases (like how should a parameter be specified in a multi-view chart) it's very unclear to me where I should be looking. |
I use the Vega editor as starting point.
But currently the following happens:
If I define the parameter as |
if self.param.expr is Undefined: | ||
return {"expr": self.name} | ||
else: | ||
return {"expr": repr(self.param.expr)} |
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've the feeling the behavior seen is because of this line: https://github.com/altair-viz/altair/pull/2528/files#diff-bbe4e187b18d242a366c820d023afd89041759cb96e4ec66c3f34559a72c2f9dR177.
I just found out it is not necessary to use an import altair as alt
from altair.expr import PI, length, data
data_wind = [
{'winddirection': 0, 'label': 'North'},
{'winddirection': 90, 'label': 'East'},
{'winddirection': 180, 'label': 'South'},
{'winddirection': 270, 'label': 'West'},
]
source_wind = alt.DataSource(alt.InlineData(values=data_wind, name='source_wind'))
theta_shift = alt.parameter(expr=(-PI/length(data('source_wind'))))
chart = alt.Chart(source_wind).mark_arc(
tooltip=True,
thetaOffset=theta_shift
).encode(
theta='winddirection:N',
color='label:N'
)
chart#.to_dict() |
Sorry for this falling off my radar. It looks like there are still some questions about corners of the new APIs... still, does anyone object to me clicking merge so we can more easily test and iterate on the new version? |
No objections, let's iterate further from main branch (or rc1 🤩) |
Two quick questions: Is there any downside to deleting the Altair repository that I forked? I find it difficult to keep these things organized. When I respond to @mattijn's questions, should I do that in a new GitHub issue or PR, or here? |
@ChristopherDavisUCI, you can respond at #2573, and if we find an answer, can create a PR afterwards. |
Regarding:
Up to you. Clean is nice. You'll have to create a new fork for a new PR. |
Wohoooo!!! It's so exciting to see this merged!! Thanks everyone for working on it, especially @ChristopherDavisUCI for championing this large undertaking 🚀 🌟 🏆 |
The code here is pretty similar to #2517, but I wanted to redo some things and it seemed easiest to start with a new pull request. Also the conversation on the other one was getting pretty long.
Main changes from #2517:
size_var + 3
created an Expression, but now it creates a Parameter. That is the only major change.selection_point
etc now create the entire Parameter.Main changes overall (from the master branch):
vegalite/v5
folder with schema 5.2.0. The first commit is just a duplication of thevegalite/v4
folder. I hope that makes it easier to tell what changes were made.OperatorMixin
. The goal is to use the same code for both something likeexpr + 3
(which should produce an Expression) and something likesize_var + 3
(which should produce a Parameter). I'm really not sure if the way I accomplished this is natural or not.warnings.warn(message, DeprecationWarning)
, but they seem to all be hidden by default, so I have never successfully seen one of these messages displayed. The code would be a little cleaner if we didn't try to keep this old syntax.If you see something that could be improved, please let me know, because I'm happy to learn about more efficient ways of doing things.
To do:
warnings.warn
approach seems worthless at the moment since the messages don't get displayed by default.selection
, which in the new schema should beparam
. I think it's not worth the effort of writing code to try to make this example compile, and we should rewrite that example (only two words need to be changed).test_spec_to_vegalite_mimebundle
.Thanks for any comments/requests!