|
5 | 5 | from packaging.version import Version
|
6 | 6 |
|
7 | 7 |
|
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: |
15 | 9 | try:
|
16 |
| - import tiledb.cloud |
| 10 | + import pandas |
17 | 11 |
|
18 |
| - ver = tiledb.cloud.__version__ |
| 12 | + import tiledb.cloud |
19 | 13 | 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 | + ) |
25 | 38 | # Get a list of all modules from a completely fresh interpreter.
|
26 | 39 | all_mods_str = subprocess.check_output(
|
27 | 40 | (
|
|
0 commit comments