Skip to content

Commit a168c00

Browse files
author
Zack Cornelius
committed
Check for existing module in get_module before importing
Significantly speeds up graph rendering when using large (10K entry) pandas dataframe columns. Using 50000 point Pandas series, this speeds up scatter plot generation from 2 seconds to ~280ms
1 parent 168398e commit a168c00

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

Diff for: packages/python/plotly/_plotly_utils/optional_imports.py

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from importlib import import_module
88
import logging
9+
import sys
910

1011
logger = logging.getLogger(__name__)
1112
_not_importable = set()
@@ -20,6 +21,8 @@ def get_module(name):
2021
:return: (module|None) If import succeeds, the module will be returned.
2122
2223
"""
24+
if name in sys.modules:
25+
return sys.modules[name]
2326
if name not in _not_importable:
2427
try:
2528
return import_module(name)

0 commit comments

Comments
 (0)