Skip to content

Commit d4fc257

Browse files
authored
Make pandas lazy import check conditional on tiledb.cloud version (#1826)
* Make pandas lazy import check conditional on tiledb.cloud version * Address feedback
1 parent f3f5102 commit d4fc257

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

tiledb/tests/test_basic_import.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,33 @@
22
import subprocess
33
import sys
44

5+
from packaging.version import Version
6+
57

68
def test_dont_import_pandas() -> None:
79
"""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.
15+
try:
16+
import tiledb.cloud
17+
18+
ver = tiledb.cloud.__version__
19+
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 = ""
825
# Get a list of all modules from a completely fresh interpreter.
926
all_mods_str = subprocess.check_output(
10-
(sys.executable, "-c", "import sys, tiledb; print(list(sys.modules))")
27+
(
28+
sys.executable,
29+
"-c",
30+
f"import sys; {suppress_cloud} import tiledb; print(list(sys.modules))",
31+
)
1132
)
1233
all_mods = ast.literal_eval(all_mods_str.decode())
1334
assert "pandas" not in all_mods

0 commit comments

Comments
 (0)