Skip to content

Commit d4d58b0

Browse files
committed
feat: delay pandas / numpy imports
1 parent 04720f5 commit d4d58b0

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

pythonwhat/Test.py

+9-4
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,19 @@ def areinstance(x, y, tuple_of_classes):
109109
# First try to the faster equality functions. If these don't pass,
110110
# Run the assertions that are typically slower.
111111
def is_equal(x, y):
112-
import pandas as pd
113-
from pandas.testing import assert_frame_equal, assert_series_equal
114-
import numpy as np
115112
try:
113+
if areinstance(x, y, (str, int, float, bool, type(None), dict, list, tuple, set)):
114+
return x == y
116115
if areinstance(x, y, (Exception,)):
117116
# Types of errors don't matter (this is debatable)
118117
return str(x) == str(y)
119-
if areinstance(x, y, (np.ndarray, dict, list, tuple)):
118+
119+
# Delay importing pandas / numpy until absolutely necessary. This is important for performance in Pyodide.
120+
import pandas as pd
121+
from pandas.testing import assert_frame_equal, assert_series_equal
122+
import numpy as np
123+
124+
if areinstance(x, y, (np.ndarray,)):
120125
np.testing.assert_equal(x, y)
121126
return True
122127
elif areinstance(x, y, (map, filter)):

0 commit comments

Comments
 (0)