Skip to content

Commit dc70860

Browse files
committed
FIX: fixed dispatch_file_suffix_by_available_module requiring submodules
importlib.util.find_spec only works lazily for top-level modules
1 parent 44ac608 commit dc70860

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

larray_editor/arrayadapter.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2009,7 +2009,7 @@ def __init__(self, data, attributes):
20092009

20102010
def _open_file(self, col_indices=None):
20112011
"""col_indices is only taken into account if self.data is a Path"""
2012-
ipc = sys.modules['pyarrow.ipc']
2012+
import pyarrow.ipc as ipc
20132013
if isinstance(self.data, Path):
20142014
if col_indices is not None:
20152015
options = ipc.IpcReadOptions(included_fields=col_indices)
@@ -3514,6 +3514,14 @@ def dispatch_parquet_path_adapter(fpath):
35143514
# modules are tried in the order they are defined
35153515
def dispatch_file_suffix_by_available_module(suffix, module_dict: dict):
35163516
for module_name, adapter_cls in module_dict.items():
3517+
# We need this special case because find_spec can only safely check the
3518+
# presence of top level modules. For submodules, it actually imports
3519+
# the parent module and only then checks for the submodule, which
3520+
# breaks if the parent module is not available.
3521+
if '.' in module_name:
3522+
top_module = module_name.split('.')[0]
3523+
if importlib.util.find_spec(top_module) is None:
3524+
continue
35173525
if importlib.util.find_spec(module_name) is not None:
35183526
return adapter_cls
35193527
module_names = ', '.join(module_dict.keys())

0 commit comments

Comments
 (0)