Skip to content

Commit 1a8972b

Browse files
GH-36553: [Python] Improve error message if certain submodule (cython or cpp) is not built (#36554)
### Rationale for this change Improving the error message when a submodule is not built (by catching the ImportError and re-raising it reworded) * Closes: #36553 Authored-by: Joris Van den Bossche <[email protected]> Signed-off-by: Sutou Kouhei <[email protected]>
1 parent b77af9e commit 1a8972b

5 files changed

Lines changed: 125 additions & 95 deletions

File tree

‎python/pyarrow/acero.py‎

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,22 @@
2525
from pyarrow.lib import Table
2626
from pyarrow.compute import Expression, field
2727

28-
from pyarrow._acero import ( # noqa
29-
Declaration,
30-
ExecNodeOptions,
31-
TableSourceNodeOptions,
32-
FilterNodeOptions,
33-
ProjectNodeOptions,
34-
AggregateNodeOptions,
35-
OrderByNodeOptions,
36-
HashJoinNodeOptions,
37-
)
28+
try:
29+
from pyarrow._acero import ( # noqa
30+
Declaration,
31+
ExecNodeOptions,
32+
TableSourceNodeOptions,
33+
FilterNodeOptions,
34+
ProjectNodeOptions,
35+
AggregateNodeOptions,
36+
OrderByNodeOptions,
37+
HashJoinNodeOptions,
38+
)
39+
except ImportError as exc:
40+
raise ImportError(
41+
f"The pyarrow installation is not built with support for 'acero' ({str(exc)})"
42+
) from None
43+
3844

3945
try:
4046
import pyarrow.dataset as ds

‎python/pyarrow/dataset.py‎

Lines changed: 39 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -20,39 +20,45 @@
2020
import pyarrow as pa
2121
from pyarrow.util import _is_iterable, _stringify_path, _is_path_like
2222

23-
from pyarrow._dataset import ( # noqa
24-
CsvFileFormat,
25-
CsvFragmentScanOptions,
26-
JsonFileFormat,
27-
JsonFragmentScanOptions,
28-
Dataset,
29-
DatasetFactory,
30-
DirectoryPartitioning,
31-
FeatherFileFormat,
32-
FilenamePartitioning,
33-
FileFormat,
34-
FileFragment,
35-
FileSystemDataset,
36-
FileSystemDatasetFactory,
37-
FileSystemFactoryOptions,
38-
FileWriteOptions,
39-
Fragment,
40-
FragmentScanOptions,
41-
HivePartitioning,
42-
IpcFileFormat,
43-
IpcFileWriteOptions,
44-
InMemoryDataset,
45-
Partitioning,
46-
PartitioningFactory,
47-
Scanner,
48-
TaggedRecordBatch,
49-
UnionDataset,
50-
UnionDatasetFactory,
51-
WrittenFile,
52-
get_partition_keys,
53-
get_partition_keys as _get_partition_keys, # keep for backwards compatibility
54-
_filesystemdataset_write,
55-
)
23+
try:
24+
from pyarrow._dataset import ( # noqa
25+
CsvFileFormat,
26+
CsvFragmentScanOptions,
27+
JsonFileFormat,
28+
JsonFragmentScanOptions,
29+
Dataset,
30+
DatasetFactory,
31+
DirectoryPartitioning,
32+
FeatherFileFormat,
33+
FilenamePartitioning,
34+
FileFormat,
35+
FileFragment,
36+
FileSystemDataset,
37+
FileSystemDatasetFactory,
38+
FileSystemFactoryOptions,
39+
FileWriteOptions,
40+
Fragment,
41+
FragmentScanOptions,
42+
HivePartitioning,
43+
IpcFileFormat,
44+
IpcFileWriteOptions,
45+
InMemoryDataset,
46+
Partitioning,
47+
PartitioningFactory,
48+
Scanner,
49+
TaggedRecordBatch,
50+
UnionDataset,
51+
UnionDatasetFactory,
52+
WrittenFile,
53+
get_partition_keys,
54+
get_partition_keys as _get_partition_keys, # keep for backwards compatibility
55+
_filesystemdataset_write,
56+
)
57+
except ImportError as exc:
58+
raise ImportError(
59+
f"The pyarrow installation is not built with support for 'dataset' ({str(exc)})"
60+
) from None
61+
5662
# keep Expression functionality exposed here for backwards compatibility
5763
from pyarrow.compute import Expression, scalar, field # noqa
5864

‎python/pyarrow/flight.py‎

Lines changed: 52 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -15,50 +15,55 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717

18-
from pyarrow._flight import ( # noqa:F401
19-
connect,
20-
Action,
21-
ActionType,
22-
BasicAuth,
23-
CallInfo,
24-
CertKeyPair,
25-
ClientAuthHandler,
26-
ClientMiddleware,
27-
ClientMiddlewareFactory,
28-
DescriptorType,
29-
FlightCallOptions,
30-
FlightCancelledError,
31-
FlightClient,
32-
FlightDataStream,
33-
FlightDescriptor,
34-
FlightEndpoint,
35-
FlightError,
36-
FlightInfo,
37-
FlightInternalError,
38-
FlightMetadataReader,
39-
FlightMetadataWriter,
40-
FlightMethod,
41-
FlightServerBase,
42-
FlightServerError,
43-
FlightStreamChunk,
44-
FlightStreamReader,
45-
FlightStreamWriter,
46-
FlightTimedOutError,
47-
FlightUnauthenticatedError,
48-
FlightUnauthorizedError,
49-
FlightUnavailableError,
50-
FlightWriteSizeExceededError,
51-
GeneratorStream,
52-
Location,
53-
MetadataRecordBatchReader,
54-
MetadataRecordBatchWriter,
55-
RecordBatchStream,
56-
Result,
57-
SchemaResult,
58-
ServerAuthHandler,
59-
ServerCallContext,
60-
ServerMiddleware,
61-
ServerMiddlewareFactory,
62-
Ticket,
63-
TracingServerMiddlewareFactory,
64-
)
18+
try:
19+
from pyarrow._flight import ( # noqa:F401
20+
connect,
21+
Action,
22+
ActionType,
23+
BasicAuth,
24+
CallInfo,
25+
CertKeyPair,
26+
ClientAuthHandler,
27+
ClientMiddleware,
28+
ClientMiddlewareFactory,
29+
DescriptorType,
30+
FlightCallOptions,
31+
FlightCancelledError,
32+
FlightClient,
33+
FlightDataStream,
34+
FlightDescriptor,
35+
FlightEndpoint,
36+
FlightError,
37+
FlightInfo,
38+
FlightInternalError,
39+
FlightMetadataReader,
40+
FlightMetadataWriter,
41+
FlightMethod,
42+
FlightServerBase,
43+
FlightServerError,
44+
FlightStreamChunk,
45+
FlightStreamReader,
46+
FlightStreamWriter,
47+
FlightTimedOutError,
48+
FlightUnauthenticatedError,
49+
FlightUnauthorizedError,
50+
FlightUnavailableError,
51+
FlightWriteSizeExceededError,
52+
GeneratorStream,
53+
Location,
54+
MetadataRecordBatchReader,
55+
MetadataRecordBatchWriter,
56+
RecordBatchStream,
57+
Result,
58+
SchemaResult,
59+
ServerAuthHandler,
60+
ServerCallContext,
61+
ServerMiddleware,
62+
ServerMiddlewareFactory,
63+
Ticket,
64+
TracingServerMiddlewareFactory,
65+
)
66+
except ImportError as exc:
67+
raise ImportError(
68+
f"The pyarrow installation is not built with support for 'flight' ({str(exc)})"
69+
) from None

‎python/pyarrow/parquet/core.py‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,14 @@
3333

3434
import pyarrow as pa
3535
import pyarrow.lib as lib
36-
import pyarrow._parquet as _parquet
36+
37+
try:
38+
import pyarrow._parquet as _parquet
39+
except ImportError as exc:
40+
raise ImportError(
41+
"The pyarrow installation is not built with support "
42+
f"for the Parquet file format ({str(exc)})"
43+
) from None
3744

3845
from pyarrow._parquet import (ParquetReader, Statistics, # noqa
3946
FileMetaData, RowGroupMetaData,

‎python/pyarrow/substrait.py‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,13 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717

18-
from pyarrow._substrait import ( # noqa
19-
get_supported_functions,
20-
run_query,
21-
)
18+
try:
19+
from pyarrow._substrait import ( # noqa
20+
get_supported_functions,
21+
run_query,
22+
)
23+
except ImportError as exc:
24+
raise ImportError(
25+
"The pyarrow installation is not built with support "
26+
f"for 'substrait' ({str(exc)})"
27+
) from None

0 commit comments

Comments
 (0)