File tree 3 files changed +34
-4
lines changed
3 files changed +34
-4
lines changed Original file line number Diff line number Diff line change @@ -96,7 +96,8 @@ Other Enhancements
96
96
- :meth: `DataFrame.query ` and :meth: `DataFrame.eval ` now supports quoting column names with backticks to refer to names with spaces (:issue: `6508 `)
97
97
- :func: `merge_asof ` now gives a more clear error message when merge keys are categoricals that are not equal (:issue: `26136 `)
98
98
- :meth: `pandas.core.window.Rolling ` supports exponential (or Poisson) window type (:issue: `21303 `)
99
- - :class: `DatetimeIndex ` and :class: `TimedeltaIndex ` now have a `mean ` method (:issue: `24757 `)
99
+ - Error message for missing required imports now includes the original import error's text (:issue: `23868 `)
100
+ - :class: `DatetimeIndex ` and :class: `TimedeltaIndex ` now have a ``mean `` method (:issue: `24757 `)
100
101
- :meth: `DataFrame.describe ` now formats integer percentiles without decimal point (:issue: `26660 `)
101
102
102
103
.. _whatsnew_0250.api_breaking :
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 ("{0}: {1}" . format ( dependency , str ( e )) )
14
14
15
15
if missing_dependencies :
16
- raise ImportError (
17
- "Missing required dependencies {0}" .format (missing_dependencies ))
16
+ raise ImportError ("Unable to import required dependencies:\n " + "\n " .join (missing_dependencies ))
18
17
del hard_dependencies , dependency , missing_dependencies
19
18
20
19
# numpy compat
Original file line number Diff line number Diff line change 1
1
"""
2
2
Testing that we work in the downstream packages
3
3
"""
4
+ import builtins
4
5
import importlib
5
6
import subprocess
6
7
import sys
@@ -131,3 +132,32 @@ def test_pyarrow(df):
131
132
table = pyarrow .Table .from_pandas (df )
132
133
result = table .to_pandas ()
133
134
tm .assert_frame_equal (result , df )
135
+
136
+
137
+ def test_missing_required_dependency (monkeypatch ):
138
+ # GH 23868
139
+ original_import = __import__
140
+
141
+ def mock_import_fail (name , * args , ** kwargs ):
142
+ if name == "numpy" :
143
+ raise ImportError ("cannot import name numpy" )
144
+ elif name == "pytz" :
145
+ raise ImportError ("cannot import name some_dependency" )
146
+ elif name == "dateutil" :
147
+ raise ImportError ("cannot import name some_other_dependency" )
148
+ else :
149
+ return original_import (name , * args , ** kwargs )
150
+
151
+ expected_msg = (
152
+ "Unable to import required dependencies:"
153
+ "\n numpy: cannot import name numpy"
154
+ "\n pytz: cannot import name some_dependency"
155
+ "\n dateutil: cannot import name some_other_dependency"
156
+ )
157
+
158
+ import pandas as pd
159
+
160
+ with monkeypatch .context () as m :
161
+ m .setattr (builtins , "__import__" , mock_import_fail )
162
+ with pytest .raises (ImportError , match = expected_msg ):
163
+ importlib .reload (pd )
You can’t perform that action at this time.
0 commit comments