Skip to content

Commit

Permalink
Check for existing module in get_module before importing
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Zack Cornelius committed Jul 26, 2019
1 parent 168398e commit a168c00
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/python/plotly/_plotly_utils/optional_imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from importlib import import_module
import logging
import sys

logger = logging.getLogger(__name__)
_not_importable = set()
Expand All @@ -20,6 +21,8 @@ def get_module(name):
:return: (module|None) If import succeeds, the module will be returned.
"""
if name in sys.modules:
return sys.modules[name]
if name not in _not_importable:
try:
return import_module(name)
Expand Down

0 comments on commit a168c00

Please sign in to comment.