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.

fix: lazyframe to use polars table manager (#4990)

Shahmir Varqha069eec46f98f
diff --git a/marimo/_plugins/ui/_impl/tables/polars_table.py b/marimo/_plugins/ui/_impl/tables/polars_table.py
index 761b5c7ff4..1df84526b0 100644
--- a/marimo/_plugins/ui/_impl/tables/polars_table.py
+++ b/marimo/_plugins/ui/_impl/tables/polars_table.py
@@ -56,6 +56,9 @@ class PolarsTableManagerFactory(TableManagerFactory):
@cached_property
def schema(self) -> dict[str, pl.DataType]:
+ if isinstance(self._original_data, pl.LazyFrame):
+ # Less expensive operation
+ return self._original_data.collect_schema()
return self._original_data.schema
def to_arrow_ipc(self) -> bytes:
@@ -188,7 +191,7 @@ class PolarsTableManagerFactory(TableManagerFactory):
@staticmethod
def is_type(value: Any) -> bool:
- return isinstance(value, pl.DataFrame)
+ return isinstance(value, (pl.DataFrame, pl.LazyFrame))
def search(self, query: str) -> PolarsTableManager:
query = query.lower()
diff --git a/tests/_plugins/ui/_impl/charts/test_altair_transformers.py b/tests/_plugins/ui/_impl/charts/test_altair_transformers.py
index 02a7a52153..8b7a7bfbd1 100644
--- a/tests/_plugins/ui/_impl/charts/test_altair_transformers.py
+++ b/tests/_plugins/ui/_impl/charts/test_altair_transformers.py
@@ -229,7 +229,7 @@ def test_register_transformers(mock_data_transformers: MagicMock):
)
-SUPPORTS_ARROW_IPC = ["pandas", "polars"]
+SUPPORTS_ARROW_IPC = ["pandas", "polars", "lazy-polars"]
@pytest.mark.skipif(not HAS_DEPS, reason="optional dependencies not installed")
diff --git a/tests/_plugins/ui/_impl/tables/test_polars_table.py b/tests/_plugins/ui/_impl/tables/test_polars_table.py
index 074c7c21cb..06ad237c5d 100644
--- a/tests/_plugins/ui/_impl/tables/test_polars_table.py
+++ b/tests/_plugins/ui/_impl/tables/test_polars_table.py
@@ -916,8 +916,7 @@ class TestPolarsTableManagerFactory(unittest.TestCase):
with pytest.raises(TypeError):
manager.take(count=10, offset=10)
- # TODO: Fix this, it should be 1
- assert len(recorded_warnings) == 1
+ assert len(recorded_warnings) == 0
def test_to_json_bigint(self) -> None:
import polars as pl