7
7
import importlib
8
8
import os
9
9
import warnings
10
- from importlib .metadata import distributions
10
+ from importlib .metadata import PackageNotFoundError , distribution
11
11
from logging import getLogger
12
12
from types import ModuleType
13
13
from typing import Union
@@ -85,13 +85,13 @@ def _import_or_missing_pandas_option() -> (
85
85
os .environ ["ARROW_DEFAULT_MEMORY_POOL" ] = "system"
86
86
87
87
# Check whether we have the currently supported pyarrow installed
88
- installed_packages = {
89
- package . metadata [ "Name" ]: package for package in distributions ( )
90
- }
91
- if { "pyarrow" , "snowflake-connector-python" } <= installed_packages . keys ():
92
- dependencies = installed_packages [
93
- "snowflake-connector-python"
94
- ]. metadata . get_all ( "Requires-Dist" , [] )
88
+ try :
89
+ pyarrow_dist = distribution ( "pyarrow" )
90
+ snowflake_connector_dist = distribution ( "snowflake-connector-python" )
91
+
92
+ dependencies = snowflake_connector_dist . metadata . get_all (
93
+ "Requires-Dist" , []
94
+ )
95
95
pandas_pyarrow_extra = None
96
96
for dependency in dependencies :
97
97
dep = Requirement (dependency )
@@ -103,16 +103,15 @@ def _import_or_missing_pandas_option() -> (
103
103
pandas_pyarrow_extra = dep
104
104
break
105
105
106
- installed_pyarrow_version = installed_packages [ "pyarrow" ] .version
106
+ installed_pyarrow_version = pyarrow_dist .version
107
107
if not pandas_pyarrow_extra .specifier .contains (installed_pyarrow_version ):
108
108
warn_incompatible_dep (
109
109
"pyarrow" , installed_pyarrow_version , pandas_pyarrow_extra
110
110
)
111
111
112
- else :
112
+ except PackageNotFoundError as e :
113
113
logger .info (
114
- "Cannot determine if compatible pyarrow is installed because of missing package(s) from "
115
- "{}" .format (list (installed_packages .keys ()))
114
+ f"Cannot determine if compatible pyarrow is installed because of missing package(s): { e } "
116
115
)
117
116
return pandas , pyarrow , True
118
117
except ImportError :
0 commit comments