@@ -129,31 +129,17 @@ def test_broadcast_to(x, data):
129129 # TODO: test values
130130
131131
132- @given (_from = non_complex_dtypes (), to = non_complex_dtypes (), data = st .data ())
133- def test_can_cast (_from , to , data ):
134- from_ = data .draw (
135- st .just (_from ) | hh .arrays (dtype = _from , shape = hh .shapes ()), label = "from_"
136- )
132+ @given (_from = hh .all_dtypes , to = hh .all_dtypes )
133+ def test_can_cast (_from , to ):
134+ out = xp .can_cast (_from , to )
137135
138- out = xp .can_cast (from_ , to )
136+ expected = False
137+ for other in dh .all_dtypes :
138+ if dh .promotion_table .get ((_from , other )) == to :
139+ expected = True
140+ break
139141
140142 f_func = f"[can_cast({ dh .dtype_to_name [_from ]} , { dh .dtype_to_name [to ]} )]"
141- assert isinstance (out , bool ), f"{ type (out )= } , but should be bool { f_func } "
142- if _from == xp .bool :
143- expected = to == xp .bool
144- else :
145- same_family = None
146- for dtypes in [dh .all_int_dtypes , dh .real_float_dtypes , dh .complex_dtypes ]:
147- if _from in dtypes :
148- same_family = to in dtypes
149- break
150- assert same_family is not None # sanity check
151- if same_family :
152- from_min , from_max = dh .dtype_ranges [_from ]
153- to_min , to_max = dh .dtype_ranges [to ]
154- expected = from_min >= to_min and from_max <= to_max
155- else :
156- expected = False
157143 if expected :
158144 # cross-kind casting is not explicitly disallowed. We can only test
159145 # the cases where it should return True. TODO: if expected=False,
0 commit comments