Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c71fddd

Browse files
committed
TST: cover ValueError on complex keys for _determine_key_type
1 parent f3c2285 commit c71fddd

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

sklearn/utils/tests/test_utils.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,16 @@ def test_determine_key_type_array_api(array_namespace, device, dtype_name):
267267
bool_array_key = xp.asarray([True, False, True])
268268
assert _determine_key_type(bool_array_key) == "bool"
269269

270+
try:
271+
complex_array_key = xp.asarray([1 + 1j, 2 + 2j, 3 + 3j])
272+
except TypeError:
273+
# Complex numbers are not supported by all Array API libraries.
274+
complex_array_key = None
275+
276+
if complex_array_key is not None:
277+
with pytest.raises(ValueError, match="No valid specification of the"):
278+
_determine_key_type(complex_array_key)
279+
270280

271281
@pytest.mark.parametrize(
272282
"array_type", ["list", "array", "sparse", "dataframe", "polars"]

0 commit comments

Comments
 (0)