Skip to content

Commit 70099e5

Browse files
committed
Assert x_like.dtype == x.dtype when dtype kwarg is None
1 parent 312db69 commit 70099e5

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

array_api_tests/test_creation_functions.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,9 @@ def test_empty_like(x, dtype):
9797
x_like = empty_like(x, **kwargs)
9898

9999
if dtype is None:
100-
# TODO: Should it actually match a.dtype?
101-
# assert is_float_dtype(x_like.dtype), "empty_like() should produce an array with the default floating point dtype"
102-
pass
100+
assert x_like.dtype == x.dtype, f"{x.dtype=!s}, but empty_like() did not produce a {x.dtype} array - instead was {x_like.dtype}"
103101
else:
104-
assert x_like.dtype == dtype, "empty_like() produced an array with an incorrect dtype"
102+
assert x_like.dtype == dtype, f"{dtype=!s}, but empty_like() did not produce a {dtype} array - instead was {x_like.dtype}"
105103

106104
assert x_like.shape == x.shape, "empty_like() produced an array with an incorrect shape"
107105

@@ -165,9 +163,9 @@ def test_full_like(x, fill_value, dtype):
165163
x_like = full_like(x, fill_value, dtype=dtype)
166164

167165
if dtype is None:
168-
assert x_like.dtype == x.dtype, f"{x.dtype=}, but full_like() did not produce a {x.dtype} array - instead was {x_like.dtype}"
166+
assert x_like.dtype == x.dtype, f"{x.dtype=!s}, but full_like() did not produce a {x.dtype} array - instead was {x_like.dtype}"
169167
else:
170-
assert x_like.dtype == None, f"{dtype=}, but full_like() did not produce a {dtype} array - instead was {x_like.dtype}"
168+
assert x_like.dtype == dtype, f"{dtype=!s}, but full_like() did not produce a {dtype} array - instead was {x_like.dtype}"
171169

172170
assert x_like.shape == x.shape, "full_like() produced an array with incorrect shape"
173171
if is_float_dtype(x_like.dtype) and isnan(asarray(fill_value)):
@@ -258,10 +256,9 @@ def test_ones_like(x, dtype):
258256
x_like = ones_like(x, **kwargs)
259257

260258
if dtype is None:
261-
# TODO: Should it actually match a.dtype?
262-
pass
259+
assert x_like.dtype == x.dtype, f"{x.dtype=!s}, but ones_like() did not produce a {x.dtype} array - instead was {x_like.dtype}"
263260
else:
264-
assert x_like.dtype == dtype, "ones_like() produced an array with an incorrect dtype"
261+
assert x_like.dtype == dtype, f"{dtype=!s}, but ones_like() did not produce a {dtype} array - instead was {x_like.dtype}"
265262

266263
assert x_like.shape == x.shape, "ones_like() produced an array with an incorrect shape"
267264
assert all(equal(x_like, full((), ONE, dtype=x_like.dtype))), "ones_like() array did not equal 1"
@@ -306,10 +303,9 @@ def test_zeros_like(x, dtype):
306303
x_like = zeros_like(x, **kwargs)
307304

308305
if dtype is None:
309-
# TODO: Should it actually match a.dtype?
310-
pass
306+
assert x_like.dtype == x.dtype, f"{x.dtype=!s}, but zeros_like() did not produce a {x.dtype} array - instead was {x_like.dtype}"
311307
else:
312-
assert x_like.dtype == dtype, "zeros_like() produced an array with an incorrect dtype"
308+
assert x_like.dtype == dtype, f"{dtype=!s}, but zeros_like() did not produce a {dtype} array - instead was {x_like.dtype}"
313309

314310
assert x_like.shape == x.shape, "zeros_like() produced an array with an incorrect shape"
315311
assert all(equal(x_like, full((), ZERO, dtype=x_like.dtype))), "zeros_like() array did not equal 0"

0 commit comments

Comments
 (0)