Skip to content

Commit

Permalink
Use dynamic imports to delay package downloading until needed
Browse files Browse the repository at this point in the history
  • Loading branch information
wch committed Jan 18, 2024
1 parent 2b3b2e4 commit c304c35
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/hooks/usePyodide.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@ def _shim_seaborn_load_dataset():
import importlib
import importlib.abc
import io
import os
import sys
import pyodide.code
# ==========================================================================
Expand Down Expand Up @@ -257,10 +257,12 @@ def _shim_seaborn_load_dataset():
return list(filter(None, dataset_names))
def load_dataset(name, cache=True, data_home=None, **kws):
import os
import pandas as pd
import seaborn
# Load these dynamically with importlib instead of with 'import pandas'
# because if we do a normal import, then Pyodide will detect and
# automatically download the files for these packages and all their
# dependencies when it starts, which is slow.
pd = importlib.import_module("pandas")
seaborn = importlib.import_module("seaborn")
if isinstance(name, pd.DataFrame):
err = (
Expand Down

0 comments on commit c304c35

Please sign in to comment.