Skip to content

Commit 52e00a3

Browse files
authored
ENH: improve optional import error message (#61597)
* improve optional import error message * add fix on tests * fix tests * fix test_parquest tests
1 parent acccdac commit 52e00a3

File tree

5 files changed

+10
-10
lines changed

5 files changed

+10
-10
lines changed

pandas/compat/_optional.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,8 @@ def import_optional_dependency(
152152
install_name = package_name if package_name is not None else name
153153

154154
msg = (
155-
f"Missing optional dependency '{install_name}'. {extra} "
156-
f"Use pip or conda to install {install_name}."
155+
f"`Import {install_name}` failed. {extra} "
156+
f"Use pip or conda to install the {install_name} package."
157157
)
158158
try:
159159
module = importlib.import_module(name)

pandas/tests/io/test_fsspec.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ def test_s3_parquet(s3_public_bucket, s3so, df1):
282282

283283
@td.skip_if_installed("fsspec")
284284
def test_not_present_exception():
285-
msg = "Missing optional dependency 'fsspec'|fsspec library is required"
285+
msg = "`Import fsspec` failed. Use pip or conda to install the fsspec package."
286286
with pytest.raises(ImportError, match=msg):
287287
read_csv("memory://test/test.csv")
288288

pandas/tests/io/test_parquet.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ def test_get_engine_auto_error_message():
325325
with pytest.raises(ImportError, match=match):
326326
get_engine("auto")
327327
else:
328-
match = "Missing optional dependency .pyarrow."
328+
match = "Unable to find a usable engine; tried using: 'pyarrow'"
329329
with pytest.raises(ImportError, match=match):
330330
get_engine("auto")
331331

@@ -334,7 +334,7 @@ def test_get_engine_auto_error_message():
334334
with pytest.raises(ImportError, match=match):
335335
get_engine("auto")
336336
else:
337-
match = "Missing optional dependency .fastparquet."
337+
match = "Use pip or conda to install the fastparquet package"
338338
with pytest.raises(ImportError, match=match):
339339
get_engine("auto")
340340

@@ -1133,9 +1133,9 @@ def test_string_inference(self, tmp_path, pa, using_infer_string):
11331133
index=pd.Index(["a", "b"], dtype=dtype),
11341134
columns=pd.Index(
11351135
["a"],
1136-
dtype=object
1137-
if pa_version_under19p0 and not using_infer_string
1138-
else dtype,
1136+
dtype=(
1137+
object if pa_version_under19p0 and not using_infer_string else dtype
1138+
),
11391139
),
11401140
)
11411141
tm.assert_frame_equal(result, expected)

pandas/tests/test_optional_dependency.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313

1414
def test_import_optional():
15-
match = "Missing .*notapackage.* pip .* conda .* notapackage"
15+
match = "Import .*notapackage.* pip .* conda .* notapackage"
1616
with pytest.raises(ImportError, match=match) as exc_info:
1717
import_optional_dependency("notapackage")
1818
# The original exception should be there as context:

pandas/tests/util/test_numba.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77

88
@td.skip_if_installed("numba")
99
def test_numba_not_installed_option_context():
10-
with pytest.raises(ImportError, match="Missing optional"):
10+
with pytest.raises(ImportError, match="`Import numba` failed"):
1111
with option_context("compute.use_numba", True):
1212
pass

0 commit comments

Comments
 (0)