-
Notifications
You must be signed in to change notification settings - Fork 4k
Fix DataEditor MultiselectColumn bug and add test #12860
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
Fix DataEditor MultiselectColumn bug and add test #12860
Conversation
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
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.
Pull Request Overview
This PR fixes a bug in the Streamlit DataEditor where columns containing lists (like multiselect columns) would raise a ValueError during rendering due to pandas array assignment issues with sequences.
Key Changes:
- Modified
_apply_row_additionsto wrap new row data inpd.Serieswith explicit column index alignment - Added comprehensive unit test to verify the fix works with multiselect columns
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| lib/streamlit/elements/widgets/data_editor.py | Fixed row addition logic to properly handle list-type cells by wrapping assignments in pd.Series |
| lib/tests/streamlit/multiselect_column_test.py | Added unit test verifying DataEditor works with multiselect columns containing list values |
| @@ -0,0 +1,77 @@ | |||
| # Copyright (c) Streamlit Inc. (2018-2022) Snowflake Inc. (2022-2025) | |||
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.
Our tests are typically organized around the widget/element. Did you consider adding a test into data_editor_test.py?
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.
Thanks for letting me know. Have moved the test into data_editor_test.py.
b832e2f to
9bb1049
Compare
|
@kkchemboli thanks for creating this PR! We had another issue come in where there was a silent failure when we start with an empty data editor. It could be a similar root cause, so I am wondering if you would be willing to test if your fix resolves this as well and if so add some test coverage for this? #12842 |
| ) | ||
|
|
||
| assert len(df) == 5 | ||
| assert len(df["col5"].tolist()) == 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.
It would be good to strengthen this test by testing that the values are preserved correctly.
# Replace weak assertion:
assert len(df["col5"].tolist()) == 5
# With value verification:
assert df.loc[3, "col5"] == ["x", "y"]
assert df.loc[4, "col5"] == ["z"]
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.
Thanks for pointing that out . I've made the change.
I tested the case from #12842 (starting with an empty data editor), and it looks like my current fix doesn’t resolve that issue. |
|
It looks like the CI run failed due to a timeout .Would it be possible to re-run the checks when you get a chance? Thanks! |
|
@kkchemboli thanks for your contribution :) I looked into this as well, and I think using I will merge your PR into mine to give you co-contributor credits. |
…-MultiselectColumn
8abaf76
into
streamlit:fix/multiselect-col-shape-error
Describe your changes
This PR fixes a bug in the Streamlit DataEditor where columns containing lists (like a multiselect column) would raise a ValueError when rendering:
ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions.GitHub Issue Link (if applicable)
Fixes #12815
Testing Plan
Contribution License Agreement
By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.
Note
No changes in this PR.
Written by Cursor Bugbot for commit f08956b. This will update automatically on new commits. Configure here.