Skip to content
Merged
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
3 changes: 2 additions & 1 deletion doc/source/whatsnew/v1.4.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ Other enhancements
- :meth:`IntegerArray.all` , :meth:`IntegerArray.any`, :meth:`FloatingArray.any`, and :meth:`FloatingArray.all` use Kleene logic (:issue:`41967`)
- Added support for nullable boolean and integer types in :meth:`DataFrame.to_stata`, :class:`~pandas.io.stata.StataWriter`, :class:`~pandas.io.stata.StataWriter117`, and :class:`~pandas.io.stata.StataWriterUTF8` (:issue:`40855`)
- :meth:`DataFrame.__pos__`, :meth:`DataFrame.__neg__` now retain ``ExtensionDtype`` dtypes (:issue:`43883`)

- The error raised when an optional dependency can't be imported now includes the original exception, for easier investigation (:issue:`43882`)
-

.. ---------------------------------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion pandas/compat/_optional.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def import_optional_dependency(
module = importlib.import_module(name)
except ImportError:
if errors == "raise":
raise ImportError(msg) from None
raise ImportError(msg)
else:
return None

Expand Down
4 changes: 3 additions & 1 deletion pandas/tests/test_optional_dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@

def test_import_optional():
match = "Missing .*notapackage.* pip .* conda .* notapackage"
with pytest.raises(ImportError, match=match):
with pytest.raises(ImportError, match=match) as exc_info:
import_optional_dependency("notapackage")
# The original exception should be there as context:
assert isinstance(exc_info.value.__context__, ImportError)

result = import_optional_dependency("notapackage", errors="ignore")
assert result is None
Expand Down