st.dataframe sorting for line_chart columns is not based on list's numeric values but string
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 42/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- pandas, python
- Domain
- data-visualization
Research direction
Start at the st.dataframe sorting behavior and the LineChartColumn configuration shown in the reproducible example, then run that example to confirm the ordering problem. Done means sorting list-backed line chart columns by numeric values rather than their string representation, with the expected ordering covered by a regression test.
Written by the indexing model from the issue text.
Description
Checklist
- I have searched the existing issues for similar issues.
- I added a very descriptive title to this issue.
- I have provided sufficient information below to help reproduce this issue.
Summary
In my use case, I use dataframe a lot to present data. Using st.column_config.LineChartColumn to include sparklines is a great way to visualize trends. However I noticed that the line chart column values are passed in as lists, and when column is sorted, it is sorted by the string value of the lists. See the example below for more explanation of the bug.
Reproducible Code Example
#Using the code example from streamlit doc column_config with values changed
import pandas as pd
import streamlit as st
data_df = pd.DataFrame(
{
"sales": [
[9, 4, 26, 80, 100, 40],
[80, 20, 80, 35, 40, 100],
[21, 20, 80, 80, 70, 0],
[100, 100, 20, 100, 30, 100],
],
}
)
st.dataframe(
data_df,
column_config={
"sales": st.column_config.LineChartColumn(
"Sales (last 6 months)",
width="medium",
help="The sales volume in the last 6 months",
y_min=0,
y_max=100,
),
},
hide_index=True,
)
Steps To Reproduce
- sort the dataframe column in decending order by clicking the column header twice.
- We will see that the sorting is based on the string order of the lists:
https://www.awesomescreenshot.com/video/22175576?key=fc3e8a42600ecadc20ab9d3109f9ed07
Expected Behavior
It is expected to sort by the actual numeric value of items in the list. In this example:
[100, 100, 20, 100, 30, 100],
[21, 20, 80, 80, 70, 0],
[80, 20, 80, 35, 40, 100],
[9, 4, 26, 80, 100, 40]
100 being the largest, 9 being the smallest.
And it would be better for the st.column_config.LineChartColumn takes a parameter as a sorting index and sorts values based on the index of the column lists. for example, in the above dataframe, if we want to sort by the last value in the list, we can pass in 5 or -1 as index sorting parameter.
Current Behavior
It is sorted based on the string order of the lists instead of the actual numeric value of the list items:
[9, 4, 26, 80, 100, 40],
[80, 20, 80, 35, 40, 100],
[21, 20, 80, 80, 70, 0],
[100, 100, 20, 100, 30, 100]
9... being largest, 1... being smallest
Is this a regression?
- Yes, this used to work in a previous version.
Debug info
- Streamlit version: 1.28.0
- Python version: 3.12
- Operating System: Windows 10
- Browser: Chrome
Additional Information
No response
- Dominant language
- Python
- Stars
- 45.8k
- Forks
- 4.4k
- Avg merge
- 21h 22m
- Merged PRs (30d)
- 316
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from streamlit/streamlit
-
area:backend area:network feature:embedding feature:runtime priority:P3 status:confirmed type:bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
area:frontend area:security feature:st.file_uploader status:unlikely type:enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
area:backend area:security feature:cache feature:cache-hash-func priority:P4 status:confirmed type:bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
area:mobile feature:st.camera_input papercut type:enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
area:ai type:enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
All issues in streamlit/streamlit
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
bancolombia/sentinel#23 ·
-
test md OpenCI
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
langchain-ai/deepagents#6450 ·
-
bug client
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100