Skip to content

Conversation

@lukasmasuch
Copy link
Collaborator

@lukasmasuch lukasmasuch commented Nov 5, 2025

Describe your changes

Fixes an issue when adding new data to MultiselectColumn resulting in a wrong shape error.

GitHub Issue Link (if applicable)

Testing Plan

  • Added unit test.

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.

  • Data Editor (backend):
    • Introduce _assign_row_values to assign rows via dict(zip(df.columns, row_values)).
    • Replace df.loc[...]=new_row in _apply_row_additions with _assign_row_values to prevent NumPy coercion of list values.
  • Tests (lib/tests/streamlit/elements/data_editor_test.py):
    • Extend test_apply_row_additions with list column col5 and verify list values persist and dtypes remain correct.

Written by Cursor Bugbot for commit 8abaf76. This will update automatically on new commits. Configure here.

@snyk-io
Copy link
Contributor

snyk-io bot commented Nov 5, 2025

Snyk checks have passed. No issues have been found so far.

Status Scanner Critical High Medium Low Total (0)
Licenses 0 0 0 0 0 issues
Open Source Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@github-actions
Copy link
Contributor

github-actions bot commented Nov 5, 2025

✅ PR preview is ready!

Name Link
📦 Wheel file https://core-previews.s3-us-west-2.amazonaws.com/pr-12936/streamlit-1.51.0-py3-none-any.whl
📦 @streamlit/component-v2-lib Download from artifacts
🕹️ Preview app pr-12936.streamlit.app (☁️ Deploy here if not accessible)

@lukasmasuch lukasmasuch added security-assessment-completed Security assessment has been completed for PR change:bugfix PR contains bug fix implementation impact:users PR changes affect end users labels Nov 5, 2025
@lukasmasuch lukasmasuch requested a review from Copilot November 5, 2025 01:55
Copy link
Contributor

Copilot AI left a 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_values that assigns values via a dictionary mapping to prevent numpy type coercion
  • Replaces direct .loc assignments 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

@lukasmasuch lukasmasuch marked this pull request as ready for review November 5, 2025 02:49
## 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]>
Copy link
Collaborator

@sfc-gh-lwilby sfc-gh-lwilby left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@sfc-gh-lmasuch sfc-gh-lmasuch merged commit 6c3f2ba into develop Nov 5, 2025
37 checks passed
@sfc-gh-lmasuch sfc-gh-lmasuch deleted the fix/multiselect-col-shape-error branch November 5, 2025 21:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

change:bugfix PR contains bug fix implementation impact:users PR changes affect end users security-assessment-completed Security assessment has been completed for PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MultiselectColumn: inhomogeneous array shape error when adding new row to data editor with multiple columns

5 participants