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: more defensive can_narwhalify (#7160)
Myles Scolnick336b560b09c0
diff --git a/marimo/_utils/narwhals_utils.py b/marimo/_utils/narwhals_utils.pyindex c9ecff95c0..bb50cde775 100644--- a/marimo/_utils/narwhals_utils.py+++ b/marimo/_utils/narwhals_utils.py@@ -70,7 +70,10 @@ def can_narwhalify(try:nw.from_native(obj, pass_through=False, eager_only=eager_only) # type: ignore[call-overload]return True- except TypeError:+ except (TypeError, AttributeError):+ # TypeError: object is not a supported type+ # AttributeError: object has __module__ = None (e.g., SymPy dynamic classes)+ # See: https://github.com/marimo-team/marimo/issues/7158return Falsediff --git a/tests/_utils/test_narwhals_utils.py b/tests/_utils/test_narwhals_utils.pyindex 77aa69070f..13e6383c35 100644--- a/tests/_utils/test_narwhals_utils.py+++ b/tests/_utils/test_narwhals_utils.py@@ -80,6 +80,24 @@ def test_can_narwhalify():assert can_narwhalify(pl.DataFrame({"a": [1, 2, 3]})) is True+def test_can_narwhalify_with_none_module():+ """Test that can_narwhalify handles objects with __module__ = None gracefully.++ This reproduces the issue with SymPy's dynamically created function classes+ which have __module__ = None+ See: https://github.com/marimo-team/marimo/issues/7158+ """++ # Create a class with __module__ = None+ class DynamicClass:+ pass++ obj = DynamicClass()+ obj.__class__.__module__ = None # type: ignore[misc]++ assert can_narwhalify(obj) is False++@pytest.mark.parametrize("df", create_dataframes({"a": [1, 2], "b": ["x", "y"]}))