-
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
Error calling chart.save
when using __dataframe__
protocol
#3109
Comments
Thanks for giving the DataFrame interchange protocol a try. It looks like what's happening here is that you need to be explicit about the column encoding type when using the DataFrame interchange protocol. This fixes it: import altair as alt
import pyarrow as pa
data = pa.Table.from_pydict(
{'x': ['A', 'B', 'C', 'D', 'E'],
'y': [5, 3, 6, 7, 2]}
)
chart = alt.Chart(data).mark_bar().encode(
x='x:O', # <-- Change Here
y='y:Q', # <-- Change Here
)
chart.save("out.html") The Altair has special logic for inferring these from Pandas DataTypes, which is why they aren't always required. But it looks like that logic isn't applied when the input data comes from a @binste @mattijn Do you have thoughts on how hard it would be to support encoding type inference for the DataFrame interchange protocol objects? |
Thanks for the explanation! While that fixes it, it'd be nice if users could write the same code as the pandas version. If we're saving the output to Alternatively the inference logic could maybe be implemented to infer from the |
Totally agree
When VegaFusion is active, it intercepts the In general, I like the idea of getting the schema from the |
In addition to what @jonmmease mentioned, there is some more discussion about how to support other dataframe libraries from this comment and onwards #2868 (comment) with similar suggestions about why it might be a good idea to not rely on pandas for other protocols. |
Support for the DataFrame Interchange Protocol is still experimental and it currently lacks features as type inference. Another related quote from the same issue @joelostblom refers to: #2868 (comment)
Once pyarrow is wasm-friendly: pyodide/pyodide#2933 and/or pandas has pyarrow as a hard dependency pandas-dev/pandas#52711 we can phase-in the dataframe interchange protocol for all dataframe-a-likes (and simultaneously phase-out the dependency on pandas). The question remains if the current type inference for pandas dataframes can be used for all dataframes (that are parsed through the dataframe interchange protocol) or if this needs to be done differently. Somehow related: #3076, first PR that works on data serialization of data parsed through the dataframe interchange protocol. Additional improvements are welcome 🤗 |
I'm trying out altair's support for the new
__dataframe__
protocol, and am running into a few issues.Given the following pyarrow & altair code (taken and modified from the getting started guide):
This outputs:
Versions:
The text was updated successfully, but these errors were encountered: