Skip to content

Commit b734d6c

Browse files
Ensure that the Pandas import test will work with old Pandas. (#1829)
Because the tiledb-cloud package necessarily has to import Pandas if the installed version of Pandas is old, we also need to suppress the importing of tiledb.cloud in the Pandas import test if the version of Pandas available is old. (This specifically happens in py3.7.)
1 parent 6b28b25 commit b734d6c

File tree

1 file changed

+27
-14
lines changed

1 file changed

+27
-14
lines changed

tiledb/tests/test_basic_import.py

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,36 @@
55
from packaging.version import Version
66

77

8-
def test_dont_import_pandas() -> None:
9-
"""Verifies that when we import TileDB, we don't import Pandas eagerly."""
10-
11-
# If tiledb.cloud < 0.10.21 is installed, we should prevent it from being imported
12-
# before running the test; cloud-py eagerly imported pandas before that version.
13-
# Note that we import tiledb.cloud within tiledb-py, if available, in order to hook
14-
# Array.apply and other functionality.
8+
def tiledb_cloud_eagerly_imports_pandas() -> bool:
159
try:
16-
import tiledb.cloud
10+
import pandas
1711

18-
ver = tiledb.cloud.__version__
12+
import tiledb.cloud
1913
except ImportError:
20-
ver = None
21-
if ver and Version(ver) < Version("0.10.21"):
22-
suppress_cloud = "sys.modules['tiledb.cloud'] = None;"
23-
else:
24-
suppress_cloud = ""
14+
# Can't import something that's not installed.
15+
return False
16+
if Version(tiledb.cloud.__version__) < Version("0.10.21"):
17+
# Old versions of tiledb-cloud will import Pandas eagerly.
18+
return True
19+
if Version(pandas.__version__) < Version("1.5"):
20+
# If an old version of Pandas is installed, tiledb-cloud needs to
21+
# import it eagerly to patch it.
22+
return True
23+
return False
24+
25+
26+
def test_dont_import_pandas() -> None:
27+
"""Verifies that when we import TileDB, we don't import Pandas eagerly."""
28+
29+
# We import tiledb.cloud within tiledb-py, if available, in order to hook
30+
# Array.apply and other functionality. If the version of tiledb-cloud
31+
# we have installed would import Pandas eagerly on its own, we need to
32+
# suppress its importation.
33+
suppress_cloud = (
34+
"sys.modules['tiledb.cloud'] = None;"
35+
if tiledb_cloud_eagerly_imports_pandas()
36+
else ""
37+
)
2538
# Get a list of all modules from a completely fresh interpreter.
2639
all_mods_str = subprocess.check_output(
2740
(

0 commit comments

Comments
 (0)