File tree Expand file tree Collapse file tree 3 files changed +33
-4
lines changed
Expand file tree Collapse file tree 3 files changed +33
-4
lines changed Original file line number Diff line number Diff line change @@ -82,7 +82,7 @@ Other Enhancements
8282- :meth: `DataFrame.query ` and :meth: `DataFrame.eval ` now supports quoting column names with backticks to refer to names with spaces (:issue: `6508 `)
8383- :func: `merge_asof ` now gives a more clear error message when merge keys are categoricals that are not equal (:issue: `26136 `)
8484- :meth: `pandas.core.window.Rolling ` supports exponential (or Poisson) window type (:issue: `21303 `)
85- -
85+ - Error message for missing required imports now includes the original ImportError's text ( :issue: ` 23868 `)
8686
8787.. _whatsnew_0250.api_breaking :
8888
Original file line number Diff line number Diff line change 1010 try :
1111 __import__ (dependency )
1212 except ImportError as e :
13- missing_dependencies .append (dependency )
13+ missing_dependencies .append (( dependency , e ) )
1414
1515if missing_dependencies :
16- raise ImportError (
17- "Missing required dependencies {0}" .format (missing_dependencies ))
16+ msg = "Unable to import required dependencies:"
17+ for dependency , e in missing_dependencies :
18+ msg += "\n {0}: {1}" .format (dependency , str (e ))
19+ raise ImportError (msg )
1820del hard_dependencies , dependency , missing_dependencies
1921
2022# numpy compat
Original file line number Diff line number Diff line change 11from datetime import datetime , timedelta
2+ from importlib import reload
23from io import StringIO
34import re
45import sys
6+ from unittest .mock import patch
57
68import numpy as np
79import pytest
@@ -1341,3 +1343,28 @@ def test_to_numpy_dtype(as_series):
13411343 expected = np .array (['2000-01-01T05' , '2001-01-01T05' ],
13421344 dtype = 'M8[ns]' )
13431345 tm .assert_numpy_array_equal (result , expected )
1346+
1347+
1348+ @patch ("builtins.__import__" )
1349+ def test_missing_required_dependency (mock_import ):
1350+ def mock_import_fail (name , * args , ** kwargs ):
1351+ if name == "numpy" :
1352+ raise ImportError ("cannot import name numpy" )
1353+ elif name == "pytz" :
1354+ raise ImportError ("cannot import name some_dependency" )
1355+ elif name == "dateutil" :
1356+ raise ImportError ("cannot import name some_other_dependency" )
1357+ else :
1358+ return __import__ (name , * args , ** kwargs )
1359+
1360+ mock_import .side_effect = mock_import_fail
1361+
1362+ expected_msg = (
1363+ "Unable to import required dependencies:"
1364+ "\n numpy: cannot import name numpy"
1365+ "\n pytz: cannot import name some_dependency"
1366+ "\n dateutil: cannot import name some_other_dependency"
1367+ )
1368+
1369+ with pytest .raises (ImportError , match = expected_msg ):
1370+ reload (pd )
You can’t perform that action at this time.
0 commit comments