-
Notifications
You must be signed in to change notification settings - Fork 4k
Add support for Altair 5 #6618
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
Add support for Altair 5 #6618
Conversation
|
@lukasmasuch Just fyi, Altair 5 got released today 🥳 |
Co-authored-by: Stefan Binder <binder_stefan@outlook.com>
…it/streamlit into feature/altair-5-support
| # - Include relevant lower bound for any features we use from our dependencies | ||
| # - And include an upper bound that's < NEXT_MAJOR_VERSION | ||
| INSTALL_REQUIRES = [ | ||
| "altair>=3.2.0, <5", |
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 this breaking for Altair 3? We had conversations about 4 to 5, but want to verify the problem with 3.
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.
Ah Lukas pointed this out, but we already used v4 as well, so we were probably already breaking.
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 3.x version does not even contain the altair.vegalite.v4.api.Chart import we were using, so I'm pretty sure that we haven't been supporting this version anyways for a while 😅
| ) | ||
| self.assertEqual(spec_dict["data"], {"name": proto.datasets[0].name}) | ||
| self.assertEqual(spec_dict["mark"], "bar") | ||
| self.assertIn(spec_dict["mark"], ["bar", {"type": "bar"}]) |
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.
We check both here bar and {"type": "bar"} to allow our tests to run with v4 and v5 versions.
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 good to me - my only concern is how sure we are that we're still compatible with Altair 4 ... and beyond that, how do we ensure that we remain compatible with Altair 4.
- Maybe we just cross our fingers now, and it gets worked out with @AnOctopus's "test min versions of dependencies in CI" project?
- Alternately: do we want to require
altair >=5, <6for now, and drop Altair 4 support?
| @@ -1,29 +0,0 @@ | |||
| # Copyright (c) Streamlit Inc. (2018-2022) Snowflake Inc. (2022) | |||
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.
Why don't we want this test anymore?
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 was just a temporary feature - before we had the theme parameter - that got removed in this PR as a side-effect. It was possible to set the theme via:
alt.themes.enable("streamlit")But we never advertised it and this has some technical issue related to it, so we introduced the theme parameter with our charting commands instead. So this is just removing some unused tech debt.
| def _arrow_altair_chart( | ||
| self, | ||
| altair_chart: Chart, | ||
| altair_chart: "Chart", |
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.
Nit: I think you can avoid the quotes for this type annotation if you add a from __future__ import annotations at the top of the file (even though the import is conditional on the TYPE_CHECKING flag)
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.
Oh, I didn't know. I will update this later :)
|
|
||
| if TYPE_CHECKING: | ||
| from altair.vegalite.v4.api import Chart | ||
| from altair import Chart |
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.
Does this "from altair import Chart" import work for Altair 4?
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.
Yep, from altair import Chart is the actual public API that always existed this way :)
From a Python side, this PR will make Streamli neutral to the underlying vega-lite version since we just use the actual public Altair API: However, the frontend part is more relevant regarding the compatibility of the vega-lite specs. We have been running vega-lite spec v5 anyways already in the frontend for a few months (probably accidentally), even though the supported Altair version has been producing v4 spec. Since it didn't cause any issues in the last few months, I don't expect that this change will introduce any additional issues. |
I assume this would probably be a too harsh pin here since Altair 5 just got released
I think I will merge this PR after the |
I fully agree with this, the frontend has already been updated anyway, and I again went through the changes and can't spot anything that would no longer work with Altair 4. Apart from the changes in imports to the I think many users are looking forward to this and so it would be great if it can already be included in the 1.23 release but I also understand if you first want to improve the testing strategy! Thank you in any case, looking forward to it. |
|
@binste Thanks for all the help and input on the Altair 5 update! 👍 |
|
Sure, thank you for doing it and always happy to chat about the Altair integration in Streamlit! :) |
* develop: (22 commits) enzyme -> react-testing-library (Countdown, Modal, ProgressBar) (streamlit#6744) Remove console.log (streamlit#6753) Update `st.data_editor` and `st.dataframe` docstrings (streamlit#6752) Update `st.data_editor` session state format (streamlit#6711) Cypress flaky test fixes (streamlit#6743) Document integer size limit for number_input and slider (streamlit#6724) Change default theme hash on app init (streamlit#6729) Use .genericFonts instead of .fonts to fix bug with theme postMessage. (streamlit#6732) Improve startup performance by lazy loading some dependencies (streamlit#6531) Add support for Altair 5 (streamlit#6618) Update modals (streamlit#6688) Improve docstrings for `ttl` and `max_entries` (streamlit#6733) Improve `st.columns` docstring (streamlit#6727) Removed orphan line in dataframe docstring (streamlit#6734) Fix useIsOverflowing dependency array (streamlit#6731) Remove experimental from data editor (streamlit#6712) Clarify set_page_config docstring and exception message (streamlit#6594) Add a config option to disable warning for setting both a widget default and its key in session_state (streamlit#6640) Add column configuration API for `st.dataframe` and `st.data_editor` (streamlit#6598) Migrate datetime column formatting from date-fns to momentJS (streamlit#6702) ...
📚 Context
Altair 5 was released in a couple of days ago. This PR makes Streamlit compatible with the 5.x version. More specifically, we previously explicitly used the
altair.vegalite.v4.api.Chartmodule (part of the internal API), but this no longer exists in Altair 5. Instead, it is advised to directly usealtair.Chart(see conversation in #6215), which is the official public API that will stay stable.In addition, this PR also updates our frontend vega dependencies to the latest versions and moves the
altairimport to lazy loading for performance improvement. This also removes the registeredstreamlitaltair theme, which was only an unofficial workaround for the initial implementation of the Streamlit chart theme.Since we were anyways already running Vega lite v5 in our frontend for the last few months, I don't expect this update to introduce any incompatibilities. V4 and v5 should be "mostly" compatible anyways. The backend changes are also completely independent of the Altair version since the public API relevant to Streamlit (e.g.
altair.Chart) was stable across the versions.What kind of change does this PR introduce?
🧪 Testing Done
🌐 References
Does this depend on other work, documents, or tickets?
Contribution License Agreement
By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.