Skip to content

Commit 8c55992

Browse files
Prevent exception when encountering numpy scalar types
1 parent 21bd50a commit 8c55992

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

observ/watcher.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def traverse(obj, seen=None):
114114
seen = []
115115
seen.append(obj)
116116
for v in val_iter:
117-
if has_numpy and isinstance(v, np.ndarray):
117+
if has_numpy and isinstance(v, (np.ndarray, np.generic)):
118118
continue
119119
if v not in seen:
120120
traverse(v, seen=seen)

tests/test_object_proxy.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,13 @@ def test_usage_numpy():
104104

105105
@pytest.mark.skipif(not has_numpy, reason=numpy_missing_reason)
106106
def test_usage_watcher_with_numpy_values():
107-
proxy = reactive({"key": np.eye(4)})
107+
proxy = reactive(
108+
{
109+
"key": np.eye(4),
110+
"float": np.float64(1.2),
111+
"int": np.short(2),
112+
}
113+
)
108114

109115
_ = watch(lambda: proxy, lambda: (), deep=True)
110116

0 commit comments

Comments
 (0)