@@ -61,6 +61,21 @@ def warn_incompatible_dep(
6161 )
6262
6363
64+ def pandas ():
65+ try :
66+ return importlib .import_module ("pandas" )
67+ except ImportError :
68+ return MissingPandas ()
69+
70+
71+ def pyarrow ():
72+ try :
73+ pyarrow = importlib .import_module ("pyarrow" )
74+ return pyarrow
75+ except ImportError :
76+ raise errors .MissingDependencyError ("pyarrow" )
77+
78+
6479def _import_or_missing_pandas_option () -> (
6580 tuple [ModuleLikeObject , ModuleLikeObject , bool ]
6681):
@@ -114,6 +129,12 @@ def _import_or_missing_pandas_option() -> (
114129 return MissingPandas (), MissingPandas (), False
115130
116131
132+ def installed_pandas () -> bool :
133+ """This function checks if pandas is available and compatible."""
134+ _ , _ , installed = _import_or_missing_pandas_option ()
135+ return installed
136+
137+
117138def _import_or_missing_keyring_option () -> tuple [ModuleLikeObject , bool ]:
118139 """This function tries importing the following packages: keyring.
119140
@@ -127,5 +148,22 @@ def _import_or_missing_keyring_option() -> tuple[ModuleLikeObject, bool]:
127148
128149
129150# Create actual constants to be imported from this file
130- pandas , pyarrow , installed_pandas = _import_or_missing_pandas_option ()
151+ try :
152+ pyarrow = importlib .import_module ("pyarrow" )
153+ except ImportError :
154+ raise errors .MissingDependencyError ("pyarrow" )
155+
131156keyring , installed_keyring = _import_or_missing_keyring_option ()
157+
158+
159+ def __getattr__ (name ):
160+ if name == "pandas" :
161+ try :
162+ return importlib .import_module ("pandas" )
163+ except ImportError :
164+ return MissingPandas ()
165+
166+ elif name == "installed_pandas" :
167+ return installed_pandas ()
168+
169+ raise AttributeError (f"module { __name__ !r} has no attribute { name !r} " )
0 commit comments