From 186bd755fbf00e374503e0be2da79a53f788b968 Mon Sep 17 00:00:00 2001 From: Emily Kellison-Linn <4672118+emilykl@users.noreply.github.com> Date: Fri, 29 Mar 2024 15:57:35 -0400 Subject: [PATCH 1/7] import orjson on initial load --- packages/python/plotly/plotly/io/_json.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/python/plotly/plotly/io/_json.py b/packages/python/plotly/plotly/io/_json.py index 15375632c7..200f970f16 100644 --- a/packages/python/plotly/plotly/io/_json.py +++ b/packages/python/plotly/plotly/io/_json.py @@ -8,6 +8,9 @@ from _plotly_utils.optional_imports import get_module from _plotly_utils.basevalidators import ImageUriValidator +# Ensure `orjson` module is loaded immediately if present (to avoid error on hot reload) +get_module("orjson", should_load=True) + # Orca configuration class # ------------------------ @@ -105,6 +108,7 @@ def to_json_plotly(plotly_object, pretty=False, engine=None): -------- to_json : Convert a plotly Figure to JSON with validation """ + orjson = get_module("orjson", should_load=True) # Determine json engine From 564d2d888e3103eaf282cee6d7f8227e2879ad9e Mon Sep 17 00:00:00 2001 From: Emily Kellison-Linn <4672118+emilykl@users.noreply.github.com> Date: Wed, 3 Apr 2024 12:35:28 -0400 Subject: [PATCH 2/7] improved logic for optional module loading --- .../plotly/_plotly_utils/optional_imports.py | 27 ++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/packages/python/plotly/_plotly_utils/optional_imports.py b/packages/python/plotly/_plotly_utils/optional_imports.py index 32dec4e12a..648626acce 100644 --- a/packages/python/plotly/_plotly_utils/optional_imports.py +++ b/packages/python/plotly/_plotly_utils/optional_imports.py @@ -2,6 +2,7 @@ Stand-alone module to provide information about whether optional deps exist. """ + from importlib import import_module import logging import sys @@ -19,16 +20,18 @@ def get_module(name, should_load=True): :return: (module|None) If import succeeds, the module will be returned. """ - if name in sys.modules: - return sys.modules[name] if not should_load: - return None - if name not in _not_importable: - try: - return import_module(name) - except ImportError: - _not_importable.add(name) - except Exception: - _not_importable.add(name) - msg = f"Error importing optional module {name}" - logger.exception(msg) + return sys.modules.get(name, None) + + else: + if name not in _not_importable: + try: + return import_module(name) + except ImportError: + _not_importable.add(name) + except Exception: + _not_importable.add(name) + msg = f"Error importing optional module {name}" + logger.exception(msg) + else: + return None From 5ec780ac9116a310b8b8b283321c993aa1870024 Mon Sep 17 00:00:00 2001 From: Emily Kellison-Linn <4672118+emilykl@users.noreply.github.com> Date: Wed, 3 Apr 2024 12:42:27 -0400 Subject: [PATCH 3/7] remove extra orjson load --- packages/python/plotly/plotly/io/_json.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/packages/python/plotly/plotly/io/_json.py b/packages/python/plotly/plotly/io/_json.py index 200f970f16..15375632c7 100644 --- a/packages/python/plotly/plotly/io/_json.py +++ b/packages/python/plotly/plotly/io/_json.py @@ -8,9 +8,6 @@ from _plotly_utils.optional_imports import get_module from _plotly_utils.basevalidators import ImageUriValidator -# Ensure `orjson` module is loaded immediately if present (to avoid error on hot reload) -get_module("orjson", should_load=True) - # Orca configuration class # ------------------------ @@ -108,7 +105,6 @@ def to_json_plotly(plotly_object, pretty=False, engine=None): -------- to_json : Convert a plotly Figure to JSON with validation """ - orjson = get_module("orjson", should_load=True) # Determine json engine From 6e59a509fd75fa6d794c8e59eac34b6c4d63547c Mon Sep 17 00:00:00 2001 From: Emily Kellison-Linn <4672118+emilykl@users.noreply.github.com> Date: Wed, 3 Apr 2024 14:25:01 -0400 Subject: [PATCH 4/7] remove else --- packages/python/plotly/_plotly_utils/optional_imports.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/python/plotly/_plotly_utils/optional_imports.py b/packages/python/plotly/_plotly_utils/optional_imports.py index 648626acce..64a494671e 100644 --- a/packages/python/plotly/_plotly_utils/optional_imports.py +++ b/packages/python/plotly/_plotly_utils/optional_imports.py @@ -33,5 +33,5 @@ def get_module(name, should_load=True): _not_importable.add(name) msg = f"Error importing optional module {name}" logger.exception(msg) - else: - return None + + return None From 51c5597dbc55c8db5a7033de49fda7a779aa36e3 Mon Sep 17 00:00:00 2001 From: Emily Kellison-Linn <4672118+emilykl@users.noreply.github.com> Date: Wed, 3 Apr 2024 14:35:15 -0400 Subject: [PATCH 5/7] remove else --- .../plotly/_plotly_utils/optional_imports.py | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/packages/python/plotly/_plotly_utils/optional_imports.py b/packages/python/plotly/_plotly_utils/optional_imports.py index 64a494671e..a31e087a34 100644 --- a/packages/python/plotly/_plotly_utils/optional_imports.py +++ b/packages/python/plotly/_plotly_utils/optional_imports.py @@ -23,15 +23,14 @@ def get_module(name, should_load=True): if not should_load: return sys.modules.get(name, None) - else: - if name not in _not_importable: - try: - return import_module(name) - except ImportError: - _not_importable.add(name) - except Exception: - _not_importable.add(name) - msg = f"Error importing optional module {name}" - logger.exception(msg) - - return None + if name not in _not_importable: + try: + return import_module(name) + except ImportError: + _not_importable.add(name) + except Exception: + _not_importable.add(name) + msg = f"Error importing optional module {name}" + logger.exception(msg) + + return None From b8fd65e18724faf24b977d9b0942f2a28ad910ff Mon Sep 17 00:00:00 2001 From: Emily Kellison-Linn <4672118+emilykl@users.noreply.github.com> Date: Fri, 5 Apr 2024 18:36:28 -0400 Subject: [PATCH 6/7] bump pytest version to fix tests? --- .../python/plotly/test_requirements/requirements_38_core.txt | 2 +- .../plotly/test_requirements/requirements_38_optional.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/python/plotly/test_requirements/requirements_38_core.txt b/packages/python/plotly/test_requirements/requirements_38_core.txt index edb622db5c..61bfc653cd 100644 --- a/packages/python/plotly/test_requirements/requirements_38_core.txt +++ b/packages/python/plotly/test_requirements/requirements_38_core.txt @@ -1,3 +1,3 @@ requests==2.25.1 tenacity==6.2.0 -pytest==6.2.3 +pytest==8.1.1 diff --git a/packages/python/plotly/test_requirements/requirements_38_optional.txt b/packages/python/plotly/test_requirements/requirements_38_optional.txt index e1c0c56b38..4eed0bb5e6 100644 --- a/packages/python/plotly/test_requirements/requirements_38_optional.txt +++ b/packages/python/plotly/test_requirements/requirements_38_optional.txt @@ -5,7 +5,7 @@ numpy==1.20.2 xarray==0.17.0 statsmodels Pillow==8.2.0 -pytest==6.2.3 +pytest==8.1.1 pytz==2021.1 ipython[all]==7.22.0 ipywidgets==8.0.2 From 4f72c59ffdeec9535e50fb5c4fd36c34e548ad04 Mon Sep 17 00:00:00 2001 From: Emily Kellison-Linn <4672118+emilykl@users.noreply.github.com> Date: Thu, 11 Apr 2024 17:05:09 -0400 Subject: [PATCH 7/7] refresh doc test cache --- doc/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/requirements.txt b/doc/requirements.txt index 9dd0319ffe..5c4ee63947 100644 --- a/doc/requirements.txt +++ b/doc/requirements.txt @@ -37,5 +37,5 @@ orjson dash-bio jinja2<3.1 parmed<=3.4.4; python_version<"3.8" +dask==2022.2.0 polars -dask==2022.2.0 \ No newline at end of file