8000 MNT use raise from in validation.py (#17545) · scikit-learn/scikit-learn@52cd110 · GitHub
[go: up one dir, main page]

Skip to content

Commit 52cd110

Browse files
authored
MNT use raise from in validation.py (#17545)
1 parent a8067f7 commit 52cd110

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

sklearn/utils/validation.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,8 @@ def _num_samples(x):
202202

203203
try:
204204
return len(x)
205-
except TypeError:
206-
raise TypeError(message)
205+
except TypeError as type_error:
206+
raise TypeError(message) from type_error
207207

208208

209209
def check_memory(memory):
@@ -597,9 +597,9 @@ def check_array(array, accept_sparse=False, *, accept_large_sparse=True,
597597
array = array.astype(dtype, casting="unsafe", copy=False)
598598
else:
599599
array = np.asarray(array, order=order, dtype=dtype)
600-
except ComplexWarning:
600+
except ComplexWarning as complex_warning:
601601
raise ValueError("Complex data not supported\n"
602-
"{}\n".format(array))
602+
"{}\n".format(array)) from complex_warning
603603

604604
# It is possible that the np.array(..) gave no warning. This happens
605605
# when no dtype conversion happened, for example dtype = None. The

0 commit comments

Comments
 (0)
0