11import codecs
2+ import importlib .util
23import pathlib
34from typing import Any , Callable
45
910
1011ReadCallable = Callable [..., dn .DataFrame ]
1112
13+ # Optional third-party modules required to read each format. Formats not listed here
14+ # rely only on the core dependencies and are always readable.
15+ _READER_REQUIREMENTS : dict [ff .FileFormat , tuple [str , ...]] = {
16+ ff .FileFormat .Sqlite : ("adbc_driver_manager" , "adbc_driver_sqlite" ),
17+ }
18+
19+
20+ def missing_requirements (format : ff .FileFormat ) -> list [str ]:
21+ """Return the modules required to read the format that are not installed."""
22+ return [
23+ module for module in _READER_REQUIREMENTS .get (format , ()) if importlib .util .find_spec (module ) is None
24+ ]
25+
1226
1327def _read_csv (
1428 ctx : dn .SessionContext , path : str | pathlib .Path , delimiter : str , ** kwargs : dict [str , Any ]
@@ -22,7 +36,7 @@ def _read_ipc(ctx: dn.SessionContext, path: str | pathlib.Path, **kwargs: dict[s
2236 import pyarrow .feather
2337
2438 # table = pyarrow.feather.read_table(path, {**{"memory_map": True}, **kwargs})
25- table = pyarrow .feather .read_table (path , ** kwargs )
39+ table = pyarrow .feather .read_table (path , ** kwargs ) # type: ignore[no-untyped-call]
2640 return ctx .from_arrow (table )
2741
2842
@@ -31,7 +45,7 @@ def _read_orc(ctx: dn.SessionContext, path: str | pathlib.Path, **kwargs: dict[s
3145 # Evolution for native datafusion reader
3246 import pyarrow .orc
3347
34- table = pyarrow .orc .read_table (path , ** kwargs )
48+ table = pyarrow .orc .read_table (path , ** kwargs ) # type: ignore[no-untyped-call]
3549 return ctx .from_arrow (table )
3650
3751
@@ -128,11 +142,11 @@ def write_csv(
128142 memory_pool : pa .MemoryPool | None = None ,
129143 ** kwargs : dict [str , Any ],
130144 ) -> None :
131- pyarrow .csv .write_csv (
145+ pyarrow .csv .write_csv ( # type: ignore[attr-defined]
132146 data = data ,
133147 output_file = str (output_file ),
134148 memory_pool = memory_pool ,
135- write_options = pyarrow .csv .WriteOptions (** kwargs ),
149+ write_options = pyarrow .csv .WriteOptions (** kwargs ), # type: ignore[attr-defined]
136150 )
137151
138152 out = write_csv
0 commit comments