@@ -62,8 +62,7 @@ def _get_version(module: types.ModuleType) -> str:
6262def import_optional_dependency (
6363 name : str ,
6464 extra : str = "" ,
65- raise_on_missing : bool = True ,
66- on_version : str = "raise" ,
65+ errors : str = "raise" ,
6766 min_version : Optional [str ] = None ,
6867):
6968 """
@@ -79,29 +78,30 @@ def import_optional_dependency(
7978 The module name.
8079 extra : str
8180 Additional text to include in the ImportError message.
82- raise_on_missing : bool, default True
83- Whether to raise if the optional dependency is not found.
84- When False and the module is not present, None is returned.
85- on_version : str {'raise', 'warn'}
86- What to do when a dependency's version is too old.
81+ errors : str {'raise', 'warn', 'ignore'}
82+ What to do when a dependency is not found or its version is too old.
8783
8884 * raise : Raise an ImportError
89- * warn : Warn that the version is too old. Returns None
90- * ignore: Return the module, even if the version is too old.
85+ * warn : Only applicable when a module's version is to old.
86+ Warns that the version is too old and returns None
87+ * ignore: If the module is not installed, return None, otherwise,
88+ return the module, even if the version is too old.
9189 It's expected that users validate the version locally when
92- using ``on_version ="ignore"`` (see. ``io/html.py``)
90+ using ``errors ="ignore"`` (see. ``io/html.py``)
9391 min_version : str, default None
9492 Specify a minimum version that is different from the global pandas
9593 minimum version required.
9694 Returns
9795 -------
9896 maybe_module : Optional[ModuleType]
9997 The imported module, when found and the version is correct.
100- None is returned when the package is not found and `raise_on_missing `
101- is False, or when the package's version is too old and `on_version `
98+ None is returned when the package is not found and `errors `
99+ is False, or when the package's version is too old and `errors `
102100 is ``'warn'``.
103101 """
104102
103+ assert errors in {"warn" , "raise" , "ignore" }
104+
105105 package_name = INSTALL_MAPPING .get (name )
106106 install_name = package_name if package_name is not None else name
107107
@@ -112,7 +112,7 @@ def import_optional_dependency(
112112 try :
113113 module = importlib .import_module (name )
114114 except ImportError :
115- if raise_on_missing :
115+ if errors == "raise" :
116116 raise ImportError (msg ) from None
117117 else :
118118 return None
@@ -128,15 +128,14 @@ def import_optional_dependency(
128128 if minimum_version :
129129 version = _get_version (module_to_get )
130130 if distutils .version .LooseVersion (version ) < minimum_version :
131- assert on_version in {"warn" , "raise" , "ignore" }
132131 msg = (
133132 f"Pandas requires version '{ minimum_version } ' or newer of '{ parent } ' "
134133 f"(version '{ version } ' currently installed)."
135134 )
136- if on_version == "warn" :
135+ if errors == "warn" :
137136 warnings .warn (msg , UserWarning )
138137 return None
139- elif on_version == "raise" :
138+ elif errors == "raise" :
140139 raise ImportError (msg )
141140
142141 return module
0 commit comments