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(cache): avoid treating class-like __array__ refs as data primitives (#9569)

Jeremy Tan87ac7a5d9e79
diff --git a/marimo/_runtime/primitives.py b/marimo/_runtime/primitives.py
index 38f38cb45a..7bd25ce9db 100644
--- a/marimo/_runtime/primitives.py
+++ b/marimo/_runtime/primitives.py
@@ -60,6 +60,9 @@ def is_data_primitive(value: Any) -> bool:
if is_primitive(value):
return True
+ if inspect.isclass(value):
+ return False
+
if not (
hasattr(value, "__array__")
or hasattr(value, "toarray")
diff --git a/tests/_runtime/test_primitives.py b/tests/_runtime/test_primitives.py
index 272387e38f..bd41239a87 100644
--- a/tests/_runtime/test_primitives.py
+++ b/tests/_runtime/test_primitives.py
@@ -3,7 +3,26 @@
import functools
from typing import Any
-from marimo._runtime.primitives import is_pure_function
+import pytest
+
+from marimo._dependencies.dependencies import DependencyManager
+from marimo._runtime.primitives import is_data_primitive, is_pure_function
+
+HAS_NUMPY = DependencyManager.numpy.has()
+
+
+class TestDataPrimitiveClassification:
+ @pytest.mark.skipif(not HAS_NUMPY, reason="numpy is required")
+ def test_rejects_class_like_array_protocol(self) -> None:
+ """Issue #9563: class-like __array__ refs are not data primitives."""
+ import numpy as np
+
+ class _ClassLikeArray:
+ @classmethod
+ def __array__(cls, dtype: Any = None) -> Any:
+ return np.array([object()], dtype=object)
+
+ assert is_data_primitive(_ClassLikeArray) is False
class TestWrappedFunctionHandling: