Fix MultiselectColumn shape error when adding data#12936
Merged
sfc-gh-lmasuch merged 2 commits intodevelopfrom Nov 5, 2025
Merged
Fix MultiselectColumn shape error when adding data#12936sfc-gh-lmasuch merged 2 commits intodevelopfrom
MultiselectColumn shape error when adding data#12936sfc-gh-lmasuch merged 2 commits intodevelopfrom
Conversation
Contributor
✅ 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. |
Contributor
✅ PR preview is ready!
|
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR fixes an issue where pandas/numpy incorrectly coerces nested sequences (e.g., lists) into multi-dimensional arrays when adding rows to a DataFrame with columns that legitimately store list values.
- Introduces a new helper function
_assign_row_valuesthat assigns values via a dictionary mapping to prevent numpy type coercion - Replaces direct
.locassignments with the new helper function in_apply_row_additions - Adds test coverage for list-valued columns in row additions
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| lib/streamlit/elements/widgets/data_editor.py | Adds _assign_row_values helper function and updates _apply_row_additions to use it instead of direct .loc assignments |
| lib/tests/streamlit/elements/data_editor_test.py | Enhances test_apply_row_additions with list-valued column test cases and additional assertions |
## 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 - Added unit test for Python --- **Contribution License Agreement** By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Use Series-based row insertion in DataEditor to support list-valued columns and add tests covering multiselect/list columns. > > - **Data Editor (backend)**: > - When adding rows in `_apply_row_additions`, assign via `pd.Series(new_row, index=df.columns)` to preserve column types (e.g., list-valued columns) instead of assigning raw lists. > - **Tests**: > - Extend `test_apply_row_additions` to include a list column (`col5`) and validate list values are correctly inserted for new rows. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 87c8ea3. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY --> --------- Co-authored-by: kkchemboli <[email protected]> Co-authored-by: Lukas Masuch <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Describe your changes
Fixes an issue when adding new data to
MultiselectColumnresulting in a wrong shape error.GitHub Issue Link (if applicable)
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
Use dict-based row assignment to preserve list values during row additions and add tests covering list columns.
_assign_row_valuesto assign rows viadict(zip(df.columns, row_values)).df.loc[...]=new_rowin_apply_row_additionswith_assign_row_valuesto prevent NumPy coercion of list values.lib/tests/streamlit/elements/data_editor_test.py):test_apply_row_additionswith list columncol5and verify list values persist and dtypes remain correct.Written by Cursor Bugbot for commit 8abaf76. This will update automatically on new commits. Configure here.