Skip to content

Commit 2cb368c

Browse files
Merge pull request #1496 from IntelPython/replace-typeerror-with-valueerror-as-appropriate
2 parents fbe0081 + a2ec2f2 commit 2cb368c

17 files changed

+34
-29
lines changed

dpctl/tensor/_elementwise_common.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ def __call__(self, x, out=None, order="K"):
188188
acceptance_fn=self.acceptance_fn_,
189189
)
190190
if res_dt is None:
191-
raise TypeError(
191+
raise ValueError(
192192
f"function '{self.name_}' does not support input type "
193193
f"({x.dtype}), "
194194
"and the input could not be safely coerced to any "
@@ -209,7 +209,7 @@ def __call__(self, x, out=None, order="K"):
209209
)
210210

211211
if res_dt != out.dtype:
212-
raise TypeError(
212+
raise ValueError(
213213
f"Output array of type {res_dt} is needed,"
214214
f" got {out.dtype}"
215215
)
@@ -587,7 +587,7 @@ def __call__(self, o1, o2, out=None, order="K"):
587587
)
588588

589589
if res_dt is None:
590-
raise TypeError(
590+
raise ValueError(
591591
f"function '{self.name_}' does not support input types "
592592
f"({o1_dtype}, {o2_dtype}), "
593593
"and the inputs could not be safely coerced to any "
@@ -608,7 +608,7 @@ def __call__(self, o1, o2, out=None, order="K"):
608608
)
609609

610610
if res_dt != out.dtype:
611-
raise TypeError(
611+
raise ValueError(
612612
f"Output array of type {res_dt} is needed,"
613613
f"got {out.dtype}"
614614
)

dpctl/tests/elementwise/test_add.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ def test_add_dtype_error(
337337

338338
y = dpt.zeros_like(ar1, dtype="int8")
339339
assert_raises_regex(
340-
TypeError, "Output array of type.*is needed", dpt.add, ar1, ar2, y
340+
ValueError, "Output array of type.*is needed", dpt.add, ar1, ar2, y
341341
)
342342

343343

@@ -384,7 +384,7 @@ def test_add_inplace_dtype_matrix(op1_dtype, op2_dtype):
384384
dpt.asnumpy(ar3) == np.full(ar3.shape, 2, dtype=ar3.dtype)
385385
).all()
386386
else:
387-
with pytest.raises(TypeError):
387+
with pytest.raises(ValueError):
388388
ar1 += ar2
389389
dpt.add(ar1, ar2, out=ar1)
390390

@@ -404,7 +404,7 @@ def test_add_inplace_dtype_matrix(op1_dtype, op2_dtype):
404404
dpt.asnumpy(ar4) == np.full(ar4.shape, 2, dtype=ar4.dtype)
405405
).all()
406406
else:
407-
with pytest.raises(TypeError):
407+
with pytest.raises(ValueError):
408408
dpt.add(ar1, ar2, out=ar2)
409409

410410

dpctl/tests/elementwise/test_bitwise_and.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def test_bitwise_and_inplace_dtype_matrix(op1_dtype, op2_dtype):
123123
ar3 &= ar4
124124
assert dpt.all(ar3 == 1)
125125
else:
126-
with pytest.raises(TypeError):
126+
with pytest.raises(ValueError):
127127
ar1 &= ar2
128128
dpt.bitwise_and(ar1, ar2, out=ar1)
129129

@@ -139,5 +139,5 @@ def test_bitwise_and_inplace_dtype_matrix(op1_dtype, op2_dtype):
139139
dpt.bitwise_and(ar3, ar4, out=ar4)
140140
dpt.all(ar4 == 1)
141141
else:
142-
with pytest.raises(TypeError):
142+
with pytest.raises(ValueError):
143143
dpt.bitwise_and(ar1, ar2, out=ar2)

dpctl/tests/elementwise/test_bitwise_left_shift.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def test_bitwise_left_shift_inplace_dtype_matrix(op1_dtype, op2_dtype):
131131
ar3 <<= ar4
132132
assert dpt.all(ar3 == 2)
133133
else:
134-
with pytest.raises(TypeError):
134+
with pytest.raises(ValueError):
135135
ar1 <<= ar2
136136
dpt.bitwise_left_shift(ar1, ar2, out=ar1)
137137

@@ -147,5 +147,5 @@ def test_bitwise_left_shift_inplace_dtype_matrix(op1_dtype, op2_dtype):
147147
dpt.bitwise_left_shift(ar3, ar4, out=ar4)
148148
dpt.all(ar4 == 2)
149149
else:
150-
with pytest.raises(TypeError):
150+
with pytest.raises(ValueError):
151151
dpt.bitwise_left_shift(ar1, ar2, out=ar2)

dpctl/tests/elementwise/test_bitwise_or.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def test_bitwise_or_inplace_dtype_matrix(op1_dtype, op2_dtype):
123123
ar3 |= ar4
124124
assert dpt.all(ar3 == 1)
125125
else:
126-
with pytest.raises(TypeError):
126+
with pytest.raises(ValueError):
127127
ar1 |= ar2
128128
dpt.bitwise_or(ar1, ar2, out=ar1)
129129

@@ -139,5 +139,5 @@ def test_bitwise_or_inplace_dtype_matrix(op1_dtype, op2_dtype):
139139
dpt.bitwise_or(ar3, ar4, out=ar4)
140140
dpt.all(ar4 == 1)
141141
else:
142-
with pytest.raises(TypeError):
142+
with pytest.raises(ValueError):
143143
dpt.bitwise_or(ar1, ar2, out=ar2)

dpctl/tests/elementwise/test_bitwise_right_shift.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def test_bitwise_right_shift_inplace_dtype_matrix(op1_dtype, op2_dtype):
131131
ar3 >>= ar4
132132
assert dpt.all(ar3 == 0)
133133
else:
134-
with pytest.raises(TypeError):
134+
with pytest.raises(ValueError):
135135
ar1 >>= ar2
136136
dpt.bitwise_right_shift(ar1, ar2, out=ar1)
137137

@@ -147,5 +147,5 @@ def test_bitwise_right_shift_inplace_dtype_matrix(op1_dtype, op2_dtype):
147147
dpt.bitwise_right_shift(ar3, ar4, out=ar4)
148148
dpt.all(ar4 == 0)
149149
else:
150-
with pytest.raises(TypeError):
150+
with pytest.raises(ValueError):
151151
dpt.bitwise_right_shift(ar1, ar2, out=ar2)

dpctl/tests/elementwise/test_bitwise_xor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def test_bitwise_xor_inplace_dtype_matrix(op1_dtype, op2_dtype):
123123
ar3 ^= ar4
124124
assert dpt.all(ar3 == 0)
125125
else:
126-
with pytest.raises(TypeError):
126+
with pytest.raises(ValueError):
127127
ar1 ^= ar2
128128
dpt.bitwise_xor(ar1, ar2, out=ar1)
129129

@@ -139,5 +139,5 @@ def test_bitwise_xor_inplace_dtype_matrix(op1_dtype, op2_dtype):
139139
dpt.bitwise_xor(ar3, ar4, out=ar4)
140140
dpt.all(ar4 == 0)
141141
else:
142-
with pytest.raises(TypeError):
142+
with pytest.raises(ValueError):
143143
dpt.bitwise_xor(ar1, ar2, out=ar2)

dpctl/tests/elementwise/test_divide.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ def test_divide_inplace_dtype_matrix(op1_dtype, op2_dtype):
235235
ar3 /= ar4
236236
assert dpt.all(ar3 == 1)
237237
else:
238-
with pytest.raises(TypeError):
238+
with pytest.raises(ValueError):
239239
ar1 /= ar2
240240
dpt.divide(ar1, ar2, out=ar1)
241241

@@ -254,5 +254,5 @@ def test_divide_inplace_dtype_matrix(op1_dtype, op2_dtype):
254254
dpt.divide(ar3, ar4, out=ar4)
255255
dpt.all(ar4 == 1)
256256
else:
257-
with pytest.raises(TypeError):
257+
with pytest.raises(ValueError):
258258
dpt.divide(ar1, ar2, out=ar2)

dpctl/tests/elementwise/test_floor_ceil_trunc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def test_floor_ceil_trunc_error_dtype(dpt_call, dtype):
100100
x = dpt.zeros(5, dtype=dtype)
101101
y = dpt.empty_like(x, dtype="b1")
102102
assert_raises_regex(
103-
TypeError, "Output array of type.*is needed", dpt_call, x, y
103+
ValueError, "Output array of type.*is needed", dpt_call, x, y
104104
)
105105

106106

dpctl/tests/elementwise/test_floor_divide.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ def test_floor_divide_inplace_dtype_matrix(op1_dtype, op2_dtype):
299299
ar3 //= ar4
300300
assert dpt.all(ar3 == 1)
301301
else:
302-
with pytest.raises(TypeError):
302+
with pytest.raises(ValueError):
303303
ar1 //= ar2
304304
dpt.floor_divide(ar1, ar2, out=ar1)
305305

@@ -315,5 +315,5 @@ def test_floor_divide_inplace_dtype_matrix(op1_dtype, op2_dtype):
315315
dpt.floor_divide(ar3, ar4, out=ar4)
316316
dpt.all(ar4 == 1)
317317
else:
318-
with pytest.raises(TypeError):
318+
with pytest.raises(ValueError):
319319
dpt.floor_divide(ar1, ar2, out=ar2)

0 commit comments

Comments
 (0)