-
Notifications
You must be signed in to change notification settings - Fork 42
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
cannot display pint-pandas DataFrame in Streamlit #181
Comments
Not that I know of
You can try asking Streamlit or pyarrow and see if anyone is interested. It isn't anyone's respsonsibility. |
Hello @mkaut, I have the same problem :( As a temporary workaround, I am converting everything to string. df = pd.DataFrame({
"torque": pd.Series([1., 2., 2., 3.], dtype="pint[lbf ft]"),
"angular_velocity": pd.Series([1., 2., 2., 3.], dtype="pint[rpm]"),
}, dtype = str) # conversion to string here If you want to make the dataframe editable, maybe it's possible to keep the data as separate import pandas as pd
import streamlit as st
import pint
# sets compact unit formatting
u = pint.UnitRegistry()
u.default_format = '~P'
pint.set_application_registry(u)
# initial data
columns = {
"torque": pd.Series([1., 2., 2., 3.], dtype="pint[lbf ft]"),
"angular_velocity": pd.Series([1., 2., 2., 3.], dtype="pint[rpm]"),
}
# shows data editor widget, with string data type
st.data_editor(pd.DataFrame(columns, dtype = str), key = "my_data_editor")
# gets edited rows
edited_rows = st.session_state.get("my_data_editor", {}).get("edited_rows", {})
st.write(edited_rows)
# converts edited rows to pint quantities
for rowIndex, editData in edited_rows.items():
for colIndex, newValue in editData.items():
columns[colIndex][rowIndex] = u.Quantity(newValue)
# shows edited data
for colName, colSeries in columns.items():
st.write(colName, colSeries.tolist()) This solutions converts values correctly even using different units. p.s. if you opened some issue about this on streamlit and/or arrow, please post the link here. |
I tried using pint-pandas-enhanced DataFrames in a Streamlit app, but displaying it leads to an error from pyarrow.
My code:
The penultimate line display the
dtypes
and confirms that the dataframe is created correctly,but the last line fails with the following error message in the app:
and in the terminal:
To me, it looks like Streamlit is using Arrow to process the dataframe for display, and Arrow does not recognize/understand the pint types.
Is there some way to fix it, or get around it?
And should it be reported to Streamlit developers, or is it pint-pandas' responsibility?
The text was updated successfully, but these errors were encountered: