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
optimize for lazy as_frame, fix snapshot tests (#8643)
Shahmir Varqha408529707a33
diff --git a/marimo/_plugins/ui/_impl/tables/narwhals_table.py b/marimo/_plugins/ui/_impl/tables/narwhals_table.pyindex 925ccd50ad..4f99a6c4b3 100644--- a/marimo/_plugins/ui/_impl/tables/narwhals_table.py+++ b/marimo/_plugins/ui/_impl/tables/narwhals_table.py@@ -66,11 +66,15 @@ class NarwhalsTableManager() -> NarwhalsTableManager[IntoDataFrameT, IntoLazyFrameT]:return NarwhalsTableManager(nw.from_native(data, pass_through=False))- def as_frame(self) -> nw.DataFrame[Any]:+ @cached_property+ def _collected_frame(self) -> nw.DataFrame[Any]:if is_narwhals_lazyframe(self.data):return self.data.collect()return self.data+ def as_frame(self) -> nw.DataFrame[Any]:+ return self._collected_frame+def as_lazy_frame(self) -> nw.LazyFrame[Any]:if is_narwhals_lazyframe(self.data):return self.data@@ -545,6 +549,11 @@ class NarwhalsTableManager(dtype = self.nw_schema[column]+ # Some backends (e.g. DuckDB) report Unknown for types like Time+ # until the data is collected. Resolve by checking the collected schema.+ if dtype == nw.Unknown:+ dtype = self.as_frame().schema[column]+if dtype.is_temporal():return self._get_bin_values_temporal(column, dtype, num_bins)diff --git a/tests/_sql/test_sql.py b/tests/_sql/test_sql.pyindex 138c728f6a..57c3eef8f8 100644--- a/tests/_sql/test_sql.py+++ b/tests/_sql/test_sql.py@@ -485,9 +485,9 @@ logical_planassert result == snapshot("""\physical_plan┌───────────────────────────┐-│ SEQ_SCAN │+│ SEQ_SCAN ││ ──────────────────── │-│ Table: t │+│ Table: memory.main.t ││ Type: Sequential Scan ││ Projections: id ││ │