-
Notifications
You must be signed in to change notification settings - Fork 4k
Fix MultiselectColumn shape error when adding data
#12936
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
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. |
✅ PR preview is ready!
|
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 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]>
sfc-gh-lwilby
left a comment
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.
LGTM
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.