Skip to content

Commit

Permalink
feat: delay pandas / numpy imports
Browse files Browse the repository at this point in the history
  • Loading branch information
rikbw committed Dec 30, 2024
1 parent 04720f5 commit d4d58b0
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions pythonwhat/Test.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,19 @@ def areinstance(x, y, tuple_of_classes):
# First try to the faster equality functions. If these don't pass,
# Run the assertions that are typically slower.
def is_equal(x, y):
import pandas as pd
from pandas.testing import assert_frame_equal, assert_series_equal
import numpy as np
try:
if areinstance(x, y, (str, int, float, bool, type(None), dict, list, tuple, set)):
return x == y
if areinstance(x, y, (Exception,)):
# Types of errors don't matter (this is debatable)
return str(x) == str(y)
if areinstance(x, y, (np.ndarray, dict, list, tuple)):

# Delay importing pandas / numpy until absolutely necessary. This is important for performance in Pyodide.
import pandas as pd
from pandas.testing import assert_frame_equal, assert_series_equal
import numpy as np

if areinstance(x, y, (np.ndarray,)):
np.testing.assert_equal(x, y)
return True
elif areinstance(x, y, (map, filter)):
Expand Down

0 comments on commit d4d58b0

Please sign in to comment.