File tree 3 files changed +33
-4
lines changed
3 files changed +33
-4
lines changed Original file line number Diff line number Diff line change @@ -82,7 +82,7 @@ Other Enhancements
82
82
- :meth: `DataFrame.query ` and :meth: `DataFrame.eval ` now supports quoting column names with backticks to refer to names with spaces (:issue: `6508 `)
83
83
- :func: `merge_asof ` now gives a more clear error message when merge keys are categoricals that are not equal (:issue: `26136 `)
84
84
- :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 `)
86
86
87
87
.. _whatsnew_0250.api_breaking :
88
88
Original file line number Diff line number Diff line change 10
10
try :
11
11
__import__ (dependency )
12
12
except ImportError as e :
13
- missing_dependencies .append (dependency )
13
+ missing_dependencies .append (( dependency , e ) )
14
14
15
15
if 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 )
18
20
del hard_dependencies , dependency , missing_dependencies
19
21
20
22
# numpy compat
Original file line number Diff line number Diff line change 1
1
from datetime import datetime , timedelta
2
+ from importlib import reload
2
3
from io import StringIO
3
4
import re
4
5
import sys
6
+ from unittest .mock import patch
5
7
6
8
import numpy as np
7
9
import pytest
@@ -1341,3 +1343,28 @@ def test_to_numpy_dtype(as_series):
1341
1343
expected = np .array (['2000-01-01T05' , '2001-01-01T05' ],
1342
1344
dtype = 'M8[ns]' )
1343
1345
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