Skip to content

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.

improvements: row viewer panel in run mode & lazyframe support (#5071)

Shahmir Varqha2209a416c973
diff --git a/frontend/src/components/data-table/TableActions.tsx b/frontend/src/components/data-table/TableActions.tsx
index 0f48dafc22..e907a456c7 100644
--- a/frontend/src/components/data-table/TableActions.tsx
+++ b/frontend/src/components/data-table/TableActions.tsx
@@ -12,7 +12,6 @@ import type { DataTableSelection } from "./types";
import type { GetRowIds } from "@/plugins/impl/DataTablePlugin";
import { toast } from "../ui/use-toast";
import { cn } from "@/utils/cn";
-import { initialMode } from "@/core/mode";
interface TableActionsProps<TData> {
enableSearch: boolean;
@@ -119,8 +118,7 @@ export const TableActions = <TData,>({
</Button>
</Tooltip>
)}
- {/* Disable in read mode, for now, until the panel is shown */}
- {toggleRowViewerPanel && initialMode !== "read" && (
+ {toggleRowViewerPanel && (
<Tooltip content="Toggle row viewer">
<Button variant="text" size="xs" onClick={toggleRowViewerPanel}>
<PanelRightIcon
diff --git a/frontend/src/components/editor/chrome/wrapper/app-chrome.tsx b/frontend/src/components/editor/chrome/wrapper/app-chrome.tsx
index 5fd9b23dc1..98e7640a16 100644
--- a/frontend/src/components/editor/chrome/wrapper/app-chrome.tsx
+++ b/frontend/src/components/editor/chrome/wrapper/app-chrome.tsx
@@ -34,6 +34,7 @@ import { TracingPanel } from "../panels/tracing-panel";
import { SecretsPanel } from "../panels/secrets-panel";
import { ContextAwarePanel } from "../panels/context-aware-panel/context-aware-panel";
import { handleDragging } from "./utils";
+import { PanelsWrapper } from "./panels";
const LazyTerminal = React.lazy(() => import("@/components/terminal/terminal"));
@@ -223,7 +224,7 @@ export const AppChrome: React.FC<PropsWithChildren> = ({ children }) => {
);
return (
- <div className="flex flex-col flex-1 overflow-hidden absolute inset-0 print:relative">
+ <PanelsWrapper>
<PanelGroup
autoSaveId="marimo:chrome:v1:l2"
direction={"horizontal"}
@@ -246,6 +247,6 @@ export const AppChrome: React.FC<PropsWithChildren> = ({ children }) => {
<Footer />
</TooltipProvider>
</ErrorBoundary>
- </div>
+ </PanelsWrapper>
);
};
diff --git a/frontend/src/components/editor/chrome/wrapper/panels.tsx b/frontend/src/components/editor/chrome/wrapper/panels.tsx
new file mode 100644
index 0000000000..f12f95332a
--- /dev/null
+++ b/frontend/src/components/editor/chrome/wrapper/panels.tsx
@@ -0,0 +1,10 @@
+/* Copyright 2024 Marimo. All rights reserved. */
+import type { PropsWithChildren } from "react";
+
+export const PanelsWrapper: React.FC<PropsWithChildren> = ({ children }) => {
+ return (
+ <div className="flex flex-col flex-1 overflow-hidden absolute inset-0 print:relative">
+ {children}
+ </div>
+ );
+};
diff --git a/frontend/src/components/pages/run-page.tsx b/frontend/src/components/pages/run-page.tsx
index 2bf51f8b10..3804f9279e 100644
--- a/frontend/src/components/pages/run-page.tsx
+++ b/frontend/src/components/pages/run-page.tsx
@@ -5,6 +5,10 @@ import { StaticBanner } from "../static-html/static-banner";
import { isStaticNotebook } from "@/core/static/static-state";
import { isWasm } from "@/core/wasm/utils";
import { Constants } from "@/core/constants";
+import { ContextAwarePanel } from "../editor/chrome/panels/context-aware-panel/context-aware-panel";
+import { PanelGroup, Panel } from "react-resizable-panels";
+import { createStorage } from "../editor/chrome/wrapper/storage";
+import { PanelsWrapper } from "../editor/chrome/wrapper/panels";
interface Props {
appConfig: AppConfig;
@@ -14,11 +18,20 @@ const showWatermark = isWasm() || isStaticNotebook();
const RunPage = (props: Props) => {
return (
- <>
- <StaticBanner />
- <RunApp appConfig={props.appConfig} />
- {showWatermark && <Watermark />}
- </>
+ <PanelsWrapper>
+ <PanelGroup
+ direction="horizontal"
+ autoSaveId="marimo:chrome:v1:run1"
+ storage={createStorage("left")}
+ >
+ <StaticBanner />
+ <Panel>
+ <RunApp appConfig={props.appConfig} />
+ {showWatermark && <Watermark />}
+ </Panel>
+ <ContextAwarePanel />
+ </PanelGroup>
+ </PanelsWrapper>
);
};
diff --git a/marimo/_plugins/ui/_impl/table.py b/marimo/_plugins/ui/_impl/table.py
index 926bc8bdd3..10b4e343d7 100644
--- a/marimo/_plugins/ui/_impl/table.py
+++ b/marimo/_plugins/ui/_impl/table.py
@@ -993,7 +993,6 @@ class table(
),
)
- # If the arguments are hashable, use the cached method
filter_function = (
self._apply_filters_query_sort_cached
if is_hashable(args.filters, args.query, args.sort)
diff --git a/marimo/_plugins/ui/_impl/tables/narwhals_table.py b/marimo/_plugins/ui/_impl/tables/narwhals_table.py
index e7b85e8ee7..7534f6c6b5 100644
--- a/marimo/_plugins/ui/_impl/tables/narwhals_table.py
+++ b/marimo/_plugins/ui/_impl/tables/narwhals_table.py
@@ -260,7 +260,13 @@ class NarwhalsTableManager(
if offset == 0:
return self.with_new_data(self.data.head(count))
else:
- return self.with_new_data(self.data[offset : offset + count])
+ if is_narwhals_lazyframe(self.data):
+ # Lazyframes do not support slicing, https://github.com/narwhals-dev/narwhals/issues/2389
+ # So we collect the first n rows
+ data = self.data.head(offset + count).collect()
+ return self.with_new_data(data[offset : offset + count])
+ else:
+ return self.with_new_data(self.data[offset : offset + count])
def search(self, query: str) -> TableManager[Any]:
query = query.lower()
diff --git a/tests/_plugins/ui/_impl/tables/test_narwhals.py b/tests/_plugins/ui/_impl/tables/test_narwhals.py
index 6c7d78056f..d1f559f325 100644
--- a/tests/_plugins/ui/_impl/tables/test_narwhals.py
+++ b/tests/_plugins/ui/_impl/tables/test_narwhals.py
@@ -289,6 +289,17 @@ class TestNarwhalsTableManagerFactory(unittest.TestCase):
assert self.manager.take(2, 1).data["A"].to_list() == [2, 3]
assert self.manager.take(2, 2).data["A"].to_list() == [3]
+ def test_take_lazyframe(self) -> None:
+ lazy_df = self.data.lazy()
+ lazy_manager = NarwhalsTableManager.from_dataframe(lazy_df)
+
+ assert lazy_manager.take(1, 0).data.collect()["A"].to_list() == [1]
+ assert lazy_manager.take(2, 0).data.collect()["A"].to_list() == [1, 2]
+
+ # Converted to eager frame
+ assert lazy_manager.take(2, 1).data["A"].to_list() == [2, 3]
+ assert lazy_manager.take(2, 2).data["A"].to_list() == [3]
+
def test_take_zero(self) -> None:
limited_manager = self.manager.take(0, 0)
assert limited_manager.data.is_empty()
diff --git a/tests/_plugins/ui/_impl/tables/test_polars_table.py b/tests/_plugins/ui/_impl/tables/test_polars_table.py
index b8fb8658fa..b4a7796ed9 100644
--- a/tests/_plugins/ui/_impl/tables/test_polars_table.py
+++ b/tests/_plugins/ui/_impl/tables/test_polars_table.py
@@ -912,9 +912,9 @@ class TestPolarsTableManagerFactory(unittest.TestCase):
]
assert manager.take(count=10, offset=0).get_num_rows() == 10
- # This is ok and expected, since we don't support pagination for lazy frames
- with pytest.raises(TypeError):
- manager.take(count=10, offset=10)
+ result = manager.take(count=5, offset=10)
+ assert result.get_num_rows() == 5
+ assert result.data["A"].to_list() == [10, 11, 12, 13, 14]
assert len(recorded_warnings) == 0