Skip to content

ENH: improve optional import error message #61597

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pandas/compat/_optional.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ def import_optional_dependency(
install_name = package_name if package_name is not None else name

msg = (
f"Missing optional dependency '{install_name}'. {extra} "
f"Use pip or conda to install {install_name}."
f"`Import {install_name}` failed. {extra} "
f"Use pip or conda to install the {install_name} package."
)
try:
module = importlib.import_module(name)
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/io/test_fsspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ def test_s3_parquet(s3_public_bucket, s3so, df1):

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

Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/io/test_parquet.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ def test_get_engine_auto_error_message():
with pytest.raises(ImportError, match=match):
get_engine("auto")
else:
match = "Missing optional dependency .pyarrow."
match = "Import .pyarrow failed."
with pytest.raises(ImportError, match=match):
get_engine("auto")

Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/test_optional_dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@


def test_import_optional():
match = "Missing .*notapackage.* pip .* conda .* notapackage"
match = "Import .*notapackage.* pip .* conda .* notapackage"
with pytest.raises(ImportError, match=match) as exc_info:
import_optional_dependency("notapackage")
# The original exception should be there as context:
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/util/test_numba.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@

@td.skip_if_installed("numba")
def test_numba_not_installed_option_context():
with pytest.raises(ImportError, match="Missing optional"):
with pytest.raises(ImportError, match="Import numba failed"):
with option_context("compute.use_numba", True):
pass
Loading