From f14283b6604e3fb9b3716e84b89f8f857fff3d0d Mon Sep 17 00:00:00 2001 From: philippe Date: Mon, 1 Aug 2022 12:13:23 -0400 Subject: [PATCH 1/5] Add test callback ndarray output --- .../callbacks/test_basic_callback.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/integration/callbacks/test_basic_callback.py b/tests/integration/callbacks/test_basic_callback.py index bd1cb479bf..320bfcf4ba 100644 --- a/tests/integration/callbacks/test_basic_callback.py +++ b/tests/integration/callbacks/test_basic_callback.py @@ -765,3 +765,21 @@ def update_output(value): return f"returning {value}" assert update_output("my-value") == "returning my-value" + + +def test_cbsc018_callback_ndarray_output(dash_duo): + import numpy as np + + app = Dash(__name__) + app.layout = html.Div([dcc.Store(id="output"), html.Button("click", id="clicker")]) + + @app.callback( + Output("output", "data"), + Input("clicker", "n_clicks"), + ) + def on_click(_): + return np.array([[1, 2, 3], [4, 5, 6]], np.int32) + + dash_duo.start_server(app) + + assert dash_duo.get_logs() == [] From bdecc65b77c4ef39acb4501f26912f326eff0639 Mon Sep 17 00:00:00 2001 From: philippe Date: Mon, 1 Aug 2022 12:16:38 -0400 Subject: [PATCH 2/5] Fix is_no_update with numpy outputs. --- dash/_callback.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/dash/_callback.py b/dash/_callback.py index 6f48ca63c1..b878482cfb 100644 --- a/dash/_callback.py +++ b/dash/_callback.py @@ -40,9 +40,11 @@ def to_plotly_json(self): # pylint: disable=no-self-use @staticmethod def is_no_update(obj): - return isinstance(obj, NoUpdate) or obj == { - "_dash_no_update": "_dash_no_update" - } + return ( + isinstance(obj, NoUpdate) + or isinstance(obj, dict) + and obj == {"_dash_no_update": "_dash_no_update"} + ) GLOBAL_CALLBACK_LIST = [] From ae5f60c08878b19f83801fe5836a2222d0283473 Mon Sep 17 00:00:00 2001 From: philippe Date: Mon, 1 Aug 2022 12:44:57 -0400 Subject: [PATCH 3/5] Update changelog. --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a73465b95..ae4c6516dc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,9 @@ This project adheres to [Semantic Versioning](https://semver.org/). ## [UNRELEASED] +### Fixed + +- [#2175](https://github.com/plotly/dash/pull/2175) Fix [#2173](https://github.com/plotly/dash/issues/2173) callback output of ndarray and no_update check. - [#2146](https://github.com/plotly/dash/pull/2146) Remove leftover debug console.log statement. - [#2168](https://github.com/plotly/dash/pull/2168) Reverts [#2126](https://github.com/plotly/dash/pull/2126) (supporting redirect from root when using pages) until the new bugs introduced by that PR are fixed. From 249c934bb943947d24593685dea488927e942060 Mon Sep 17 00:00:00 2001 From: Philippe Duval Date: Tue, 2 Aug 2022 10:01:03 -0400 Subject: [PATCH 4/5] Update dash/_callback.py Co-authored-by: Alex Johnson --- dash/_callback.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dash/_callback.py b/dash/_callback.py index b878482cfb..f463d82396 100644 --- a/dash/_callback.py +++ b/dash/_callback.py @@ -42,8 +42,8 @@ def to_plotly_json(self): # pylint: disable=no-self-use def is_no_update(obj): return ( isinstance(obj, NoUpdate) - or isinstance(obj, dict) - and obj == {"_dash_no_update": "_dash_no_update"} + or (isinstance(obj, dict) + and obj == {"_dash_no_update": "_dash_no_update"}) ) From 73c80cfc781cd2b85489729680ab480762232575 Mon Sep 17 00:00:00 2001 From: philippe Date: Tue, 2 Aug 2022 10:03:31 -0400 Subject: [PATCH 5/5] Format and move import. --- dash/_callback.py | 6 ++---- tests/integration/callbacks/test_basic_callback.py | 3 +-- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/dash/_callback.py b/dash/_callback.py index f463d82396..b23f14c6c3 100644 --- a/dash/_callback.py +++ b/dash/_callback.py @@ -40,10 +40,8 @@ def to_plotly_json(self): # pylint: disable=no-self-use @staticmethod def is_no_update(obj): - return ( - isinstance(obj, NoUpdate) - or (isinstance(obj, dict) - and obj == {"_dash_no_update": "_dash_no_update"}) + return isinstance(obj, NoUpdate) or ( + isinstance(obj, dict) and obj == {"_dash_no_update": "_dash_no_update"} ) diff --git a/tests/integration/callbacks/test_basic_callback.py b/tests/integration/callbacks/test_basic_callback.py index 320bfcf4ba..709122dc6b 100644 --- a/tests/integration/callbacks/test_basic_callback.py +++ b/tests/integration/callbacks/test_basic_callback.py @@ -4,6 +4,7 @@ import pytest import time +import numpy as np import werkzeug from dash_test_components import ( @@ -768,8 +769,6 @@ def update_output(value): def test_cbsc018_callback_ndarray_output(dash_duo): - import numpy as np - app = Dash(__name__) app.layout = html.Div([dcc.Store(id="output"), html.Button("click", id="clicker")])