Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
838d75f
fix: using polars unnest for all backend types.
Shamik-07 May 15, 2026
851e5b1
fix: update the expand dict print statement.
Shamik-07 May 15, 2026
0ea6758
tests: enabling the expand dict test and adding the necessary datafra…
Shamik-07 May 15, 2026
294e21e
tests: removing ibis skip in expand dict test.
Shamik-07 May 15, 2026
0d1e52f
Merge branch 'main' into fix/expand_dict_transformation
Shamik-07 May 19, 2026
24f672b
fix: removing additional polars dataframe creation and using the none…
Shamik-07 May 19, 2026
4e82164
fix: using polars as optional in test handlers.
Shamik-07 May 19, 2026
88ce223
fix: processing pandas backend separately to not cause arrow coercion…
Shamik-07 May 19, 2026
1f722b8
fix: mypy error.
Shamik-07 May 19, 2026
ff063e5
fix: changing the expand dict print code function for pandas to using…
Shamik-07 May 19, 2026
eb5ed5f
Merge branch 'main' into fix/expand_dict_transformation
Shamik-07 May 20, 2026
6e16445
Merge branch 'main' into fix/expand_dict_transformation
Shamik-07 May 21, 2026
de2ee2e
feat: unnesting only one level of pandas df.
Shamik-07 May 21, 2026
83126b2
refactor: modifying the pandas print module to expect one level of di…
Shamik-07 May 21, 2026
7eedc2d
tests: added a nested dict test for the expand dict handler.
Shamik-07 May 21, 2026
78cbe7d
tests: added a nested dict test for the expand dict handler.
Shamik-07 May 21, 2026
855cd5b
docs: adding comment for using max_level=0 in pd.json_normalize for e…
Shamik-07 May 21, 2026
803d52f
Merge branch 'main' into fix/expand_dict_transformation
Shamik-07 May 21, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion marimo/_plugins/ui/_impl/dataframes/transforms/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,12 @@ def handle_explode_columns(
def handle_expand_dict(
df: DataFrame, transform: ExpandDictTransform
) -> DataFrame:
return df.explode(transform.column_id)
# Convert to Polars for native unnest, which handles null values
# correctly (fixes: 'NoneType' cannot be converted to 'PyDict' issue #4583)
collected_df, undo = collect_and_preserve_type(df)
polars_df = collected_df.to_polars()
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
unnested = polars_df.unnest(transform.column_id)
return undo(nw.from_native(unnested))

@staticmethod
def handle_unique(df: DataFrame, transform: UniqueTransform) -> DataFrame:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ def generate_where_clause_polars(where: FilterCondition) -> str:

elif transform.type == TransformType.EXPAND_DICT:
column_id = _as_literal(transform.column_id)
return f"{df_name}.hstack(pl.DataFrame({df_name}.select({column_id}).to_series().to_list())).drop({column_id})"
return f"{df_name}.unnest({column_id})"

elif transform.type == TransformType.UNIQUE:
column_ids = transform.column_ids
Expand Down
24 changes: 17 additions & 7 deletions tests/_plugins/ui/_impl/dataframes/test_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@

pytest.importorskip("ibis")
pd = pytest.importorskip("pandas")
pytest.importorskip("polars")
pytest.importorskip("pyarrow")
pl = pytest.importorskip("polars")


def apply(df: DataFrameType, transform: Transform) -> DataFrameType:
Expand Down Expand Up @@ -1733,22 +1733,32 @@ def test_explode_columns(df: DataFrameType) -> None:
assert nw_result.columns == ["A", "B", "C"]

@staticmethod
@pytest.mark.skip(
reason="Dict/struct expansion not supported uniformly across backends"
)
@pytest.mark.parametrize(
("df", "expected"),
list(
zip(
create_test_dataframes(
{"A": [{"foo": 1, "bar": "hello"}], "B": [1]}
{"A": [{"foo": 1, "bar": "hello"}], "B": [1]},
),
create_test_dataframes(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

polars should already be created in this create_test_dataframes. so we dont need to add the dataframe below

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed

{"B": [1], "foo": [1], "bar": ["hello"]}
{"B": [1], "foo": [1], "bar": ["hello"]},
),
strict=False,
)
),
)
+ [
(
pl.DataFrame(
{
"A": [{"foo": 1, "bar": "hello"}, None],
"B": [1, 2],
}
),
pl.DataFrame(
{"B": [1, 2], "foo": [1, None], "bar": ["hello", None]}
),
)
],
)
def test_expand_dict(df: DataFrameType, expected: DataFrameType) -> None:
transform = ExpandDictTransform(
Expand Down
Loading