A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
fix: unable to download csv/json for no selection (#4262)
Shahmir Varqhada0665fae110
diff --git a/marimo/_plugins/ui/_impl/table.py b/marimo/_plugins/ui/_impl/table.pyindex 8bbacb6415..2d8062d795 100644--- a/marimo/_plugins/ui/_impl/table.py+++ b/marimo/_plugins/ui/_impl/table.py@@ -553,7 +553,13 @@ class table(Raises:ValueError: If format is not 'csv' or 'json'.+ NotImplementedError: If download is not supported for cell selection."""+ if self._selection in ["single-cell", "multi-cell"]:+ raise NotImplementedError(+ "Download is not supported for cell selection."+ )+manager = (self._selected_managerif self._selected_manager and self._has_any_selection@@ -561,10 +567,7 @@ class table()# Remove the selection column before downloading- if isinstance(manager, TableManager) and self._selection in [- "single",- "multi",- ]:+ if isinstance(manager, TableManager):manager = manager.drop_columns([INDEX_COLUMN_NAME])ext = args.format@@ -576,7 +579,7 @@ class table(raise ValueError("format must be one of 'csv' or 'json'.")else:raise NotImplementedError(- "Download is not supported for cell selection."+ "Download is not supported for this table format.")def _get_column_summaries(self, args: EmptyArgs) -> ColumnSummaries:diff --git a/tests/_plugins/ui/_impl/test_table.py b/tests/_plugins/ui/_impl/test_table.pyindex fb206635a3..77f72a05ae 100644--- a/tests/_plugins/ui/_impl/test_table.py+++ b/tests/_plugins/ui/_impl/test_table.py@@ -1111,9 +1111,21 @@ def test_download_as_polars() -> None:assert selected_df["cities"][0] == "New York"-def test_download_as_for_cell_selection_is_unsupported() -> None:- table = ui.table(data=[], selection="single-cell")- with pytest.raises(NotImplementedError):+def test_download_as_for_unsupported_cell_selection() -> None:+ for selection in ["single-cell", "multi-cell"]:+ table = ui.table(data=[], selection=selection)+ with pytest.raises(NotImplementedError):+ table._download_as(DownloadAsArgs(format="csv"))+++ not DependencyManager.pandas.has() or not DependencyManager.polars.has(),+ reason="Pandas or Polars not installed",+)+def test_download_as_for_supported_cell_selection() -> None:+ # Assert that download works for other selection types+ for selection in ["single", "multi", None]:+ table = ui.table(data=[], selection=selection)table._download_as(DownloadAsArgs(format="csv"))