8000 MNT Use raise from in 19 modules · scikit-learn/scikit-learn@ad29136 · GitHub
[go: up one dir, main page]

Skip to content

Commit ad29136

Browse files
committed
MNT Use raise from in 19 modules
1 parent 52cd110 commit ad29136

File tree

19 files changed

+304
-297
lines changed

19 files changed

+304
-297
lines changed

benchmarks/bench_tsne_mnist.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def sanitize(filename):
106106
if args.bhtsne:
107107
try:
108108
from bhtsne.bhtsne import run_bh_tsne
109-
except ImportError:
109+
except ImportError as e:
110110
raise ImportError("""\
111111
If you want comparison with the reference implementation, build the
112112
binary from source (https://github.com/lvdmaaten/bhtsne) in the folder
@@ -117,7 +117,7 @@ def sanitize(filename):
117117
$ g++ sptree.cpp tsne.cpp tsne_main.cpp -o bh_tsne -O2
118118
$ touch __init__.py
119119
$ cd ..
120-
""")
120+
""") from e
121121

122122
def bhtsne(X):
123123
"""Wrapper for the reference lvdmaaten/bhtsne implementation."""
@@ -131,10 +131,10 @@ def bhtsne(X):
131131

132132
try:
133133
from memory_profiler import profile
134-
except ImportError:
134+
except ImportError as e:
135135
raise ImportError("To run the benchmark with `--profile`, you "
136136
"need to install `memory_profiler`. Please "
137-
"run `pip install memory_profiler`.")
137+
"run `pip install memory_profiler`.") from e
138138
methods = [(n, profile(m)) for n, m in methods]
139139

140140
data_size = [100, 500, 1000, 5000, 10000]

doc/conftest.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,23 +46,23 @@ def setup_working_with_text_data():
4646
def setup_compose():
4747
try:
4848
import pandas # noqa
49-
except ImportError:
50-
raise SkipTest("Skipping compose.rst, pandas not installed")
49+
except ImportError as e:
50+
raise SkipTest("Skipping compose.rst, pandas not installed") from e
5151

5252

5353
def setup_impute():
5454
try:
5555
import pandas # noqa
56-
except ImportError:
57-
raise SkipTest("Skipping impute.rst, pandas not installed")
56+
except ImportError as e:
57+
raise SkipTest("Skipping impute.rst, pandas not installed") from e
5858

5959

6060
def setup_unsupervised_learning():
6161
try:
6262
import skimage # noqa
63-
except ImportError:
63+
except ImportError as e:
6464
raise SkipTest("Skipping unsupervised_learning.rst, scikit-image "
65-
"not installed")
65+
"not installed") from e
6666
# ignore deprecation warnings from scipy.misc.face
6767
warnings.filterwarnings('ignore', 'The binary mode of fromstring',
6868
DeprecationWarning)

doc/tutorial/machine_learning_map/parse_path.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ def Sequence(token):
5454
def convertToFloat(s, loc, toks):
5555
try:
5656
return float(toks[0])
57-
except:
58-
raise ParseException(loc, "invalid float format %s"%toks[0])
57+
except BaseException as e:
58+
raise ParseException(loc, "invalid float format %s" % toks[0]) from e
5959

6060
exponent = CaselessLiteral("e")+Optional(sign)+Word(nums)
6161

0 commit comments

Comments
 (0)
0