streamlit icon indicating copy to clipboard operation
streamlit copied to clipboard

st.data_editor column order not respected when column name type is not str

Open timotk opened this issue 1 year ago • 4 comments

Checklist

  • [X] I have searched the existing issues for similar issues.
  • [X] I added a very descriptive title to this issue.
  • [X] I have provided sufficient information below to help reproduce this issue.

Summary

I want to make an editable dataframe using st.data_editor. My dataframe has int column names, in descending order. For my application, it is important that this order is respected.

However, when I define the column_config argument, the order gets flipped into ascending order.

I have also tried specifying column_order, but this results in an error TypeError: bad argument type for built-in operation (this is because the column names are not str type but they are expected as such)

df = st.data_editor(
    df,
    column_order=df.columns,
    column_config={
            col: st.column_config.TextColumn(
                col,
            )
            for col in df.columns
        },
)

Reproducible Code Example

Open in Streamlit Cloud

import pandas as pd
import streamlit as st

df = pd.DataFrame(
    [
        ["A", "B", "C"],
        ["D", "E", "F"],
        ["G", "H", "I"],
    ],
    columns=range(3, 0, -1)

df = st.data_editor(
    df,
    column_config={
        col: st.column_config.TextColumn(
            col,
        )
        for col in df.columns
    },
)

Steps To Reproduce

Run the above code and see the column order be incorrect

Expected Behavior

image

Current Behavior

image

Is this a regression?

  • [ ] Yes, this used to work in a previous version.

Debug info

  • Streamlit version: 1.33.0
  • Python version: 3.12
  • Operating System: Mac OS X
  • Browser: Firefox

Additional Information

No response

timotk avatar Apr 10 '24 15:04 timotk

If this issue affects you, please react with a 👍 (thumbs up emoji) to the initial post.

Your feedback helps us prioritize which bugs to investigate and address first.

Visits

github-actions[bot] avatar Apr 10 '24 15:04 github-actions[bot]

@timotk Thanks for reporting this issue 👍 I was able to reproduce this here. Non-string column names aren't super well supported right now, but I think it wouldn't be to complicated to fix this.

lukasmasuch avatar Apr 18 '24 16:04 lukasmasuch

I would like to work on this. Can I get assigned to this issue?

utkanuygur avatar Apr 20 '24 02:04 utkanuygur

Could I get assigned to this please?

takuel37 avatar Apr 21 '24 03:04 takuel37