Skip to content

Commit

Permalink
fix: unwrap narwhals type from mo.ui.table()
Browse files Browse the repository at this point in the history
  • Loading branch information
mscolnick committed Nov 5, 2024
1 parent 03fbd5a commit 51b3fd7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion marimo/_plugins/ui/_impl/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ def _convert_value(
indices = [int(v) for v in value]
self._selected_manager = self._searched_manager.select_rows(indices)
self._has_any_selection = len(indices) > 0
return self._selected_manager.data # type: ignore[no-any-return]
return unwrap_narwhals_dataframe(self._selected_manager.data) # type: ignore[no-any-return]

def download_as(self, args: DownloadAsArgs) -> str:
# download selected rows if there are any, otherwise use all rows
Expand Down
20 changes: 15 additions & 5 deletions tests/_plugins/ui/_impl/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,9 @@ def test_value_with_sorting_then_selection_dfs(df: Any) -> None:
page_number=0,
)
)
assert nw.from_native(table._convert_value(["0"]))["a"][0] == "z"
value = table._convert_value(["0"])
assert not isinstance(value, nw.DataFrame)
assert nw.from_native(value)["a"][0] == "z"

table.search(
SearchTableArgs(
Expand All @@ -279,7 +281,9 @@ def test_value_with_sorting_then_selection_dfs(df: Any) -> None:
page_number=0,
)
)
assert nw.from_native(table._convert_value(["0"]))["a"][0] == "x"
value = table._convert_value(["0"])
assert not isinstance(value, nw.DataFrame)
assert nw.from_native(value)["a"][0] == "x"


def test_value_with_search_then_selection() -> None:
Expand Down Expand Up @@ -335,7 +339,9 @@ def test_value_with_search_then_selection_dfs(df: Any) -> None:
page_number=0,
)
)
assert nw.from_native(table._convert_value(["0"]))["a"][0] == "bar"
value = table._convert_value(["0"])
assert not isinstance(value, nw.DataFrame)
assert nw.from_native(value)["a"][0] == "bar"

table.search(
SearchTableArgs(
Expand All @@ -344,7 +350,9 @@ def test_value_with_search_then_selection_dfs(df: Any) -> None:
page_number=0,
)
)
assert nw.from_native(table._convert_value(["0"]))["a"][0] == "foo"
value = table._convert_value(["0"])
assert not isinstance(value, nw.DataFrame)
assert nw.from_native(value)["a"][0] == "foo"

# empty search
table.search(
Expand All @@ -353,7 +361,9 @@ def test_value_with_search_then_selection_dfs(df: Any) -> None:
page_number=0,
)
)
assert nw.from_native(table._convert_value(["2"]))["a"][0] == "baz"
value = table._convert_value(["2"])
assert not isinstance(value, nw.DataFrame)
assert nw.from_native(value)["a"][0] == "baz"


def test_table_with_too_many_columns_passes() -> None:
Expand Down

0 comments on commit 51b3fd7

Please sign in to comment.